Commit 5e6b743f authored by ryan.whiteley's avatar ryan.whiteley

Thinkspeak updates now back working

parent b2998462
......@@ -5,8 +5,8 @@ from ADCDevice import *
adc = ADCDevice()
ts_channel_id = 1234
ts_write_key = ''
ts_channel_id = 1564450
ts_write_key = 'JK4S0XWAC8YK9GDU'
mqtt_soil_server = "192.168.0.25"
mqtt_soil_path_one = "soil_one"
......@@ -28,15 +28,15 @@ def adc_setup():
exit(-1)
#main driver for measurments and MQTT
def main_loop():#insert channel variable when setting up thingspeak
def main_loop(channel):#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_one_percent = ((soil_one - one_dry_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_two_percent = ((soil_two - two_dry_reading) * 100)/(two_wet_reading - two_dry_reading)
soil_avg = (soil_one_percent + soil_two_percent) / 2
print(soil_one)
......@@ -50,6 +50,10 @@ def main_loop():#insert channel variable when setting up thingspeak
#publish.single(mqtt_soil_path_one, stuff, hostname= mqtt_soil_server)
#send to thingspeak
test = 5
response = channel.update({'field1': soil_one_percent, 'field2': soil_two_percent, 'field3': soil_avg, 'field4': test})
#print to the LCD display
except:
print('failed')
......@@ -60,12 +64,12 @@ def destroy_all():
if __name__ == '__main__':
#thingspeak channel settings here
channel = thingspeak.Channel(id = ts_channel_id, api_key = ts_write_key)
try:
while True:
adc_setup()
main_loop()
time.sleep(10)
main_loop(channel)
time.sleep(15)
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