V_UP and V_DOWN are a great suggestion. I use a distance sensor on my garage door for the state. This will let me know when a button push occurred or a remote open was used.
Posts made by mikeones
-
RE: Automated garage door
-
RE: Relay Outlet + Button + OpenHab + Tasker + Android Wear = Freaking Awesome!
I like that you were able to keep all the electronics inside the gang box. I would like to do something similar for my light switches but I not worked out how to power the components via the mains. Stuffing a charger in the box seems like overkill but it is one solution.
Any other options for powering that node? Any safety issues with having a charge stuffed in a gang box and left inside the drywall?
Thanks in advance
-
RE: smoke/lightlevel/humidty/temp/smoketest
Is that a hardwired smoke detector? I am looking for a hardwired solution that utilizes/runs off the power from a hardwired connection. Not sure if I would have access to 3.3 volts to run the Pro Mini and radio.
-
RE: What is wrong with this node?
If you have the hardware, hook up a sniffer and see what is happening with wireshark at the network layer. I had similar issues and found with the help of the sniffer, my node was having resend/timeout issues even being a couple of feet away. Playing with the channel and data rate, I was able to get a better signal and those st fail messages have stopped. This node is normally in the garage so the interference I had on the default channel was causing issues. Use the sniffer to see what is happening at the network layer.
-
RE: Multi Binary Switches
It forces a status update at a predefined interval.
Alarm.timerRepeat(720, updateState); // update relay status every 2 hrs
-
RE: Multi Binary Switches
Here is one example with a few extras.
// Simple binary switch example // Connect button or door/window reed switch between // digitial I/O pin 3 (BUTTON_PIN below) and GND. #include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <Time.h> //http://playground.arduino.cc/Code/Time #include <TimeAlarms.h> //http://playground.arduino.cc/Code/Time MySensor gw; #define RADIO_ID 12 #define noReeds 5 const int BUTTON_PIN[] = {14, 15, 16, 17, 18}; // Arduino Digital I/O pin for button/reed switch, A0 - A4 boolean reedState[] = {HIGH, HIGH, HIGH, HIGH, HIGH}; Bounce debouncer[noReeds]; MyMessage msg[noReeds]; void setup(){ Serial.println("Starting setup" ); gw.begin(NULL, RADIO_ID, true); //stattc RADIO_ID an enable repeater Alarm.delay(250); gw.sendSketchInfo("Alarm Pannel", "1.0"); Alarm.delay(250); gw.requestTime(receiveTime); // initialize Relays with corresponding buttons for (int i = 0; i < noReeds; i++){ msg[i].sensor = i; // initialize messages msg[i].type = V_TRIPPED; debouncer[i] = Bounce(); // initialize debouncer debouncer[i].attach(BUTTON_PIN[i]); debouncer[i].interval(5); // Setup the button pinMode(BUTTON_PIN[i],INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN[i],HIGH); gw.present(i, S_DOOR); // present sensor to gateway Serial.print("setup for switch: "); Serial.print(BUTTON_PIN[i]); Serial.println(" complete" ); Alarm.timerRepeat(720, updateState); // update relay status every 2 hrs Alarm.delay(250); } Serial.println("Setup complete" ); } // Check if digital input has changed and send in new value void loop() { gw.process(); for (int i = 0; i < noReeds; i++){ debouncer[i].update(); // Get the update value int value = debouncer[i].read(); if (value != reedState[i]) { // Send in the new value gw.send(msg[i].set(value==HIGH ? 1 : 0), false); reedState[i] = value; Serial.print("updating state for swicth: "); Serial.print(BUTTON_PIN[i]); Serial.print(" state: "); Serial.println(reedState[i]); } } } void updateState(){ Serial.println("Start state info"); for (int i = 0; i < noReeds; i++) { Serial.print("sending update for switch: "); Serial.println(BUTTON_PIN[i]); gw.present(i, S_DOOR); Alarm.delay(250); //MyMessage msg(relayPin[pin],V_LIGHT); gw.send(msg[i].set(reedState[i]), false); // Send last state from eprom to GW Alarm.delay(250); } } // This is called when a new time value was received void receiveTime(unsigned long time) { setTime(time); }```
-
RE: Motion & Relay Sensor issue
You should check if the value changed and only send updates when true. Something like this.
if (lastTripped != tripped ) {
-
RE: Interfacing nasty stuff with MySensors
That usb housing is pretty sweet. A nice shell for a PIR and Temp sensors.
-
RE: Data collection
You may look at the node js controller. It has database support. https://github.com/mysensors/Arduino/tree/master/NodeJsController Also check out the controller section of the form. http://forum.mysensors.org/category/3/controllers
-
RE: Can't tell if time is set with TimeAwareSensor Sketch
Thanks, changing type from 4 to 1 fixed it.
-
Can't tell if time is set with TimeAwareSensor Sketch
I am running the TimeAwareSensor.ino sketch and I can't tell if the time ever gets set. I added a couple of serial print lines to the receiveTime function and they never get logged to my serial monitor. Also, timeReceived never gets set to true.
// Example sketch showing how to request time from controller. // Created by Henrik Ekblad <henrik.ekblad@mysensors.org> #include <SPI.h> #include <MySensor.h> #include <Time.h> MySensor gw; boolean timeReceived = false; unsigned long lastUpdate=0, lastRequest=0; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Clock", "1.0"); // Request time from controller. gw.requestTime(receiveTime); } // This is called when a new time value was received void receiveTime(unsigned long time) { // Ok, set incoming time Serial.print("Got Time"); Serial.println(time); setTime(time); timeReceived = true; } void loop() { unsigned long now = millis(); gw.process(); // If no time has been received yet, request it every 10 second from controller // When time has been received, request update every hour if ((!timeReceived && now-lastRequest > 20*100) || (timeReceived && now-lastRequest > 60*1000*60)) { // Request time from controller. Serial.println("requesting time"); gw.requestTime(receiveTime); lastRequest = now; } // Print time every second if (timeReceived && now-lastUpdate > 1000) { Serial.print(hour()); printDigits(minute()); printDigits(second()); Serial.print(" "); Serial.print(day()); Serial.print(" "); Serial.print(month()); Serial.print(" "); Serial.print(year()); Serial.println(); lastUpdate = now; } } void printDigits(int digits){ // utility function for digital clock display: prints preceding colon and leading 0 Serial.print(":"); if(digits < 10) Serial.print('0'); Serial.print(digits); }
Here is the serial monitor output.
sensor started, id 5 send: 5-5-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4 send: 5-5-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0 read: 0-0-5 s=255,c=3,t=6,pt=0,l=1:I send: 5-5-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Clock send: 5-5-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0 send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=3,st=ok:1.0 requesting time send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=3,st=ok:1.0 read: 0-0-5 s=255,c=3,t=4,pt=0,l=10:1411246677 requesting time send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=10,st=ok:1411246677 read: 0-0-5 s=255,c=3,t=4,pt=0,l=10:1411246679 requesting time send: 5-5-0-0 s=255,c=3,t=1,pt=0,l=10,st=ok:1411246679 read: 0-0-5 s=255,c=3,t=4,pt=0,l=10:1411246681
It seems like the sensor starts sending the time back to the controller but timeReceived never gets set to true so the current time is not printed to the serial monitor every second. Any suggestions?
-
Relay Actuator Sketch
I got hung up today working on a relay sketch. I believe the example in GIT is for a repeater node and not a relay.
// Initialize library and add callback for incoming messages gw.begin(incomingMessage, AUTO, true);
Is this really for a relaying node or is it for a sensor that controls a relay?
// Initialize library and add callback for incoming messages gw.begin(incomingMessage, AUTO, false);
-
Internal I_REBOOT command
Does the 1.4 I_REBOOT command rely on having the OTA boot loader installed or can this be used to reboot a sensor node running 1.4 without having the OTA boot loader installed? I would like to reset my sensors on occasion without having to power cycle them. I have tried sending this via my GW but the node seems to ignore it.
11;1;3;0;13;1
-
RE: MySensors 1.4 Released
What does st=fail represent? Is that stating the ack failed or sending failed? Would this error show up for all messages if debug is enabled on the sensor node and not the gateway.? Maybe this is a non issue? I am trying to confirm if gw.getConfig and gw.requestTime requests are reaching the GW since they don't seem to be set consistently in my environment.
sensor started, id 3 send: 3-3-0-0 s=255,c=0,t=17,pt=0,l=3,st=fail:1.4 send: 3-3-0-0 s=255,c=3,t=6,pt=1,l=1,st=fail:0 send: 3-3-0-0 s=255,c=3,t=11,pt=0,l=8,st=ok:Humidity send: 3-3-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0 send: 3-3-0-0 s=0,c=0,t=7,pt=0,l=3,st=fail:1.4 send: 3-3-0-0 s=1,c=0,t=6,pt=0,l=3,st=fail:1.4 send: 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,st=fail:25.8 T: 25.80 send: 3-3-0-0 s=0,c=1,t=1,pt=7,l=5,st=fail:50.4 H: 50.40 send: 3-3-0-0 s=1,c=1,t=0,pt=7,l=5,st=fail:25.8 T: 25.80 send: 3-3-0-0 s=0,c=1,t=1,pt=7,l=5,st=fail:50.4 H: 50.40
-
RE: MySensors 1.4 Released
It appears sending "255;255;3;0;4;1\r\n" fixes my issue.
send: 255-255-255-0 s=255,c=3,t=3,pt=0,l=0,st=fail: read: 0-0-255 s=255,c=3,t=4,pt=0,l=1:1 id=1 sensor started, id 1
-
RE: MySensors 1.4 Released
@hek After updating, I have tested this via the serial monitor and it seems ok.
send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail: read: 0-0-255 s=255,c=3,t=4,pt=0,l=1:1 id=1
When I send this string via a (ago) controller, the node sets an id of 0 again. Do you see any issue with this string format?
255;255;3;0;4;1
Serial monitor output. Does "l=0:" indicate there was an issue with the payload?
send: 255-255-255-0 s=255,c=3,t=3,pt=0,l=0,st=fail: read: 0-0-255 s=255,c=3,t=4,pt=0,l=0: id=0
-
RE: MySensors 1.4 Released
@hek I am having an issue assigning a node ID since the last update. I have cleared the eprom in one of my nodes and I am trying to assign a node id of 1 via the serial monitor on the GW. I am sending "255;255;3;0;4;1" in response to the node ID request of "255;255;3;0;3;".
This is the console log from the node with debug enabled.
send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail: read: 0-0-255 s=255,c=3,t=8,pt=1,l=1:0 new parent=0, d=1 req node id send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=ok: read: 0-0-255 s=255,c=3,t=4,pt=0,l=1:1 id=49 sensor started, id 49 send: 49-49-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4 send: 49-49-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
Here is the console log from the GW.
0;0;3;0;14;Gateway startup complete. 255;255;3;0;3; 49;255;0;0;17;1.4 49;255;3;0;6;0
What I don't understand is why the node would get assigned ID "49" when I sent "1" as the new node ID. Should the node get an ID of "1" or "49" for the command below?
255;255;3;0;4;1
-
RE: EasyIoT server - Mysensors Raspberry Pi controller
Interesting. Is this project GPL or closed source/commercial?
-
RE: Over the air updates
@ToSa I use a Mini-B USB cable between my PRi and my gateway.
-
RE: Over the air updates
On my RPi, the serial gateway is detected as dev/ttyUSB0.
-
RE: 'MySensoring' an Intermatic EH40 (Project Completed!)
So you incorporated a delay between sending your temp values to resolve the issue? Were you spamming the GW with messages without the delay?
-
RE: Water Flow Sensor
It may not make a difference but, have you tried moving your gw.messageAvailable() check to the top of the loop? I have a relay installed along with a distance sensor attached to my garage door. I get distance updates every 30 seconds when the door is stationary and when the door is moving, I send an update every half second. Having gw.messageAvailable() at the beginning of my loop() works the best in my environment. This assumes you are not fighting a reception or interference issue though.
-
RE: RELAY_ON 0 or 1?
After more searching, I see the relay I am using is ACTIVE LOW. Which means it acts in reverse of an ACTIVE HIGH relay. I guess I need to reverse the value from digitalread before updating the GW.
digitalRead(RELAY_1+i)==1?0:1
-
RELAY_ON 0 or 1?
I am running the relay sketch and I am having an issue with checking if the relay is HIGH or LOW. I don't have a whole lot of experience with these arduinos but shouldn't RELAY_ON == 1 (LOW) and off == 0 (HIGH)
#define RELAY_ON 0 #define RELAY_OFF 1
When using the example relay state, RELAY_OFF sets the relay to off but when I check the PIN state via digitalRead(RELAY_1) I get the opposite of what I expect.
digitalRead(RELAY_1) returns HIGH when the relay is OFF and LOW when the relay is ON. I have tried changing the state definitions to the reverse of what is in the example but this results in the relay turning ON when it should be OFF. Anyone know what might be causing this?
#define RELAY_ON 1 #define RELAY_OFF 0
-
RE: implementing multiple sensors
The sensor is not running on battery power so I did not spend much time with the interrupt/sleep options.
-
RE: implementing multiple sensors
@waynehead99 Here is a sketch I run with DHT and motion support.
#include <Sleep_n0m1.h> #include <SPI.h> #include <EEPROM.h> #include <RF24.h> #include <Sensor.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define HUMIDITY_SENSOR_DIGITAL_PIN 4 Sensor gw; DHT dht; Sleep sleep; float lastTemp; float lastHum; boolean lastValue = false; boolean metric = false; #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 2 // Id of the sensor child long previousMillis_T = 0; // will store last time temp data sent unsigned long startTime_T; unsigned long sensorInterval = 30000; // change this to desired sensor read interval in milliseconds void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor and DHT", "1.0"); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 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); gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM); gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP); metric = gw.isMetricSystem(); startTime_T = millis(); Serial.println("Setup complete"); } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; if (lastValue != tripped) { gw.sendVariable(CHILD_ID, V_TRIPPED, tripped?"1":"0"); // Send tripped value to gw lastValue=tripped; //Serial.println(tripped); } if (millis() - startTime_T >= sensorInterval) { delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1); Serial.print("T: "); Serial.println(temperature); } //delay(dht.getMinimumSamplingPeriod()); float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity) { lastHum = humidity; gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1); Serial.print("H: "); Serial.println(humidity); } startTime_T = millis(); } // 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 }
-
RE: Get Relay State
@epierre What would that look like? I was thinking of sending back the status on request. Something like this.
void setRelayStatus(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_LIGHT) { int incomingRelayStatus = atoi(message.data); if incomingRelayStatus == 2 { gw.sendVariable(message.header.childId, V_LIGHT, digitalRead(message.header.childId)); } else { // Change relay state digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF); // Write some debug info Serial.print("Incoming change for relay on pin:"); Serial.print(message.header.childId); Serial.print(", New status: "); Serial.println(incomingRelayStatus); } } }
-
Get Relay State
Is there an options to get the state of a relay? The API shows there is a light status option but it looks like it only sets the state.
V_LIGHT 2 Light status. 0=off 1=on
Here is the part of the relay sketch I am looking at.
void setRelayStatus(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_LIGHT) { int incomingRelayStatus = atoi(message.data); // Change relay state digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF); // Write some debug info Serial.print("Incoming change for relay on pin:"); Serial.print(message.header.childId); Serial.print(", New status: "); Serial.println(incomingRelayStatus); } }
Is there something similar to the lock status variable for a relay?
V_LOCK_STATUS 36 Set or get lock status. 1=Locked, 0=Unlocked
-
RE: Open Source Home Automation (Raspberry)
@bjornhallberg Did you add the mysensors config file?
$ cat /etc/opt/agocontrol/conf.d/mysensors.conf [mysensors] device=/dev/ttyUSB0
-
RE: Open Source Home Automation (Raspberry)
I have been using agocontrol on my RPI with pretty good results. The few issues I posted about in the agocontrol form are likely user error on my part. I think ago is written in C and runs well on my PI. I am currently running 4 nodes with about 22 child devices. They have implemented just about all the device types which is a plus. I am running temperature, humidity and distance sensors along with relays and reed switches. Communication and stability have been solid so far.
I recommend agocontrol to anyone wanting to get some sensor nodes up and talking to a control that don't have a vera. They have x86 packages also so you are not limited to only running on a PI.
-
RE: Irrigation Controller (up to 16 valves with Shift Registers)
Looking at the sketch, there seems to be a fair bit of logic and processing that happens in the Arduino. A lot more than a simple on/off command for the zone. Any reason for this logic not to be controlled by the gateway?
-
RE: Binary sensor expanded help
I have this on a nano also but the only open pins I have left are analog. That is why I started at ping 14.
-
RE: Binary sensor expanded help
I have been using this sketch for about a week now and it is working fine for my needs.
// Simple binary switch example // Connect button or door/window reed switch between // digitial I/O pin 3 (ZONE_1 below) and GND. #include <Sensor.h> #include <SPI.h> #include <EEPROM.h> #include <RF24.h> #include <Bounce2.h> #define ZONE_1 14 // Arduino Digital I/O pin for button/reed switch #define NUMBER_OF_ZONES 6 Sensor gw; Bounce debouncer_1 = Bounce(); Bounce debouncer_2 = Bounce(); Bounce debouncer_3 = Bounce(); Bounce debouncer_4 = Bounce(); Bounce debouncer_5 = Bounce(); Bounce debouncer_6 = Bounce(); int oldValue_1 =-1; int oldValue_2 =-1; int oldValue_3 =-1; int oldValue_4 =-1; int oldValue_5 =-1; int oldValue_6 =-1; void setup() { gw.begin(); for (int i=0; i<NUMBER_OF_ZONES;i++) { // Setup the button pinMode(ZONE_1+i,INPUT); // Activate internal pull-up digitalWrite(ZONE_1+i,HIGH); // After setting up the button, setup debouncer switch (1+i) { case 1: debouncer_1.attach(ZONE_1); debouncer_1.interval(5); break; case 2: debouncer_2.attach(ZONE_1+i); debouncer_2.interval(5); break; case 3: debouncer_3.attach(ZONE_1+i); debouncer_3.interval(5); break; case 4: debouncer_4.attach(ZONE_1+i); debouncer_4.interval(5); break; case 5: debouncer_5.attach(ZONE_1+i); debouncer_5.interval(5); break; } // 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 below. gw.sendSensorPresentation(ZONE_1+i, S_DOOR); delay(1000); } } // Check if digital input has changed and send in new value void loop() { for (int i=0; i<NUMBER_OF_ZONES;i++) { int num = 1+i; // Get the update value switch (num) { case 1: { debouncer_1.update(); int value_1 = debouncer_1.read(); if (value_1 != oldValue_1) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_1==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_1 = value_1; } break; } case 2: { debouncer_2.update(); int value_2 = debouncer_2.read(); if (value_2 != oldValue_2) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_2==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_2 = value_2; } break; } case 3: { debouncer_3.update(); int value_3 = debouncer_3.read(); if (value_3 != oldValue_3) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_3==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_3 = value_3; } break; } case 4: { debouncer_4.update(); int value_4 = debouncer_4.read(); if (value_4 != oldValue_4) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_4==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_4 = value_4; } break; } case 5: { debouncer_5.update(); int value_5 = debouncer_5.read(); if (value_5 != oldValue_5) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_5==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_5 = value_5; } break; } case 6: { debouncer_6.update(); int value_6 = debouncer_6.read(); if (value_6 != oldValue_6) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_6==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_6 = value_6; } break; } } } }
-
RE: Multi-Binary Switch Sketch
I did get this code to compile... I am going to test with this over the weekend.
// Simple binary switch example // Connect button or door/window reed switch between // digitial I/O pin 3 (ZONE_1 below) and GND. #include <Sensor.h> #include <SPI.h> #include <EEPROM.h> #include <RF24.h> #include <Bounce2.h> #define ZONE_1 14 // Arduino Digital I/O pin for button/reed switch #define NUMBER_OF_ZONES 6 Sensor gw; Bounce debouncer_1 = Bounce(); Bounce debouncer_2 = Bounce(); Bounce debouncer_3 = Bounce(); Bounce debouncer_4 = Bounce(); Bounce debouncer_5 = Bounce(); Bounce debouncer_6 = Bounce(); int oldValue_1 =-1; int oldValue_2 =-1; int oldValue_3 =-1; int oldValue_4 =-1; int oldValue_5 =-1; int oldValue_6 =-1; void setup() { gw.begin(); for (int i=0; i<NUMBER_OF_ZONES;i++) { // Setup the button pinMode(ZONE_1+i,INPUT); // Activate internal pull-up digitalWrite(ZONE_1+i,HIGH); // After setting up the button, setup debouncer switch (1+i) { case 1: debouncer_1.attach(ZONE_1); debouncer_1.interval(5); break; case 2: debouncer_2.attach(ZONE_1+i); debouncer_2.interval(5); break; case 3: debouncer_3.attach(ZONE_1+i); debouncer_3.interval(5); break; case 4: debouncer_4.attach(ZONE_1+i); debouncer_4.interval(5); break; case 5: debouncer_5.attach(ZONE_1+i); debouncer_5.interval(5); break; } // 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 below. gw.sendSensorPresentation(ZONE_1+i, S_DOOR); delay(1000); } } // Check if digital input has changed and send in new value void loop() { for (int i=0; i<NUMBER_OF_ZONES;i++) { int num = 1+i; // Get the update value switch (num) { case 1: { debouncer_1.update(); int value_1 = debouncer_1.read(); if (value_1 != oldValue_1) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_1==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_1 = value_1; } break; } case 2: { debouncer_2.update(); int value_2 = debouncer_2.read(); if (value_2 != oldValue_2) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_2==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_2 = value_2; } break; } case 3: { debouncer_3.update(); int value_3 = debouncer_3.read(); if (value_3 != oldValue_3) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_3==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_3 = value_3; } break; } case 4: { debouncer_4.update(); int value_4 = debouncer_4.read(); if (value_4 != oldValue_4) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_4==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_4 = value_4; } break; } case 5: { debouncer_5.update(); int value_5 = debouncer_5.read(); if (value_5 != oldValue_5) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_5==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_5 = value_5; } break; } case 6: { debouncer_6.update(); int value_6 = debouncer_6.read(); if (value_6 != oldValue_6) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value_6==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_6 = value_6; } break; } } } }
-
RE: Sensor node stuck in a sending loop?
That seems to be the case. If I shutdown the controller, the sensor node does not see the extra replies from the gateway.
Thanks
-
Multi-Binary Switch Sketch
Anyone have a working example of a multi-switch sketch? I have started to modify the BinarySwitchSensor.ino sketch but I am not sure how to get the debouce settings per switch or if it is needed. I have attached my sketch and error that results when I try an compile this. Any suggestions?
BinarySwitchSensor.ino: In function ‘void setup()’: BinarySwitchSensor:39: error: request for member ‘attach’ in ‘i’, which is of non-class type ‘int’ BinarySwitchSensor:40: error: request for member ‘interval’ in ‘i’, which is of non-class type ‘int’ BinarySwitchSensor.ino: In function ‘void loop()’: BinarySwitchSensor:54: error: request for member ‘update’ in ‘i’, which is of non-class type ‘int’ BinarySwitchSensor:56: error: request for member ‘read’ in ‘i’, which is of non-class type ‘int’ BinarySwitchSensor:61: error: lvalue required as left operand of assignment
This is the code so far.
// Simple binary switch example // Connect button or door/window reed switch between // digitial I/O pin 3 (ZONE_1 below) and GND. #include <Sensor.h> #include <SPI.h> #include <EEPROM.h> #include <RF24.h> #include <Bounce2.h> #define ZONE_1 14 // Arduino Digital I/O pin for button/reed switch #define NUMBER_OF_ZONES 6 Sensor gw; Bounce debouncer_1 = Bounce(); Bounce debouncer_2 = Bounce(); Bounce debouncer_3 = Bounce(); Bounce debouncer_4 = Bounce(); Bounce debouncer_5 = Bounce(); Bounce debouncer_6 = Bounce(); int oldValue_1 =-1; int oldValue_2 =-1; int oldValue_3 =-1; int oldValue_4 =-1; int oldValue_5 =-1; int oldValue_6 =-1; void setup() { gw.begin(); for (int i=0; i<NUMBER_OF_ZONES;i++) { // Setup the button pinMode(ZONE_1+i,INPUT); // Activate internal pull-up digitalWrite(ZONE_1+i,HIGH); // After setting up the button, setup debouncer debouncer_1+i.attach(ZONE_1+i); debouncer_1+i.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 below. gw.sendSensorPresentation(ZONE_1+i, S_DOOR); } } // Check if digital input has changed and send in new value void loop() { for (int i=0; i<NUMBER_OF_ZONES;i++) { debouncer_1+i.update(); // Get the update value int value = debouncer_1+i.read(); if (value != oldValue_1+i) { // Send in the new value gw.sendVariable(ZONE_1+i, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above oldValue_1+i = value; } } }
-
Sensor node stuck in a sending loop?
I am not sure if my sensor node is re-sending a message that the node generated. The messages I see in the console makes me think the node is stuck in a loop resending the same messages. Here is the sketch I am using. This is loaded in a nano and I am using the serial GW sketch to talk to a PI running agocontrol.
#include <Sleep_n0m1.h> #include <SPI.h> #include <EEPROM.h> #include <RF24.h> #include <Sensor.h> #include <DHT.h> #include <Relay.h> // 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 #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 #define RELAY_ON 1 #define RELAY_OFF 0 unsigned long SLEEP_TIME = 10; // Sleep time between reads (in seconds) long previousMillis = 0; // will store last time temp data sent Sensor gw(9, 10); 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); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Register all sensors to gw (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM); gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP); metric = gw.isMetricSystem(); // Register all sensors to gw (they will be created as child devices) for (int i=0; i<NUMBER_OF_RELAYS;i++) { gw.sendSensorPresentation(RELAY_1+i, S_LIGHT); } // Fetch relay status for (int i=0; i<NUMBER_OF_RELAYS;i++) { // Make sure relays are off when starting up digitalWrite(RELAY_1+i, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_1+i, OUTPUT); // Request/wait for relay status gw.getStatus(RELAY_1+i, V_LIGHT); setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw } } void loop() { if (gw.messageAvailable()) { message_s message = gw.getMessage(); setRelayStatus(message); } unsigned long currentMillis = millis(); if(currentMillis - previousMillis > 10000) { // save the last time you blinked the LED previousMillis = currentMillis; delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1); Serial.print("T: "); Serial.println(temperature); } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity) { lastHum = humidity; gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1); Serial.print("H: "); Serial.println(humidity); } // 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 //gw.powerDown(); //sleep.pwrDownMode(); //set sleep mode //sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime } } void setRelayStatus(message_s message) { if (message.header.messageType=M_SET_VARIABLE && message.header.type==V_LIGHT) { int incomingRelayStatus = atoi(message.data); // Change relay state digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF); // Write some debug info Serial.print("Incoming change for relay on pin:"); Serial.print(message.header.childId); Serial.print(", New status: "); Serial.println(incomingRelayStatus); } }
Here is the console logs. Does it look like the sensor node is replying to a message from the GW creating a loop?
Started sensor. Relay=0, distance=1 Radio id stored in EEPROM was: 2 Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=255,mt=0,ty=17,cr=52: 1.2+ Sent successfully Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=255,mt=4,ty=7,cr=14: 0 Sent successfully Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=0,mt=0,ty=7,cr=65: 1.2+ Sent successfully Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=1,mt=0,ty=6,cr=226: 1.2+ Sent successfully Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=255,mt=4,ty=13,cr=206: Sent successfully Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=255,mt=4,t=13,cr=16(ok): I Message addressed for this node. Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=0,ty=3,cr=255: 1.2+ Sent successfully Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=2,ty=2,cr=178: Sent successfully Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=48(ok): 1 Message addressed for this node. Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,ty=2,cr=2: 1 Sent successfully Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=87(ok): 0 Message addressed for this node. Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,ty=2,cr=101: 0 Sent successfully Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=4,mt=3,t=2,cr=230(ok): 1 Message addressed for this node. Incoming change for relay on pin:4, New status: 1 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=4,mt=3,t=2,cr=129(ok): 0 Message addressed for this node. Incoming change for relay on pin:4, New status: 0 Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=1,mt=1,ty=0,cr=131: 75.2 Sent successfully T: 75.20 Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=0,mt=1,ty=1,cr=110: 36.0 Sent successfully H: 36.00 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=103(ok): 75.2 Message addressed for this node. Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ec): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=48(ok): 1 Message addressed for this node. Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,ty=2,cr=2: 1 Sent successfully Incoming change for relay on pin:4, New status: 1 Message available on pipe 1 Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=48(ok): 1 Message addressed for this node. Relaying message back to gateway. Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,