cuHead v2

I don’t know if its been covered but I have kinda figured out how to serve up my wind speed and direction data to a local page via cpu/tablet or WiFi enabled smart phone using WiServer.

/*
 * A simple sketch that uses WiServer to serve a web page
 * Using Davis Instraments Anemometer(reed switch) / Wind Vain (Constant rotational Variable resistor)
 */


#include <WiServer.h>

#include <Wire.h>
#include "RTClib.h"
# define anemom 3
#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2
RTC_Millis RTC;
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,201};//192.168.1.201	// IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"Michie Residence"};// max 32 bytes
unsigned char security_type = 2;// 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"webf113b"};	// max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
				};
//-------------------------------------
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
//unsigned char wireless_mode = WIRELESS_MODE_ADHOC;
//You can use the defines as well
//unsigned char wireless_mode = 1;
//unsigned char wireless_mode = 2;
//-------------------------------------
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------


//----Begin Anemometer Params------------------
const float pi = 3.14159265;  // pi number
volatile byte rpmcount;
 unsigned int rpm;
 unsigned long timeold;
 int radio = 50;//Diameter of the wind speed meter from the center of rotation to the center of one of the "CUP'S"
 //----END Anemometer Params------------------
 
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
  
  //----Anemometer Readinigs------------------
  float voltage = analogRead(A4) * (3.3 / 1023.0);//read the voltage from the wind vane
  float RPM = rpm;
  float speedwind =  ((2 * pi * radio * RPM)/60) / 1000;  // Calculate wind speed on m/s
  float wind =  ((speedwind) /2 / 0.445);
  DateTime now = RTC.now();
    const uint8_t h = now.hour();
    const uint8_t hr_12 = h%12;
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
      
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='5;url=/'></HEAD></HTML>");
        WiServer.print("<html>");
    WiServer.print("Current Time:    ");
    if(hr_12 < 10){                                      // Zero padding if value less than 10 ie."09" instead of "9"
      WiServer.print(" ");
      WiServer.print((h > 12) ? h - 12 : ((h == 0) ? 12 : h), DEC); // Conversion to AM/PM  
    }
    else{
      WiServer.print((h > 12) ? h - 12 : ((h == 0) ? 12 : h), DEC); // Conversion to AM/PM
    }
    WiServer.print(':');
    if(now.minute() < 10){                               // Zero padding if value less than 10 ie."09" instead of "9"
      WiServer.print("0");
      WiServer.print(now.minute(), DEC);
    }
    else{
      WiServer.print(now.minute(), DEC);
    }
    if(h < 12){                                          // Adding the AM/PM sufffix
      WiServer.print(" AM");
    }
    else{
      WiServer.print(" PM");
    }
   
        WiServer.print("
");
        WiServer.print(" Winds are:        ");
        WiServer.print (wind);
        WiServer.print(" MPH               ");
        WiServer.print("
");
        WiServer.print(" from the:         ");
        //print out the direction according to the voltage
      if ((voltage >= 3.01)||(voltage < 0.10))WiServer.println(" N   ");
      if ((voltage >= 0.11)&&(voltage < 0.25))WiServer.println(" NNE ");
      if ((voltage >= 0.26)&&(voltage < 0.45))WiServer.println(" NE  ");
      if ((voltage >= 0.46)&&(voltage < 0.65))WiServer.println(" ENE ");
      if ((voltage >= 0.66)&&(voltage < 0.85))WiServer.println(" E   ");
      if ((voltage >= 0.86)&&(voltage < 1.00))WiServer.println(" ESE ");
      if ((voltage >= 1.01)&&(voltage < 1.20))WiServer.println(" SE  ");
      if ((voltage >= 1.21)&&(voltage < 1.30))WiServer.println(" SSE ");
      if ((voltage >= 1.31)&&(voltage < 1.55))WiServer.println(" S   ");
      if ((voltage >= 1.56)&&(voltage < 1.76))WiServer.println(" SSW ");
      if ((voltage >= 1.77)&&(voltage < 1.97))WiServer.println(" SW  ");
      if ((voltage >= 1.98)&&(voltage < 2.20))WiServer.println(" WSW ");
      if ((voltage >= 2.21)&&(voltage < 2.40))WiServer.println(" W   ");
      if ((voltage >= 2.41)&&(voltage < 2.60))WiServer.println(" WNW ");
      if ((voltage >= 2.61)&&(voltage < 2.85))WiServer.println(" NW  ");
      if ((voltage >= 2.86)&&(voltage < 3.00))WiServer.println(" NNW ");
      WiServer.println("
");
        
        WiServer.print(" RPM:           ");
        WiServer.println (RPM);
        
        
        WiServer.print("</html>");
        
        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}


void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  Serial.println("Starting wind speed mesurments");
   RTC.begin(DateTime(__DATE__, __TIME__));
  WiServer.enableVerboseMode(true);
   //----Anemometer Connected to Dig pin 3------------------
  attachInterrupt(1, rpm_fun, FALLING);  //to detect when the switch is opened/closed using 3.3volts to power a reed switch in the anemometer
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
}

void loop(){

  // Run WiServer
  WiServer.server_task();
 if (rpmcount >= 20) { 
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update
     rpm = 15*1000/(millis() - timeold)*rpmcount;
     timeold = millis();
     rpmcount = 0;
     //Serial.println(rpm,DEC);
   }
  delay(10);
}
void rpm_fun()
 {
   rpmcount++;
   //Each rotation, this interrupt function is run twice
 }