How can I set parameter if there are multible instances of the sensor class?
-
Hi (once again),
I just try to create my own sensor class within NodeManager. I have Chirp sensors (https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/) at home for monitoring the mositure of the soil of my plants.
My current (minimal) implementation of the class works fine, but now. I have 3 problems:1.) The sensor produces 3 sensor readings (Capacitance,Light and Temperature). This creates 3 instances of my new Chirp class. If I try to set the class specific parameter (I would like to set an individual capacitance measurement offset because of the scattering of each individual sensor hardware) like in your description:
SensorCHIRP* myCHIRP = (SensorCHIRP*)nodeManager.getSensor(nodeManager.registerSensor(SENSOR_CHIRP)); myCHIRP->setMoistureOffset(330); myCHIRP->setMoistureRange(520); myCHIRP->setRreturnMoistureNormalized(true);
It sets the parameter only in the last instance of the class, but this is not the instance for moisture (ok, I can rearrange the initialization, but maybe there is a better way).
The only way I found, is to substract 2 from the sensorID:(SensorCHIRP*)nodeManager.getSensor(nodeManager.registerSensor(SENSOR_CHIRP)-2);
because it is the first created instance of the class.
Maybe my last c++ project was tooooooo long ago ....
2.) that means: if I want to set (as an example) the setTrackLastValue parameter, I have to do this for all 3 instances?
3.) every instance of the Chirp class does its own sensor initialization. It there a way to do this only once?
If my Chirp class have no further errors (and a way to deal with the above), you can include this class into your package, if you wish ...
Best regards and THANKS for this really helpfull NodeManager library
Frank (Betonmowew)
-
ok ok ... I found a way: the word static is the key !
I have declared all my needed variables as static and do a global initialization in NodeManager.cpp just in front of the code for my Chirp methods. The -2 is not necessary any more and with a helper variable, (address of the sensor) there is only one sensor initialization/reset.
Now, only question 2 is open ...
-
Hi, the workaround of using a static variable is ok but of course would not necessarily work well in any situation but I'm glad you got it working somehow :).
However you're right, this is a known issue in NodeManager. https://github.com/mysensors/NodeManager/issues/176 should tell you why and answer your question #2. The solution unfortunately is not that easy since would require re-thinking the way sensors are mapped to child IDs. Work is in progress though(https://github.com/mysensors/NodeManager/issues/198)
Suggested Topics
-
Sensors db
My Project • 16 Apr 2014, 07:06 • Dvbit 16 Apr 2014, 17:37 -
Compilation error
NodeManager • 19 Sept 2020, 15:41 • htaxil 18 Oct 2020, 09:37 -
SI7021 with Nodemanager
NodeManager • 30 Dec 2020, 14:15 • xlibor 1 Jan 2021, 20:20 -
Help needed with connecting MySensors node to Home Assistant
NodeManager • 16 May 2024, 09:59 • HJ_SK 19 May 2024, 15:01 -
DS18B20 ESP32 nodemanager problem
NodeManager • 13 Sept 2022, 10:59 • A3V 15 Sept 2022, 22:11 -
Nodemanager: How to control a local output from a local input?
NodeManager • 30 Jan 2022, 21:01 • A3V 5 Feb 2022, 16:24