Error not intercepted[SOLVED]



Briefly, I found out GrovePi and I though it could be a great way to fast prototyping or realize small appliances.
So I bought one and hooked up few sensors and try a ready made example.
I used a Raspberry Pi B+ and the image for Dexter, following the installation procedure, including updating the OS and the firmware.
I had already around few sensors from Groove (for MSP430) and so I choose to use the plant monitor project as test.
I did hook up the sensors, I don’t have the camera so I commented out the call to the function and tried it.
It worked nicely.

So, why I’m writing ? :slight_smile:
I left the code running for a while and I saw after a while (15 minutes approx) the program did crash.
I took a look at the code and I saw already was using to catch the exception.
Then I decided to modify the code little bit trying to catch every specific operation error, and again after a while the code crashed instead to have the exception catch working.

#Read the data from the sensors
def read_sensor():
	except IOError as TypeError:
		print("Moisture error reading\n")
		return [-1,-1,-1,-1]

	except IOError as TypeError:
		print("Light error reading\n")
		return [-1,-1,-1,-1]

		[temp,humidity] = grovepi.dht(temp_humidity_sensor,white)
	except IOError as TypeError:
		print("Temp/Humidity error reading\n")
		return [-1,-1,-1,-1]

	if math.isnan(temp) or math.isnan(humidity):		#temp/humidity sensor sometimes gives nan
		return [-1,-1,-1,-1]
	return [moisture,light,temp,humidity]

With the code modified as above, I noticed that the catch is not working for the temp/humidity reading.

Traceback (most recent call last):
File “./”, line 117, in
File “./”, line 89, in read_sensor
[temp,humidity] = grovepi.dht(temp_humidity_sensor,white)
TypeError: ‘int’ object is not iterable

Sometime the catch did work, sometime not.
I wonder if anybody else experienced this kind of problems with Python on the Raspberry using GrovePi.

So far I see that the light sensor sometime has a bad reading but so far the catch works.
The temperature is the one that failed to be catch sometime.

The errors seems quite random so far, the code it can run for hours or few minutes before to stop for the error.

Any suggestion to solve this problem ?



It looks like the temp & humidity sensors code is crashing because of a TypeError which is coming because of an IOError. Can you try replacing
except IOError as TypeError:
in the temp & Hum sensor by
except (IOError, TypeError):
and see if that works any better for you.


Thanks !
I did the modification and I’ll let run the app to see if there are more crash.
So far so good but it need to run for long time.



Just an update.
I decided to intercept all the possible errors and resume a single catch and so far it seems working.
My main goal is to don’t have the app crashing for a sensor reading, it has to run and so far seems happily running.
Thanks for the diagnosis and suggestion. Now is stable enough and I can start to build over it the real app.



Hi @TheFwGuy,

Glad we were able to help you. Thanks for the update.



This topic was automatically closed after 24 hours. New replies are no longer allowed.