Go Down

Topic: How to send multiple HTTP requests to ardino web servers in one "click"? (Read 886 times) previous topic - next topic

churduino

Hi,

My goal is the following:

To have several arduino ethernet shields in the same LAN each set up as a web server.
I also have a web page locally on the computer with a frameset with the same number of frames as ethernet shields (web servers) in the network.
Upon the start-up of the web page, a simple HTML page is loaded into each frame from each web server.
Each page has just one or links used for turning on/off the LED on the corresponding arduino via HTTP requests.

I want to have one link (or button) for turning off (or on) all LEDs on all arduinos. So I am looking for the way how to "tell" all arduinos with one "click" to do so. Technically I see it as sending multiple HTTP requests to web servers in a sequence within a short period of time or at the same time.

I have searched different topics, but could not find this kind of solution. I even do not know if it is technically possible to do so.

What would be your recommendation to achieve this goal?

Many thanks!
/churduino

SurferTim

JavaScript. Write a script that submits the forms in each frame.
Watch for me on National Geographic Wild "When Sharks Attack: Gulf Coast Killers". Airs on June 22nd.

zoomkat

Quote
I want to have one link (or button) for turning off (or on) all LEDs on all arduinos. So I am looking for the way how to "tell" all arduinos with one "click" to do so. Technically I see it as sending multiple HTTP requests to web servers in a sequence within a short period of time or at the same time.


You can embed your arduino command calls as links in a very simple web page that will activate the links when the page is loaded in a browser. On a main web page these various command pages can be called to a frame using simple link calls. The below code basically calls three different web pages from a main web page which are displayed in a frame.

Code: [Select]

// zoomkat's meta refresh data iframe test page 12/24/12
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
unsigned long int x=0; //set refresh counter to 0
String readString;

//////////////////////

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c;
         }
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print("<HTML><HEAD>");
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print("<meta http-equiv='refresh' content='1'>");
            if(readString.indexOf("datafast") >0) client.print("<meta http-equiv='refresh' content='0'>");
            client.print("<title>Zoomkat's meta-refresh test</title></head><BODY><br>");
            client.print("page refresh number ");
            client.print(x); //current refresh count
            client.print("<br><br>");
              //output the value of each analog input pin
             for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
             client.print("analog input ");
             client.print(analogChannel);
             client.print(" is ");
             client.print(analogRead(analogChannel));
             client.print("<br>");
             }
            client.print("</BODY></HTML>");
           }
          //generate main page with iframe
          else
          {
            client.print("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>");
            client.print("Zoomkat's Arduino frame meta refresh test 2/20/13");
            client.print("<BR><BR>Arduino analog input data frame:<BR>");
            client.print("&nbsp;&nbsp;<a href='http://192.168.1.102:84/datastart' target='DataBox' title=''yy''>META-REFRESH</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/data' target='DataBox' title=''xx''>SINGLE-STOP</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/datafast' target='DataBox' title=''zz''>FAST-DATA</a><BR>");
            client.print("<iframe src='http://192.168.1.102:84/data' width='350' height='250' name='DataBox'>");
            client.print("</iframe><BR></HTML>");
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

churduino

Thanks guys for your feedback and tips!

Zoomkat,

I have tested your code on my Arduino.
I have one question though.

Quote
web page that will activate the links when the page is loaded


How can I achieve this without clicking on each and very link? Each link will represent each node (IP and socket of each Arduino is listening on).
I can have several links on one page, but how can I activate all of them automatically when the page is refreshed in order to send multiple requests to all Arduinos?

Or do I misunderstand your suggested solution?

Thanks!
/churduino

zoomkat

I'd try embedding the command as an image link similar to the below, and the browser should send the request to the desired server. Also a redirect call to the desired server should also work. You will need to try various methods to see what works.

Code: [Select]
<img src="http://arduino.cc/forum/Themes/arduinoWide/images/home_icon.gif" alt="home icon" title=" home icon " width="9" height="11">

Code: [Select]
<meta http-equiv="Refresh" content="0; url=http://www.quackit.com/html/tags/">

http://www.w3schools.com/html/html_images.asp

http://www.w3schools.com/tags/att_img_src.asp

http://www.w3schools.com/html/html_videos.asp

http://www.quackit.com/html/html_redirect.cfm
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy