Migrating to MySensors 2.0



  • Dear MySensors Devs,

    I already have a basic home automation setup with MySensors 1.5-6. Now I decided to give a try and update my nodes to run MySensors 2.0, but Im facing challenges i cant overcome at the moment.
    More or less its related to my low experience with C++ and Arduino build. I hope this will be easy for you.

    The main problem is, i implemented some classes to separate responsibilities. Few of them are depending on MyMessage and one depends on MyGateway. Since 2.0 these classes seems to be not available for inclusion from the .ino and other .h/.cpp files.

    Is there any workaround for this? (basically i have no reference to MySensor's gateway object, none of them can be included)
    Another way will be to hide all MySensors functionality behind an interface, implemented in the main .ino file, passing calls to mySensors. I'm about to make this change to make the MySensors dependency somewhat weaker, but would be nice to refactor this after i have a working state.

    One of my classes in the example: RadioMirror's constructor:
    RadioMirror(MySensor *gw, OutputState state, byte outputCount, const byte radioIds);
    , where i cant pass a gw object anymore, because its hidden somewhere (or include MyMessage.h anymore).

    Thank you in advance, You created an awesome library anyway 🙂
    BR,
    marcell


  • Admin

    I don't think you need to pass gw object any more. Methods like send/request is available in the global scope.

    You might need to declare them extern so the compiler won't complain.



  • @hek said:

    You might need to declare them extern so the compiler won't complain.

    This IS the solution. Thank you for this. To be honest i never used (or knew) extern keyword exists. As a Java-dev, i see this against I believe in : )

    Thank you! You made me see the light in the tunnel. (I'm still in the hope its not the train : )

    To share the actual solution:
    In the class, where I was using MyGateway *gw before, now I have this (in the .cpp file):
    extern bool send(MyMessage &message, bool enableAck)
    ...and i replaced gw->send(..) with send(..)

    The imports for the MyMessage class had to be changed to core/MyMessage.h.
    I'm using visual micro + visual studio for this development.


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 1
  • 6
  • 2

12
Online

11.4k
Users

11.1k
Topics

112.7k
Posts