I have a photodiode connected to an ADS1015 A/D converter (many thanks to Roberthh for his modifications to the driver) and everything is working fine on the converter side. Basically I am measuring the time between pulses and writing the resulting delay in microseconds to an InfluxDB database. All subsequent calculations are done with a database query, eliminating lengthy calculations in code.
This works fine for 1-3 hours and then I get the dreaded ECONNABORTED (103) error.
I am pretty new to this and would appreciate comments on how to eliminate the error which I suspect has something to do with urequests.
I am simulating a load of 3.6kW with a Pyboard using the red LED which is flashing about 4 times a second.
Code: Select all
from machine import I2C, Pin, Timer, idle, disable_irq, enable_irq
from ads1x15 import ADS1015
import urequests
import utime
import gc
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
adc = ADS1015(i2c, 72, 3)
adc.alert_start(4, 0, threshold_high=500,threshold_low=498,latched=False)
server='http://192.168.1.2:8086/write?db=energy'
data = 'useconds value='
now_ms = utime.ticks_us()
last_ms = utime.ticks_us()
diff=0
pulsed=False
alert = Pin(12, Pin.IN)
def pulse(p):
global now_ms, last_ms, diff, pulsed
state = disable_irq()
pulsed=True
last_ms = now_ms
now_ms = utime.ticks_us()
diff = utime.ticks_diff(now_ms, last_ms)
enable_irq(state)
alert.irq(trigger=Pin.IRQ_FALLING, handler=pulse, hard = True)
while True:
try:
if pulsed:
ms = str(diff)
send_data=data+ms
resp = urequests.post(server, data=send_data)
resp.close()
pulsed = False
gc.collect()
gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
idle()
except Exception as err:
print("Exception", err)