I am working on small web application that am using to turn a lamp on and off through internet. In case the lamp is on it shows on Lamp image, else it shows off lamp image. I am thinking in this procedure to implement this application: 1- I create an html file on server called lamp.html 2- Every 5 sec the lamp controller circuit send http data to a php server application which takes the data and opens the lamp.html file and rewrites the html file with the new data recieved from the lamp controller. Example: If the lamp is on, server application writes to lamp.html file an image tag with an image of ON lamp, and so on. 3- I request the lamp.html file from the browser . ex: http:mysite.com/lamp.html the file has auto refresh every 5 sec.
Is it good procedure to implement? Is there another method that i can use to make remote control using http request?
The prinicpal idea you have sounds good, but it has room for improvements. But first let's look on the general design:
To simplify your system it's actually enough if the server stores the last value transmitted by the lamp into a file. You don't need to render a full HTML file on every change, just modify a single byte inside a file.
The browser on the other hand won't need to refresh the full page as well every 5 seconds. Instead implement something like Stream Updates with Server-Sent Events so that the webserver will actually tell the browser when the lamp changed. The browser then can change the image URL and other stuff via javascript which makes it look much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With