In the e-book “build web servers” there is a capital called “Websocket web server”.
I can understand that a little but i want to send the time every minute to the esp8266
I think you need a timer like this
setTimeout(showTime, 1000);
showTime()
but i don’t have any idea how to use it.
I think you need to elaborate on what you are trying to do here. Why would you want to send the time from your browser (Where Javascript runs) to an ESP8266? If the ESP8266 needs the correct time then it would be better if it connected to an NTP server to get it.
I want to make a thermostat to regulate the heating in my living room. I have made it so far with the slicers and button’s from the guide. I also made a klok on the website. But not a timer. I have made already a thermostat with only esp8266, but when you can control the heating with a website on your phone it’s much nicer, and the NTP server doesn’t change on winter and summertime or is the time which you get from the website the same as from the NTP-server
To get Daylight Saving Time you can use a combination of NTP, Time and Timezone libraries. See https://www.mischianti.org/2020/08/08/network-time-protocol-ntp-timezone-and-daylight-saving-time-dst-with-esp8266-esp32-or-arduino/
Thanks Steve, may be i need that link in the future.
I already found the solution, the function showtime() i found somewere on the internet and with websocket.send() you can send the data to main.ccp ->”void handleWebSocketMessage”
I had to place a loop within the function to send the text every minute. I tried to send it every second, but that didn’t work.
Start your code here
function showTime() {
vardate=newDate();
varh=date.getHours(); // 0 – 23
varm=date.getMinutes(); // 0 – 59
vars=date.getSeconds(); // 0 – 59
varw=date.getDay();
varm_old;
h= (h<10) ?”0″+h:h;
m= (m<10) ?”0″+m:m;
s= (s<10) ?”0″+s:s;
vardaylist= [“Zondag”, “Maandag”, “Dinsdag”, “Woensdag “, “Donderdag”, “Vrijdag”, “Zaterdag”];
vartime=daylist[w] +” “+h+”:”+m+”:”+s;
document.getElementById(“MyClockDisplay”).innerText=time;
document.getElementById(“MyClockDisplay”).textContent=time;
//websocket.send(“blabla”); //doesn’t do anything here
if (s==0){
websocket.send(time); // send time to handleWebSocketMessage
}
setTimeout(showTime, 1000);
}
showTime();