ESP8266 i get command but payload is empty

Thanks fro prompt reply… Verified the the library used is the latest (6/25). Using the esp8266 example in the package. Enabled the three lines to acquire the payload. Send command “toggle” with payload {“temperature”: 75} and {“temperature”: “75”}… In the serial monitor I get “0” for the temperature. If I do the mods to convert the payload to text I get the entire payload as a text.?
Using json 1.6.
Thanks

@Nicolas_Assouad,

Would you be able to confirm that you are using ArduinoJson v6 as the Losant MQTT Library does depend on this package.

Would you be able to share a screenshot of Workflow or Input Control Block in Losant that is sending the device command? Would you be able to share a code snippet from your code where you are handling the incoming command?

Thank you,
Heath

Hello,

ArduinoJsonversion is 6.17.1

Code used:

void handleCommand(LosantCommand *command) {
  Serial.print("Command received: ");
  Serial.println(command->name);
  
  Serial.print("time: ");
  Serial.println(command->time);
  //Serial.print("payload: ");
  //Serial.println(command->payload);
  // Optional command payload. May not be present on all commands.
  JsonObject& payload = *command->payload;
  // Perform action specific to the command received.
  if(strcmp(command->name, "toggle") == 0) {
      toggle();
    /**
    * In Losant, including a payload along with your
    * command is optional. This is an example of how
    * to parse a JSON payload from Losant and print
    * the value of a key called "temperature".
    */
     int temperature = payload["temperature"];
     Serial.println(temperature);
  }
}

Losant Commad:
Received Payload

  • :arrow_forward:

(root){} 3 keys

  • “name”:“toggle”
  • “payload”:"[temperature": “75”]"
  • “time”:“2020-11-09T18:33:32.736Z”

Serial Monitor:
First case was serial mode where the payload is a text
Second case in Json mode
image

By the way the “command->time” is always NULL!!! in both cases (json or serial mode)

Thanks

Hey @Nicolas_Assouad,

I took a look at your code, and even looked at it side by side to our example code for the ESP8266.

One issue I can see is in your line:

JsonObject& payload = *command->payload;

Our example code shows:

JsonObject payload = *command->payload;

Further, I’d like to make sure that in your void setup() function, you are subscribing to the device command with:

// Register the command handler to be called when a command is received
// from the Losant platform.
device.onCommand(&handleCommand);

Please let me know if this helps in any way.

Thank you,
Heath

Hello,
Nogo…
Verified that device.onCommand(&handleCommand); is in the setup()… Otherwise no command will be handled…

Changed JsonObject& payload = *command->payload; to JsonObject payload = *command->payload;

CODE

void handleCommand(LosantCommand *command) {
  Serial.print("Command received: ");
  Serial.println(command->name);
  
  Serial.print("time: ");
  Serial.println(command->time);
  //Serial.print("payload: ");
  //Serial.println(command->payload);
  // Optional command payload. May not be present on all commands.
  JsonObject payload = *command->payload;
  // Perform action specific to the command received.
  if(strcmp(command->name, "toggle") == 0) {
      toggle();
    /**
    * In Losant, including a payload along with your
    * command is optional. This is an example of how
    * to parse a JSON payload from Losant and print
    * the value of a key called "temperature".
    */
     int temperature = payload["temperature"];
     Serial.println(temperature);
}

LOSANT LOG:

User Nicolas Assouad sent command toggle to Device [Lights Gateway]
Tue Nov 10, 2020 13:56:39.279 GMT-07:00

Received Payload

  • :arrow_forward:

(root){} 3 keys

  • “name”:“toggle”
  • “payload”:“76”
  • “time”:“2020-11-10T20:56:39.275Z”

Received in Serial Monitor:

image

Thanks

@Nicolas_Assouad,

Could you give me more information about how you’re sending the command in the Losant platform? Are you using an Input Control Block in a dashboard? Or with the Device Command Output Node?

Would you be able to share a screenshot of your configuration on the Losant side for how you’re sending this device command?

Thank you,
Heath

Hello,

Commands are sent using the “device actions” drop box and selecting: "Send Command "

Then Using the popup to fill the command and payload

Device Attributes:

The application used in this case is a stepper motor control…

Thanks

Hey @Nicolas_Assouad,

Thank you so much for bearing with me and testing all of this! I think we’re getting close to an answer!

When you send a device command via a workflow, instead of from the Device Actions Menu, do you get the same issue? You can make a simple workflow of just a Virtual Button and a Device Command Output Node just like below:

Please let me know what you find!

Thank you,
Heath

Thanks for your patience… Need to get familiarized with workflow.
Will try when at ease with it…

Works great under Workflow!!!
Fails under “Send command” with the same payload format as used in the workflow: {
“temperature”: 100}…
Thanks

Hello,
in workflow there are 3 options for the payload: String, Jason and… I suspect that in device “send command” the payload is defaulting to String mode instead of Jason…
Thanks