Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding More Fields to state_reported in sendData #8

Closed
ashajjar opened this issue May 2, 2019 · 3 comments
Closed

Adding More Fields to state_reported in sendData #8

ashajjar opened this issue May 2, 2019 · 3 comments

Comments

@ashajjar
Copy link

ashajjar commented May 2, 2019

Hi

Thank you for the code it is very useful. It works out of the box for me. However when I try to change the function void sendData(void) by adding extra fields to the reported state as follows :

void sendData(void)
{
  DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(3) + 1000);
  JsonObject root = jsonBuffer.to<JsonObject>();
  JsonObject state = root.createNestedObject("state");
  JsonObject state_reported = state.createNestedObject("reported");
/// the new fields
  state_reported["humidity"] = humidity;
  state_reported["temperature"] = temperature;
  state_reported["heatIndex"] = heatIndex;
  state_reported["gasReading"] = gasReading;
  state_reported["now"] = now;

  Serial.printf("Sending  [%s]: ", MQTT_PUB_TOPIC);
  serializeJson(root, Serial);
  Serial.println();
  char shadow[measureJson(root) + 1];
  serializeJson(root, shadow, sizeof(shadow));
  if (!client.publish(MQTT_PUB_TOPIC, shadow, false))
    pubSubErr(client.state());
}

The code above actually prints something like this to the serial monitor, but never updates the shadow state:

Sending  [$aws/things/HomeEnvThing/shadow/update]: {"state":{"reported":{"humidity":34,"temperature":30,"heatIndex":29.07598,"gasReading":8,"now":1556807522}}}

Any suggestions ?

Thanks again 😃

@ashajjar
Copy link
Author

ashajjar commented May 2, 2019

Adding this flag to PlatformIO ini file solved the issue :

build_flags = -DMQTT_MAX_PACKET_SIZE=256

@ashajjar
Copy link
Author

ashajjar commented May 2, 2019

The issue is related to the payload maximum size specified by PubSub Library

@ashajjar ashajjar closed this as completed May 2, 2019
@debsahu
Copy link
Owner

debsahu commented May 2, 2019

PIO FTW!

There are other methods to send large data as well on PubSubClient see knolleary/pubsubclient#517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants