61 lines
2.6 KiB
Python
61 lines
2.6 KiB
Python
import redis
|
|
import time
|
|
import requests
|
|
|
|
r = redis.Redis(host='localhost', port=6379, db=1, decode_responses=True)
|
|
|
|
def send_data(results):
|
|
output = requests.post('http://192.168.1.221:8086/write?db=garagedb', data = results, timeout=30)
|
|
print(output)
|
|
|
|
|
|
def get_data():
|
|
batt_v_V = int(r.get('batt_v')) / 1000
|
|
main_current = r.get('main_current')
|
|
panel_voltage = int(r.get('panel_voltage')) / 1000
|
|
panel_power = r.get('panel_power')
|
|
load_current = int(r.get('load_current')) / 1000
|
|
yield_today = int(r.get('yield_today')) / 100
|
|
max_power_today = r.get('max_power_today')
|
|
load_power = load_current * batt_v_V
|
|
energy_production_today = int(r.get('energy_production_today'))
|
|
energy_production_tomorrow = int(r.get('energy_production_tomorrow'))
|
|
|
|
return batt_v_V, main_current, panel_voltage, panel_power, load_current, yield_today, max_power_today, load_power, energy_production_today, energy_production_tomorrow
|
|
|
|
|
|
batt_v_V, main_current, panel_voltage, panel_power, load_current, yield_today, max_power_today, load_power, energy_production_today, energy_production_tomorrow = get_data()
|
|
|
|
print(batt_v_V)
|
|
print(main_current)
|
|
print(panel_voltage)
|
|
print(panel_power)
|
|
print(load_current)
|
|
print(yield_today)
|
|
print(max_power_today)
|
|
print(load_power)
|
|
|
|
while True:
|
|
batt_v_V, main_current, panel_voltage, panel_power, load_current, yield_today, max_power_today, load_power, energy_production_today, energy_production_tomorrow = get_data()
|
|
print('batt_v {}'.format(batt_v_V))
|
|
print('current {}'.format(main_current))
|
|
print('panel v {}'.format(panel_voltage))
|
|
print('panel p {}'.format(panel_power))
|
|
print('load a {}'.format(load_current))
|
|
print('yield {}'.format(yield_today))
|
|
print('max p today {}'.format(max_power_today))
|
|
print('load p {}'.format(load_power))
|
|
|
|
send_data('battery_v,host=solar_sys value={}'.format(batt_v_V))
|
|
send_data('panel_v,host=solar_sys value={}'.format(panel_voltage))
|
|
send_data('battery_c,host=solar_sys value={}'.format(main_current))
|
|
send_data('load_c,host=solar_sys value={}'.format(load_current))
|
|
send_data('panel_p,host=solar_sys value={}'.format(panel_power))
|
|
send_data('load_p,host=solar_sys value={}'.format(load_power))
|
|
send_data('yield_today,host=solar_sys value={}'.format(yield_today))
|
|
send_data('max_power_today,host=solar_sys value={}'.format(max_power_today))
|
|
send_data('energy_production_today,host=solar_sys value={}'.format(energy_production_today))
|
|
send_data('energy_production_tomorrow,host=solar_sys value={}'.format(energy_production_tomorrow))
|
|
|
|
time.sleep(60)
|