ESP8266 i get command but payload is empty

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();
}

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:

Thanks!
Julia

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);
}

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

i am using a dashboard and trigger button.

Hi @Raymond_phillips

I think your problem may be related to packet size.

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.

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

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.

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:

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 where at the bottom under “Summary” you can see the differences on Serializing between v5 and v6.

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.

@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? :

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

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

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

I grabbed it from here:

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("");.

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’”}.

@Raymond_phillips,

Totally fine! Happy we got it figured out. :slight_smile:

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

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}

/**
 * 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);
}

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 as well as a upgrading from v5 to v6 document.

Thank you!
Heath

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 losant2
regards
rake

@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

1 Like

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 = &object;
command.payload = root[“payload”];
LosantDevice::commandCallback(&command);
}

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

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?

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