Last active
August 8, 2018 19:53
-
-
Save jrleeman/74401dd87f819503c04d27b62750caf5 to your computer and use it in GitHub Desktop.
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
import serial | |
import sys | |
import time | |
from datetime import datetime | |
def post_data_to_chords(data, time): | |
# 88.1, 88.7, 93.3, 97.9, 100.3, 101.1, 105.9, T, p, rh | |
sensor_indices = [1, 4, 27, 50, 62, 66, 90] | |
sensor_id = 'fmradar' | |
user_email = '[email protected]' | |
api_key = 'GOESHERE' | |
base_url = 'is-geo.chordsrt.com' | |
put_string = ( | |
'http://'+base_url+'/measurements/url_create?' + | |
'sensor_id=' + sensor_id + # CHORDS Sensor ID | |
'&KAWZ=' + str(data[sensor_indices[0]]) + | |
'&KLOV=' + str(data[sensor_indices[1]]) + | |
'&KMWB=' + str(data[sensor_indices[2]]) + | |
'&KKBG=' + str(data[sensor_indices[3]]) + | |
'&KAPA=' + str(data[sensor_indices[4]]) + | |
'&KUHH=' + str(data[sensor_indices[5]]) + | |
'&KPOI=' + str(data[sensor_indices[6]]) + | |
'&T=' + str(data[101]) + | |
'&p=' + str(data[102]) + | |
'&Rh=' + str(data[103]) + | |
'&at=' + datetime.strftime(time, '%Y-%m-%dT%H:%M') + | |
'&email=' + user_email + #authenticating email | |
'&api_key=' + api_key # authenticating API Key | |
) | |
r = requests.get(put_string) | |
fname = 'fm_radar_log.csv' | |
f = open(fname, 'a') | |
s = serial.Serial('/dev/ttyUSB1', 9600) | |
while True: | |
if s.inWaiting() > 1: | |
f = open(fname, 'a') | |
line = s.readline() | |
time = datetime.utcnow() | |
time_str = datetime.strftime(time, '%m-%d-%YT%H:%M:%S') | |
f.write(time_str) | |
f.write(",") | |
f.write(line) | |
print "Logged: ", time_str | |
f.close() | |
if '#' in line: | |
print "Skipping Header" | |
pass | |
else: | |
print "Chords posting" | |
data = line.split(',') | |
data = [float(a) for a in data] | |
post_data_to_chords(data, time) | |
print "Complete" | |
else: | |
# Sleep to save system resources | |
time.sleep(10) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment