Hi,
I have tried as many MQTT examples as I can find and always hit the same brick wall.
I can get connected and I can publish messages which at least proves fundamentally I have a working system.
My problem is in the Arduino code to unpack the message data from a subscribed topic.
I have not uploaded code because what I am hoping is a pointer to a couple of known good examples which I can work with.
My experience has been...
if my topic receives a single numerical digit (0 through 9) I am fine but as soon as I try and unpack a 23 for example, the example I was following doesn't work. Although I can see that the code is meant to loop through the received numbers and stitch it back together to be a 23.
if my topic receives a string of characters I have great difficulty looping through the received characters and putting it back together. So a simple on or off would be a struggle.
So my question really is, who has found a great robust example for reference or which of the Arduino functions do you recommend I try to use that will provide a reliable and robust solution?
Thanks in advance
Richard
Jackson,
Thanks for your reply and I should have added a little more context.
Yes I am using the pubsubclient addin as part of the examples I have found.
The void callback is also in the examples I have tried. I have seen a few versions which seem to use different code examples to loop through the received characters/digits and re-assemble them back into a variable.
I'm confident the data is landing in the specified subscribed topic but it seems to be the 2 or 3 lines trying to put the characters/digits back together which trip me up.
Unfortunately I am not a great programmer and I can't figure out the issue.
When sending digits maybe they are interpreted as characters, I really don't know but 0 through 9 works okay.
To be honest, I will make the message content match a working example. I can publish what I want it has just been that no matter what I publish I seem to be struggling matching it back in a loop to an action.
I'm also not sending a lot or often so it can be a little crude, it just needs to be robust in the outcome.
Thanks again.
Richard