Skip to content

Instantly share code, notes, and snippets.

@jeznag
Last active August 2, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeznag/25b4b32885cbffb32c2a062d84e95aaa to your computer and use it in GitHub Desktop.
Save jeznag/25b4b32885cbffb32c2a062d84e95aaa to your computer and use it in GitHub Desktop.
Send serial data to ada fruit IO
from Adafruit_IO import *
import sys, os, serial, threading
aio = Client('CLIENT_KEY')
def monitor():
ser = serial.Serial('/dev/tty.usbmodem1411', 9600)
while (1):
line = ser.readline()
if (line != ""):
str_data = (line.replace("concentration = ", "").replace("pcs/0.01cf", "").strip())
if (len(str_data) != 0):
data = float(str_data)
aio.send('AQ data', data)
print data
text_file = open("aq-data.log", "a")
text_file.write(str(data) + "\n")
text_file.close() # do some other things here print "Stop Monitoring"
""" -------------------------------------------
MAIN APPLICATION
"""
print "Start Serial Monitor"
print
monitor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment