I just managed to find a way and just changed the Arduino 2 code and now I replaced it with Nodemcu but this is what happened when I installed the website
// 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
}