I’m trying to use your Spark Core code to read a waterproof DS18B20 and I’m getting it to post the temperature to the serial port. However when I try to use your Python code I’m running into errors. Since I’m trying to just get the temperature reading first before worrying about Librato, I’ve masked those lines out.
However, I think I’m having a problem with the ‘requests’ library as neat at it looks.
My python code:
import librato, json, requests, socket, time, os
import json, requests, socket, time, os
from sseclient import SSEClient
librato_user = os.environ[‘LIBRATO_USER’]
librato_auth = os.environ[‘LIBRATO_AUTH’]
SPARK_CORE_ID = 'snipped’
SPARK_CORE_TOKEN = ‘sniped’
spark_core_id = os.environ[SPARK_CORE_ID]
spark_core_token = os.environ[SPARK_CORE_TOKEN]
librato_api = librato.connect(librato_user, librato_auth)
while True:
try:
spark_messages = SSEClient(“https://api.spark.io/v1/devices/%s/events/?access_token=%s” % (spark_core_id, spark_core_token))
for msg in spark_messages:
if msg.event == “temperature1”:
data = json.loads(msg.data);
print “Decoded data:”, data
librato_api.submit(“temperature”, data[‘data’], description=“temperature of fermenter 1”, source=“fermenter1”)
except socket.gaierror:
print "Connection error. Trying again in a minute."
time.sleep(60)
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
print "Server request error. Trying again in a minute."
time.sleep(60)
except librato.exceptions.BadRequest:
print “Librato error. Trying again in a minute.”
time.sleep(60)
error code I get:
================================ RESTART ================================
Traceback (most recent call last):
File “/Users/msharris/documents/Spark Core/hot tub control/hottub-server.py”, line 2, in
import json, requests, socket, time, os
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/init.py”, line 58, in
from . import utils
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/utils.py”, line 25, in
from .compat import parse_http_list as _parse_list_header
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/compat.py”, line 7, in
from .packages import chardet
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/init.py”, line 3, in
from . import urllib3
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/init.py”, line 16, in
from .connectionpool import (
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 36, in
from .connection import (
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/connection.py”, line 43, in
from .util import (
ImportError: No module named util
Although I’ve used Python before, I am in the middle of learning it again.
Thanks for any help.
Mark
MarkSHarrisTX@gmail.com