Hi.
I am a beginner to this field and currently designing a digital alcohol sensor project. To briefly explain, if a sensor does not detect any alcohol, the data value is 0 but when it does the value becomes 1.
I am using Raspberry pi zero wireless and python.
My problem is, the sensor works perfectly with Ubidots for the first 15~30 minutes. However, after certain amount of time has passed, the connection abruptly fails and stops sending data.
Here’s my code(GPIO no.7 is where I plugged the sensor in) :
from ubidots import ApiClient
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
try:
api = ApiClient(token="wn28jJZVysdZOL6WM2DbnBVi4bKiOM")
variable = api.get_variable("594e66f27625423d76e57f83")
print("connectd to ubidots")
except:
print ("connection failure")
digital = 0
while(1):
presence = GPIO.input(7)
if (presence==0):
variable.save_value({"value":digital})
if (presence):
digital = 1
variable.save_value({"value":digital})
Also, when the device gets disconnected with Ubidots, this is what comes out on the Terminal.
Traceback (most recent call last):
File “ubi.py”, line 24, in
variable.save_value({“value”:digital})
File “/usr/local/lib/python2.7/dist-packages/ubidots/apiclient.py”, line 148, in wrapped_f
return fn(self, *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/ubidots/apiclient.py”, line 306, in save_value
return self.bridge.post(‘variables/’ + self.id + ‘/values’, data).json()
File “/usr/lib/python2.7/dist-packages/requests/models.py”, line 793, in json
return json.loads(self.text, **kwargs)
File “/usr/lib/python2.7/json/init.py”, line 338, in loads
return _default_decoder.decode(s)
File “/usr/lib/python2.7/json/decoder.py”, line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python2.7/json/decoder.py”, line 384, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded
Thank you!