Created
February 9, 2013 19:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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