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. Easiest way to enable/disable MySensors on running node?

Easiest way to enable/disable MySensors on running node?

Scheduled Pinned Locked Moved Development
10 Posts 5 Posters 977 Views 5 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.
  • alowhumA Offline
    alowhumA Offline
    alowhum
    Plugin Developer
    wrote on last edited by
    #1

    I have some sensor nodes that connect to the MySensors network. Even as 'stand alone' devices they are still useful, since they also show the sensor values on a little OLED screen.

    Imagine this being a sensor in a teenager's bedroom, and the teenager has the ability and right to always disable the sensor if it wants to.

    To enhance the end user's privacy and general empowerment, I want to offer the option to enable or disable connecting to the MySensors network with a little toggle switch.

    I could create a lot of if (connecting_allowed){ around the send()functions in the script. But perhaps there's an easier way that involves less coding?

    Question 1: is there a quick central way to (temporarily) disable MySensors?

    And what would happen if this is a repeater node? Perhaps nodes with this functionality should never be repeaters? What, in practice, is the effect of a repeater node disappearing form the network? How quickly would the other nodes try to find alternative routes? Is there a period when signals would simply not reach the gateway?

    Question 2: Should the user be dissuaded from making such a toggle-able device a repeater?

    skywatchS 1 Reply Last reply
    0
    • alowhumA alowhum

      I have some sensor nodes that connect to the MySensors network. Even as 'stand alone' devices they are still useful, since they also show the sensor values on a little OLED screen.

      Imagine this being a sensor in a teenager's bedroom, and the teenager has the ability and right to always disable the sensor if it wants to.

      To enhance the end user's privacy and general empowerment, I want to offer the option to enable or disable connecting to the MySensors network with a little toggle switch.

      I could create a lot of if (connecting_allowed){ around the send()functions in the script. But perhaps there's an easier way that involves less coding?

      Question 1: is there a quick central way to (temporarily) disable MySensors?

      And what would happen if this is a repeater node? Perhaps nodes with this functionality should never be repeaters? What, in practice, is the effect of a repeater node disappearing form the network? How quickly would the other nodes try to find alternative routes? Is there a period when signals would simply not reach the gateway?

      Question 2: Should the user be dissuaded from making such a toggle-able device a repeater?

      skywatchS Offline
      skywatchS Offline
      skywatch
      wrote on last edited by skywatch
      #2

      @alowhum As a part of my roller blind project, I have used a window sensor to detect if the window is open or closed.

      Normally this is sent as an advisory so the blinds won't close with the window open (in case it gets windy and shreds the blind).
      But I also use it as an intruder detection sensor which can be active or not depending on the V_ARMED status of the sensor.

      So you could have a button on a node pin (or via any other means to get V_ARMED message to your node) that either 'arms' the send function for local sensors and they send data, or disarms the send function, they don't send data (but still display locally) and a message on the screen updates the armed/disarmed status so the 'teenager' you are holding hostage will know the state. ;)

      This approach will still allow you to use the node as a repeater.

      So you can either,

      • disarm the sensor data being read.
        -disarm the node sending sensor data but still display sensor data locally on oled.
        -disarm sensor data and local display.
      1 Reply Last reply
      0
      • electrikE Offline
        electrikE Offline
        electrik
        wrote on last edited by
        #3

        @alowhum said in Easiest way to enable/disable MySensors on running node?:

        I could create a lot of if (connecting_allowed){ around the send()functions in the script. But perhaps there's an easier way that involves less coding?

        Make a new sendWithPermission() function that is called from the sketch, and check in there if (connecting_allowed)

        1 Reply Last reply
        1
        • franz-unixF Offline
          franz-unixF Offline
          franz-unix
          wrote on last edited by
          #4

          Hi,

          check the MY_TRANSPORT_WAIT_READY_MS, maybe is suitable for you needs.

          I use this directive to start a sketch, even if the MySensors network is not available

          1 Reply Last reply
          0
          • alowhumA Offline
            alowhumA Offline
            alowhum
            Plugin Developer
            wrote on last edited by
            #5

            Thanks everyone.
            @skywatch I get where you're coming from - setting the privacy value from outside - but in this case it will be a physical toggle on the device that decides if it can 'chat'.
            @electrik Creating a function is not a bad idea. Can that be done 'universally'? Or will I have to create a function for each type of variable? What about send functions that currently send strings using F("I am a string")?
            @franz-unix Hmm. I already use that, but only to continue if there's an issue, as you say. If the sketch is already running, it won't allow me to arbitrarily block MySensors functionality?

            franz-unixF electrikE 2 Replies Last reply
            0
            • alowhumA alowhum

              Thanks everyone.
              @skywatch I get where you're coming from - setting the privacy value from outside - but in this case it will be a physical toggle on the device that decides if it can 'chat'.
              @electrik Creating a function is not a bad idea. Can that be done 'universally'? Or will I have to create a function for each type of variable? What about send functions that currently send strings using F("I am a string")?
              @franz-unix Hmm. I already use that, but only to continue if there's an issue, as you say. If the sketch is already running, it won't allow me to arbitrarily block MySensors functionality?

              franz-unixF Offline
              franz-unixF Offline
              franz-unix
              wrote on last edited by franz-unix
              #6

              @alowhum No of course the MY_TRANSPORT_WAIT_READY_MS is not sufficient to achieve your goal, you have to tweak your code. The idea of @electrik is a good one.

              I have faced a similar problem with an MQ2 gas sensor that implements a visual (LED) and acoustic (Buzzer) alarm when a gas leak is detected. The visual and sound alarms, that can work also in absence of the MySensors network, can be activated or deactivated with a physical button on the node or also in the controller with two dedicated switches (S_BINARY, V_STATUS).

              The code is here.

              One interesting option that you can consider is that if you define a constant at the beginning of your code like for example

              #define PRIVACY_MODE
              

              and the you wrap all of your privacy related code inside an #ifdef statement

              #ifdef PRIVACY_MODE
              sendWithPermission();
              #endif
              #ifndef PRIVACY_MODE
              send();
              #endif
              

              the compiler will compile only the relevant part of the code, saving some space of your MCU memory.
              This allows also you the easily disable and enable the functionality with a firmware flash.

              You can also save the privacy state to EEPROM if you want to keep your setting across power cycle.

              1 Reply Last reply
              0
              • skywatchS Offline
                skywatchS Offline
                skywatch
                wrote on last edited by
                #7

                @alowhum Am I missing something here?
                What would be wrong with a set up like........

                1.toggle switch connects to pin x
                2.collect all data from sensors into variables.
                3.decide if to send data or not...
                if(digitalRead(x) == LOW){
                Send (msg1.set(sensor));
                Send (msg2.set(sensor));
                etc....}
                else{
                display on screen an icon or message to say sending data disabled.....
                }

                1 Reply Last reply
                0
                • alowhumA alowhum

                  Thanks everyone.
                  @skywatch I get where you're coming from - setting the privacy value from outside - but in this case it will be a physical toggle on the device that decides if it can 'chat'.
                  @electrik Creating a function is not a bad idea. Can that be done 'universally'? Or will I have to create a function for each type of variable? What about send functions that currently send strings using F("I am a string")?
                  @franz-unix Hmm. I already use that, but only to continue if there's an issue, as you say. If the sketch is already running, it won't allow me to arbitrarily block MySensors functionality?

                  electrikE Offline
                  electrikE Offline
                  electrik
                  wrote on last edited by
                  #8

                  @alowhum
                  I use a similar function like this

                  sendWithPermission(msgHum.set(humidity, 1));
                  
                  boolean sendWithPermission(MyMessage &msg)
                  {
                  // Check permission and send here
                  }
                  
                  1 Reply Last reply
                  0
                  • alowhumA Offline
                    alowhumA Offline
                    alowhum
                    Plugin Developer
                    wrote on last edited by
                    #9

                    @electrik Could you perhaps share the full code inside that function too? It sounds like a good idea.

                    @skywatch The reason is I have a lot of sketches so a find/replace type solution would be great. I also want to avoid code replication to keep the sketches small.

                    F 1 Reply Last reply
                    0
                    • alowhumA alowhum

                      @electrik Could you perhaps share the full code inside that function too? It sounds like a good idea.

                      @skywatch The reason is I have a lot of sketches so a find/replace type solution would be great. I also want to avoid code replication to keep the sketches small.

                      F Offline
                      F Offline
                      FlyingDomotic
                      wrote on last edited by
                      #10

                      @alowhum: Perhaps something like

                      boolean sendWithPermission(MyMessage &msg)
                      {
                        // Check permission and send here
                        if (connecting_allowed){
                          send(msg);
                        }
                      }```
                      1 Reply Last reply
                      1
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      16

                      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