Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. NodeManager
  4. How can I set parameter if there are multible instances of the sensor class?

How can I set parameter if there are multible instances of the sensor class?

Scheduled Pinned Locked Moved NodeManager
3 Posts 2 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    betonmoewe
    wrote on last edited by
    #1

    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)

    B 1 Reply Last reply
    0
    • B betonmoewe

      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)

      B Offline
      B Offline
      betonmoewe
      wrote on last edited by betonmoewe
      #2

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

      1 Reply Last reply
      0
      • U Offline
        U Offline
        user2684
        Contest Winner
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        18

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular