Weather station loop webserver

Hello arduino fans!

I have been working with the arduino since a couple of months, but now I am at a point where I am stuck.
At this moment I am working on a weather station. It has to create a xml file with the temperature and windspeed and a PHP script catches the information and puts in into a database. So far so good.
My problem is, I can use the data of the windmeter, but only the current state of my windmeter (on/off) and not the current RPM. If i put my webserver in the loop with the RPM counter, my arduino keeps posting the xml data instead of only the current...
How is it possible to let the webserver only show once the XML data but it keeps counting the RPM of the windmeter?

I hope someone could help me,

Roy Schoep

How is it possible to let the webserver only show once the XML data but it keeps counting the RPM of the windmeter?

We need to see your code.

  int tempoutPin = 0;    // select the input pin for the Tempout sensor
  int tempinPin = 1;    // select the input pin for the Tempout sensor
  int hallPin = 2;
  float temperatureout;
  float temperaturein;
  int windSpeed;
  int rpmcount = 0;
  int rpm = 0;
  int timeold = 0;
  int val = 0;
  boolean on;

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,2, 177 };

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Server server(80);

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  windSpeed = 80;
}

void loop()
{
    
  val = analogRead(hallPin);  // read the Hall Effect Sensor


  // If hall effect sensors reading is more than three, set on to true
  if (val > 3)
  {
   on = true;
  }
  
  // If on is true, add one RPM and immediately set on to false
    if (on == true){
      rpmcount++;  
      on = false;
    }
  
   // if rpm count = more than 20, show the time that it took to rotate 20 times.
   if (rpmcount >= 20) { 
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update
     rpm = 30*1000/(millis() - timeold)*rpmcount;
     timeold = millis();
     rpmcount = 0;
     Serial.println(rpm,DEC);
   }
  
      //TEMP OUT    
    temperatureout = getVoltage(tempoutPin);  //getting the voltage reading from the temperature sensor
    int temperature1out = (temperatureout - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
    
    temperatureout = (temperatureout - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
    
        
     //TEMP IN
    temperaturein = getVoltage(tempinPin);  //getting the voltage reading from the temperature sensor
    int temperature1in = (temperaturein - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
    
    temperaturein = (temperaturein - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
    
   
    
   
  
  //Print the XML file to the screen
  
  /////////////////////////////////
    /////////////////////////////////
      /////////////////////////////////
        /////////////////////////////////
   // THIS CODE BELOW SHOULD BE FIRED ONCE EVERYTIME A SCRIPT ACCESSES THE ARDUINO WEBSERVER
     /////////////////////////////////
       /////////////////////////////////
         /////////////////////////////////
           /////////////////////////////////
  
  // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
    

    
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
          client.print("<values>\n");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 3; analogChannel++) {
            client.print("<pin>\n");
            client.print("<channel>");
            client.print(analogChannel);
            client.print("</channel>\n");
            client.print("<value>");
            if(analogChannel == 0){
            client.print(temperatureout); 
            }
            if(analogChannel == 1){
              client.print(temperaturein); 
            }
            
            if(analogChannel == 2){
              client.print(windSpeed);
            }  
         
            //client.print(analogRead(analogChannel));
            
            client.print("</value>\n");
            client.println("</pin>\n");
          }
          client.println("</values>");
          
          
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}


float getVoltage(int tempinPin){
return (analogRead(tempinPin) * .004882814); //converting from a 0 to 1024 digital range
}

I'm confused. The code you posted calculates RPM whenever conditions are right, on every pass through loop. On any given pass, if a client connected, it serves up a page that contains temperature and a hardcoded value for windspeed.

It looks to me like you need to map RPM to windspeed when the client wants to know stuff.

Yes that is true, I hadn't replaced the Windspeed variable when I was finished testing. But that does not solves the page continuously loading. How can i prevent my arduino from sending multiple times the requested information? Is it possible to make an if statement where you set the boolean to false when the webserver has provided you the XML content? How does the boolean resets itself when you access the webserver again?

But that does not solves the page continuously loading. How can i prevent my arduino from sending multiple times the requested information?

I don't see how it is doing that. Of course, your loop() function is very long. It would be better to create some functions, like checkWindData(), getTemperature(), checkForClient(), etc.

In the checkForClient() function, add a Serial.print() statement whenever there is a client connection. Serial.print() the data being sent, too. See if the problem is on the client side or the server side.