Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web application: html and php

Tags:

html

http

php

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?

like image 316
Hisham Avatar asked Nov 05 '22 01:11

Hisham


1 Answers

The prinicpal idea you have sounds good, but it has room for improvements. But first let's look on the general design:

enter image description here

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.

like image 160
hakre Avatar answered Nov 10 '22 16:11

hakre