Update examples

This commit is contained in:
Henrik Ekblad
2015-09-19 23:54:35 +02:00
parent 9ed25eb8dc
commit 96f702fa4f
44 changed files with 970 additions and 764 deletions
+3 -3
View File
@@ -45,7 +45,7 @@
#endif #endif
/********************************** /**********************************
* Radio selection and modes * Radio selection and node config
***********************************/ ***********************************/
// Selecting radio transport is optional (for a gateway node). // Selecting radio transport is optional (for a gateway node).
@@ -101,7 +101,7 @@
// When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches // When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
// off when blinking // off when blinking
//#define WITH_LEDS_BLINKING_INVERSE //#define MY_WITH_LEDS_BLINKING_INVERSE
// default LEDs blinking period in milliseconds // default LEDs blinking period in milliseconds
@@ -198,7 +198,7 @@
//#define MY_RF24_ENABLE_ENCRYPTION //#define MY_RF24_ENABLE_ENCRYPTION
// Default encrytion key. Override in sketch if needed. // Default encrytion key. Override in sketch if needed.
#ifndef MY_RF24_CE_PIN #ifndef MY_RF24_ENCRYPTKEY
#define MY_RF24_ENCRYPTKEY 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16 #define MY_RF24_ENCRYPTKEY 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16
#endif #endif
+1 -1
View File
@@ -21,7 +21,7 @@
#define MyLeds_h #define MyLeds_h
#ifdef WITH_LEDS_BLINKING_INVERSE #ifdef MY_WITH_LEDS_BLINKING_INVERSE
#define LED_ON 0x1 #define LED_ON 0x1
#define LED_OFF 0x0 #define LED_OFF 0x0
#else #else
@@ -27,12 +27,18 @@
*/ */
#include <SPI.h>
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
MySensor gw;
unsigned long SLEEP_TIME = 900000; // sleep time between reads (seconds * 1000 milliseconds) unsigned long SLEEP_TIME = 900000; // sleep time between reads (seconds * 1000 milliseconds)
int oldBatteryPcnt = 0; int oldBatteryPcnt = 0;
@@ -44,10 +50,9 @@ void setup()
#else #else
analogReference(INTERNAL); analogReference(INTERNAL);
#endif #endif
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Battery Meter", "1.0"); sendSketchInfo("Battery Meter", "1.0");
} }
void loop() void loop()
@@ -77,8 +82,8 @@ void loop()
if (oldBatteryPcnt != batteryPcnt) { if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep // Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt); sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt; oldBatteryPcnt = batteryPcnt;
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -27,14 +27,19 @@
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h> #include <Bounce2.h>
#define CHILD_ID 3 #define CHILD_ID 3
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
MySensor gw;
Bounce debouncer = Bounce(); Bounce debouncer = Bounce();
int oldValue=-1; int oldValue=-1;
@@ -43,9 +48,7 @@ MyMessage msg(CHILD_ID,V_TRIPPED);
void setup() void setup()
{ {
gw.begin(); // Setup the button
// Setup the button
pinMode(BUTTON_PIN,INPUT); pinMode(BUTTON_PIN,INPUT);
// Activate internal pull-up // Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH); digitalWrite(BUTTON_PIN,HIGH);
@@ -57,7 +60,7 @@ void setup()
// Register binary input sensor to gw (they will be created as child devices) // Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
gw.present(CHILD_ID, S_DOOR); present(CHILD_ID, S_DOOR);
} }
@@ -70,7 +73,7 @@ void loop()
if (value != oldValue) { if (value != oldValue) {
// Send in the new value // Send in the new value
gw.send(msg.set(value==HIGH ? 1 : 0)); send(msg.set(value==HIGH ? 1 : 0));
oldValue = value; oldValue = value;
} }
} }
@@ -30,8 +30,14 @@
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#define SKETCH_NAME "Binary Sensor" #define SKETCH_NAME "Binary Sensor"
#define SKETCH_MAJOR_VER "1" #define SKETCH_MAJOR_VER "1"
@@ -56,7 +62,6 @@
#error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same #error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
#endif #endif
MySensor sensor_node;
// Change to V_LIGHT if you use S_LIGHT in presentation below // Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED); MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
@@ -64,8 +69,6 @@ MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
void setup() void setup()
{ {
sensor_node.begin();
// Setup the buttons // Setup the buttons
pinMode(PRIMARY_BUTTON_PIN, INPUT); pinMode(PRIMARY_BUTTON_PIN, INPUT);
pinMode(SECONDARY_BUTTON_PIN, INPUT); pinMode(SECONDARY_BUTTON_PIN, INPUT);
@@ -75,13 +78,13 @@ void setup()
digitalWrite(SECONDARY_BUTTON_PIN, HIGH); digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER); sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
// Register binary input sensor to sensor_node (they will be created as child devices) // Register binary input sensor to sensor_node (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
sensor_node.present(PRIMARY_CHILD_ID, S_DOOR); present(PRIMARY_CHILD_ID, S_DOOR);
sensor_node.present(SECONDARY_CHILD_ID, S_DOOR); present(SECONDARY_CHILD_ID, S_DOOR);
} }
// Loop will iterate on changes on the BUTTON_PINs // Loop will iterate on changes on the BUTTON_PINs
@@ -92,13 +95,13 @@ void loop()
static uint8_t sentValue2=2; static uint8_t sentValue2=2;
// Short delay to allow buttons to properly settle // Short delay to allow buttons to properly settle
sensor_node.sleep(5); sleep(5);
value = digitalRead(PRIMARY_BUTTON_PIN); value = digitalRead(PRIMARY_BUTTON_PIN);
if (value != sentValue) { if (value != sentValue) {
// Value has changed from last transmission, send the updated value // Value has changed from last transmission, send the updated value
sensor_node.send(msg.set(value==HIGH ? 1 : 0)); send(msg.set(value==HIGH ? 1 : 0));
sentValue = value; sentValue = value;
} }
@@ -106,10 +109,10 @@ void loop()
if (value != sentValue2) { if (value != sentValue2) {
// Value has changed from last transmission, send the updated value // Value has changed from last transmission, send the updated value
sensor_node.send(msg2.set(value==HIGH ? 1 : 0)); send(msg2.set(value==HIGH ? 1 : 0));
sentValue2 = value; sentValue2 = value;
} }
// Sleep until something happens with the sensor // Sleep until something happens with the sensor
sensor_node.sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0); sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
} }
@@ -38,9 +38,14 @@
* Contributor: epierre * Contributor: epierre
**/ **/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#define CHILD_ID_AIQ 0 #define CHILD_ID_AIQ 0
#define AIQ_SENSOR_ANALOG_PIN 6 #define AIQ_SENSOR_ANALOG_PIN 6
@@ -50,22 +55,19 @@ unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds
float valAIQ =0.0; float valAIQ =0.0;
float lastAIQ =0.0; float lastAIQ =0.0;
MySensor gw;
MyMessage msg(CHILD_ID_AIQ, V_LEVEL); MyMessage msg(CHILD_ID_AIQ, V_LEVEL);
MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX); MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0"); sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0");
// Register all sensors to gateway (they will be created as child devices) // Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_AIQ, S_AIR_QUALITY); present(CHILD_ID_AIQ, S_AIR_QUALITY);
gw.send(msg2.set("ppm")); send(msg2.set("ppm"));
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT); pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT);
@@ -88,7 +90,7 @@ void loop() {
long co2ppm = 2 * ((duration/1000) - 2); long co2ppm = 2 * ((duration/1000) - 2);
//Serial.print(co2ppm); //Serial.print(co2ppm);
if ((co2ppm != lastAIQ)&&(abs(co2ppm-lastAIQ)>=10)) { if ((co2ppm != lastAIQ)&&(abs(co2ppm-lastAIQ)>=10)) {
gw.send(msg.set((long)ceil(co2ppm))); send(msg.set((long)ceil(co2ppm)));
lastAIQ = ceil(co2ppm); lastAIQ = ceil(co2ppm);
} }
@@ -96,5 +98,5 @@ void loop() {
// Power down the radio. Note that the radio will get powered back up // Power down the radio. Note that the radio will get powered back up
// on the next write() call. // on the next write() call.
gw.sleep(SLEEP_TIME); //sleep for: sleepTime sleep(SLEEP_TIME); //sleep for: sleepTime
} }
@@ -24,13 +24,12 @@
* *
*/ */
#include <SPI.h> #include <MyConfig.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <MySensor.h>
void setup() void setup()
{ {
Serial.begin(BAUD_RATE); Serial.begin(MY_BAUD_RATE);
Serial.println("Started clearing. Please wait..."); Serial.println("Started clearing. Please wait...");
for (int i=0;i<512;i++) { for (int i=0;i<512;i++) {
EEPROM.write(i, 0xff); EEPROM.write(i, 0xff);
@@ -24,8 +24,15 @@
* http://www.mysensors.org/build/temp * http://www.mysensors.org/build/temp
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
#include <OneWire.h> #include <OneWire.h>
@@ -36,7 +43,6 @@
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
MySensor gw;
float lastTemperature[MAX_ATTACHED_DS18B20]; float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0; int numSensors=0;
boolean receivedConfig = false; boolean receivedConfig = false;
@@ -51,40 +57,34 @@ void setup()
// requestTemperatures() will not block current thread // requestTemperatures() will not block current thread
sensors.setWaitForConversion(false); sensors.setWaitForConversion(false);
// Startup and initialize MySensors library. Set callback for incoming messages.
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Temperature Sensor", "1.1"); sendSketchInfo("Temperature Sensor", "1.1");
// Fetch the number of attached temperature sensors // Fetch the number of attached temperature sensors
numSensors = sensors.getDeviceCount(); numSensors = sensors.getDeviceCount();
// Present all sensors to controller // Present all sensors to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
gw.present(i, S_TEMP); present(i, S_TEMP);
} }
} }
void loop() void loop()
{ {
// Process incoming messages (like config from server)
gw.process();
// Fetch temperatures from Dallas sensors // Fetch temperatures from Dallas sensors
sensors.requestTemperatures(); sensors.requestTemperatures();
// query conversion time and sleep until conversion completed // query conversion time and sleep until conversion completed
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
gw.sleep(conversionTime); sleep(conversionTime);
// Read temperatures and send them to controller // Read temperatures and send them to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal // Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
// Only send data if temperature has changed and no error // Only send data if temperature has changed and no error
#if COMPARE_TEMP == 1 #if COMPARE_TEMP == 1
@@ -94,10 +94,10 @@ void loop()
#endif #endif
// Send in the new temperature // Send in the new temperature
gw.send(msg.setSensor(i).set(temperature,1)); send(msg.setSensor(i).set(temperature,1));
// Save new temperatures for next compare // Save new temperatures for next compare
lastTemperature[i]=temperature; lastTemperature[i]=temperature;
} }
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -35,17 +35,21 @@
* http://www.mysensors.org/build/dimmer * http://www.mysensors.org/build/dimmer
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h>
#define SN "DimmableLED" #define SN "DimmableLED"
#define SV "1.1" #define SV "1.1"
#include <MySensor.h>
#include <SPI.h>
#define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin #define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin
#define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim) #define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
MySensor gw;
static int currentLevel = 0; // Current dim level... static int currentLevel = 0; // Current dim level...
MyMessage dimmerMsg(0, V_DIMMER); MyMessage dimmerMsg(0, V_DIMMER);
MyMessage lightMsg(0, V_LIGHT); MyMessage lightMsg(0, V_LIGHT);
@@ -56,15 +60,15 @@ MyMessage lightMsg(0, V_LIGHT);
*/ */
void setup() void setup()
{ {
Serial.println( SN ); // Initialize library and add callback for incoming messages (signing is required)
gw.begin( incomingMessage ); setIncomingCallback(incomingMessage);
// Register the LED Dimmable Light with the gateway // Register the LED Dimmable Light with the gateway
gw.present( 0, S_DIMMER ); present( 0, S_DIMMER );
gw.sendSketchInfo(SN, SV); sendSketchInfo(SN, SV);
// Pull the gateway's current dim level - restore light level upon sendor node power-up // Pull the gateway's current dim level - restore light level upon sendor node power-up
gw.request( 0, V_DIMMER ); request( 0, V_DIMMER );
} }
/*** /***
@@ -72,7 +76,6 @@ void setup()
*/ */
void loop() void loop()
{ {
gw.process();
} }
@@ -98,10 +101,10 @@ void incomingMessage(const MyMessage &message) {
fadeToLevel( requestedLevel ); fadeToLevel( requestedLevel );
// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value... // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0)); send(lightMsg.set(currentLevel > 0 ? 1 : 0));
// hek comment: Is this really nessesary? // hek comment: Is this really nessesary?
gw.send( dimmerMsg.set(currentLevel) ); send( dimmerMsg.set(currentLevel) );
} }
@@ -29,7 +29,13 @@
* *
*/ */
#include <SPI.h> // Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#define CHILD_ID_LIGHT 1 #define CHILD_ID_LIGHT 1
@@ -46,24 +52,24 @@
int LastLightState=LIGHT_OFF; int LastLightState=LIGHT_OFF;
int LastDimValue=100; int LastDimValue=100;
MySensor gw;
MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT); MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);
MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER); MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
void setup() void setup()
{ {
gw.begin(incomingMessage, AUTO, false); // Initialize library and add callback for incoming messages (signing is required)
setIncomingCallback(incomingMessage);
// Send the Sketch Version Information to the Gateway // Send the Sketch Version Information to the Gateway
gw.sendSketchInfo(SN, SV); sendSketchInfo(SN, SV);
gw.present(CHILD_ID_LIGHT, S_DIMMER ); present(CHILD_ID_LIGHT, S_DIMMER );
//Retreive our last light state from the eprom //Retreive our last light state from the eprom
int LightState=gw.loadState(EPROM_LIGHT_STATE); int LightState=loadState(EPROM_LIGHT_STATE);
if (LightState<=1) { if (LightState<=1) {
LastLightState=LightState; LastLightState=LightState;
int DimValue=gw.loadState(EPROM_DIMMER_LEVEL); int DimValue=loadState(EPROM_DIMMER_LEVEL);
if ((DimValue>0)&&(DimValue<=100)) { if ((DimValue>0)&&(DimValue<=100)) {
//There should be no Dim value of 0, this would mean LIGHT_OFF //There should be no Dim value of 0, this would mean LIGHT_OFF
LastDimValue=DimValue; LastDimValue=DimValue;
@@ -78,9 +84,6 @@ void setup()
void loop() void loop()
{ {
//delay(1000); // Removed by hek
// Process incoming messages (like config and light state from controller)
gw.process();
} }
void incomingMessage(const MyMessage &message) void incomingMessage(const MyMessage &message)
@@ -94,14 +97,14 @@ void incomingMessage(const MyMessage &message)
return; return;
} }
LastLightState=lstate; LastLightState=lstate;
gw.saveState(EPROM_LIGHT_STATE, LastLightState); saveState(EPROM_LIGHT_STATE, LastLightState);
if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) { if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
//In the case that the Light State = On, but the dimmer value is zero, //In the case that the Light State = On, but the dimmer value is zero,
//then something (probably the controller) did something wrong, //then something (probably the controller) did something wrong,
//for the Dim value to 100% //for the Dim value to 100%
LastDimValue=100; LastDimValue=100;
gw.saveState(EPROM_DIMMER_LEVEL, LastDimValue); saveState(EPROM_DIMMER_LEVEL, LastDimValue);
} }
//When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value //When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
@@ -121,7 +124,7 @@ void incomingMessage(const MyMessage &message)
else { else {
LastLightState=LIGHT_ON; LastLightState=LIGHT_ON;
LastDimValue=dimvalue; LastDimValue=dimvalue;
gw.saveState(EPROM_DIMMER_LEVEL, LastDimValue); saveState(EPROM_DIMMER_LEVEL, LastDimValue);
} }
} }
else { else {
@@ -150,10 +153,10 @@ void SetCurrentState2Hardware()
void SendCurrentState2Controller() void SendCurrentState2Controller()
{ {
if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) { if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
gw.send(dimmerMsg.set(0)); send(dimmerMsg.set(0));
} }
else { else {
gw.send(dimmerMsg.set(LastDimValue)); send(dimmerMsg.set(LastDimValue));
} }
} }
@@ -41,10 +41,16 @@
*/ */
#include <SPI.h> // Enable debug prints
#include <Encoder.h> #define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <Bounce2.h> #include <Bounce2.h>
#include <Encoder.h>
#define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin #define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin
#define KNOB_ENC_PIN_1 4 // Rotary encoder input pin 1 #define KNOB_ENC_PIN_1 4 // Rotary encoder input pin 1
@@ -73,13 +79,15 @@ unsigned long lastFadeStep;
unsigned long sendDimTimeout; unsigned long sendDimTimeout;
char convBuffer[10]; char convBuffer[10];
MySensor gw;
MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER); MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
Encoder knob(KNOB_ENC_PIN_1, KNOB_ENC_PIN_2); Encoder knob(KNOB_ENC_PIN_1, KNOB_ENC_PIN_2);
Bounce debouncer = Bounce(); Bounce debouncer = Bounce();
void setup() void setup()
{ {
// Initialize library and add callback for incoming messages (signing is required)
setIncomingCallback(incomingMessage);
// Set knob button pin as input (with debounce) // Set knob button pin as input (with debounce)
pinMode(KNOB_BUTTON_PIN, INPUT); pinMode(KNOB_BUTTON_PIN, INPUT);
digitalWrite(KNOB_BUTTON_PIN, HIGH); digitalWrite(KNOB_BUTTON_PIN, HIGH);
@@ -90,28 +98,22 @@ void setup()
// Set analog led pin to off // Set analog led pin to off
analogWrite( LED_PIN, 0); analogWrite( LED_PIN, 0);
// Init mysensors library
gw.begin(incomingMessage, AUTO, false);
// Send the Sketch Version Information to the Gateway // Send the Sketch Version Information to the Gateway
gw.present(CHILD_ID_LIGHT, S_DIMMER); present(CHILD_ID_LIGHT, S_DIMMER);
gw.sendSketchInfo(SN, SV); sendSketchInfo(SN, SV);
// Retreive our last dim levels from the eprom // Retreive our last dim levels from the eprom
fadeTo = dimValue = 0; fadeTo = dimValue = 0;
byte oldLevel = loadLevelState(EEPROM_DIM_LEVEL_LAST); byte oldLevel = loadLevelState(EEPROM_DIM_LEVEL_LAST);
Serial.print("Sending in last known light level to controller: "); Serial.print("Sending in last known light level to controller: ");
Serial.println(oldLevel); Serial.println(oldLevel);
gw.send(dimmerMsg.set(oldLevel), true); send(dimmerMsg.set(oldLevel), true);
Serial.println("Ready to receive messages..."); Serial.println("Ready to receive messages...");
} }
void loop() void loop()
{ {
// Process incoming messages (like config and light state from controller)
gw.process();
// Check if someone turned the rotary encode // Check if someone turned the rotary encode
checkRotaryEncoder(); checkRotaryEncoder();
@@ -133,7 +135,7 @@ void incomingMessage(const MyMessage &message)
newLevel = loadLevelState(EEPROM_DIM_LEVEL_SAVE); newLevel = loadLevelState(EEPROM_DIM_LEVEL_SAVE);
} }
// Send dimmer level back to controller with ack enabled // Send dimmer level back to controller with ack enabled
gw.send(dimmerMsg.set(newLevel), true); send(dimmerMsg.set(newLevel), true);
// We do not change any levels here until ack comes back from gateway // We do not change any levels here until ack comes back from gateway
return; return;
} else if (message.type == V_DIMMER) { } else if (message.type == V_DIMMER) {
@@ -190,7 +192,7 @@ void checkButtonClick() {
int saved = loadLevelState(EEPROM_DIM_LEVEL_SAVE); int saved = loadLevelState(EEPROM_DIM_LEVEL_SAVE);
newLevel = saved > 0 ? saved : 100; newLevel = saved > 0 ? saved : 100;
} }
gw.send(dimmerMsg.set(newLevel),true); send(dimmerMsg.set(newLevel),true);
} }
oldButtonVal = buttonVal; oldButtonVal = buttonVal;
} }
@@ -220,17 +222,17 @@ void fadeStep() {
if (sendDimValue && currentTime > sendDimTimeout + SEND_THROTTLE_DELAY) { if (sendDimValue && currentTime > sendDimTimeout + SEND_THROTTLE_DELAY) {
// We're done fading.. send in new dim-value to controller. // We're done fading.. send in new dim-value to controller.
// Send in new dim value with ack (will be picked up in incomingMessage) // Send in new dim value with ack (will be picked up in incomingMessage)
gw.send(dimmerMsg.set(dimValue), true); // Send new dimmer value and request ack back send(dimmerMsg.set(dimValue), true); // Send new dimmer value and request ack back
sendDimValue = false; sendDimValue = false;
} }
} }
// Make sure only to store/fetch values in the range 0-100 from eeprom // Make sure only to store/fetch values in the range 0-100 from eeprom
int loadLevelState(byte pos) { int loadLevelState(byte pos) {
return min(max(gw.loadState(pos),0),100); return min(max(loadState(pos),0),100);
} }
void saveLevelState(byte pos, byte data) { void saveLevelState(byte pos, byte data) {
gw.saveState(pos,min(max(data,0),100)); saveState(pos,min(max(data,0),100));
} }
@@ -26,7 +26,13 @@
* http://www.mysensors.org/build/distance * http://www.mysensors.org/build/distance
*/ */
#include <SPI.h> // Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <NewPing.h> #include <NewPing.h>
@@ -36,7 +42,6 @@
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds) unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
MySensor gw;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
MyMessage msg(CHILD_ID, V_DISTANCE); MyMessage msg(CHILD_ID, V_DISTANCE);
int lastDist; int lastDist;
@@ -44,14 +49,12 @@ boolean metric = true;
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Distance Sensor", "1.0"); sendSketchInfo("Distance Sensor", "1.0");
// Register all sensors to gw (they will be created as child devices) // Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID, S_DISTANCE); present(CHILD_ID, S_DISTANCE);
metric = gw.getConfig().isMetric; metric = getConfig().isMetric;
} }
void loop() void loop()
@@ -62,11 +65,11 @@ void loop()
Serial.println(metric?" cm":" in"); Serial.println(metric?" cm":" in");
if (dist != lastDist) { if (dist != lastDist) {
gw.send(msg.set(dist)); send(msg.set(dist));
lastDist = dist; lastDist = dist;
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -38,8 +38,14 @@
* *
*/ */
// Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#define CHILD_ID_DUST 0 #define CHILD_ID_DUST 0
#define DUST_SENSOR_ANALOG_PIN 1 #define DUST_SENSOR_ANALOG_PIN 1
@@ -56,19 +62,15 @@ float voMeasured = 0;
float calcVoltage = 0; float calcVoltage = 0;
float dustDensity = 0; float dustDensity = 0;
MySensor gw;
MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL); MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Dust Sensor", "1.1"); sendSketchInfo("Dust Sensor", "1.1");
// Register all sensors to gateway (they will be created as child devices) // Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_DUST, S_DUST); present(CHILD_ID_DUST, S_DUST);
} }
void loop() void loop()
@@ -93,9 +95,9 @@ void loop()
Serial.println(dustDensity); // unit: ug/m3 Serial.println(dustDensity); // unit: ug/m3
if (ceil(dustDensity) != lastDUST) { if (ceil(dustDensity) != lastDUST) {
gw.send(dustMsg.set((int)ceil(dustDensity))); send(dustMsg.set((int)ceil(dustDensity)));
lastDUST = ceil(dustDensity); lastDUST = ceil(dustDensity);
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -30,9 +30,14 @@
* Contributor: epierre * Contributor: epierre
**/ **/
// Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#define CHILD_ID_DUST_PM10 0 #define CHILD_ID_DUST_PM10 0
#define CHILD_ID_DUST_PM25 1 #define CHILD_ID_DUST_PM25 1
@@ -55,7 +60,6 @@ float ratio = 0;
long concentrationPM25 = 0; long concentrationPM25 = 0;
long concentrationPM10 = 0; long concentrationPM10 = 0;
MySensor gw;
MyMessage dustMsgPM10(CHILD_ID_DUST_PM10, V_LEVEL); MyMessage dustMsgPM10(CHILD_ID_DUST_PM10, V_LEVEL);
MyMessage msgPM10(CHILD_ID_DUST_PM10, V_UNIT_PREFIX); MyMessage msgPM10(CHILD_ID_DUST_PM10, V_UNIT_PREFIX);
MyMessage dustMsgPM25(CHILD_ID_DUST_PM25, V_LEVEL); MyMessage dustMsgPM25(CHILD_ID_DUST_PM25, V_LEVEL);
@@ -63,20 +67,17 @@ MyMessage msgPM25(CHILD_ID_DUST_PM25, V_UNIT_PREFIX);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Dust Sensor DSM501", "1.4"); sendSketchInfo("Dust Sensor DSM501", "1.4");
// Register all sensors to gateway (they will be created as child devices) // Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_DUST_PM10, S_DUST); present(CHILD_ID_DUST_PM10, S_DUST);
gw.send(msgPM10.set("ppm")); send(msgPM10.set("ppm"));
gw.present(CHILD_ID_DUST_PM25, S_DUST); present(CHILD_ID_DUST_PM25, S_DUST);
gw.send(msgPM25.set("ppm")); send(msgPM25.set("ppm"));
pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT); pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT);
pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT); pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT);
} }
void loop() void loop()
@@ -89,10 +90,11 @@ void loop()
Serial.print("\n"); Serial.print("\n");
if ((concentrationPM25 != lastDUSTPM25)&&(concentrationPM25>0)) { if ((concentrationPM25 != lastDUSTPM25)&&(concentrationPM25>0)) {
gw.send(dustMsgPM25.set((long)ceil(concentrationPM25))); send(dustMsgPM25.set((long)ceil(concentrationPM25)));
lastDUSTPM25 = ceil(concentrationPM25); lastDUSTPM25 = ceil(concentrationPM25);
} }
//get PM 1.0 - density of particles over 1 μm.
//get PM 1.0 - density of particles over 1 μm.
concentrationPM10=getPM(DUST_SENSOR_DIGITAL_PIN_PM10); concentrationPM10=getPM(DUST_SENSOR_DIGITAL_PIN_PM10);
Serial.print("PM10: "); Serial.print("PM10: ");
Serial.println(concentrationPM10); Serial.println(concentrationPM10);
@@ -103,12 +105,12 @@ void loop()
long ppmv=(concentrationPM10*0.0283168/100/1000) * (0.08205*temp)/0.01; long ppmv=(concentrationPM10*0.0283168/100/1000) * (0.08205*temp)/0.01;
if ((ceil(concentrationPM10) != lastDUSTPM10)&&((long)concentrationPM10>0)) { if ((ceil(concentrationPM10) != lastDUSTPM10)&&((long)concentrationPM10>0)) {
gw.send(dustMsgPM10.set((long)ppmv)); send(dustMsgPM10.set((long)ppmv));
lastDUSTPM10 = ceil(concentrationPM10); lastDUSTPM10 = ceil(concentrationPM10);
} }
//sleep to save on radio //sleep to save on radio
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -34,7 +34,13 @@
* http://www.mysensors.org/build/pulse_power * http://www.mysensors.org/build/pulse_power
*/ */
#include <SPI.h> // Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!)
@@ -43,8 +49,8 @@
#define MAX_WATT 10000 // Max watt value to report. This filetrs outliers. #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers.
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define CHILD_ID 1 // Id of the sensor child #define CHILD_ID 1 // Id of the sensor child
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
MySensor gw;
double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
boolean pcReceived = false; boolean pcReceived = false;
volatile unsigned long pulseCount = 0; volatile unsigned long pulseCount = 0;
@@ -61,16 +67,17 @@ MyMessage pcMsg(CHILD_ID,V_VAR1);
void setup() void setup()
{ {
gw.begin(incomingMessage); // Initialize library and add callback for incoming messages (signing is required)
setIncomingCallback(incomingMessage);
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Energy Meter", "1.0"); sendSketchInfo("Energy Meter", "1.0");
// Register this device as power sensor // Register this device as power sensor
gw.present(CHILD_ID, S_POWER); present(CHILD_ID, S_POWER);
// Fetch last known pulse count value from gw // Fetch last known pulse count value from gw
gw.request(CHILD_ID, V_VAR1); request(CHILD_ID, V_VAR1);
attachInterrupt(INTERRUPT, onPulse, RISING); attachInterrupt(INTERRUPT, onPulse, RISING);
lastSend=millis(); lastSend=millis();
@@ -79,7 +86,6 @@ void setup()
void loop() void loop()
{ {
gw.process();
unsigned long now = millis(); unsigned long now = millis();
// Only send values at a maximum frequency or woken up from sleep // Only send values at a maximum frequency or woken up from sleep
bool sendTime = now - lastSend > SEND_FREQUENCY; bool sendTime = now - lastSend > SEND_FREQUENCY;
@@ -89,7 +95,7 @@ void loop()
// Check that we dont get unresonable large watt value. // Check that we dont get unresonable large watt value.
// could hapen when long wraps or false interrupt triggered // could hapen when long wraps or false interrupt triggered
if (watt<((unsigned long)MAX_WATT)) { if (watt<((unsigned long)MAX_WATT)) {
gw.send(wattMsg.set(watt)); // Send watt value to gw send(wattMsg.set(watt)); // Send watt value to gw
} }
Serial.print("Watt:"); Serial.print("Watt:");
Serial.println(watt); Serial.println(watt);
@@ -98,23 +104,23 @@ void loop()
// Pulse cout has changed // Pulse cout has changed
if (pulseCount != oldPulseCount) { if (pulseCount != oldPulseCount) {
gw.send(pcMsg.set(pulseCount)); // Send pulse count value to gw send(pcMsg.set(pulseCount)); // Send pulse count value to gw
double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
oldPulseCount = pulseCount; oldPulseCount = pulseCount;
if (kwh != oldKwh) { if (kwh != oldKwh) {
gw.send(kwhMsg.set(kwh, 4)); // Send kwh value to gw send(kwhMsg.set(kwh, 4)); // Send kwh value to gw
oldKwh = kwh; oldKwh = kwh;
} }
} }
lastSend = now; lastSend = now;
} else if (sendTime && !pcReceived) { } else if (sendTime && !pcReceived) {
// No count received. Try requesting it again // No count received. Try requesting it again
gw.request(CHILD_ID, V_VAR1); request(CHILD_ID, V_VAR1);
lastSend=now; lastSend=now;
} }
if (SLEEP_MODE) { if (SLEEP_MODE) {
gw.sleep(SEND_FREQUENCY); sleep(SEND_FREQUENCY);
} }
} }
@@ -63,11 +63,9 @@
#define MY_RADIO_NRF24 #define MY_RADIO_NRF24
//#define MY_RADIO_RFM69 //#define MY_RADIO_RFM69
//#define MY_RF24_ENABLE_ENCRYPTION
// Enable gateway transportation type // Enable gateway transportation type
//#define MY_GATEWAY_W5100 #define MY_GATEWAY_W5100
#define MY_GATEWAY_ENC28J60 //#define MY_GATEWAY_ENC28J60
// Enable Soft SPI for radio (note different radio wiring required) // Enable Soft SPI for radio (note different radio wiring required)
// Useful for W5100 which sometimes have hard time co-operate with radio on the same spi bus. // Useful for W5100 which sometimes have hard time co-operate with radio on the same spi bus.
@@ -27,7 +27,13 @@
* http://www.mysensors.org/build/humidity * http://www.mysensors.org/build/humidity
*/ */
#include <SPI.h> // Enable debug prints
//#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <DHT.h> #include <DHT.h>
@@ -36,7 +42,6 @@
#define HUMIDITY_SENSOR_DIGITAL_PIN 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 3
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MySensor gw;
DHT dht; DHT dht;
float lastTemp; float lastTemp;
float lastHum; float lastHum;
@@ -47,17 +52,16 @@ MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
void setup() void setup()
{ {
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway // Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("Humidity", "1.0"); sendSketchInfo("Humidity", "1.0");
// Register all sensors to gw (they will be created as child devices) // Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_HUM, S_HUM);
gw.present(CHILD_ID_TEMP, S_TEMP); present(CHILD_ID_TEMP, S_TEMP);
metric = gw.getConfig().isMetric; metric = getConfig().isMetric;
} }
void loop() void loop()
@@ -72,7 +76,7 @@ void loop()
if (!metric) { if (!metric) {
temperature = dht.toFahrenheit(temperature); temperature = dht.toFahrenheit(temperature);
} }
gw.send(msgTemp.set(temperature, 1)); send(msgTemp.set(temperature, 1));
Serial.print("T: "); Serial.print("T: ");
Serial.println(temperature); Serial.println(temperature);
} }
@@ -82,12 +86,12 @@ void loop()
Serial.println("Failed reading humidity from DHT"); Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum) { } else if (humidity != lastHum) {
lastHum = humidity; lastHum = humidity;
gw.send(msgHum.set(humidity, 1)); send(msgHum.set(humidity, 1));
Serial.print("H: "); Serial.print("H: ");
Serial.println(humidity); Serial.println(humidity);
} }
gw.sleep(SLEEP_TIME); //sleep a bit sleep(SLEEP_TIME); //sleep a bit
} }
@@ -31,8 +31,14 @@
* http://www.mysensors.org/build/ir * http://www.mysensors.org/build/ir
*/ */
// Enable debug prints
//#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <IRLib.h> #include <IRLib.h>
int RECV_PIN = 8; int RECV_PIN = 8;
@@ -44,26 +50,24 @@ IRrecv irrecv(RECV_PIN);
IRdecode decoder; IRdecode decoder;
//decode_results results; //decode_results results;
unsigned int Buffer[RAWBUF]; unsigned int Buffer[RAWBUF];
MySensor gw;
MyMessage msg(CHILD_1, V_VAR1); MyMessage msg(CHILD_1, V_VAR1);
void setup() void setup()
{ {
irrecv.enableIRIn(); // Start the ir receiver irrecv.enableIRIn(); // Start the ir receiver
decoder.UseExtnBuf(Buffer); decoder.UseExtnBuf(Buffer);
gw.begin(incomingMessage); setIncomingCallback(incomingMessage);
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("IR Sensor", "1.0"); sendSketchInfo("IR Sensor", "1.0");
// Register a sensors to gw. Use binary light for test purposes. // Register a sensors to Use binary light for test purposes.
gw.present(CHILD_1, S_LIGHT); present(CHILD_1, S_LIGHT);
} }
void loop() void loop()
{ {
gw.process();
if (irrecv.GetResults(&decoder)) { if (irrecv.GetResults(&decoder)) {
irrecv.resume(); irrecv.resume();
decoder.decode(); decoder.decode();
@@ -72,7 +76,7 @@ void loop()
char buffer[10]; char buffer[10];
sprintf(buffer, "%08lx", decoder.value); sprintf(buffer, "%08lx", decoder.value);
// Send ir result to gw // Send ir result to gw
gw.send(msg.set(buffer)); send(msg.set(buffer));
} }
} }
@@ -80,18 +80,25 @@ INSTRUCTIONS:
Contributed by Jim (BulldogLowell@gmail.com) with much contribution from Pete (pete.will@mysensors.org) and is released to the public domain Contributed by Jim (BulldogLowell@gmail.com) with much contribution from Pete (pete.will@mysensors.org) and is released to the public domain
*/ */
// //
// Enable debug prints
//#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
//#define MY_NODE_ID 1 // Set this to fix your Radio ID or use Auto
#include <Wire.h> #include <Wire.h>
#include <Time.h> #include <Time.h>
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
//
#define NUMBER_OF_VALVES 8 // Change this to set your valve count up to 16. #define NUMBER_OF_VALVES 8 // Change this to set your valve count up to 16.
#define VALVE_RESET_TIME 7500UL // Change this (in milliseconds) for the time you need your valves to hydraulically reset and change state #define VALVE_RESET_TIME 7500UL // Change this (in milliseconds) for the time you need your valves to hydraulically reset and change state
#define RADIO_ID AUTO // Change this to fix your Radio ID or use Auto
#define SKETCH_NAME "MySprinkler" #define SKETCH_NAME "MySprinkler"
#define SKETCH_VERSION "2.0" #define SKETCH_VERSION "2.0"
@@ -113,7 +120,6 @@ Contributed by Jim (BulldogLowell@gmail.com) with much contribution from Pete (p
#ifdef DEBUG_ON #ifdef DEBUG_ON
#define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINT(x) Serial.print(x)
#define DEBUG_PRINTLN(x) Serial.println(x) #define DEBUG_PRINTLN(x) Serial.println(x)
#define SERIAL_START(x) Serial.begin(x)
#else #else
#define DEBUG_PRINT(x) #define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x) #define DEBUG_PRINTLN(x)
@@ -161,15 +167,15 @@ byte raindrop[8] = {0x4, 0x4, 0xA, 0xA, 0x11, 0xE, 0x0,}; // fetching Valve Data
// Set the pins on the I2C chip used for LCD connections: // Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address to 0x27 LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address to 0x27
MySensor gw;
// //
MyMessage msg1valve(CHILD_ID_SPRINKLER, V_LIGHT); MyMessage msg1valve(CHILD_ID_SPRINKLER, V_LIGHT);
MyMessage var1valve(CHILD_ID_SPRINKLER, V_VAR1); MyMessage var1valve(CHILD_ID_SPRINKLER, V_VAR1);
MyMessage var2valve(CHILD_ID_SPRINKLER, V_VAR2); MyMessage var2valve(CHILD_ID_SPRINKLER, V_VAR2);
bool receivedInitialValue = false;
// //
void setup() void setup()
{ {
SERIAL_START(115200);
DEBUG_PRINTLN(F("Initialising...")); DEBUG_PRINTLN(F("Initialising..."));
pinMode(latchPin, OUTPUT); pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT); pinMode(clockPin, OUTPUT);
@@ -191,20 +197,20 @@ void setup()
//check for saved date in EEPROM //check for saved date in EEPROM
DEBUG_PRINTLN(F("Checking EEPROM for stored date:")); DEBUG_PRINTLN(F("Checking EEPROM for stored date:"));
delay(500); delay(500);
if (gw.loadState(0) == 0xFF) // EEPROM flag if (loadState(0) == 0xFF) // EEPROM flag
{ {
DEBUG_PRINTLN(F("Retreiving last run time from EEPROM...")); DEBUG_PRINTLN(F("Retreiving last run time from EEPROM..."));
for (int i = 0; i < 4 ; i++) for (int i = 0; i < 4 ; i++)
{ {
lastTimeRun = lastTimeRun << 8; lastTimeRun = lastTimeRun << 8;
lastTimeRun = lastTimeRun | gw.loadState(i + 1); // assemble 4 bytes into an ussigned long epoch timestamp lastTimeRun = lastTimeRun | loadState(i + 1); // assemble 4 bytes into an ussigned long epoch timestamp
} }
} }
gw.begin(getVariables, RADIO_ID, false); // Change 'false' to 'true' to create a Radio repeating node setIncomingCallback(getVariables);
gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
for (byte i = 0; i <= NUMBER_OF_VALVES; i++) for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
{ {
gw.present(i, S_LIGHT); present(i, S_LIGHT);
} }
DEBUG_PRINTLN(F("Sensor Presentation Complete")); DEBUG_PRINTLN(F("Sensor Presentation Complete"));
// //
@@ -219,10 +225,9 @@ void setup()
int clockCounter = 0; int clockCounter = 0;
while (timeStatus() == timeNotSet && clockCounter < 21) while (timeStatus() == timeNotSet && clockCounter < 21)
{ {
gw.process(); requestTime(receiveTime);
gw.requestTime(receiveTime);
DEBUG_PRINTLN(F("Requesting time from Gateway:")); DEBUG_PRINTLN(F("Requesting time from Gateway:"));
delay(1000); wait(1000);
lcd.print("."); lcd.print(".");
clockCounter++; clockCounter++;
if (clockCounter > 16) if (clockCounter > 16)
@@ -232,7 +237,7 @@ void setup()
lcd.print(F(" Failed Clock ")); lcd.print(F(" Failed Clock "));
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F(" Syncronization ")); lcd.print(F(" Syncronization "));
delay(2000); wait(2000);
break; break;
} }
} }
@@ -249,29 +254,31 @@ void setup()
DEBUG_PRINT(F("Calling for Valve ")); DEBUG_PRINT(F("Calling for Valve "));
DEBUG_PRINT(i); DEBUG_PRINT(i);
DEBUG_PRINTLN(F(" Data...")); DEBUG_PRINTLN(F(" Data..."));
while (gw.process() == false) while (!receivedInitialValue)
{ {
lcd.setCursor(15, 0); lcd.setCursor(15, 0);
flashIcon = !flashIcon; flashIcon = !flashIcon;
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" ")); flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
gw.request(i, V_VAR1); request(i, V_VAR1);
delay(100); wait(500);
} }
while (gw.process() == false) receivedInitialValue = false;
while (!receivedInitialValue)
{ {
lcd.setCursor(15, 0); lcd.setCursor(15, 0);
flashIcon = !flashIcon; flashIcon = !flashIcon;
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" ")); flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
gw.request(i, V_VAR2); request(i, V_VAR2);
delay(100); wait(500);
} }
while (gw.process() == false) receivedInitialValue = false;
while (!receivedInitialValue)
{ {
lcd.setCursor(15, 0); lcd.setCursor(15, 0);
flashIcon = !flashIcon; flashIcon = !flashIcon;
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" ")); flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
gw.request(i, V_VAR3); request(i, V_VAR3);
delay(100); wait(500);
} }
} }
lcd.clear(); lcd.clear();
@@ -279,7 +286,6 @@ void setup()
// //
void loop() void loop()
{ {
gw.process();
updateClock(); updateClock();
updateDisplay(); updateDisplay();
goGetValveTimes(); goGetValveTimes();
@@ -316,15 +322,15 @@ void loop()
DEBUG_PRINTLN(F("State Changed... all Zones off")); DEBUG_PRINTLN(F("State Changed... all Zones off"));
for (byte i = 0; i <= NUMBER_OF_VALVES; i++) for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
{ {
delay(50); wait(50);
gw.send(msg1valve.setSensor(i).set(false), false); send(msg1valve.setSensor(i).set(false), false);
} }
lcd.clear(); lcd.clear();
lcd.setCursor(0,0); lcd.setCursor(0,0);
lcd.print(F("** Irrigation **")); lcd.print(F("** Irrigation **"));
lcd.setCursor(0,1); lcd.setCursor(0,1);
lcd.print(F("** Halted **")); lcd.print(F("** Halted **"));
delay(2000); wait(2000);
lastValve = -1; lastValve = -1;
} }
} }
@@ -337,11 +343,11 @@ void loop()
{ {
if (i == 0 || i == valveNumber) if (i == 0 || i == valveNumber)
{ {
gw.send(msg1valve.setSensor(i).set(true), false); send(msg1valve.setSensor(i).set(true), false);
} }
else else
{ {
gw.send(msg1valve.setSensor(i).set(false), false); send(msg1valve.setSensor(i).set(false), false);
} }
} }
} }
@@ -377,7 +383,7 @@ void loop()
saveDateToEEPROM(lastTimeRun); saveDateToEEPROM(lastTimeRun);
for (byte i = 0; i <= NUMBER_OF_VALVES; i++) for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
{ {
gw.send(msg1valve.setSensor(i).set(false), false); send(msg1valve.setSensor(i).set(false), false);
} }
DEBUG_PRINT(F("State = ")); DEBUG_PRINT(F("State = "));
DEBUG_PRINTLN(state); DEBUG_PRINTLN(state);
@@ -394,11 +400,11 @@ void loop()
{ {
if (i == 0 || i == valveNumber) if (i == 0 || i == valveNumber)
{ {
gw.send(msg1valve.setSensor(i).set(true), false); send(msg1valve.setSensor(i).set(true), false);
} }
else else
{ {
gw.send(msg1valve.setSensor(i).set(false), false); send(msg1valve.setSensor(i).set(false), false);
} }
} }
DEBUG_PRINTLN(F("State Changed, Single Zone Running...")); DEBUG_PRINTLN(F("State Changed, Single Zone Running..."));
@@ -419,7 +425,7 @@ void loop()
updateRelays(ALL_VALVES_OFF); updateRelays(ALL_VALVES_OFF);
for (byte i = 0; i <= NUMBER_OF_VALVES; i++) for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
{ {
gw.send(msg1valve.setSensor(i).set(false), false); send(msg1valve.setSensor(i).set(false), false);
} }
state = CYCLE_COMPLETE; state = CYCLE_COMPLETE;
startMillis = millis(); startMillis = millis();
@@ -577,6 +583,7 @@ void getVariables(const MyMessage &message)
zoneTimeUpdate = true; zoneTimeUpdate = true;
} }
receivedInitialValue = true;
} }
else if (message.type == V_VAR2) else if (message.type == V_VAR2)
{ {
@@ -590,6 +597,7 @@ void getVariables(const MyMessage &message)
valveSoloTime[i] = variable2; valveSoloTime[i] = variable2;
zoneTimeUpdate = true; zoneTimeUpdate = true;
} }
receivedInitialValue = true;
} }
else if (message.type == V_VAR3) else if (message.type == V_VAR3)
{ {
@@ -611,6 +619,7 @@ void getVariables(const MyMessage &message)
DEBUG_PRINT(F(" and it is now called: ")); DEBUG_PRINT(F(" and it is now called: "));
DEBUG_PRINTLN(valveNickName[i]); DEBUG_PRINTLN(valveNickName[i]);
} }
receivedInitialValue = true;
} }
} }
if (zoneTimeUpdate) if (zoneTimeUpdate)
@@ -826,7 +835,7 @@ void updateClock()
lcd.setCursor(15, 0); lcd.setCursor(15, 0);
lcd.write(byte(0)); lcd.write(byte(0));
clockUpdating = true; clockUpdating = true;
gw.requestTime(receiveTime); requestTime(receiveTime);
lastVeraGetTime = millis(); lastVeraGetTime = millis();
} }
} }
@@ -834,14 +843,14 @@ void updateClock()
void saveDateToEEPROM(unsigned long theDate) void saveDateToEEPROM(unsigned long theDate)
{ {
DEBUG_PRINTLN(F("Saving Last Run date")); DEBUG_PRINTLN(F("Saving Last Run date"));
if (gw.loadState(0) != 0xFF) if (loadState(0) != 0xFF)
{ {
gw.saveState(0, 0xFF); // EEPROM flag for last date saved stored in EEPROM (location zero) saveState(0, 0xFF); // EEPROM flag for last date saved stored in EEPROM (location zero)
} }
// //
for (int i = 1; i < 5; i++) for (int i = 1; i < 5; i++)
{ {
gw.saveState(5 - i, byte(theDate >> 8 * (i - 1))); // store epoch datestamp in 4 bytes of EEPROM starting in location one saveState(5 - i, byte(theDate >> 8 * (i - 1))); // store epoch datestamp in 4 bytes of EEPROM starting in location one
} }
} }
// //
@@ -854,9 +863,9 @@ void goGetValveTimes()
DEBUG_PRINTLN(F("Calling for Valve Data...")); DEBUG_PRINTLN(F("Calling for Valve Data..."));
lcd.setCursor(15, 0); lcd.setCursor(15, 0);
lcd.write(byte(1)); //lcd.write(1); lcd.write(byte(1)); //lcd.write(1);
gw.request(valveIndex, V_VAR1); request(valveIndex, V_VAR1);
gw.request(valveIndex, V_VAR2); request(valveIndex, V_VAR2);
gw.request(valveIndex, V_VAR3); request(valveIndex, V_VAR3);
valveUpdateTime = millis(); valveUpdateTime = millis();
valveIndex++; valveIndex++;
if (valveIndex > NUMBER_OF_VALVES + 1) if (valveIndex > NUMBER_OF_VALVES + 1)
@@ -1,9 +1,85 @@
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* REVISION HISTORY
* Version 1.0 - idefix
*
* DESCRIPTION
* Arduino BH1750FVI Light sensor
* communicate using I2C Protocol
* this library enable 2 slave device addresses
* Main address 0x23
* secondary address 0x5C
* connect the sensor as follows :
*
* VCC >>> 5V
* Gnd >>> Gnd
* ADDR >>> NC or GND
* SCL >>> A5
* SDA >>> A4
* http://www.mysensors.org/build/light
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h> #include <BH1750.h>
#include <Wire.h>
MyTransportNRF24 transport; #define CHILD_ID_LIGHT 0
MyHwATMega328 hw; unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MySensor gw(transport, hw);
void setup() {} BH1750 lightSensor;
void loop() {}
// V_LIGHT_LEVEL should only be used for uncalibrated light level 0-100%.
// If your controller supports the new V_LEVEL variable, use this instead for
// transmitting LUX light level.
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
// MyMessage msg(CHILD_ID_LIGHT, V_LEVEL);
uint16_t lastlux;
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Light Lux Sensor", "1.0");
// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
lightSensor.begin();
}
void loop()
{
uint16_t lux = lightSensor.readLightLevel();// Get Lux value
Serial.println(lux);
if (lux != lastlux) {
send(msg.set(lux));
lastlux = lux;
}
sleep(SLEEP_TIME);
}
@@ -2,9 +2,15 @@
// with the MySensors environment and is based on a sketch provided by Playing With Fusion // with the MySensors environment and is based on a sketch provided by Playing With Fusion
// http://playingwithfusion.com/productview.php?pdid=22&catid=1001 // http://playingwithfusion.com/productview.php?pdid=22&catid=1001
// //
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include "MySensor.h" #include "MySensor.h"
// the lightning sensor can communicate via SPI or I2C. This sketch uses the SPI interface
#include "SPI.h"
// include Playing With Fusion AXS3935 libraries // include Playing With Fusion AXS3935 libraries
#include "PWFusion_AS3935.h" #include "PWFusion_AS3935.h"
@@ -28,20 +34,17 @@ PWF_AS3935 lightning0(CS_PIN, IRQ_PIN, SI_PIN);
#define CHILD_ID_DISTANCE 1 #define CHILD_ID_DISTANCE 1
#define CHILD_ID_INTENSITY 2 #define CHILD_ID_INTENSITY 2
MySensor gw;
MyMessage msgDist(CHILD_ID_DISTANCE, V_DISTANCE); MyMessage msgDist(CHILD_ID_DISTANCE, V_DISTANCE);
MyMessage msgInt(CHILD_ID_INTENSITY, V_VAR1); MyMessage msgInt(CHILD_ID_INTENSITY, V_VAR1);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Lightning Sensor", "1.1"); sendSketchInfo("Lightning Sensor", "1.1");
// Register all sensors to gw (they will be created as child devices) // Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_DISTANCE, S_DISTANCE); present(CHILD_ID_DISTANCE, S_DISTANCE);
gw.present(CHILD_ID_INTENSITY, S_CUSTOM); present(CHILD_ID_INTENSITY, S_CUSTOM);
Serial.begin(115200); Serial.begin(115200);
Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001"); Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001");
@@ -99,8 +102,8 @@ void loop()
Serial.println(" kilometers"); Serial.println(" kilometers");
Serial.print("Lightning detected! Lightning Intensity: "); Serial.print("Lightning detected! Lightning Intensity: ");
Serial.println(lightning_intensity); Serial.println(lightning_intensity);
gw.send(msgDist.set(lightning_dist_km)); send(msgDist.set(lightning_dist_km));
gw.send(msgInt.set(lightning_intensity)); send(msgInt.set(lightning_intensity));
} }
else if(2 == int_src) else if(2 == int_src)
{ {
@@ -35,9 +35,16 @@
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <MAX6675.h> #include <MAX6675.h>
#include <SPI.h>
uint8_t CS0 = 4; // CS pin on MAX6675 uint8_t CS0 = 4; // CS pin on MAX6675
uint8_t SO = 3; // SO pin of MAX6675 uint8_t SO = 3; // SO pin of MAX6675
uint8_t SCLK = 5; // SCK pin of MAX6675 uint8_t SCLK = 5; // SCK pin of MAX6675
@@ -46,7 +53,6 @@ float temperature = 0.0; // Temperature output variable
float lastTemperature; float lastTemperature;
unsigned long SLEEP_TIME = 30000; unsigned long SLEEP_TIME = 30000;
boolean metric = true; boolean metric = true;
MySensor gw;
MyMessage msg(0, V_TEMP); MyMessage msg(0, V_TEMP);
@@ -56,21 +62,15 @@ MAX6675 temp0(CS0, SO, SCLK, units);
void setup() void setup()
{ {
// Startup and initialize MySensors library. Set callback for incoming messages.
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Max6675 Temp Sensor", "1.0"); sendSketchInfo("Max6675 Temp Sensor", "1.0");
// Present all sensors to controller // Present all sensors to controller
gw.present(0, S_TEMP); present(0, S_TEMP);
} }
void loop() void loop()
{ {
// Process incoming messages (like config from server)
gw.process();
temperature = temp0.read_temp(); // Read the temp temperature = temp0.read_temp(); // Read the temp
if (temperature < 0) { // If there is an error with the TC, temperature will be < 0 if (temperature < 0) { // If there is an error with the TC, temperature will be < 0
@@ -79,9 +79,9 @@ void loop()
Serial.print("Current Temperature: "); Serial.print("Current Temperature: ");
Serial.println( temperature ); // Print the temperature to Serial Serial.println( temperature ); // Print the temperature to Serial
if (temperature != lastTemperature) if (temperature != lastTemperature)
gw.send(msg.setSensor(0).set(temperature, 1)); send(msg.setSensor(0).set(temperature, 1));
lastTemperature = temperature; lastTemperature = temperature;
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -6,16 +6,16 @@
* Barduino 2015, GizMoCuz 2015 * Barduino 2015, GizMoCuz 2015
*/ */
#include <MySigningNone.h> // Enable debug prints to serial monitor
#include <MyTransportRFM69.h> #define MY_DEBUG
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h> // Enable and select radio type attached
#include <MySigningAtsha204Soft.h> #define MY_RADIO_NRF24
#include <MySigningAtsha204.h> //#define MY_RADIO_RFM69
#define MY_NODE_ID 254
#include <SPI.h>
#include <MySensor.h> #include <MySensor.h>
#include <MyMessage.h>
#define RADIO_ERROR_LED_PIN 4 // Error led pin #define RADIO_ERROR_LED_PIN 4 // Error led pin
#define RADIO_RX_LED_PIN 6 // Receive led pin #define RADIO_RX_LED_PIN 6 // Receive led pin
@@ -88,27 +88,6 @@ unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
boolean metric = true; boolean metric = true;
long randNumber; long randNumber;
// Instanciate MySersors Gateway
MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL);
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;
//MySigningAtsha204Soft signer;
//MySigningAtsha204 signer;
// Hardware profile
MyHwATMega328 hw;
// Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
// To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
#ifdef WITH_LEDS_BLINKING
MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
#else
MySensor gw(transport, hw /*, signer*/);
#endif
//MySensor gw;
//Instanciate Messages objects //Instanciate Messages objects
@@ -355,22 +334,22 @@ void setup()
randomSeed(analogRead(0)); randomSeed(analogRead(0));
// Start the gateway // Start the gateway
gw.begin(incomingMessage,254); setIncomingCallback(incomingMessage);
gw.wait(LONG_WAIT); wait(LONG_WAIT);
Serial.println("GW Started"); Serial.println("GW Started");
// Send the Sketch Version Information to the Gateway // Send the Sketch Version Information to the Gateway
Serial.print("Send Sketch Info: "); Serial.print("Send Sketch Info: ");
gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
Serial.print(SKETCH_NAME); Serial.print(SKETCH_NAME);
Serial.println(SKETCH_VERSION); Serial.println(SKETCH_VERSION);
gw.wait(LONG_WAIT); wait(LONG_WAIT);
// Get controller configuration // Get controller configuration
Serial.print("Get Config: "); Serial.print("Get Config: ");
metric = gw.getConfig().isMetric; metric = getConfig().isMetric;
Serial.println(metric ? "Metric":"Imperial"); Serial.println(metric ? "Metric":"Imperial");
gw.wait(LONG_WAIT); wait(LONG_WAIT);
// Init Armed // Init Armed
#ifdef ID_S_ARMED #ifdef ID_S_ARMED
@@ -383,170 +362,170 @@ void setup()
#ifdef ID_S_DOOR #ifdef ID_S_DOOR
Serial.println(" S_DOOR"); Serial.println(" S_DOOR");
gw.present(ID_S_DOOR,S_DOOR,"Outside Door"); present(ID_S_DOOR,S_DOOR,"Outside Door");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_MOTION #ifdef ID_S_MOTION
Serial.println(" S_MOTION"); Serial.println(" S_MOTION");
gw.present(ID_S_MOTION,S_MOTION,"Outside Motion"); present(ID_S_MOTION,S_MOTION,"Outside Motion");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_SMOKE #ifdef ID_S_SMOKE
Serial.println(" S_SMOKE"); Serial.println(" S_SMOKE");
gw.present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke"); present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_LIGHT #ifdef ID_S_LIGHT
Serial.println(" S_LIGHT"); Serial.println(" S_LIGHT");
gw.present(ID_S_LIGHT,S_LIGHT,"Hall Light"); present(ID_S_LIGHT,S_LIGHT,"Hall Light");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_DIMMER #ifdef ID_S_DIMMER
Serial.println(" S_DIMMER"); Serial.println(" S_DIMMER");
gw.present(ID_S_DIMMER,S_DIMMER,"Living room dimmer"); present(ID_S_DIMMER,S_DIMMER,"Living room dimmer");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_COVER #ifdef ID_S_COVER
Serial.println(" S_COVER"); Serial.println(" S_COVER");
gw.present(ID_S_COVER,S_COVER,"Window cover"); present(ID_S_COVER,S_COVER,"Window cover");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_TEMP #ifdef ID_S_TEMP
Serial.println(" S_TEMP"); Serial.println(" S_TEMP");
gw.present(ID_S_TEMP,S_TEMP,"House Temperarue"); present(ID_S_TEMP,S_TEMP,"House Temperarue");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_HUM #ifdef ID_S_HUM
Serial.println(" S_HUM"); Serial.println(" S_HUM");
gw.present(ID_S_HUM,S_HUM,"Current Humidity"); present(ID_S_HUM,S_HUM,"Current Humidity");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_BARO #ifdef ID_S_BARO
Serial.println(" S_BARO"); Serial.println(" S_BARO");
gw.present(ID_S_BARO,S_BARO," Air pressure"); present(ID_S_BARO,S_BARO," Air pressure");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_WIND #ifdef ID_S_WIND
Serial.println(" S_WIND"); Serial.println(" S_WIND");
gw.present(ID_S_WIND,S_WIND,"Wind Station"); present(ID_S_WIND,S_WIND,"Wind Station");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_RAIN #ifdef ID_S_RAIN
Serial.println(" S_RAIN"); Serial.println(" S_RAIN");
gw.present(ID_S_RAIN,S_RAIN,"Rain Station"); present(ID_S_RAIN,S_RAIN,"Rain Station");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_UV #ifdef ID_S_UV
Serial.println(" S_UV"); Serial.println(" S_UV");
gw.present(ID_S_UV,S_UV,"Ultra Violet"); present(ID_S_UV,S_UV,"Ultra Violet");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_WEIGHT #ifdef ID_S_WEIGHT
Serial.println(" S_WEIGHT"); Serial.println(" S_WEIGHT");
gw.present(ID_S_WEIGHT,S_WEIGHT,"Outdoor Scale"); present(ID_S_WEIGHT,S_WEIGHT,"Outdoor Scale");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_POWER #ifdef ID_S_POWER
Serial.println(" S_POWER"); Serial.println(" S_POWER");
gw.present(ID_S_POWER,S_POWER,"Power Metric"); present(ID_S_POWER,S_POWER,"Power Metric");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_HEATER #ifdef ID_S_HEATER
Serial.println(" S_HEATER"); Serial.println(" S_HEATER");
gw.present(ID_S_HEATER,S_HEATER,"Garage Heater"); present(ID_S_HEATER,S_HEATER,"Garage Heater");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_DISTANCE #ifdef ID_S_DISTANCE
Serial.println(" S_DISTANCE"); Serial.println(" S_DISTANCE");
gw.present(ID_S_DISTANCE,S_DISTANCE,"Distance Measure"); present(ID_S_DISTANCE,S_DISTANCE,"Distance Measure");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_LIGHT_LEVEL #ifdef ID_S_LIGHT_LEVEL
Serial.println(" S_LIGHT_LEVEL"); Serial.println(" S_LIGHT_LEVEL");
gw.present(ID_S_LIGHT_LEVEL,S_LIGHT_LEVEL,"Outside Light Level"); present(ID_S_LIGHT_LEVEL,S_LIGHT_LEVEL,"Outside Light Level");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_LOCK #ifdef ID_S_LOCK
Serial.println(" S_LOCK"); Serial.println(" S_LOCK");
gw.present(ID_S_LOCK,S_LOCK,"Front Door Lock"); present(ID_S_LOCK,S_LOCK,"Front Door Lock");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_IR #ifdef ID_S_IR
Serial.println(" S_IR"); Serial.println(" S_IR");
gw.present(ID_S_IR,S_IR,"Univeral Command"); present(ID_S_IR,S_IR,"Univeral Command");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_WATER #ifdef ID_S_WATER
Serial.println(" S_WATER"); Serial.println(" S_WATER");
gw.present(ID_S_WATER,S_WATER,"Water Level"); present(ID_S_WATER,S_WATER,"Water Level");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_AIR_QUALITY #ifdef ID_S_AIR_QUALITY
Serial.println(" S_AIR_QUALITY"); Serial.println(" S_AIR_QUALITY");
gw.present(ID_S_AIR_QUALITY,S_AIR_QUALITY,"Air Station"); present(ID_S_AIR_QUALITY,S_AIR_QUALITY,"Air Station");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_DUST #ifdef ID_S_DUST
Serial.println(" S_DUST"); Serial.println(" S_DUST");
gw.present(ID_S_DUST,S_DUST,"Dust Level"); present(ID_S_DUST,S_DUST,"Dust Level");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_SCENE_CONTROLLER #ifdef ID_S_SCENE_CONTROLLER
Serial.println(" S_SCENE_CONTROLLER"); Serial.println(" S_SCENE_CONTROLLER");
gw.present(ID_S_SCENE_CONTROLLER,S_SCENE_CONTROLLER,"Scene Controller"); present(ID_S_SCENE_CONTROLLER,S_SCENE_CONTROLLER,"Scene Controller");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_RGB_LIGHT #ifdef ID_S_RGB_LIGHT
Serial.println(" RGB_LIGHT"); Serial.println(" RGB_LIGHT");
gw.present(ID_S_RGB_LIGHT,S_RGB_LIGHT,"Mood Light"); present(ID_S_RGB_LIGHT,S_RGB_LIGHT,"Mood Light");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_RGBW_LIGHT #ifdef ID_S_RGBW_LIGHT
Serial.println(" RGBW_LIGHT"); Serial.println(" RGBW_LIGHT");
gw.present(ID_S_RGBW_LIGHT,S_RGBW_LIGHT,"Mood Light 2"); present(ID_S_RGBW_LIGHT,S_RGBW_LIGHT,"Mood Light 2");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_COLOR_SENSOR #ifdef ID_S_COLOR_SENSOR
Serial.println(" COLOR_SENSOR"); Serial.println(" COLOR_SENSOR");
gw.present(ID_S_COLOR_SENSOR,S_COLOR_SENSOR,"Hall Painting"); present(ID_S_COLOR_SENSOR,S_COLOR_SENSOR,"Hall Painting");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_HVAC #ifdef ID_S_HVAC
Serial.println(" HVAC"); Serial.println(" HVAC");
gw.present(ID_S_HVAC,S_HVAC,"HVAC"); present(ID_S_HVAC,S_HVAC,"HVAC");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_MULTIMETER #ifdef ID_S_MULTIMETER
Serial.println(" MULTIMETER"); Serial.println(" MULTIMETER");
gw.present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Staion"); present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Staion");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_SPRINKLER #ifdef ID_S_SPRINKLER
@@ -562,14 +541,14 @@ void setup()
#ifdef ID_S_MOISTURE #ifdef ID_S_MOISTURE
Serial.println(" S_MOISTURE"); Serial.println(" S_MOISTURE");
gw.present(ID_S_MOISTURE,S_MOISTURE,"Basement Sensor"); present(ID_S_MOISTURE,S_MOISTURE,"Basement Sensor");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_CUSTOM #ifdef ID_S_CUSTOM
Serial.println(" S_CUSTOM"); Serial.println(" S_CUSTOM");
gw.present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff"); present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff");
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
#endif #endif
@@ -590,13 +569,13 @@ void loop()
Serial.println(randNumber); Serial.println(randNumber);
// Send fake battery level // Send fake battery level
Serial.println("Send Battery Level"); Serial.println("Send Battery Level");
gw.sendBatteryLevel(randNumber); sendBatteryLevel(randNumber);
gw.wait(LONG_WAIT); wait(LONG_WAIT);
// Request time // Request time
Serial.println("Request Time"); Serial.println("Request Time");
gw.requestTime(receiveTime); requestTime(receiveTime);
gw.wait(LONG_WAIT); wait(LONG_WAIT);
//Read Sensors //Read Sensors
#ifdef ID_S_DOOR #ifdef ID_S_DOOR
@@ -730,11 +709,10 @@ void loop()
custom(); custom();
#endif #endif
gw.sendBatteryLevel(randNumber); sendBatteryLevel(randNumber);
gw.wait(SHORT_WAIT); wait(SHORT_WAIT);
gw.process();
Serial.println("#########################"); Serial.println("#########################");
gw.wait(SLEEP_TIME); //sleep a bit wait(SLEEP_TIME); //sleep a bit
} }
// This is called when a new time value was received // This is called when a new time value was received
@@ -754,15 +732,15 @@ void door(){
if (randNumber <= 50) { if (randNumber <= 50) {
Serial.println("Open"); Serial.println("Open");
gw.send(msg_S_DOOR_T.set(1)); send(msg_S_DOOR_T.set(1));
} else { } else {
Serial.println("Closed"); Serial.println("Closed");
gw.send(msg_S_DOOR_T.set(0)); send(msg_S_DOOR_T.set(0));
} }
#ifdef ID_S_ARMED #ifdef ID_S_ARMED
Serial.print("System is: " ); Serial.print("System is: " );
Serial.println((isArmed ? "Armed":"Disarmed")); Serial.println((isArmed ? "Armed":"Disarmed"));
gw.send(msg_S_DOOR_A.set(isArmed)); send(msg_S_DOOR_A.set(isArmed));
#endif #endif
} }
#endif #endif
@@ -774,16 +752,16 @@ void motion(){
if (randNumber <= 50) { if (randNumber <= 50) {
Serial.println("Active"); Serial.println("Active");
gw.send(msg_S_MOTION_T.set(1)); send(msg_S_MOTION_T.set(1));
} else { } else {
Serial.println("Quiet"); Serial.println("Quiet");
gw.send(msg_S_MOTION_T.set(0)); send(msg_S_MOTION_T.set(0));
} }
#ifdef ID_S_ARMED #ifdef ID_S_ARMED
Serial.print("System is: " ); Serial.print("System is: " );
Serial.println((isArmed ? "Armed":"Disarmed")); Serial.println((isArmed ? "Armed":"Disarmed"));
gw.send(msg_S_MOTION_A.set(isArmed)); send(msg_S_MOTION_A.set(isArmed));
#endif #endif
} }
#endif #endif
@@ -795,16 +773,16 @@ void smoke(){
if (randNumber <= 50) { if (randNumber <= 50) {
Serial.println("Active"); Serial.println("Active");
gw.send(msg_S_SMOKE_T.set(1)); send(msg_S_SMOKE_T.set(1));
} else { } else {
Serial.println("Quiet"); Serial.println("Quiet");
gw.send(msg_S_SMOKE_T.set(0)); send(msg_S_SMOKE_T.set(0));
} }
#ifdef ID_S_ARMED #ifdef ID_S_ARMED
Serial.print("System is: " ); Serial.print("System is: " );
Serial.println((isArmed ? "Armed":"Disarmed")); Serial.println((isArmed ? "Armed":"Disarmed"));
gw.send(msg_S_SMOKE_A.set(isArmed)); send(msg_S_SMOKE_A.set(isArmed));
#endif #endif
} }
@@ -816,7 +794,7 @@ void light(){
Serial.print("Light is: " ); Serial.print("Light is: " );
Serial.println((isLightOn ? "On":"Off")); Serial.println((isLightOn ? "On":"Off"));
gw.send(msg_S_LIGHT.set(isLightOn)); send(msg_S_LIGHT.set(isLightOn));
} }
#endif #endif
@@ -827,7 +805,7 @@ void dimmer(){
Serial.print("Dimmer is set to: " ); Serial.print("Dimmer is set to: " );
Serial.println(dimmerVal); Serial.println(dimmerVal);
gw.send(msg_S_DIMMER.set(dimmerVal)); send(msg_S_DIMMER.set(dimmerVal));
} }
#endif #endif
@@ -839,15 +817,15 @@ void cover(){
if (coverState == 1){ if (coverState == 1){
Serial.println("Opening"); Serial.println("Opening");
gw.send(msg_S_COVER_U.set(1)); send(msg_S_COVER_U.set(1));
}else if (coverState == -1){ }else if (coverState == -1){
Serial.println("Closing"); Serial.println("Closing");
gw.send(msg_S_COVER_D.set(0)); send(msg_S_COVER_D.set(0));
}else{ }else{
Serial.println("Idle"); Serial.println("Idle");
gw.send(msg_S_COVER_S.set(-1)); send(msg_S_COVER_S.set(-1));
} }
gw.send(msg_S_COVER_V.set(coverState)); send(msg_S_COVER_V.set(coverState));
} }
#endif #endif
@@ -857,7 +835,7 @@ void temp(){
Serial.print("Temperature is: " ); Serial.print("Temperature is: " );
Serial.println(map(randNumber,1,100,0,45)); Serial.println(map(randNumber,1,100,0,45));
gw.send(msg_S_TEMP.set(map(randNumber,1,100,0,45))); send(msg_S_TEMP.set(map(randNumber,1,100,0,45)));
} }
#endif #endif
@@ -868,7 +846,7 @@ void hum(){
Serial.print("Humitidty is: " ); Serial.print("Humitidty is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_HUM.set(randNumber)); send(msg_S_HUM.set(randNumber));
} }
#endif #endif
@@ -882,11 +860,11 @@ void baro(){
Serial.print("Atmosferic Pressure is: " ); Serial.print("Atmosferic Pressure is: " );
Serial.println(pressure); Serial.println(pressure);
gw.send(msg_S_BARO_P.set(pressure)); send(msg_S_BARO_P.set(pressure));
Serial.print("Weather forecast: " ); Serial.print("Weather forecast: " );
Serial.println(weather[forecast]); Serial.println(weather[forecast]);
gw.send(msg_S_BARO_F.set(weather[forecast])); send(msg_S_BARO_F.set(weather[forecast]));
} }
#endif #endif
@@ -896,15 +874,15 @@ void wind(){
Serial.print("Wind Speed is: " ); Serial.print("Wind Speed is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_WIND_S.set(randNumber)); send(msg_S_WIND_S.set(randNumber));
Serial.print("Wind Gust is: " ); Serial.print("Wind Gust is: " );
Serial.println(randNumber+10); Serial.println(randNumber+10);
gw.send(msg_S_WIND_G.set(randNumber+10)); send(msg_S_WIND_G.set(randNumber+10));
Serial.print("Wind Direction is: " ); Serial.print("Wind Direction is: " );
Serial.println(map(randNumber,1,100,0,360)); Serial.println(map(randNumber,1,100,0,360));
gw.send(msg_S_WIND_D.set(map(randNumber,1,100,0,360))); send(msg_S_WIND_D.set(map(randNumber,1,100,0,360)));
} }
#endif #endif
@@ -915,12 +893,12 @@ void rain(){
Serial.print("Rain ammount is: " ); Serial.print("Rain ammount is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_RAIN_A.set(randNumber)); send(msg_S_RAIN_A.set(randNumber));
Serial.print("Rain rate is: " ); Serial.print("Rain rate is: " );
Serial.println(randNumber/60); Serial.println(randNumber/60);
gw.send(msg_S_RAIN_R.set(randNumber/60,1)); send(msg_S_RAIN_R.set(randNumber/60,1));
} }
#endif #endif
@@ -931,7 +909,7 @@ void uv(){
Serial.print("Ultra Violet level is: " ); Serial.print("Ultra Violet level is: " );
Serial.println(map(randNumber,1,100,0,15)); Serial.println(map(randNumber,1,100,0,15));
gw.send(msg_S_UV.set(map(randNumber,1,100,0,15))); send(msg_S_UV.set(map(randNumber,1,100,0,15)));
} }
#endif #endif
@@ -942,7 +920,7 @@ void weight(){
Serial.print("Weight is: " ); Serial.print("Weight is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_WEIGHT.set(map(randNumber,1,100,0,150))); send(msg_S_WEIGHT.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -952,11 +930,11 @@ void power(){
Serial.print("Watt is: " ); Serial.print("Watt is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_POWER_W.set(map(randNumber,1,100,0,150))); send(msg_S_POWER_W.set(map(randNumber,1,100,0,150)));
Serial.print("KWH is: " ); Serial.print("KWH is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_POWER_K.set(map(randNumber,1,100,0,150))); send(msg_S_POWER_K.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -970,19 +948,19 @@ void heater(){
Serial.print("Heater flow state is: " ); Serial.print("Heater flow state is: " );
Serial.println(heater_flow_state); Serial.println(heater_flow_state);
gw.send(msg_S_HEATER_FLOW_STATE.set(heater_flow_state.c_str())); send(msg_S_HEATER_FLOW_STATE.set(heater_flow_state.c_str()));
// Serial.print("Heater on/off is: " ); // Serial.print("Heater on/off is: " );
// Serial.println((heater_status==true)?"On":"Off"); // Serial.println((heater_status==true)?"On":"Off");
// gw.send(msg_S_HEATER_STATUS.set(heater_status)); // send(msg_S_HEATER_STATUS.set(heater_status));
// Serial.print("Heater Temperature is: " ); // Serial.print("Heater Temperature is: " );
// Serial.println(heater_temp,1); // Serial.println(heater_temp,1);
// gw.send(msg_S_HEATER_TEMP.set(heater_temp,1)); // send(msg_S_HEATER_TEMP.set(heater_temp,1));
Serial.print("Heater Setpoint: " ); Serial.print("Heater Setpoint: " );
Serial.println(heater_setpoint,1); Serial.println(heater_setpoint,1);
gw.send(msg_S_HEATER_SET_POINT.set(heater_setpoint,1)); send(msg_S_HEATER_SET_POINT.set(heater_setpoint,1));
} }
#endif #endif
@@ -992,7 +970,7 @@ void distance(){
Serial.print("Distance is: " ); Serial.print("Distance is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_DISTANCE.set(map(randNumber,1,100,0,150))); send(msg_S_DISTANCE.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -1003,7 +981,7 @@ void light_level(){
Serial.print("Light is: " ); Serial.print("Light is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_LIGHT_LEVEL.set(map(randNumber,1,100,0,150))); send(msg_S_LIGHT_LEVEL.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -1013,7 +991,7 @@ void lock(){
Serial.print("Lock is: " ); Serial.print("Lock is: " );
Serial.println((isLocked ? "Locked":"Unlocked")); Serial.println((isLocked ? "Locked":"Unlocked"));
gw.send(msg_S_LOCK.set(isLocked)); send(msg_S_LOCK.set(isLocked));
} }
#endif #endif
@@ -1024,8 +1002,8 @@ void ir(){
Serial.print("Infrared is: " ); Serial.print("Infrared is: " );
Serial.println(irVal); Serial.println(irVal);
gw.send(msg_S_IR_S.set(irVal)); send(msg_S_IR_S.set(irVal));
gw.send(msg_S_IR_R.set(irVal)); send(msg_S_IR_R.set(irVal));
} }
#endif #endif
@@ -1036,12 +1014,12 @@ void water(){
Serial.print("Water flow is: " ); Serial.print("Water flow is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_WATER_F.set(map(randNumber,1,100,0,150))); send(msg_S_WATER_F.set(map(randNumber,1,100,0,150)));
Serial.print("Water volume is: " ); Serial.print("Water volume is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_WATER_V.set(map(randNumber,1,100,0,150))); send(msg_S_WATER_V.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -1052,7 +1030,7 @@ void air(){
Serial.print("Air Quality is: " ); Serial.print("Air Quality is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_AIR_QUALITY.set(randNumber)); send(msg_S_AIR_QUALITY.set(randNumber));
} }
#endif #endif
@@ -1063,7 +1041,7 @@ void dust(){
Serial.print("Dust level is: " ); Serial.print("Dust level is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_DUST.set(randNumber)); send(msg_S_DUST.set(randNumber));
} }
#endif #endif
@@ -1075,8 +1053,8 @@ void scene(){
Serial.println(scenes[sceneVal]); Serial.println(scenes[sceneVal]);
if(sceneValPrevious != sceneVal){ if(sceneValPrevious != sceneVal){
gw.send(msg_S_SCENE_CONTROLLER_OF.set(sceneValPrevious)); send(msg_S_SCENE_CONTROLLER_OF.set(sceneValPrevious));
gw.send(msg_S_SCENE_CONTROLLER_ON.set(sceneVal)); send(msg_S_SCENE_CONTROLLER_ON.set(sceneVal));
sceneValPrevious=sceneVal; sceneValPrevious=sceneVal;
} }
@@ -1088,11 +1066,11 @@ void rgbLight(){
Serial.print("RGB Light state is: " ); Serial.print("RGB Light state is: " );
Serial.println(rgbState); Serial.println(rgbState);
gw.send(msg_S_RGB_LIGHT_V_RGB.set(rgbState.c_str())); send(msg_S_RGB_LIGHT_V_RGB.set(rgbState.c_str()));
Serial.print("RGB Light Watt is: " ); Serial.print("RGB Light Watt is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_RGB_LIGHT_V_WATT.set(map(randNumber,1,100,0,150))); send(msg_S_RGB_LIGHT_V_WATT.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -1102,11 +1080,11 @@ void rgbwLight(){
Serial.print("RGBW Light state is: " ); Serial.print("RGBW Light state is: " );
Serial.println(rgbwState); Serial.println(rgbwState);
gw.send(msg_S_RGBW_LIGHT_V_RGBW.set(rgbwState.c_str())); send(msg_S_RGBW_LIGHT_V_RGBW.set(rgbwState.c_str()));
Serial.print("RGBW Light Watt is: " ); Serial.print("RGBW Light Watt is: " );
Serial.println(map(randNumber,1,100,0,150)); Serial.println(map(randNumber,1,100,0,150));
gw.send(msg_S_RGBW_LIGHT_V_WATT.set(map(randNumber,1,100,0,150))); send(msg_S_RGBW_LIGHT_V_WATT.set(map(randNumber,1,100,0,150)));
} }
#endif #endif
@@ -1123,7 +1101,7 @@ void color(){
Serial.print("Color state is: " ); Serial.print("Color state is: " );
Serial.println(colorState); Serial.println(colorState);
gw.send(msg_S_COLOR_SENSOR_V_RGB.set(colorState.c_str())); send(msg_S_COLOR_SENSOR_V_RGB.set(colorState.c_str()));
} }
#endif #endif
@@ -1139,23 +1117,23 @@ void hvac(){
Serial.print("HVAC Set Point Heat is: " ); Serial.print("HVAC Set Point Heat is: " );
Serial.println(hvac_SetPointHeat); Serial.println(hvac_SetPointHeat);
gw.send(msg_S_HVAC_V_HVAC_SETPOINT_HEAT.set(hvac_SetPointHeat,1)); send(msg_S_HVAC_V_HVAC_SETPOINT_HEAT.set(hvac_SetPointHeat,1));
Serial.print("HVAC Set Point Cool is: " ); Serial.print("HVAC Set Point Cool is: " );
Serial.println(hvac_SetPointCool); Serial.println(hvac_SetPointCool);
gw.send(msg_S_HVAC_V_HVAC_SETPOINT_COOL.set(hvac_SetPointCool,1)); send(msg_S_HVAC_V_HVAC_SETPOINT_COOL.set(hvac_SetPointCool,1));
Serial.print("HVAC Flow State is: " ); Serial.print("HVAC Flow State is: " );
Serial.println(hvac_FlowState); Serial.println(hvac_FlowState);
gw.send(msg_S_HVAC_V_HVAC_FLOW_STATET.set(hvac_FlowState.c_str())); send(msg_S_HVAC_V_HVAC_FLOW_STATET.set(hvac_FlowState.c_str()));
Serial.print("HVAC Flow Mode is: " ); Serial.print("HVAC Flow Mode is: " );
Serial.println(hvac_FlowMode); Serial.println(hvac_FlowMode);
gw.send(msg_S_HVAC_V_HVAC_FLOW_MODE.set(hvac_FlowMode.c_str())); send(msg_S_HVAC_V_HVAC_FLOW_MODE.set(hvac_FlowMode.c_str()));
Serial.print("HVAC Speed is: " ); Serial.print("HVAC Speed is: " );
Serial.println(hvac_Speed); Serial.println(hvac_Speed);
gw.send(msg_S_HVAC_V_HVAC_SPEED.set(hvac_Speed.c_str())); send(msg_S_HVAC_V_HVAC_SPEED.set(hvac_Speed.c_str()));
} }
#endif #endif
@@ -1168,15 +1146,15 @@ void multimeter(){
Serial.print("Impedance is: " ); Serial.print("Impedance is: " );
Serial.println(impedance); Serial.println(impedance);
gw.send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance)); send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance));
Serial.print("Voltage is: " ); Serial.print("Voltage is: " );
Serial.println(volt); Serial.println(volt);
gw.send(msg_S_MULTIMETER_V_VOLTAGE.set(volt)); send(msg_S_MULTIMETER_V_VOLTAGE.set(volt));
Serial.print("Current is: " ); Serial.print("Current is: " );
Serial.println(amps); Serial.println(amps);
gw.send(msg_S_MULTIMETER_V_CURRENT.set(amps)); send(msg_S_MULTIMETER_V_CURRENT.set(amps));
} }
#endif #endif
@@ -1198,7 +1176,7 @@ void moisture(){
Serial.print("Moisture level is: " ); Serial.print("Moisture level is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_MOISTURE.set(randNumber)); send(msg_S_MOISTURE.set(randNumber));
} }
#endif #endif
@@ -1208,11 +1186,11 @@ void custom(){
Serial.print("Custom value is: " ); Serial.print("Custom value is: " );
Serial.println(randNumber); Serial.println(randNumber);
gw.send(msg_S_CUSTOM_1.set(randNumber)); send(msg_S_CUSTOM_1.set(randNumber));
gw.send(msg_S_CUSTOM_2.set(randNumber)); send(msg_S_CUSTOM_2.set(randNumber));
gw.send(msg_S_CUSTOM_3.set(randNumber)); send(msg_S_CUSTOM_3.set(randNumber));
gw.send(msg_S_CUSTOM_4.set(randNumber)); send(msg_S_CUSTOM_4.set(randNumber));
gw.send(msg_S_CUSTOM_5.set(randNumber)); send(msg_S_CUSTOM_5.set(randNumber));
} }
#endif #endif
@@ -27,28 +27,15 @@
* *
*/ */
// Enable debug prints
//#define MY_DEBUG //#define MY_DEBUG
// Enable and select radio type // Enable and select radio type attached
#define MY_RADIO_NRF24 #define MY_RADIO_NRF24
//#define MY_RADIO_RFM69 //#define MY_RADIO_RFM69
//#define MY_SOFTSPI
//#define MY_OTA_FIRMWARE_FEATURE
//#define MY_SIGNING_SOFT
//#define MY_REPEATER_FEATURE
//#define MY_INCLUSION_MODE_FEATURE
//#define MY_INCLUSION_BUTTON_FEATURE
//#define MY_GATEWAY_SERIAL // REMOVE-ME
//#define MY_GATEWAY_PROTOCOL_DEFAULT // REMOVE-ME
//#define MY_LEDS_BLINKING_FEATURE
#include <MySensor.h> #include <MySensor.h>
unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
@@ -57,8 +44,6 @@ unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in millisecond
// Initialize motion message // Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED); MyMessage msg(CHILD_ID, V_TRIPPED);
void setup() void setup()
{ {
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
@@ -8,8 +8,14 @@
* 2015-05-25 Bruce Lacey v1.0 * 2015-05-25 Bruce Lacey v1.0
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include "MYSLog.h" #include "MYSLog.h"
#define VSN "v1.0" #define VSN "v1.0"
@@ -19,21 +25,16 @@
#define YANG 201 #define YANG 201
#define CHILD 1 #define CHILD 1
// Sensor objects
MySensor gw;
MyMessage mPing(CHILD, V_VAR1); //Ping message MyMessage mPing(CHILD, V_VAR1); //Ping message
MyMessage mPong(CHILD, V_VAR2); //Pong message MyMessage mPong(CHILD, V_VAR2); //Pong message
void setup() { void setup() {
setIncomingCallback(incomingMessage);
Serial.begin(115200); present(CHILD, S_CUSTOM); //
gw.begin(incomingMessage); // Node ids are written to EEPROM during sensor node configuration by entering a 0 or 1 sendSketchInfo( nodeTypeAsCharRepresentation( getNodeId() ), VSN );
gw.present(CHILD, S_CUSTOM); // LOG(F("\n%sReady.\n"), nodeTypeAsCharRepresentation(getNodeId()));
gw.sendSketchInfo( nodeTypeAsCharRepresentation( gw.getNodeId() ), VSN );
LOG(F("\n%sReady.\n"), nodeTypeAsCharRepresentation(gw.getNodeId()));
} }
void loop() { void loop() {
@@ -43,7 +44,7 @@ void loop() {
// Entering T on either node will initiatve a ping-pong test. // Entering T on either node will initiatve a ping-pong test.
if (Serial.available()) { if (Serial.available()) {
byte inChar = Serial.read(); byte inChar = Serial.read();
uint8_t node = gw.getNodeId(); uint8_t node = getNodeId();
// Manual Test Mode // Manual Test Mode
if (inChar == 'T' || inChar == 't') { if (inChar == 'T' || inChar == 't') {
@@ -60,9 +61,6 @@ void loop() {
LOG("Invalid input\n"); LOG("Invalid input\n");
} }
} }
// Process sensor messages
gw.process();
} }
void incomingMessage(const MyMessage &message) { void incomingMessage(const MyMessage &message) {
@@ -82,7 +80,7 @@ void sendPingOrPongResponse( MyMessage msg ) {
// Set payload to current time in millis to ensure each message is unique // Set payload to current time in millis to ensure each message is unique
response.set( millis() ); response.set( millis() );
response.setDestination(msg.sender); response.setDestination(msg.sender);
gw.send(response); send(response);
} }
void setNodeId(byte nodeID) { void setNodeId(byte nodeID) {
@@ -27,7 +27,13 @@
* *
*/ */
#include <SPI.h> // Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <Wire.h> #include <Wire.h>
#include <Adafruit_BMP085.h> #include <Adafruit_BMP085.h>
@@ -52,7 +58,6 @@ enum FORECAST
}; };
Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor
MySensor gw;
float lastPressure = -1; float lastPressure = -1;
float lastTemp = -1; float lastTemp = -1;
@@ -81,10 +86,8 @@ MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Pressure Sensor", "1.1"); sendSketchInfo("Pressure Sensor", "1.1");
if (!bmp.begin()) if (!bmp.begin())
{ {
@@ -93,9 +96,9 @@ void setup()
} }
// Register sensors to gw (they will be created as child devices) // Register sensors to gw (they will be created as child devices)
gw.present(BARO_CHILD, S_BARO); present(BARO_CHILD, S_BARO);
gw.present(TEMP_CHILD, S_TEMP); present(TEMP_CHILD, S_TEMP);
metric = gw.getConfig().isMetric; metric = getConfig().isMetric;
} }
void loop() void loop()
@@ -123,23 +126,23 @@ void loop()
if (temperature != lastTemp) if (temperature != lastTemp)
{ {
gw.send(tempMsg.set(temperature, 1)); send(tempMsg.set(temperature, 1));
lastTemp = temperature; lastTemp = temperature;
} }
if (pressure != lastPressure) if (pressure != lastPressure)
{ {
gw.send(pressureMsg.set(pressure, 0)); send(pressureMsg.set(pressure, 0));
lastPressure = pressure; lastPressure = pressure;
} }
if (forecast != lastForecast) if (forecast != lastForecast)
{ {
gw.send(forecastMsg.set(weather[forecast])); send(forecastMsg.set(weather[forecast]));
lastForecast = forecast; lastForecast = forecast;
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
float getLastPressureSamplesAverage() float getLastPressureSamplesAverage()
@@ -43,8 +43,14 @@
* http://www.mysensors.org/build/rfid * http://www.mysensors.org/build/rfid
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <Wire.h> #include <Wire.h>
#include <PN532_I2C.h> #include <PN532_I2C.h>
#include <PN532.h> #include <PN532.h>
@@ -62,11 +68,9 @@ int keyCount = sizeof validKeys / maxKeyLength;
#define CHILD_ID 99 // Id of the sensor child #define CHILD_ID 99 // Id of the sensor child
/*Pin definitions*/ // Pin definition
const int lockPin = 4; // (Digital 4) The pin that activates the relay/solenoid lock. const int lockPin = 4; // (Digital 4) The pin that activates the relay/solenoid lock.
bool lockStatus; bool lockStatus;
MySensor gw;
MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS); MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS);
PN532_I2C pn532i2c(Wire); PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c); PN532 nfc(pn532i2c);
@@ -92,19 +96,17 @@ void setup() {
// configure board to read RFID tags // configure board to read RFID tags
nfc.SAMConfig(); nfc.SAMConfig();
// Init mysensors library // Add callback for incoming messages
gw.begin(incomingMessage); setIncomingCallback(incomingMessage);
gw.sendSketchInfo("RFID Lock", "1.0"); sendSketchInfo("RFID Lock", "1.0");
gw.present(CHILD_ID, S_LOCK); present(CHILD_ID, S_LOCK);
lockStatus = gw.loadState(0); // Read last lock status from eeprom lockStatus = loadState(0); // Read last lock status from eeprom
setLockState(lockStatus, true); // Now set the last known state and send it to controller setLockState(lockStatus, true); // Now set the last known state and send it to controller
} }
void loop() { void loop() {
gw.process(); // Process incomming messages
boolean success; boolean success;
uint8_t key[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t key[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t currentKeyLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) uint8_t currentKeyLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
@@ -155,15 +157,15 @@ void loop() {
// Unlocks the door. // Unlocks the door.
void setLockState(bool state, bool send){ void setLockState(bool state, bool doSend){
if (state) if (state)
Serial.println("open lock"); Serial.println("open lock");
else else
Serial.println("close lock"); Serial.println("close lock");
if (send) if (doSend)
gw.send(lockMsg.set(state)); send(lockMsg.set(state));
digitalWrite(lockPin, state); digitalWrite(lockPin, state);
gw.saveState(0,state); saveState(0,state);
lockStatus = state; lockStatus = state;
} }
+61 -62
View File
@@ -29,18 +29,20 @@
#define SN "RGB Led strip 3D" #define SN "RGB Led strip 3D"
#define SV "v1" #define SV "v1"
// Load mysensors library // Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
// Load Serial Peripheral Interface library
#include <SPI.h>
// Arduino pin attached to MOSFET Gate pin // Arduino pin attached to MOSFET Gate pin
#define RED_PIN 3 #define RED_PIN 3
#define GREEN_PIN 5 #define GREEN_PIN 5
#define BLUE_PIN 6 #define BLUE_PIN 6
MySensor gw;
// Define message name and type to send sensor info // Define message name and type to send sensor info
MyMessage RedStatus(RED_PIN, V_DIMMER); MyMessage RedStatus(RED_PIN, V_DIMMER);
MyMessage GreenStatus(GREEN_PIN, V_DIMMER); MyMessage GreenStatus(GREEN_PIN, V_DIMMER);
@@ -60,17 +62,17 @@ int isShow;
void setup() void setup()
{ {
// Initializes the sensor node (Callback function for incoming messages, node id, is repeater) // Add callback for incoming messages
gw.begin(incomingMessage, 31, true); setIncomingCallback(incomingMessage);
// Present sketch (name, version) // Present sketch (name, version)
gw.sendSketchInfo(SN, SV); sendSketchInfo(SN, SV);
// Register sensors (id, type, description, ack back) // Register sensors (id, type, description, ack back)
gw.present(RED_PIN, S_DIMMER, "present RED light", false); present(RED_PIN, S_DIMMER, "present RED light", false);
gw.present(GREEN_PIN, S_DIMMER, "present GREEN light", false); present(GREEN_PIN, S_DIMMER, "present GREEN light", false);
gw.present(BLUE_PIN, S_DIMMER, "present BLUE light", false); present(BLUE_PIN, S_DIMMER, "present BLUE light", false);
gw.present(0, S_LIGHT, "present Show button", false); present(0, S_LIGHT, "present Show button", false);
// Define pin mode (pin number, type) // Define pin mode (pin number, type)
pinMode(RED_PIN, OUTPUT); pinMode(RED_PIN, OUTPUT);
@@ -78,38 +80,38 @@ void setup()
pinMode(BLUE_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT);
// Correct saved RGB value for first start // Correct saved RGB value for first start
gw.saveState(RED_PIN, constrain((int8_t)gw.loadState(RED_PIN), 0, 100)); saveState(RED_PIN, constrain((int8_t)loadState(RED_PIN), 0, 100));
gw.saveState(GREEN_PIN, constrain((int8_t)gw.loadState(GREEN_PIN), 0, 100)); saveState(GREEN_PIN, constrain((int8_t)loadState(GREEN_PIN), 0, 100));
gw.saveState(BLUE_PIN, constrain((int8_t)gw.loadState(BLUE_PIN), 0, 100)); saveState(BLUE_PIN, constrain((int8_t)loadState(BLUE_PIN), 0, 100));
// Get value from eeprom and write to output // Get value from eeprom and write to output
analogWrite(RED_PIN, 255 * gw.loadState(RED_PIN) / 100); analogWrite(RED_PIN, 255 * loadState(RED_PIN) / 100);
analogWrite(GREEN_PIN, 255 * gw.loadState(GREEN_PIN) / 100); analogWrite(GREEN_PIN, 255 * loadState(GREEN_PIN) / 100);
analogWrite(BLUE_PIN, 255 * gw.loadState(BLUE_PIN) / 100); analogWrite(BLUE_PIN, 255 * loadState(BLUE_PIN) / 100);
// Write some debug info // Write some debug info
Serial.print("Load from eeprom RED: "); Serial.print("Load from eeprom RED: ");
Serial.print(gw.loadState(RED_PIN)); Serial.print(loadState(RED_PIN));
Serial.println("%"); Serial.println("%");
Serial.print("Load from eeprom GREEN: "); Serial.print("Load from eeprom GREEN: ");
Serial.print(gw.loadState(GREEN_PIN)); Serial.print(loadState(GREEN_PIN));
Serial.println("%"); Serial.println("%");
Serial.print("Load from eeprom BLUE: "); Serial.print("Load from eeprom BLUE: ");
Serial.print(gw.loadState(BLUE_PIN)); Serial.print(loadState(BLUE_PIN));
Serial.println("%"); Serial.println("%");
// Send RGB value to controler (request ack back: true/false) // Send RGB value to controler (request ack back: true/false)
Serial.println("Send eeprom value to controler"); Serial.println("Send eeprom value to controler");
gw.send( RedStatus.set(gw.loadState(RED_PIN)), false ); send( RedStatus.set(loadState(RED_PIN)), false );
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false ); send( GreenStatus.set(loadState(GREEN_PIN)), false );
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false ); send( BlueStatus.set(loadState(BLUE_PIN)), false );
// Correct RGB show state for first start and load it (set to 'On' at first start) // Correct RGB show state for first start and load it (set to 'On' at first start)
gw.saveState(0, constrain((int8_t)gw.loadState(0), 0, 1)); saveState(0, constrain((int8_t)loadState(0), 0, 1));
isShow=gw.loadState(0); isShow=loadState(0);
// Send RGB show state to controler (request ack back: true/false) // Send RGB show state to controler (request ack back: true/false)
gw.send( rgbShowState.set(isShow), false); send( rgbShowState.set(isShow), false);
if (isShow==1){Serial.println("RGB show running..."); } if (isShow==1){Serial.println("RGB show running..."); }
Serial.println("Ready to receive messages..."); Serial.println("Ready to receive messages...");
@@ -117,9 +119,6 @@ void setup()
void loop() void loop()
{ {
// Process incoming messages (like config and light state from controller)
gw.process();
// Run RGB show if is set // Run RGB show if is set
if (isShow==1) if (isShow==1)
{ {
@@ -156,27 +155,27 @@ void incomingMessage(const MyMessage &message)
Serial.println(": On"); Serial.println(": On");
Serial.print("Load from eeprom: "); Serial.print("Load from eeprom: ");
if ( gw.loadState(message.sensor) == 0) if ( loadState(message.sensor) == 0)
{ {
// Pick up last saved dimmer level from the eeprom // Pick up last saved dimmer level from the eeprom
analogWrite(message.sensor, 255 * gw.loadState(10*message.sensor) / 100); analogWrite(message.sensor, 255 * loadState(10*message.sensor) / 100);
// Save loaded value to current // Save loaded value to current
gw.saveState(message.sensor, gw.loadState(10*message.sensor)); saveState(message.sensor, loadState(10*message.sensor));
Serial.print(gw.loadState(10*message.sensor)); Serial.print(loadState(10*message.sensor));
Serial.println("%"); Serial.println("%");
// Send value to controler // Send value to controler
Serial.println("Send value to controler"); Serial.println("Send value to controler");
gw.send(Status.setSensor(message.sensor).set(gw.loadState(10*message.sensor)),false); send(Status.setSensor(message.sensor).set(loadState(10*message.sensor)),false);
} }
else else
{ {
// Pick up last saved dimmer level from the eeprom // Pick up last saved dimmer level from the eeprom
analogWrite(message.sensor, 255 * gw.loadState(message.sensor) / 100); analogWrite(message.sensor, 255 * loadState(message.sensor) / 100);
Serial.print(gw.loadState(message.sensor)); Serial.print(loadState(message.sensor));
Serial.println("%"); Serial.println("%");
// Send value to controler // Send value to controler
Serial.println("Send value to controler"); Serial.println("Send value to controler");
gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false); send(Status.setSensor(message.sensor).set(loadState(message.sensor)),false);
} }
// Stop the show if it's running // Stop the show if it's running
if (isShow==1){ rgbShowStop(message.sensor); } if (isShow==1){ rgbShowStop(message.sensor); }
@@ -187,23 +186,23 @@ void incomingMessage(const MyMessage &message)
// Write output to 0 (Off) // Write output to 0 (Off)
analogWrite(message.sensor, 0); analogWrite(message.sensor, 0);
// Save old value to eeprom if it'was not zero // Save old value to eeprom if it'was not zero
if ( gw.loadState(message.sensor) != 0 ) if ( loadState(message.sensor) != 0 )
{ {
gw.saveState(10*message.sensor, constrain((int8_t)gw.loadState(message.sensor), 0, 100)); saveState(10*message.sensor, constrain((int8_t)loadState(message.sensor), 0, 100));
} }
// Save new value to eeprom // Save new value to eeprom
gw.saveState(message.sensor, 0); saveState(message.sensor, 0);
// Write some debug info // Write some debug info
Serial.print("Incoming change for "); Serial.print("Incoming change for ");
Serial.print(color[message.sensor]); Serial.print(color[message.sensor]);
Serial.print(": "); Serial.print(": ");
Serial.println("Off"); Serial.println("Off");
Serial.print("Store old value: "); Serial.print("Store old value: ");
Serial.print(gw.loadState(10*message.sensor)); Serial.print(loadState(10*message.sensor));
Serial.println("%"); Serial.println("%");
// Send value to controler // Send value to controler
Serial.println("Send value to controler"); Serial.println("Send value to controler");
gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false); send(Status.setSensor(message.sensor).set(loadState(message.sensor)),false);
// Stop the show if it's running // Stop the show if it's running
if (isShow==1){ rgbShowStop(message.sensor); } if (isShow==1){ rgbShowStop(message.sensor); }
} }
@@ -216,7 +215,7 @@ void incomingMessage(const MyMessage &message)
// Change Dimmer level // Change Dimmer level
analogWrite(message.sensor, 255 * incomingDimmerStatus / 100); analogWrite(message.sensor, 255 * incomingDimmerStatus / 100);
//Save value to eeprom //Save value to eeprom
gw.saveState(message.sensor, incomingDimmerStatus); saveState(message.sensor, incomingDimmerStatus);
// Write some debug info // Write some debug info
Serial.print("Incoming change for "); Serial.print("Incoming change for ");
Serial.print(color[message.sensor]); Serial.print(color[message.sensor]);
@@ -225,7 +224,7 @@ void incomingMessage(const MyMessage &message)
Serial.println("%"); Serial.println("%");
// Send value to controler // Send value to controler
Serial.println("Send value to controler"); Serial.println("Send value to controler");
gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false); send(Status.setSensor(message.sensor).set(loadState(message.sensor)),false);
// Stop the show if it's running // Stop the show if it's running
if (isShow==1){ rgbShowStop(message.sensor); } if (isShow==1){ rgbShowStop(message.sensor); }
} }
@@ -248,7 +247,7 @@ void rgbShowOn()
// define show On // define show On
isShow=1; isShow=1;
// Save state // Save state
gw.saveState(0, 1); saveState(0, 1);
// Write some debug info // Write some debug info
Serial.println("Show must go on"); Serial.println("Show must go on");
} }
@@ -258,19 +257,19 @@ void rgbShowOff()
// define show Off // define show Off
isShow=0; isShow=0;
// Save state // Save state
gw.saveState(0, 0); saveState(0, 0);
// Save RGB value to eeprom // Save RGB value to eeprom
gw.saveState(RED_PIN, 100 * redval / 255); saveState(RED_PIN, 100 * redval / 255);
gw.saveState(GREEN_PIN, 100 * greenval / 255); saveState(GREEN_PIN, 100 * greenval / 255);
gw.saveState(BLUE_PIN, 100 * blueval / 255); saveState(BLUE_PIN, 100 * blueval / 255);
// Write some debug info // Write some debug info
Serial.println("Stop the show"); Serial.println("Stop the show");
// Send actual RGB value and state to controler and request ack back (true/false) // Send actual RGB value and state to controler and request ack back (true/false)
Serial.println("Send eeprom value to controler"); Serial.println("Send eeprom value to controler");
gw.send( RedStatus.set(gw.loadState(RED_PIN)), false ); send( RedStatus.set(loadState(RED_PIN)), false );
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false ); send( GreenStatus.set(loadState(GREEN_PIN)), false );
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false ); send( BlueStatus.set(loadState(BLUE_PIN)), false );
gw.send( rgbShowState.set(0), false); send( rgbShowState.set(0), false);
} }
void rgbShowStop(int sensor) void rgbShowStop(int sensor)
@@ -278,27 +277,27 @@ void rgbShowStop(int sensor)
// define show Off // define show Off
isShow=0; isShow=0;
// Save state // Save state
gw.saveState(0, 0); saveState(0, 0);
// Write some debug info // Write some debug info
Serial.println("Stop the show"); Serial.println("Stop the show");
// Send actual RGB value and state to controler and request ack back (true/false) // Send actual RGB value and state to controler and request ack back (true/false)
Serial.println("Send eeprom value to controler"); Serial.println("Send eeprom value to controler");
if (sensor != RED_PIN) if (sensor != RED_PIN)
{ {
gw.saveState(RED_PIN, 100 * redval / 255); saveState(RED_PIN, 100 * redval / 255);
gw.send( RedStatus.set(gw.loadState(RED_PIN)), false ); send( RedStatus.set(loadState(RED_PIN)), false );
} }
if (sensor != GREEN_PIN) if (sensor != GREEN_PIN)
{ {
gw.saveState(GREEN_PIN, 100 * greenval / 255); saveState(GREEN_PIN, 100 * greenval / 255);
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false ); send( GreenStatus.set(loadState(GREEN_PIN)), false );
} }
if (sensor != BLUE_PIN) if (sensor != BLUE_PIN)
{ {
gw.saveState(BLUE_PIN, 100 * blueval / 255); saveState(BLUE_PIN, 100 * blueval / 255);
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false ); send( BlueStatus.set(loadState(BLUE_PIN)), false );
} }
gw.send( rgbShowState.set(0), false); send( rgbShowState.set(0), false);
} }
@@ -34,12 +34,20 @@
by @BulldogLowell and @PeteWill for free public use by @BulldogLowell and @PeteWill for free public use
*/ */
#include <SPI.h>
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
//#define MY_NODE_ID 7
#include <MySensor.h> #include <MySensor.h>
#include <math.h> #include <math.h>
#include <Time.h> #include <Time.h>
#define NODE_ID 24 //or AUTO to let controller assign
#define SKETCH_NAME "Rain Gauge" #define SKETCH_NAME "Rain Gauge"
#define SKETCH_VERSION "1.4.1a" #define SKETCH_VERSION "1.4.1a"
@@ -69,8 +77,6 @@
#define SERIAL_START(x) #define SERIAL_START(x)
#endif #endif
// //
MySensor gw;
//
MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE); MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE);
MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN); MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
// //
@@ -140,13 +146,14 @@ void setup()
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
// //
//Let's get the controller talking to the Arduino //Let's get the controller talking to the Arduino
gw.begin(getVariables, NODE_ID); setIncomingCallback(getVariables);
gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
gw.wait(DWELL_TIME); sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
gw.present(CHILD_ID_RAIN_LOG, S_RAIN); wait(DWELL_TIME);
gw.wait(DWELL_TIME); present(CHILD_ID_RAIN_LOG, S_RAIN);
gw.present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION); wait(DWELL_TIME);
gw.wait(DWELL_TIME); present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
wait(DWELL_TIME);
DEBUG_PRINTLN(F("Sensor Presentation Complete")); DEBUG_PRINTLN(F("Sensor Presentation Complete"));
// //
//Sync time with the server, this will be called hourly in order to keep time from creeping with the crystal //Sync time with the server, this will be called hourly in order to keep time from creeping with the crystal
@@ -154,10 +161,9 @@ void setup()
unsigned long functionTimeout = millis(); unsigned long functionTimeout = millis();
while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL) while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
{ {
gw.process(); requestTime(receiveTime);
gw.requestTime(receiveTime);
DEBUG_PRINTLN(F("Getting Time")); DEBUG_PRINTLN(F("Getting Time"));
gw.wait(1000); // call once per second wait(1000); // call once per second
DEBUG_PRINTLN(F(".")); DEBUG_PRINTLN(F("."));
} }
currentHour = hour(); currentHour = hour();
@@ -168,7 +174,7 @@ void setup()
boolean isDataOnEeprom = false; boolean isDataOnEeprom = false;
for (int i = 0; i < E_BUFFER_LENGTH; i++) for (int i = 0; i < E_BUFFER_LENGTH; i++)
{ {
byte locator = gw.loadState(EEPROM_BUFFER_LOCATION + i); byte locator = loadState(EEPROM_BUFFER_LOCATION + i);
if (locator == 0xFE) // found the EEPROM circular buffer index if (locator == 0xFE) // found the EEPROM circular buffer index
{ {
eepromIndex = EEPROM_BUFFER_LOCATION + i; eepromIndex = EEPROM_BUFFER_LOCATION + i;
@@ -185,36 +191,36 @@ void setup()
{ {
DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0")); DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0"));
eepromIndex = EEPROM_BUFFER_LOCATION; eepromIndex = EEPROM_BUFFER_LOCATION;
gw.saveState(eepromIndex, 0xFE); saveState(eepromIndex, 0xFE);
gw.saveState(eepromIndex + 1, 0xFE); saveState(eepromIndex + 1, 0xFE);
//then I will clear out any bad data //then I will clear out any bad data
for (int i = 2; i <= E_BUFFER_LENGTH; i++) for (int i = 2; i <= E_BUFFER_LENGTH; i++)
{ {
gw.saveState(i, 0x00); saveState(i, 0x00);
} }
} }
dataMillis = millis(); dataMillis = millis();
lastTipTime = millis() - oneHour; //why is this -oneHour?? Doesn't millis() start at 0 when first powered on? lastTipTime = millis() - oneHour; //why is this -oneHour?? Doesn't millis() start at 0 when first powered on?
// //
gw.request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1); request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
gw.request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2); request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
// //
#ifdef DHT_ON #ifdef DHT_ON
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Register all sensors to gw (they will be created as child devices) // Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_HUM, S_HUM);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
gw.present(CHILD_ID_TEMP, S_TEMP); present(CHILD_ID_TEMP, S_TEMP);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
metric = gw.getConfig().isMetric; metric = getConfig().isMetric;
gw.wait(DWELL_TIME); wait(DWELL_TIME);
#endif #endif
// //
#ifdef LUX_ON #ifdef LUX_ON
gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
lightSensor.begin(); lightSensor.begin();
#endif #endif
// //
@@ -224,7 +230,6 @@ void setup()
void loop() void loop()
{ {
gw.process();
if (state) if (state)
{ {
prettyFade(); // breathe if tripped prettyFade(); // breathe if tripped
@@ -261,8 +266,8 @@ void loop()
state = (measure >= (rainSensorThreshold * 100)); state = (measure >= (rainSensorThreshold * 100));
if (state != oldState) if (state != oldState)
{ {
gw.send(msgTripped.set(state)); send(msgTripped.set(state));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
DEBUG_PRINT(F("New Sensor State... Sensor: ")); DEBUG_PRINT(F("New Sensor State... Sensor: "));
DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped"); DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped");
oldState = state; oldState = state;
@@ -274,14 +279,14 @@ void loop()
DEBUG_PRINTLN(F("Sensor Tipped")); DEBUG_PRINTLN(F("Sensor Tipped"));
DEBUG_PRINT(F("rainBucket [0] value: ")); DEBUG_PRINT(F("rainBucket [0] value: "));
DEBUG_PRINTLN(rainBucket [0]); DEBUG_PRINTLN(rainBucket [0]);
gw.send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day
gw.wait(DWELL_TIME); wait(DWELL_TIME);
wasTippedBuffer--; wasTippedBuffer--;
rainRate = ((oneHour) / tipDelay); rainRate = ((oneHour) / tipDelay);
if (rainRate != lastRainRate) if (rainRate != lastRainRate)
{ {
gw.send(msgRainRate.set(rainRate, 1)); send(msgRainRate.set(rainRate, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
DEBUG_PRINT(F("RainRate= ")); DEBUG_PRINT(F("RainRate= "));
DEBUG_PRINTLN(rainRate); DEBUG_PRINTLN(rainRate);
lastRainRate = rainRate; lastRainRate = rainRate;
@@ -293,20 +298,20 @@ void loop()
if (currentHour != lastHour) if (currentHour != lastHour)
{ {
DEBUG_PRINTLN(F("One hour elapsed.")); DEBUG_PRINTLN(F("One hour elapsed."));
gw.send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall
gw.wait(DWELL_TIME); wait(DWELL_TIME);
gw.saveState(eepromIndex, highByte(rainBucket[0])); saveState(eepromIndex, highByte(rainBucket[0]));
gw.saveState(eepromIndex + 1, lowByte(rainBucket[0])); saveState(eepromIndex + 1, lowByte(rainBucket[0]));
DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = ")); DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = "));
DEBUG_PRINTLN(rainBucket[0]); DEBUG_PRINTLN(rainBucket[0]);
for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array
{ {
rainBucket [i + 1] = rainBucket [i]; rainBucket [i + 1] = rainBucket [i];
} }
gw.request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1); request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
gw.request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2); request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
gw.wait(DWELL_TIME); wait(DWELL_TIME);
rainBucket[0] = 0; rainBucket[0] = 0;
eepromIndex = eepromIndex + 2; eepromIndex = eepromIndex + 2;
if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH) if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH)
@@ -315,14 +320,14 @@ void loop()
} }
DEBUG_PRINT(F("Writing to EEPROM. Index: ")); DEBUG_PRINT(F("Writing to EEPROM. Index: "));
DEBUG_PRINTLN(eepromIndex); DEBUG_PRINTLN(eepromIndex);
gw.saveState(eepromIndex, 0xFE); saveState(eepromIndex, 0xFE);
gw.saveState(eepromIndex + 1, 0xFE); saveState(eepromIndex + 1, 0xFE);
gw.requestTime(receiveTime); // sync the time every hour requestTime(receiveTime); // sync the time every hour
gw.wait(DWELL_TIME); wait(DWELL_TIME);
transmitRainData(); transmitRainData();
rainRate = 0; rainRate = 0;
gw.send(msgRainRate.set(rainRate, 1)); send(msgRainRate.set(rainRate, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
DEBUG_PRINTLN(F("Sending rainRate is 0 to controller")); DEBUG_PRINTLN(F("Sending rainRate is 0 to controller"));
lastHour = currentHour; lastHour = currentHour;
} }
@@ -352,8 +357,8 @@ void doDHT(void)
{ {
temperature = dht.toFahrenheit(temperature); temperature = dht.toFahrenheit(temperature);
} }
gw.send(msgTemp.set(temperature, 1)); send(msgTemp.set(temperature, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
DEBUG_PRINT(F("Temperature is: ")); DEBUG_PRINT(F("Temperature is: "));
DEBUG_PRINTLN(temperature); DEBUG_PRINTLN(temperature);
} }
@@ -364,8 +369,8 @@ void doDHT(void)
} else if (humidity != lastHum) } else if (humidity != lastHum)
{ {
lastHum = humidity; lastHum = humidity;
gw.send(msgHum.set(humidity, 1)); send(msgHum.set(humidity, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
DEBUG_PRINT(F("Humidity is: ")); DEBUG_PRINT(F("Humidity is: "));
DEBUG_PRINTLN(humidity); DEBUG_PRINTLN(humidity);
} }
@@ -381,7 +386,7 @@ void doLUX(void)
heartbeat++; heartbeat++;
if (lux != lastlux || heartbeat > 10) if (lux != lastlux || heartbeat > 10)
{ {
gw.send(msg.set(lux)); send(msg.set(lux));
lastlux = lux; lastlux = lux;
} }
if (heartbeat > 10) if (heartbeat > 10)
@@ -437,8 +442,8 @@ void loadRainArray(int value) // retrieve stored rain array from EEPROM on power
} }
DEBUG_PRINT(F("EEPROM location: ")); DEBUG_PRINT(F("EEPROM location: "));
DEBUG_PRINTLN(value); DEBUG_PRINTLN(value);
byte rainValueHigh = gw.loadState(value); byte rainValueHigh = loadState(value);
byte rainValueLow = gw.loadState(value + 1); byte rainValueLow = loadState(value + 1);
unsigned int rainValue = rainValueHigh << 8; unsigned int rainValue = rainValueHigh << 8;
rainValue |= rainValueLow; rainValue |= rainValueLow;
rainBucket[i + 1] = rainValue; rainBucket[i + 1] = rainValue;
@@ -464,8 +469,8 @@ void transmitRainData(void)
} }
DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = ")); DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = "));
DEBUG_PRINTLN((float)rainUpdateTotal / 100.0); DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
gw.send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight) send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight)
gw.wait(DWELL_TIME); wait(DWELL_TIME);
#ifdef USE_DAILY #ifdef USE_DAILY
rainUpdateTotal = 0; rainUpdateTotal = 0;
#endif #endif
@@ -478,8 +483,8 @@ void transmitRainData(void)
} }
DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = ")); DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = "));
DEBUG_PRINTLN((float)rainUpdateTotal / 100.0); DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
gw.send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1)); send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
#ifdef USE_DAILY #ifdef USE_DAILY
rainUpdateTotal = 0; rainUpdateTotal = 0;
#endif #endif
@@ -492,8 +497,8 @@ void transmitRainData(void)
} }
DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = ")); DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = "));
DEBUG_PRINTLN((float)rainUpdateTotal / 100.0); DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
gw.send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1)); send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
#ifdef USE_DAILY #ifdef USE_DAILY
rainUpdateTotal = 0; rainUpdateTotal = 0;
#endif #endif
@@ -506,8 +511,8 @@ void transmitRainData(void)
} }
DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = ")); DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = "));
DEBUG_PRINTLN((float)rainUpdateTotal / 100.0); DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
gw.send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1)); send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
#ifdef USE_DAILY #ifdef USE_DAILY
rainUpdateTotal = 0; rainUpdateTotal = 0;
#endif #endif
@@ -520,8 +525,8 @@ void transmitRainData(void)
} }
DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = ")); DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = "));
DEBUG_PRINTLN((float)rainUpdateTotal / 100.0); DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
gw.send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1)); send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1));
gw.wait(DWELL_TIME); wait(DWELL_TIME);
} }
void getVariables(const MyMessage &message) void getVariables(const MyMessage &message)
@@ -545,7 +550,7 @@ void getVariables(const MyMessage &message)
} }
if (rainWindow != atoi(message.data)) // if I changed the value back inside the boundries, push that number back to Vera if (rainWindow != atoi(message.data)) // if I changed the value back inside the boundries, push that number back to Vera
{ {
gw.send(msgTrippedVar1.set(rainWindow)); send(msgTrippedVar1.set(rainWindow));
} }
} }
else if (message.type == V_VAR2) else if (message.type == V_VAR2)
@@ -561,7 +566,7 @@ void getVariables(const MyMessage &message)
} }
if (rainSensorThreshold != atoi(message.data)) // if I changed the value back inside the boundries, push that number back to Vera if (rainSensorThreshold != atoi(message.data)) // if I changed the value back inside the boundries, push that number back to Vera
{ {
gw.send(msgTrippedVar2.set(rainSensorThreshold)); send(msgTrippedVar2.set(rainSensorThreshold));
} }
} }
} }
@@ -39,15 +39,19 @@
* *
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensor.h> #include <MySensor.h>
#include <Time.h> #include <Time.h>
#include <DS3232RTC.h> // A DS3231/DS3232 library #include <DS3232RTC.h> // A DS3231/DS3232 library
#include <Wire.h> #include <Wire.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
MySensor gw;
boolean timeReceived = false; boolean timeReceived = false;
unsigned long lastUpdate=0, lastRequest=0; unsigned long lastUpdate=0, lastRequest=0;
@@ -57,16 +61,14 @@ LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("RTC Clock", "1.0"); sendSketchInfo("RTC Clock", "1.0");
// the function to get the time from the RTC // the function to get the time from the RTC
setSyncProvider(RTC.get); setSyncProvider(RTC.get);
// Request latest time from controller at startup // Request latest time from controller at startup
gw.requestTime(receiveTime); requestTime(receiveTime);
// initialize the lcd for 16 chars 2 lines and turn on backlight // initialize the lcd for 16 chars 2 lines and turn on backlight
lcd.begin(16,2); lcd.begin(16,2);
@@ -84,7 +86,6 @@ void receiveTime(unsigned long controllerTime) {
void loop() void loop()
{ {
unsigned long now = millis(); unsigned long now = millis();
gw.process();
// If no time has been received yet, request it every 10 second from controller // If no time has been received yet, request it every 10 second from controller
// When time has been received, request update every hour // When time has been received, request update every hour
@@ -92,7 +93,7 @@ void loop()
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) { || (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
// Request time from controller. // Request time from controller.
Serial.println("requesting time"); Serial.println("requesting time");
gw.requestTime(receiveTime); requestTime(receiveTime);
lastRequest = now; lastRequest = now;
} }
@@ -29,8 +29,17 @@
* http://www.mysensors.org/build/relay * http://www.mysensors.org/build/relay
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
// Enabled repeater feature for this node
#define MY_REPEATER_FEATURE
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h> #include <Bounce2.h>
#define RELAY_PIN 4 // Arduino Digital I/O pin number for relay #define RELAY_PIN 4 // Arduino Digital I/O pin number for relay
@@ -42,15 +51,15 @@
Bounce debouncer = Bounce(); Bounce debouncer = Bounce();
int oldValue=0; int oldValue=0;
bool state; bool state;
MySensor gw;
MyMessage msg(CHILD_ID,V_LIGHT); MyMessage msg(CHILD_ID,V_LIGHT);
void setup() void setup()
{ {
gw.begin(incomingMessage, AUTO, true); setIncomingCallback(incomingMessage);
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Relay & Button", "1.0"); sendSketchInfo("Relay & Button", "1.0");
// Setup the button // Setup the button
pinMode(BUTTON_PIN,INPUT); pinMode(BUTTON_PIN,INPUT);
@@ -62,7 +71,7 @@ void setup()
debouncer.interval(5); debouncer.interval(5);
// Register all sensors to gw (they will be created as child devices) // Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID, S_LIGHT); present(CHILD_ID, S_LIGHT);
// Make sure relays are off when starting up // Make sure relays are off when starting up
digitalWrite(RELAY_PIN, RELAY_OFF); digitalWrite(RELAY_PIN, RELAY_OFF);
@@ -70,7 +79,7 @@ void setup()
pinMode(RELAY_PIN, OUTPUT); pinMode(RELAY_PIN, OUTPUT);
// Set relay to last known state (using eeprom storage) // Set relay to last known state (using eeprom storage)
state = gw.loadState(CHILD_ID); state = loadState(CHILD_ID);
digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
} }
@@ -80,12 +89,11 @@ void setup()
*/ */
void loop() void loop()
{ {
gw.process();
debouncer.update(); debouncer.update();
// Get the update value // Get the update value
int value = debouncer.read(); int value = debouncer.read();
if (value != oldValue && value==0) { if (value != oldValue && value==0) {
gw.send(msg.set(state?false:true), true); // Send new state and request ack back send(msg.set(state?false:true), true); // Send new state and request ack back
} }
oldValue = value; oldValue = value;
} }
@@ -101,7 +109,7 @@ void incomingMessage(const MyMessage &message) {
state = message.getBool(); state = message.getBool();
digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
// Store state in eeprom // Store state in eeprom
gw.saveState(CHILD_ID, state); saveState(CHILD_ID, state);
// Write some debug info // Write some debug info
Serial.print("Incoming change for sensor:"); Serial.print("Incoming change for sensor:");
@@ -25,26 +25,28 @@
* Example sketch showing how to create a node thay repeates messages * Example sketch showing how to create a node thay repeates messages
* from nodes far from gateway back to gateway. * from nodes far from gateway back to gateway.
* It is important that nodes that has enabled repeater mode calls * It is important that nodes that has enabled repeater mode calls
* gw.process() frequently. Repeaters should never sleep. * process() frequently. Repeaters should never sleep.
*/ */
#include <MySensor.h> // Enable debug prints to serial monitor
#include <SPI.h> #define MY_DEBUG
MySensor gw; // Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
// Enabled repeater feature for this node
#define MY_REPEATER_FEATURE
#include <MySensor.h>
void setup() void setup()
{ {
// The third argument enables repeater mode.
gw.begin(NULL, AUTO, true);
//Send the sensor node sketch version information to the gateway //Send the sensor node sketch version information to the gateway
gw.sendSketchInfo("Repeater Node", "1.0"); sendSketchInfo("Repeater Node", "1.0");
} }
void loop() void loop()
{ {
// By calling process() you route messages in the background
gw.process();
} }
@@ -50,8 +50,15 @@
* http://www.mysensors.org/build/connect_radio * http://www.mysensors.org/build/connect_radio
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#define CHILD_ID 99 // Id of the sensor child #define CHILD_ID 99 // Id of the sensor child
@@ -80,9 +87,8 @@ int knockSensorValue = 0; // Last reading of the knock sensor.
boolean programModeActive = false; // True if we're trying to program a new knock. boolean programModeActive = false; // True if we're trying to program a new knock.
bool lockStatus; bool lockStatus;
MySensor gw;
MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS);
MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS);
void setup() { void setup() {
@@ -92,24 +98,23 @@ void setup() {
pinMode(programButton, INPUT); pinMode(programButton, INPUT);
digitalWrite(programButton, HIGH); // Enable internal pull up digitalWrite(programButton, HIGH); // Enable internal pull up
gw.begin(incomingMessage); setIncomingCallback(incomingMessage);
gw.sendSketchInfo("Secret Knock", "1.0"); sendSketchInfo("Secret Knock", "1.0");
gw.present(CHILD_ID, S_LOCK); present(CHILD_ID, S_LOCK);
readSecretKnock(); // Load the secret knock (if any) from EEPROM. readSecretKnock(); // Load the secret knock (if any) from EEPROM.
digitalWrite(lockPin, HIGH); // Unlock the door for a bit when we power up. For system check and to allow a way in if the key is forgotten digitalWrite(lockPin, HIGH); // Unlock the door for a bit when we power up. For system check and to allow a way in if the key is forgotten
delay(500); // Wait a short time delay(500); // Wait a short time
lockStatus = gw.loadState(0); // Read last lock status from eeprom lockStatus = loadState(0); // Read last lock status from eeprom
setLockState(lockStatus, true); // Now set the last known state and send it to controller setLockState(lockStatus, true); // Now set the last known state and send it to controller
delay(500); // This delay is here because the solenoid lock returning to place can otherwise trigger and inadvertent knock. delay(500); // This delay is here because the solenoid lock returning to place can otherwise trigger and inadvertent knock.
} }
void loop() { void loop() {
gw.process(); // Process incomming messages
// Listen for any knock at all. // Listen for any knock at all.
knockSensorValue = digitalRead(knockSensor); knockSensorValue = digitalRead(knockSensor);
if (digitalRead(programButton) == LOW){ // is the program button pressed? if (digitalRead(programButton) == LOW){ // is the program button pressed?
@@ -219,17 +224,17 @@ void listenToSecretKnock(){
// Unlocks the door. // Unlocks the door.
void setLockState(bool state, bool send){ void setLockState(bool state, bool doSend){
if (state) if (state)
Serial.println("open lock"); Serial.println("open lock");
else else
Serial.println("close lock"); Serial.println("close lock");
if (send) if (doSend)
gw.send(lockMsg.set(state)); send(lockMsg.set(state));
digitalWrite(ledPin, state); digitalWrite(ledPin, state);
digitalWrite(lockPin, state); digitalWrite(lockPin, state);
gw.saveState(0,state); saveState(0,state);
lockStatus = state; lockStatus = state;
delay(500); // This delay is here because releasing the latch can cause a vibration that will be sensed as a knock. delay(500); // This delay is here because releasing the latch can cause a vibration that will be sensed as a knock.
} }
@@ -298,10 +303,10 @@ boolean validateKnock(){
// reads the secret knock from EEPROM. (if any.) // reads the secret knock from EEPROM. (if any.)
void readSecretKnock(){ void readSecretKnock(){
byte reading; byte reading;
reading = gw.loadState(1); reading = loadState(1);
if (reading == eepromValid){ // only read EEPROM if the signature byte is correct. if (reading == eepromValid){ // only read EEPROM if the signature byte is correct.
for (int i=0; i < maximumKnocks ;i++){ for (int i=0; i < maximumKnocks ;i++){
secretCode[i] = gw.loadState(i+2); secretCode[i] = loadState(i+2);
} }
} }
} }
@@ -309,11 +314,11 @@ void readSecretKnock(){
//saves a new pattern too eeprom //saves a new pattern too eeprom
void saveSecretKnock(){ void saveSecretKnock(){
gw.saveState(1, 0); // clear out the signature. That way we know if we didn't finish the write successfully. saveState(1, 0); // clear out the signature. That way we know if we didn't finish the write successfully.
for (int i=0; i < maximumKnocks; i++){ for (int i=0; i < maximumKnocks; i++){
gw.saveState(i+2, secretCode[i]); saveState(i+2, secretCode[i]);
} }
gw.saveState(1, eepromValid); // all good. Write the signature so we'll know it's all good. saveState(1, eepromValid); // all good. Write the signature so we'll know it's all good.
} }
// Plays back the pattern of the knock in blinks and beeps // Plays back the pattern of the knock in blinks and beeps
@@ -1,9 +1,17 @@
// Sensebender Micro board // Sensebender Micro board
// Simple blinking FW to test OTA updates // Simple blinking FW to test OTA updates
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable repeater feature
#define MY_REPEATER_FEATURE
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include "utility/SPIFlash.h"
#define SketchName "Sensebender Blink" #define SketchName "Sensebender Blink"
#define SketchVersion "20150721" #define SketchVersion "20150721"
@@ -17,32 +25,26 @@
unsigned long lastUpdate = 0; unsigned long lastUpdate = 0;
boolean LED_STATUS = false; boolean LED_STATUS = false;
SPIFlash flash(8, 0x1F65);
MySensor gw;
MyMessage msgCounter(CHILD_ID_COUNTER, V_VAR1); MyMessage msgCounter(CHILD_ID_COUNTER, V_VAR1);
void setup() { void setup() {
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LED_STATUS); digitalWrite(LED_PIN, LED_STATUS);
// repeater mode on sendSketchInfo(SketchName, SketchVersion);
gw.begin(NULL,NODE_ID,true);
gw.sendSketchInfo(SketchName, SketchVersion);
gw.present(CHILD_ID_COUNTER, S_CUSTOM,"Millis()");
present(CHILD_ID_COUNTER, S_CUSTOM,"Millis()");
} }
void loop() { void loop() {
gw.wait(BLINK_INTERVAL); wait(BLINK_INTERVAL);
LED_STATUS ^= true; LED_STATUS ^= true;
digitalWrite(LED_PIN, LED_STATUS); digitalWrite(LED_PIN, LED_STATUS);
if (millis()-lastUpdate > REPORT_TIME) { if (millis()-lastUpdate > REPORT_TIME) {
gw.send(msgCounter.set( millis() )); send(msgCounter.set( millis() ));
lastUpdate = millis(); lastUpdate = millis();
} }
} }
@@ -37,21 +37,26 @@
* *
*/ */
// Enable debug prints to serial monitor
//#define MY_DEBUG
// Define a static node address, remove if you want auto address assignment
//#deine MY_NODE_ID 3
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <Wire.h> #include <Wire.h>
#include <SI7021.h> #include <SI7021.h>
#include <SPI.h> #include "drivers/SPIFlash/SPIFlash.cpp"
#include "utility/SPIFlash.h"
#include <EEPROM.h> #include <EEPROM.h>
#include <sha204_lib_return_codes.h> #include <sha204_lib_return_codes.h>
#include <sha204_library.h> #include <sha204_library.h>
#include <RunningAverage.h> #include <RunningAverage.h>
//#include <avr/power.h> //#include <avr/power.h>
// Define a static node address, remove if you want auto address assignment
//#define NODE_ADDRESS 3
// Uncomment the line below, to transmit battery voltage as a normal sensor value // Uncomment the line below, to transmit battery voltage as a normal sensor value
//#define BATT_SENSOR 199 //#define BATT_SENSOR 199
@@ -92,8 +97,6 @@ atsha204Class sha204(sha204Pin);
SI7021 humiditySensor; SI7021 humiditySensor;
SPIFlash flash(8, 0x1F65); SPIFlash flash(8, 0x1F65);
MySensor gw;
// Sensor messages // Sensor messages
MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
@@ -153,29 +156,23 @@ void setup() {
digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN, HIGH);
#ifdef NODE_ADDRESS
gw.begin(NULL, NODE_ADDRESS, false);
#else
gw.begin(NULL,AUTO,false);
#endif
humiditySensor.begin(); humiditySensor.begin();
digitalWrite(LED_PIN, LOW); digitalWrite(LED_PIN, LOW);
Serial.flush(); Serial.flush();
Serial.println(F(" - Online!")); Serial.println(F(" - Online!"));
gw.sendSketchInfo("Sensebender Micro", RELEASE); sendSketchInfo("Sensebender Micro", RELEASE);
gw.present(CHILD_ID_TEMP,S_TEMP); present(CHILD_ID_TEMP,S_TEMP);
gw.present(CHILD_ID_HUM,S_HUM); present(CHILD_ID_HUM,S_HUM);
#ifdef BATT_SENSOR #ifdef BATT_SENSOR
gw.present(BATT_SENSOR, S_POWER); present(BATT_SENSOR, S_POWER);
#endif #endif
isMetric = gw.getConfig().isMetric; isMetric = getConfig().isMetric;
Serial.print(F("isMetric: ")); Serial.println(isMetric); Serial.print(F("isMetric: ")); Serial.println(isMetric);
raHum.clear(); raHum.clear();
sendTempHumidityMeasurements(false); sendTempHumidityMeasurements(false);
@@ -207,8 +204,6 @@ void loop() {
measureCount = 0; measureCount = 0;
} }
gw.process();
sendTempHumidityMeasurements(forceTransmit); sendTempHumidityMeasurements(forceTransmit);
if (sendBattery > 60) if (sendBattery > 60)
{ {
@@ -217,10 +212,10 @@ void loop() {
} }
if (ota_enabled & transmission_occured) { if (ota_enabled & transmission_occured) {
gw.wait(OTA_WAIT_PERIOD); wait(OTA_WAIT_PERIOD);
} }
gw.sleep(MEASURE_INTERVAL); sleep(MEASURE_INTERVAL);
} }
@@ -258,8 +253,8 @@ void sendTempHumidityMeasurements(bool force)
Serial.print("T: ");Serial.println(temperature); Serial.print("T: ");Serial.println(temperature);
Serial.print("H: ");Serial.println(humidity); Serial.print("H: ");Serial.println(humidity);
gw.send(msgTemp.set(temperature,1)); send(msgTemp.set(temperature,1));
gw.send(msgHum.set(humidity)); send(msgHum.set(humidity));
lastTemperature = temperature; lastTemperature = temperature;
lastHumidity = humidity; lastHumidity = humidity;
transmission_occured = true; transmission_occured = true;
@@ -282,7 +277,7 @@ void sendBattLevel(bool force)
lastBattery = vcc; lastBattery = vcc;
#ifdef BATT_SENSOR #ifdef BATT_SENSOR
gw.send(msgBatt.set(vcc)); send(msgBatt.set(vcc));
#endif #endif
// Calculate percentage // Calculate percentage
@@ -290,7 +285,7 @@ void sendBattLevel(bool force)
vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
long percent = vcc / 14.0; long percent = vcc / 14.0;
gw.sendBatteryLevel(percent); sendBatteryLevel(percent);
transmission_occured = true; transmission_occured = true;
} }
} }
@@ -31,9 +31,14 @@
* http://www.mysensors.org/build/servo * http://www.mysensors.org/build/servo
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <Servo.h> #include <Servo.h>
#define SERVO_DIGITAL_OUT_PIN 3 #define SERVO_DIGITAL_OUT_PIN 3
@@ -42,7 +47,6 @@
#define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo #define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
#define CHILD_ID 10 // Id of the sensor child #define CHILD_ID 10 // Id of the sensor child
MySensor gw;
MyMessage msg(CHILD_ID, V_DIMMER); MyMessage msg(CHILD_ID, V_DIMMER);
Servo myservo; // create servo object to control a servo Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created Sensor gw(9,10); // a maximum of eight servo objects can be created Sensor gw(9,10);
@@ -52,21 +56,20 @@ bool attachedServo = false;
void setup() void setup()
{ {
// Attach method for incoming messages // Attach method for incoming messages
gw.begin(incomingMessage); setIncomingCallback(incomingMessage);
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Servo", "1.0"); sendSketchInfo("Servo", "1.0");
// Register all sensors to gw (they will be created as child devices) // Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID, S_COVER); present(CHILD_ID, S_COVER);
// Request last servo state at startup // Request last servo state at startup
gw.request(CHILD_ID, V_DIMMER); request(CHILD_ID, V_DIMMER);
} }
void loop() void loop()
{ {
gw.process();
if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) { if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) {
myservo.detach(); myservo.detach();
attachedServo = false; attachedServo = false;
@@ -85,11 +88,11 @@ void incomingMessage(const MyMessage &message) {
} else if (message.type==V_UP) { } else if (message.type==V_UP) {
Serial.println("Servo UP command"); Serial.println("Servo UP command");
myservo.write(SERVO_MIN); myservo.write(SERVO_MIN);
gw.send(msg.set(100)); send(msg.set(100));
} else if (message.type==V_DOWN) { } else if (message.type==V_DOWN) {
Serial.println("Servo DOWN command"); Serial.println("Servo DOWN command");
myservo.write(SERVO_MAX); myservo.write(SERVO_MAX);
gw.send(msg.set(0)); send(msg.set(0));
} else if (message.type==V_STOP) { } else if (message.type==V_STOP) {
Serial.println("Servo STOP command"); Serial.println("Servo STOP command");
myservo.detach(); myservo.detach();
@@ -60,15 +60,20 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <math.h> // Conversion equation from resistance to % #include <math.h> // Conversion equation from resistance to %
#include <SPI.h>
#include <MySensor.h> #include <MySensor.h>
// Setting up format for reading 3 soil sensors // Setting up format for reading 3 soil sensors
#define NUM_READS 10 // Number of sensor reads for filtering #define NUM_READS 10 // Number of sensor reads for filtering
#define CHILD_ID 0 #define CHILD_ID 0
MySensor gw; // Arduino initialization
MyMessage msg(CHILD_ID, V_LEVEL); MyMessage msg(CHILD_ID, V_LEVEL);
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
@@ -90,11 +95,9 @@ values valueOf[NUM_READS]; // Calculated moisture percentages and resista
int i; // Simple index variable int i; // Simple index variable
void setup() { void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(115200); sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
gw.begin(); present(CHILD_ID, S_HUM);
gw.sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
gw.present(CHILD_ID, S_HUM);
// initialize the digital pins as an output. // initialize the digital pins as an output.
// Pin 6,7 is for sensor 1 // Pin 6,7 is for sensor 1
// initialize the digital pin as an output. // initialize the digital pin as an output.
@@ -104,8 +107,6 @@ void setup() {
// initialize the digital pin as an output. // initialize the digital pin as an output.
// Pin 7 is sense resistor voltage supply 2 // Pin 7 is sense resistor voltage supply 2
pinMode(7, OUTPUT); pinMode(7, OUTPUT);
} }
void loop() { void loop() {
@@ -129,9 +130,9 @@ void loop() {
Serial.println (); Serial.println ();
//send back the values //send back the values
gw.send(msg.set((long int)ceil(sensor1))); send(msg.set((long int)ceil(sensor1)));
// delay until next measurement (msec) // delay until next measurement (msec)
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
void measure (int phase_b, int phase_a, int analog_input) void measure (int phase_b, int phase_a, int analog_input)
@@ -25,24 +25,26 @@
* Example sketch showing how to request time from controller. * Example sketch showing how to request time from controller.
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensor.h> #include <MySensor.h>
#include <Time.h> #include <Time.h>
MySensor gw;
boolean timeReceived = false; boolean timeReceived = false;
unsigned long lastUpdate=0, lastRequest=0; unsigned long lastUpdate=0, lastRequest=0;
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Clock", "1.0"); sendSketchInfo("Clock", "1.0");
// Request time from controller. // Request time from controller.
gw.requestTime(receiveTime); requestTime(receiveTime);
} }
// This is called when a new time value was received // This is called when a new time value was received
@@ -55,15 +57,14 @@ void receiveTime(unsigned long time) {
void loop() void loop()
{ {
unsigned long now = millis(); unsigned long now = millis();
gw.process();
// If no time has been received yet, request it every 10 second from controller // If no time has been received yet, request it every 10 second from controller
// When time has been received, request update every hour // When time has been received, request update every hour
if ((!timeReceived && (now-lastRequest) > (10UL*1000UL)) if ((!timeReceived && (now-lastRequest) > (10UL*1000UL))
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) { || (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
// Request time from controller. // Request time from controller.
Serial.println("requesting time"); Serial.println("requesting time");
gw.requestTime(receiveTime); requestTime(receiveTime);
lastRequest = now; lastRequest = now;
} }
@@ -37,8 +37,6 @@
* The 3v3 output on the ATMega2560 is especially bad. I had to use a step down * The 3v3 output on the ATMega2560 is especially bad. I had to use a step down
* on the 5V output to get solid transmissions. * on the 5V output to get solid transmissions.
* *
* The shield does not seem like sharing SPI with RF24 so you'll have to
* activate SOFTSPI-define in MySenors/util/RF24_config.h
* *
* Connect radio * Connect radio
* ---------------------------------- * ----------------------------------
@@ -54,8 +52,16 @@
* *
*/ */
#include <DigitalIO.h> // Enable debug prints to serial monitor
#include <SPI.h> #define MY_DEBUG
// Enable soft spi as radio has a hard time sharing spi
#define MY_SOFTSPI
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <Time.h> #include <Time.h>
#include <MySensor.h> #include <MySensor.h>
#include <stdarg.h> #include <stdarg.h>
@@ -87,9 +93,6 @@ const int buttonCount = sizeof(buttons)/sizeof(char *);
const int padding = 10; const int padding = 10;
const int topBarHeight = 60; const int topBarHeight = 60;
MyTransportNRF24 radio; // NRFRF24L01 radio driver
MyHwATMega328 hw; // Select AtMega328 hardware profile
MySensor gw(radio, hw);
MyMessage on(CHILD_ID, V_SCENE_ON); MyMessage on(CHILD_ID, V_SCENE_ON);
MyMessage off(CHILD_ID, V_SCENE_OFF); MyMessage off(CHILD_ID, V_SCENE_OFF);
@@ -103,8 +106,6 @@ char timeBuf[20];
void setup() void setup()
{ {
gw.begin(NULL, AUTO, false, 0);
myGLCD.InitLCD(); myGLCD.InitLCD();
myGLCD.clrScr(); myGLCD.clrScr();
myGLCD.setFont((uint8_t*)ArialNumFontPlus); myGLCD.setFont((uint8_t*)ArialNumFontPlus);
@@ -127,10 +128,10 @@ void setup()
myButtons.drawButtons(); myButtons.drawButtons();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Scene Ctrl", "1.0"); sendSketchInfo("Scene Ctrl", "1.0");
gw.present(CHILD_ID, S_SCENE_CONTROLLER); present(CHILD_ID, S_SCENE_CONTROLLER);
// Request time from controller. // Request time from controller.
gw.requestTime(receiveTime); requestTime(receiveTime);
} }
@@ -140,7 +141,6 @@ unsigned long lastPressedButtonTime = 0;
void loop() void loop()
{ {
gw.process();
unsigned long now = millis(); unsigned long now = millis();
if (myTouch.dataAvailable()) { if (myTouch.dataAvailable()) {
@@ -151,10 +151,10 @@ void loop()
if (pressedButton != lastPressedButton || now-lastPressedButtonTime > (unsigned long)RESEND_DEBOUNCE) { if (pressedButton != lastPressedButton || now-lastPressedButtonTime > (unsigned long)RESEND_DEBOUNCE) {
if (longPress) { if (longPress) {
gw.send(off.set(pressedButton)); send(off.set(pressedButton));
Serial.print("Long pressed: "); Serial.print("Long pressed: ");
} else { } else {
gw.send(on.set(pressedButton)); send(on.set(pressedButton));
Serial.print("Pressed: "); Serial.print("Pressed: ");
} }
Serial.println(pressedButton); Serial.println(pressedButton);
@@ -170,7 +170,7 @@ void loop()
|| (timeReceived && now-lastRequest > (unsigned long)60*1000*60)) { || (timeReceived && now-lastRequest > (unsigned long)60*1000*60)) {
// Request time from controller. // Request time from controller.
Serial.println("requesting time"); Serial.println("requesting time");
gw.requestTime(receiveTime); requestTime(receiveTime);
lastRequest = now; lastRequest = now;
} }
@@ -36,10 +36,14 @@
* License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) * License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
*/ */
#include <SPI.h> // Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <MySensor.h>
#include <SPI.h>
#define UV_SENSOR_ANALOG_PIN 0 #define UV_SENSOR_ANALOG_PIN 0
@@ -47,7 +51,6 @@
unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
MySensor gw;
MyMessage uvMsg(CHILD_ID_UV, V_UV); MyMessage uvMsg(CHILD_ID_UV, V_UV);
unsigned long lastSend =0; unsigned long lastSend =0;
@@ -57,13 +60,11 @@ uint16_t uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976,
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("UV Sensor", "1.2"); sendSketchInfo("UV Sensor", "1.2");
// Register all sensors to gateway (they will be created as child devices) // Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_UV, S_UV); present(CHILD_ID_UV, S_UV);
} }
void loop() void loop()
@@ -100,9 +101,9 @@ void loop()
//Send value to gateway if changed, or at least every 5 minutes //Send value to gateway if changed, or at least every 5 minutes
if ((uvIndex != lastUV)||(currentTime-lastSend >= 5UL*60UL*1000UL)) { if ((uvIndex != lastUV)||(currentTime-lastSend >= 5UL*60UL*1000UL)) {
lastSend=currentTime; lastSend=currentTime;
gw.send(uvMsg.set(uvIndex,2)); send(uvMsg.set(uvIndex,2));
lastUV = uvIndex; lastUV = uvIndex;
} }
gw.sleep(SLEEP_TIME); sleep(SLEEP_TIME);
} }
@@ -32,9 +32,14 @@
* Contributor: epierre * Contributor: epierre
**/ **/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#include <Wire.h> #include <Wire.h>
#define CHILD_ID_VIBRATION 0 #define CHILD_ID_VIBRATION 0
@@ -49,18 +54,15 @@ float valVIBRATION =0.0;
float lastVIBRATION =0.0; float lastVIBRATION =0.0;
unsigned char state = 0; unsigned char state = 0;
MySensor gw;
MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL); MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL);
void setup() void setup()
{ {
gw.begin();
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("VIBRATION Sensor", "1.0"); sendSketchInfo("VIBRATION Sensor", "1.0");
// Register all sensors to gateway (they will be created as child devices) // Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_VIBRATION, S_VIBRATION); present(CHILD_ID_VIBRATION, S_VIBRATION);
pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT); pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT);
@@ -72,7 +74,7 @@ void loop()
{ {
if(state>=40){ // basically below 40 so ignire basic level if(state>=40){ // basically below 40 so ignire basic level
gw.send(vibrationMsg.set(int(state))); send(vibrationMsg.set(int(state)));
state = 0; state = 0;
digitalWrite(SensorLED,HIGH); digitalWrite(SensorLED,HIGH);
} else { } else {
@@ -85,7 +87,7 @@ void loop()
// on the next write() call. // on the next write() call.
delay(1000); //delay to allow serial to fully print before sleep delay(1000); //delay to allow serial to fully print before sleep
gw.sleep(SLEEP_TIME); //sleep for: sleepTime sleep(SLEEP_TIME); //sleep for: sleepTime
} }
void blink()//Interrupts function void blink()//Interrupts function
@@ -34,8 +34,14 @@
* http://www.mysensors.org/build/pulse_water * http://www.mysensors.org/build/pulse_water
*/ */
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h> #include <MySensor.h>
#include <SPI.h>
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!)
#define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
@@ -50,7 +56,6 @@
unsigned long SEND_FREQUENCY = 30000; // Minimum time between send (in milliseconds). We don't want to spam the gateway. unsigned long SEND_FREQUENCY = 30000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
MySensor gw;
MyMessage flowMsg(CHILD_ID,V_FLOW); MyMessage flowMsg(CHILD_ID,V_FLOW);
MyMessage volumeMsg(CHILD_ID,V_VOLUME); MyMessage volumeMsg(CHILD_ID,V_VOLUME);
MyMessage lastCounterMsg(CHILD_ID,V_VAR1); MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
@@ -71,21 +76,21 @@ unsigned long lastPulse =0;
void setup() void setup()
{ {
gw.begin(incomingMessage); setIncomingCallback(incomingMessage);
// initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion) // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP); pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
// Send the sketch version information to the gateway and Controller // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Water Meter", "1.1"); sendSketchInfo("Water Meter", "1.1");
// Register this device as Waterflow sensor // Register this device as Waterflow sensor
gw.present(CHILD_ID, S_WATER); present(CHILD_ID, S_WATER);
pulseCount = oldPulseCount = 0; pulseCount = oldPulseCount = 0;
// Fetch last known pulse count value from gw // Fetch last known pulse count value from gw
gw.request(CHILD_ID, V_VAR1); request(CHILD_ID, V_VAR1);
lastSend = lastPulse = millis(); lastSend = lastPulse = millis();
@@ -95,7 +100,6 @@ void setup()
void loop() void loop()
{ {
gw.process();
unsigned long currentTime = millis(); unsigned long currentTime = millis();
// Only send values at a maximum frequency or woken up from sleep // Only send values at a maximum frequency or woken up from sleep
@@ -105,7 +109,7 @@ void loop()
if (!pcReceived) { if (!pcReceived) {
//Last Pulsecount not yet received from controller, request it again //Last Pulsecount not yet received from controller, request it again
gw.request(CHILD_ID, V_VAR1); request(CHILD_ID, V_VAR1);
return; return;
} }
@@ -118,7 +122,7 @@ void loop()
// Check that we dont get unresonable large flow value. // Check that we dont get unresonable large flow value.
// could hapen when long wraps or false interrupt triggered // could hapen when long wraps or false interrupt triggered
if (flow<((unsigned long)MAX_FLOW)) { if (flow<((unsigned long)MAX_FLOW)) {
gw.send(flowMsg.set(flow, 2)); // Send flow value to gw send(flowMsg.set(flow, 2)); // Send flow value to gw
} }
} }
@@ -134,7 +138,7 @@ void loop()
Serial.print("pulsecount:"); Serial.print("pulsecount:");
Serial.println(pulseCount); Serial.println(pulseCount);
gw.send(lastCounterMsg.set(pulseCount)); // Send pulsecount value to gw in VAR1 send(lastCounterMsg.set(pulseCount)); // Send pulsecount value to gw in VAR1
double volume = ((double)pulseCount/((double)PULSE_FACTOR)); double volume = ((double)pulseCount/((double)PULSE_FACTOR));
if ((volume != oldvolume)||(!SLEEP_MODE)) { if ((volume != oldvolume)||(!SLEEP_MODE)) {
@@ -143,12 +147,12 @@ void loop()
Serial.print("volume:"); Serial.print("volume:");
Serial.println(volume, 3); Serial.println(volume, 3);
gw.send(volumeMsg.set(volume, 3)); // Send volume value to gw send(volumeMsg.set(volume, 3)); // Send volume value to gw
} }
} }
} }
if (SLEEP_MODE) { if (SLEEP_MODE) {
gw.sleep(SEND_FREQUENCY); sleep(SEND_FREQUENCY);
} }
} }
+84
View File
@@ -0,0 +1,84 @@
#######################################
# Datatypes (KEYWORD1)
#######################################
MyMessage KEYWORD1
MySensor KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
setIncomingCallback KEYWORD2
present KEYWORD2
send KEYWORD2
sendSketchInfo KEYWORD2
sendBatteryLevel KEYWORD2
sendHeartbeat KEYWORD2
getNodeId KEYWORD2
request KEYWORD2
requestTime KEYWORD2
saveState KEYWORD2
loadState KEYWORD2
wait KEYWORD2
######################################
# Constants (LITERAL1)
#######################################
AUTO LITERAL1
MY_DEBUG LITERAL1
MY_REPEATER_FEATURE LITERAL1
MY_RADIO_NRF24 LITERAL1
MY_RADIO_RFM69 LITERAL1
MY_BAUD_RATE LITERAL1
MY_NODE_ID LITERAL1
MY_PARENT_NODE_ID LITERAL1
MY_OTA_FIRMWARE_FEATURE LITERAL1
MY_OTA_FLASH_SS LITERAL1
MY_OTA_FLASH_JDECID LITERAL1
MY_LEDS_BLINKING_FEATURE LITERAL1
WITH_LEDS_BLINKING_INVERSE LITERAL1
MY_DEFAULT_LED_BLINK_PERIOD LITERAL1
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1
MY_DEFAULT_RX_LED_PIN LITERAL1
MY_DEFAULT_TX_LED_PIN LITERAL1
MY_DEFAULT_ERR_LED_PIN LITERAL1
MY_INCLUSION_MODE_FEATURE LITERAL1
MY_INCLUSION_BUTTON_FEATURE LITERAL1
MY_INCLUSION_MODE_BUTTON_PIN LITERAL1
MY_INCLUSION_MODE_DURATION LITERAL1
MY_SIGNING_ATSHA204 LITERAL1
MY_SIGNING_SOFT LITERAL1
MY_VERIFICATION_TIMEOUT_MS LITERAL1
MY_SIGNING_NODE_WHITELIST LITERAL1
MY_SIGNING_ATSHA204_PIN LITERAL1
MY_SIGNING_SOFT_RANDOMSEED_PIN LITERAL1
MY_SIGNING_SOFT_SERIAL LITERAL1
MY_SIGNING_SOFT_HMAC_KEY LITERAL1
MY_RF24_ENABLE_ENCRYPTION LITERAL1
MY_RF24_ENCRYPTKEY LITERAL1
MY_RF24_CE_PIN LITERAL1
MY_RF24_CS_PIN LITERAL1
MY_RF24_PA_LEVEL LITERAL1
MY_RF24_CHANNEL LITERAL1
MY_RF24_DATARATE LITERAL1
MY_RF24_BASE_RADIO_ID LITERAL1
MY_SOFTSPI LITERAL1
MY_SOFT_SPI_SCK_PIN LITERAL1
MY_SOFT_SPI_MISO_PIN LITERAL1
MY_SOFT_SPI_MOSI_PIN LITERAL1
MY_RFM69_FREQUENCY LITERAL1
MY_RFM69_FREQUENCY LITERAL1
MY_IS_RFM69HW LITERAL1
MY_RFM69_NETWORKID LITERAL1
MY_RF69_IRQ_PIN LITERAL1
MY_RF69_SPI_CS LITERAL1
MY_RF69_IRQ_NUM LITERAL1
MY_RFM69_ENCRYPTKEY LITERAL1
MY_GATEWAY_W5100 LITERAL1
MY_GATEWAY_ENC28J60 LITERAL1
MY_GATEWAY_ESP8266 LITERAL1
MY_PORT LITERAL1
MY_IP_ADDRESS LITERAL1
MY_USE_UDP LITERAL1
MY_IP_RENEWAL_INTERVAL LITERAL1
MY_MAC_ADDRESS LITERAL1
MY_CONTROLLER_IP_ADDRESS LITERAL1
@@ -9,7 +9,7 @@
* SEN-39001 (universal applications) * SEN-39001 (universal applications)
* ---> http://www.playingwithfusion.com/productview.php?pdid=22 * ---> http://www.playingwithfusion.com/productview.php?pdid=22
* *
* Copyright © 2014 Playing With Fusion, Inc. * Copyright � 2014 Playing With Fusion, Inc.
* SOFTWARE LICENSE AGREEMENT: This code is released under the MIT License. * SOFTWARE LICENSE AGREEMENT: This code is released under the MIT License.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
@@ -51,7 +51,7 @@
#include "avr/pgmspace.h" #include "avr/pgmspace.h"
#include "util/delay.h" #include "util/delay.h"
#include "stdlib.h" #include "stdlib.h"
#include "SPI.h" #include "drivers/AVR/SPI/SPI.h"
class PWF_AS3935 class PWF_AS3935
{ {