You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
4 years ago
|
import smbus
|
||
|
import time
|
||
|
import re
|
||
|
from datetime import datetime
|
||
|
from influxdb import InfluxDBClient
|
||
|
|
||
|
|
||
|
client = InfluxDBClient('192.168.1.6', 8086, 'test', 'test', 'sensor')
|
||
|
|
||
|
|
||
|
bus = smbus.SMBus(1)
|
||
|
address = 0x16
|
||
|
|
||
|
while True:
|
||
|
try:
|
||
|
now = datetime.now()
|
||
|
data = ""
|
||
|
for i in range(0, 40):
|
||
|
data += chr(bus.read_byte(address));
|
||
|
|
||
|
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
|
||
|
file = open("sensor_logs", "a")
|
||
|
file.write(date_time +" "+ data + "\n")
|
||
|
file.close()
|
||
|
find_values = re.findall(r'[-]{0,1}[\d]*[\.][\d]+', data)
|
||
|
create_list = list(map(str,find_values))
|
||
|
# print (create_list)
|
||
|
# print(create_list[0])
|
||
|
# print(create_list[1])
|
||
|
# print(create_list[2])
|
||
|
x_value = (create_list[0])
|
||
|
y_value = (create_list[1])
|
||
|
z_value = (create_list[2])
|
||
|
|
||
|
client.write(["logg,sensor_type=lilypad x_value="+x_value+",y_value="+y_value+",z_value="+z_value+""],{'db':'sensor'},204,'line')
|
||
|
|
||
|
print (date_time+ " " + data)
|
||
|
print("\n")
|
||
|
time.sleep(1);
|
||
|
|
||
|
except KeyboardInterrupt:
|
||
|
print("\n"+"Interrupt detected Stopping program")
|
||
|
exit(0)
|