Skip to content

eb3nezer/WeatherOrNot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeatherOrNot

WeatherOrNot is an object oriented utility library for Arduino weather station projects. It pulls together a few on-off-keying (OOK) utilities, and provides a simple-to-configure callback interface.

The main class handling the OOK -> binary translation is the popular DecodeOOK class.

Sample Use

Let's cut straight to the code. Suppose you have an Oregon Scientific system (v2 protocol) and you have an indoor temperature/humidity sensor that you want to decode. The 433MHz receiver sends data to digital pin 8.

Let's declare the classes we will need.

#include <WeatherData.h>
#include <WeatherOrNot.h>
#include <OSV2IndoorTempHygroSensor.h>
#include <DecodeOOK.h>
#include <Sensor.h>
#include <OregonDecoderV2.h>

// WeatherOrNot does all the work
WeatherOrNot weatherReceiver;

// Declare the decoder for Oregon Scientific V2 protocol sensors
OregonDecoderV2 oregonv2;
// Declare an Oregon Scientific indoor temperature/hygro sensor
OSV2IndoorTempHygroSensor indoorTempHygro;

Next we do some setup.

void setup () {
    // Add the Oregon v2 indoor temp/hygro sensor to the Oregon v2 decoder
    oregonv2.addSensor((Sensor *)&indoorTempHygro);
    // Add the Oregon v2 decoder to WeatherOrNot
    weatherReceiver.addDecoder(&oregonv2);
    
    // Tell it which pin it will see the data on    
    weatherReceiver.setDataPin(DATA_PIN);
}

A couple of final things. We need to declare a callback function that will get called when some weather data is received. This is a function that takes a pointer to WeatherData, and returns void.

Maybe you want your callback to do something with the data, but here I will make it set a flag that the main loop will see.

int dataReceived = 0;
WeatherData currentWeather;

// Callback comes to here
void newWeather(WeatherData *weatherData)
{
    dataReceived = 1;
}

Now in my setup() I need to tell WeatherOrNot about my callback, and turn on interrupts. Once interrupts are turned on, it will call me if any of my sensors receive data. I also give WeatherOrNot a pointer to the weather data object I would like it to populate.

    // Tell it to call our newWeather() function
    weatherReceiver.setCallback(newWeather, &currentWeather);
    
    // set up my data pin
    pinMode(DATA_PIN, OUTPUT);
    digitalWrite(DATA_PIN, HIGH);
    digitalWrite(DATA_PIN, LOW);
    pinMode(DATA_PIN, INPUT);

    // Turn on interrupts    
    weatherReceiver.setInterrupt(true);
    sei();

Now in my main loop I need to check the dataReceived flag.

void loop () {
    if (dataReceived) {
      // Turn off interrupts so we can process the data
      weatherReceiver.setInterrupt(false);
      // Do someting with the data
      // displayWeather(&currentWeather);
      // clear out the data that was just sent from the weatherData object
      currentWeather.clearDataFields();
      // Turn interrupts back on again
      dataReceived = 0;
      weatherReceiver.setInterrupt(true);
    }

}

See the example OregonTempReader project for more information.

Attribution

I have re-used code from a few sources, and have tried to provide the correct attribution where known (in source code).

License

Apart from non-original code (see Attribution), other code is Copyright (C) 2014 Ben Kelley. This code is licensed under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages