# Unable to extract payload of type string shipped to Arduino via Device Command

**URL:** <https://forums.losant.com/t/unable-to-extract-payload-of-type-string-shipped-to-arduino-via-device-command/731>\
**Category:** Help\
**Created:** [January 12, 2018, 7:15pm UTC](https://forums.losant.com/t/unable-to-extract-payload-of-type-string-shipped-to-arduino-via-device-command/731 "2018-01-12T19:15:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjay\_Bhatikar](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sanjay_bhatikar/32/314_2.png) [@Sanjay\_Bhatikar](https://forums.losant.com/u/Sanjay_Bhatikar)\
**Post date:** [January 12, 2018, 7:15pm UTC](https://forums.losant.com/t/unable-to-extract-payload-of-type-string-shipped-to-arduino-via-device-command/731/1 "2018-01-12T19:15:17Z")

</div>

I am sending a string as payload with device command from Losant to nodemcu. Serial monitor shows nothing.

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/8eaa64cbc6c5e9d779250c74943972acb62d0f4f.png)

Where it shows curly braces, it should be displaying a string (“Just about anything!”).

I have verified the following:

1. The device is connected
2. It receives the command
3. The device log shows message sent with the string.

Code compiles but doesn’t work as intended.

```
// Called whenever the device receives a command from the Losant platform.
void handleCommand(LosantCommand *command) {
  Serial.print("Command received: ");
  Serial.println(command->name);
  
  if(strcmp(command->name, "toggle") == 0) {
    toggle();
  }

  // TRY 1: Print payload using printTo
  JsonObject& payload = *command->payload;
  Serial.println("Received payload: ");
  payload.printTo(Serial); // Gives {}
  Serial.println();

  // TRY 2: Serialize payload and print
  char json[200];  
  StaticJsonBuffer<200> jsonBuffer;
  payload.printTo(json, sizeof(json));
  Serial.print(json); // Gives {}

}

```

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/9b1722a1b1b6e7e9b2d12625b801d0fa8f9d28ec.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [January 17, 2018, 12:16am UTC](https://forums.losant.com/t/unable-to-extract-payload-of-type-string-shipped-to-arduino-via-device-command/731/2 "2018-01-17T00:16:37Z")

</div>

Apologies for the confusion here. Our Arduino client is expecting JSON data within commands. Since that string is not valid JSON, the client is failing to parse the command payload, so nothing is returned.

The fastest workaround would be to make your payload JSON. Something like `{ "value" : "Just about any thing!" }`. You can then access that field using the following:

```auto
JsonObject& payload = *command->payload;
Serial.println(payload["value"]);

```

I created an issue on the repo to add a new field to the command object for the raw string for cases like this.

> <https://github.com/Losant/losant-mqtt-arduino/issues/7>

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [January 17, 2018, 12:28am UTC](https://forums.losant.com/t/unable-to-extract-payload-of-type-string-shipped-to-arduino-via-device-command/731/3 "2018-01-17T00:28:39Z")

</div>

Also, make sure to increase the max mqtt packet size if you’re sending commands. Instructions here:

> [@Sending commands with larger payloads](https://forums.losant.com/t/sending-commands-with-larger-payloads/135):
>
> If you’re using a Losant Builder Kit or the losant-sdk-arduino on another board, you’ll likely hit the default mqtt packet size limit defined in the underlying pubsubclient library. Unfortunately the packet is blocked before reaching any of your code, so it’s hard to debug. It simply looks like the command was never received. For example: { "foo" : "bar" } works, whereas { "somethingLarger" : "with a longer value" } doesn’t work. This is because the default packet size is 128, which provides en…
