73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
import numpy as np
|
||
|
import os, serial,time,socket,sys,json,logging,requests,getopt
|
||
|
from meas_data import meas_data
|
||
|
# import the server implementation
|
||
|
# import ADC
|
||
|
#import vedirect
|
||
|
#import upload_osm
|
||
|
|
||
|
configfile="config.json"
|
||
|
cf=open(configfile,"r")
|
||
|
log_conf=json.load(cf)
|
||
|
cf.close()
|
||
|
|
||
|
parameter={"device":socket.gethostname(),"mean_count":5,"ring_length":10,"wait":0.5,"sigma":2}
|
||
|
for n in parameter:
|
||
|
if n in log_conf:
|
||
|
parameter[n]=log_conf[n]
|
||
|
|
||
|
bveml=False
|
||
|
if "veml6070" in log_conf:
|
||
|
bveml=True
|
||
|
if "enable" in log_conf['veml6070']:
|
||
|
if log_conf['veml6070']['enable'] == 0:
|
||
|
bveml=False
|
||
|
if bveml:
|
||
|
import veml6070
|
||
|
veml_port=1
|
||
|
if "port" in log_conf['veml6070']:
|
||
|
veml_port=int(log_conf['veml6070']['port'])
|
||
|
try:
|
||
|
veml = veml6070.Veml6070(i2c_bus=veml_port)
|
||
|
except:
|
||
|
bveml=False
|
||
|
else:
|
||
|
tsl_sigma=parameter['sigma']
|
||
|
if "sigma" in log_conf['veml6070']:
|
||
|
tsl_sigma=int(log_conf['veml6070']['sigma'])
|
||
|
if tsl_sigma < 1:
|
||
|
tsl_sigma=1
|
||
|
tsl_data=meas_data(var_name="uv",ring_length=parameter['ring_length'],device=parameter['device'],sensor="VEML6070",i2c=veml_port,store_file="/home/pi/log/data_uv",sigma=tsl_sigma)
|
||
|
if "sqlserver" in log_conf:
|
||
|
hostname="banana"
|
||
|
if "host" in log_conf['sqlserver']:
|
||
|
hostname=log_conf['sqlserver']['host']
|
||
|
port=24048
|
||
|
if "port" in log_conf['sqlserver']:
|
||
|
port=int(log_conf['sqlserver']['port'])
|
||
|
tsl_data.set_sql(host=hostname,port=port)
|
||
|
if "opensensemap" in log_conf['tsl2591']:
|
||
|
osm=log_conf['veml6070']['opensensemap']
|
||
|
if "sensebox_id" in osm:
|
||
|
sid=osm['sensebox_id']
|
||
|
if "sensors" in osm:
|
||
|
if "uv" in osm['sensors']:
|
||
|
tsl_data.set_sensebox(sid,osm['sensors']['uv'])
|
||
|
|
||
|
|
||
|
if bveml:
|
||
|
while True:
|
||
|
|
||
|
# read bme280 (temperature, humidity, pressure)
|
||
|
veml.set_integration_time(veml6070.INTEGRATIONTIME_1T)
|
||
|
tsl_data.append(int(1000*veml.get_uva_light_intensity()))
|
||
|
time.sleep(parameter['wait'])
|
||
|
|
||
|
|
||
|
# close the client
|
||
|
print("done")
|
||
|
|
||
|
|