Commit b2998462 authored by ryan.whiteley's avatar ryan.whiteley

sensors back working

parent 98ea4574
......@@ -11,9 +11,11 @@ ts_write_key = ''
mqtt_soil_server = "192.168.0.25"
mqtt_soil_path_one = "soil_one"
mqtt_soil_path_two = "soil_two"
dry_reading = 80
wet reading = 200
#sensor calibration, Garrus would be proud
one_dry_reading = 202
one_wet_reading = 80
two_dry_reading = 224
two_wet_reading = 89
#setup for the ADC module
def adc_setup():
......@@ -26,21 +28,31 @@ def adc_setup():
exit(-1)
#main driver for measurments and MQTT
def main_loop(channel):
def main_loop():#insert channel variable when setting up thingspeak
try:
#get sensor reading and percentage conversions
soil_one = adc.analogRead(0)
soil_one_percent = ((soil_one - one_wet_reading) * 100)/(one_wet_reading - one_dry_reading)
soil_two = adc.analogRead(1)
soil_two_percent = ((soil_two - two_wet_reading) * 100)/(two_wet_reading - two_dry_reading)
soil_avg = (soil_one_percent + soil_two_percent) / 2
print(soil_one)
print(soil_two)
print('soil one: %d%%' % soil_one_percent)
print('soil two: %d%%' % soil_two_percent)
print('soil average: %d%%' % soil_avg)
#publish sensor info to MQTT server
publish.single(mqtt_soil_path_one, stuff, hostname= mqtt_soil_server)
#publish.single(mqtt_soil_path_one, stuff, hostname= mqtt_soil_server)
#print to the LCD display
except:
print('failed')
#LCD display code
def destroy_all():
......@@ -50,7 +62,10 @@ if __name__ == '__main__':
#thingspeak channel settings here
try:
adc_setup()
while True:
adc_setup()
main_loop()
time.sleep(10)
except KeyboardInterrupt:
destroy_all()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment