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. NodeManager Motion Sensor: how to use the SensorSwitch class?

NodeManager Motion Sensor: how to use the SensorSwitch class?

Scheduled Pinned Locked Moved NodeManager
17 Posts 5 Posters 4.5k Views 6 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.
  • I Offline
    I Offline
    iahim67
    wrote on last edited by
    #1

    Hi,

    When using the Node Manager for a Motion Sensor, I read the default interrupt mode is "CHANGE" (see that in NodeManager.h).
    I would like it to replace with "RISING" and I can see it could be in the SensorSwitch class, I just don't know how to code this.
    I took the NodeManager "Motion Sensor" example and tried to add "SensorSwitch.setMode(1);" in the before() routine but I'll get a compilation error of course as I didn't code that the right way.
    Can someone please teach me how to make it right?
    This is my code so far:

    /*
      NodeManager is intended to take care on your behalf of all those common tasks a MySensors node has to accomplish, speeding up the development cycle of your projects.
    
      NodeManager includes the following main components:
      - Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
      - Power manager: allows powering on your sensors only while the node is awake
      - Battery manager: provides common functionalities to read and report the battery level
      - Remote configuration: allows configuring remotely the node without the need to have physical access to it
      - Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
    
      Documentation available on: https://github.com/mysensors/NodeManager
    */
    
    
    // load user settings
    #include "config.h"
    // load MySensors library
    #include <MySensors.h>
    // load NodeManager library
    #include "NodeManager.h"
    
    // create a NodeManager instance
    NodeManager nodeManager;
    
    // before
    void before() {
      // setup the serial port baud rate
      Serial.begin(MY_BAUD_RATE);
      /*
         Register below your sensors
      */
      SensorSwitch.setMode(1);
    
      nodeManager.setBatteryMin(1.8);
      nodeManager.setBatteryMax(5.2);
      nodeManager.setSleep(SLEEP, 1, MINUTES);
      nodeManager.registerSensor(SENSOR_MOTION, 3);
    
      /*
         Register above your sensors
      */
      nodeManager.before();
    }
    
    // presentation
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      // call NodeManager presentation routine
      nodeManager.presentation();
    
    }
    
    // setup
    void setup() {
      // call NodeManager setup routine
      nodeManager.setup();
    }
    
    // loop
    void loop() {
      // call NodeManager loop routine
      nodeManager.loop();
    
    }
    
    // receive
    void receive(const MyMessage &message) {
      // call NodeManager receive routine
      nodeManager.receive(message);
    }```
    1 Reply Last reply
    0
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #2

      You don't want to report when pir sensors resets to "no motion"?

      1 Reply Last reply
      0
      • I Offline
        I Offline
        iahim67
        wrote on last edited by
        #3

        I'm not sure about that, what I really want is to learn how to use NodeManager.
        Like how can I make such changes as described.
        I want to experiment a bit and don't know how :simple_smile:

        1 Reply Last reply
        0
        • gohanG Offline
          gohanG Offline
          gohan
          Mod
          wrote on last edited by
          #4

          Node manager is made to automate the most common tasks and the pir sensor normally needs to report both status changes, so if you need to experiment you'd probably need to write some code yourself ☺️

          1 Reply Last reply
          0
          • I Offline
            I Offline
            iahim67
            wrote on last edited by
            #5

            You're absolutely right :simple_smile:
            I am experimenting with mysensors as much as I can. My motion sensor works fine without NodeManager ... but I'm interested in NodeManager too.
            Back to my question however, how can solve my issue?

            1 Reply Last reply
            0
            • gohanG Offline
              gohanG Offline
              gohan
              Mod
              wrote on last edited by
              #6

              Only author can answer that 😀

              1 Reply Last reply
              0
              • I Offline
                I Offline
                iahim67
                wrote on last edited by
                #7

                That fine ... I just don't know who's the author, I guess I have to solve this issue first :smile: , or I get lucky and he'll read my post!

                1 Reply Last reply
                0
                • gohanG Offline
                  gohanG Offline
                  gohan
                  Mod
                  wrote on last edited by
                  #8

                  @user2684 is the guy

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

                    Sorry for the delay guys, for some reasons I haven't got the notification of this thread, thanks @gohan for pulling me in! When using SENSOR_MOTION, the default mode is already RISING. To help you reading through the code, the registerSensor() in NodeManager.cpp would create an instance of the SensorMotion class. SensorMotion is derived from SensorSwitch (which has CHANGE has default mode) but in its constructor (SensorMotion::SensorMotion) you will find a setMode(RISING) which is then the default value.

                    Whatever parameter you want to change, this requires three steps:

                    • registering the sensor
                    • retrieving the instance of the class
                    • invoking its functions

                    SensorSwitch in your example above is a class, you need the instantiated object to invoke its member functions. So something like the following:

                    // register the sensor and keep track of its id
                    int sensorPIR = nodeManager.registerSensor(SENSOR_MOTION,3);
                    // retrieve the instance of the object. Since getSensor() will return a generic Sensor class, you need to cast it accordingly
                    SensorMotion* sensorMotion = (SensorMotion*)nodeManager.getSensor(sensorPIR_Id);
                    // invoke whatever function you need. Since sensorMotion is a pointer, you need to use the -> notation
                    sensorMotion->setMode(CHANGE);
                    sensorMotion->setInitial(LOW);
                    

                    Does it make sense now?
                    Thanks

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      iahim67
                      wrote on last edited by
                      #10

                      Thank you very much sir, it start making sense to me, I still need to "digest" this :smile: as I am a HW engineer ... but trying to improve my SW skills.
                      I am comfortable with the basics of C and Arduino but not really with object oriented programming.
                      What literature would you suggest me to start with to understand this kind of coding? Java perhaps?

                      gohanG 1 Reply Last reply
                      0
                      • I iahim67

                        Thank you very much sir, it start making sense to me, I still need to "digest" this :smile: as I am a HW engineer ... but trying to improve my SW skills.
                        I am comfortable with the basics of C and Arduino but not really with object oriented programming.
                        What literature would you suggest me to start with to understand this kind of coding? Java perhaps?

                        gohanG Offline
                        gohanG Offline
                        gohan
                        Mod
                        wrote on last edited by
                        #11

                        @iahim67 c++? 😁

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          iahim67
                          wrote on last edited by
                          #12

                          I thought you may say that :smile: ... is there a good C++ book for beginners that you would recommend?
                          On paper I mean, that I can buy?

                          TerrenceT 1 Reply Last reply
                          0
                          • gohanG Offline
                            gohanG Offline
                            gohan
                            Mod
                            wrote on last edited by
                            #13

                            I could sell you mine, it is still brand new but it is in Italian 😁

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

                              Agree starting from c++ would make more sense :-) Just a silly personal advise: pay attention not to get lost into the tons of capabilities c++ can provide, especially if you want to be just focused on arduino to start with since you can easily get lost. Sometimes I personally prefer just an electronic one-pager with a good amount of examples :-)

                              1 Reply Last reply
                              0
                              • I iahim67

                                I thought you may say that :smile: ... is there a good C++ book for beginners that you would recommend?
                                On paper I mean, that I can buy?

                                TerrenceT Offline
                                TerrenceT Offline
                                Terrence
                                wrote on last edited by
                                #15

                                @iahim67 Simon Monk's Programming Arduino: Getting Started... book is pretty good.

                                Look at the table of contents.

                                https://www.amazon.com/Programming-Arduino-Getting-Started-Sketches/dp/1259641635/

                                1 Reply Last reply
                                0
                                • I Offline
                                  I Offline
                                  iahim67
                                  wrote on last edited by
                                  #16

                                  Thanks for your help, I'll start with Simon Monk's Programming Arduino :smile: !

                                  1 Reply Last reply
                                  0
                                  • JoeyGJ Offline
                                    JoeyGJ Offline
                                    JoeyG
                                    wrote on last edited by
                                    #17
                                    This post is deleted!
                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    22

                                    Online

                                    11.7k

                                    Users

                                    11.2k

                                    Topics

                                    113.1k

                                    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