# ESP8266 i get command but payload is empty

**URL:** <https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983>\
**Category:** Help\
**Tags:** mqtt, device\
**Created:** [May 29, 2020, 12:10am UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983 "2020-05-29T00:10:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [May 29, 2020, 12:10am UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/1 "2020-05-29T00:10:48Z")

</div>

so i update one of my project from using arduinoJson V5 to version V6. but when i did my payloads are not coming in any more. my command comes in so i see the commands name. but when i try and see what is in the payload it null. it worked in v5 but not v6. here is the snip of my code.

// Called whenever the device receives a command from the Losant platform.  
void handleCommand(LosantCommand \*command) {  
Serial.print("Command received: ");  
Serial.println(command-\>name);  
latch = true;

if (strcmp(command-\>name, “ledCommand”) == 0)  
{  
JsonObject& payload = \*command-\>payload;

```
Serial.println("");

msgs[1] = payload["pattern"].as<String>();
msgs[2] = payload["cycles"].as<String>();
msgs[3] = payload["runTime"].as<String>();
msgs[4] = payload["color1"].as<String>();
msgs[5] = payload["color2"].as<String>();

```

}

//commandChanged();  
}

---

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [May 29, 2020, 2:49pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/3 "2020-05-29T14:49:40Z")

</div>

Hi @Raymond_phillips,

Could you possibly include a screenshot of what this command looks like when it does not include a payload? And are you receiving any errors anywhere?

I would recommend checking out the following forum posts, they might prove helpful as they focus on issues with upgrading to ArduinoJson V6 and likely may provide a solution:

> [@ESP8266 and arduinoJson 6 - Not going well](https://forums.losant.com/t/esp8266-and-arduinojson-6-not-going-well/2658):
>
> Hello I am trying to build a new device based on ESP8266 and an example from [https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor](https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor). My device does not succeed to connect to Losant (I have made plenty of devices in the past that did, I generated and used the ID, access key & secret - twice.) The ArduinoJson library has updated since someone wrote this example and lots of stuff did not compile - I had to modify quite a bit just for that. tried solutions in: [Unable to c…](https://forums.losant.com/t/unable-to-connect-losant-plattform-using-esp8266-module/1264)

> [@Device won't transmit to Losant, mqttClient.state -2](https://forums.losant.com/t/device-wont-transmit-to-losant-mqttclient-state-2/2649):
>
> Hello, I have am working on setting up a temperature and humidity sensor based on [the tutorial](https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor) by @anaptfox. When testing though, the device says authentication succeeded in the application log, however it doesn’t transmit any data afterward. [log] I am also getting this readout in the serial monitor: WiFi connected IP address: xxx.xxx.x.x Authenticating Device...This device is authorized! Connecting to Losant...-2 .-2 .-2 .-2 .-2 .-2 I have tried removing everything marked “secure” in …

> [@Issue connecting to losant](https://forums.losant.com/t/issue-connecting-to-losant/2573/3):
>
> I am having similar issues. I have narrowed it down (maybe incorrectly) to JSON upgrade from 5 to 6. I have tried following along with the upgrade instructions on the ArduinoJson upgrade site but I am still having issues. Will the examples be changed to reflect the JSON upgrade?

Thanks!  
Julia

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [May 29, 2020, 7:49pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/4 "2020-05-29T19:49:55Z")

</div>

i don’t get errors it blank the command from losant says it sent and the device revived it. the device does see the command and i can see the name of the command but when i try to print it to serial directly it just blank. i have tried the suggestion above before asking. those seem to be not connection issues or they didn’t receive the command. below is my full code

```
/**
   Example that connects an Adafruit Feather Huzzah to the Losant
   IoT platform. This example reports state to Losant whenever a button is
   pressed. It also listens for the "toggle" command to turn the LED on and off.

   Copyright (c) 2016 Losant. All rights reserved.
   http://losant.com
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <Losant.h>
#include <Adafruit_NeoPixel.h>

#define PIN 14

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(100, PIN, NEO_RGB + NEO_KHZ400);

// WiFi credentials.
char* WIFI_SSID = "";
char* WIFI_PASS = "";

// Losant credentials.
const char* LOSANT_DEVICE_ID = "";
const char* LOSANT_ACCESS_KEY = "";
const char* LOSANT_ACCESS_SECRET = "";

// Cert taken from 
// https://github.com/Losant/losant-mqtt-ruby/blob/master/lib/losant_mqtt/RootCA.crt
static const char digicert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----
)EOF";

BearSSL::WiFiClientSecure wifiClient;

LosantDevice device(LOSANT_DEVICE_ID);

// Set time via NTP, as required for x.509 validation
void setClock() {
  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  time_t now = time(nullptr);
  while (now < 8 * 3600 * 2) {
    delay(500);
    now = time(nullptr);
  }
  struct tm timeinfo;
  gmtime_r(&now, &timeinfo);
}

String msgs[6];
bool latch = false;
bool other = false;

void commandChanged() {
  // Losant uses a JSON protocol. Construct the simple state object.
  // { "Power_State" : true Or false }
  StaticJsonDocument<200> doc;
  JsonObject root = doc.to<JsonObject>();
  // Send the state to Losant.
  root["pattern"] = msgs[1];
  root["run_time"] = msgs[3];
  root["color_1"] = msgs[4];
  root["color_2"] = msgs[5];
  device.sendState(root);
}

void powerStateChange(bool state) {
  Serial.println("State Change!");

  // Losant uses a JSON protocol. Construct the simple state object.
  // { "Power_State" : true Or false }
  StaticJsonDocument<200> doc;
  JsonObject root = doc.to<JsonObject>();
  if (state == true) {
    root["Power_State"] = true;
  } else {
    root["Power_State"] = false;
  }
  // Send the state to Losant.
  device.sendState(root);
}

// Called whenever the device receives a command from the Losant platform.
void handleCommand(LosantCommand *command) {
  Serial.print("Command received: ");
  Serial.println(command->name);
  latch = true;

  if (strcmp(command->name, "ledCommand") == 0) 
  {
    JsonObject& payload = *command->payload;
  
    Serial.println("");

    msgs[1] = payload["pattern"].as<String>();
    msgs[2] = payload["cycles"].as<String>();
    msgs[3] = payload["runTime"].as<String>();
    msgs[4] = payload["color1"].as<String>();
    msgs[5] = payload["color2"].as<String>();
  }

  //commandChanged();
}

void connect() {

  // Connect to Wifi.
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);

  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  // Validating the SSL for for a secure connection you must
  // set trust anchor, as well as set the time.
  BearSSL::X509List cert(digicert);
  wifiClient.setTrustAnchors(&cert);
  setClock();

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Connect to Losant.
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  // For an unsecure connection.
   //device.connect(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while (!device.connected()) {
    delay(500);
    //Serial.println(device.mqttClient.state()); // HERE
    Serial.print(".");
  }

  Serial.println("Connected!");
}

void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    device.loop();
    delay(wait);
  }
  Serial.println(msgs[1]);
}

void colorsWipe(int wipeTime) {
  latch = false;
  colorWipe(strip.Color(255, 0, 0), wipeTime); // Red
  colorWipe(strip.Color(255, 128, 0), wipeTime);
  colorWipe(strip.Color(255, 255, 0), wipeTime);
  colorWipe(strip.Color(128, 255, 0), wipeTime);
  colorWipe(strip.Color(0, 255, 0), wipeTime); // Green
  colorWipe(strip.Color(0, 255, 128), wipeTime);
  colorWipe(strip.Color(0, 255, 255), wipeTime);
  colorWipe(strip.Color(0, 128, 255), wipeTime);
  colorWipe(strip.Color(0, 0, 255), wipeTime); // Blue
  colorWipe(strip.Color(128, 0, 255), wipeTime);
  colorWipe(strip.Color(255, 0, 255), wipeTime);
  colorWipe(strip.Color(255, 0, 128), wipeTime);
}

// this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  latch = false;
  uint16_t i, j;

  for (j = 0; j < 256; j++) { // 15 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    device.loop();
    delay(wait);
    Serial.println(msgs[1] + "t");
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if (WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

void solidColor(String color) {
  latch = false;
  if (color == "white") {
    colorWipe(strip.Color(255, 255, 255), 50);
  } else if (color == "blue") {
    colorWipe(strip.Color(0, 0, 255), 50);
  } else if (color == "red") {
    colorWipe(strip.Color(255, 0, 0), 50);
  } else if (color == "green") {
    colorWipe(strip.Color(0, 255, 0), 50);
  } else if (color == "magenta") {
    colorWipe(strip.Color(255, 0, 255), 50);
  } else if (color == "yellow") {
    colorWipe(strip.Color(255, 255, 0), 50);
  } else if (color == "cyan") {
    colorWipe(strip.Color(0, 255, 255), 50);
  } else if (color == "orange") {
    colorWipe(strip.Color(255, 165, 0), 50);
  } else if (color == "purple") {
    colorWipe(strip.Color(128, 0, 128), 50);
  } else if (color == "blueviolet") {
    colorWipe(strip.Color(138, 43, 226), 50);
  } else if (color == "olivedrab") {
    colorWipe(strip.Color(107, 142, 35), 50);
  } else if (color == "olive") {
    colorWipe(strip.Color(128, 128, 0), 50);
  } else if (color == "teal") {
    colorWipe(strip.Color(0, 128, 128), 50);
  }

  strip.show();

}

uint32_t colorPicker(String color) {
  uint32_t colorPicked;
  if (color == "white") {
    colorPicked = strip.Color(255, 255, 255);
  } else if (color == "blue") {
    colorPicked = strip.Color(0, 0, 255);
  } else if (color == "red") {
    colorPicked = strip.Color(255, 0, 0);
  } else if (color == "green") {
    colorPicked = strip.Color(0, 255, 0);
  } else if (color == "magenta") {
    colorPicked = strip.Color(255, 0, 255);
  } else if (color == "yellow") {
    colorPicked = strip.Color(255, 255, 0);
  } else if (color == "cyan") {
    colorPicked = strip.Color(0, 255, 255);
  } else if (color == "orange") {
    colorPicked = strip.Color(255, 165, 0);
  } else if (color == "purple") {
    colorPicked = strip.Color(128, 0, 128);
  } else if (color == "blueviolet") {
    colorPicked = strip.Color(138, 43, 226);
  } else if (color == "olivedrab") {
    colorPicked = strip.Color(107, 142, 35);
  } else if (color == "olive") {
    colorPicked = strip.Color(128, 128, 0);
  } else if (color == "teal") {
    colorPicked = strip.Color(0, 128, 128);
  }
  return (colorPicked);
}

void colorChase(String background, String forground, int runTime) {
  latch = false;
  uint32_t forgroundColor;
  uint32_t backgroundColor;

  int li = 0;
  int gi = 0;

  forgroundColor = colorPicker(forground);
  backgroundColor = colorPicker(background);
  Serial.println(forground + forgroundColor);
  Serial.println(background + backgroundColor);
  for (int i = 0; i < strip.numPixels(); i++) {
    li = i - 1;
    gi = i + 1;
    strip.fill(backgroundColor);
    strip.show();

    if (li >= 0) {
      strip.setPixelColor(li, forgroundColor);
    }
    if (gi <= strip.numPixels()) {
      strip.setPixelColor(gi, forgroundColor);
    }
    strip.setPixelColor(i, forgroundColor);
    strip.show();
    device.loop();
    delay(runTime);

  }

}

void colorBlink( String background, String forground, int runTime) {
  latch = false;
  uint32_t forgroundColor;
  uint32_t backgroundColor;

  forgroundColor = colorPicker(forground);
  backgroundColor = colorPicker(background);

  for (int i = 0; i < strip.numPixels(); i++) {
    if (other) {
      strip.setPixelColor(i, forgroundColor);
      i++;
      strip.setPixelColor(i, backgroundColor);
      other = false;
    } else {
      strip.setPixelColor(i, backgroundColor);
      i++;
      strip.setPixelColor(i, forgroundColor);
      other = true;
    }
  }
  strip.show();
  device.loop();
  delay(runTime);
}

void setup() {
  Serial.begin(115200);
  while (!Serial) { }

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

  connect();

  strip.begin();
  strip.setBrightness(30); //adjust brightness here
  strip.show(); // Initialize all pixels to 'off'

  powerStateChange(false);
}

void loop() {

  if (msgs[1] == "off") {
    Serial.print("off");
    powerStateChange(false);
    strip.clear();
    strip.show();
    msgs[1] = "off1";
  } else if (msgs[1] == "rainbow") {
    Serial.print("rainbow");
    if (latch) {
      powerStateChange(true);
    }
    rainbowCycle(msgs[3].toInt());
  } else if (msgs[1] == "solid") {
    Serial.print("solid");
    if (latch) {
      powerStateChange(true);
    }
    solidColor(msgs[4]);
  } else if (msgs[1] == "color chase") {
    Serial.print("color chase");
    if (latch) {
      powerStateChange(true);
    }
    colorChase(msgs[4], msgs[5], msgs[3].toInt());
  } else if (msgs[1] == "two color blink") {
    Serial.print("two color blink");
    if (latch) {
      powerStateChange(true);
    }
    colorBlink(msgs[4], msgs[5], msgs[3].toInt());
  } else if (msgs[1] == "colors wipe") {
    Serial.print("color wipe");
    if (latch) {
      powerStateChange(true);
    }
    colorsWipe(msgs[3].toInt());
  }

  bool toReconnect = false;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Disconnected from WiFi");
    toReconnect = true;
  }

  if (!device.connected()) {
    Serial.println("Disconnected from Losant");
    //Serial.println(device.mqttClient.state());
    toReconnect = true;
  }

  if (toReconnect) {
    connect();
  }

  device.loop();

  delay(100);
}
```

---

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [May 29, 2020, 8:43pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/5 "2020-05-29T20:43:46Z")

</div>

Hi @Raymond_phillips,

How are you triggering this command from Losant? Could you include a screenshot of the workflow or dashboard configuration? I’m hoping to see the data you are sending should I need to replicate or debug some unexpected behavior.

Thanks so much!  
Julia

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [May 29, 2020, 10:42pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/6 "2020-05-29T22:42:34Z")

</div>

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/7b17b5625a11fef3eb8139efe6317798a1ce882c.png)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/3/3eb76bdd268ca5306a6ef79e332a2e7b4d1def85.png)

i am using a dashboard and trigger button.

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [June 1, 2020, 1:08pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/7 "2020-06-01T13:08:42Z")

</div>

Hi @Raymond_phillips

I think your problem may be related to packet size.

> [@Unable to connect Losant Plattform using ESP8266 module](https://forums.losant.com/t/unable-to-connect-losant-plattform-using-esp8266-module/1264):
>
> Hi, I do need help as I couldn’t make to connect Losant plattform using ESP8266 12E module (WiFi+Microcontroller). I do follow all instruction as per ‘Moisture Sensor Kit Instruction’ and can connect only WiFi and Losant plattform is failed to connect. Please help me to solve it out. Advance in thanks.

In the past, we’ve seen this device fail due to this. However, in the link I sent above was for an older version of our client. I linked it to demonstrate what the past solution was.

I’d have to do some digging to see what this looks like now. But, if you reduce the size of the payload, do you see normal behavior? If so, my theory may be correct.

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [June 2, 2020, 1:08am UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/9 "2020-06-02T01:08:07Z")

</div>

i will try and reduce payload but why did it work with ArduinoJSON V5 but not V6?

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [June 2, 2020, 1:28am UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/11 "2020-06-02T01:28:45Z")

</div>

still no luck i change the payload from String to int and it had not effect still get the command but the payload still empty.

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [June 8, 2020, 2:07pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/14 "2020-06-08T14:07:00Z")

</div>

Hey @Raymond_phillips!

I’ve followed along with this thread and am hoping I can help you!

I’ve looked at your code that you posted, and it looks like you might be mixing a little bit of ArduinoJson v5 and v6 with these two lines:

```auto
StaticJsonDocument<200> doc;
JsonObject root = doc.to<JsonObject>();

```

With ArduinoJson v6, you only need to write the line `StaticJsonDocument<200> doc;`. ArduinoJson provided a fantastic [migration document](https://arduinojson.org/v6/doc/upgrade/) where at the bottom under “Summary” you can see the differences on Serializing between v5 and v6.

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [June 8, 2020, 8:48pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/17 "2020-06-08T20:48:57Z")

</div>

ive tried that sadly that. what i posted is using the example from losant lib. im confused to what going on. not sure if you can write an example that a payloads works. i have tried several iterations with no luck. the name comes through but not the payload i have tried examples but nothing working in arduinoJSON v6.

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [June 8, 2020, 9:39pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/19 "2020-06-08T21:39:49Z")

</div>

@Raymond_phillips,

When debugging hardware issues, it’s helpful to isolate where the problem may be. In this case, your code does a lot more than simply connecting to Losant and receiving commands. Since the issue you’re communicating is about the device not receive the command, if you started from the example code, Do you get the same result? :

> <https://github.com/Losant/losant-mqtt-arduino/blob/master/examples/esp8266/esp8266.ino>

Next, after reading your message again, this sparked interest:

> [@Raymond\_phillips](#):
>
> i don’t get errors it blank the command from losant says it sent and the device revived it. the device does see the command and i can see the name of the command but when i try to print it to serial directly it just blank.

If you see the name of the command, you’re getting to this part of the code:

```auto
Serial.print("Command received: ");
Serial.println(command->name);

```

I grabbed it from here:

> [@Raymond\_phillips](#):
>
> ```auto
> // Called whenever the device receives a command from the Losant platform.
> void handleCommand(LosantCommand *command) {
> Serial.print("Command received: ");
> Serial.println(command->name);
> latch = true;
> 
> if (strcmp(command->name, "ledCommand") == 0) 
> {
> JsonObject& payload = *command->payload;
>   
> Serial.println("");
> 
> msgs[1] = payload["pattern"].as<String>();
> msgs[2] = payload["cycles"].as<String>();
> msgs[3] = payload["runTime"].as<String>();
> msgs[4] = payload["color1"].as<String>();
> msgs[5] = payload["color2"].as<String>();
> }
> 
> //commandChanged();
> }
> 
> ```

To help figure out what’s supposed to happen, what are you expecting to see when your command is run? Currently, you only have it configured to print and empty quote `Serial.println("");`.

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [June 8, 2020, 10:12pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/20 "2020-06-08T22:12:15Z")

</div>

ooops sorry i guess during my many attempts i left that empty. so i was trying to print any of those msg. i am using a trigger button in dash board and just sending a simple payload to msg[1]. i tried sending just {“pattern”:“foo’”}.

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [June 9, 2020, 12:09pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/21 "2020-06-09T12:09:22Z")

</div>

@Raymond_phillips,

Totally fine! Happy we got it figured out. 🙂

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [June 9, 2020, 12:24pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/23 "2020-06-09T12:24:49Z")

</div>

Sadly still not working. This was just an oops while posting.

---

<div class="post-metadata">

**Author:** ![Raymond\_phillips](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Raymond\_phillips](https://forums.losant.com/u/Raymond_phillips)\
**Post date:** [June 21, 2020, 11:09pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/26 "2020-06-21T23:09:19Z")

</div>

hello below is a using the example but the pay load is not being received but the command is. i am send a simple int in the payload. i am using ArdiunoJson V6. i am at a lost of what going on can some one test this code? i am just using a simple trigger button from the dashboard sending {“foo”:100}

```auto
/**
 * Example that connects an Adafruit Feather Huzzah to the Losant
 * IoT platform. This example reports state to Losant whenever a button is
 * pressed. It also listens for the "toggle" command to turn the LED on and off.
 *
 * This example assumes the following connections:
 * Button connected to pin 14.
 * LED connected to pin 12.
 *
 * Copyright (c) 2020 Losant. All rights reserved.
 * http://losant.com
 */

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>
#include <Losant.h>

// WiFi credentials.
const char* WIFI_SSID = "";
const char* WIFI_PASS = "";

// Losant credentials.
const char* LOSANT_DEVICE_ID = "";
const char* LOSANT_ACCESS_KEY = "";
const char* LOSANT_ACCESS_SECRET = "";

// Cert taken from 
// https://github.com/Losant/losant-mqtt-ruby/blob/master/lib/losant_mqtt/RootCA.crt
static const char digicert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----
)EOF";

BearSSL::WiFiClientSecure wifiClient;

LosantDevice device(LOSANT_DEVICE_ID);

// Set time via NTP, as required for x.509 validation
void setClock() {
  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  time_t now = time(nullptr);
  while (now < 8 * 3600 * 2) {
    delay(500);
    now = time(nullptr);
  }
  struct tm timeinfo;
  gmtime_r(&now, &timeinfo);
}

// 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, "ledCommand") == 0) {
    JsonObject& payload = *command->payload;
    int bar = payload["foo"];
    Serial.println(bar);
  }
}

void connect() {

  // Connect to Wifi.
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);

  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  // Validating the SSL for for a secure connection you must
  // set trust anchor, as well as set the time.
  BearSSL::X509List cert(digicert);
  wifiClient.setTrustAnchors(&cert);
  setClock();
  

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Connect to Losant.
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while(!device.connected()) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("Connected!");
}

void setup() {
  Serial.begin(115200);
  while(!Serial) { }
  
  // Register the command handler to be called when a command is received
  // from the Losant platform.
  device.onCommand(&handleCommand);

  connect();
}

void loop() {

  bool toReconnect = false;

  if(WiFi.status() != WL_CONNECTED) {
    Serial.println("Disconnected from WiFi");
    toReconnect = true;
  }

  if(!device.connected()) {
    Serial.println("Disconnected from Losant");
    toReconnect = true;
  }

  if(toReconnect) {
    connect();
  }

  device.loop();

  delay(100);
}

```

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [June 24, 2020, 9:18pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/30 "2020-06-24T21:18:24Z")

</div>

Hey @Raymond_phillips,

I’ll be digging into this as much as I can to get you a proper answer. I’ll be sure to update you on this as soon as I can.

So far, I’ve been able to replicate your issue on my own device, and have tried every which way of using arduinojson v6. So I am going to go fishing in the Losant MQTT package and see if I can find something.

While I work on this, here is the the [arduinojson documentation](https://arduinojson.org/v6/doc/) as well as a [upgrading from v5 to v6 document](https://arduinojson.org/v6/doc/upgrade/).

Thank you!  
Heath

---

<div class="post-metadata">

**Author:** ![rake\_silverrian](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/rake_silverrian/32/2793_2.png) [@rake\_silverrian](https://forums.losant.com/u/rake_silverrian)\
**Post date:** [June 25, 2020, 10:53am UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/32 "2020-06-25T10:53:22Z")

</div>

hey losant dev team

Great iot platform you build, i just want to inform that i got similar problem about sending device command from input control directly to my device (nodeMCU). the device seems responded to the command but the payload isn’t coming. Hopefully you’re figuring this problem ASAP.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/4/46ad842cc6da78d054382cd92d231a387c2cf48a.png) ![losant2](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/1d2cf763d1891b458478abdef7254f532b5448cc.png)  
regards  
rake

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [June 25, 2020, 4:05pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/35 "2020-06-25T16:05:22Z")

</div>

@Raymond_phillips & @rake_silverrian,

We were able to find the bug and initiate a fix! It’s currently under review, so I will be sure to update you when the package is updated so that you can pull the latest losant-mqtt-arduino package.

Also, this update will include updated example code for both the ESP32 and ESP8266.

Heath

---

<div class="post-metadata">

**Author:** ![Nicolas\_Assouad](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@Nicolas\_Assouad](https://forums.losant.com/u/Nicolas_Assouad)\
**Post date:** [November 9, 2020, 2:29am UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/38 "2020-11-09T02:29:55Z")

</div>

Hello, Thanks for all the help… Any idea when the new release with the fix for the payload will be released?  
Temp fix: converted the payload to \*char and did the parsing in the .ino

**Mods in Losantcommand.h:**

class LosantCommand {  
public:  
const char\* name;  
const char\* time;  
const char\* payload;  
//JsonObject\* payload;  
};

_Mods in Losantdevice\_cpp:_

if (!error) {  
command.name = root[“name”];  
command.time = root["$time"];  
//JsonObject object = root[“payload”];  
[//command.payload](https://command.payload) = &object;  
command.payload = root[“payload”];  
LosantDevice::commandCallback(&command);  
}

The reference to the payload in .ino file is: command-\>payload  
Thanks

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [November 9, 2020, 3:01pm UTC](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983/40 "2020-11-09T15:01:14Z")

</div>

Hello @Nicolas_Assouad,

Welcome to the Losant Forums! We’re very happy you’re here.

In regards to the fix to the Losant Arduino package, we released a fix a few months back. Have you pulled down the latest package from [the GitHub repository?](https://github.com/Losant/losant-mqtt-arduino)

Please let me know if this issue is still persistent in the newest version of the package, or if you have any other questions.

Thank you,  
Heath

[Next page](https://forums.losant.com/t/esp8266-i-get-command-but-payload-is-empty/2983.md?page=2)
