@TimO, cool that you are stil on it, even if it's on the "todo-list".
Kudos and keep up the great work
Posts made by Nicklas Starkel
-
RE: openHAB 2.2 binding
-
RE: openHAB 2.2 binding
@TimO , is this binding supported via mysensors MQTT gateway?
In previous bending inormation you had some text indicating that you would implement it. But all that is gone.
So I'm thinking you either implemented it, or aborted that feature -
RE: openHAB 2.0 binding
@TimO , did you ever get MQTT to work or do you need someone to test?
-
Watering flowers on the balcony + LED illumination
I recently managed to build a small irrigation system for my balcony, using mysensors of course!
It was picked up by Sweden's best "smart home"-shop "m.nu" and I had a chance to blog about it.
@hek , I didn't really clean up the code so you actually got credit for it on their facebook page, lol.
Hope you approve or I will make them change it.
Maybe you can see a trade off with the fame and that I also mentioned mysensors.orgSwedish version:
https://blog.m.nu/gastblogg-styrning-av-bevattning-balkonglador/English using google translate:
https://translate.google.com/translate?sl=sv&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=https%3A%2F%2Fblog.m.nu%2Fgastblogg-styrning-av-bevattning-balkonglador%2F&edit-text=Cheers
-
RE: openHAB 2.0 binding
I was checking back on this bindning and it really has matured!
On GitHub I see that there are some updates referring to MqTT protocol.
Are they available in the JAR that is posted here?
http://www.oberfoell.com/openhab2/org.openhab.binding.mysensors-2.0.0-SNAPSHOT.jarKudos on the great work!
-
RE: delay different functions in loop
After some hours of sleep and refactoring everything, now I think I've managed to get everything working.
I have some problem wrapping my head around "forceTransmit" command and how it works.
Also, millis() is also something I have to learnHere is the code if anyone finds it interesting.
What it does is measure soil moisture every hour and sends info (normal forkthingie).
Also reading every 30 seconds for temperature and humidity (si7021)
If humidity changes by 1 or temperature by 0.2 it will send info.
If no info has been sent it will force send info every 20 minutes.3 Relays are there to power water pumps and a LED strip.
i have now semi-learned the use of functions, which is fun
cheers!/** * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay */ // Enable debug prints to serial monitor #define MY_DEBUG //Network #define MY_NODE_ID 62 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC #define MY_RADIO_NRF24 //Includes #include <SPI.h> #include <MySensors.h> #include <SI7021.h> #include <RunningAverage.h> //Define Relay #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_2 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_3 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 3 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define RELEASE "1.4" //Define Moisture things #define AVERAGES 2 // Child sensor ID's #define CHILD_ID_TEMP 5 #define CHILD_ID_HUM 6 #define CHILD_ID_MOISTURE 7 // How many milli seconds between each measurement of temp and humidity #define MEASURE_INTERVAL 30000 // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller #define FORCE_TRANSMIT_INTERVAL 2000 // 20minutes // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #define HUMI_TRANSMIT_THRESHOLD 1.0 #define TEMP_TRANSMIT_THRESHOLD 0.2 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0])) #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading SI7021 humiditySensor; // Sensor messages MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgMoist(CHILD_ID_MOISTURE, V_HUM); MyMessage msgR1(RELAY_1, V_STATUS); MyMessage msgR2(RELAY_2, V_STATUS); // Global settings const unsigned long tUpdateTemp = 5000; // update interval unsigned long t0; const unsigned long tUpdateMoist = 360000; // update interval unsigned long t1; int measureCount = 0; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements float lastTemperature = -100; int lastHumidity = -100; int oldMoistureLevel = -1; //Change direction on moisture byte direction = 0; //Moisture sensor pins RunningAverage raHum(AVERAGES); const int SENSOR_ANALOG_PINS[] = {A0, A1}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups. void before() { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { Serial.begin(115200); humiditySensor.begin(); isMetric = getControllerConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); raHum.clear(); t0=millis(); t1=millis(); //sendTempHumidityMeasurements(true); //sendMoistureMeasurements(); delay(250); for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) { pinMode(SENSOR_ANALOG_PINS[i], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[i], LOW); } } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("RelayTempHumMoist", "1.0"); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY,"Relays"); } present(CHILD_ID_TEMP,S_TEMP,"Temperature"); present(CHILD_ID_HUM,S_HUM,"Humidity"); present(CHILD_ID_MOISTURE, S_HUM,"Moisture"); } void loop() { measureCount ++; bool forceTransmit = false; transmission_occured = false; if (measureCount > FORCE_TRANSMIT_INTERVAL) { forceTransmit = true; measureCount = 0; Serial.print(F("inne i loopen :")); } if ((millis() - t1) > tUpdateMoist) sendMoistureMeasurements(); sendTempHumidityMeasurements(forceTransmit); } void sendTempHumidityMeasurements(bool force) { wait(MEASURE_INTERVAL); bool tx = force; si7021_env data = humiditySensor.getHumidityAndTemperature(); raHum.addValue(data.humidityPercent); float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); float diffHum = abs(lastHumidity - raHum.getAverage()); Serial.print(F("TempDiff :"));Serial.println(diffTemp); Serial.print(F("HumDiff :"));Serial.println(diffHum); t0 = millis(); if (isnan(diffHum)) tx = true; if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true; if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true; if (tx) { measureCount = 0; float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0; int humidity = data.humidityPercent; Serial.print("T: ");Serial.println(temperature); Serial.print("H: ");Serial.println(humidity); send(msgTemp.set(temperature,1)); send(msgHum.set(humidity)); lastTemperature = temperature; lastHumidity = humidity; transmission_occured = true; } } void sendMoistureMeasurements() { pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging sleep(STABILIZATION_TIME); int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction])); // Turn off the sensor to conserve battery and minimize corrosion pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[direction], LOW); direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion // Always send moisture information so the controller sees that the node is alive // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information if (oldMoistureLevel == -1) { // First reading, save value oldMoistureLevel = moistureLevel; } send(msgMoist.set((moistureLevel + oldMoistureLevel + 0.5) / 2 / 10.23, 1)); oldMoistureLevel = moistureLevel; t1 = millis(); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }```
-
delay different functions in loop
Well, it's been a couple of hours now I've been trying to get things to work but now I have to ask for help.
I understand that you can call a function from the loop.
I have combined the sketches: RELAY, SOIL MOISTURE and SI7021 (which is a temperature/humidity sensor).all parts are working as expected but I want for instance the soil moisture to only be activated and do it's stuff every hour or so.
While the temperature/humidity should be checked every 5 minutes and send info if changed + forced every 30 minutes..
I have gotten it to work, but it's not a nice sketch, and I have problem with the timings.
Because if I call the functions they only work if I add a serial print to see if it's actually counting.
If I comment it out, it will show everything like every 3 seconds..
I understand my sketch is aweful, but it's the best I can do at the moment (still learning).Someone that could take a look and/or point em in the right direction?
Thanks./** * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay */ // Enable debug prints to serial monitor #define MY_DEBUG #define MY_NODE_ID 62 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node //#define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #include <SI7021.h> #include <RunningAverage.h> #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_2 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_3 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 3 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define RELEASE "1.4" #define AVERAGES 2 // Child sensor ID's #define CHILD_ID_TEMP 5 #define CHILD_ID_HUM 6 #define CHILD_ID_MOISTURE 7 // How many milli seconds between each measurement #define MEASURE_INTERVAL 30000 // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller #define FORCE_TRANSMIT_INTERVAL 120000 // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #define HUMI_TRANSMIT_THRESHOLD 0.2 #define TEMP_TRANSMIT_THRESHOLD 0.2 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0])) #define MOISTURE_TIME 5000 //1800000 // Sleep time between reads (in milliseconds) #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading SI7021 humiditySensor; // Sensor messages MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msg(CHILD_ID_MOISTURE, V_HUM); // Global settings int measureCount = 0; int TempHum = 0; int Moisture = 0; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements float lastTemperature = -100; int lastHumidity = -100; int oldMoistureLevel = -1; byte direction = 0; RunningAverage raHum(AVERAGES); const int SENSOR_ANALOG_PINS[] = {A0, A1}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups. void before() { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { Serial.begin(115200); Serial.print(F("Sensebender Micro FW ")); Serial.print(RELEASE); Serial.flush(); humiditySensor.begin(); Serial.flush(); Serial.println(F(" - Online!")); isMetric = getControllerConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); raHum.clear(); sendTempHumidityMeasurements(false); present(CHILD_ID_MOISTURE, S_HUM); for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) { pinMode(SENSOR_ANALOG_PINS[i], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[i], LOW); } } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay", "1.0"); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); present(CHILD_ID_TEMP,S_TEMP); present(CHILD_ID_HUM,S_HUM); present(CHILD_ID_MOISTURE, S_HUM); } } void loop() { TempHum ++; Moisture ++; measureCount ++; bool forceTransmitTemp = false; bool forceTransmitMoist = false; transmission_occured = false; if (TempHum > FORCE_TRANSMIT_INTERVAL) { // force a transmission //forceTransmitTemp = true; TempHum = 0; sendTempHumidityMeasurements(forceTransmitTemp); } if (Moisture > MOISTURE_TIME) { // force a transmission //forceTransmitMoist = true; Moisture = 0; sendMoistureMeasurements(forceTransmitMoist); } Serial.print(F("TempHum interval :"));Serial.println(TempHum); //wait(MEASURE_INTERVAL); } void sendTempHumidityMeasurements(bool force) { bool tx = force; si7021_env data = humiditySensor.getHumidityAndTemperature(); raHum.addValue(data.humidityPercent); float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); float diffHum = abs(lastHumidity - raHum.getAverage()); Serial.print(F("TempDiff :"));Serial.println(diffTemp); Serial.print(F("HumDiff :"));Serial.println(diffHum); if (isnan(diffHum)) tx = true; if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true; if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true; if (tx) { TempHum = 0; float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0; int humidity = data.humidityPercent; Serial.print("T: ");Serial.println(temperature); Serial.print("H: ");Serial.println(humidity); send(msgTemp.set(temperature,1)); send(msgHum.set(humidity)); lastTemperature = temperature; lastHumidity = humidity; transmission_occured = true; } } void sendMoistureMeasurements(bool force) { pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging sleep(STABILIZATION_TIME); int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction])); // Turn off the sensor to conserve battery and minimize corrosion pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[direction], LOW); direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion // Always send moisture information so the controller sees that the node is alive // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information if (oldMoistureLevel == -1) { // First reading, save value oldMoistureLevel = moistureLevel; } send(msg.set((moistureLevel + oldMoistureLevel + 0.5) / 2 / 10.23, 1)); oldMoistureLevel = moistureLevel; transmission_occured = true; Serial.print("M: ");Serial.println(moistureLevel); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }```
-
RE: Wall mounted 'mood light' v2
Hey @AWI
I have some trouble using this with MqTT messages.
I can get alarm to go off by sending a payload of '1' to 'InMQTT/62/4/1/0/2' and subsequently turn it off with any other value.But I can't get the rest of your functions to work!
If I read your code correct, to set a solid color I would have to send several MqTT messages to the children?
Ex, I would have to send 'InMQTT/62/1/1/0/40' and payload ex 'Candle' first.
Then 'InMQTT/62/1/1/0/2' with payload of '1' to turn it on?
I was looking at the serial protocol and do not find what V_Dimmer is for type. (https://www.mysensors.org/download/serial_api_20#variable-types)Anyways, i cant get it to work properly, maybe you could shed some light (pun not intended ) )?
-
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@Anticimex and @tekka .
I just upgraded my GW (MEGA) and most sensors.
I do not know what you did, but my range is incredible now (and everything works!)
I had good coverage in my apartment before, but if I went outside my front door it started failing (steel security door).
Now, I can not only go outside the door, I can actually go 3 stairs down in my building with AWIs NRF tester.
Same hardware is used and nothing has changed from my part.Kudos and thank you.
-
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@Anticimex , eh, no apologies needed. I'm thankful mysensors is opensource and actually FREE!
Cool that you found a bug and if I helped, I'm glad -
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@Anticimex I not sure I follow you and perhaps I am doing it wrong
I power my arduinos via their usb jacket, 5V/2.1A
If I'm using the NRF plate it has its own dedicated regulator hence its getting 3xAAA 4.5V.
Otherwise I am using 2xAA which is around 3.3V connected to VCC/GND of the radio module and GND is also connected to the arduino. -
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@Anticimex
I power either with 3xAAA (4.5V) if I'm using the plate.
If I'm using only capacitor I power with 2xAA (3.3V).
Tried both versions with same results. Only difference is Arduino/MEGA.
All batteries fresh and also checked with voltmeter -
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@tekka that was my next goal
I just built an UNO with an ethernet shield and low and behold its working with 47uF capacitor.
Conclusion:
MEGA does not work with NRF plate adapter nor 47uF capacitor.
UNO works with 47uF capacitor only (not with plate).All nodes are reporting in (mixed 2.0 and 2.1).
I use @AWI quality meter with NRF plate board to test as well and it is OK.So same NRF hardware yields different results on UNO and MEGA for me.
-
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@Anticimex maybe I was not clear enough or used the wrong words?
I still understand that the problem is not with signing.
I pointed out that using signing provokes the error.
The error is still an underlying issue weather it be my hardware or it be NRF module code in mysensors 2.1. -
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
Well so I deleted whole Arduino to make sure I got everything fresh.
Installed arduino and mysensors 2.0 via library manager and also mysensors HW arduino manager in preferences.Updated my gateway and all nodes work with signing ON.
The nodes are a mixture now with mysensors 2.0 as well as 2.1.I updated library to 2.1 in my GW and instantly I have failed messages with Signing ON.
To make sure, I powered the GW from one source and NRF separately from external source (5v computer usb)
No changes. I tried different NRF as well as NRF PA with big antenna.
I even tried different antennas (used to other applications). With mysensors 2.0 they work, with 2.1 fails.I took a node and powered it similar with external power source (3x1.5v AAA) for the NRF but it would still give me fails.
When I go back to mysensors 2.0 everything works great again.
I guess I'll stick with 2.0 and wait and see if other people upgrade their stuff and use signing might see the same problem with their hardware.
-
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@Anticimex I understand that the problem is not with signing itself.
I also understand that with longer messages with low power things it gets extra difficult.What I am saying is mysensors 2.1 did something and my hardware can't cope with it.
I have tried socket adapters for NRF modules.
I have tried giving them external power.
I tried without socket adapters.
Giving external power as well.
I have tried 47uF capacitator.Mind you, I have tried several different hardware pieces as well just to make sure.
I will redo everything above again just to make sure and report back.
-
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
@tekka Im not saying it doesn't work, but it doesn't work
I have spent some hours yesterday and today testing different possibilities.
However, as soon as I enable soft signing it just my nodes get no reply or partial reply sometimes.If I disable softsigning in GW, everything works perfect.
I would guess that the problem could be with my hardware as everything except my ethernetshield is china clones.
But since I had used everything and everything worked without a flaw (with signing) and the only thing I did was update library via arduino, and uploaded the same sketch (without editing it) to the GW.
I would beg to differ that something is not broken with mysensors 2.1. Or atleast maybe compability has been lowered.
Or mysensors 2.1 changed something in the use of the NRF chips (the + as well as PA with big antenna!).I uninstalled arduino completely, but had some problems installing 2.0 as it complained about some stuff about my arduino mega. But when I installed 2.1 it worked with mega which is also weird.
It is no biggie that signing doesn't work for me, but It bugs me that this should be simple and it isn't.
To sum up:
My NRF works without signing. It even works behind steel heat radiators across my flat (yes, did that for testing purposes!)
Switch on signing and I can barely connect to my GW. -
RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
I had built the NRF tester and had perfect coverage with no drops in my apartment before (with signing!) from any of my NRFs.
To test further I even put one of those plateboards for testing NRF to my gateway. Added external power from another source.
Did the same to my NRF tester but still it fails.
Have put them close and also gone around in my apartment to eliminate distance signal error, still the same.
So only difference is mysensors 2.1.
However, since no one else is complaining then maybe the problem IS with my setup.
Or could also be that no one else has updatedI'm using Arduino 1.6.11, maybe I should install 1.8.1?
-
[SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
So I took the plunge and sent the same sketch as I had when using mysensors 2.0 to my Arduino Mega with w5100 ethernet shield.
It is the MQTT sketch.After this I could not use any nodes with signing.
LOGS as follow.
Gateway:
0;255;3;0;9;Attempting MQTT connection... 0;255;3;0;9;MQTT connected 0;255;3;0;9;Sending message on topic: MyMQTT/0/255/0/0/18 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.1.0 0;255;3;0;9;!TSF:MSG:SIGN VERIFY FAIL 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0 0;255;3;0;9;!TSF:MSG:SIGN VERIFY FAIL 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=3,t=11,pt=0,l=17,sg=0:Sensebender Micro 0;255;3;0;9;!TSF:MSG:SIGN VERIFY FAIL 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2 0;255;3;0;9;!TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=16,pt=0,l=0,sg=0,ft=0,st=NACK: 0;255;3;0;9;!TSF:MSG:SIGN FAIL 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2 0;255;3;0;9;TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=16,pt=0,l=0,sg=0,ft=0,st=OK: 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=3,t=17,pt=6,l=25,sg=0:192E7CA3C75EA05198759BA9F6FF17532DA77693DED0692059 0;255;3;0;9;!TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=27,pt=1,l=1,sg=1,ft=0,st=NACK:1 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2 0;255;3;0;9;!TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=16,pt=0,l=0,sg=1,ft=0,st=NACK: 0;255;3;0;9;!TSF:MSG:SIGN FAIL 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=1,c=1,t=0,pt=7,l=5,sg=0:26.9 0;255;3;0;9;!TSF:MSG:SIGN VERIFY FAIL 0;255;3;0;9;TSF:MSG:READ,6-6-0,s=0,c=1,t=1,pt=2,l=2,sg=0:34 0;255;3;0;9;!TSF:MSG:SIGN VERIFY FAIL
And this is a NODE:
0 MCO:BGN:INIT NODE,CP=RNNNAS-,VER=2.1.0 3 TSM:INIT 4 TSF:WUR:MS=0 11 TSM:INIT:TSP OK 13 TSM:INIT:STATID=6 15 TSF:SID:OK,ID=6 17 TSM:FPAR 53 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2060 !TSM:FPAR:NO REPLY 2062 TSM:FPAR 2105 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 4112 !TSM:FPAR:NO REPLY 4114 TSM:FPAR 4118 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 6125 !TSM:FPAR:NO REPLY 6127 TSM:FPAR 6130 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 8138 !TSM:FPAR:FAIL 8139 TSM:FAIL:CNT=1 8141 TSM:FAIL:PDT 18144 TSM:FAIL:RE-INIT 18146 TSM:INIT 18153 TSM:INIT:TSP OK
If I remove the below signing code in the GW it all works OK.
#define MY_SIGNING_SOFT #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 #define MY_SIGNING_REQUEST_SIGNATURES
Anyone else with the same problem (ping @Anticimex )?
I downgraded my arduino boards to 1.6.11 as per instructions in some other posts.
I also ran the signing sketch again (software backend) on my nodes, but to no avail.//Nicklas
-
RE: WS2811 RGB strip lights up in groups of three
@mfalkvidd , quite OT, but how do you power these?
I have them as well and when I calculate how much amp they should draw it is quite much!
However, when I check what they actually draw is quite low. Around 3-4A on full bright white.
Do not really know what I should aim for because you can find nice 5A or less quite easily while above this you would have to go with big ugly power supplys.
And it's a shame they work in 5V only as 12V would be much better for me (and get more A out of as well from smaller power supplys) -
RE: Office plant monitoring
@joshmosh I use MySensors V2 and took a sample every 30 seconds over a few days simulating almost 28000 transmits.
I've come down to have roughly 0.08V decrease for all these transmits which is very close to what @mfalkvidd has.@TON-RIJNAARD , here is my sketch! I think I use signing as well, so if you don't use it just remove
// Enable debug prints to serial monitor #define MY_DEBUG //The node ID #define MY_NODE_ID 7 //250 is test // Enable and select radio type attached and also set parent ID #define MY_RADIO_NRF24 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC //Signing, make sure the arduino is prepped for signing before! #define MY_SIGNING_SOFT #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 #define MY_SIGNING_REQUEST_SIGNATURES #include <SPI.h> #include <MySensors.h> #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0])) #define CHILD_ID_MOISTURE 0 #define CHILD_ID_BATTERY 1 #define SLEEP_TIME 1800000 // Sleep time between reads (in milliseconds) #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading #define BATTERY_FULL 3000 // 3,000 millivolts for 2xAA #define BATTERY_ZERO 2800 // 1,900 millivolts (1.9V, limit for nrf24l01 without step-up. 2.8V limit for Atmega328 without BOD disabled)) const int SENSOR_ANALOG_PINS[] = {A0, A1}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups. MyMessage msg(CHILD_ID_MOISTURE, V_HUM); MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE); long oldvoltage = 0; byte direction = 0; int oldMoistureLevel = -1; void setup() { sendSketchInfo("Plant moisture w bat", "1.5"); present(CHILD_ID_MOISTURE, S_HUM); delay(250); present(CHILD_ID_BATTERY, S_CUSTOM); for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) { pinMode(SENSOR_ANALOG_PINS[i], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[i], LOW); } } void loop() { pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging sleep(STABILIZATION_TIME); int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction])); // Turn off the sensor to conserve battery and minimize corrosion pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[direction], LOW); direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion // Always send moisture information so the controller sees that the node is alive // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information if (oldMoistureLevel == -1) { // First reading, save value oldMoistureLevel = moistureLevel; } send(msg.set((moistureLevel + oldMoistureLevel + 0.5) / 2 / 10.23, 1)); oldMoistureLevel = moistureLevel; long voltage = readVcc(); if (oldvoltage != voltage) { // Only send battery information if voltage has changed, to conserve battery. send(voltage_msg.set(voltage / 1000.0, 3)); // redVcc returns millivolts. Set wants volts and how many decimals (3 in our case) sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO))); oldvoltage = voltage; } sleep(SLEEP_TIME); } long readVcc() { // From http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA, ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high << 8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts }```
-
RE: openHAB 2.0 binding
Just stumbled across this binding great work!
Until now I have used MQTT binding and MQTT gateway.
Will try this later on.
However, is there a reason why this binding is not part as downloadable from within OH2?
Cheers -
RE: Gateway or mqtt?
If we go from the front to the back this is what is needed:
1 Node: For example a door bell.
This node sends information to a gateway.
2 The gateway takes the message from the node and sends this to a controller. For instance Openhab or Domotics. This can be done in several ways. MqTT being one.
3 Controller: takes the information and displays it to you.So in my case, I hardcode Node ID and CHILD ID (the complete door bell is a NODE whereas CHILD IDs may be the button pressed and maybe temperature reading at the same time).
This sends to Gate way that takes the information and creates a MqTT message.
What this message is, please read the instructions on this site. -
RE: Gateway or mqtt?
I think you mean you want to use the Gateway WITH MqTT
https://www.mysensors.org/build/mqtt_gatewayThis works very well and I'm using it myself.
I have the MqTT broker on a raspberry pi.
And the gateway is an arduino with W5100 ethernet board. -
RE: gw.sleep on battery powered magnet door switch
@siod and @LastSamurai
Connect the REED Switch with one leg to GND and the other leg to PIN2.
And then you put a 1MOhm resistor between VCC and PIN2. -
RE: Office plant monitoring
@joshmosh , actually there is so many variables that it is impossible to check and the term "milage may vary" is spot on.
All batteries are not the same.
Temperature.
Arduino.
Time between readings (some batteries prefer small current over time and some handle bursts better).
etcI've set to report moisture every 30 seconds and obviously the voltage report from an arduino is not 100%. And with that said, it is probably not 100% consistent neither as it could differ between readings as well.
The only real way to tell is know starting point via multimeter and then check after a month what has happened.
For me, doing a check, I've come down to 0.08V per 76000 readings.
I did the estimation based on about 8500 readings and extrapolated it to 76000 reports based on @mfalkvidd information.For me, this is enough and I'm sure my sensor will survive for a long time and can now program it to take more reasonable moisture readings. Example, 1reading/h for the plots that dries the fastest (in direct sunlight) and less when they are in the shade.
In the spring the balcony will have several sensors with automatic watering -
RE: ๐ฌ Battery Powered Sensors
@AWI OMG there is so many options when you look at it!
I think it all boils down to design (size) or money.
Normal AA roughly 0.3EUR/pc are quite large but OK power but cheap
CR123 roughly 2.5EUR/pc are quite small and OK power but expensive
Coin cell roughly 1EUR/pc and they are the smallest but not packing a good punch while being semi cheap/expensive.Obviously I have to build one node with each and put them in flowerpots around the flat to see in in action
And to top it off, I know there is a company in USA that has created a new battery that will double 'Ah' in same size batteries. They should launch this month i think, but think they will go for cellphone makers in the beginning.
-
RE: Office plant monitoring
@mfalkvidd that is really awesome!
Did you set any Brown Out Fuses?
From what I gather the arduino pro mini will stop working at 2.8V and you have to set other fuses for it to reach the lower voltages.I did a quick test with one flowerpot and from what I see my power consumption will be around 0.2V per year. It's more than double of what you're getting. But still low enough as changing 2 AA over 1-2 years is OK in my book if I'm not changing the fuses
EDIT: Actually, calculating with your numbers of updates I get around 0.6V consumption per year for my setup and that is far from your low power consumption.
I think I will have to go through this thread once more to try to find why the difference is so big and what you have done. I see 2 potential culprits. One is the arduino mini pro (china clone without power LED and voltage regulator) or maybe it could be my mysensors 2.0 version vs your 1.6. -
RE: ๐ฌ Battery Powered Sensors
@AWI in the first part it states:
"Primary cells such as lithium-metal and alkaline retain the stored energy best, and can be kept in storage for several years."
So you are correct and between Alkaline and Lithium-metal maybe the latter would be best.
I have no experience with coin cells and will do some testing with them as soon as I can.
Since this is the battery article, would you please tell me what you use and how you use it. What you expected and if the batteries lived up to your expectations. Would be cool to know as you've had more experience then me (and many like me)! -
RE: ๐ฌ Battery Powered Sensors
Good article/site on why Alkaline is the best way to go for Mysensors nodes
http://batteryuniversity.com/learn/article/elevating_self_discharge -
RE: gw.sleep on battery powered magnet door switch
@siod , I had the same problem.
I actually ordered a original NRF 24 mini and this seemed to solve some of my problems.
i think another problem I'm having is that my batteries has a huge self discharge (old 3.7v 18650)On a side note.. I'm with @sling .
Loose the pullups and set them LOWยด.
I have a 1MOhm resistor between VCC and PIN 2 and PIN 3 (also 2 switches).
Using the pullup HIGH draws around 130uA versus LOW it draws between 7 to 10uA! -
RE: ๐ฌ Battery Powered Sensors
@hek , I've read that post several times
Since it was so outdated (2 years) I naturally assumed the 'battery powering article' was a newer way to do it (especially since mys2.0).
Also, the post you linked to is attributed if you use no voltage regulator.
And in the article this is also one of the things you are recommended to remove, hence making it even more confusing as to why the article describes another way than the post. -
RE: ๐ฌ Battery Powered Sensors
@gloob thanks!
One would think running with no resistors and not using a separate PIN would be better.@hek or @mfalkvidd , any comments as to why the original sketch is preferred over the other 'way' in this article?
-
RE: ๐ฌ Battery Powered Sensors
Another battery related question that I really do not understand.
Are there different versions on how to read battery consumption?I see some sketches uses:
long readVcc() { long result; // Read 1.1V reference against AVcc ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle noInterrupts (); // start the conversion ADCSRA |= _BV (ADSC) | _BV (ADIE); set_sleep_mode (SLEEP_MODE_ADC); // sleep during sample interrupts (); sleep_mode (); // reading should be done, but better make sure // maybe the timer interrupt fired while (bit_is_set(ADCSRA,ADSC)); result = ADCL; result |= ADCH<<8; result = 1126400L / result; // Back-calculate AVcc in mV```
However some (like the original one in this thread) uses:
int sensorValue = analogRead(BATTERY_SENSE_PIN);
Is it due to different libraries or maybe it is the same but just programming wise different?
-
RE: Sleep time is not actual sleep time
@Yveaux and @mfalkvidd thanks!
It's not important for me, just curious to know why -
Sleep time is not actual sleep time
Hello,
I use Sleep on one of my nodes and then wake up to report to GW.
It is set to sleep 3600000 which should equivalent to 1 hour (10006060).
However, I can see that this is not the case.
My node wakes up, but about every 1hour 9 minutes instead to report.
I'm using a arduino pro mini (chinese) so obviously this could be the culprit.
Just wondering if anyone else has seen this -
RE: ๐ฌ Battery Powered Sensors
@parachutesj you have to modify the pro mini. Remove the power led according to instructions!
-
RE: Battery powered sensor last 1 week
@Martin-Tellblom , how is your project going!
Did you manage to get longer lasting nodes?I have one reed magnetic switch. It seems this only draws 7-10ua in sleep mode and upwards 17ma when sending.
However, it still drains my batteries very quick which I find odd.
It wakes up once every hour to send and that should not be much..
Could be that my rechargable battery is bad so I'll try to replace it with 2AA instead of one 3,7v. -
RE: ๐ฌ Battery Powered Sensors
@mfalkvidd , it was too late at night for me.
I had it at current but it didn't show anything. So without thinking I put it at voltage.
And the problem with not showing anything when I had it at current was I had blown the internal multimeter fuse some days ago.
Ehrmm.. yes. move along, nothing to see here -
RE: ๐ฌ Battery Powered Sensors
@mfalkvidd that's what I thought! I see that I'm getting 3.4V in the multimeter but my pro mini nor nano will start up (I have not removed the LEDs so they should light up).
If I use more V (6.8V) I put in via RAW on the PRO mini, and I can see teh voltage, but the same thing, it's not starting up, hmmm I wonder what rookie mistake I'm doing! -
RE: ๐ฌ Battery Powered Sensors
Sorry, where do you measure the power when it is in sleep mode? ie, where do you put your multimeter probes.
-
RE: My 2AA battery sensor
@EasyIoT , how are your sensors doing, its been 2 years
And also, @m26872 , the node 105. Is it alive? -
RE: ๐ฌ Building a MQTT Gateway
Regarding ACK flag in MQTT.
If a sensor sends data to the gateway, and it requests an ACK.
It is the gateway that responds with an ACK, not the controller.How do one utilize the ACK flag in MQTT?
Or rather, how do one get the ACK to display in a MQTT message?void receive(const MyMessage &message) { int value = debouncer.read(); //We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } }
Should I write a codesnippet like the above but one that sends a message back to the gateway, that the ACK was received?
And also, if an ACK was not received that the sensor should try to send the message again. -
RE: Battery powered sensor last 1 week
@Martin-Tellblom , I'm in this mess as well. Just ordered a new Multimeter off aliexpress
@sundberg84 , have you tried other batteries? I bough some ultrafire 3.7V 8800mAh and will try these.
They were cheap so no loss if they do not work out.. -
RE: nRf24L01+ connection quality meter
@AWI what is the board between the nano and the radio?
Something available via aliexpress?I really do not need this as I live in a small flat.. but I NEED THIS!
-
RE: domoticz auto add device (mysensors) even if disable "Accept new Hardware Devices"
@Anticimex yes. But since his neighbours nodes aren't signed (or with wrong signation), the repeater will not forward them to his gateway.
Or am I totally wrong? -
RE: domoticz auto add device (mysensors) even if disable "Accept new Hardware Devices"
@Reza
From what I understand the GateWay will add all nodes even if you do not want them to. But not to the controller if you have "inclusion option" on the GateWay.
There is a possibility that if you use the "inclusion option" maybe it will pick up all sensors not already added (ie your neighbour) if they are sending while inclusion is looking for new sensors.
If you want to stop this you will have to use whitelisting on MAC adress. But this requires you to reprogram GateWay everytime you want to add new sensor (or maybe it is possibility to have same MAC for all?).
And of course you will have to program a MAC adress for all sensors/per sensor the first time as well.
I thought this problem would be solved with only using Signing, but because of backwards compability the creators did not enable this in the GateWay.
If you only would want signing, you could make all nodes connect via a repeater node.
Because between repeater nodes and regular nodes signing is enabled and no other nodes is accepted which aren't signed with correct signing
And if you use Whitelisting only between GateWay and repeater node, you are set.Note: I could be wrong
-
RE: domoticz auto add device (mysensors) even if disable "Accept new Hardware Devices"
@scalz said:
@Reza
Finally, the inclusion mode. That's mostly the feature you need, because it could help you to block new nodes. I think this is a feature that the controller has to implement. I don't use inclusion mode in mysensors (not tried yet),
but in the controller I'm using (jeedom), it works well. There is one inclusion button (I don't advice you to use jeedom, it's french! and not 2.0 full compliant). As you can see this is possible to have a working inclusion button in controllerYou have to use whitelisting to block nodes. 'Signing' in GateWay does not work as it accepts non signed nodes. Signing primarily is used for nodes receiving info.
-
RE: Forced transmit by threshold is not working
@mfalkvidd thanks!
I actually found the problem while messing around with different settings.
I changed 'uint16_t' to regular 'int' and it started working!
Now, both should have worked (I guess by doing a quick google on uint16_t).
So as to why how what.. im perplexed.
Thanks for looking at the code -
Forced transmit by threshold is not working
Hello,
So I combined 2 sketches and I'm having some problems.
The temperature and Humidity thresholds works great.
But my Lux threshold does not work as it should.
I really can't pin point what I am doing wrong!// Enable debug prints to serial monitor #define MY_DEBUG #define MY_SIGNING_SOFT #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 #define MY_SIGNING_REQUEST_SIGNATURES // Define a static node address, remove if you want auto address assignment #define MY_NODE_ID 4 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable to support OTA for this node (needs DualOptiBoot boot-loader to fully work) //#define MY_OTA_FIRMWARE_FEATURE #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <SI7021.h> #include <BH1750.h> #ifndef MY_OTA_FIRMWARE_FEATURE #include "drivers/SPIFlash/SPIFlash.cpp" #endif #include <EEPROM.h> #include <RunningAverage.h> //#include <avr/power.h> // Uncomment the line below, to transmit battery voltage as a normal sensor value //#define BATT_SENSOR 199 #define RELEASE "1.4" #define AVERAGES 2 // Child sensor ID's #define CHILD_ID_TEMP 1 #define CHILD_ID_HUM 0 #define CHILD_ID_LIGHT 2 // How many milli seconds between each measurement #define MEASURE_INTERVAL 3000 // How many milli seconds should we wait for OTA? #define OTA_WAIT_PERIOD 300 // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller #define FORCE_TRANSMIT_INTERVAL 30 // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes. // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #define HUMI_TRANSMIT_THRESHOLD 10.5 #define TEMP_TRANSMIT_THRESHOLD 10.1 #define LUX_TRANSMIT_THRESHOLD 200.0 // Pin definitions #define TEST_PIN A0 #define LED_PIN A2 BH1750 lightSensor; SI7021 humiditySensor; SPIFlash flash(8, 0x1F65); // Sensor messages MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgLightLevel(CHILD_ID_LIGHT, V_LEVEL); // Global settings int measureCount = 0; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements float lastTemperature = -100; int lastHumidity = -100; uint16_t lastLux = -100; RunningAverage raHum(AVERAGES); /**************************************************** * * Setup code * ****************************************************/ void setup() { pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); Serial.begin(115200); Serial.print(F("Sensebender Micro FW ")); Serial.print(RELEASE); Serial.flush(); // First check if we should boot into test mode pinMode(TEST_PIN,INPUT); digitalWrite(TEST_PIN, HIGH); // Enable pullup if (!digitalRead(TEST_PIN)) testMode(); digitalWrite(TEST_PIN,LOW); digitalWrite(LED_PIN, HIGH); humiditySensor.begin(); digitalWrite(LED_PIN, LOW); Serial.flush(); Serial.println(F(" - Online!")); isMetric = getConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); raHum.clear(); sendTempHumidityMeasurements(false); lightSensor.begin(); } void presentation() { sendSketchInfo("Sensebender Micro", RELEASE); present(CHILD_ID_TEMP,S_TEMP); present(CHILD_ID_HUM,S_HUM); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } /*********************************************** * * Main loop function * ***********************************************/ void loop() { measureCount ++; bool forceTransmit = false; transmission_occured = false; if (measureCount > FORCE_TRANSMIT_INTERVAL) { // force a transmission forceTransmit = true; measureCount = 0; } sendTempHumidityMeasurements(forceTransmit); /* if (sendBattery > 60) { sendBattLevel(forceTransmit); // Not needed to send battery info that often sendBattery = 0; }*/ sleep(MEASURE_INTERVAL); } /********************************************* * * Sends temperature and humidity from Si7021 sensor * * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) * *********************************************/ void sendTempHumidityMeasurements(bool force) { bool tx = force; // Read light level uint16_t lux = lightSensor.readLightLevel(); uint16_t diffLux = abs(lastLux - lux); Serial.print(F("TempLux :")); Serial.println(diffLux); si7021_env data = humiditySensor.getHumidityAndTemperature(); raHum.addValue(data.humidityPercent); float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); float diffHum = abs(lastHumidity - raHum.getAverage()); Serial.print(F("TempDiff :"));Serial.println(diffTemp); Serial.print(F("HumDiff :"));Serial.println(diffHum); if (isnan(diffHum)) tx = true; if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true; if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true; if (diffLux < LUX_TRANSMIT_THRESHOLD) tx = true; if (tx) { measureCount = 0; float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0; int humidity = data.humidityPercent; Serial.print("T: ");Serial.println(temperature); Serial.print("H: ");Serial.println(humidity); Serial.print(F("TempLux :")); Serial.println(diffLux); send(msgTemp.set(temperature,1)); send(msgHum.set(humidity)); lastTemperature = temperature; lastHumidity = humidity; send(msgLightLevel.set(lux)); // Send tripped value to gw lastLux = lux; transmission_occured = true; } } /******************************************** * * Sends battery information (battery percentage) * * Parameters * - force : Forces transmission of a value * *******************************************/ /******************************************* * * Internal battery ADC measuring * *******************************************/ /**************************************************** * * Verify all peripherals, and signal via the LED if any problems. * ****************************************************/ void testMode() { uint8_t rx_buffer[SHA204_RSP_SIZE_MAX]; uint8_t ret_code; byte tests = 0; digitalWrite(LED_PIN, HIGH); // Turn on LED. Serial.println(F(" - TestMode")); Serial.println(F("Testing peripherals!")); Serial.flush(); Serial.print(F("-> SI7021 : ")); Serial.flush(); if (humiditySensor.begin()) { Serial.println(F("ok!")); tests ++; } else { Serial.println(F("failed!")); } Serial.flush(); Serial.print(F("-> Flash : ")); Serial.flush(); if (flash.initialize()) { Serial.println(F("ok!")); tests ++; } else { Serial.println(F("failed!")); } Serial.flush(); }
The sketch itself is working alright and reads/sends the information.
The humidity/Temp waits until the threshold is reached before sending the message.
But my Lyx sends it really random and not accompanied by the threshold I've set.
Are the tags wrong?Also, since I am a newb, in the sketch there is this row:
SPIFlash flash(8, 0x1F65);
What does it do?
I figured it sets the I2C adress for the SI7021 chip?
However, since I have not set any I2C adress for the BH1750, is this done within the library "#include <BH1750.h>"? -
RE: Read this first - it could SAVE YOU A LOT OF TIME
I just checked my sensors and I'm using 470ยตF.
Shows to go you really should check what you grab from a bag of capacitors -
RE: Enable RF24 Encryption with mysensors V2.x
ahh, so basically the gateway will always accept everything, but nodes will not if signing is enabled.
Maybe it's a longshot, but I was worried that if someone knows my MQTT pathways they would be able to
1: Use a node and send information (ex MQTT/MyActuator/TurnON)
2: The gateway picks it up and converts to MQTT information and publish to MQTT broker
3: My actuator subscribes to this special channel and gets the "TurnON"
And then for example turns on my lights or whatever.While I was writing this I realize more and more that the above is pretty far fetched
Also, I have separated MySensors channel from other channels so they should be safe.But to be on the safe side and there seems not to be any apparent drawbacks, I will use Whitelisting as well.
Thank you for the help @Anticimex ! -
RE: Enable RF24 Encryption with mysensors V2.x
@Anticimex great!
So flashed my gateway and 1 node.
How do you know it "works"?
In my gateway and node sketch I have included:
#define MY_SIGNING_SOFT
#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
#define MY_SIGNING_REQUEST_SIGNATURESReading the document I would expect that all other nodes that isn't "signing" the information would be disregarded by the gateway.
But in my case they can send info to the gateway and it will forward it via MQTT (as I have the ethernet w5100 gateway with MQTTclient).Using serial monitor on the gateway this is what is seen when a signed node is reporting:
0;255;3;0;9;TSF:MSG:READ,4-4-0,s=0,c=3,t=16,pt=0,l=0,sg=1:
0;255;3;0;9;TSF:MSG:SEND,0-0-4-4,s=255,c=3,t=17,pt=6,l=25,sg=1,ft=0,st=OK:5D7FA0C430E8A0363FEBA8E73BDBBD2755DFC7A53E8D1B394F
0;255;3;0;9;TSF:MSG:READ,4-4-0,s=0,c=1,t=16,pt=2,l=2,sg=1:0
0;255;3;0;9;Sending message on topic: Broker/1/0/1/0/16
0;255;3;0;9;TSF:SANCHK:OKA node that isn't signed:
0;255;3;0;9;TSF:MSG:READ,2-2-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;TSF:MSG:BC
0;255;3;0;9;TSF:MSG:FPAR REQ,ID=2
0;255;3;0;9;TSF:CHKUPL:OK
0;255;3;0;9;TSF:MSG:GWL OK
0;255;3;0;9;!TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0
0;255;3;0;9;TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;TSF:MSG:BC
0;255;3;0;9;TSF:MSG:FPAR REQ,ID=1
0;255;3;0;9;TSF:CHKUPL:OK
0;255;3;0;9;TSF:MSG:GWL OK
0;255;3;0;9;TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;TSF:SANCHK:OKTo me it looks like it's ignoring the node because no temperature is received and shown in serial monitor.
But it still reports everything via MQTT.Am I doing something wrong?
-
RE: Enable RF24 Encryption with mysensors V2.x
Hello,
Before I do anything stupid
I followed the documents but want to clarify so...
I used SecurityPersonalizer.ino and uploaded it to a node.
The results were just a bunch of "FFFFFFFFFFFFFFFFFFFFFFFFF".
I defined my own MY_HMAC_KEY, MY_SOFT_HMAC_KEY, MY_SOFT_SERIAL and MY_AES_KEY with different values.
Uploaded it to a node and it saved it in EEPROM (I ran the original sketch to find out what was saved)1: Do I use the same SecurityPersonalizer.ino to my gateway and all nodes so they all have same keys?
Or do I have to change any key?Thanks!
-
RE: ๐ฌ Building a MQTT Gateway
How do you mean it is a problem? Everything works, just needed to know what the extra was
I too use NODE RED, but just listening on MQTT and then putting the info into mysql databases.@hek
Thank you! I have used search, but it is difficult when you do not know what you are searching for And all information about 2.0 is overwhelming at the time being for me. -
RE: ๐ฌ Building a MQTT Gateway
Quick question.
I have built GatewayW5100MQTTClient according to mysensors.
It works and relays my nodes.
However, my old gateway with MqTT delivered the messages with my selected prefix and then node/child number + variable/sensor.
Ex MyMQTT/1/1/S_TEMP
Now the new gateway with MqTT delivers node and child and more like this:
MyMQTT/1/1/x/x/x where X is some number.
It does not display S_TEMP.
And what are the extra "numbers"?And it also displays when the node starts up some MqTT messages that are empty ex:
MyMQTT/1/255/3/0/1 with no information.
I do not know what publishes these..For relevance, the sketches I upload are the ones in the new mysensors library, ex Atmospheric Pressure Sensor.
-
RE: Office plant monitoring
@mfalkvidd , I think there has been many discussions on how these sensors corrodes over time.
I can see that this node sleeps between the readings and thus reduces corrosion as it only is powered during reading.
However, some threads I've read suggests that you alternate the power, as well, between readings.
Something you might implement in the code?
Also, do you have an estimate on the duration usage on the batteries for one of your plants?
Cheers!