Hi, thanks for your help, that´s the solution!!
siod
Posts
-
[SOLVED] call of overloaded 'sleep(int, int)' is ambiguous -
[SOLVED] Node not uisng it´s ID!?damn it, that did the trick!! Just haven´t noticed...
Thx for your superfast support!!
-
[SOLVED] Node not uisng it´s ID!?I have a problem with one of my nodes. I assigned Node ID 10 to it, but it seems like it´s requesting an ID from the gateway!? This is my gateway output when I power on the Node:
0;255;3;0;9;3513128927 TSF:MSG:READ,255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0: 0;255;3;0;9;3513128933 TSF:MSG:BC 0;255;3;0;9;3513128936 TSF:MSG:FPAR REQ,ID=255 0;255;3;0;9;3513128941 TSF:PNG:SEND,TO=0 0;255;3;0;9;3513128944 TSF:CKU:OK 0;255;3;0;9;3513128947 TSF:MSG:GWL OK 0;255;3;0;9;3513130002 TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;3513130893 TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0: 0;255;3;0;9;3513130900 Sending message on topic: mygateway1-out/255/255/3/0/3 0;255;3;0;9;3513132862 TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0: 0;255;3;0;9;3513132869 Sending message on topic: mygateway1-out/255/255/3/0/3 0;255;3;0;9;3513134829 TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0: 0;255;3;0;9;3513134836 Sending message on topic: mygateway1-out/255/255/3/0/3 0;255;3;0;9;3513136797 TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0: 0;255;3;0;9;3513136804 Sending message on topic: mygateway1-out/255/255/3/0/3 0;255;3;0;9;3513148605 TSF:MSG:READ,255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0: 0;255;3;0;9;3513148612 TSF:MSG:BC 0;255;3;0;9;3513148615 TSF:MSG:FPAR REQ,ID=255 0;255;3;0;9;3513148619 TSF:PNG:SEND,TO=0 0;255;3;0;9;3513148623 TSF:CKU:OKand this is my Node´s sketch:
#define MY_RADIO_NRF24 #include <MySensors.h> #include <SPI.h> // Define Node ID #define MY_NODE_ID 10 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC //Batterysensor int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; #define CHILD_ID_BATT 7 //Kontaktschalter #define CHILD_ID 1 #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch //MySensor gw; // Change to V_LIGHT if you use S_LIGHT in presentation below MyMessage msg(CHILD_ID,V_TRIPPED); MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE); void setup() { int buzzer = 7; //Buzzer Anschlusspin pinMode(buzzer, OUTPUT); pinMode(13,OUTPUT); digitalWrite(13,HIGH); digitalWrite(buzzer, HIGH); wait(50); digitalWrite(buzzer, LOW); wait(50); digitalWrite(buzzer, HIGH); wait(50); digitalWrite(buzzer, LOW); wait(50); digitalWrite(buzzer, HIGH); wait(50); digitalWrite(buzzer, LOW); //gw.begin(NULL, MY_NODE_ID, true); // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); //Batterysensor // use the 1.1 V internal reference #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif // Send the sketch version information to the gateway and Controller } // 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 presentation() { sendSketchInfo("Wohunungstuer Alarm", "1.0"); wait(500); present(CHILD_ID, S_DOOR); wait(500); } // Check if digital input has changed and send in new value void loop() { //Türkontakt prüfen: uint8_t value; static uint8_t sentValue = 2; value = digitalRead(BUTTON_PIN); if (value==HIGH){ //Buzzer wird ausgelöst int buzzer = 7; //Buzzer Anschlusspin pinMode(buzzer, OUTPUT); digitalWrite(buzzer, HIGH); wait(500); digitalWrite(buzzer, LOW); wait(500); digitalWrite(buzzer, HIGH); wait(500); digitalWrite(buzzer, LOW); wait(500); digitalWrite(buzzer, HIGH); wait(500); digitalWrite(buzzer, LOW); wait(2000); digitalWrite(buzzer, HIGH); wait(500); digitalWrite(buzzer, LOW); wait(500); digitalWrite(buzzer, HIGH); wait(500); digitalWrite(buzzer, LOW); wait(500); digitalWrite(buzzer, HIGH); wait(500); digitalWrite(buzzer, LOW); } // Short wait to allow buttons to properly settle wait(5); //Batterysensor // get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef DEBUG Serial.println(sensorValue); #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 float batteryV = sensorValue * 0.003363075; int batteryPcnt = sensorValue / 10; #ifdef DEBUG Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep sendBatteryLevel(batteryPcnt); wait(500); send(msgbatt.set(batteryPcnt),true); wait(500); oldBatteryPcnt = batteryPcnt; } if (value != sentValue) { // Value has changed from last transmission, send the updated value send(msg.set(value == HIGH ? 1 : 0),true); wait(500); sentValue = value; } // Sleep until something happens with the sensor digitalWrite(13,LOW); Serial.println("Sleep"); sleep(BUTTON_PIN - 2, CHANGE);// changing Secondary button to correct pin (-3) does not work. So keep it on (-2) }What is wrong here?
-
[SOLVED] call of overloaded 'sleep(int, int)' is ambiguousHi,
I have an older sketch which I modified and want to upload again now to my Arduino. I am using Lib 2.2.0 now, but I am getting this error at this line:
sleep(BUTTON_PIN - 2, CHANGE);call of overloaded 'sleep(int, int)' is ambiguousThe code worked very well in the past, so whats wrong here now?
edit: I´m using Arduino IDE 1.8.5
edit2: I can compile using lib 2.0.0. So there must have been a change in the meantime. -
Sonoff Pow with Tasmota: HowTo MQTT?Hi,
I´ve successfully flashed Tasmota to my Sonoff Pow and I see it´s connected to my MQTT Broker, but I haven´t understood how to send commands to the Pow over MQTT.
e.g. in the docs they are saying this:
*To execute these, issue (publish) these MQTT requests
MQTT topic MQTT payload
cmnd/my_device/power <empty>
cmnd/my_device/power on
cmnd/my_device/power off*But actually the device is not turning off or on. One imortant thing is I don´t know what is "my_device".
Finally I need to know how I could best combine this device with my Openhab2 and Mysesnsors setup.Any help is appreciated, thanks in advance!
-
Need help with ESP8266 Node in MQTT Network -
Need help with ESP8266 Node in MQTT Networkwell, this looks quiet interesting, but I think I´m quicker if I just use my actual Arduino IDE setup and some lines of code to achieve my goal because I feel more comfortable wit this IDE...
But I will have a look at ESPEasy anyway, thanks for that!!
edit: Do I have to upload the ESP8266 Gateway Code to every ESP8266 Node?
What I actually want to achieve is to build a IR Sender which sends IR commands to my TV or other IR devices that where sent by openhab.
-
Need help with ESP8266 Node in MQTT NetworkHi guys,
I would like to add an ESP8266 WIFI Node to my existing NRF24 MQTT Network. I´ve set up a Mosquitto broker on my LAN connected Raspberry pi with openhab2 running on it acting as the controller.
Unfortunately I have no idea where to start to include the new WIFI node to talk to my controller. Does someone know a tutorial could give me some code examples of where to start?Thanks in advance!
-
What settings for ESP8266 Node?Hi,
I would like to convert the below sketch to a ESP8266 /WeMos D1 Mini compatible sketch. Do I have to change MY RADIO NRF24 to ESP8266 or sth like that? PS I am using MQTT and Openhab 2...
/* * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend * An IR LED must be connected to Arduino PWM pin 3. * Version 0.1 July, 2009 * Copyright 2009 Ken Shirriff * http://arcfn.com */ #define MY_RADIO_NRF24 // Define Node ID #define MY_NODE_ID 5 //#define MY_PARENT_NODE_ID 50 //Repeater Node 1! //#define MY_PARENT_NODE_IS_STATIC #include <MySensors.h> #include <SPI.h> #include <IRremote.h> #define CHILD_ID 1 // Id of the sensor child IRsend irsend; // Initialize message MyMessage msg(CHILD_ID, V_IR_SEND); void setup() { Serial.begin(9600); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("LED Licht TV Steuerung", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_IR); } void loop() { } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. Serial.println(F("Incoming Message:")); Serial.println(message.getString()); if (message.type == V_IR_RECEIVE) { // Send command to Turn LEDs On if (message.getString("anaus")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF02FD, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs Red else if (message.getString("rot")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF1AE5, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs green else if (message.getString("gruen")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF9A65, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs blue else if (message.getString("blau")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFA25D, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs white else if (message.getString("weiss")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF22DD, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs faster else if (message.getString("schneller")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFE817, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs slower else if (message.getString("langsamer")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFC837, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs brighter else if (message.getString("heller")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF3AC5, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs darker else if (message.getString("dunkler")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFBA45, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs Fade7 else if (message.getString("fade7")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFE01F, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs flash else if (message.getString("flash")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFD02F, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } // Send command to Turn LEDs Jump7 else if (message.getString("jump")) { for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFFA05F, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } else{ // if nothing else matches, do the default // default is optional Serial.println("Nicht belegt"); } } } -
How to send MQTT message from controller to Node?This the code I got so far, which does not work :(
#define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen // Define Node ID #define MY_NODE_ID 5 //#define MY_PARENT_NODE_ID 50 //Repeater Node 1! //#define MY_PARENT_NODE_IS_STATIC #include <MySensors.h> #include <SPI.h> #include <IRremote.h> #define CHILD_ID 1 // Id of the sensor child IRsend irsend; // Initialize motion message MyMessage msg(CHILD_ID, V_IR_SEND); void setup() { Serial.begin(9600); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("LED Licht TV Steuerung", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_IR); } void loop() { } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_IR_SEND) { // Send command to Turn LEDs On if (message.getString() == "FF02FD") { // ??? for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF02FD, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } } } }edit: from the serial monitor I see that the node receives the "FF02FD" String, but it does not enter this part
if (message.getString() == "FF02FD") { // ??? for (int i = 0; i < 3; i++) { irsend.sendNEC(0xFF02FD, 32); Serial.println(message.getString()); Serial.println("Message sent"); delay(40); } }edit2:
This is what I am sending from openhab over MQTT:
mygateway1-in/5/1/1/0/32edit3:
Ok, now I see where it fails:
message.getString()contains FF02FD
but when I say
if (message.getString() == "FF02FD")it does not recognise the FF02FD. But I don´t understand why
edit4:
Ok, I got it, finally...:
message.getString("FF02FD");:astonished: :facepunch:
-
How to send MQTT message from controller to Node?So, if I want to send HEX Values to the node, can I send them through openahb over MQTT like this (Node 2 / Sensor 2 / SET / NO ACK / V_IR_RECEIVE):
Switch MQTTTestSwitch "MQTT Test Switch" (gBasement) {mqtt=">[mysensor:mygateway1-in/2/2/1/0/33:command:ON:1E240],>[mysensor:mygateway1-in/2/2/1/0/33:command:OFF:1E249]"} //????and pick it up on the node uisng the receive() function like this:
void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_IR_RECEIVE) { // Send command to Turn LEDs On if (message.getstring()==1E240){ // ??? Irsend.NEC(1E240) //send IR command using IRemote Library over IR LED attached to PIN 4 } }??? ??? ???
Of course I could sned 1 or 0 to turn it On or Off, but when going to send color HEX Codes I thought I should start working whith HEX Codes from the beginning...
-
How to send MQTT message from controller to Node?Hi,
I´ve set up a IR sender to control a RGB LED behind my TV. Now I want to communicate with this node using openhab and MQTT over NRF24. Unfortunately I have no idea how to send commands to a node, until now I was only sending informations from the Nodes/Sensors to the controller.
So, I need to create functions for the Node like
If command "ON/Off" received from openhab
-send IR Command for ON/OFF
If Command "Red" received from openhab
-send IR Command for color red
If Command "Fade" received from openhab
-send IR Command for fading through colorsI need to know how to send this from openhab or Mosquitto for example and especially how to catch these messages and process them in the Arduino code.
I guess this is a beginners task but I have no idea where to start...
Thanks for your help!
-
💬 Motion SensorHi, I´ve read this above
"however this sensor requires 5 VDC so you will need to use a step-up regulator if you are running the 3.3V version of the Arduino Pro Mini."
So I am using 3 V, could you propose a fitting step up regulator so I can use this PIR (best from ebay)? Thank you!
-
Repeater Node not working, pls help debug...Hi,
unfortunately I can´t get my first repeater node to work. Actually it worked a few times, now I only get these messages and it is not communicating correctly with my GW:
This is my repeater node code:
// Repeater Node1, Repeater Nodes starten bei ID 50 //#define MY_DEBUG #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen // Define Node ID #define MY_NODE_ID 50 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC #define MY_REPEATER_FEATURE #include <MySensors.h> #include <SPI.h> #include "Timer.h" //Variables Timer t; //Messages //Presentation; present sensors to gateway! void presentation(){ // Send the sketch version information to the gateway and Controller sendSketchInfo("Repeater Node 1", "1.0"); wait(500); } //Setup void setup() { Serial.begin(9600); sendImAlive(); t.every(60000, sendImAlive); } //Starte den Loop void loop() { Serial.println("Sending Update..."); t.update(); Serial.println("...Done!"); } void sendImAlive() { sendHeartbeat(); }I hope you can help me! Thanks in advance!!!
-
Pls help debug this...@tbowmo I removed the 100 uF cap, now it is working :thumbsup:
-
Pls help debug this...can someone help me debug this output of my repeater node:
402795 !TSF:MSG:SEND,50-50-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=3,st=NACK:1 404802 TSM:UPL 406402 !TSF:MSG:SEND,50-50-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=4,st=NACK:1 408410 TSM:UPL 410009 !TSF:MSG:SEND,50-50-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=5,st=NACK:1 412017 TSM:UPL 413617 !TSF:MSG:SEND,50-50-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=6,st=NACK:1 415625 !TSM:UPL:FAIL 415626 TSM:FPAR 415628 TSM:FPAR:STATP=0 415630 TSM:ID 415632 TSM:ID:OK 415633 TSM:UPLthis is continuosly repeating.
-
💬 Serial Protocol - 2.x@gvorster Thank you for explanation!
One more thing: I wanted to implement a sendHeartbeat() into a Repeater node (which should never sleep!), where should I put this function and how? When putting it just into the loop it is of course spamming my gateway with heartbeat messages...Is it possible anyway?
-
💬 Serial Protocol - 2.xhow can I handle sendheartbeat() messages in my controller? What payload will be sent? 1 or 0, True or False...?
ps I´m using openhab
-
Windows GUI/Controller for MySensorsHi, I am trying your software but I only get "connection refused" though in the status bar it says Connected... what can I do?
-
Slim Node as a Mini 2AA Battery PIR Motion SensorNope, 2.2 is giving me the same fail trip messages.
When using IDE 1.6.5 with 1.5.4 I don´t even get it compiled, Arduino is automatically using 2.2.0 library from 1.8.2 version which is, of course, still installed on my system and I don´t want to uninstall it...edit: Ok, the way @komaandy proposed is working, though I like the other sketch more...
edit2: Well, seems like it has sth. to do with the battery sensing: when removing this part from void loop() it works as it is supposed to (see what I commented out between /* and */):
void loop() { //Batterysensor // get the battery Voltage /*int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef DEBUG #endif int batteryPcnt = sensorValue / 10; gw.sendBatteryLevel(batteryPcnt); gw.wait(500); gw.send(msgbatt.set(batteryPcnt)); gw.wait(500); */ if (interruptReturn) { // Woke up by rising pin gw.send(msg.set("1")); // Just send trip (set) commands to controller. (Let controller reset and decide what to do with it.) irtCounter++; } gw.sleep(3000); // Make sure everything is stable before start to sleep with interrupts. (don't use "gw.wait()" here). Tests shows false trip ~2s after battery report otherwise. // Sleep until interrupt comes in on motion sensor or sleep time passed. interruptReturn = gw.sleep(MOTION_INPUT_PIN-2,CHANGE, ONE_DAY_SLEEP_TIME); // DEBUG_PRINT("interruptReturn: ");DEBUG_PRINTLN(interruptReturn); }edit3: I obviously mixed up things, now it seems like it´s working... I will report back after some time of testing, but this should be my working code:
/** * EgSlimReed2 * Sketch for Slim Node and HC-SR505 based motion sensor. * Inspired by: * - MySensors motion sensor example: http://www.mysensors.org/build/motion * - AWI's CR123A based Slim Node motion sensor: http://forum.mysensors.org/topic/2478/slim-cr123a-2aa-battery-node * * Created by m26872 * Documentation: 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 - Test to if node can operate in some way dealing with the Pir extreme sensitivity to noise on Vcc. * Version 2.0 - First "production node". "Inactivity day counter" introduced. * * DESCRIPTION * This sketch will only send trips as "1" to the controller. It's up to the controller to deal with the info. * The motion node will not notify controller when resets back to low state and is ready for a new trip. In reality * this is ~10s. And EVEN IF motion is detected continuously, there will be no new trip until motion has stopped for ~10s. * The HC-SR505 is very noise sensitive and will trigger spuriously for almost any activity * on Vcc (test thoroughly). To run the HC-505 at low voltages (tested flawlessly down to 1.6V), * the 7133-reg and diode are removed (and possibly increase the sensitivity even further). * Solution is to deal with it by interrupt type, check which source, block by sleep time etc. * * HC-505 output connects to MOTION_INPUT_PIN (here D3) without any supporting component. Input pull-up disabled. * Every 24 hrs without trip, increments a counter and after "BATTERY_REPORT_DAY" counts a battery report will be sent as a heartbeat signal. * Else a battery report will be sent after every "BATTERY_REPORT_BY_IRT_CYCLE" motion trips. * */ #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen // Define Node ID #define MY_NODE_ID 21 #define MY_PARENT_NODE_ID 0 //Repeater Node 1=50 / Gateway=0! #define MY_PARENT_NODE_IS_STATIC //Batterysensor int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; #define CHILD_ID_BATT 7 #include <MySensor.h> #include <SPI.h> #include <Vcc.h> //#define DEBUG #define SKETCH_NAME "Motion PIR Keller_1" #define SKETCH_VERSION "2.0" #define CHILD_ID 1 #define MOTION_INPUT_PIN 3 #define BATTERY_REPORT_DAY 2 // Desired heartbeat(battery report) interval when inactive. #define BATTERY_REPORT_BY_IRT_CYCLE 10 // Make a battery report after this many trips. Maximum report interval will also be equal to this number of days. #define ONE_DAY_SLEEP_TIME 86400000 #define VCC_MIN 1.9 #define VCC_MAX 3.3 #ifdef DEBUG #define DEBUG_SERIAL(x) Serial.begin(x) #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #else #define DEBUG_SERIAL(x) #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #endif int dayCounter = BATTERY_REPORT_DAY; int irtCounter = 0; bool interruptReturn = false; // "false" will make the first loop disregard high output from HV-505 (from start-up) and make a battery report instead. Vcc vcc; MySensor gw; MyMessage msg(CHILD_ID, V_TRIPPED); //Battery MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE); void setup() { //Batterysensor // use the 1.1 V internal reference #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif DEBUG_SERIAL(9600); DEBUG_PRINTLN(("Serial started")); delay(100); // to settle power for radio gw.begin(NULL,MY_NODE_ID); pinMode(MOTION_INPUT_PIN, INPUT); digitalWrite(MOTION_INPUT_PIN, LOW); // Disable internal pull-ups gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); gw.present(CHILD_ID, S_MOTION); DEBUG_PRINTLN("Warming and blocking PIR trip for 20s."); gw.sleep(20000); // Wait until HC-505 warmed-up and output returned low. } void presentation() { // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor Keller_1", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); //Battery gw.present(CHILD_ID_BATT,V_VOLTAGE); } void loop() { //Batterysensor // get the battery Voltage /*int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef DEBUG #endif int batteryPcnt = sensorValue / 10; gw.sendBatteryLevel(batteryPcnt); gw.wait(500); gw.send(msgbatt.set(batteryPcnt)); gw.wait(500); */ if (interruptReturn) { // Woke up by rising pin gw.send(msg.set("1")); // Just send trip (set) commands to controller. (Let controller reset and decide what to do with it.) irtCounter++; if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) { irtCounter=0; sendBatteryReport(); } } else { // Woke up by timer (or it's the first run) dayCounter++; if (dayCounter >= BATTERY_REPORT_DAY) { dayCounter = 0; sendBatteryReport(); } } gw.sleep(3000); // Make sure everything is stable before start to sleep with interrupts. (don't use "gw.wait()" here). Tests shows false trip ~2s after battery report otherwise. // Sleep until interrupt comes in on motion sensor or sleep time passed. interruptReturn = gw.sleep(MOTION_INPUT_PIN-2,CHANGE, ONE_DAY_SLEEP_TIME); // DEBUG_PRINT("interruptReturn: ");DEBUG_PRINTLN(interruptReturn); } void sendBatteryReport() { float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true); int batteryPcnt = static_cast<int>(p); gw.sendBatteryLevel(batteryPcnt); }edit4: ok, with my edited code this sketch is also working fine now with IDE 1.8.2 and lib 2.2.0 beta. So now everythings works fine!
/** * EgSlimReed2 * Sketch for Slim Node and HC-SR505 based motion sensor. * Inspired by: * - MySensors motion sensor example: http://www.mysensors.org/build/motion * - AWI's CR123A based Slim Node motion sensor: http://forum.mysensors.org/topic/2478/slim-cr123a-2aa-battery-node * * Created by m26872 * Documentation: 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 - Test to if node can operate in some way dealing with the Pir extreme sensitivity to noise on Vcc. * Version 2.0 - First "production node". "Inactivity day counter" introduced. * * DESCRIPTION * This sketch will only send trips as "1" to the controller. It's up to the controller to deal with the info. * The motion node will not notify controller when resets back to low state and is ready for a new trip. In reality * this is ~10s. And EVEN IF motion is detected continuously, there will be no new trip until motion has stopped for ~10s. * The HC-SR505 is very noise sensitive and will trigger spuriously for almost any activity * on Vcc (test thoroughly). To run the HC-505 at low voltages (tested flawlessly down to 1.6V), * the 7133-reg and diode are removed (and possibly increase the sensitivity even further). * Solution is to deal with it by interrupt type, check which source, block by sleep time etc. * * HC-505 output connects to MOTION_INPUT_PIN (here D3) without any supporting component. Input pull-up disabled. * Every 24 hrs without trip, increments a counter and after "BATTERY_REPORT_DAY" counts a battery report will be sent as a heartbeat signal. * Else a battery report will be sent after every "BATTERY_REPORT_BY_IRT_CYCLE" motion trips. * */ //Sensor 21, erster PIR Sensor #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen // Define Node ID #define MY_NODE_ID 21 #define MY_PARENT_NODE_ID 50 //Repeater Node 1! #define MY_PARENT_NODE_IS_STATIC //Batterysensor int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; #define CHILD_ID_BATT 7 #include <MySensors.h> #include <SPI.h> #include <Vcc.h> unsigned long SLEEP_TIME = 86400000; // 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 CHILD_ID 1 // Id of the sensor child #define BATTERY_REPORT_DAY 2 // Desired heartbeat(battery report) interval when inactive. #define BATTERY_REPORT_BY_IRT_CYCLE 10 // Make a battery report after this many trips. Maximum report interval will also be equal to this number of days. #define ONE_DAY_SLEEP_TIME 86400000 #define VCC_MIN 1.9 #define VCC_MAX 3.3 int dayCounter = BATTERY_REPORT_DAY; int irtCounter = 0; bool interruptReturn = false; // "false" will make the first loop disregard high output from HV-505 (from start-up) and make a battery report instead. Vcc vcc; //Battery MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE); // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input //Batterysensor // use the 1.1 V internal reference #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Motion Sensor Keller_1", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_MOTION); //Battery present(CHILD_ID_BATT,V_VOLTAGE); } void loop() { //Batterysensor // get the battery Voltage /*int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef DEBUG #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 //float batteryV = sensorValue * 0.003363075; int batteryPcnt = sensorValue / 10; sendBatteryLevel(batteryPcnt); wait(500); send(msgbatt.set(batteryPcnt)); wait(500); */ // Read digital motion value bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); send(msg.set(tripped?"1":"0")); // Send tripped value to gw irtCounter++; if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) { irtCounter=0; sendBatteryReport(); } else { // Woke up by timer (or it's the first run) dayCounter++; if (dayCounter >= BATTERY_REPORT_DAY) { dayCounter = 0; sendBatteryReport(); } } sleep(3000); // Sleep 3s to make sure everything is stable before we start to sleep with interrupts. // Sleep until interrupt comes in on motion sensor. Send update every 24 hours. sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); } void sendBatteryReport() { float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true); int batteryPcnt = static_cast<int>(p); sendBatteryLevel(batteryPcnt); }