Skip to content

Instantly share code, notes, and snippets.

@tiefpunkt
Created February 9, 2013 19:54
Show Gist options
  • Save tiefpunkt/4746781 to your computer and use it in GitHub Desktop.
Save tiefpunkt/4746781 to your computer and use it in GitHub Desktop.
Sending measurements from a MighyOhm Geiger Counter to cosm, using a Raspberry Pi and its onboard serial interface.
#!/bin/python
import serial
from datetime import datetime
import eeml
import eeml.datastream
API_KEY = 'YOUR_COSM_API_KEY'
API_URL = 102285
ser = serial.Serial(port="/dev/ttyAMA0", baudrate=9600)
#sio = io.TextIOWrapper(io.BufferedRWPair(ser,ser))
ser.open()
cpm = []
usv = []
currentMinute = datetime.now().minute
while 1 < 2:
if not datetime.now().minute == currentMinute:
cpm_avg = round(sum(cpm)/float(len(cpm)),1)
usv_avg = round(sum(usv)/len(usv),3)
print currentMinute, ": CPM: ", cpm_avg, " uSv/h: ", usv_avg
cosm = eeml.datastream.Cosm(API_URL, API_KEY, use_https=False)
cosm.update([eeml.Data(0, cpm_avg), eeml.Data(1, usv_avg)])
try:
cosm.put()
except:
print "Something unexpected happed. Let's forget about it and continue..."
cpm = []
usv = []
currentMinute = datetime.now().minute
line = ser.readline().split(", ")
cpm.append(int(line[3]))
usv.append(float(line[5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment