def senddata(file_name, url, sdata, headers, data, vers): try: if internet_on(): sentsavedata(file_name, temp_file="temp.csv", url=url, vers=vers) gpio.output(led1, 1) time.sleep(0.1) print("near r") print(data) if not GSM: r = requests.post(url, data=json.dumps(data), headers=headers, timeout=2) else: r = gsm.requests.post(url=url, data=json.dump(data)) print(r) print(r.content) except: print('no net') writecsv(file_name, sdata) gpio.output(led1, 0) time.sleep(0.1)
"tr_grid_voltage": registers.get(3016)[5]["value"], "grid_power": grid_power, "radiator_temperature": registers.get(3025)[5]["value"], "module_temperature": registers.get(3026)[5]["value"], "total_energy": total_energy_1, "alarm_code": registers.get(3036)[5]["value"], "annual_energy": annual_energy, "daily_energy": registers.get(3042)[5]["value"], "apparent_power": apparent_power, "reactive_power": reactive_power, "power_factor": registers.get(3056)[5]["value"], "recorded_at": timesend } headers = {'Content-type': 'application/json'} try: sentsavedata(file_name) # r = requests.post(url, data=json.dumps(data), headers=headers) print("send") except: print('no net') with open(file_name, mode='a') as csv_file: fieldnames = [ 'mac', 'pv1_voltage', 'pv2_voltage', 'pv3_voltage', 'pv1_current', 'pv2_current', 'pv3_current', 'pv1_power', 'pv2_power', 'pv3_power', 'rs_grid_voltage', 'st_grid_voltage', 'tr_grid_voltage', 'grid_power', 'radiator_temperature', 'module_temperature', 'total_energy', 'alarm_code', 'annual_energy', 'daily_energy', 'apparent_power', 'reactive_power',