Issue publishing via mqtt
hansamann last edited by
I seem to narrow down the issues I have with the mqtt lib that I found here;
I am now able to connect and also publish messages, currently to adafruit io every two seconds. The problem with the subscription remains, I would hope someone has a clue.
My current subscribe method looks liek this
def subscribe(self, topic, qos=0): assert self.cb is not None, "Subscribe callback is not set" pkt = bytearray(b"\x82\0\0\0") self.pid += 1 struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid) #print(hex(len(pkt)), hexlify(pkt, ":")) self.sock.write(pkt) self._send_str(topic) self.sock.write(qos.to_bytes(1, sys.byteorder)) while 1: op = self.wait_msg() if op == 0x90: resp = self.sock.read(4) #print(resp) assert resp == pkt and resp == pkt if resp == 0x80: raise MQTTException(resp) return
I had to import sys and change the line
I otherwise cannot call the qos.to_bytes method as it expects the byteorder on the micropython lopy that I have. Unfortunately I cannot see messages that I send to the topic - I've verified that messages are sent using another mqtt client that subscribed.
Can anyone help? What is the correct code for subscribing?