Arduino C++ programm locks up after sending "on" but not "off" -


i have piece of code sending mqtt message.

the message same change being changing action between 'on' , 'off'. can end off many times like, when send 'on' locks (even if first message)

here code

void update_thing(int pin, string thing, string action) {      serial.println(thing + " state requested " + action);   serial.println(action.c_str());     if (action == "on") {       digitalwrite(pin, high);                    // pin  = 5 v, led turns on     } else {       digitalwrite(pin, low);                     // pin  = 5 v, led turns off          }    // generate new message    sprintf(msg, "{\"state\":{\"reported\":{\"%s\": \"%s\"}}}", thing.c_str(), action.c_str());   if((rc = myclient.publish("$aws/things/myyunlight/shadow/update", msg, strlen(msg), 1, false)) != 0) {     serial.println("publish failed!");     serial.println(rc);   } } 

the issue appears lie in msg variable, declared

char msg[100]; // read-write buffer 

and in particular value fed action (or if remove , use text 'on' or 'off'. if use 'on ' (with space) works fine


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -