working version after restructuring
parent
2b202bdd72
commit
0948589ed6
|
@ -18,7 +18,7 @@
|
|||
"bme280":
|
||||
{"enable": 1, "port": 1,"address": "0x77"},
|
||||
"tristar":
|
||||
{"enable": 1, "port": "/dev/ttyUSB0","baud": 9600,"timeout": 1},
|
||||
{"enable": 1, "port": "/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0","baud": 9600,"timeout": 1},
|
||||
"vedirect":
|
||||
{"enable": 0, "port": "/dev/serial/by-id/usb-VictronEnergy_BV_VE_Direct_cable_VE1SSBVT-if00-port0"},
|
||||
"ads1x15":
|
||||
|
|
89
logger.py
89
logger.py
|
@ -9,7 +9,12 @@ from pymodbus.client.sync import ModbusSerialClient as ModbusClient
|
|||
from Adafruit_ADS1x15 import ADS1115
|
||||
from Adafruit_ADS1x15 import ADS1015
|
||||
import vedirect
|
||||
import upload_osm
|
||||
|
||||
def upload_osm(sensor_id,value):
|
||||
url="https://ingress.opensensemap.org/boxes/%s/%s" % (sensebox_id,sensor_id)
|
||||
r = requests.post(url,json={'value': value})
|
||||
if r.status_code != requests.codes.ok:
|
||||
print("Error %d: %s" % (r.status_code,r.text))
|
||||
|
||||
configfile="config.json.template"
|
||||
cf=open(configfile,"r")
|
||||
|
@ -68,7 +73,7 @@ if "bme280" in log_conf:
|
|||
else:
|
||||
bme_port=1
|
||||
if "address" in log_conf['bme280']:
|
||||
bme_add=log_conf['bme280']['address']
|
||||
bme_add=int(log_conf['bme280']['address'],16)
|
||||
else:
|
||||
bme_add=0x77
|
||||
try:
|
||||
|
@ -94,29 +99,23 @@ if "tristar" in log_conf:
|
|||
if "enable" in log_conf['tristar']:
|
||||
if log_conf['tristar']['enable'] == 0:
|
||||
btristar=False
|
||||
|
||||
tri_port='/dev/ttyUSB0'
|
||||
if "port" in log_conf['tristar']:
|
||||
tri_port=log_conf['tristar']['port']
|
||||
else:
|
||||
tri_port='/dev/ttyUSB0'
|
||||
tri_baud=9600
|
||||
if "baud" in log_conf['tristar']:
|
||||
tri_baud=log_conf['tristar']['baud']
|
||||
else:
|
||||
tri_baud=9600
|
||||
tri_timeout=1
|
||||
if "timeout" in log_conf['tristar']:
|
||||
tri_timeout=log_conf['tristar']['timeout']
|
||||
else:
|
||||
tri_timeout=1
|
||||
try:
|
||||
triclient = ModbusClient(method='rtu', port=tri_port, baudrate=tri_baud, timeout=tri_timeout)
|
||||
except:
|
||||
btristar=False
|
||||
else:
|
||||
triclient.connect()
|
||||
for i in ["volt_scale","amp_scale","volt_bat_term","volt_bat_sens","volt_arr","amp_bat",
|
||||
"amp_arr","temp_heatsink","temp_bat","ah_res","ah_tot","kwh_res","kwh_tot","watt_in",
|
||||
"watt_out","hour_tot","state","volt_sweep_mp","volt_sweep_oc"]:
|
||||
channel_names.append[i]
|
||||
for i in ["volt_scale","amp_scale","volt_bat_term","volt_bat_sens","volt_arr","amp_bat","amp_arr","temp_heatsink","temp_bat","ah_res","ah_tot","kwh_res","kwh_tot","watt_in","watt_out","hour_tot","state","volt_sweep_mp","volt_sweep_oc"]:
|
||||
channel_names.append(i)
|
||||
|
||||
# declare ve mppt
|
||||
bve=False
|
||||
|
@ -135,7 +134,7 @@ if "vedirect" in log_conf:
|
|||
bve=False
|
||||
else:
|
||||
for i in ["volt_bat_ve","volt_arr_ve","amp_ve","watt_ve","days_ve"]:
|
||||
channel_names.append[i]
|
||||
channel_names.append(i)
|
||||
|
||||
# declare adc
|
||||
badc=False
|
||||
|
@ -151,10 +150,12 @@ if "ads1x15" in log_conf:
|
|||
GAIN=1
|
||||
if "adc" in log_conf['ads1x15']:
|
||||
adc_count=0
|
||||
for x,y in log_conf['ads1x15']['adc']:
|
||||
tadc=log_conf['ads1x15']['adc']
|
||||
for x in tadc:
|
||||
y=tadc[x]
|
||||
adc_address=0x48
|
||||
if "address" in y:
|
||||
adc_address=y['address']
|
||||
adc_address=int(y['address'],16)
|
||||
abc_bus=1
|
||||
if "busnum" in y:
|
||||
adc_bus=y['busnum']
|
||||
|
@ -176,17 +177,15 @@ if "ads1x15" in log_conf:
|
|||
print("could not assign ADC")
|
||||
if adc_assigned:
|
||||
for j in range(4):
|
||||
channel_names.append["a"+str(adc_count)+"_"+str(j)]
|
||||
adc_count=adc_count+1
|
||||
channel_names.append("a"+str(adc_count)+"_"+str(j))
|
||||
adc_count=adc_count+1
|
||||
else:
|
||||
badc=False
|
||||
|
||||
|
||||
|
||||
|
||||
ch_val=np.zeros(len(channel_names))
|
||||
for i in range(len(channel_names)):
|
||||
ch_val[i]=(-1)
|
||||
ch_old=ch_val
|
||||
|
||||
while a > 1:
|
||||
# copy channel values to backup
|
||||
|
@ -204,10 +203,10 @@ while a > 1:
|
|||
|
||||
# read adc's
|
||||
if badc:
|
||||
for i in badc:
|
||||
cname="a"+i+"_{0}"
|
||||
for i in adc:
|
||||
cname="a"+str(i)+"_{0}"
|
||||
for j in range(4):
|
||||
ch_val[channel.names.index(cname.format(j))]=adc[j].read_adc(j,gain=GAIN)
|
||||
ch_val[channel_names.index(cname.format(j))]=adc[i].read_adc(j,gain=GAIN)
|
||||
|
||||
if btristar:
|
||||
try:
|
||||
|
@ -215,25 +214,29 @@ while a > 1:
|
|||
except:
|
||||
print("could not get data from tristar")
|
||||
else:
|
||||
ch_val[channel_names.index("volt_scale")]=rr.registers[0]*65536+rr.registers[1]
|
||||
ch_val[channel_names.index("amp_scale")]= rr.registers[2]*65536+rr.registers[3]
|
||||
ch_val[channel_names.index("volt_bat_term")]=rr.registers[25]
|
||||
ch_val[channel_names.index("volt_bat_sens")]=rr.registers[26]
|
||||
ch_val[channel_names.index("volt_arr")]=rr.registers[27] # Array voltage
|
||||
ch_val[channel_names.index("amp_bat")]=rr.registers[28] # Battery current
|
||||
ch_val[channel_names.index("amp_arr")]=rr.registers[29] # Array current
|
||||
ch_val[channel_names.index("temp_heatsink")]=rr.registers[35] # Temperature heatsink
|
||||
ch_val[channel_names.index("temp_bat")]=rr.registers[36] # Temperature battery
|
||||
ch_val[channel_names.index("ah_res")]=rr.registers[52] * 65536 + rr.registers[53] # Ah resetable
|
||||
ch_val[channel_names.index("ah_tot")]=rr.registers[54] * 65536 + rr.registers[55] # Ah total
|
||||
ch_val[channel_names.index("kwh_res")]=rr.registers[56] # kwh resetable
|
||||
ch_val[channel_names.index("kwh_tot")]=rr.registers[57] # kwh total
|
||||
ch_val[channel_names.index("watt_in")]=rr.registers[58] # Power in
|
||||
ch_val[channel_names.index("watt_out")]=rr.registers[59] # Power out
|
||||
ch_val[channel_names.index("hour_tot")]=rr.registers[42] * 65536 + rr.registers[43] # hour total
|
||||
ch_val[channel_names.index("state")]=rr.registers[50] # State
|
||||
ch_val[channel_names.index("volt_sweep_mp")]=rr.registers[61] # Array voltage
|
||||
ch_val[channel_names.index("volt_sweep_oc")]=rr.registers[62] # Array voltage
|
||||
try:
|
||||
ch_val[channel_names.index("volt_scale")]=rr.registers[0]*65536+rr.registers[1]
|
||||
except:
|
||||
print("could not read from tristar")
|
||||
else:
|
||||
ch_val[channel_names.index("amp_scale")]= rr.registers[2]*65536+rr.registers[3]
|
||||
ch_val[channel_names.index("volt_bat_term")]=rr.registers[25]
|
||||
ch_val[channel_names.index("volt_bat_sens")]=rr.registers[26]
|
||||
ch_val[channel_names.index("volt_arr")]=rr.registers[27] # Array voltage
|
||||
ch_val[channel_names.index("amp_bat")]=rr.registers[28] # Battery current
|
||||
ch_val[channel_names.index("amp_arr")]=rr.registers[29] # Array current
|
||||
ch_val[channel_names.index("temp_heatsink")]=rr.registers[35] # Temperature heatsink
|
||||
ch_val[channel_names.index("temp_bat")]=rr.registers[36] # Temperature battery
|
||||
ch_val[channel_names.index("ah_res")]=rr.registers[52] * 65536 + rr.registers[53] # Ah resetable
|
||||
ch_val[channel_names.index("ah_tot")]=rr.registers[54] * 65536 + rr.registers[55] # Ah total
|
||||
ch_val[channel_names.index("kwh_res")]=rr.registers[56] # kwh resetable
|
||||
ch_val[channel_names.index("kwh_tot")]=rr.registers[57] # kwh total
|
||||
ch_val[channel_names.index("watt_in")]=rr.registers[58] # Power in
|
||||
ch_val[channel_names.index("watt_out")]=rr.registers[59] # Power out
|
||||
ch_val[channel_names.index("hour_tot")]=rr.registers[42] * 65536 + rr.registers[43] # hour total
|
||||
ch_val[channel_names.index("state")]=rr.registers[50] # State
|
||||
ch_val[channel_names.index("volt_sweep_mp")]=rr.registers[61] # Array voltage
|
||||
ch_val[channel_names.index("volt_sweep_oc")]=rr.registers[62] # Array voltage
|
||||
|
||||
# read bme280 (temperature, humidity, pressure)
|
||||
if bbme:
|
||||
|
|
Loading…
Reference in New Issue