'Client' object has no attribute '_on_pre_connect'

221 views
Skip to first unread message

Juma

unread,
Jan 29, 2023, 2:03:49 PM1/29/23
to MQTT
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'

Matt Lloyd

unread,
Jan 30, 2023, 4:55:52 AM1/30/23
to mq...@googlegroups.com
--
To learn more about MQTT see https://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mqtt/2c2bd7c8-56d4-4d91-98e4-cd0e377c9896n%40googlegroups.com.

Juma

unread,
Jan 30, 2023, 2:52:00 PM1/30/23
to MQTT
Thanks,
Am a bit new to scripting, how do I use this?
Reply all
Reply to author
Forward
0 new messages