I have displayed json to Nodemcu and it can appear on the website and serial print. After the text appeared, suddenly "panic" occurred, what was wrong. I can't install it in setup because the loop won't work when displaying json?
0x4020af5c: operator new (unsigned int) at /home/gonit/.arduino15/packages/esp8266 /hardware/esp8266/3.1.2/cores/esp8266/abi.cpp line 44
8x40208604: AsyncWebServer::on (char const*, unsigned char, std::function) at
/home/gonit/Arduino/libraries/ESPAsyncWebServer/src/WebServer.cpp line 149
0x40214208: std::_Function_handler >::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at /home/gonit/.arduino15/packages /esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-1x106-elf/include /c++/10.3.0/bits/std_function.h line 268
8x402011f8: std:: Function_handler >::_M_invoke(const std::_Any_data &, AsyncWebServerRequest *&&) at /home/gonit/.arduino15/packages/esp8266/tools/xtensa- 1x106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-1x106-elf/include/c++/18.3.0 /bits/std_function.h line 289
0x4020a38d: String::operator= (char const*) at /home/gonit/. arduino15/packages /esp8266/hardware/esp8266/3.1.2/cores/esp8266/WString.cpp line 319
8x482027b2: Loop() at /home/gonit/.arduino15/packages/esp8266/tools/xtensa-lx106- elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0 /bits/std_function.h line 303
0x402142d4: std:: Function_handler >::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at /home/gonit/.arduino15/packages /esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include /c++/10.3.0/bits/std_function.h line 268
0x402011a0: std::_Function_handler >::_M_invoke(const std::_Any_data &, AsyncWebServerRequest *&&) at /home/gonit/.arduino15/packages/esp8266/tools/xtensa- 1x106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0 /bits/std_function.h line 289
8x40202a77: ESP8266WiFiAPClass::softAPConfig(IPAddress, IPAddress, IPAddress) at /home/gonit/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries /ESP8266WiFi/src/ESP8266WiFiAP.cpp line 259
8x4820b2f8: Loop_wrapper() at /home/gonit/.arduino15/packages/esp8266/hardware /esp8266/3.1.2/cores/esp8266/core_esp8266_main.cpp line 258
// Import required libraries
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <FS.h>
#include <ArduinoJson.h>
String temp = "";
String pressure = "";
int range;
String rain = "";
float lux;
String light = "";
/* Put your SSID & Password */
const char* ssid = "Weather Station"; // Enter SSID here
const char* password = "12345678"; //Enter Password here
/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
void setup() {
// Initialize Serial port
Serial.begin(9600);
while (!Serial) continue;
if(SPIFFS.begin()==true) {
Serial.println("SPIFFS initialised OK");
}
WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(100);
}
void loop() {
const size_t capacity = JSON_OBJECT_SIZE(128);
DynamicJsonDocument doc(capacity);
DeserializationError error = deserializeJson(doc, Serial);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
//serializeJson(doc, Serial);
Serial.print("SUHU UDARA: ");
temp = doc["temperature"].as<String>();
Serial.print(temp);
Serial.println(" *C");
Serial.print("TEKANAN UDARA: ");
pressure = doc["pressure"].as<String>();
Serial.print(pressure);
Serial.println(" hPa");
Serial.print("CURAH HUJAN: ");
range = doc["range"];
switch (range){
case 0:
rain = "HUJAN";
break;
case 1:
rain = "PERINGATAN HUJAN";
break;
case 2:
rain = "TIDAK HUJAN";
break;
}
Serial.println(rain);
Serial.print("KECERAHAN: ");
lux = doc["lux"];
if(lux < 100){
light = "GELAP";
}
else if(lux > 100){
light = "TERANG";
}
Serial.println(light);
Serial.println("-----------------------------------------");
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/index.html", "text/html");
});
server.on("/assets/css/foundation.css", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/assets/css/foundation.css", "text/css");
});
server.on("/assets/js/vendor.js", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/assets/js/vendor.js", "text/js");
});
server.on("/assets/js/foundation.js", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/assets/js/foundation.js", "text/js");
});
server.on("/temp", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", temp.c_str());
});
server.on("/pressure", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", pressure.c_str());
});
server.on("/rain", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", rain.c_str());
});
server.on("/light", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", light.c_str());
});
server.begin();
//end
}