guild icon
Toit
#First off thank you to @floitsch for his in depth response about timing. now more help please.
Thread channel in help
Macca
Macca 04/07/2023 02:55 AM
Using the code below I get the error report, but if I comment out 'Debug Message:' so the debug message becomes part of report: it doesn't error.
Start code
transport := mqtt.TcpTransport net.open --host=HOST --port=PORT client := mqtt.FullClient --transport=transport options := mqtt.SessionOptions --client_id=CLIENT_ID unsubscribed_latch := monitor.Latch // ------------------------------------------------------------------ report: Temp /string := "" temperatures.do: Temp = it //client.publish "$TOPIC_PREFIX/temps" it.to_byte_array --qos=1 DS18B20_Ids.do:client.publish "$TOPIC_PREFIX/" + it Temp.to_byte_array --qos=1 // ------------------------------------------------------------------ Debug Message: client.publish "$TOPIC_PREFIX/Debug" Message.to_byte_array // ------------------------------------------------------------------ main: task:: MQTT Debug "Started"
Decoding by jag, device has version <2.0.0-alpha.69>
**

Class 'Null_' does not have any method 'pending_count'.
0: FullClient.publish.<block> <pkg:mqtt>/fullclient.toit:964:43
1: Signal.wait.<block> <sdk>/monitor.toit:153:17
2: Monitor.locked
.<block> <sdk>/core/monitorimpl.toit:123:12
3: Monitor.locked_ <sdk>/core/monitorimpl.toit:95:3
4: Signal.wait <sdk>/monitor.toit:152:3
5: FullClient.publish <pkg:mqtt>/full_client.toit:964:28
6: Debug HWS_Monitor.toit:48:10
7: main HWS_Monitor.toit:54:3
**
(edited)
floitsch
floitsch 04/07/2023 01:02 PM
It's hard to tell exactly what's going on.

Please use triple backticks to enclose your code, so it gets easier to read. See, https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51#code-blocks


My guess is, that the client isn't yet running.
When using the FullClient you need to call connect and handle. See an example here: https://github.com/toitware/mqtt/blob/main/examples/full_client.toit

When using the standard Client you only need to call start.
See an example here: https://github.com/toitware/mqtt/blob/main/examples/publish.toit

Generally the Client is easier to use, so I would recommend that one, unless you need more features.
Contribute to toitware/mqtt development by creating an account on GitHub.
Contribute to toitware/mqtt development by creating an account on GitHub.
A guide to Markdown on Discord. GitHub Gist: instantly share code, notes, and snippets.
Macca
Macca 04/08/2023 12:09 AM
@floitsch thank you once more your help is so appreciated. I will use triple backticks in future (I hadn't found that yet) and yes I will convert to using client instead of full client.
Macca
Macca 04/11/2023 12:30 AM
Using just MQTT client solved my problem Thank you.
👍1
4 messages in total