Log in to unlock Raspberry Pi 5 for $60 (was $80) with $100+ in eligible purchases.
import machine
import urequests
import time
rtc = machine.RTC() # Clock for deepsleep
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
adc = machine.ADC(0) # Pin to Read sensor voltage
######################
# Sensor calibration #
######################
# values on right are inverse * 1000 values on left
# dry air = 759 (0%) = 1.31752305665349143610013175231
# water = 382 (100%) = 2.61780104712041884816753926702
# The Difference = 1.30027799046692741206740751471
# 1 % = 0.0130027799046692741206740751471
hours = str(time.localtime()[3])
mins = str(time.localtime()[4])
secs = str(time.localtime()[5])
if int(secs) < 10:
secs = '0' + secs
if int(mins) < 10:
mins = '0' + mins
timestr = hours + ':' + mins + ':' + secs
variable = (((1 / adc.read())* 1000) / 0.0130027799046692741206740751471) - 101
if variable > 100:
variable = 100
if variable < 0:
variable = 0
url = 'http://192.168.1.2:8000/solomon'
headers = {'content-type': 'application/json'}
data = '{"Value": "%s", "Time": "%s"}' % (variable, timestr)
resp = urequests.post(url, data=data, headers=headers) # Send the request
print(resp.json())
rtc.alarm(rtc.ALARM0, 25000) # Set alarm for 25 seconds
machine.deepsleep() # Go to sleep ...