Go Down

Topic: Pushing a html page to a client device when a push button is pressed (Read 7 times) previous topic - next topic

Jackhobbiest

Dear Arduino Team,

I started a new project, i have a device that will play html pages. Now i'm trying to implement a project that ....

when i press a push-button attached to Arduino ethernet shield ( acting as a server ) should push a html page to the specified client.

I got struct with the code. Please help me on code ASAP.

Thanks in advance
Regards,
Jack.



Jackhobbiest

Hi Team,


Please revert me back .....its quite urgent..


Thanks in advance
Jack

RicDias

Hi Jack.

Maybe you had no replies because this is not the way HTTP was designed to work. HTTP works with requests!
As you said, Arduino will act as a server, which means it is waiting for any requests from 1 or more clients.

The workaround is to provide some polling javascript in the first page you provide to the client. Then It will be the client to continuously poll the server for updates (in this case, it is the push of a button).

You can implement it in AJAX and have the page reconfiguring itself without refreshing if you can.
OR
You can add something like this inside the head tag:
<meta http-equiv="refresh" content="5">

This will refresh the page every 5 seconds. On the Arduino side, all you have to do is to store the pushbutton state (pressed/not pressed - boolean?). Then, each time you receive a request from the client, you just verify the button state and serve a different page if the button was previously pressed.

Of course, this won't be a real-time system, but if you need it, you sould consider something like UDP for the communication.

Best regards,
Ricardo Dias
Visit my website: http://ricardo-dias.com/ for Arduinos and other stuff! :)

TKHouse

Some more specifics would be helpful on this. It sounds as though this will not be a typical http server situation. As noted by Ricardo, html is not "pushed" to a client, html is requested from a server and delivered to the client.

Without knowing the specifics of the project, I would recommend reconsidering how you're thinking about this. The "pushbutton" is really the client, sending a request to the server to display something. The client can certainly send relevant information to the server to affect how the html file is created and thus displayed.

That being said, it wouldn't be bad to implement an auto-refresh solution to this as Ricardo describes. Depending on what you're doing, however, the lack of a real-time system could be irritating.

waltsailing

Hi,

Not sure if this helps, but it works for me.  This code puts a button on the web page and then the action can take you to a different page, or can control the arduino.  If you are running a server on the Arduino, then these do the submit action which is like a specific web page request.  The labeled Button is on the web page... and it sends it to the arduino.  The arduino serves up the web page, so you don't need a separate server.

The first example code sends your browser off to google, from the arduino.

The second example, the action 192.168.1.177/A and action 192.168.1.177/B  gets you the  /A  or /B after the GET which is sent back to the server running on the Arduino.  This can be parsed out and you can then take action in the arduino code to either do the A function or the B function.

Regards,
Walt,

Code: [Select]
           client.println(F("<FORM METHOD='LINK' ACTION='http://www.google.com'><INPUT TYPE='submit' VALUE='go and google stuff'></FORM>  "));

Code: [Select]
    client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/A\r'><INPUT TYPE='submit' VALUE='Den Pole Light On '></FORM>  "));                 
client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/C\r'><INPUT TYPE='submit' VALUE='Den Pole Light Off '></FORM>  "));     


       

Go Up