public
Created

Sending measurements from a MighyOhm Geiger Counter to cosm, using a Raspberry Pi and its onboard serial interface.

  • Download Gist
geiger.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/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]))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.