From 546ed1d4aed36378cabd189b579336384dd32f6f Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Tue, 4 Mar 2014 00:24:26 +0100 Subject: [PATCH] Added new (optional) arguments to begin where you can set PA level and radio channel in sketches and gateway. Default values for constructor and begin arguments also made it possible to simplify all sketches when using defualt ce/cs pins (9,10) for radio and AUTO radion Id mode. --- EthernetGateway/EthernetGateway.ino | 12 ++++----- SerialGateway/SerialGateway.ino | 13 ++++++---- libraries/MySensors/Gateway.cpp | 26 +++++++++---------- libraries/MySensors/Gateway.h | 14 +++++----- libraries/MySensors/Relay.cpp | 4 +-- libraries/MySensors/Relay.h | 8 +++--- libraries/MySensors/Sensor.cpp | 12 +++++---- libraries/MySensors/Sensor.h | 14 +++++----- .../DallasTemperatureSensor.ino | 18 +++---------- .../DistanceSensor/DistanceSensor.ino | 13 +++------- .../EnergyMeterPulseSensor.ino | 15 +++-------- .../HumiditySensor/HumiditySensor.ino | 10 ++----- .../MySensors/examples/IrSensor/IrSensor.ino | 13 ++-------- .../LightLuxSensor/LightLuxSensor.ino | 17 ++++-------- .../examples/LightSensor/LightSensor.ino | 11 +++----- .../examples/MotionSensor/MotionSensor.ino | 11 ++------ .../PressureSensor/PressureSensor.ino | 11 ++------ .../examples/RelayActuator/RelayActuator.ino | 11 ++------ .../RelayWithButtonActuator.ino | 11 ++------ .../examples/RelayingNode/RelayingNode.ino | 16 +++++------- .../examples/ServoActuator/ServoActuator.ino | 12 +++------ .../SoilMoistSensor/SoilMoistSensor.ino | 13 +++------- .../TimeAndVariableSensor.ino | 9 ++----- .../WaterMeterPulseSensor.ino | 19 +++----------- 24 files changed, 100 insertions(+), 213 deletions(-) diff --git a/EthernetGateway/EthernetGateway.ino b/EthernetGateway/EthernetGateway.ino index bd3d8f8..e87e9c3 100644 --- a/EthernetGateway/EthernetGateway.ino +++ b/EthernetGateway/EthernetGateway.ino @@ -80,30 +80,28 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // DEAD BEEF FEED // a R/W server on the port EthernetServer server = EthernetServer(IP_PORT); +// No blink or button functionality. Use the vanilla constructor. +Gateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_TIME); // Uncomment this constructor if you have leds and include button attached to your gateway -//Gateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN); +//Gateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN); -// Constructor for NON blinking gateway -Gateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_TIME); char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface int inputPos = 0; void setup() { - - gw.begin(GATEWAY_ADDRESS, writeEthernet); + // Initialize gateway at maximum PA level, channel 70 and callback for write operations + gw.begin(RF24_PA_MAX, 70, writeEthernet); Ethernet.begin(mac, myIp); - // give the Ethernet interface a second to initialize delay(1000); // start listening for clients server.begin(); - // C++ classes and interrupts really sucks. Need to attach interrupt // outside thw Gateway class due to language shortcomings! Gah! diff --git a/SerialGateway/SerialGateway.ino b/SerialGateway/SerialGateway.ino index 62ff541..e158eaa 100644 --- a/SerialGateway/SerialGateway.ino +++ b/SerialGateway/SerialGateway.ino @@ -33,11 +33,13 @@ #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled #define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button -// Start gateway with include button and led blinking functionality enabled (see documetation) -//Gateway gw(9, 10, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, 6, 5, 4); -// If blink and include mode button not is used uncomment and use below constructor instead -Gateway gw(9, 10, INCLUSION_MODE_TIME); +// No blink or button functionality. Use the vanilla constructor. +Gateway gw; + +// To start gateway with include button and led blinking functionality enabled use this instead! +//Gateway gw(9, 10, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN, 6, 5, 4); + char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface int inputPos = 0; @@ -46,7 +48,7 @@ boolean commandComplete = false; // whether the string is complete void setup() { gw.begin(); - gw.setPALevel(RF24_PA_LOW); //Adjust PA-level: MIN, LOW, HIGH, MAX (MAX can sometimes cause problems when using amplified NRF24L01) + gw.setPALevel(RF24_PA_LOW); //Adjust PA-level: MIN, LOW, HIGH, MAX (MAX can sometimes cause problems when using amplified NRF24L01) // C++ classes and interrupts really sucks. Need to attach interrupt // outside thw Gateway class due to language shortcomings! Gah! @@ -67,6 +69,7 @@ void loop() } + void startInclusionInterrupt() { gw.startInclusionInterrupt(); } diff --git a/libraries/MySensors/Gateway.cpp b/libraries/MySensors/Gateway.cpp index 7c970a8..5eadc98 100644 --- a/libraries/MySensors/Gateway.cpp +++ b/libraries/MySensors/Gateway.cpp @@ -17,17 +17,18 @@ Gateway::Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time) : Rela inclusionTime = _inclusion_time; } -Gateway::Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion, uint8_t _inclusion_time, uint8_t _rx, uint8_t _tx, uint8_t _er) : Relay(_cepin, _cspin) { +Gateway::Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time, uint8_t _inclusion_pin, uint8_t _rx, uint8_t _tx, uint8_t _er) : Relay(_cepin, _cspin) { ledMode = true; isRelay = true; - pinInclusion = _inclusion; + pinInclusion = _inclusion_pin; inclusionTime = _inclusion_time; pinRx = _rx; pinTx = _tx; pinEr = _er; } -void Gateway::begin(uint8_t _radioId, void (*inDataCallback)(char *)) { +void Gateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, void (*inDataCallback)(char *)) { + Serial.begin(BAUD_RATE); if (inDataCallback != NULL) { useWriteCallback = true; @@ -64,11 +65,8 @@ void Gateway::begin(uint8_t _radioId, void (*inDataCallback)(char *)) { } - // Set baudrate of serial link - Serial.begin(BAUD_RATE); - // Start up the radio library - setupRadio(); + setupRadio(paLevel, channel); RF24::openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID); RF24::startListening(); @@ -103,7 +101,7 @@ void Gateway::checkButtonTriggeredInclusion() { } void Gateway::checkInclusionFinished() { - if (inclusionMode && millis()-inclusionStartTime>60000L*inclusionTime) { + if (inclusionMode && millis()-inclusionStartTime>60000UL*inclusionTime) { // inclusionTimeInMinutes minute(s) has passed.. stop inclusion mode setInclusionMode(false); } @@ -111,13 +109,13 @@ void Gateway::checkInclusionFinished() { void Gateway::parseAndSend(char *commandBuffer) { - boolean ok; - char *str, *p, *value; + boolean ok = false; + char *str, *p, *value=NULL; int i = 0; - uint16_t sensorRadioId; - uint8_t childId; - uint8_t messageType; - uint8_t type; + uint16_t sensorRadioId = 0; + uint8_t childId = 0; + uint8_t messageType = 0; + uint8_t type = 0; // Extract command data coming on serial line for (str = strtok_r(commandBuffer, ";", &p); // split using semicolon diff --git a/libraries/MySensors/Gateway.h b/libraries/MySensors/Gateway.h index 3ff9951..fc6bc98 100644 --- a/libraries/MySensors/Gateway.h +++ b/libraries/MySensors/Gateway.h @@ -27,20 +27,20 @@ class Gateway : public Relay * If you don't use status leds and/or inclusion mode button on your arduino gateway * you can disable this functionality by calling the 2 argument constructor. * - * @param _cepin The pin attached to RF24 Chip Enable on the RF module - * @param _cspin The pin attached to RF24 Chip Select - * @param _inclusion Digital pin that triggers inclusion mode - * @param _inclusion_time Time of inclusion mode (in minutes) + * @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9) + * @param _cspin The pin attached to RF24 Chip Select (defualt 10) + * @param _inclusion_time Time of inclusion mode (in minutes, default 1) + * @param _inclusion_pin Digital pin that triggers inclusion mode * @param _rx Digital pin for receive led * @param _tx Digital pin for transfer led * @param _er Digital pin for error led * */ - Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time); - Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion, uint8_t _inclusion_time, uint8_t _rx, uint8_t _tx, uint8_t _er); + Gateway(uint8_t _cepin=9, uint8_t _cspin=10, uint8_t _inclusion_time = 1); + Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time, uint8_t _inclusion_pin, uint8_t _rx, uint8_t _tx, uint8_t _er); /* Use this and pass a function that should be called when you want to process commands that arrive from radio network */ - void begin(uint8_t _radioId=AUTO, void (*dataCallback)(char *)=NULL); + void begin(rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=70, void (*dataCallback)(char *)=NULL); void processRadioMessage(); void parseAndSend(char *inputString); diff --git a/libraries/MySensors/Relay.cpp b/libraries/MySensors/Relay.cpp index 1a90860..3ada0cb 100644 --- a/libraries/MySensors/Relay.cpp +++ b/libraries/MySensors/Relay.cpp @@ -16,8 +16,8 @@ Relay::Relay(uint8_t _cepin, uint8_t _cspin) : Sensor(_cepin, _cspin) { } -void Relay::begin(uint8_t _radioId) { - Sensor::begin(_radioId); +void Relay::begin(uint8_t radioId, rf24_pa_dbm_e paLevel, uint8_t channel) { + Sensor::begin(radioId, paLevel, channel); // Read routing table from EEPROM for (unsigned int i=0;i #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected - +#define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds) OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); - -Sensor gw(9, 10); +Sensor gw; Sleep sleep; - -#define MAX_ATTACHED_DS18B20 16 - float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean metric = true; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters sensors.begin(); - gw.begin(RADIO_ID); + gw.begin(); // Fetch the number of attached sensors numSensors = sensors.getDeviceCount(); @@ -41,9 +32,6 @@ void setup() metric = gw.isMetricSystem(); } - - - void loop() { gw.powerUp(); diff --git a/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino b/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino index dcabe03..3693509 100644 --- a/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino +++ b/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino @@ -5,28 +5,21 @@ #include #include - -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID 8 - #define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 5 // Arduino pin tied to echo pin on the ultrasonic sensor. #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 = 5; // Sleep time between reads (in seconds) -Sensor gw(9, 10); +Sensor gw; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. Sleep sleep; int lastDist; -boolean metric; +boolean metric = true; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); // Register all sensors to gw (they will be created as child devices) gw.sendSensorPresentation(0, S_DISTANCE); diff --git a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino index a823f0e..6492b92 100644 --- a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino +++ b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino @@ -13,21 +13,15 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR 1000 // Nummber of blinks per KWH of your meeter #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false. #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 CHILD_ID 1 // Id of the sensor child unsigned long SEND_FREQUENCY = 20; // Minimum time between send (in seconds). We don't wnat to spam the gateway. - -#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) -#define CHILD_ID 5 // Id of the sensor child - -Sensor gw(9,10); - +Sensor gw; Sleep sleep; //double kwhPerBlink = 1.0/((double)PULSE_FACTOR); @@ -43,8 +37,7 @@ unsigned long lastSend; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); // Register this device as power sensor gw.sendSensorPresentation(CHILD_ID, S_POWER); diff --git a/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino b/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino index 5300455..0021073 100644 --- a/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino +++ b/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino @@ -5,27 +5,21 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define HUMIDITY_SENSOR_DIGITAL_PIN 3 - unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds) -Sensor gw(9, 10); +Sensor gw; DHT dht; Sleep sleep; - float lastTemp; float lastHum; boolean metric = true; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Register all sensors to gw (they will be created as child devices) diff --git a/libraries/MySensors/examples/IrSensor/IrSensor.ino b/libraries/MySensors/examples/IrSensor/IrSensor.ino index e2217e6..277cf31 100644 --- a/libraries/MySensors/examples/IrSensor/IrSensor.ino +++ b/libraries/MySensors/examples/IrSensor/IrSensor.ino @@ -11,10 +11,6 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - int RECV_PIN = 8; #define CHILD_1 3 // childId @@ -23,17 +19,12 @@ IRsend irsend; IRrecv irrecv(RECV_PIN); decode_results results; - -Sensor gw(9,10); - - +Sensor gw; void setup() { - Serial.begin(BAUD_RATE); // Used to write debug info - irrecv.enableIRIn(); // Start the ir receiver - gw.begin(RADIO_ID); + gw.begin(); // Register a sensors to gw. Use binary light for test purposes. gw.sendSensorPresentation(CHILD_1, S_LIGHT); diff --git a/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino b/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino index 63ca6ea..579d13e 100644 --- a/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino +++ b/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino @@ -25,25 +25,18 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 0 - -BH1750 lightSensor; - unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds) -Sensor gw(9,10); - -int lastlux; +BH1750 lightSensor; +Sensor gw; Sleep sleep; +int lastlux; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); // Register all sensors to gateway (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID_LIGHT, S_LIGHT_LEVEL); @@ -53,7 +46,7 @@ void setup() void loop() { - gw.powerUp(); // Power up radio + gw.powerUp(); // Power up radio (after sleep) uint16_t lux = lightSensor.readLightLevel();// Get Lux value Serial.println(lux); diff --git a/libraries/MySensors/examples/LightSensor/LightSensor.ino b/libraries/MySensors/examples/LightSensor/LightSensor.ino index 62a24cf..43f14d6 100644 --- a/libraries/MySensors/examples/LightSensor/LightSensor.ino +++ b/libraries/MySensors/examples/LightSensor/LightSensor.ino @@ -4,23 +4,18 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 0 unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds) -Sensor gw(9,10); - +Sensor gw; int lastLightLevel; Sleep sleep; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); // Register all sensors to gateway (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID_LIGHT, S_LIGHT_LEVEL); @@ -28,7 +23,7 @@ void setup() void loop() { - gw.powerUp(); // Power up radio + gw.powerUp(); // Power up radio (after sleep) int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); diff --git a/libraries/MySensors/examples/MotionSensor/MotionSensor.ino b/libraries/MySensors/examples/MotionSensor/MotionSensor.ino index 24e7513..dfb48c5 100644 --- a/libraries/MySensors/examples/MotionSensor/MotionSensor.ino +++ b/libraries/MySensors/examples/MotionSensor/MotionSensor.ino @@ -4,23 +4,16 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #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 CHILD_ID 0 // Id of the sensor child -Sensor gw(9,10); - +Sensor gw; Sleep sleep; - void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // Register all sensors to gw (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID, S_MOTION); diff --git a/libraries/MySensors/examples/PressureSensor/PressureSensor.ino b/libraries/MySensors/examples/PressureSensor/PressureSensor.ino index f1fd7ff..6d49d20 100644 --- a/libraries/MySensors/examples/PressureSensor/PressureSensor.ino +++ b/libraries/MySensors/examples/PressureSensor/PressureSensor.ino @@ -6,16 +6,11 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #define LIGHT_SENSOR_ANALOG_PIN 0 - unsigned long SLEEP_TIME = 60; // Sleep time between reads (in seconds) Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor -Sensor gw(9, 10); +Sensor gw; float lastPressure = -1; float lastTemp = -1; @@ -31,8 +26,7 @@ float dP_dt; boolean metric; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) { } @@ -42,7 +36,6 @@ void setup() { gw.sendSensorPresentation(0, S_BARO); gw.sendSensorPresentation(1, S_TEMP); metric = gw.isMetricSystem(); - } diff --git a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino index d08d215..94cf357 100644 --- a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino +++ b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino @@ -5,23 +5,16 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 - #define RELAY_ON 0 #define RELAY_OFF 1 -Relay gw(9,10); +Relay gw; void setup() { - Serial.begin(BAUD_RATE); // Used to write debug info - - gw.begin(RADIO_ID); + gw.begin(); // Register all sensors to gw (they will be created as child devices) for (int i=0; i #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO #define RELAY_PIN 4 // Arduino Digital I/O pin number for relay #define BUTTON_PIN 3 // Arduino Digital I/O pin number for button (with 10k pulldown) - #define CHILD_ID 1 // Id of the sensor child - #define RELAY_ON 0 #define RELAY_OFF 1 @@ -25,13 +20,11 @@ int switched = 0; long pressTime = 0; // the last time the button pin was pressed long debounce = 200; // the debounce time, increase if the output flickers -Relay gw(9,10); +Relay gw; void setup() { - Serial.begin(BAUD_RATE); // Used to write debug info - - gw.begin(RADIO_ID); + gw.begin(); // Set buttonPin as Input pinMode(BUTTON_PIN, INPUT); diff --git a/libraries/MySensors/examples/RelayingNode/RelayingNode.ino b/libraries/MySensors/examples/RelayingNode/RelayingNode.ino index 44ff448..9c2e8ac 100644 --- a/libraries/MySensors/examples/RelayingNode/RelayingNode.ino +++ b/libraries/MySensors/examples/RelayingNode/RelayingNode.ino @@ -9,23 +9,19 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - -Relay gw(9,10); +Relay gw; void setup() { - Serial.begin(BAUD_RATE); // Used to write debug info - gw.begin(RADIO_ID); - + gw.begin(); } void loop() { - if (gw.messageAvailable()) { - // Incoming message for this node... + // By calling this regularely you route messages in the background + if (gw.messageAvailable()) { + + // Handleincoming message for this node here... } } diff --git a/libraries/MySensors/examples/ServoActuator/ServoActuator.ino b/libraries/MySensors/examples/ServoActuator/ServoActuator.ino index 2247863..fcd6168 100644 --- a/libraries/MySensors/examples/ServoActuator/ServoActuator.ino +++ b/libraries/MySensors/examples/ServoActuator/ServoActuator.ino @@ -16,24 +16,18 @@ #define SERVO_MIN 0 // Fine tune your servos min. 0-180 #define SERVO_MAX 180 // Fine tune your servos max. 0-180 #define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo - -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID 6 #define CHILD_ID 10 // Id of the sensor child -Sensor gw(9, 10); +Sensor gw; Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created Sensor gw(9,10); unsigned long timeOfLastChange = 0; bool attachedServo = false; - - + void setup() { - Serial.begin(BAUD_RATE); - gw.begin(RADIO_ID); + gw.begin(); // Register all sensors to gw (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID, S_COVER); diff --git a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino index 4f4ab49..ca5d31f 100644 --- a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino +++ b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino @@ -4,29 +4,22 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #define DIGITAL_INPUT_SOIL_SENSOR 3 // Digital input did you attach your soil sensor. #define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID 0 // Id of the sensor child -Sensor gw(9, 10); +Sensor gw; Sleep sleep; +int lastSoilValue = -1; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT); // sets the soil sensor digital pin as input // Register all sensors to gw (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID, S_MOTION); - } - -int lastSoilValue = -1; void loop() { diff --git a/libraries/MySensors/examples/TimeAndVariableSensor/TimeAndVariableSensor.ino b/libraries/MySensors/examples/TimeAndVariableSensor/TimeAndVariableSensor.ino index 17b4a16..71d4c36 100644 --- a/libraries/MySensors/examples/TimeAndVariableSensor/TimeAndVariableSensor.ino +++ b/libraries/MySensors/examples/TimeAndVariableSensor/TimeAndVariableSensor.ino @@ -8,19 +8,14 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #define CHILD_ID 0 // Id of the sensor child -Sensor gw(9, 10); +Sensor gw; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); // Register any sensortype. This example we just create a motion sensor. gw.sendSensorPresentation(CHILD_ID, S_MOTION); diff --git a/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino b/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino index 7193ce8..fb88d36 100644 --- a/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino +++ b/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino @@ -9,9 +9,6 @@ // to calculate/report flow. // // Sensor on pin 3 -// -// -// #include @@ -21,24 +18,15 @@ #include #include -// Set RADIO_ID to something unique in your sensor network (1-254) -// or set to AUTO if you want gw to assign a RADIO_ID for you. -#define RADIO_ID AUTO - #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR 1000 // Nummber of blinks per m3 of your meter (One rotation/liter) #define SLEEP_MODE false // flowvalue can only be reported when sleep mode is false. #define MAX_FLOW 40 // Max flow (l/min) value to report. This filetrs outliers. -unsigned long SEND_FREQUENCY = 20; // Minimum time between send (in seconds). We don't want to spam the gateway. #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID 5 // Id of the sensor child +unsigned long SEND_FREQUENCY = 20; // Minimum time between send (in seconds). We don't want to spam the gateway. - - - -Sensor gw(9,10); - -//enable sleep +Sensor gw; Sleep sleep; double ppl = ((double)PULSE_FACTOR)/1000; // Pulses per liter @@ -58,8 +46,7 @@ boolean metric; void setup() { - Serial.begin(BAUD_RATE); // Used to type in characters - gw.begin(RADIO_ID); + gw.begin(); // Register this device as Waterflow sensor gw.sendSensorPresentation(CHILD_ID, S_WATER);