Node do not wake up
-
Hi guys.
First of all, happy new year to all the team from France. all the best for this year guys.
And congratulation for the new web page. We will find good hardware platform here for sure.Quick question, I have multiple battery powered node with the same sensor (temp, hum, motion, light) and exactly the same sketch.
Everything seems to work well except that sometimes, for some reason, one of the node (always the same one) seems to not wake up when the Sleep function should be finish (I would say it append twice a week).
The only things that makes it wake up it's when the motion sensor trigger the interrupt. (but need to be hard-reset to prevent this things append again)It's very sporadic, and can't find the reason.
I already switch radio module, but same things.Any clue ?
I copy the sketch below but nothing exotic in there.
Thanks in advance./** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: 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. * */ //################# // INCLUDE //################# #include <SPI.h> #include <MySensor.h> #include <DHT.h> //################# // OPTION //################# unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) //#define DEBUG //################# // CHILD ID //################# #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOTION 2 #define CHILD_ID_LIGHT 3 #define CHILD_ID_BATTLVL 4 //################# // PIN DEF //################# #define LIGHT_SENSOR_ANALOG_PIN A3 #define MOTION_SENSOR_DIGITAL_PIN 2 #define INTERRUPT MOTION_SENSOR_DIGITAL_PIN #define HUMIDITY_SENSOR_DIGITAL_PIN 4 //################# // VAR //################# MySensor gw; DHT dht; float lastTemp; float lastHum; float lastbattvoltage; boolean metric = true; int lastLightLevel; char lasttripped; int lastBatteryPcnt; int updateAll = 60; int updateCount = 0; uint8_t backup; //################# // Messsage Settings //################# MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msg(CHILD_ID_MOTION, V_TRIPPED); MyMessage msglight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); MyMessage msgvoltage(CHILD_ID_BATTLVL, V_VOLTAGE); void setup() { backup = ADCSRA ; gw.begin(NULL, AUTO, false); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); pinMode(MOTION_SENSOR_DIGITAL_PIN, INPUT); attachInterrupt(digitalPinToInterrupt(MOTION_SENSOR_DIGITAL_PIN), loop, CHANGE); //################# // Info //################# gw.sendSketchInfo("Sensor Pack", "1.5"); //################# // Send Presentation //################# gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); gw.present(CHILD_ID_MOTION, S_MOTION); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); gw.present(CHILD_ID_BATTLVL, S_POWER); } void loop() { updateCount += 1; if (updateCount == updateAll) { lastTemp = -1; lastHum = -1; lastLightLevel = -1; lastBatteryPcnt = -1; lasttripped = -1; lastbattvoltage = -1; updateCount = 0; } ADCSRA = backup ; // Motion Sensor boolean tripped = digitalRead(MOTION_SENSOR_DIGITAL_PIN) == HIGH; #if defined(DEBUG) Serial.print("Motion : "); Serial.println(tripped); #endif if (tripped != lasttripped) { gw.send(msg.set(tripped ? "1" : "0")); // Send tripped value to gw lasttripped = tripped; } // DHT sensor for Humidity and temperature delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); if (isnan(temperature)) { #if defined(DEBUG) Serial.println("Failed reading temperature from DHT"); Serial.println(dht.getTemperature()); #endif } else if (temperature != lastTemp) { lastTemp = temperature; gw.send(msgTemp.set(temperature, 1)); #if defined(DEBUG) Serial.print("Temperature : "); Serial.println(temperature); #endif } float humidity = dht.getHumidity(); if (isnan(humidity)) { #if defined(DEBUG) Serial.println("Failed reading humidity from DHT"); Serial.println(dht.getHumidity()); #endif } else if (humidity != lastHum) { lastHum = humidity; gw.send(msgHum.set(humidity, 1)); #if defined(DEBUG) Serial.print("Humidity: "); Serial.println(humidity); #endif } // Light Sensor int anaread = analogRead(LIGHT_SENSOR_ANALOG_PIN); int lightLevel = (1023 - anaread) / 10.23; #if defined(DEBUG) Serial.print("Light : "); Serial.println(lightLevel); Serial.print("Analog Value : "); Serial.println(anaread); #endif if (lightLevel != lastLightLevel) { gw.send(msglight.set(lightLevel)); lastLightLevel = lightLevel; } // Batt float sensorValue = readVcc() - 2600; sensorValue = sensorValue / 6.0; //(Tension 3.2V à 2.6V min. Soit 0.6V d'amplitude. 0.6 / 100 = 6mV par %) long batteryPcnt = sensorValue; #if defined(DEBUG) Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif if (lastBatteryPcnt != batteryPcnt) { gw.sendBatteryLevel(batteryPcnt); lastBatteryPcnt = batteryPcnt; } float Battvoltage = readVcc() / 1000.0; #if defined(DEBUG) Serial.print("Battery volt: "); Serial.print(Battvoltage); Serial.println(" Volt"); #endif if(Battvoltage!=lastbattvoltage) { gw.send(msgvoltage.set(Battvoltage,2)); lastbattvoltage = Battvoltage; } gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); }
-
I don't think you can use the loop as interrupt service routine. An interrupt service routine is supposed to be very short/quick, not use any timers and not go to sleep. The loop fails all three of those.
Create a new function, see https://www.arduino.cc/en/Reference/AttachInterrupt for an example.
-
Hi!
If you just want to wake from sleep, ie not run a special ISR, just remove the attachInterrupt call. The sleep function will exit and continue the loop by interrupt if you define the interrupt argument correctly.
Right now that's not done. You use the same number for the interrupt as your motion pin number. Either use the pin-to-interrupt function or subtract 2 from the pin number to get correct interrupt number.
-
Hi Thanks for your reply.
I need to use the interrupt for the motion sensor.
Actually this part is working quite well. the only issue it's sometimes, it doesn't exit from the Sleep mode even when the 60 seconds time expired.I just see that I normally don't need this line :
attachInterrupt(digitalPinToInterrupt(MOTION_SENSOR_DIGITAL_PIN), loop, CHANGE);
I will try without it.
-
Hello,
In MySensors example there is no
attachInterrupt
so sure it's not useful.
Your problem occurred also when battery are full ?May I asked you some question on your design ? On this post or by private message (could be in French ;)) ?
David.