Easiest way to enable/disable MySensors on running node?


  • Plugin Developer

    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?



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


  • @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)



  • 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


  • Plugin Developer

    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?



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



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



  • @alowhum
    I use a similar function like this

    sendWithPermission(msgHum.set(humidity, 1));
    
    boolean sendWithPermission(MyMessage &msg)
    {
    // Check permission and send here
    }
    

  • Plugin Developer

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



  • @alowhum: Perhaps something like

    boolean sendWithPermission(MyMessage &msg)
    {
      // Check permission and send here
      if (connecting_allowed){
        send(msg);
      }
    }```

Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 6
  • 2
  • 1
  • 3

17
Online

11.4k
Users

11.1k
Topics

112.7k
Posts