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. API, Documentation and examples

API, Documentation and examples

Scheduled Pinned Locked Moved Development
11 Posts 6 Posters 3.1k 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.
  • marceltrapmanM Offline
    marceltrapmanM Offline
    marceltrapman
    Mod
    wrote on last edited by
    #1

    While moving my sketches from 1.5 to 2.2 I noticed that most examples do not really follow the same logic.

    I sometimes have a hard time to understand how and why things are done, not only because of the above but also because there seems to be no agreement on conventions.

    I understand why this is but for people with less programmer experience than I have (and mine is 'only' Java, Python, Xojo, SQL etc but not C++) it must be hard to interpret all examples.

    On question I have at the moment is the following:

    I see that there a some methods I can use:

    // Before radio initialization
    void preHwInit();
    
    // Before node initialization
    void before();
    
    // While node initialization
    void presentation();
    
    // Setup?
    void setup();
    
    // Running
    void loop();
    
    // Receive messages
    void receive( const MyMessage &message );
    

    What I would like to understand is the difference between presentation and setup because both are used.

    Fulltime Servoy Developer
    Parttime Moderator MySensors board

    I use Domoticz as controller for Z-Wave and MySensors (previously Indigo and OpenHAB).
    I have a FABtotum to print cases.

    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      We added presentation() to allow controller to re-request presentation from a node during runtime. Should contain all present()-statements.

      setup() is a good place to initialise one-time only things like pin settings.

      marceltrapmanM 1 Reply Last reply
      0
      • hekH hek

        We added presentation() to allow controller to re-request presentation from a node during runtime. Should contain all present()-statements.

        setup() is a good place to initialise one-time only things like pin settings.

        marceltrapmanM Offline
        marceltrapmanM Offline
        marceltrapman
        Mod
        wrote on last edited by
        #3

        @hek Hi Henrik, that is exactly why I ask.

        When I take the RelayActuator for example I see that the setup/initialise stuff is happening in the before method.

        Or did I find an exception (I have not checked all sketches)?

        Fulltime Servoy Developer
        Parttime Moderator MySensors board

        I use Domoticz as controller for Z-Wave and MySensors (previously Indigo and OpenHAB).
        I have a FABtotum to print cases.

        1 Reply Last reply
        1
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          Yes, that seem to be an exception. Not sure why someone (me?) put it in before().

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

            Kind of off topic but maybe can save somebody's else time: presentation() is called before setup(). For some unknown reasons I was convinced setup() was called first due to its name and it took me a while to find this out even if in all the examples the order is correct. So if there is any need to do something which will be used during presentation(), this has to go into before().

            rejoe2R 1 Reply Last reply
            1
            • U user2684

              Kind of off topic but maybe can save somebody's else time: presentation() is called before setup(). For some unknown reasons I was convinced setup() was called first due to its name and it took me a while to find this out even if in all the examples the order is correct. So if there is any need to do something which will be used during presentation(), this has to go into before().

              rejoe2R Offline
              rejoe2R Offline
              rejoe2
              wrote on last edited by
              #6

              @user2684 The order of the calls presentation() and setup() have been changed somewhere between 2.1.0 and 2.1.1 . This was when I first noticed the before()-call.

              I used this for correct initialisation of a second SPI-device (resistor) sharing all the PINS with the nRF. Now I am wondering, whether it is better to stick to this procedure or better move this part to preHwInit(). Can someone explain the "right way" to deal with this kind of hardware-setup?

              Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

              marceltrapmanM 1 Reply Last reply
              0
              • rejoe2R rejoe2

                @user2684 The order of the calls presentation() and setup() have been changed somewhere between 2.1.0 and 2.1.1 . This was when I first noticed the before()-call.

                I used this for correct initialisation of a second SPI-device (resistor) sharing all the PINS with the nRF. Now I am wondering, whether it is better to stick to this procedure or better move this part to preHwInit(). Can someone explain the "right way" to deal with this kind of hardware-setup?

                marceltrapmanM Offline
                marceltrapmanM Offline
                marceltrapman
                Mod
                wrote on last edited by
                #7

                @rejoe2 I second your question.
                Maybe it is good to have a good explanation of what to do when.
                I have the order correct in my original post I believe.
                But especially the setup method confuses me...

                Fulltime Servoy Developer
                Parttime Moderator MySensors board

                I use Domoticz as controller for Z-Wave and MySensors (previously Indigo and OpenHAB).
                I have a FABtotum to print cases.

                rejoe2R 1 Reply Last reply
                0
                • marceltrapmanM marceltrapman

                  @rejoe2 I second your question.
                  Maybe it is good to have a good explanation of what to do when.
                  I have the order correct in my original post I believe.
                  But especially the setup method confuses me...

                  rejoe2R Offline
                  rejoe2R Offline
                  rejoe2
                  wrote on last edited by
                  #8

                  @marceltrapman setup() I found to be pretty self-explanating: I came across this wrt some DS18B20-sketches using more than one of these on one 1-wire-bus: I just sent the Dallas-Addresses of them als "ID" once when the node was starting. Before, this had to be placed in the loop() with an additional marker, if this was already send.
                  So the controller could check, if all of the chips where reported under the same ChildID. This could change using the "normal" skech in case of additional or less sensors on the bus.

                  Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

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

                    @user2684 said:

                    Kind of off topic but maybe can save somebody's else time: presentation() is called before setup()

                    @rejoe2 said:

                    The order of the calls presentation() and setup() have been changed somewhere between 2.1.0 and 2.1.1

                    What is the current order of the calls?

                    And is there a downside to putting setup things in the presentation function? As I'm looping over nodes I'd like to also do some other things while I'm at it.

                    rejoe2R mfalkviddM 2 Replies Last reply
                    0
                    • alowhumA alowhum

                      @user2684 said:

                      Kind of off topic but maybe can save somebody's else time: presentation() is called before setup()

                      @rejoe2 said:

                      The order of the calls presentation() and setup() have been changed somewhere between 2.1.0 and 2.1.1

                      What is the current order of the calls?

                      And is there a downside to putting setup things in the presentation function? As I'm looping over nodes I'd like to also do some other things while I'm at it.

                      rejoe2R Offline
                      rejoe2R Offline
                      rejoe2
                      wrote on last edited by
                      #10

                      @alowhum AFAIK, now the order of execution is preHwInit(), before(), presentation() and setup(), then loop().
                      As you may call the presentation function to be redone from controller side you should decide whether this is desired or not; depends on your needs imo.

                      Personally, I prefer having all kind of controller-independent initialisation in before() (especially turning relays off/desired state and so on; this allows also to use additional SPI stuff on hardware SPI PINs), put all controller-communication stuff in presentation() and the other things in setup(). For e.g. asking acutal values of counters setup() might be a good choice, as one typically want to do that only once after node has started.

                      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                      1 Reply Last reply
                      2
                      • alowhumA alowhum

                        @user2684 said:

                        Kind of off topic but maybe can save somebody's else time: presentation() is called before setup()

                        @rejoe2 said:

                        The order of the calls presentation() and setup() have been changed somewhere between 2.1.0 and 2.1.1

                        What is the current order of the calls?

                        And is there a downside to putting setup things in the presentation function? As I'm looping over nodes I'd like to also do some other things while I'm at it.

                        mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by
                        #11

                        @alowhum MySensors allows customization, which unfortunately makes it very hard to describe the order. An attempt has been made in https://github.com/mysensors/MySensors/issues/927 but we have not found a clear way to document it.

                        1 Reply Last reply
                        1
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        19

                        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