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

fixed mqtt issues

parent c457d435
......@@ -2,15 +2,19 @@ import thingspeak
import time
import paho.mqtt.publish as publish
from ADCDevice import *
from PCF8574 import PCF8574_GPIO
from Adafruit_LCD1602 import Adafruit_CharLCD
adc = ADCDevice()
ts_channel_id = 1564450
ts_write_key = 'JK4S0XWAC8YK9GDU'
#mqtt sever and channel path settings
mqtt_soil_server = "192.168.0.25"
mqtt_soil_path_one = "soil_one"
mqtt_soil_path_two = "soil_two"
mqtt_soil_path_avg = "soil_average"
#sensor calibration, Garrus would be proud
one_dry_reading = 202
one_wet_reading = 80
......@@ -36,6 +40,10 @@ def cpu_temp_finder():
#main driver for measurments and MQTT
def main_loop(channel):#insert channel variable when setting up thingspeak
#LCD initialisation goes here
mcp.output(3,1)
lcd.begin(16,2)
try:
#get sensor reading and percentage conversions
......@@ -57,21 +65,41 @@ def main_loop(channel):#insert channel variable when setting up thingspeak
print('soil two: %d%%' % soil_two_percent)
print('soil average: %d%%' % soil_avg)
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
test = 5
response = channel.update({'field1': soil_one_percent, 'field2': soil_two_percent, 'field3': soil_avg, 'field4': cpu_ts})
#print to the LCD display
#lcd.setCursor(0,0)
#lcd.message('Soil avg: ' + soil_avg)
#ldc.message('CPU Temp: ' + cpu_temp_finder())
except:
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():
adc.close()
lcd.clear()
if __name__ == '__main__':
#thingspeak channel settings here
......
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