Go Down

Topic: Arduino web server ideas. (Read 561 times) previous topic - next topic

Adriem

Hello,
I'm actually doing a project for high school, it is a weather station, i need to get the sensors data, and be able to check it on a web page, so I made a quick program wich hosts a webpage, but the HTML is integrated into the C code which is not really clean, so I read about something to call a webpage hosted on the SD card. But doing that I don't know how to transfer the data from the C code to the HTML. I was thinking of ad txt file which would be edited by the C and got back by the HTML to display it on the webpage. Any ideas ?
Thanks by advance for your responses.
Hope my english is comprehensible because it is not my native language.

SurferTim

Normally, I would recommend my code in the playground, but zoomkat is the guy with the SD interface examples working. You might want to look at the code in this link:
http://arduino.cc/forum/index.php/topic,152642.msg1147210.html#msg1147210

Adriem

Thanks a lot i'll read this.

mixania

I think you could use the Arduino IDE language println(); function and just put the readings and HTML code inside it.

For example: to display a text you could do the following:

Code: [Select]

print("<h3> Reading from termometer is: " );
print(analogRead(A0));
println(</h3>);

print("<h3> Humidity is: " );
print(analogRead(A1));
println(</h3>);
Arduino Uno R3
Mac OSX Lion

AWOL

Better still would be to use the "F()" macro with your prints, so you don't clog up RAM with constant strings
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Adriem

@mixania : it will become so crappy, and I can't include CSS

SurferTim

Besides, there are some files too big to fit into program memory. Here is zoomkat testing a 253k file download speed.
http://arduino.cc/forum/index.php/topic,134868.msg1124757.html#msg1124757

zoomkat

Quote
i need to get the sensors data, and be able to check it on a web page


If you are interested in monitoring data input, the below may be one method. The below code provides a web page that will display the current analog pin values (with nothing connected to the pins, the pins have random floating values).

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="";
        }
      }
    }
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up