Arduino Windsensor with WebServer to pull values


hi there,

i want build arduino windsensor combined webserver shows measured values.
here code.
(i can't find error right now)

#include <spi.h>
#include <ethernet.h>
#include <time.h>
#include <timelib.h>

#define delay 1000
#define sensorid 2

// enter mac address , ip address controller below.
// ip address dependent on local network:
byte mac[] = { <mymac> };  //mac-id, steht auf den ethershield
ipaddress ip(192,168,2,36);

string cmd="";
int cmd_length=0;

unsigned long last_upload=0;
float current_speed=0.0f;
float accum_speed;

unsigned long sum_pulses=0;
unsigned long sum_delay=0;


unsigned long samples;
float current_direction=0.0f;
unsigned long pulses = 0;

// initialize ethernet server library
// ip address , port want use
// (port 80 default http):
ethernetserver server(80);

void setup() {
  // start serial library:
  serial.begin(9600);
  serial.println("hello");
   pinmode(4,output);
   digitalwrite(4,high);


  // start ethernet connection , server:
  ethernet.begin(mac, ip);
  server.begin();
  serial.print("server @ ");
  serial.println(ethernet.localip());
}

void windpulscallback() {
  //  latest_interrupted_pin=pcintport::arduinopin;
  //  interrupt_count[latest_interrupted_pin]++;
  pulses++;
}


void calculatespeed() {
  unsigned long start;
  unsigned long end;
  unsigned long diff;

  // vorbereitung
//  pcintport::attachinterrupt(windspeedpin, &windpulscallback, rising);  // add more attachinterrupt code required
  attachinterrupt(1, windpulscallback, rising);

  // messung starten (5 sekunden)
  pulses=0;
  start=micros();
  delay(delay); // in milliseconds
  end=micros();

  // shutdown
//  pcintport::detachinterrupt(windspeedpin);
  detachinterrupt(1);

  // berechnung
  diff=end-start;
  serial.print("time(in microsec):");
  serial.println(diff);
  serial.print("pulses:");
  serial.println(pulses);
  sum_pulses+=pulses;
  sum_delay+=diff;
 
  current_speed=pulses*1000.0f*delay/6.0f/diff;
  serial.print("speed:");
  serial.println(current_speed);

}

void loop(){
  // listen incoming clients
  ethernetclient client = server.available();
  if (client) {
    serial.println("new client");
    // http request ends blank line
    boolean currentlineisblank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        //        serial.write(c);
        // if you've gotten end of line (received newline
        // character) , line blank, http request has ended,
        // can send reply
        if (c == '\n' && currentlineisblank) {
          break;
        }
        if (c == '\n') {
          // you're starting new line
          currentlineisblank = true;
        }
        else if (c != '\r') {
          // you've gotten character on current line
          currentlineisblank = false;
          if (c=='?'){
            serial.print("commando ? gesendet\n\n");
            while (c!='\r')
            {
              cmd+=c;
              //              serial.print(c);
              c=client.read();
            }
            serial.println(cmd);
            if (cmd.startswith("?cmd")) {
              serial.println("kommando erkannt");
              cmd_length=cmd.length();
              serial.println (cmd_length);
               if (cmd.startswith("?cmd=read_t0"))
                serial.println("kommando lese t0");
             
                client.print(current_speed); 
                cmd="";   
              }

              else{
              serial.println("kein gueltiges kommando erkannt");
              client.println("nicht gültig");

              cmd="";
          }
             
         
        }

      }
    }
    }
    // give web browser time receive data
    delay(1);
    // close connection:
    client.stop();
    serial.println("client disonnected");

  }

  } 
   
  calculatespeed();
  accum_speed+=current_speed;
  samples++;
}




when access url can't actual values of wind speed.
what wrong here ...?!


regards,
alex

please comment code little make easier read , focus question more.

do calculations work? transmitting problem? or reading problem?

if understand more can aswell ;)

best regards
majorprob


Arduino Forum > Using Arduino > Programming Questions > Arduino Windsensor with WebServer to pull values


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'