Pushing a html page to a client device when a push button is pressed

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.

Hi Team,

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

Thanks in advance
Jack

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:

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

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.

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,

           client.println(F("<FORM METHOD='LINK' ACTION='http://www.google.com'><INPUT TYPE='submit' VALUE='go and google stuff'></FORM>  "));
    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>  "));

There is no HTTP "link" method; it's either "get" or "post".

http://www.w3.org/TR/html-markup/form.html

It appears that if you use an invalid method that your browser will fall back to "get" but still it seems like a bad idea to rely on that.

Hi,

I am not sure I understand your comment... There are lots of web pages that discuss this simple solution. See link below. You are correct that this will result in a Get. But this is standard HTML and its a form method with an action of going to a link.

Is there a better or simpler way to do this type of control for the arduino? That is, to have a page shown on the web browser (running on any platform), with a set of button shown that causes an action in the arduino? I guess I was thinking that not having a program on the computer or an app on the phone, would be a plus.

for example, if you run this line in your browser, you will end up with a button that links back to this topic when you push it, (Copy and put it into a HTML file to try). You might be able to put it here but i don't know all the syntax for this list server.

Thanks,
Walt,

waltsailing:
for example, if you run this line in your browser, you will end up with a button that links back to this topic when you push it, (Copy and put it into a HTML file to try). You might be able to put it here but i don't know all the syntax for this list server.

This works also:

That doesn't make it right.

This works also:

That doesn't make it right.

Ok, then i just removed it and tried it, didnt do to much from what i can tell either, and may have just wasted my program space. It works just fine with out METHOD='LINK' apparently the method='link' is not required at all. maybe you can explain this.

This being the case, then maybe i can simplify my code to be much better in my original program and recover a few bytes of code.

Ill try this...

client.println(F("<FORM ACTION='http://192.168.1.177/A\r'><INPUT TYPE='submit' VALUE='Den Pole Light On '></FORM>

Thanks,
Walt