I have been using Arduino Uno and ESP 8266 wifi module to post data to my webserver using the code below...but it doesn't post the ID as stated in the ESP8266 serial monitor. I have already achieved sending the data from Arduino to ESP serial monitor.I need help posting the data to my webserver as different entries everytime i send it from my Arduino Uno...each time having its own timestamp
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
const long utcOffsetInSeconds = 10800;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
unsigned long epochTime = timeClient.getEpochTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
const char* ssid = "****";
const char* password = "*****";
ESP8266WebServer server(80);
String SendHTML(String ID , String TimeWeb, String DateWeb);
void handle_OnConnect();
void handle_NotFound();
String ID ;
String formattedTime;
String Date;
int Day;
int Month;
int Year;
void setup() {
Serial.begin(9600);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi");
Serial.print("IP: "); Serial.println(WiFi.localIP());
server.on("/", handle_OnConnect);
server.onNotFound(handle_NotFound);
server.begin(); //Start the server
Serial.println("Server listening");
timeClient.begin();
}
void loop() {
if (Serial.available()) {
Serial.write(Serial.read());
}
server.handleClient();
}
void handle_OnConnect() {
timeClient.update();
unsigned long epochTime = timeClient.getEpochTime();
String formattedTime = timeClient.getFormattedTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
int currentMonth = ptm->tm_mon+1;
int currentYear = ptm->tm_year+1900;
formattedTime = timeClient.getFormattedTime();
Date = String(currentYear) + "-" + String(currentMonth) + "-" + String(monthDay);
ID = Serial.write(Serial.read());
server.send(200, "text/html", SendHTML(ID,formattedTime,Date));
}
void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}
String SendHTML(String ID, String TimeWeb,String DateWeb){
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>ESP8266 Hosp Server</title>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<div id=\"webpage\">\n";
ptr +="<h1>ESP8266 Hosp Server</h1>\n";
ptr +="<p>Date: ";
ptr +=(String)DateWeb;
ptr +="</p>";
ptr +="<p>Time: ";
ptr +=(String)TimeWeb;
ptr +="</p>";
ptr +="<p>ID: ";
ptr +=(String) ID;
ptr +="</p>";
ptr +="</div>\n";
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
}
The time displayed in the webserver is okay but cant seem to get the right date