Door, Motion and Temperature Sensor
-
Hi guys,
It's been a few months since I last made a sensor, and I'm experiencing some issues trying to create one now. I've made a sketch, from parts from other projects and made myself a 3in1 sensor, but the problem is that I have no parent node, and I can't understand why.
Can anyone take a look over it and correct me ?
Note that this is meant to be a power operated sensor. Thank you :)
//This sketch is for Door & Motion & Temp Sensor #include <MySensor.h> #include <SPI.h> #include <DallasTemperature.h> #include <OneWire.h> #include <Bounce2.h> char sketch_name[] = "Multi Sensor"; char sketch_ver[] = "1.0"; #define CLIENT_ID AUTO // Sets MYSensors client id #define RADIO_CH 76 // Sets MYSensors to use Radio Channel #define TRIGGER 3 // used to connect motion sensor #define BUTTON_PIN 4 // used to connect door/window sensor //Temp Sensor bits #define ONE_WIRE_BUS 14 // Pin where dallas sensor is connected OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DallasSensors(&oneWire); float lastTemperature ; #define CHILD_ID_T1 3 //CHILD ID for temp //Door/Window bits #define CHILD_ID_D1 1 //CHILD ID for door/window //Trigger Sensor Bits #define CHILD_ID_S1 2 //CHILD ID for Reed/Motion sensor boolean lastTripped = 0; MySensor gw; Bounce debouncer = Bounce(); int oldValue=-1; // Change to V_LIGHT if you use S_LIGHT in presentation below MyMessage msg(CHILD_ID_D1,V_TRIPPED); MyMessage triggerMsg(CHILD_ID_S1,V_TRIPPED); MyMessage tempMsg(CHILD_ID_T1,V_TEMP); void setup() { // Startup OneWire Temp Sensors DallasSensors.begin(); // Initialize library and add callback for incoming messages gw.begin(NULL, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo(sketch_name, sketch_ver); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_D1, S_DOOR); gw.present(CHILD_ID_T1, S_TEMP); gw.present(CHILD_ID_S1, S_MOTION); // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // 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. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. } void loop() { // Alway process incoming messages whenever possible gw.process(); // Check for motion change value boolean tripped = digitalRead(TRIGGER) == HIGH; if (lastTripped != tripped ) { gw.send(triggerMsg.set(tripped?"1":"0")); // Send new state and request ack back Serial.println("Tripped"); lastTripped=tripped; } // Check if digital input has changed and send in new value debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue) { // Send in the new value gw.send(msg.set(value==HIGH ? 1 : 0)); oldValue = value; } // Fetch temperatures from Dallas sensors DallasSensors.requestTemperatures(); float tempC = DallasSensors.getTempCByIndex(1); // Only send data if temperature has changed and no error if (lastTemperature != tempC && tempC != -127.00) { // Send in the new temperature gw.send(tempMsg.set(tempC,1)); lastTemperature=tempC; delay(30000); } } -
Hi guys,
It's been a few months since I last made a sensor, and I'm experiencing some issues trying to create one now. I've made a sketch, from parts from other projects and made myself a 3in1 sensor, but the problem is that I have no parent node, and I can't understand why.
Can anyone take a look over it and correct me ?
Note that this is meant to be a power operated sensor. Thank you :)
//This sketch is for Door & Motion & Temp Sensor #include <MySensor.h> #include <SPI.h> #include <DallasTemperature.h> #include <OneWire.h> #include <Bounce2.h> char sketch_name[] = "Multi Sensor"; char sketch_ver[] = "1.0"; #define CLIENT_ID AUTO // Sets MYSensors client id #define RADIO_CH 76 // Sets MYSensors to use Radio Channel #define TRIGGER 3 // used to connect motion sensor #define BUTTON_PIN 4 // used to connect door/window sensor //Temp Sensor bits #define ONE_WIRE_BUS 14 // Pin where dallas sensor is connected OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DallasSensors(&oneWire); float lastTemperature ; #define CHILD_ID_T1 3 //CHILD ID for temp //Door/Window bits #define CHILD_ID_D1 1 //CHILD ID for door/window //Trigger Sensor Bits #define CHILD_ID_S1 2 //CHILD ID for Reed/Motion sensor boolean lastTripped = 0; MySensor gw; Bounce debouncer = Bounce(); int oldValue=-1; // Change to V_LIGHT if you use S_LIGHT in presentation below MyMessage msg(CHILD_ID_D1,V_TRIPPED); MyMessage triggerMsg(CHILD_ID_S1,V_TRIPPED); MyMessage tempMsg(CHILD_ID_T1,V_TEMP); void setup() { // Startup OneWire Temp Sensors DallasSensors.begin(); // Initialize library and add callback for incoming messages gw.begin(NULL, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo(sketch_name, sketch_ver); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_D1, S_DOOR); gw.present(CHILD_ID_T1, S_TEMP); gw.present(CHILD_ID_S1, S_MOTION); // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // 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. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. } void loop() { // Alway process incoming messages whenever possible gw.process(); // Check for motion change value boolean tripped = digitalRead(TRIGGER) == HIGH; if (lastTripped != tripped ) { gw.send(triggerMsg.set(tripped?"1":"0")); // Send new state and request ack back Serial.println("Tripped"); lastTripped=tripped; } // Check if digital input has changed and send in new value debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue) { // Send in the new value gw.send(msg.set(value==HIGH ? 1 : 0)); oldValue = value; } // Fetch temperatures from Dallas sensors DallasSensors.requestTemperatures(); float tempC = DallasSensors.getTempCByIndex(1); // Only send data if temperature has changed and no error if (lastTemperature != tempC && tempC != -127.00) { // Send in the new temperature gw.send(tempMsg.set(tempC,1)); lastTemperature=tempC; delay(30000); } }@CaptainZap
What do you mean by "have no parent node"?Have a look at the serial monitor (connected to the sensor Arduino).
And you are initializing this node as a repeater.. is that what you were planning to do?// Initialize library and add callback for incoming messages gw.begin(NULL, AUTO, true); // change to gw.begin(NULL, <fixed_node>) -
@AWI Yes I want all my nodes to be repeaters, and that's exactly what I want to do :) However I use a Vera as my controller, and there you are supposed to have a parent node for your arduino sensor, followed by child devices for sensors/relays etc. Right now I have 3 child devices for the My Sensors plugin which isn't right.
-
The fetching of Dallas temperature and also the delay(30000) are rather blocking code. Maybe not the cause of your problem, but not very good as a repeater node. Use a timing if-statement instead.
-
The fetching of Dallas temperature and also the delay(30000) are rather blocking code. Maybe not the cause of your problem, but not very good as a repeater node. Use a timing if-statement instead.
@m26872 No idea how do to that, could you please help me ? :)
-
@m26872 No idea how do to that, could you please help me ? :)
@CaptainZap said:
@m26872 No idea how do to that, could you please help me ? :)
Here is an excellent article; How and why to avoid Delay()
-
Regarding the Vera parental node issue. I see it often but don't know what's causing this. A lot of struggle usually help. I'd try things like:
- put a "delay(500);" before gw.begin and before gw.sendsketchinfo to make sure radio is fully powered and ready when initializing. Then redo the Vera inclusion. Try a few times.
- If still no success. Load and run the ClearEepromConfig sketch. Reload your sketch again and continue trying inclusion in vera.
Perhaps you'll get a lot of ghost child nodes to delete. I use static node Ids so inclusion with cleared eeprom doesn't make the controller give me new node ids every time.
-
-
DallasSensors.requestTemperatures();delays code execution up to 750ms. MySensors DS18B20 library is bit outdated, you should update library (https://github.com/milesburton/Arduino-Temperature-Control-Library) and use following code:In setup:
DallasSensors.begin(); DallasSensors.setWaitForConversion(false);In loop:
DallasSensors.requestTemperatures(); // no delay here gw.wait(750); // insert another value for non-12-bit resolution float tempC = DallasSensors.getTempCByIndex(1); -
@robosensor Thank you very much for your insight... do I just download the new library and overwrite the one in the Arduino IDE install folder ?
I've also used your code and I'm getting errors compiling it, any hints ? I guess it could be because of the library ?
Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Mini, ATmega328"
Door_Motion_Temp_rev2.ino: In function 'void getTemps()':
Door_Motion_Temp_rev2:115: error: 'class MySensor' has no member named 'wait'
Multiple libraries were found for "DallasTemperature.h"Used: C:\Users***\Documents\Arduino\libraries\DallasTemperature << this is where I've copied the downloaded library
Not used: C:\Users***\Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master
'class MySensor' has no member named 'wait'
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.'class MySensor' has no member named 'wait'
-
@robosensor Thank you very much for your insight... do I just download the new library and overwrite the one in the Arduino IDE install folder ?
I've also used your code and I'm getting errors compiling it, any hints ? I guess it could be because of the library ?
Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Mini, ATmega328"
Door_Motion_Temp_rev2.ino: In function 'void getTemps()':
Door_Motion_Temp_rev2:115: error: 'class MySensor' has no member named 'wait'
Multiple libraries were found for "DallasTemperature.h"Used: C:\Users***\Documents\Arduino\libraries\DallasTemperature << this is where I've copied the downloaded library
Not used: C:\Users***\Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master
'class MySensor' has no member named 'wait'
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.'class MySensor' has no member named 'wait'
@CaptainZap yes, but update two libraries (OneWire and Dallas).
gw.wait()function was added 1 feb 2015: https://github.com/mysensors/Arduino/commit/d45a48d8b786656968fb4b45b049e16700dd3fd0 so you should use latest stable 1.4.* code. -
@CaptainZap yes, but update two libraries (OneWire and Dallas).
gw.wait()function was added 1 feb 2015: https://github.com/mysensors/Arduino/commit/d45a48d8b786656968fb4b45b049e16700dd3fd0 so you should use latest stable 1.4.* code.@robosensor I don't know where to find the complete library for version 1.4.x
-
@robosensor I don't know where to find the complete library for version 1.4.x
http://www.mysensors.org/download/ click on Download button under "1.4 - Latest Release" section, download zip archive, extract archive and check Arduino-master\libraries\MySensors\Version.h file.
-
http://www.mysensors.org/download/ click on Download button under "1.4 - Latest Release" section, download zip archive, extract archive and check Arduino-master\libraries\MySensors\Version.h file.
@robosensor Thanks, I installed that but it's version 1.5 b1 and after using it it's giving me lots of errors :| I think there have been changes in how the code is used...
LE: I finally found the 1.4.1 branch and downloaded it however it's still giving me the same error about wait:
Door_Motion_Temp_rev2.ino: In function 'void getTemps()':
Door_Motion_Temp_rev2:115: error: 'class MySensor' has no member named 'wait'
'class MySensor' has no member named 'wait'LLE: Just checked the cpp and there is no wait, this is the library I used :
https://github.com/mysensors/Arduino/tree/1.4.1Can you tell me if there will be any issue if I comment that part ?
-
@robosensor Thanks, I installed that but it's version 1.5 b1 and after using it it's giving me lots of errors :| I think there have been changes in how the code is used...
LE: I finally found the 1.4.1 branch and downloaded it however it's still giving me the same error about wait:
Door_Motion_Temp_rev2.ino: In function 'void getTemps()':
Door_Motion_Temp_rev2:115: error: 'class MySensor' has no member named 'wait'
'class MySensor' has no member named 'wait'LLE: Just checked the cpp and there is no wait, this is the library I used :
https://github.com/mysensors/Arduino/tree/1.4.1Can you tell me if there will be any issue if I comment that part ?
-
That was the version I was using when I first encountered the issues... anyways I'll remove arduino IDE with everything and reinstall it. Thanks.
@hek I also LOL-ed :D Gotta love the helping spirit in the community you guys built.
-
That was the version I was using when I first encountered the issues... anyways I'll remove arduino IDE with everything and reinstall it. Thanks.
@hek I also LOL-ed :D Gotta love the helping spirit in the community you guys built.
@CaptainZap also try to backup and clean C:\Users***\Documents\Arduino\ directory :)
-
LOL :)
@hek as I said before, Dallas library is bit outdated. Is it possible to update dallas and onewire libraries? I provided links for newer versions of this libraries in this thread. I can do PR in github myself, but I don't know how to do it :) I need to read github manuals first :)
requestTemperatures() is can be non-blocking in newer version of dallas library, so code can deep sleep (better for batteries) or process messages (better for repeaters and msg-receiving nodes) about 750 ms.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login

