Read MQTT message from subscribe topic using Sim 800 TCP/ Node-red

Hi,

I am trying to find a way to create an Arduino code to read incomming message from a subscribed topic.

The message us not just one character but a string with different settings which are stpred in RTCmemory (ESP 8266) for later use.

I’ve seen Ravi’s code in his Youtube episode about reading ONE chatacter from incomming MQTT message.

I tried several codes, like: Message = Serial.readString();

The string Message does contain the send message but starts with crap (some binairy I think) I can’t get rid of this firsty part. I tried trim, remove, etc

I also tried reading the Serial buffer character by character with Serial.read(); Also no luck.

Any example code would be nice.

Kind regards, Robert

Hi Robert,

First you need to collect all incoming serial data in a ring or circular buffer and then I guess you need to use strtok function for searching for a particular string in a buffer. There will be a few binary characters which are part of MQTT protocol, but you strtok should be able to find you the string desired.

Hi Ravi,

Thank you for your advice.

I did use a while loop with timelimit to collect/ wait for Serial inputs.

I will try strtok.

Kind regards Robert

1 Like