This commit is contained in:
parent
1d48996e68
commit
8a6ff0c678
1 changed files with 45 additions and 1 deletions
|
|
@ -1,11 +1,15 @@
|
|||
#from influxdb import InfluxDBClient
|
||||
from influxdb import InfluxDBClient
|
||||
import serial
|
||||
import uuid
|
||||
import random
|
||||
import time
|
||||
import datetime
|
||||
import s2cell
|
||||
|
||||
dbframe = 0
|
||||
|
||||
cosmicdict = {
|
||||
"DeviceID": 0,
|
||||
"UTCUnixTime": 0,
|
||||
"SubSeconds": 0.0,
|
||||
"TemperatureC": 0.0,
|
||||
|
|
@ -17,13 +21,27 @@ cosmicdict = {
|
|||
"MagY": 0.0,
|
||||
"MagZ": 0.0,
|
||||
"Pressure": 0.0,
|
||||
"Altitude": 0.0,
|
||||
"Longitude": 0.0,
|
||||
"Latitude": 0.0
|
||||
}
|
||||
|
||||
nstimestamp = 0
|
||||
|
||||
s2celllocation = 0
|
||||
|
||||
print("starting")
|
||||
ser = serial.Serial(port='/dev/serial0', baudrate=115200, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
|
||||
print("connected to: " + ser.portstr)
|
||||
print ("The device ID using uuid1() is : ",end="")
|
||||
print (uuid.uuid1().int)
|
||||
cosmicdict['DeviceID']=uuid.uuid1().int
|
||||
|
||||
print("DB connection")
|
||||
client = InfluxDBClient(host='localhost', port=8086)
|
||||
client.create_database('cosmicpilocal')
|
||||
data=[]
|
||||
|
||||
#ser.write("help\n");
|
||||
while True:
|
||||
line = ser.readline();
|
||||
|
|
@ -85,3 +103,29 @@ while True:
|
|||
current_subSeconds = float(divisors[0]) / float(divisors[1])
|
||||
cosmicdict['SubSeconds'] = current_subSeconds
|
||||
print(cosmicdict)
|
||||
#conversion to ns for influx
|
||||
#add s and ns, then multiply by 1e9
|
||||
nstimestamp = cosmicdict['UTCUnixTime']+cosmicdict['SubSeconds']
|
||||
nstimestamp = nstimestamp*1e9
|
||||
nstimestamp = int(nstimestamp)
|
||||
s2celllocation = s2cell.lat_lon_to_cell_id(cosmicdict['Latitude'],cosmicdict['Longitude'])
|
||||
data = []
|
||||
data.append("{measurement},id={DeviceID} s2_cell_id={s2_cell_id},lat={latitude},lon={longitude},Temp={Temp},Hum={Hum},Accelx={Accelx},Accely={Accely},Accelz={Accelz},Magx={Magx},Magy={Magy},Magz={Magz},Press={Pressx},Alt={Altx} {timestamp}"
|
||||
.format(measurement='CosmicPiV1.8.1',
|
||||
DeviceID=cosmicdict['DeviceID'],
|
||||
s2_cell_id=s2celllocation,
|
||||
latitude=cosmicdict['Longitude'],
|
||||
longitude=cosmicdict['Latitude'],
|
||||
Temp=cosmicdict['TemperatureC'],
|
||||
Hum=cosmicdict['Humidity'],
|
||||
Accelx=cosmicdict['AccelX'],
|
||||
Accely=cosmicdict['AccelY'],
|
||||
Accelz=cosmicdict['AccelZ'],
|
||||
Magx=cosmicdict['MagX'],
|
||||
Magy=cosmicdict['MagY'],
|
||||
Magz=cosmicdict['MagZ'],
|
||||
Pressx=cosmicdict['Pressure'],
|
||||
Altx=cosmicdict['Altitude'],
|
||||
timestamp=nstimestamp))
|
||||
print(data)
|
||||
client.write_points(data, database='cosmicpilocal', time_precision='n', batch_size=1, protocol='line')
|
||||
Loading…
Reference in a new issue