Go Down

Topic: Webpage/while loop (Read 420 times) previous topic - next topic

Hi guys

I am using a arduino with an ethernetshield. I am making a smart desklight. I have a photosensor that, in auto mode, needs to be continuously read. After the read it needs to adjust the ledpin to the correct value. Currently the automode works but refreshing the webpage wont work since the arduino is in that loop. I tried some things but it didnt bother.

Please HELP!

king regards



Probably best you post your code to better understand just what you are desiring. Below is some meta refresh web page code that updates with the current analog pin values.

Code: [Select]

// zoomkat's meta refresh data frame test page 4/12/13
// use in your brouser for main page
// static data page
// 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>

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

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(){
    // disable SD SPI if memory card in the uSD slot

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  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

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

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            //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
              //output the value of each analog input pin
            client.print("analog input0 ");
            client.print(" is ");
            client.println("<br />");
            client.print("analog input1 ");
            client.print(" is ");
            client.println("<br />");
            client.print("analog input2 ");
            client.print(" is ");
            client.println("<br />");
            client.print("analog input3 ");
            client.print(" is ");
            client.println("<br />");
            client.print("analog input4 ");
            client.print(" is ");
            client.println("<br />");
            client.print("analog input5 ");
            client.print(" is ");
            client.println("<br />");
          //generate main page with iframe
            client.print("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>");
            client.print("Zoomkat's Arduino frame meta refresh test 4/12/13");
            client.print("<BR><BR>Arduino analog input data frame:<BR>");
            client.print("&nbsp;&nbsp;<a href='' target='DataBox' title=''yy''>META-REFRESH</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='' target='DataBox' title=''xx''>SINGLE-STOP</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='' target='DataBox' title=''zz''>FAST-DATA</a><BR>");
            client.print("<iframe src='' width='350' height='250' name='DataBox'>");
          //stopping client
          //clearing string for next read

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!

via Egeo 16
Torino, 10131