💬 Sensebender Gateway



  • @meddie said in 💬 Sensebender Gateway:

    Ok i just connected the W5100 and NRF24 Module and uploaded the GatewayW5100 Sketch and when the upload is done after reset i dont get any output on serial monitor.
    The orange, green and red led are lighting.

    When i upload the SensebenderGatewaySerial then i get output on serial monitor. It think the problem must be the w5100. But what going wrong?

    @meddie Did you figure out what the problem is? I have exactly the same issue



  • @alexsh1
    hi, yes it was very simple 😄 the gateway has worked fine in this time, i thought that when nothing shown in serial monitor that the gateway dont work, but it did it, after i connected the gateway to FHEM (my controller) i saw that FHEM connects t mys Gateway.
    So it worked all the time

    Greets Eddie


  • Admin

    @alexsh1

    Have you tried to enable the debug output in the GatewayW5100 example? I think it is disabled by default, due to the limited memory on the small atmega 328p



  • @tbowmo

    Yes, I did

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_DEBUG_VERBOSE_SIGNING
    


  • I am running Arduino IDE 1.8.1 on Windows 10
    Arduino AVR 1.6.18
    Arduino SAMD 1.6.12
    MySensors SAMD 1.0.5

    EDIT: I have tried to upload the default sketch on macbook with Arduino IDE 1.6.2
    It is still the same - no debug info in the terminal



  • OK, I did manage to get debug working partially.
    The gateway reads messages, but does not work as the gateway

    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    0;255;3;0;9;TSF:MSG:READ,10-10-0,s=1,c=1,t=17,pt=5,l=4,sg=0:348
    0;255;3;0;9;TSF:MSG:READ,26-10-0,s=3,c=1,t=24,pt=5,l=4,sg=0:51219479
    0;255;3;0;9;TSF:MSG:READ,10-10-0,s=1,c=1,t=24,pt=5,l=4,sg=0:51219482
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=2,c=1,t=37,pt=7,l=5,sg=0:1717.62
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=0,c=1,t=37,pt=7,l=5,sg=0:5338.44
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=3,c=1,t=37,pt=7,l=5,sg=0:10.75
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=3,c=1,t=37,pt=7,l=5,sg=0:10.76
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=4,c=1,t=37,pt=4,l=4,sg=0:880
    0;255;3;0;9;TSF:MSG:READ,6-6-0,s=2,c=1,t=1,pt=7,l=5,sg=0:64.8
    0;255;3;0;9;TSF:MSG:READ,6-6-0,s=0,c=1,t=4,pt=7,l=5,sg=0:1015
    

    I never had a message:

    Gateway startup complete.
    

    EDIT: Self-test with SensebenderSerial sketch gives me this:

    Sensebender GateWay test routine
    Mysensors core version : 2.1.1
    GateWay sketch version : 0.2
    ----------------------------------
    
    - > SHA204 Failed to wakeup SHA204
    - > SD CARD SD CARD did not initialize!
     -> EEPROM PASSED
    -> analog : 38 Failed
    

  • Admin

    @alexsh1

    Could you check the soldering of the samd?

    SD card fails, if you haven't inserted a card, when running the self test.



  • @tbowmo

    I do not have the SD card so that's fine

    The samd looks fine - no bridges etc
    I can try to re-solder it with a hot fan
    Do you think samd may be at fault even though the serial GW is working?

    Unfortunately, I do not have another Ethernet w5100 to try it. Probably have to order a new one


  • Admin

    @alexsh1

    I know that @Anticimex had problems with one of the pre-production samples that we got from China, with various problems, that was solved with "reflowing" the samd with a hot air gun.. So it was just a thought, that it could be a bad solder joint..

    The W5100 is using it's own dedicated SPI port, so even though that the radio works, doesn't mean that there couldn't be any solder problems around the samd pins for W5100.

    We have 3 different SPI ports in use on the gateway, one for the MysX connector, one for radio / sdcard, and one for W5100..



  • @tbowmo I do not have the oven to reflow the whole board, but can mount / unmount or re-work certain components 0805 or 0603. Below this it is a pain in the a***

    Another observation - The GW behaves like this with or without W5100 mounted.
    Seems like an SPI problem to me. How can I wire W5100 to MYSX please and what shall I can in the sketch please? Thank for your help - very much appreciate it


  • Contest Winner

    @alexsh1 The ATSHA is not connected to the SPI and is totally unrelated, so I am also inclined to suspect that perhaps one side of the SAMD is not entirely in contact with the pads. I had to hot-airgun mine to get USB working well but it was an early prototype like @tbowmo said.



  • @tbowmo OK, I manage to find the answer here -

    MYSX
    D11 - MOSI
    D12 - MISO
    D13 - SCK
    D14 -CS

    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 13
    #define MY_SOFT_SPI_MISO_PIN 12
    #define MY_SOFT_SPI_MOSI_PIN 11
    MY_RF24_CS_PIN 14
    RF24_CE_PIN ???

    Am I correct?



  • My current config for nrf24l01+ and w5100 is as follows:

    #define MY_GATEWAY_W5100
    
    #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
    #endif
    
    #define MY_RF24_CE_PIN 5
    #define MY_RF24_CS_PIN 6
    

    Why CE / CS pins are 5 and 6?
    Should that be 27 and 3?



  • @tbowmo I have just re-worked SAMD and all the connectors (nrf24l01+ and NET_SPI), but still have the same issue sadly.

    EDIT: If I change to rfm69, the same behavior is observed. It seems that Net_SPI is just not working.


  • Admin

    @alexsh1

    Configuration of the pins are handled by the hardware configuration file, https://github.com/mysensors/ArduinoHwSAMD/blob/master/variants/mysensors_gw/variant.h#L227

    If you look in the gatewayW5100 sketch, the settings for CE / CS pins are enclosed in ifdefs, so they are only used if they are not defined previously.

    If you want to connect the W5100 to the mysx connector, you can change line 174 in the hardware definition file, use SPI2 instead of SPI1 for SPI_ETH

    It could also be a defective W5100 shield? Can you verify that it works on other hardware?



  • @tbowmo Swapping SPIs did not resolve the problem. I am now getting another W5100 to test further.



  • Unfortunately, a new W5100 shield did not work - it seems like a production issue with this sensebender gatewsay as the SPI2 did not work either with W5100.
    Will get a new one ordered.


  • Admin

    Is it possible for you to check the spi wires with a scope? Just to make sure if mosi/miso/ce/Ss lines are toggling as expected?


  • Admin

    Another thing, are you using static ip? If yes, can you ping it? If no, does your DHCP server hand out an ip address?

    Have you tried the basic ethernet examples for the W5100?



  • @tbowmo I am using the static IP and I can ping it, but the "Gateway Ready" message never comes up. Also I can only see the neg24l01+ log (incoming messages only)


  • Admin

    @alexsh1

    If you can ping it, then the W5100 is configured. Something else is wrong..

    One thing that comes to mind, if you compile it as an ethernet GW, then it does not wait for serial console to be active, before initializing the radio. If you compile it as serial GW, then it waits with initialization, until serial is active.

    This means that you probably is missing the GW ready message on the serial port, as it is "sent" before you have an active serial connection.

    Look in MyHwSamd.cpp in the HwInit routine, remove the #ifdef around the while() loop, and try again.



  • @tbowmo Well, if I try the MEGA 2560 with W5100, I get the following:

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGAS-,VER=2.1.1
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    IP: 10.1.1.120
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    

    I never get this message with Sensebender GW. I only get

    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=2,c=1,t=37,pt=7,l=5,sg=0:2019.12
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=0,c=1,t=37,pt=7,l=5,sg=0:6275.51
    0;255;3;0;9;TSF:MSG:READ,11-11-0,s=3,c=1,t=37,pt=7,l=5,sg=0:18.77
    

    or similar messages from nodes.


  • Admin

    @alexsh1

    on atmega2560 you are resetting the device, when you connect a serial terminal to the usb device, so you get all the debug messages on the serial port..

    On SAMD it uses a native USB port, and the chip is not reset when connecting a serial terminal. When using serialGw it will wait until a serial terminal is connected. before initializing radio transport (this is because it does not make sense to have a serial gateway that spits out data to a none existing port).

    When using it as a ethernet gateway, we skip this, as we do not want to wait for a serial terminal, in case you are just using the USB as a power source. So in this mode, it skips the waiting, and just initializes radio gateway etc.

    as stated in my previous message you could look at the MyHwSAMD.cpp file line 73. Remove the #ifdef recompile, upload, and check your serial terminal again.

    Also the log shows that you actually are receiving data from your nodes, so the radio transport is clearly active.. And you can ping your gateways static IP, which means that the W5100 is initialized with the correct IP address.


  • Admin

    @alexsh1

    Did you try my suggestion about hacking the core? Or did you give up on the beast? 🙂

    I'm curious to hear if it is solved..



  • @tbowmo I will try it tomorrow. However, given the amount of time I spent already, I am about to give up...



  • Hello everybody.

    I got my Sensebender gateway yesterday. Have the W5100 Ethernet board mounted and loaded a sketch with the WizNET (W5100) Ethernet module and MQTT.

    The gateway immediately ran as desired.
    Unfortunately only for about 2 hours, then it freezes.
    After a restart it runs again 3 hours and freezes again.
    And so on.

    I wanted to replace an RPI Gatway, which has worked flawlessly for many weeks.

    If the Sensebender gateway works only a few hours it is quite useless.


  • Admin

    @micropet

    It must be a software issue. Are you using it with nrf24? Do you have a github account? If you have, would you mind filling an issue report on the mysensors library? As we need to dig further into this. Please also make a note of how many nodes you have running in your system.


  • Admin

    @alexsh1

    I would really like to get it solved, so it can bring peace to my mind 🙂 so please, if you can..



  • I also think that it is a software problem.

    I use only the RFM96HW.
    My "real" network has 20 nodes.

    The Sensebender gateway has only one DS18b20 node on a seperate frequency.
    (#define MY_RFM69_FREQUENCY (868200000ul))

    And yes, I have a github account and will make an issue report today.



  • @tbowmo I think I am on the right track here. This is the log:

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGS--,VER=2.1.1
    0;255;3;0;9;TSF:LRT:OK
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    IP: 0.0.0.0
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    

    The GW Init is correct one, but IP is 0.0.0.0

    This is the sketch:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_DEBUG_VERBOSE_RF24
    //#define MY_RADIO_RFM69
    #define MY_RF24_CHANNEL    76
    
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // 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
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 10,1,1,150   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    
    void setup()
    {
    }
    
    void loop()
    {
    }
    

    I cannot connect to W5100. Tried a different shield with the same result.



  • @tbowmo BTW, I cannot ping it (I suppose there was another network device with the same IP on a network).
    If I try to switch to DHCP I get:

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGS--,VER=2.1.1
    0;255;3;0;9;TSF:LRT:OK
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    DHCP FAILURE...0;255;3;0;9;!MCO:BGN:TSP FAIL
    


  • @tbowmo I have received the second GW and I have exactly the same problem. As you suggested, I modified MyHwSAMD.cpp and can see now the start-up message, but there is a problem between the W5100 and GW:

    0;255;3;0;9;660 MCO:BGN:INIT GW,CP=RNNGS---,VER=2.2.0-beta
    0;255;3;0;9;707 TSF:LRT:OK
    0;255;3;0;9;717 TSM:INIT
    0;255;3;0;9;727 TSF:WUR:MS=0
    0;255;3;0;9;742 TSM:INIT:TSP OK
    0;255;3;0;9;752 TSM:INIT:GW MODE
    0;255;3;0;9;762 TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;772 MCO:REG:NOT NEEDED
    IP: 0.0.0.0
    0;255;3;0;9;2082 MCO:BGN:STP
    0;255;3;0;9;2092 MCO:BGN:INIT OK,TSP=1
    0;255;3;0;9;17920 TSF:MSG:READ,11-11-0,s=2,c=1,t=37,pt=7,l=5,sg=0:1956.28
    0;255;3;0;9;17931 TSF:MSG:READ,11-11-0,s=0,c=1,t=37,pt=7,l=5,sg=0:6080.20
    0;255;3;0;9;17942 TSF:MSG:READ,11-11-0,s=3,c=1,t=37,pt=7,l=5,sg=0:20.71
    0;255;3;0;9;17953 TSF:MSG:READ,11-11-0,s=1,c=1,t=37,pt=7,l=5,sg=0:13282.11
    
    

    I tried different MySensors (stable and dev) and checked solding.
    Now sure what to do now

    EDIT: This is my sketch:

    /**
     * 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    //#define MY_DEBUG_VERBOSE_SIGNING
    
    //#define MY_SIGNING_ATSHA204
    //#define MY_SIGNING_REQUEST_SIGNATURES
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // 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
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 10,1,1,150   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    
    void setup()
    {
    }
    
    void loop()
    {
    }
    

  • Admin

    have you tried the ethernet webserver example sketch (default arduino sketch)?

    Just to rule out mysensors..

    Also, you are using static IP, right? What if you ping that IP address? Do you get a response? If yes, then the W5100 is configured by your sketch, and the connection should be ok between the samd and the ethernet module.



  • @tbowmo ethernet wedserver sketch is giving me this:

    server is at 0.0.0.0
    

    EDIT: I can ping the IP and yes it is static.



  • @tbowmo Do you think softSPI is at fault? What pins shall I use? I tried these

    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 24 //13 //23  //14
    #define MY_SOFT_SPI_MISO_PIN 22 //14 //22 //16
    #define MY_SOFT_SPI_MOSI_PIN 23 //12 //21 //15
    


  • @tbowmo I cannot ping it though if I load MySensors GW sketch -
    Destination host unreachable.



  • @tbowmo I have just discovered that the second Ethernet module I have is not W5100 but ENC28J60. Not sure if it is supported by sensebender GW (probably using native Arduino ethernet library?).
    So this module is now being returned and just to figure out any hardware issue I need to order a new W5100


  • Admin

    You should not use soft spi, as there is separate hardware spi ports for radio and W5100.

    If you load the default GatewayW5100 example sketch, then it should work out if the box. Perhaps you need to enable rfm69 instead of nrf24 at the top of the file, but that should be all that is needed.. To get a gateway up and running with W5100


  • Admin

    @alexsh1

    OK, just to recap here, you have a gateway, and a W5100. If you use that combo, and the http server example, you can ping the gateway, and Load the html files in a browser, right?

    If you load stock GatewayW5100 mysensors example sketch, then does that work? (no need to redefine pins for hardware etc, that is handled by the target hardware profile, you choose in arduino)



  • @tbowmo I must admit I have not tried to load files in the browser when trying Ethernet sketch. Only pinging
    Yes, you are correct - gateway, nrf24l01+ and w5100


  • Admin

    @alexsh1

    So gateway with nrf and W5100 is working as it should as an ethernet gateway? Then the W5100 is working with the gateway.

    What is the hardware configuration that you can't get to work? Rfm69 and W5100? Together with the samd GW?

    (just trying to figure out what is going on :))



  • @tbowmo No, sensebender GW is working with nrf24l01+ as a serial GW, but not with W5100 as ethernet GW.

    Interesting observation - I cannot ping the IP any more if I load the ethernet sketch. For your understanding the sensebender GW was never working with W5100 with either nrf or rfm69. Something going wrong around W5100.

    I'll hook up W5100 shield to Arduino nano to test it - I have a suspicion about it. However, even without W5100 connected, sensebender GW is showing IP as 0.0.0.0 (I set IP 10.1.1.150). Why?


  • Admin

    If the ethernet library can't initialize the W5100, it will just write IP address as 0.0.0.0.

    Can you please turn on verbose compile logging in arduino? (file -> Settings, set a checkmark at show verbose output during compilation, and choose "all" in Compiler warnings)

    I just want to make sure that it is using the correct ethernet library.



  • @tbowmo I have verbose on already.
    I think you hit the nail on the head:

    Linking everything together...
    "C:\Users\Alex\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gcc"  "-LC:\Users\Alex\AppData\Local\Temp\arduino_build_753079" -Os -Wl,--gc-sections -save-temps  "-TC:\Users\Alex\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.5\variants\mysensors_gw/linker_scripts/gcc/flash_with_bootloader.ld" "-Wl,-Map,C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/GatewayW5100.ino.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -o "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/GatewayW5100.ino.elf" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\sketch\GatewayW5100.ino.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\Dhcp.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\Dns.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\Ethernet.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\EthernetClient.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\EthernetServer.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\EthernetUdp.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\utility\socket.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Ethernet\utility\w5100.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\Wire\Wire.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\libraries\SPI\SPI.cpp.o" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079\core\variant.cpp.o" -Wl,--start-group "-LC:\Users\Alex\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Lib/GCC/" -larm_cortexM0l_math -lm "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/core\core.a" -Wl,--end-group
    "C:\Users\Alex\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-objcopy" -O binary  "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/GatewayW5100.ino.elf" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/GatewayW5100.ino.bin"
    "C:\Users\Alex\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom  "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/GatewayW5100.ino.elf" "C:\Users\Alex\AppData\Local\Temp\arduino_build_753079/GatewayW5100.ino.hex"
    Multiple libraries were found for "Ethernet.h"
     Used: C:\Users\Alex\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.5\libraries\Ethernet
     Not used: C:\Program Files (x86)\Arduino\libraries\Ethernet
    Using library Ethernet at version 1.1.2 in folder: C:\Users\Alex\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.5\libraries\Ethernet 
    Using library MySensors at version 2.2.0-beta in folder: C:\Users\Alex\Documents\Arduino\libraries\MySensors 
    Using library Wire at version 1.0 in folder: C:\Users\Alex\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.12\libraries\Wire 
    Using library SPI at version 1.0 in folder: C:\Users\Alex\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.12\libraries\SPI 
    Sketch uses 45512 bytes (17%) of program storage space. Maximum is 262144 bytes.```

  • Admin

    It is using "our" ethernet driver, which it should be.. The default arduino ethernet driver is hardwired to SERCOM0 for SPI, while we have it on SERCOM1.

    I'll try to bring up one of my own gateways with W5100 later today.


  • Admin

    @alexsh1

    Below is the startup log from my Gateway with W5100 and RFM69 attached:

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGS--,VER=2.2.0-beta
    0;255;3;0;9;TSF:LRT:OK
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    IP: 192.168.1.66
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    

    As seen, the W5100 is initialized with ip address,

    Telnet to the Gateway is also working:

    thomas at thomas-ThinkPad-L450 in ~ 
    >telnet 192.168.1.66 5003
    Trying 192.168.1.66...
    Connected to 192.168.1.66.
    Escape character is '^]'.
    200;255;4;0;0;FFFFFFFFFFFFFFFF0300
    200;255;0;0;17;2.2.0-beta
    200;255;3;0;6;0
    200;255;3;0;11;Sensebender Micro
    200;255;3;0;12;1.4
    200;1;0;0;6;
    200;2;0;0;7;
    200;1;1;0;0;23.3
    200;2;1;0;1;46
    200;255;3;0;0;81
    

    The above is with the stock example sketch from mysensors (right now latest development branch though). The only things I changed, was to enable RFM69, instead of NRF24, and set a different IP address, to match my network settings.

    Everything else is running as is, delivered from the mysensors examples..



  • @tbowmo if you take off the W5100 shield, does it still come up with IP please:

    255;3;0;9;MCO:REG:NOT NEEDED
    IP: 192.168.1.66
    

  • Admin

    @alexsh1

    This log is without ethernet shield attached

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGS--,VER=2.2.0-beta
    0;255;3;0;9;TSF:LRT:OK
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    IP: 0.0.0.0
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    


  • @tbowmo Thanks - I am assuming that I have a faulty W5100 shield in this case. Unfortunately, I have received a wrong replacement shield enc28j60 instead of W5100. Do you know if Sensebender GW would work with

    #define MY_GATEWAY_ENC28J60
    

    The one I have does not have AMS1117-3.3 on board and must be fed with 3.3V instead of 5v



  • @tbowmo The problem has been identified. I have used a hot fan to re-sit W5100 on the network shield.
    AND

    0;255;3;0;9;2430 MCO:BGN:INIT GW,CP=RNNGS---,VER=2.2.0-beta
    0;255;3;0;9;2477 TSF:LRT:OK
    0;255;3;0;9;2487 TSM:INIT
    0;255;3;0;9;2497 TSF:WUR:MS=0
    0;255;3;0;9;2512 TSM:INIT:TSP OK
    0;255;3;0;9;2522 TSM:INIT:GW MODE
    0;255;3;0;9;2532 TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;2542 MCO:REG:NOT NEEDED
    IP: 10.1.1.200
    0;255;3;0;9;3852 MCO:BGN:STP
    0;255;3;0;9;3862 MCO:BGN:INIT OK,TSP=1
    

    Still cannot ping it, which means there is still a problem with the shield.
    It is of a poor quality and does have multiple bridges around W5100 like this:
    0_1495292173685_HTB1VJAfNFXXXXaGXFXXq6xXFXXXF.jpg

    I found a similar problem here:
    https://electronics.stackexchange.com/questions/156147/are-solder-bridges-on-chips-always-bad

    At least I know where the problem is.
    Thanks @tbowmo


  • Admin

    @alexsh1

    Great, that we found the problem, and thanks for reporting back here on the forum 🙂

    I haven't tried with other ethernet controllers, than the W5100, And the socket for W5100 is supplied with 5V directly.

    Also, I do not know if they are pin compatible?



  • @tbowmo I think they are pin compatible but unfortunately take different voltage. On arduino board, somebody told me that enc28j60 can tolerate 5V. It seems to be the case, as mine survived w5100 socket

    EDIT: From the enc28j60 datasheet

    • Operating Voltage of 3.1V to 3.6V (3.3V typical)
    • 5V Tolerant Input


  • @tbowmo I can confirm now that everything is working fine after I tested the Sensebender GW with the third (yes, third!!!) shield. Thanks Thomas for your help!



  • @tbowmo The pinout is identical.

    W5100
    alt text

    ENC28J60
    alt text

    I can modify ENC28J60 shield (reduce voltage to 3.3V) and test it with the sensebender GW, but it does require hardware mod



  • Question,
    "To use the serial port in the mysx connector, you should use Serial1 in your sketches, as the default Serial is connected to the USB serial device"

    What pins is the serial port in the mysx connector, I see no mention of it other than that line. I want to mirror the serial data sent to my controller via the USB port to the the serial port in the mysx connector that will then be attached to a bluetooth SPP device. Just want another way to view the radio traffic.


  • Admin

    @nitroburn

    Have you seen the documentation for MysX connector: https://www.mysensors.org/hardware/mysx?

    (hint, look for Data To Module, and Data From Module :))


  • Contest Winner

    @tbowmo @nitroburn
    Actually, it is even more clearly specified than that as DTM and DFM means Data To MCU and Data From MCU. "module" is not explicitly defining what "side" you mean. The MCU is clearly defined so DTM and DFM leavs no doubt on the direction and function of the pin.



  • @tbowmo @Anticimex Thanks, I was stupidly searching for the wrong combination of terms and hadn't seen DTM DFM used so I was naively looking for the word serial or UART rather than USART when I did a search. Thought I was missing something and didn't read the mysx page close enough after briefly searching it.

    Thanks for clearing that up. #define MYSX_D1_DFM (00ul) & #define MYSX_D2_DTM (01ul) didn't stand out to me as serial connections.



  • @scalz Can somebody edit the descriptive text for this Gateway. Under 'Secure IiT Radio Network' is quoted 'Hope RF RFM69HCW' whereas under 'Setup and use' is correctly quoted RFM69(H)W.
    Guess who had ordered the incorrect 'CW' module for this Gateway....


  • Admin

    @zboblamont

    Sorry about that, it sneaked through the reviews.. I have updated the page, so others don't fall into the same pitfall..



  • Is it really correct that orange, green and red led should light constantly when powered on. On some activity from the sensors the leds blink, but goes to full constant light directly.

    An other thing, inclusion button. In sketch this is commented out, should it?

    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    

    For me it is like GW is in constant inclusion mode. Gateway seams to work, it shows up in controller, and as soon as a sensor is powered up, it automatically also appears in controller... feels very unsecure. Just give power to a random sensor and it is in my controller.


  • Admin

    @Magnus-Pernemark

    You can reverse the led behaviour by defining:

    #define MY_WITH_LEDS_BLINKING_INVERSE

    Presentation messages is always forwarded to controller. Inclusion mode must be implemented/supported by the controller for it to work.



  • @hek Thanks, I'll try that. The controller is Domoticz. Does Domoticz have a flaw when it comes to inclusion? (I guess it must have, since any random sensor gets included automatically).


  • Contest Winner

    @Magnus-Pernemark I am not sure domoticz support inclusion at all.



  • @Magnus-Pernemark inclusion mode is not for Domoticz but for Vera. For Domoticz if you want to secure your sensors you need to use signing between the sensors and the GW and reject any sensor without signing



  • @alexsh1 Feels like this could be changed, so inclusion also would work for domoticz. A also have a z-wave module hooked up to domoticz and for the z-wave there is inclusion. Just have to find the right person for it 🙂

    Yes the signing. I have tried. I want everything on the mysensors network to use signing, I have enabled the MY_SIGNING_ATSHA204, all sensors have the same keys in the chip. Is it using the signing if I have done this? I will try and hook up a sensor without the correct keys and see what happens. Just have to solder it first.


  • Contest Winner

    @Magnus-Pernemark there is quite extensive documentation on how to use signing. I presume you have read it? It's on the homepage (and the forum). You need to enable a signing backend and you need to enable requirement for signatures if your node is to require it (signing does not have to go both ways).
    So no, if you have only personalized your atsha devices and enabled the atsha backend, it does not mean signing is enabled unless you on at least one node or gw have enabled MY_SIGNING_REQUEST_SIGNARURES.



  • @Anticimex Thanks. Yes I have read it and read it and read it... doesn't mean I understand it or know what to do, unfortunately. At this point I am only using the standard examples, the standard GWserial and standard sensebender micro sketch. Without modifications, except for the MY_SIGNING_ATSHA204.
    It is so much to go through.


  • Contest Winner

    @Magnus-Pernemark then you support signing, but you don't use it.
    There are several examples in the documentation which in code showes exactly what you need to define for various use cases.



  • @Magnus-Pernemark said in 💬 Sensebender Gateway:

    @alexsh1 Feels like this could be changed, so inclusion also would work for domoticz. A also have a z-wave module hooked up to domoticz and for the z-wave there is inclusion. Just have to find the right person for it 🙂

    z-wave in Domoticz is based on OpenZWave and z-wave protocol does require inclusion / exclusion. MySensors are natively supported by Domoticz and personally I do not see why inclusion/exclusion should be there. If you want security, please use signing.


  • Admin

    @Magnus-Pernemark

    You can disable domoticz automatic inclusion of new devices on the mysensors network, somewhere in the settings..



  • @tbowmo Ah, found a setting ""Accept new hardware/sensors" and a button for "allow for 5 minutes" that could be used as a global "include"-button

    @alexsh1 well, maybe, maybe not. Don't know if I agree about not having an inclusion. Almost every device you buy you have to "pair" with something. Anyway, for now disable "allow new hardware/sensors" will do.

    @Anticimex I will re-read everything and test stuff now when I have a GW and two nodes to play with.
    A quick question - Is it possible to have the gateway to allow soft signing for some nodes (those without a ATSHA) and hardware signing for those with and reject everything else?

    I found this sentence:

    It is legal to mix MySigningAtsha204 and MySigningAtsha204Soft backends in a network. They work together.
    

    The word backend is in plural, does it mean I need one GW with ATSHA and another with soft signing?


  • Contest Winner

    @Magnus-Pernemark it means literally what it says. You can mix nodes. They are fully compatible. You can have a gw with a atsha204a device using atsha backend communicating securely with a node using soft signing. Or have a node with atsha204a device and atsha backend communicate with a gw with soft signing. You could even have a node or gw with atsha204a device configured for soft signing (although that is a waste since you have hw backed support in that case which is more secure since the hmac key is readout protected). The ONLY compatibility requirement between ANY node or gw in a network is that they MUST share the same HMAC key. That's it.



  • @Anticimex Thanks again. So, really, to have hardware and software at the same time exposes the hardware key in the nodes that have soft signing, since all nodes need same HMAC, regardless of HW or SW.

    I enabled MY_SIGNING_ATSHA204 and MY_SIGNING_REQUEST_SIGNATURES in the gateway
    What I understand, this should activate signing (https://www.mysensors.org/about/signing and the "How to use this" part)

    I then took a bender with the same ATSHA keys, but without "MY_SIGNING_ATSHA204". It showed up in MYSController and reported temp. I changed the key in ATSHA to something other then the GW, it still shows up and reports the temp. So, clearly there must be something else to change as well?

    I read this in the documentation: "If this [MY_SIGNING_REQUEST_SIGNATURES] is set in a gateway, it will NOT force all nodes to sign messages to it. It will only require signatures from nodes that in turn require signatures."
    I intemperate this as, the gateway will require signatures, if the node says so, but it will talk to nodes that don't require signing too.

    All sketches are the default example sketches, except for the setting of the MY_SIGNING...

    Maybe I am over-shooting the target? What I'm after is: my devices are mine alone and they should only report to me. My receiver (GW) should only listen to my devices and ignore the neighbor's devices. The neighbor should not be able to talk to my devices.


  • Contest Winner

    @Magnus-Pernemark if you are on master, yes, then a node has to require signing to make the GW require it. On development (beta) gw will require signatures from everyone if it is set to require signatures (unless a specific flag is set).
    Doxygen holds the the current documentation for master and development.



  • @Magnus-Pernemark I would suggest you move the signing discussion into a corresponding thread. Other people may benefit reading what you have gone through 😁


  • Contest Winner

    And yes, if you have nodes "exposed" you should make sure those are using atsha204a backed signing if you are afraid they might get physically abused.


  • Contest Winner



  • @Anticimex @alexsh1 yes should be in other thread. It started with a gateway question and migrated to a signing question. This will be the last one here, since I give up now. I will focus on building a network, and secure it later.

    I'm on development branch, so I guess I just need that "specific flag". Couldn't find it in the documentation. I have it set up as the document in doxygen says, and GW should reject unsigned messages or wrong signing, documentation says, but it doesn't... Even nodes that have a different key and MY_SIGNING_ATSHA204 set, talks to the GW and reports temp.

    I'll wait until beta is released



  • @Magnus-Pernemark
    This is very simple. On the dev version:

    GW (assuming you have atsha204 or use soft signing?)
    MY_SIGNING_ATSHA204
    MY_SIGNING_REQUEST_SIGNATURES

    On a node (assuming you have hardware atsha204?):
    MY_SIGNING_ATSHA204

    This is it.


  • Contest Winner

    @Magnus-Pernemark why do you need the special flag? I just wrote that you only need that if you DON'T want your gw to require signatures from everyone. It works just like @alexsh1 wrote. And it will work like that on both bets and release after release so if you can't get it to work on beta now, it won't work on release later either.
    I suggest you start posting some logs so I can see if you really have signing enabled and that all required handshaking takes place. But don't post it in this thread please.



  • @Anticimex @alexsh1 It's working now! In one of you replies (@Anticimex ), you misspelled the flag name, and I copy / pasted what you wrote. So all this time, signing was never activated. Now it is and gateway works as expected!


  • Contest Winner

    @Magnus-Pernemark oh, sorry about that. But I do hope the ones in the docs are correct. Good that it works now 👍



  • This may be a beginner-misunderstanding, but i hope you can assist me.

    I had to move one of my repeaters to improve the WAF of my sensor installation.
    In this process i may have messed a bit too much with the routing as i think the nodes responds directly to the gateway, but the gateway answers through the repeater. The repeater is moved, and the signal does no longer reach the node, resulting in a head ache (FPAR fails).
    I read the debug-section and I think i need to clear my eeprom to allow for a new routing to happen.

    This proved more difficult than I had anticipated. below is my software stack/process:

    • Downloaded Arduino 1.8.3 for non admin install
    • Downloaded Mysensors Library v2.1.1 using Library manager
    • Downloaded Arduino SAMD Boards (32-bits ARM cortex-M0+) version 1.6.11 using Boards manager
    • Downloaded Mysensors SAMD Boards version 1.0.4 using Boards manager

    I then rebooted my machine for good measure and uploaded the ClearEepromConfig-example to the gateway. No output in the serial monitor.

    I then searched a bit on the forum and added:

    #if defined(ARDUINO_ARCH_SAMD)
        while (!Serial) {} 
     #endif
    

    In the setup()-part. This enabled me to get some output from the gateway. Unfortunatly it only returns Started clearing. Please wait...

    I then did some more digging, and apperantly i2c_eeprom_read_byte() fails. So i searched some more on the forum and found I2C eeprom write fix for SAMD. So i tried the above once again but this time with Mysensors Library v2.2.0-beta (dev branch) just to see if anything changed. It didnt.
    What did i miss ?



  • Hi,
    After weeks of tests, it doesn't work well with ethernet and RFM69HW. Every 2 days, I need to power off and on the gateway. Controller can't connect (OH2).
    for some reasons, serial doesn't work on my odroid C1 with openhabian.


  • Hero Member

    Ever since lightning took out my original RFM69 W5100 GW I have been having trouble with the replacement GW I built so now I want to use my Sensebender GW for this instead. On the GW I have allso 4 buttons and 4 relays so my question to @Anticimex is:

    Witch pins on the MYSX connector do you recommend for the buttons and relays?

    I was thinkin:
    Buttons:
    MYSX_D1_DFM
    MYSX_D2_DTM
    MYSX_D3_INT
    MYSX_D4_INT
    Relays:
    MYSX_D5_PWM
    MYSX_D6_PWM
    MYSX_D9_A3
    MYSX_D10_A4

    Can I assign the pins like this in my sketch:

    const int relayPin[] = {MYSX_D5_PWM, MYSX_D6_PWM, MYSX_D9_A3, MYSX_D10_A4};       //  switch around pins to your desire
    const int buttonPin[] = {MYSX_D1_DFM, MYSX_D2_DTM, MYSX_D3_INT, MYSX_D4_INT};   //  switch around pins to your desire
    

    Here is the complete sketch, please comment if something can be improved:

    /**
     * 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    #define SN "EthGW/RFM69 Rele Button"
    #define SV "1.5"
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_NRF5_ESB
    #define MY_RADIO_RFM69
    #define MY_RFM69_FREQUENCY RF69_433MHZ
    #define MY_IS_RFM69HW
    //#define MY_RADIO_RFM95
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // 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
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable UDP communication
    //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,1,100
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xED, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define RELAY_ON 0                      // switch around for ACTIVE LOW / ACTIVE HIGH relay
    #define RELAY_OFF 1
    //
    
    #define noRelays 4                     //2-4
    
    const int relayPin[] = {MYSX_D5_PWM, MYSX_D6_PWM, MYSX_D9_A3, MYSX_D10_A4};       //  switch around pins to your desire
    const int buttonPin[] = {MYSX_D1_DFM, MYSX_D2_DTM, MYSX_D3_INT, MYSX_D4_INT};   //  switch around pins to your desire
    
    class Relay             // relay class, store all relevant data (equivalent to struct)
    {
      public:
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        boolean relayState;               // relay status (also stored in EEPROM)
    };
    
    Relay Relays[noRelays];
    Bounce debouncer[noRelays];
    MyMessage msg[noRelays];
    
    
    void setup()
    {
      // Setup locally attached sensors
      wait(100);
      // Initialize Relays with corresponding buttons
      for (int i = 0; i < noRelays; i++) {
        Relays[i].buttonPin = buttonPin[i];              // assign physical pins
        Relays[i].relayPin = relayPin[i];
        msg[i].sensor = i;                                   // initialize messages
        msg[i].type = V_LIGHT;
        pinMode(Relays[i].buttonPin, INPUT_PULLUP);
        wait(100);
        pinMode(Relays[i].relayPin, OUTPUT);
        Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
        digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
        send(msg[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
        wait(50);
        debouncer[i] = Bounce();                        // initialize debouncer
        debouncer[i].attach(buttonPin[i]);
        debouncer[i].interval(30);
        wait(50);
      }
    }
    
    void presentation()
    {
      // Present locally attached sensors here
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SN, SV);
    
      wait(100);
    
      for (int i = 0; i < noRelays; i++)
        present(i, S_LIGHT);                               // present sensor to gateway
    
      wait(100);
    }
    
    void loop()
    {
      // Send locally attached sensors data here
      for (byte i = 0; i < noRelays; i++) {
        if (debouncer[i].update()) {
          
          int value = debouncer[i].read();
          
          if ( value == LOW) {
            Relays[i].relayState = !Relays[i].relayState;
            digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);
            send(msg[i].set(Relays[i].relayState ? true : false));
            // save sensor state in EEPROM (location == sensor number)
            saveState( i, Relays[i].relayState );
    
          }
    
        }
      }
      //wait(20);
    }
    
    void receive(const MyMessage &message) {
      if (message.sender == 0) {
        if (message.type == V_LIGHT) {
          if (message.sensor < noRelays) {          // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
            Relays[message.sensor].relayState = message.getBool();
            digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
            saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
          }
        }
      } 
      wait(20);
    }
    

  • Contest Winner

    @korttoma you can use any pin that can provide the type of functionality you need (for example, don't expect that using an analog pin for digital data to work). Just keep in mind that by using certain pins, you might have to give up features you might like to use later on (like in this case you take the dfm and dtm pins, so you have "taken" the UART pins if you ever plan to use that for your board).
    As for the definitions, I am not sure. @tbowmo made the mappings for that port. I believe it looks good.


  • Admin

    @korttoma
    Like @anticimex said, you will loose possibility of using the serial port if you use the dtm/dfm lines.

    But besides that, you are free to use all the ports as digital input/output, except the i2c pins as we have an i2c eeprom that is connected to the same pins.


  • Hero Member

    Thanks @Anticimex and @tbowmo I have the GW up and running with one external sensor now. I just need to connect the buttons and relays to test those.

    I'm not sure if I will ever need the UART pins but I will make the hardware so that I can easily change the pins used for buttons and relays.

    btw, what is the use cases for UART pins?


  • Contest Winner

    @korttoma if you have peripherals on your daughter board that communicate using a serial protocol it makes sense to leverage any hw UART capable blocks on the main board. The MYSX standard just indicate that if the main board has such capability, the interface is available on those two pins. You can of course bit bang it on any digital io (depending on core clock) if you need several interfaces.


  • Contest Winner

    @korttoma that said, note that the dtm and dfm pins also serves as general digital io, so you can use them like any Dx pin.


  • Hero Member

    Button and relay pins I assigned seem to work correctly but now I managed to release some magic smoke from the Sensebender GW board 😞 shorted something by mistake and at least FB1 is tost. Can I just shor FB1 to see if the board is stil alive or do I have to replace FB1? Seems like nothing else was damaged (at least I hope so) since it was GND and Vraw that was shorted.

    Edit: Just confirmed that it is only FB1 that was destroyed the rest seems to work 😄 just cant power it from the USB anymore. Hope I can stil write to it.


  • Admin

    @korttoma said in 💬 Sensebender Gateway:

    Button and relay pins I assigned seem to work correctly but now I managed to release some magic smoke from the Sensebender GW board 😞 shorted something by mistake and at least FB1 is tost. Can I just shor FB1 to see if the board is stil alive or do I have to replace FB1? Seems like nothing else was damaged (at least I hope so) since it was GND and Vraw that was shorted.

    Edit: Just confirmed that it is only FB1 that was destroyed the rest seems to work 😄 just cant power it from the USB anymore. Hope I can stil write to it.

    FB1 is just a filter to suppress spurious RF (if any) on the gnd wire exiting the board. So it can be shorted. The gateway should function fine without it.



  • Hi All,
    I have purchased a SenseBender Gateway, tested the MySensors MQTT code etc on it and thats all good.
    Now I want to experiment with my own code on it. I notice that in the example code there are some references to the onboard LEDs, such as;

    static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE};

    which is great, I will use those to manage the LEDs in my sketch.
    What I'd like to know is where are LED_BLUE, LED_RED etc actually defined? What file? The reason I ask is that I also want to know which pin is connected to the RFM69 RESET pin. On the schematic for the SenseBender it is labelled RESET_RFM on the SAMD21 chip, and is physical chip pin 23 and also PB10. I don't know how to use that in my sketch, so if I had a macro like there is for the LEDs then I could just call that.
    I'm assuming that if I find where LED_BLUE is defined I may find info about the other pins I also want to use 🙂

    Thanks,
    Paul


  • Admin



  • @hek thanks, Now I understand.
    I was poking around near that file before, but could not figure it out.
    Thanks again,
    Paul


  • Hero Member

    Received a new ferrite bead and soldered it to my device. The bead showed 0 ohm with a multimeter so I don't know if it is the real deal but it seems to work even if it is not pretty:

    0_1509948945658_20171106_080332.jpg


  • Admin

    at DC it should be close to 0 ohm, but on higher frequencies it should act as a resistor.

    btw. it seems like the old one had exploded? 🙂


  • Hero Member

    @tbowmo said in 💬 Sensebender Gateway:

    it seems like the old one had exploded?

    That's what happens when you short Vraw to GND on the MYSX connector in one of those facepalm moments 😄 (we need an :facepalm emoji!).

    alt text



  • I have a lot of problem with this gateway. First I think it was caused by network module but with serial sketch I have a lot of issues. After 2 or 3 days, gateway crash. If I remove some sensors reporting every 30 seconds it crash but later.
    This morning, all leds are off on the board. After powering off and on it was ok.
    I'im using RFM69 with Openhab2 as controller.
    Is someone experience same issue ? I will fall back to my old Jeelink gateway (ATmega328 based).


Log in to reply
 

Suggested Topics

14
Online

11.4k
Users

11.1k
Topics

112.7k
Posts