ahhhhhhhhhhhh - I created a door/window sensor some weeks ago - but I couldn't make it run to fire an interrupt on pin change (INT0 and INT1 are used to connect external magnetic sensors) - today I decided to work on this issue again and found this topic at the forum - so I downgraded my arduino IDE by downloading v1.6.8 from arduino.cc today - compiled my code again - falshed it - and voilà - it works
That is really frustrating by wasting that many hours of time only by inconsistancy with compiler/board definitions.
Is there any need to update to newer arduino-IDE - otherwise I would recommend to general stick to one version ...
JoergP
@JoergP
Best posts made by JoergP
-
RE: Interrupt and sleep
Latest posts made by JoergP
-
RE: Interrupt and sleep
hmmmm .... I'm not so familiar with the arduino build process - I guess that Interrupt Request registers are not reset correctly, but never did that manual with Arduino
I use following board setting
AAnode1.name=AA sensor node (1MHz int) AAnode1.upload.tool=avrdude AAnode1.upload.protocol=arduino AAnode1.upload.maximum_size=32256 AAnode1.upload.speed=9600 AAnode1.bootloader.tool=avrdude AAnode1.bootloader.low_fuses=0x62 AAnode1.bootloader.high_fuses=0xde AAnode1.bootloader.extended_fuses=0x07 AAnode1.bootloader.path=optiboot_v50 AAnode1.bootloader.unlock_bits=0x3F AAnode1.bootloader.lock_bits=0x2F AAnode1.build.mcu=atmega328p AAnode1.build.f_cpu=1000000L AAnode1.build.core=arduino AAnode1.build.variant=standard AAnode1.build.board=AVR_AANODE_1MHz
I guess the xxx.build.xxx settings are of interest - do you use the same or do you have different?
-
RE: Interrupt and sleep
@Efflon I'm not sure what exactly you mean - do you refer to my code? In that case this is a quick and dirty try - I'll send at every pin change and at timeout the input values ...
-
RE: Interrupt and sleep
That's bad - if you like you can send me your source and I can try to compile it on my environment.
I use the watchdog in general - in the past I had the issue that some nodes stopped working without any reason - watchdog helped to solve this -
RE: Interrupt and sleep
I checked the used versions - as I already wrote the used arduino-IDE is 1.6.8. But due to the case that I used 1.8.0 before and downgraded the board definition by "Board manager" the board definition is 1.6.11 (if you down/upgrade by BoardManager you can find the files in dir "C:\Users...\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11"
I added my own definitions to board.txt (because I use 2AA Battery node -> https://www.openhardware.io/view/10/My-Slim-2AA-Battery-Node)here my quick and dirty source - have to clean up if it works as expected:
// --------------------------------------------------------- // based on 2AA Battery Node // ATMEGA328P (@ internal OSC 1MHz) // device ID = 0x07D5 (2005d ) // --------------------------------------------------------- // 0 - Input 0 -> S_DOOR / V_TRIPPED // 1 - Input 1 -> S_DOOR / V_TRIPPED // 2 - temperature (HTU) // 3 - humidity (HTU) // --------------------------------------------------------- // --------------------------------------------------------- // includes // --------------------------------------------------------- #include <Wire.h> #include "Adafruit_HTU21DF.h" #include <Vcc.h> #include <avr/wdt.h> // --------------------------------------------------------- // MySensors // --------------------------------------------------------- #define MY_RADIO_NRF24 #define MY_RF24_PA_LEVEL RF24_PA_MAX #include <MySensors.h> #include <SPI.h> // --------------------------------------------------------- // MySensor // --------------------------------------------------------- #define SN "AA - Windows / Temperature" #define SV "1.1" #define ms_input_0 0 #define ms_input_1 1 #define ms_temperature 2 #define ms_humidity 3 // --------------------------------------------------------- // used PINs // --------------------------------------------------------- #define PIN_INPUT_0 2 #define PIN_INPUT_1 3 // --------------------------------------------------------- // Sleep // --------------------------------------------------------- #define SLEEP_TIME 300000 // ms => 5 min #define VALUE_MIN_COUNT 12 // send min every 12th measurement one value (once per hour) // --------------------------------------------------------- // Vcc // --------------------------------------------------------- #define VCC_MIN 1.9 #define VCC_MAX 3.3 #define BATTERY_COUNT 288 // 288 * 5 min = 1 day // --------------------------------------------------------- // global vars // --------------------------------------------------------- MyMessage msg(0,0); Adafruit_HTU21DF htu = Adafruit_HTU21DF(); boolean htu_available = false; float htu_temperature = 1000; float htu_humidity = 1000; int batteryCnt = 0; int temperatureCnt = 0; int humidityCnt = 0;; Vcc vcc; // ######################################################### // setup // ######################################################### void setup() { // --------- // PINs // --------- pinMode(PIN_INPUT_0, INPUT_PULLUP); pinMode(PIN_INPUT_1, INPUT_PULLUP); // --------- // HTU21 // --------- if (htu.begin()) htu_available = true; } // ######################################################### // presentation // ######################################################### void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SN, SV); // Send sensor information present(ms_input_0, S_DOOR); present(ms_input_1, S_DOOR); if(htu_available) { present(ms_temperature, S_TEMP); present(ms_humidity, S_HUM); } } // ######################################################### // loop // ######################################################### void loop() { // enable watchdog wdt_enable(WDTO_8S); // ------------- // inputs // ------------- sendInput0(); sendInput1(); // ------------- // check battery // ------------- if(batteryCnt == 0) sendBatteryReport(); batteryCnt++; if(batteryCnt > BATTERY_COUNT) batteryCnt = 0; // ------------- // temperature // ------------- if(htu_available) { sendTemperature(); sendHumidity(); } // ------------- // sleep // ------------- delay(500); wdt_disable(); sleep(digitalPinToInterrupt(PIN_INPUT_0), CHANGE, digitalPinToInterrupt(PIN_INPUT_1), CHANGE, SLEEP_TIME); } // ######################################################### // helper functions // ######################################################### float rfloat(float val, unsigned int num) { if(num) { float f = 10.0 * num; return round(val*f)/f; } else return round(val); } void sendTemperature() { wdt_reset(); float tmp = htu.readTemperature(); if(tmp < 900){ // check errors tmp = rfloat(tmp, 1); if((tmp != htu_temperature) || (temperatureCnt >= VALUE_MIN_COUNT)){ htu_temperature = tmp; send(msg.setSensor(ms_temperature).setType(V_TEMP).set(htu_temperature,1)); temperatureCnt = 0; } else temperatureCnt++; } } void sendHumidity() { wdt_reset(); float tmp = htu.readHumidity(); if(tmp < 900){ // check errors tmp = rfloat(tmp, 0); if((tmp != htu_humidity) || (humidityCnt >= VALUE_MIN_COUNT)){ htu_humidity = tmp; send(msg.setSensor(ms_humidity).setType(V_HUM).set(htu_humidity,0)); humidityCnt = 0; } else humidityCnt++; } } void sendBatteryReport() { wdt_reset(); delay(500); float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true); int batteryPcnt = static_cast<int>(p); sendBatteryLevel(batteryPcnt); } void sendInput0() { wdt_reset(); if(digitalRead(PIN_INPUT_0) == HIGH) send(msg.setSensor(ms_input_0).setType(V_TRIPPED).set(0)); else send(msg.setSensor(ms_input_0).setType(V_TRIPPED).set(1)); } void sendInput1() { wdt_reset(); if(digitalRead(PIN_INPUT_1) == HIGH) send(msg.setSensor(ms_input_1).setType(V_TRIPPED).set(0)); else send(msg.setSensor(ms_input_1).setType(V_TRIPPED).set(1)); }```
-
RE: Interrupt and sleep
ahhhhhhhhhhhh - I created a door/window sensor some weeks ago - but I couldn't make it run to fire an interrupt on pin change (INT0 and INT1 are used to connect external magnetic sensors) - today I decided to work on this issue again and found this topic at the forum - so I downgraded my arduino IDE by downloading v1.6.8 from arduino.cc today - compiled my code again - falshed it - and voilà - it works
That is really frustrating by wasting that many hours of time only by inconsistancy with compiler/board definitions.
Is there any need to update to newer arduino-IDE - otherwise I would recommend to general stick to one version ... -
offline mode
I'm working with mysensors since vesion v1.5 and I'm really impressed about the feature set and how easy it is to implement a new node.
In the meanwhile I have ~10 nodes installed and last weekend I upgraded to v2.1 - so far so good
During the update I thought about how I can improve the stability of my system - maybe another motivation was that my wife's mood was really sad due to offline time of the system during the update - I worked 2h on that and during this time my light and some other stuff stopped working. Do you know the statement - "happy wife - happy life"
I have a central gateway with node red and mqtt and 2 router nodes to increase the communication distance.
The main question is - how can I detect the downtime of my gateway in a node to enter a defined "offline mode". For example - I have some light controller nodes with connected PIR modules - in online mode the PIR sends a message and the controller activates the light for a dedicated time. If the network is down it would be great if the node handles this logic by it's own - without any controller. If the network is online again the node goes back to its default behavior.
I read the API documentation - specially about the function "send"
There is a return value - but I couldn't find any clear description or example how to handle this return value correctly. Another question is - what about if there is a router node between node and gateway?Does anyone has an idea how to implement such an offline detection mechanism?
Many thanks for your help in advance,
Joerg -
RE: Windows GUI/Controller for MySensors
I'm new to MySensors and playing around with this implementation since some weeks. I implemented an interface from serial to MQTT per python and everything is running fine so far. The last days I spend some time with the bootloader (it is a great feature!!!). I created also a python mqtt client that will take care on that.
I got really crazy the last 2 days with the CRC calculation. I always got a different CRC as as the MYSController. Now I found out, that it seems that the last byte within the HEX file is interpreted as 0xFF instead of the real data. I flashed now one sensor with the MYSController and as I can see in the log-file -> the last byte is read from the HEX as wrong value (0xFF instead of 0x14) -> therefore the HEX file is not flashed correctly (last byte is wrong) -> it seems that this is a bug in MYSController. (I'm using version 0.1.2.278)
Can you check that please?