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)


    Log in to reply
     


  • 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 ...


  • Contest Winner

    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)


Log in to reply
 

1 out of 3

Suggested Topics


  • My Project •   16 Apr 2014, 17:37

    2

  • NodeManager •   18 Oct 2020, 09:37

    2

  • NodeManager •   1 Jan 2021, 20:20

    2

  • NodeManager •   19 May 2024, 15:01

    4

  • NodeManager •   15 Sept 2022, 22:11

    2

  • NodeManager •   5 Feb 2022, 16:24

    2

0
Online

11.5k
Users

11.1k
Topics

112.8k
Posts