move import of specific libraries to initialization, so it is not needed, when sensor is turned off
parent
cc5d67ffaa
commit
65b1a5ab82
155
logger.py
155
logger.py
|
@ -1,13 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import numpy as np
|
||||
import os, serial,time,socket,sys,json,logging,requests
|
||||
import smbus2,bme280,getopt
|
||||
import os, serial,time,socket,sys,json,logging,requests,getopt
|
||||
# import the server implementation
|
||||
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
|
||||
# import ADC
|
||||
from Adafruit_ADS1x15 import ADS1115
|
||||
from Adafruit_ADS1x15 import ADS1015
|
||||
import vedirect
|
||||
|
||||
def upload_osm(sensor_id,value):
|
||||
|
@ -68,23 +64,25 @@ if "bme280" in log_conf:
|
|||
if "enable" in log_conf['bme280']:
|
||||
if log_conf['bme280']['enable'] == 0:
|
||||
bbme=False
|
||||
if "port" in log_conf['bme280']:
|
||||
bme_port=log_conf['bme280']['port']
|
||||
else:
|
||||
bme_port=1
|
||||
if "address" in log_conf['bme280']:
|
||||
bme_add=int(log_conf['bme280']['address'],16)
|
||||
else:
|
||||
bme_add=0x77
|
||||
try:
|
||||
bme_bus=smbus2.SMBus(bme_port)
|
||||
except:
|
||||
bbme=False
|
||||
else:
|
||||
calibration_params=bme280.load_calibration_params(bme_bus,bme_add)
|
||||
channel_names.append("temperature")
|
||||
channel_names.append("humidity")
|
||||
channel_names.append("pressure")
|
||||
if bbme:
|
||||
import bme280
|
||||
if "port" in log_conf['bme280']:
|
||||
bme_port=log_conf['bme280']['port']
|
||||
else:
|
||||
bme_port=1
|
||||
if "address" in log_conf['bme280']:
|
||||
bme_add=int(log_conf['bme280']['address'],16)
|
||||
else:
|
||||
bme_add=0x77
|
||||
try:
|
||||
bme_bus=smbus2.SMBus(bme_port)
|
||||
except:
|
||||
bbme=False
|
||||
else:
|
||||
calibration_params=bme280.load_calibration_params(bme_bus,bme_add)
|
||||
channel_names.append("temperature")
|
||||
channel_names.append("humidity")
|
||||
channel_names.append("pressure")
|
||||
|
||||
|
||||
# configure the client logging
|
||||
|
@ -99,23 +97,26 @@ 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']
|
||||
tri_baud=9600
|
||||
if "baud" in log_conf['tristar']:
|
||||
tri_baud=log_conf['tristar']['baud']
|
||||
tri_timeout=1
|
||||
if "timeout" in log_conf['tristar']:
|
||||
tri_timeout=log_conf['tristar']['timeout']
|
||||
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)
|
||||
if btristar:
|
||||
import smbus
|
||||
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
|
||||
tri_port='/dev/ttyUSB0'
|
||||
if "port" in log_conf['tristar']:
|
||||
tri_port=log_conf['tristar']['port']
|
||||
tri_baud=9600
|
||||
if "baud" in log_conf['tristar']:
|
||||
tri_baud=log_conf['tristar']['baud']
|
||||
tri_timeout=1
|
||||
if "timeout" in log_conf['tristar']:
|
||||
tri_timeout=log_conf['tristar']['timeout']
|
||||
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)
|
||||
|
||||
# declare ve mppt
|
||||
bve=False
|
||||
|
@ -140,47 +141,49 @@ if "vedirect" in log_conf:
|
|||
badc=False
|
||||
if "ads1x15" in log_conf:
|
||||
badc=True
|
||||
adc={}
|
||||
if "enable" in log_conf['ads1x15']:
|
||||
if log_conf['ads1x15']['enable'] == 0:
|
||||
badc=False
|
||||
if "gain" in log_conf['ads1x15']:
|
||||
GAIN=log_conf['ads1x15']['gain']
|
||||
else:
|
||||
if badc:
|
||||
adc={}
|
||||
GAIN=1
|
||||
if "adc" in log_conf['ads1x15']:
|
||||
adc_count=0
|
||||
tadc=log_conf['ads1x15']['adc']
|
||||
for x in tadc:
|
||||
y=tadc[x]
|
||||
adc_address=0x48
|
||||
if "address" in y:
|
||||
adc_address=int(y['address'],16)
|
||||
abc_bus=1
|
||||
if "busnum" in y:
|
||||
adc_bus=y['busnum']
|
||||
adc_type=1015
|
||||
if "type" in y:
|
||||
adc_type=y['type']
|
||||
adc_assigned=False
|
||||
if adc_type == 1115:
|
||||
try:
|
||||
adc[adc_count]=ADS1115(address=adc_address,busnum=adc_bus)
|
||||
adc_assigned=True
|
||||
except:
|
||||
print("could not assign ADC")
|
||||
if adc_type == 1015:
|
||||
try:
|
||||
adc[adc_count]=ADS1015(address=adc_address,busnum=adc_bus)
|
||||
adc_assigned=True
|
||||
except:
|
||||
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
|
||||
else:
|
||||
badc=False
|
||||
if "gain" in log_conf['ads1x15']:
|
||||
GAIN=log_conf['ads1x15']['gain']
|
||||
if "adc" in log_conf['ads1x15']:
|
||||
from Adafruit_ADS1x15 import ADS1115
|
||||
from Adafruit_ADS1x15 import ADS1015
|
||||
adc_count=0
|
||||
tadc=log_conf['ads1x15']['adc']
|
||||
for x in tadc:
|
||||
y=tadc[x]
|
||||
adc_address=0x48
|
||||
if "address" in y:
|
||||
adc_address=int(y['address'],16)
|
||||
abc_bus=1
|
||||
if "busnum" in y:
|
||||
adc_bus=y['busnum']
|
||||
adc_type=1015
|
||||
if "type" in y:
|
||||
adc_type=y['type']
|
||||
adc_assigned=False
|
||||
if adc_type == 1115:
|
||||
try:
|
||||
adc[adc_count]=ADS1115(address=adc_address,busnum=adc_bus)
|
||||
adc_assigned=True
|
||||
except:
|
||||
print("could not assign ADC")
|
||||
if adc_type == 1015:
|
||||
try:
|
||||
adc[adc_count]=ADS1015(address=adc_address,busnum=adc_bus)
|
||||
adc_assigned=True
|
||||
except:
|
||||
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
|
||||
else:
|
||||
badc=False
|
||||
|
||||
|
||||
ch_val=np.zeros(len(channel_names))
|
||||
|
|
Loading…
Reference in New Issue