RFM69 with Binary Switch example requires additional code



  • Hi
    I finally managed to try out the MySensors v1.5 library. I mainly was looking for the support of the RFM69 radios because of their better range and low power consumption.
    The serial gateway worked like a charm out of the box. But then I struggled to get the binary switch example working. I mostly got an error 'Radio Init Fail'.
    Looking into the code I also struggled to see where the code says that this should work with an RFM69 radio, like it does in the Serial Gateway code in "MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);"
    So I eventually copied a whole bunch of lines from the Serial Gateway example and now it is working perfectly.

    I may have copied too many lines and perhaps there is a much smarterway of solving this but as a feedback of what I tried and what worked, herewith the code I eventually used in my Binary Switch node:
    /**

    • The MySensors Arduino library handles the wireless radio link and protocol
    • between your home built sensors/actuators and HA controller of choice.
    • The sensors forms a self healing radio network with optional repeaters. Each
    • repeater and gateway builds a routing tables in EEPROM which keeps track of the
    • network topology allowing messages to be routed to nodes.
    • Created by Henrik Ekblad henrik.ekblad@mysensors.org
    • Copyright (C) 2013-2015 Sensnology AB
    • Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    • Documentation: http://www.mysensors.org
    • Support Forum: http://forum.mysensors.org
    • This program is free software; you can redistribute it and/or
    • modify it under the terms of the GNU General Public License
    • version 2 as published by the Free Software Foundation.

    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>

    #define CHILD_ID 3
    #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch

    MyTransportRFM69 transport;

    // Hardware profile
    MyHwATMega328 hw;

    // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
    #ifdef WITH_LEDS_BLINKING
    MySensor gw(transport, hw /, signer/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
    #else
    MySensor gw(transport, hw /, signer/);
    #endif

    Bounce debouncer = Bounce();
    int oldValue=-1;

    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);

    void setup()
    {
    gw.begin(NULL,3);

    // Setup the button
    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);

    // After setting up the button, setup debouncer
    debouncer.attach(BUTTON_PIN);
    debouncer.interval(5);

    // Register binary input sensor to gw (they will be created as child devices)
    // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
    // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
    gw.present(CHILD_ID, S_DOOR);
    }

    // Check if digital input has changed and send in new value
    void loop()
    {
    debouncer.update();
    // Get the update value
    int value = debouncer.read();

    if (value != oldValue) {
    // Send in the new value
    gw.send(msg.set(value==HIGH ? 1 : 0));
    oldValue = value;
    }
    }

    I hope this helps somebody and perhaps somebody wants to advise on how to do this much better.
    Anyhow, Big Thank You to the guys (@KOLAF,@YVEAUX, @HEK and a bunch of others) who made the effort to extend the library to RFM69. Much appreciated.



  • Excellent, it worked


 

256
Online

8.9k
Users

9.7k
Topics

101.3k
Posts