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

fixed mqtt issues

parent c457d435
...@@ -2,15 +2,19 @@ import thingspeak ...@@ -2,15 +2,19 @@ import thingspeak
import time import time
import paho.mqtt.publish as publish import paho.mqtt.publish as publish
from ADCDevice import * from ADCDevice import *
from PCF8574 import PCF8574_GPIO
from Adafruit_LCD1602 import Adafruit_CharLCD
adc = ADCDevice() adc = ADCDevice()
ts_channel_id = 1564450 ts_channel_id = 1564450
ts_write_key = 'JK4S0XWAC8YK9GDU' ts_write_key = 'JK4S0XWAC8YK9GDU'
#mqtt sever and channel path settings
mqtt_soil_server = "192.168.0.25" mqtt_soil_server = "192.168.0.25"
mqtt_soil_path_one = "soil_one" mqtt_soil_path_one = "soil_one"
mqtt_soil_path_two = "soil_two" mqtt_soil_path_two = "soil_two"
mqtt_soil_path_avg = "soil_average"
#sensor calibration, Garrus would be proud #sensor calibration, Garrus would be proud
one_dry_reading = 202 one_dry_reading = 202
one_wet_reading = 80 one_wet_reading = 80
...@@ -36,6 +40,10 @@ def cpu_temp_finder(): ...@@ -36,6 +40,10 @@ def cpu_temp_finder():
#main driver for measurments and MQTT #main driver for measurments and MQTT
def main_loop(channel):#insert channel variable when setting up thingspeak def main_loop(channel):#insert channel variable when setting up thingspeak
#LCD initialisation goes here #LCD initialisation goes here
mcp.output(3,1)
lcd.begin(16,2)
try: try:
#get sensor reading and percentage conversions #get sensor reading and percentage conversions
...@@ -57,22 +65,42 @@ def main_loop(channel):#insert channel variable when setting up thingspeak ...@@ -57,22 +65,42 @@ def main_loop(channel):#insert channel variable when setting up thingspeak
print('soil two: %d%%' % soil_two_percent) print('soil two: %d%%' % soil_two_percent)
print('soil average: %d%%' % soil_avg) print('soil average: %d%%' % soil_avg)
print('CPU temp @: ', cpu_ts) print('CPU temp @: ', cpu_ts)
#publish sensor info to MQTT server
#publish.single(mqtt_soil_path_one, stuff, hostname= mqtt_soil_server)
#publish sensor info to MQTT server
publish.single(mqtt_soil_path_one, soil_one_percent, hostname= mqtt_soil_server)
publish.single(mqtt_soil_path_two, soil_two_percent, hostname= mqtt_soil_server)
publish.single(mqtt_soil_path_avg, soil_avg, hostname= mqtt_soil_server)
#send to thingspeak #send to thingspeak
test = 5 test = 5
response = channel.update({'field1': soil_one_percent, 'field2': soil_two_percent, 'field3': soil_avg, 'field4': cpu_ts}) response = channel.update({'field1': soil_one_percent, 'field2': soil_two_percent, 'field3': soil_avg, 'field4': cpu_ts})
#print to the LCD display #print to the LCD display
#lcd.setCursor(0,0)
#lcd.message('Soil avg: ' + soil_avg)
#ldc.message('CPU Temp: ' + cpu_temp_finder())
except: except:
print('failed') print('failed')
#LCD display code
#LCD display code from freenove kit for lcd screen functionality
pcf_address = 0x27
pcfA_adress = 0x3F
try:
mcp = PCF8574_GPIO(pcf_address)
except:
try:
mcp = PCF8574_GPIO(pcfA_adress)
except:
print('failed to find I2C address')
exit(1)
lcd = Adafruit_CharLCD(pin_rs = 0, pin_e = 2, pins_db = [4,5,6,7], GPIO = mcp)
def destroy_all(): def destroy_all():
adc.close() adc.close()
lcd.clear()
if __name__ == '__main__': if __name__ == '__main__':
#thingspeak channel settings here #thingspeak channel settings here
channel = thingspeak.Channel(id = ts_channel_id, api_key = ts_write_key) channel = thingspeak.Channel(id = ts_channel_id, api_key = ts_write_key)
......
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