From f0f2542df40c1ac3d4bb6d43b856bc8c6fc61a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Sat, 16 Jul 2016 10:01:28 +0200 Subject: [PATCH] Various fixes for SAMD (#510) * Only serial GW should hold back on USB * Fixing some examples on archs other than avr * HwInit() is needed on samd, to init I2C --- core/MyHwSAMD.cpp | 8 +- .../AirQualitySensor/AirQualitySensor.ino | 118 ++--- .../BinarySwitchSleepSensor.ino | 32 +- .../DimmableLEDActuator.ino | 47 +- examples/DimmableLight/DimmableLight.ino | 39 +- examples/DustSensor/DustSensor.ino | 2 +- examples/LightSensor/LightSensor.ino | 2 +- examples/MockMySensors/MockMySensors.ino | 443 +++++++++--------- .../SecurityPersonalizer.ino | 2 +- examples/VibrationSensor/VibrationSensor.ino | 20 +- 10 files changed, 352 insertions(+), 361 deletions(-) diff --git a/core/MyHwSAMD.cpp b/core/MyHwSAMD.cpp index 115400a..264da9c 100644 --- a/core/MyHwSAMD.cpp +++ b/core/MyHwSAMD.cpp @@ -68,7 +68,7 @@ void hwReadConfigBlock(void* buf, void* adr, size_t length) int offs = reinterpret_cast(adr); while (length-- > 0) { - *dst++ = i2c_eeprom_read_byte(offs++); + *dst++ = i2c_eeprom_read_byte(offs++); } } @@ -100,7 +100,7 @@ void hwWriteConfig(int adr, uint8_t value) void hwInit() { MY_SERIALDEVICE.begin(MY_BAUD_RATE); - #ifndef MY_GATEWAY_W5100 + #if defined(MY_GATEWAY_SERIAL) while (!MY_SERIALDEVICE) {} #endif Wire.begin(); @@ -142,12 +142,12 @@ uint16_t hwCPUVoltage() { // TODO: Not supported! return 0; } - + uint16_t hwCPUFrequency() { // TODO: Not supported! return 0; } - + uint16_t hwFreeMem() { // TODO: Not supported! return 0; diff --git a/examples/AirQualitySensor/AirQualitySensor.ino b/examples/AirQualitySensor/AirQualitySensor.ino index 369cf8d..f2bc01b 100644 --- a/examples/AirQualitySensor/AirQualitySensor.ino +++ b/examples/AirQualitySensor/AirQualitySensor.ino @@ -21,30 +21,30 @@ * DESCRIPTION * * Connect the MQ2 sensor as follows : - * + * * A H A >>> 5V * B >>> A0 * H >>> GND * B >>> 10K ohm >>> GND - * + * * Contribution: epierre * Based on http://sandboxelectronics.com/?p=165 * License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) * Modified by HEK to work in 1.4 - * + * */ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include -#include +#include -#define CHILD_ID_MQ 0 +#define CHILD_ID_MQ 0 /************************Hardware Related Macros************************************/ #define MQ_SENSOR_ANALOG_PIN (0) //define which analog input channel you are going to use #define RL_VALUE (5) //define the load resistance on the board, in kilo ohms @@ -55,7 +55,7 @@ #define CALIBRATION_SAMPLE_INTERVAL (500) //define the time interal(in milisecond) between each samples in the //cablibration phase #define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to take in normal operation -#define READ_SAMPLE_TIMES (5) //define the time interal(in milisecond) between each samples in +#define READ_SAMPLE_TIMES (5) //define the time interal(in milisecond) between each samples in //normal operation /**********************Application Related Macros**********************************/ #define GAS_LPG (0) @@ -68,25 +68,25 @@ float Ro = 10000.0; // this has to be tuned 10K Ohm int val = 0; // variable to store the value coming from the sensor float valMQ =0.0; float lastMQ =0.0; -float LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve. +float LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" - //to the original curve. - //data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -0.59) -float COCurve[3] = {2.3,0.72,-0.34}; //two points are taken from the curve. - //with these two points, a line is formed which is "approximately equivalent" //to the original curve. - //data format:{ x, y, slope}; point1: (lg200, 0.72), point2: (lg10000, 0.15) -float SmokeCurve[3] ={2.3,0.53,-0.44}; //two points are taken from the curve. - //with these two points, a line is formed which is "approximately equivalent" + //data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -0.59) +float COCurve[3] = {2.3,0.72,-0.34}; //two points are taken from the curve. + //with these two points, a line is formed which is "approximately equivalent" //to the original curve. - //data format:{ x, y, slope}; point1: (lg200, 0.53), point2:(lg10000,-0.22) + //data format:{ x, y, slope}; point1: (lg200, 0.72), point2: (lg10000, 0.15) +float SmokeCurve[3] ={2.3,0.53,-0.44}; //two points are taken from the curve. + //with these two points, a line is formed which is "approximately equivalent" + //to the original curve. + //data format:{ x, y, slope}; point1: (lg200, 0.53), point2:(lg10000,-0.22) MyMessage msg(CHILD_ID_MQ, V_LEVEL); -void setup() -{ - Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air +void setup() +{ + Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air } void presentation() { @@ -94,33 +94,33 @@ void presentation() { sendSketchInfo("Air Quality Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) - present(CHILD_ID_MQ, S_AIR_QUALITY); + present(CHILD_ID_MQ, S_AIR_QUALITY); } -void loop() -{ +void loop() +{ uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO); Serial.println(val); - - Serial.print("LPG:"); + + Serial.print("LPG:"); Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_LPG) ); Serial.print( "ppm" ); - Serial.print(" "); - Serial.print("CO:"); + Serial.print(" "); + Serial.print("CO:"); Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO) ); Serial.print( "ppm" ); - Serial.print(" "); - Serial.print("SMOKE:"); + Serial.print(" "); + Serial.print("SMOKE:"); Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_SMOKE) ); Serial.print( "ppm" ); Serial.print("\n"); - + if (valMQ != lastMQ) { - send(msg.set((int)ceil(valMQ))); + send(msg.set((int16_t)ceil(valMQ))); lastMQ = ceil(valMQ); } - - sleep(SLEEP_TIME); //sleep for: sleepTime + + sleep(SLEEP_TIME); //sleep for: sleepTime } /****************** MQResistanceCalculation **************************************** @@ -129,35 +129,35 @@ Output: the calculated sensor resistance Remarks: The sensor and the load resistor forms a voltage divider. Given the voltage across the load resistor and its resistance, the resistance of the sensor could be derived. -************************************************************************************/ +************************************************************************************/ float MQResistanceCalculation(int raw_adc) { return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc)); } - + /***************************** MQCalibration **************************************** Input: mq_pin - analog channel Output: Ro of the sensor -Remarks: This function assumes that the sensor is in clean air. It use - MQResistanceCalculation to calculates the sensor resistance in clean air - and then divides it with RO_CLEAN_AIR_FACTOR. RO_CLEAN_AIR_FACTOR is about +Remarks: This function assumes that the sensor is in clean air. It use + MQResistanceCalculation to calculates the sensor resistance in clean air + and then divides it with RO_CLEAN_AIR_FACTOR. RO_CLEAN_AIR_FACTOR is about 10, which differs slightly between different sensors. -************************************************************************************/ +************************************************************************************/ float MQCalibration(int mq_pin) { int i; float val=0; - + for (i=0;i Vera Arduino Sensor project. + * This sketch provides a Dimmable LED Light using PWM and based Henrik Ekblad + * Vera Arduino Sensor project. * Developed by Bruce Lacey, inspired by Hek's MySensor's example sketches. - * - * The circuit uses a MOSFET for Pulse-Wave-Modulation to dim the attached LED or LED strip. + * + * The circuit uses a MOSFET for Pulse-Wave-Modulation to dim the attached LED or LED strip. * The MOSFET Gate pin is connected to Arduino pin 3 (LED_PIN), the MOSFET Drain pin is connected - * to the LED negative terminal and the MOSFET Source pin is connected to ground. + * to the LED negative terminal and the MOSFET Source pin is connected to ground. * * This sketch is extensible to support more than one MOSFET/PWM dimmer per circuit. * http://www.mysensors.org/build/dimmer */ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include -#include +#include #define SN "DimmableLED" #define SV "1.1" @@ -51,7 +51,7 @@ #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) -static int currentLevel = 0; // Current dim level... +static int16_t currentLevel = 0; // Current dim level... MyMessage dimmerMsg(0, V_DIMMER); MyMessage lightMsg(0, V_LIGHT); @@ -59,8 +59,8 @@ MyMessage lightMsg(0, V_LIGHT); /*** * Dimmable LED initialization method */ -void setup() -{ +void setup() +{ // Pull the gateway's current dim level - restore light level upon sendor node power-up request( 0, V_DIMMER ); } @@ -68,14 +68,14 @@ void setup() void presentation() { // Register the LED Dimmable Light with the gateway present( 0, S_DIMMER ); - + sendSketchInfo(SN, SV); } /*** - * Dimmable LED main processing loop + * Dimmable LED main processing loop */ -void loop() +void loop() { } @@ -83,31 +83,31 @@ void loop() void receive(const MyMessage &message) { if (message.type == V_LIGHT || message.type == V_DIMMER) { - + // Retrieve the power or dim level from the incoming request message int requestedLevel = atoi( message.data ); - + // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on] requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 ); - + // Clip incoming level to valid range of 0 to 100 requestedLevel = requestedLevel > 100 ? 100 : requestedLevel; requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; - + Serial.print( "Changing level to " ); Serial.print( requestedLevel ); - Serial.print( ", from " ); + Serial.print( ", from " ); Serial.println( currentLevel ); fadeToLevel( requestedLevel ); - + // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value... - send(lightMsg.set(currentLevel > 0 ? 1 : 0)); + send(lightMsg.set(currentLevel > 0)); // hek comment: Is this really nessesary? send( dimmerMsg.set(currentLevel) ); - + } } @@ -117,11 +117,10 @@ void receive(const MyMessage &message) { void fadeToLevel( int toLevel ) { int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1; - + while ( currentLevel != toLevel ) { currentLevel += delta; analogWrite( LED_PIN, (int)(currentLevel / 100. * 255) ); delay( FADE_DELAY ); } } - diff --git a/examples/DimmableLight/DimmableLight.ino b/examples/DimmableLight/DimmableLight.ino index c0f6e13..e834daf 100644 --- a/examples/DimmableLight/DimmableLight.ino +++ b/examples/DimmableLight/DimmableLight.ino @@ -20,13 +20,13 @@ * * REVISION HISTORY * Version 1.0 - January 30, 2015 - Developed by GizMoCuz (Domoticz) - * + * * DESCRIPTION - * This sketch provides an example how to implement a Dimmable Light + * This sketch provides an example how to implement a Dimmable Light * It is pure virtual and it logs messages to the serial output * It can be used as a base sketch for actual hardware. * Stores the last light state and level in eeprom. - * + * */ // Enable debug prints @@ -37,7 +37,7 @@ //#define MY_RADIO_RFM69 #include -#include +#include #define CHILD_ID_LIGHT 1 @@ -50,19 +50,19 @@ #define SN "Dimable Light" #define SV "1.0" -int LastLightState=LIGHT_OFF; -int LastDimValue=100; +int16_t LastLightState=LIGHT_OFF; +int16_t LastDimValue=100; MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT); MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER); -void setup() -{ +void setup() +{ //Retreive our last light state from the eprom - int LightState=loadState(EPROM_LIGHT_STATE); + int LightState=loadState(EPROM_LIGHT_STATE); if (LightState<=1) { LastLightState=LightState; - int DimValue=loadState(EPROM_DIMMER_LEVEL); + int DimValue=loadState(EPROM_DIMMER_LEVEL); if ((DimValue>0)&&(DimValue<=100)) { //There should be no Dim value of 0, this would mean LIGHT_OFF LastDimValue=DimValue; @@ -71,8 +71,8 @@ void setup() //Here you actualy switch on/off the light with the last known dim level SetCurrentState2Hardware(); - - Serial.println( "Node ready to receive messages..." ); + + Serial.println( "Node ready to receive messages..." ); } void presentation() { @@ -82,7 +82,7 @@ void presentation() { present(CHILD_ID_LIGHT, S_DIMMER ); } -void loop() +void loop() { } @@ -90,7 +90,7 @@ void receive(const MyMessage &message) { if (message.type == V_LIGHT) { Serial.println( "V_LIGHT command received..." ); - + int lstate= atoi( message.data ); if ((lstate<0)||(lstate>1)) { Serial.println( "V_LIGHT data invalid (should be 0/1)" ); @@ -98,7 +98,7 @@ void receive(const MyMessage &message) } LastLightState=lstate; saveState(EPROM_LIGHT_STATE, LastLightState); - + if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) { //In the case that the Light State = On, but the dimmer value is zero, //then something (probably the controller) did something wrong, @@ -106,13 +106,13 @@ void receive(const MyMessage &message) LastDimValue=100; saveState(EPROM_DIMMER_LEVEL, LastDimValue); } - + //When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value //This means if you previously set the lights dimmer value to 50%, and turn the light ON //it will do so at 50% } else if (message.type == V_DIMMER) { - Serial.println( "V_DIMMER command received..." ); + Serial.println( "V_DIMMER command received..." ); int dimvalue= atoi( message.data ); if ((dimvalue<0)||(dimvalue>100)) { Serial.println( "V_DIMMER data invalid (should be 0..100)" ); @@ -128,7 +128,7 @@ void receive(const MyMessage &message) } } else { - Serial.println( "Invalid command received..." ); + Serial.println( "Invalid command received..." ); return; } @@ -153,10 +153,9 @@ void SetCurrentState2Hardware() void SendCurrentState2Controller() { if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) { - send(dimmerMsg.set(0)); + send(dimmerMsg.set((int16_t)0)); } else { send(dimmerMsg.set(LastDimValue)); } } - diff --git a/examples/DustSensor/DustSensor.ino b/examples/DustSensor/DustSensor.ino index 3f9883e..8b4cedd 100644 --- a/examples/DustSensor/DustSensor.ino +++ b/examples/DustSensor/DustSensor.ino @@ -94,7 +94,7 @@ void loop() { Serial.println(dustDensity); // unit: ug/m3 if (ceil(dustDensity) != lastDUST) { - send(dustMsg.set((int)ceil(dustDensity))); + send(dustMsg.set((int16_t)ceil(dustDensity))); lastDUST = ceil(dustDensity); } diff --git a/examples/LightSensor/LightSensor.ino b/examples/LightSensor/LightSensor.ino index e6f4fa8..193130d 100644 --- a/examples/LightSensor/LightSensor.ino +++ b/examples/LightSensor/LightSensor.ino @@ -55,7 +55,7 @@ void presentation() { void loop() { - int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; + int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(msg.set(lightLevel)); diff --git a/examples/MockMySensors/MockMySensors.ino b/examples/MockMySensors/MockMySensors.ino index 93c8c72..dfed9be 100644 --- a/examples/MockMySensors/MockMySensors.ino +++ b/examples/MockMySensors/MockMySensors.ino @@ -7,7 +7,7 @@ */ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 @@ -16,7 +16,7 @@ #define MY_NODE_ID 254 #include -#include +#include #define RADIO_ERROR_LED_PIN 4 // Error led pin #define RADIO_RX_LED_PIN 6 // Receive led pin @@ -37,7 +37,7 @@ */ ////#define ID_S_ARDUINO_NODE //auto defined in initialization -////#define ID_S_ARDUINO_REPEATER_NODE //auto defined in initialization +////#define ID_S_ARDUINO_REPEATER_NODE //auto defined in initialization // Some of these ID's have not been updated for v1.5. Uncommenting too many of them @@ -57,15 +57,15 @@ //#define ID_S_WIND 10 //#define ID_S_RAIN 11 //#define ID_S_UV 12 -//#define ID_S_WEIGHT 13 +//#define ID_S_WEIGHT 13 //#define ID_S_POWER 14 //#define ID_S_HEATER 15 //#define ID_S_DISTANCE 16 -//#define ID_S_LIGHT_LEVEL 17 +//#define ID_S_LIGHT_LEVEL 17 //#define ID_S_LOCK 18 //#define ID_S_IR 19 -//#define ID_S_WATER 20 -//#define ID_S_AIR_QUALITY 21 +//#define ID_S_WATER 20 +//#define ID_S_AIR_QUALITY 21 //#define ID_S_DUST 22 //#define ID_S_SCENE_CONTROLLER 23 //// Lib 1.5 sensors @@ -170,20 +170,20 @@ long randNumber; #ifdef ID_S_HEATER //////// REVIEW IMPLEMENTATION //////////// - + MyMessage msg_S_HEATER_SET_POINT(ID_S_HEATER,V_HVAC_SETPOINT_HEAT); // HVAC/Heater setpoint (Integer between 0-100). S_HEATER, S_HVAC MyMessage msg_S_HEATER_FLOW_STATE(ID_S_HEATER,V_HVAC_FLOW_STATE); // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" // S_HVAC, S_HEATER - + //MyMessage msg_S_HEATER_STATUS(ID_S_HEATER,V_STATUS); //MyMessage msg_S_HEATER_TEMP(ID_S_HEATER,V_TEMP); - + float heater_setpoint=21.5; String heater_flow_state="Off"; - + // float heater_temp=23.5; // bool heater_status=false; - - + + // V_TEMP // Temperature // V_STATUS // Binary status. 0=off 1=on // V_HVAC_FLOW_STATE // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" @@ -229,22 +229,22 @@ long randNumber; // not sure if scene controller sends int or chars // betting on ints as Touch Display Scen by Hek // compiler warnings char *scenes[] = { - (char *)"Good Morning", - (char *)"Clean Up!", - (char *)"All Lights Off", + (char *)"Good Morning", + (char *)"Clean Up!", + (char *)"All Lights Off", (char *)"Music On/Off" }; - + int sceneVal=0; int sceneValPrevious=0; - + #endif -#ifdef ID_S_RGB_LIGHT +#ifdef ID_S_RGB_LIGHT MyMessage msg_S_RGB_LIGHT_V_RGB(ID_S_RGB_LIGHT,V_RGB); MyMessage msg_S_RGB_LIGHT_V_WATT(ID_S_RGB_LIGHT,V_WATT); String rgbState="000000"; - //RGB light V_RGB, V_WATT + //RGB light V_RGB, V_WATT //RGB value transmitted as ASCII hex string (I.e "ff0000" for red) #endif @@ -268,20 +268,20 @@ long randNumber; MyMessage msg_S_HVAC_V_HVAC_FLOW_STATET(ID_S_HVAC,V_HVAC_FLOW_STATE); MyMessage msg_S_HVAC_V_HVAC_FLOW_MODE(ID_S_HVAC,V_HVAC_FLOW_MODE); MyMessage msg_S_HVAC_V_HVAC_SPEED(ID_S_HVAC,V_HVAC_SPEED); - + float hvac_SetPointHeat = 16.5; float hvac_SetPointCool = 25.5; String hvac_FlowState = "AutoChangeOver"; String hvac_FlowMode = "Auto"; String hvac_Speed = "Normal"; - //Thermostat/HVAC device + //Thermostat/HVAC device //V_HVAC_SETPOINT_HEAT, // HVAC/Heater setpoint //V_HVAC_SETPOINT_COOL, // HVAC cold setpoint //V_HVAC_FLOW_STATE, // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" //V_HVAC_FLOW_MODE, // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn") //V_HVAC_SPEED // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto") - + // NOT IMPLEMENTED YET //V_TEMP // Temperature //V_STATUS // Binary status. 0=off 1=on @@ -300,7 +300,7 @@ long randNumber; #ifdef ID_S_SPRINKLER // S_SPRINKLER 31 Sprinkler device V_STATUS (turn on/off), V_TRIPPED (if fire detecting device) - // V_STATUS 2 Binary status. 0=off 1=on + // V_STATUS 2 Binary status. 0=off 1=on // V_ARMED 15 Armed status of a security sensor. 1=Armed, 0=Bypassed // V_TRIPPED 16 Tripped status of a security sensor. 1=Tripped, 0=Untripped #endif @@ -316,7 +316,7 @@ long randNumber; #ifdef ID_S_MOISTURE MyMessage msg_S_MOISTURE(ID_S_MOISTURE,V_LEVEL); -#endif +#endif #ifdef ID_S_CUSTOM MyMessage msg_S_CUSTOM_1(ID_S_CUSTOM,V_VAR1); @@ -329,11 +329,11 @@ long randNumber; -void setup() -{ +void setup() +{ // Random SEED randomSeed(analogRead(0)); - + wait(LONG_WAIT); Serial.println("GW Started"); } @@ -345,190 +345,190 @@ void presentation() { Serial.print(SKETCH_NAME); Serial.println(SKETCH_VERSION); wait(LONG_WAIT); - + // Get controller configuration Serial.print("Get Config: "); metric = getConfig().isMetric; Serial.println(metric ? "Metric":"Imperial"); wait(LONG_WAIT); - + // Init Armed #ifdef ID_S_ARMED isArmed = true; #endif - + // Register all sensors to gw (they will be created as child devices) Serial.println("Presenting Nodes"); Serial.println("________________"); - + #ifdef ID_S_DOOR Serial.println(" S_DOOR"); present(ID_S_DOOR,S_DOOR,"Outside Door"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_MOTION Serial.println(" S_MOTION"); present(ID_S_MOTION,S_MOTION,"Outside Motion"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_SMOKE Serial.println(" S_SMOKE"); present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_LIGHT Serial.println(" S_LIGHT"); present(ID_S_LIGHT,S_LIGHT,"Hall Light"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_DIMMER Serial.println(" S_DIMMER"); present(ID_S_DIMMER,S_DIMMER,"Living room dimmer"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_COVER Serial.println(" S_COVER"); present(ID_S_COVER,S_COVER,"Window cover"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_TEMP Serial.println(" S_TEMP"); present(ID_S_TEMP,S_TEMP,"House Temperarue"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_HUM Serial.println(" S_HUM"); present(ID_S_HUM,S_HUM,"Current Humidity"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_BARO Serial.println(" S_BARO"); present(ID_S_BARO,S_BARO," Air pressure"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_WIND Serial.println(" S_WIND"); present(ID_S_WIND,S_WIND,"Wind Station"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_RAIN Serial.println(" S_RAIN"); present(ID_S_RAIN,S_RAIN,"Rain Station"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_UV Serial.println(" S_UV"); present(ID_S_UV,S_UV,"Ultra Violet"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_WEIGHT Serial.println(" S_WEIGHT"); present(ID_S_WEIGHT,S_WEIGHT,"Outdoor Scale"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_POWER Serial.println(" S_POWER"); present(ID_S_POWER,S_POWER,"Power Metric"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_HEATER Serial.println(" S_HEATER"); present(ID_S_HEATER,S_HEATER,"Garage Heater"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_DISTANCE Serial.println(" S_DISTANCE"); present(ID_S_DISTANCE,S_DISTANCE,"Distance Measure"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_LIGHT_LEVEL Serial.println(" S_LIGHT_LEVEL"); present(ID_S_LIGHT_LEVEL,S_LIGHT_LEVEL,"Outside Light Level"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_LOCK Serial.println(" S_LOCK"); present(ID_S_LOCK,S_LOCK,"Front Door Lock"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_IR Serial.println(" S_IR"); present(ID_S_IR,S_IR,"Univeral Command"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_WATER Serial.println(" S_WATER"); present(ID_S_WATER,S_WATER,"Water Level"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_AIR_QUALITY Serial.println(" S_AIR_QUALITY"); present(ID_S_AIR_QUALITY,S_AIR_QUALITY,"Air Station"); wait(SHORT_WAIT); #endif - - #ifdef ID_S_DUST + + #ifdef ID_S_DUST Serial.println(" S_DUST"); present(ID_S_DUST,S_DUST,"Dust Level"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_SCENE_CONTROLLER Serial.println(" S_SCENE_CONTROLLER"); present(ID_S_SCENE_CONTROLLER,S_SCENE_CONTROLLER,"Scene Controller"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_RGB_LIGHT Serial.println(" RGB_LIGHT"); present(ID_S_RGB_LIGHT,S_RGB_LIGHT,"Mood Light"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_RGBW_LIGHT Serial.println(" RGBW_LIGHT"); present(ID_S_RGBW_LIGHT,S_RGBW_LIGHT,"Mood Light 2"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_COLOR_SENSOR Serial.println(" COLOR_SENSOR"); present(ID_S_COLOR_SENSOR,S_COLOR_SENSOR,"Hall Painting"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_HVAC Serial.println(" HVAC"); present(ID_S_HVAC,S_HVAC,"HVAC"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_MULTIMETER Serial.println(" MULTIMETER"); present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Staion"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_SPRINKLER #endif #ifdef ID_S_WATER_LEAK @@ -545,7 +545,7 @@ void presentation() { present(ID_S_MOISTURE,S_MOISTURE,"Basement Sensor"); wait(SHORT_WAIT); #endif - + #ifdef ID_S_CUSTOM Serial.println(" S_CUSTOM"); present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff"); @@ -558,139 +558,139 @@ Serial.println("________________"); } -void loop() -{ +void loop() +{ Serial.println(""); Serial.println(""); Serial.println(""); - Serial.println("#########################"); + Serial.println("#########################"); randNumber=random(0,101); - + Serial.print("RandomNumber:"); Serial.println(randNumber); // Send fake battery level Serial.println("Send Battery Level"); sendBatteryLevel(randNumber); wait(LONG_WAIT); - + // Request time Serial.println("Request Time"); requestTime(); wait(LONG_WAIT); - + //Read Sensors - #ifdef ID_S_DOOR - door(); + #ifdef ID_S_DOOR + door(); #endif - + #ifdef ID_S_MOTION motion(); #endif - + #ifdef ID_S_SMOKE smoke(); #endif - + #ifdef ID_S_LIGHT light(); #endif - + #ifdef ID_S_DIMMER dimmer(); #endif - + #ifdef ID_S_COVER cover(); #endif - + #ifdef ID_S_TEMP temp(); #endif - + #ifdef ID_S_HUM hum(); #endif - + #ifdef ID_S_BARO baro(); #endif - + #ifdef ID_S_WIND wind(); #endif - + #ifdef ID_S_RAIN rain(); #endif - + #ifdef ID_S_UV uv(); #endif - + #ifdef ID_S_WEIGHT weight(); #endif - + #ifdef ID_S_POWER power(); #endif - + #ifdef ID_S_HEATER heater(); #endif - + #ifdef ID_S_DISTANCE distance(); #endif - + #ifdef ID_S_LIGHT_LEVEL light_level(); #endif - + #ifdef ID_S_LOCK lock(); #endif - + #ifdef ID_S_IR ir(); #endif - + #ifdef ID_S_WATER water(); #endif - + #ifdef ID_S_AIR_QUALITY air(); #endif - + #ifdef ID_S_DUST dust(); #endif - + #ifdef ID_S_SCENE_CONTROLLER scene(); #endif - + #ifdef ID_S_RGB_LIGHT rgbLight(); #endif - + #ifdef ID_S_RGBW_LIGHT rgbwLight(); #endif - + #ifdef ID_S_COLOR_SENSOR color(); #endif - + #ifdef ID_S_HVAC hvac(); #endif - + #ifdef ID_S_MULTIMETER multimeter(); #endif - + #ifdef ID_S_SPRINKLER #endif #ifdef ID_S_WATER_LEAK @@ -701,15 +701,15 @@ void loop() #endif #ifdef ID_S_MOISTURE #endif - + #ifdef ID_S_MOISTURE moisture(); - #endif - + #endif + #ifdef ID_S_CUSTOM custom(); #endif - + sendBatteryLevel(randNumber); wait(SHORT_WAIT); Serial.println("#########################"); @@ -728,15 +728,15 @@ void receiveTime(unsigned long controllerTime) { #ifdef ID_S_DOOR void door(){ - + Serial.print("Door is: " ); - + if (randNumber <= 50) { Serial.println("Open"); - send(msg_S_DOOR_T.set(1)); + send(msg_S_DOOR_T.set((int16_t)1)); } else { Serial.println("Closed"); - send(msg_S_DOOR_T.set(0)); + send(msg_S_DOOR_T.set((int16_t)0)); } #ifdef ID_S_ARMED Serial.print("System is: " ); @@ -748,9 +748,9 @@ void door(){ #ifdef ID_S_MOTION void motion(){ - + Serial.print("Motion is: " ); - + if (randNumber <= 50) { Serial.println("Active"); send(msg_S_MOTION_T.set(1)); @@ -758,7 +758,7 @@ void motion(){ Serial.println("Quiet"); send(msg_S_MOTION_T.set(0)); } - + #ifdef ID_S_ARMED Serial.print("System is: " ); Serial.println((isArmed ? "Armed":"Disarmed")); @@ -771,7 +771,7 @@ void motion(){ void smoke(){ Serial.print("Smoke is: " ); - + if (randNumber <= 50) { Serial.println("Active"); send(msg_S_SMOKE_T.set(1)); @@ -779,13 +779,13 @@ void smoke(){ Serial.println("Quiet"); send(msg_S_SMOKE_T.set(0)); } - + #ifdef ID_S_ARMED Serial.print("System is: " ); Serial.println((isArmed ? "Armed":"Disarmed")); send(msg_S_SMOKE_A.set(isArmed)); #endif - + } #endif @@ -794,7 +794,7 @@ void light(){ Serial.print("Light is: " ); Serial.println((isLightOn ? "On":"Off")); - + send(msg_S_LIGHT.set(isLightOn)); } @@ -805,7 +805,7 @@ void dimmer(){ Serial.print("Dimmer is set to: " ); Serial.println(dimmerVal); - + send(msg_S_DIMMER.set(dimmerVal)); } @@ -832,73 +832,73 @@ void cover(){ #ifdef ID_S_TEMP void temp(){ - + Serial.print("Temperature is: " ); Serial.println(map(randNumber,1,100,0,45)); - + send(msg_S_TEMP.set(map(randNumber,1,100,0,45))); - + } #endif #ifdef ID_S_HUM void hum(){ - + Serial.print("Humitidty is: " ); Serial.println(randNumber); - + send(msg_S_HUM.set(randNumber)); - + } #endif #ifdef ID_S_BARO void baro(){ - + const char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"}; long pressure = map(randNumber,1,100,870,1086);// hPa? int forecast = map(randNumber,1,100,0,5); - + Serial.print("Atmosferic Pressure is: " ); Serial.println(pressure); send(msg_S_BARO_P.set(pressure)); - + Serial.print("Weather forecast: " ); Serial.println(weather[forecast]); send(msg_S_BARO_F.set(weather[forecast])); - + } #endif #ifdef ID_S_WIND void wind(){ - + Serial.print("Wind Speed is: " ); Serial.println(randNumber); send(msg_S_WIND_S.set(randNumber)); - + Serial.print("Wind Gust is: " ); Serial.println(randNumber+10); send(msg_S_WIND_G.set(randNumber+10)); - + Serial.print("Wind Direction is: " ); Serial.println(map(randNumber,1,100,0,360)); send(msg_S_WIND_D.set(map(randNumber,1,100,0,360))); - + } #endif #ifdef ID_S_RAIN void rain(){ - + Serial.print("Rain ammount is: " ); Serial.println(randNumber); - + send(msg_S_RAIN_A.set(randNumber)); - + Serial.print("Rain rate is: " ); Serial.println(randNumber/60); - + send(msg_S_RAIN_R.set(randNumber/60,1)); } @@ -906,10 +906,10 @@ void rain(){ #ifdef ID_S_UV void uv(){ - + Serial.print("Ultra Violet level is: " ); Serial.println(map(randNumber,1,100,0,15)); - + send(msg_S_UV.set(map(randNumber,1,100,0,15))); } @@ -917,10 +917,10 @@ void uv(){ #ifdef ID_S_WEIGHT void weight(){ - + Serial.print("Weight is: " ); Serial.println(map(randNumber,1,100,0,150)); - + send(msg_S_WEIGHT.set(map(randNumber,1,100,0,150))); } @@ -928,13 +928,13 @@ void weight(){ #ifdef ID_S_POWER void power(){ - + Serial.print("Watt is: " ); - Serial.println(map(randNumber,1,100,0,150)); + Serial.println(map(randNumber,1,100,0,150)); send(msg_S_POWER_W.set(map(randNumber,1,100,0,150))); Serial.print("KWH is: " ); - Serial.println(map(randNumber,1,100,0,150)); + Serial.println(map(randNumber,1,100,0,150)); send(msg_S_POWER_K.set(map(randNumber,1,100,0,150))); } @@ -946,7 +946,7 @@ void heater(){ // float heater_temp=23.5; // bool heater_status=false; // String heatState="Off"; - + Serial.print("Heater flow state is: " ); Serial.println(heater_flow_state); send(msg_S_HEATER_FLOW_STATE.set(heater_flow_state.c_str())); @@ -954,7 +954,7 @@ void heater(){ // Serial.print("Heater on/off is: " ); // Serial.println((heater_status==true)?"On":"Off"); // send(msg_S_HEATER_STATUS.set(heater_status)); - + // Serial.print("Heater Temperature is: " ); // Serial.println(heater_temp,1); // send(msg_S_HEATER_TEMP.set(heater_temp,1)); @@ -967,10 +967,10 @@ void heater(){ #ifdef ID_S_DISTANCE void distance(){ - + Serial.print("Distance is: " ); Serial.println(map(randNumber,1,100,0,150)); - + send(msg_S_DISTANCE.set(map(randNumber,1,100,0,150))); } @@ -978,10 +978,10 @@ void distance(){ #ifdef ID_S_LIGHT_LEVEL void light_level(){ - + Serial.print("Light is: " ); Serial.println(map(randNumber,1,100,0,150)); - + send(msg_S_LIGHT_LEVEL.set(map(randNumber,1,100,0,150))); } @@ -993,33 +993,33 @@ void lock(){ Serial.print("Lock is: " ); Serial.println((isLocked ? "Locked":"Unlocked")); send(msg_S_LOCK.set(isLocked)); - + } #endif #ifdef ID_S_IR void ir(){ - + Serial.print("Infrared is: " ); Serial.println(irVal); - + send(msg_S_IR_S.set(irVal)); send(msg_S_IR_R.set(irVal)); - + } #endif #ifdef ID_S_WATER void water(){ - + Serial.print("Water flow is: " ); Serial.println(map(randNumber,1,100,0,150)); - + send(msg_S_WATER_F.set(map(randNumber,1,100,0,150))); - + Serial.print("Water volume is: " ); Serial.println(map(randNumber,1,100,0,150)); - + send(msg_S_WATER_V.set(map(randNumber,1,100,0,150))); } @@ -1027,10 +1027,10 @@ void water(){ #ifdef ID_S_AIR_QUALITY void air(){ - + Serial.print("Air Quality is: " ); Serial.println(randNumber); - + send(msg_S_AIR_QUALITY.set(randNumber)); } @@ -1038,10 +1038,10 @@ void air(){ #ifdef ID_S_DUST void dust(){ - + Serial.print("Dust level is: " ); Serial.println(randNumber); - + send(msg_S_DUST.set(randNumber)); } @@ -1052,90 +1052,90 @@ void scene(){ Serial.print("Scene is: " ); Serial.println(scenes[sceneVal]); - + if(sceneValPrevious != sceneVal){ send(msg_S_SCENE_CONTROLLER_OF.set(sceneValPrevious)); send(msg_S_SCENE_CONTROLLER_ON.set(sceneVal)); sceneValPrevious=sceneVal; } - + } #endif #ifdef ID_S_RGB_LIGHT void rgbLight(){ - + Serial.print("RGB Light state is: " ); Serial.println(rgbState); send(msg_S_RGB_LIGHT_V_RGB.set(rgbState.c_str())); - + Serial.print("RGB Light Watt is: " ); - Serial.println(map(randNumber,1,100,0,150)); + Serial.println(map(randNumber,1,100,0,150)); send(msg_S_RGB_LIGHT_V_WATT.set(map(randNumber,1,100,0,150))); - + } #endif #ifdef ID_S_RGBW_LIGHT void rgbwLight(){ - + Serial.print("RGBW Light state is: " ); Serial.println(rgbwState); send(msg_S_RGBW_LIGHT_V_RGBW.set(rgbwState.c_str())); - + Serial.print("RGBW Light Watt is: " ); - Serial.println(map(randNumber,1,100,0,150)); + Serial.println(map(randNumber,1,100,0,150)); send(msg_S_RGBW_LIGHT_V_WATT.set(map(randNumber,1,100,0,150))); - + } #endif #ifdef ID_S_COLOR_SENSOR void color(){ String colorState; - + String red = String(random(0,256),HEX); String green = String(random(0,256),HEX); String blue = String(random(0,256),HEX); - + colorState=String(red + green + blue); Serial.print("Color state is: " ); Serial.println(colorState); send(msg_S_COLOR_SENSOR_V_RGB.set(colorState.c_str())); - + } #endif #ifdef ID_S_HVAC void hvac(){ - + // float hvac_SetPointHeat = 16.5; // float hvac_SetPointCool = 25.5; // String hvac_FlowState = "AutoChangeOver"; // String hvac_FlowMode = "Auto"; // String hvac_Speed = "Normal"; - + Serial.print("HVAC Set Point Heat is: " ); Serial.println(hvac_SetPointHeat); send(msg_S_HVAC_V_HVAC_SETPOINT_HEAT.set(hvac_SetPointHeat,1)); - + Serial.print("HVAC Set Point Cool is: " ); Serial.println(hvac_SetPointCool); send(msg_S_HVAC_V_HVAC_SETPOINT_COOL.set(hvac_SetPointCool,1)); - + Serial.print("HVAC Flow State is: " ); Serial.println(hvac_FlowState); send(msg_S_HVAC_V_HVAC_FLOW_STATET.set(hvac_FlowState.c_str())); - + Serial.print("HVAC Flow Mode is: " ); Serial.println(hvac_FlowMode); send(msg_S_HVAC_V_HVAC_FLOW_MODE.set(hvac_FlowMode.c_str())); - + Serial.print("HVAC Speed is: " ); Serial.println(hvac_Speed); send(msg_S_HVAC_V_HVAC_SPEED.set(hvac_Speed.c_str())); - + } #endif @@ -1144,7 +1144,7 @@ void multimeter(){ int impedance=map(randNumber,1,100,0,15000); int volt=map(randNumber,1,100,0,380); int amps=map(randNumber,1,100,0,16); - + Serial.print("Impedance is: " ); Serial.println(impedance); send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance)); @@ -1155,7 +1155,7 @@ void multimeter(){ Serial.print("Current is: " ); Serial.println(amps); - send(msg_S_MULTIMETER_V_CURRENT.set(amps)); + send(msg_S_MULTIMETER_V_CURRENT.set(amps)); } #endif @@ -1173,20 +1173,20 @@ void multimeter(){ #ifdef ID_S_MOISTURE void moisture(){ - + Serial.print("Moisture level is: " ); Serial.println(randNumber); - + send(msg_S_MOISTURE.set(randNumber)); } #endif #ifdef ID_S_CUSTOM void custom(){ - + Serial.print("Custom value is: " ); Serial.println(randNumber); - + send(msg_S_CUSTOM_1.set(randNumber)); send(msg_S_CUSTOM_2.set(randNumber)); send(msg_S_CUSTOM_3.set(randNumber)); @@ -1217,8 +1217,8 @@ void receive(const MyMessage &message) { #endif break; #endif - - + + case V_STATUS: // V_LIGHT: #ifdef ID_S_LIGHT if(message.sensor==ID_S_LIGHT){ @@ -1241,8 +1241,8 @@ void receive(const MyMessage &message) { // } // #endif break; - - + + #ifdef ID_S_DIMMER case V_DIMMER: if ((message.getInt()<0)||(message.getInt()>100)) { @@ -1257,8 +1257,8 @@ void receive(const MyMessage &message) { dimmer();// temp ack break; #endif - - #ifdef ID_S_COVER + + #ifdef ID_S_COVER case V_UP: coverState=1; Serial.print("Incoming change for ID_S_COVER:"); @@ -1267,7 +1267,7 @@ void receive(const MyMessage &message) { Serial.println("V_UP"); cover(); // temp ack break; - + case V_DOWN: coverState=-1; Serial.print("Incoming change for ID_S_COVER:"); @@ -1276,7 +1276,7 @@ void receive(const MyMessage &message) { Serial.println("V_DOWN"); cover(); //temp ack break; - + case V_STOP: coverState=0; Serial.print("Incoming change for ID_S_COVER:"); @@ -1286,14 +1286,14 @@ void receive(const MyMessage &message) { cover(); //temp ack break; #endif - - + + case V_HVAC_SETPOINT_HEAT: - + #ifdef ID_S_HEATER if(message.sensor == ID_S_HEATER){ heater_setpoint=message.getFloat(); - + Serial.print("Incoming set point for ID_S_HEATER:"); Serial.print(message.sensor); Serial.print(", New status: "); @@ -1301,7 +1301,7 @@ void receive(const MyMessage &message) { heater();//temp ack } #endif - + #ifdef ID_S_HVAC if(message.sensor == ID_S_HVAC){ hvac_SetPointHeat=message.getFloat(); @@ -1325,11 +1325,11 @@ void receive(const MyMessage &message) { heater();//temp ack } #endif - + #ifdef ID_S_HVAC if(message.sensor == ID_S_HVAC){ hvac_FlowState=message.getString(); - + Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); @@ -1338,7 +1338,7 @@ void receive(const MyMessage &message) { } #endif break; - + #ifdef ID_S_LOCK case V_LOCK_STATUS: isLocked = message.getBool(); @@ -1349,7 +1349,7 @@ void receive(const MyMessage &message) { lock(); //temp ack break; #endif - + #ifdef ID_S_IR case V_IR_SEND: irVal = message.getLong(); @@ -1368,7 +1368,7 @@ void receive(const MyMessage &message) { ir(); // temp ack break; #endif - + #ifdef ID_S_SCENE_CONTROLLER case V_SCENE_ON: sceneVal = message.getInt(); @@ -1389,7 +1389,7 @@ void receive(const MyMessage &message) { scene();// temp ack break; #endif - + #ifdef ID_S_RGB_LIGHT case V_RGB: rgbState=message.getString(); @@ -1398,10 +1398,10 @@ void receive(const MyMessage &message) { Serial.print(", New status: "); Serial.println(rgbState); rgbLight(); // temp ack - + break; #endif - + #ifdef ID_S_RGBW_LIGHT case V_RGBW: rgbwState=message.getString(); @@ -1412,37 +1412,37 @@ void receive(const MyMessage &message) { rgbwLight(); break; #endif - + #ifdef ID_S_HVAC - // hvac_SetPointHeat - // hvac_SetPointCool - // hvac_FlowState - // hvac_FlowMode - // hvac_Speed - + // hvac_SetPointHeat + // hvac_SetPointCool + // hvac_FlowState + // hvac_FlowMode + // hvac_Speed + case V_HVAC_SETPOINT_COOL: hvac_SetPointCool=message.getFloat(); - + Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_SetPointCool,1); hvac();//temp ack break; - + case V_HVAC_FLOW_MODE: hvac_Speed=message.getString(); - + Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_Speed); hvac();//temp ack break; - + case V_HVAC_SPEED: hvac_FlowMode=message.getString(); - + Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); @@ -1450,17 +1450,10 @@ void receive(const MyMessage &message) { hvac();//temp ack break; #endif - - default: + + default: Serial.print("Unknown/UnImplemented message type: "); Serial.println(message.type); } } - - - - - - - diff --git a/examples/SecurityPersonalizer/SecurityPersonalizer.ino b/examples/SecurityPersonalizer/SecurityPersonalizer.ino index 502a32a..7c7954b 100644 --- a/examples/SecurityPersonalizer/SecurityPersonalizer.ino +++ b/examples/SecurityPersonalizer/SecurityPersonalizer.ino @@ -879,7 +879,7 @@ void setup() (void)key; Serial.begin(115200); - + hwInit(); Serial.println(F("Personalization sketch for MySensors usage.")); Serial.println(F("-------------------------------------------")); diff --git a/examples/VibrationSensor/VibrationSensor.ino b/examples/VibrationSensor/VibrationSensor.ino index 8dfc1e2..f060982 100644 --- a/examples/VibrationSensor/VibrationSensor.ino +++ b/examples/VibrationSensor/VibrationSensor.ino @@ -33,7 +33,7 @@ **/ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 @@ -57,7 +57,7 @@ unsigned char state = 0; MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL); -void setup() +void setup() { pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT); attachInterrupt(digitalPinToInterrupt(VIBRATION_SENSOR_DIGITAL_PIN), blink, FALLING); // Trigger the blink function when the falling edge is detected @@ -72,19 +72,19 @@ void presentation() { present(CHILD_ID_VIBRATION, S_VIBRATION); } -void loop() -{ - +void loop() +{ + if(state>=40){ // basically below 40 so ignire basic level - send(vibrationMsg.set(int(state))); - state = 0; + send(vibrationMsg.set(int16_t(state))); + state = 0; digitalWrite(SensorLED,HIGH); } else { - state = 0; + state = 0; digitalWrite(SensorLED,LOW); - } + } + - // Power down the radio. Note that the radio will get powered back up // on the next write() call. delay(1000); //delay to allow serial to fully print before sleep