int main(void) { // sets up the wiringPi library if (wiringPiSetup () < 0) { fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)); return 1; } // set Pin 17/0 generate an interrupt on high-to-low transitions // and attach myInterrupt() to the interrupt if ( wiringPiISR (WIND_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) { fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)); return 1; } // display counter value every second. while ( 1 ) { /* Wind is 1.492 mph per event */ printf(" Wind Speed: % 4.2f\n", eventCounter * 1.492 ); printf(" Wind Direction: % 4.2f\n", get_wind_direction() ); eventCounter = 0; delay( 1000 ); // wait 1 second } return 0; }
// // This is invoked for every seconds tick // void seconds_Tick() { // Take a speed and direction reading every second for 2 minute average if(++seconds_2m > 119) seconds_2m = 0; // Calc the wind speed and direction every second for 120 second to get 2 minute average float currentSpeed = get_wind_speed(); //float currentSpeed = random(5); //For testing int currentDirection = get_wind_direction(); windspdavg[seconds_2m] = (int)currentSpeed; winddiravg[seconds_2m] = currentDirection; //if(seconds_2m % 10 == 0) displayArrays(); //For testing //Check to see if this is a gust for the minute if(currentSpeed > windgust_10m[minutes_10m]) { windgust_10m[minutes_10m] = currentSpeed; windgustdirection_10m[minutes_10m] = currentDirection; } //Check to see if this is a gust for the day if(currentSpeed > windgustmph) { windgustmph = currentSpeed; windgustdir = currentDirection; } // // A cloudTimer is used to schedule cloud updates and data print out. // cloudTimer++; if (cloudTimer == cloud_update_rate_in_seconds) { // // Get readings from all sensors. This will update the global // weather variables. // getWeather(); // // NOTE: Doing all cloud operations within one processing // loop will result in a timeout/reset of the Photon. // // So they are staged by the cloud scheduler. // cloudScheduler(); // Reset the interval counter cloudTimer = 0; } }
void compass_handler(CompassHeadingData data) { CompassStatus status = data.compass_status; int heading; char degrees[6]; char compass[2]; switch(status) { case CompassStatusCalibrated: case CompassStatusCalibrating: heading = TRIGANGLE_TO_DEG(TRIG_MAX_ANGLE - (int)data.magnetic_heading); strcpy(compass, get_wind_direction((TRIGANGLE_TO_DEG((int)data.magnetic_heading) + 180) % 360)); snprintf(degrees, sizeof(degrees), "%s", get_wind_direction_text((heading + 180) % 360)); set_compass_layer_text(compass); set_degrees_layer_text(degrees); break; case CompassStatusUnavailable: case CompassStatusDataInvalid: set_compass_layer_text("N"); set_degrees_layer_text("NA"); break; } }
void getWeather() { // Measure Relative Humidity from the HTU21D or Si7021 humidity = sensor.getRH(); // Measure Temperature from the HTU21D or Si7021 tempf = sensor.getTempF(); // // Temperature is measured every time RH is requested. // It is faster, therefore, to read it from previous RH // measurement with getTemp() instead with readTemp() // // Measure the Barometer temperature in F from the MPL3115A2 baroTemp = sensor.readBaroTempF(); // Measure Pressure from the MPL3115A2 pascals = sensor.readPressure(); // If in altitude mode, you can get a reading in feet with this line: //altf = sensor.readAltitudeFt(); getSoilTemp(); // Read the DS18B20 waterproof temp sensor getSoilMositure(); // Read the soil moisture sensor // Calc winddir winddir = get_wind_direction(); // Calc windspeed windspeedmph = get_wind_speed(); // Calc windgustmph // Calc windgustdir // Report the largest windgust today windgustmph = 0; windgustdir = 0; // Calc windspdmph_avg2m float temp = 0; for(int i = 0 ; i < 120 ; i++) { temp += windspdavg[i]; } temp /= 120.0; windspdmph_avg2m = temp; // Calc winddir_avg2m temp = 0; // Can't use winddir_avg2m because it's an int for(int i = 0 ; i < 120 ; i++) { temp += winddiravg[i]; } temp /= 120; winddir_avg2m = temp; // // Calc windgustmph_10m // Calc windgustdir_10m // Find the largest windgust in the last 10 minutes // windgustmph_10m = 0; windgustdir_10m = 0; // Step through the 10 minutes for(int i = 0; i < 10 ; i++) { if(windgust_10m[i] > windgustmph_10m) { windgustmph_10m = windgust_10m[i]; windgustdir_10m = windgustdirection_10m[i]; } } // // Total rainfall for the day is calculated within the interrupt // Calculate amount of rainfall for the last 60 minutes // rainin = 0; for(int i = 0 ; i < 60 ; i++) { rainin += rainHour[i]; } }