Hi
I need help finding what the issue could be with my MQTT publish.single function below;
import serial
import csv
import time
import json
import paho.mqtt.publish as publish
ser = serial.Serial('/dev/serial0', 9600, timeout=1)
def read_data():
data_in = ser.readline()
data = list(data_in)
distance = (570-(data[1]*256 + data[2]))/10
volume = round(28 * distance,0)
read_data.reading = {'volume':volume}
def mqttpublish(hostname,topic,payload,qos=0):
try:
publish.single("water/tank", payload=json.dumps(read_data.reading), qos=qos, hostname="10.0.0.3", auth={'username':"utility", 'password':"pass"})
except Exception as e:
print("Publish Failed because: %s"%e)
read_data()
mqttpublish()
It throws the error: 'Client' object has no attribute '_on_pre_connect'