bblanchon / ArduinoJson

📟 JSON library for Arduino and embedded C++. Simple and efficient.
https://arduinojson.org
MIT License
6.72k stars 1.12k forks source link

i'm Sending data ESP8266 to MQTT but no data show in my Serial monitor or MQTT can you show what is my mistake ? i'm using ArduinoJson V6. #1455

Closed Yash1903 closed 3 years ago

Yash1903 commented 3 years ago

hello @bblanchon

`#include

include

include

include

SoftwareSerial s(14,12);

include

const char ssid = "LIMELIGHT LAB"; const char password = "TATA@123"; const char mqttServer = "vernemq.limelightit.io"; const int mqttPort = 1883; //const char mqttUser = "yourInstanceUsername"; //const char* mqttPassword = "yourInstancePassword";

WiFiClient espClient; PubSubClient client(espClient);

void setup() { // Initialize Serial port Serial.begin(115200); s.begin(115200); // while (!Serial) continue;

WiFi.begin(ssid, password);

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

Serial.println("Connected to the WiFi network");

client.setServer(mqttServer, mqttPort);

while (!client.connected()) { Serial.println("Connecting to MQTT...");

if (client.connect("ESP8266Client")) {

  Serial.println("connected");

} else {

  Serial.print("failed with state ");
  Serial.print(client.state());
  delay(2000);

}

} } void loop() { StaticJsonDocument<300> doc; DeserializationError error = deserializeJson(doc,s); if (error) { Serial.print("deserializeJson() failed");

}

serializeJson(doc,Serial); Serial.println("Sending message to MQTT topic.."); Serial.println();

if (client.publish("esp/test",serializeJson(doc,Serial)) == true) { Serial.println("Success sending message"); } else { Serial.println("Error sending message"); }

client.loop(); Serial.println("-------------");

delay(2000); }`

bblanchon commented 3 years ago

Hi @Yash1903,

Please explain what the problem is.

Best regards, Benoit

Yash1903 commented 3 years ago

thank you for Replay @bblanchon , i have 2 question 1) in above Program run ArduinoJson 5.13.5 run completely but i modify to Arduinojson V6 then show me bytes instead of sensor data. 2) can i send whole data.json file to Mqtt ? if yes then can you share example of it. or How to write,append and read .json file in Arduinojson v6

bblanchon commented 3 years ago

Hi,

  1. I'm sorry, I don't understand what you mean by "show me bytes instead of sensor data". Can you provide an example?
  2. Please see How to use ArduinoJson with PubSubClient?
  3. Please see JsonConfigFile.ino

Best regards, Benoit

Yash1903 commented 3 years ago

hello @bblanchon I try example of JsonConfigFile.ino..but Shaw me Error.. Failed to initialize SD library how i can resolve this Error ?? and other SD example run Completely

bblanchon commented 3 years ago

This is not a problem related to ArduinoJson. Please compare the working examples with the non-working one to see how they differ.