MySensors API ver 1.6.1: MQTTClientGateway - RF69 - Arduino Uno - W5100 Shield

  • Hello to all!
    I've moved my structure to the new API version 1.6.1 succesfully. Then I've recompiled the MQTT Gateway with my NRF24L01+ to use the MQTTClientGateway and send the messages to a mosquitto server. Until here all works well.
    Now I would like to add a second radio network because seems (AFAYK) the RF69 has a better range. I'm starting to setup the MQTT Client Gateway but I'm getting always "check wires". Maybe the MQTT Client Gateway is not supported with the RF69?
    Let's start with my hardware setup:

    • Arduino Uno R3
    • W5100 Shield
    • HopeRF RFM69W 868Mhz

    I've connected the radio as follow:

    HopeRF RFM69W 868Mhz ----> Arduino W5100 Shield
    3.3V -> 3.3V
    Groud -> Ground
    DI00 -> Digital 2
    NSS -> Digital 6
    MISO -> A2
    MOSI -> A1
    SCK -> A0

    Then, into MyConfig.h I've set:

    #define MY_SOFTSPI

    Here both files:

    #include <SPI.h>
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    // Set this nodes subscripe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway2-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway2-in"
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-2"
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4  
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with 
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #define MY_RF24_CE_PIN 5
    #define MY_RF24_CS_PIN 6
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,1,52
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    // MQTT broker ip address.  
    #define MY_CONTROLLER_IP_ADDRESS 192,168,1,50
    // The MQTT broker port to to open 
    #define MY_PORT 1883      
    // Flash leds on rx/tx/err
    // Set blinking period
    // Enable inclusion mode
    // Enable Inclusion mode button on gateway
    // Set inclusion mode duration (in seconds)
    // Digital pin used for inclusion mode button
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    #include <Ethernet.h>
    #include <MySensor.h>
    void setup() { 
    void presentation() {
      // Present locally attached sensors here    
    void loop() {
      // Send locally attech sensors data here


     * 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 <>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list:
     * Documentation:
     * Support Forum:
     * 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.
     * @file MyConfig.h
     * MySensors specific configurations
    #ifndef MyConfig_h
    #define MyConfig_h
    #include <stdint.h>
    *  Serial and debug options
    // Enables this in sketch to show debug prints. This option will add a lot to the size of the
    // final sketch but is helpful to see what is actually is happening during development
    //#define MY_DEBUG
    // Enable MY_DEBUG_VERBOSE flag for verbose debug prints. Requires DEBUG to be enabled.
    // This will add even more to the size of the final sketch!
    //#define MY_DEBUG_VERBOSE
    // Enable this in sketch if you want to use TX(1), RX(0) as normal I/O pin
    //#define MY_DISABLED_SERIAL
    // Turn off debug if serial pins is used for other stuff
    #undef MY_DEBUG
    // Serial output baud rate (debug prints and serial gateway speed)
    #ifndef MY_BAUD_RATE
    #define MY_BAUD_RATE 115200
    // Disables over-the-air reset of node
    *  Radio selection and node config
    // Selecting uplink transport layer is optional (for a gateway node).
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    // Node id defaults to AUTO (tries to fetch id from controller)
    #ifndef MY_NODE_ID
    #define MY_NODE_ID AUTO
    // Node parent defaults to AUTO (tries to find a parent automatically)
    #ifndef MY_PARENT_NODE_ID
    // Enables repeater functionality (relays messages from other nodes)
    // #define MY_REPEATER_FEATURE
    // The wait period before going to sleep when using smartSleep-functions
    // This period has to be long enough for controller to be able to send out
    // potential buffered messages.
    *  Over the air firmware updates
    // Enable MY_OTA_FIRMWARE_FEATURE in sketch to allow safe over-the-air firmware updates.
    // This feature requires external flash and the DualOptiBoot boot-loader.
    // Note: You can still have OTA FW updates without external flash but it
    // requires the MYSBootloader and disabled MY_OTA_FIRMWARE_FEATURE
    // Slave select pin for external flash
    #ifndef MY_OTA_FLASH_SS
    #define MY_OTA_FLASH_SS 8
    // Flash jdecid
    #define MY_OTA_FLASH_JDECID 0x1F65
    *  Gateway config
    // Max buffersize needed for messages coming from controller
    // Max buffer size when sending messages
    // Max number of parallel clients (sever mode)
    *  Information LEDs blinking
    // This feature enables LEDs blinking on message receive, transmit
    // or if some error occurred. This was commonly used only in gateways,
    // but now can be used in any sensor node. Also the LEDs can now be
    // disabled in the gateway.
    // The following setting allows you to inverse the blinking feature MY_LEDS_BLINKING_FEATURE
    // When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
    // off when blinking
    // default LEDs blinking period in milliseconds
    // The RX LED default pin
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_DEFAULT_RX_LED_PIN 8
    		#define MY_DEFAULT_RX_LED_PIN 6
    // The TX LED default pin
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_DEFAULT_TX_LED_PIN 9
    		#define MY_DEFAULT_TX_LED_PIN 5
    // The Error LED default pin
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_DEFAULT_ERR_LED_PIN 7
    		#define MY_DEFAULT_ERR_LED_PIN 4
    *  Gateway inclusion button/mode configuration
    // Enabled inclusion mode feature
    // Enables inclusion-mode button feature on the gateway device
    // Disable inclusion mode button if inclusion mode feature is not enabled
    // The default input pin used for the inclusion mode button
    	#if defined(ARDUINO_ARCH_ESP8266)
    // Number of seconds (default one minute) inclusion mode should be enabled
    *  Message Signing Settings
     * @def MY_SIGNING_ATSHA204
     * @brief Enables HW backed signing functionality in library.
     * For any signing related functionality to be included, this define or @ref MY_SIGNING_SOFT has to be enabled.
    //#define MY_SIGNING_ATSHA204
     * @def MY_SIGNING_SOFT
     * @brief Enables SW backed signing functionality in library.
     * For any signing related functionality to be included, this define or @ref MY_SIGNING_ATSHA204 has to be enabled.
    //#define MY_SIGNING_SOFT
     * @brief Enable this to inform gateway to sign all messages sent to this node.
     * If used for a gateway, gateway will only request signatures from nodes that in turn
     * request signatures from gateway.
     * @brief Define a suitable timeout for a signature verification session
     * Consider the turnaround from a nonce being generated to a signed message being received
     * which might vary, especially in networks with many hops. 5s ought to be enough for anyone.
     * @brief Enable to turn on whitelisting
     * When enabled, a signing node will salt the signature with it's unique signature and nodeId.<br>
     * The verifying node will look up the sender in a local table of trusted nodes and
     * do the corresponding salting in order to verify the signature.<br>
     * For this reason, if whitelisting is enabled on one of the nodes in a sign-verify pair, both
     * nodes have to implement whitelisting for this to work.<br>
     * Note that a node can still transmit a non-salted message (i.e. have whitelisting disabled)
     * to a node that has whitelisting enabled (assuming the receiver does not have a matching entry
     * for the sender in it's whitelist). The whitelist to use is defined as the value of the flag.
    //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
     * @def MY_SIGNING_ATSHA204_PIN
     * @brief Atsha204 default pin setting
     * Pin where ATSHA204 is attached
    #ifndef MY_SIGNING_ATSHA204_PIN
    #define MY_SIGNING_ATSHA204_PIN 17
     * @brief Pin used for random generation in soft signing
     * Do not connect anything to this when soft signing is enabled
     * @brief Serial number for SW signing enabled node
     * Set the soft_serial value to an arbitrary value for proper security.
     * It should be random and unique for each node.
    #define MY_SIGNING_SOFT_SERIAL 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09
     * @brief Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes)
    #define MY_SIGNING_SOFT_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    *  RS485 Driver Defaults
    #ifndef MY_RS485_BAUD_RATE
    #define MY_RS485_BAUD_RATE 9600
    #define MY_RS485_MAX_MESSAGE_LENGTH 40
    *  NRF24L01 Driver Defaults
    // Enables RF24 encryption (all nodes and gateway must have this enabled)
    // Default encryption key. Override in sketch if needed.
    #ifndef MY_RF24_ENCRYPTKEY
    #define MY_RF24_ENCRYPTKEY 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16
    // Default pin settings. Override in sketch if needed.
    #ifndef MY_RF24_CE_PIN
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_RF24_CE_PIN 4
    	#elif defined(ARDUINO_ARCH_SAMD)
    		#define MY_RF24_CE_PIN 27
    		#define MY_RF24_CE_PIN 9
    #ifndef MY_RF24_CS_PIN
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_RF24_CS_PIN 15
    	#elif defined(ARDUINO_ARCH_SAMD)
    		#define MY_RF24_CS_PIN 3
    		#define MY_RF24_CS_PIN 10
    #ifndef MY_RF24_PA_LEVEL
    #define MY_RF24_PA_LEVEL RF24_PA_MAX
    // RF channel for the sensor net, 0-127
    #ifndef MY_RF24_CHANNEL
    #define MY_RF24_CHANNEL	76
    //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
    #ifndef MY_RF24_DATARATE
    #define MY_RF24_DATARATE RF24_250KBPS
    // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
    #ifndef MY_RF24_BASE_RADIO_ID
    #define MY_RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL)
    // Enable SOFTSPI for NRF24L01, useful for the W5100 Ethernet module
    #define MY_SOFTSPI
    #ifndef MY_SOFT_SPI_SCK_PIN
    #define MY_SOFT_SPI_SCK_PIN 14
    #ifndef MY_SOFT_SPI_MISO_PIN
    #define MY_SOFT_SPI_MISO_PIN 16
    #ifndef MY_SOFT_SPI_MOSI_PIN
    #define MY_SOFT_SPI_MOSI_PIN 15
    *  RFM69 Driver Defaults
    // Default frequency to use. This must match the hardware version of the RFM69 radio (uncomment one):
    #ifndef MY_RFM69_FREQUENCY
    // #define MY_RFM69_FREQUENCY   RF69_433MHZ
    #define MY_RFM69_FREQUENCY   RF69_868MHZ
    //#define MY_RFM69_FREQUENCY     RF69_915MHZ
    // Enable this if you're running the RFM69HW model
    #ifdef MY_IS_RFM69HW
    	#define MY_RFM69HW true
    	#define MY_RFM69HW false
    // Default network id. Use the same for all nodes that will talk to each other
    #ifndef MY_RFM69_NETWORKID
    #define MY_RFM69_NETWORKID     100
    #ifndef MY_RF69_IRQ_PIN
    #define MY_RF69_IRQ_PIN RF69_IRQ_PIN
    #ifndef MY_RF69_SPI_CS
    #define MY_RF69_SPI_CS RF69_SPI_CS
    #ifndef MY_RF69_IRQ_NUM
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
    		#define MY_RF69_IRQ_NUM RF69_IRQ_NUM
    // Enable this for encryption of packets
    #ifndef MY_RFM69_ENCRYPTKEY
    #define MY_RFM69_ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
    * Ethernet Gateway Transport  Defaults
    // The gateway options available
    //#define MY_GATEWAY_W5100
    //#define MY_GATEWAY_ENC28J60
    //#define MY_GATEWAY_ESP8266
    // The port to open on controller or gateway
    #ifndef MY_PORT
    #define MY_PORT 5003
    // Static ip address of gateway (if this is disabled, DHCP will be used)
    //#define MY_IP_ADDRESS 192,168,178,66
    // Enables UDP mode for Ethernet gateway (W5100)
    //#define MY_USE_UDP
    // DHCP, default renewal setting
    #define MY_IP_RENEWAL_INTERVAL 60000
    #ifndef MY_MAC_ADDRESS
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    // Controller ip-address, if this is defined, gateway will act as a client trying to contact controller on MY_PORT.
    // If MY_CONTROLLER_IP_ADDRESS is left un-defined, gateway acts as server allowing incoming connections.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    // Doxygen specific constructs, not included when built normally
    // This is used to enable disabled macros/definitions to be included in the documentation as well.
    #if DOXYGEN
    #define MY_SIGNING_ATSHA204
    #define MY_SIGNING_SOFT
    #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}

    If I try to start the node:

    0;255;3;0;9;Starting gateway (RRNGA-, 1.6.0-beta)
    0;255;3;0;9;Radio init failed. Check wiring.

    Any idea or help?



  • Plugin Developer



    NSS, MOSI and SCK on the RFM69 are not 5 V tolerant. Are you using a logic level converter?

  • Hardware Contributor

    hi. I'm not using softspi on my side. but as I'm understanding this you're connecting rfm69 and w5100 on softspi together.
    I guess you should have your rfm69 on regular hardware spi pins, and the w5100 on softspi (or vice versa).
    And then be careful like said above, rfm69 is not 5v tolerant and UNO pins are 5v if i remember right (I have no uno ..). You have to use a logic level converter for spi pins (to convert 5v uno signals to 3v rfm69 etc..).

  • @martinhjelmare
    Hi, well. I'm not so proof with that at all. Feeding it with 3.3V I was thinking it's enough. Isn't the same as for the NRF24L01+. It has it own 3.3V pin on the shield. I've an Arduino Diemilanove with W5100 for the NRF24L01+ as MQTTClientGateway and it works great.

    Hi! For the 5v question see above.
    For the pins, could you give me some pratical code hints based on the above sketch I've posted?

    Thanks to all!


  • Hardware Contributor

    you have connected radio and ethernet together on same spi bus. in theory, you could do but you wouldn't need softspi in this case 😉 actually (I don't know if it's fixed), you can't do this when using w5100.
    Here connection is explained
    for pin configuration then, look at myconfig.h
    but I don't use softspi with my rfm69 so I can't tell you. I would prefer use a board with two hardware spi bus like tbowmo GW for instance (I'm using an usb gw, and another one wifi esp8266 for the moment)

  • Hi @scalz again 🙂
    I've found this that could help to use SOFTSPI ( but seems related to API 1.5 and I'm using 1.6 and it doesn't have the MQTTClient version.
    I'm still in big doubt on WHY I have to use SOFTSPI. AFAYK it's 'cause it shares SPI and one of them needs to use software emulation.
    If so, isn't enough if W5100 uses SOFT? But being a shield it's connected to the SPI port directly so the radio must be set to SOFT-SPI?

    For the logic level converter it's something like that?
    (IIC I2C level converter module, 5-3v system compatible, arduino sensor module)
    Could I have damaged the radio without the level converter?

    I would like to prevent buying more components and find out that I cannot reach the needed goal.

    Any suggestion to create the MQTTClientGateway with the aboce hardware?

    I'm using Openhab as Controller. Any other alternative could be apreciated.
    I should have a Arduino Pro Mini 3.3V (so it doesn't require level converter) and could use the SerialGateway connecting it directly to the Raspberry Openhab?



  • Hi again to all!
    Noone has suggestions or answers for what asked above?
    I would have a ENC28J60 network controller. Would this help in solving the issue in any way?
    Main goal: MQTTGatewayClient. Alternatives are accepted as well 👍

  • Plugin Developer


    For the Uno you have to use a logic level converter to connect the RFM69. If you use a Pro Mini 3.3 V you don't need a logic converter but you need to be able to decrease the baudrate at the controller for the serial connection to work, if using that gateway type.

    Regarding ethernet gateway and SPI, I suggest you follow the build guide. I don't recommend the ENC module as it's notoriously hard to get working together with mysensors.

  • @martinhjelmare said:


    For the Uno you have to use a logic level converter to connect the RFM69.

    Ok, I'll order one. My big doubt is if I can then use the radio RFM69 + the W5100 for a MQTTClientGateway. I've tested it only for W5100 with NRF24L01+ and I fear the MQTTClientgateway doen't work with RFM69.

    If you use a Pro Mini 3.3 V you don't need a logic converter but you need to be able to decrease the baudrate at the controller for the serial connection to work, if using that gateway type.

    Do you mean decrease it from 115200 to lower? Which speed? why?

    Regarding ethernet gateway and SPI, I suggest you follow the build guide. I don't recommend the ENC module as it's notoriously hard to get working together with mysensors.

    Ok to not use then ENC. I've followed the build guide, but, as written before, I think there is an incompatibility to use RFM69 and W5100 as gateway, especially as mqttclientgateway. Any experience would be great to be shared 😉



  • Plugin Developer


    115200 is too fast for Arduino at 8 MHz. Use 38400.

    I haven't tested the RFM69 myself yet, but I don't remember reading that it should be incompatible with the W5100 either.

  • Hello,

    I've purchased this i2C level converter to use the RFM69 radio on my Arduino Uno:

    Ehm, how do I use it 🙂

    Thanks for the support!

    PS: As written at the beginning of this thread, I need to use the Arduino Uno as a gateway, so it has the ethernet shield as well.



  • Mod

    If anyone answers @xefil's question above, please answer in this thread to avoid confusion.

    @xefil: Please don't post the same question in more than one place. People will waste their time answering in one thread while the question might have been answered in another thread already.