Problem with Ardunio Ethernet as gateway



  • Hi !

    Trying to make my first gateway to work with no success.
    I found out (by adding some Serial.println() statements) it fails in rf24.isPVariant().
    Output (shown by the serial monitor) from MySensors is "0;0;3;0;9;radio init fail"
    I am rather sure I have wired my NRF24L01+ wrong since the Arduino Ethernet board does not have the exact same pin markings as listen in MySenbors,org.

    (Ethernet is correctly setup since in my sketch I can ping the Arduino from my PC without problem)

    My setup : Arduino Ethernet
    Arduino IDE : 1.6.5
    OS : Windows 10 Prof.
    MySensors library version : 1.5.4
    NRF devices are clearly the Plus version, chip is marked as
    NRF M
    24L01+
    1452AB

    Wiring (based on info I found here:
    Arduino NRF24
    GND GND
    3.3V Vcc
    Digital pin 7 CE
    Digital pin 8 CSN/CS
    SCK SCK
    MOSI MOSI
    MISO MISO
    IRQ Not connected

    Changes in the EthernetGateway sketch :
    #define RADIO_CE_PIN 7 // radio chip enable
    #define RADIO_SPI_SS_PIN 8 // radio SPI serial select

    Changes in MyConfig.h :
    #define DEBUG (obviously... 🙂 )
    ...
    #define RF24_CE_PIN 7
    #define RF24_CS_PIN 8
    ....
    const uint8_t SOFT_SPI_MISO_PIN = 12;
    const uint8_t SOFT_SPI_MOSI_PIN = 11;
    const uint8_t SOFT_SPI_SCK_PIN = 13;

    Has anyone else been successful using the Arduino Ethernet as a MySensor gateway ? If so, what am I doing wrong here... ?

    Cheers & TIA !
    /T



  • @Tias
    Hi

    I am not sure
    But for CE you wrote 7 and in sketch it is 5?
    Try to change sketch to 7.

    Same about SPI, you wrote 8 and in sketch it is 4.



  • Hi !

    Sorry, I tried both version 5 & 4 and then 7 & 😎 so that's why I messed it up in my post.
    It is 7 & 8 (now corrected in my OP) based on the info for the Arduino Ethernet I linked to in tho OP.

    Cheers !



  • @Tias
    Can you please copy your sketch here
    Easier for everyone to help you, maybe it can be something with soft pins?



  • @Tias
    Hi, I'am using :

    in my application
    #define RADIO_CE_PIN 5 // radio chip enable
    #define RADIO_SPI_SS_PIN 6 // radio SPI serial select

    in MyConfig.h
    #define SOFTSPI
    #ifdef SOFTSPI
    // Define the soft SPI pins used for NRF radio

    const uint8_t SOFT_SPI_MISO_PIN =   12;          //A2       
    const uint8_t SOFT_SPI_MOSI_PIN = 11;            //A1         
    const uint8_t SOFT_SPI_SCK_PIN =  13;            //A0         
    

    #endif

    the connection NRF24l01 with Uno, MISO->A2
    MOSI->A1
    SCK ->A0
    CE -> D5
    CS-> D6



  • @flopp
    No Problem, here's my EthernetGateway.ino and below MyConfig.h :

    EthernetGateway.ino :

    #include <MyConfig.h>
    #include <MyHw.h>
    #include <MyHwATMega328.h>
    #include <MyHwESP8266.h>
    #include <MyMessage.h>
    #include <MyParser.h>
    #include <MyParserSerial.h>
    #include <MySensor.h>
    #include <MySigning.h>
    #include <MySigningAtsha204.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningNone.h>
    #include <MyTransport.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <Version.h>
    
    #include <MyConfig.h>
    #include <MyHw.h>
    #include <MyHwATMega328.h>
    #include <MyHwESP8266.h>
    #include <MyMessage.h>
    #include <MyParser.h>
    #include <MyParserSerial.h>
    #include <MySensor.h>
    #include <MySigning.h>
    #include <MySigningAtsha204.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningNone.h>
    #include <MyTransport.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <Version.h>
    
    #include <MyConfig.h>
    #include <MyHw.h>
    #include <MyHwATMega328.h>
    #include <MyHwESP8266.h>
    #include <MyMessage.h>
    #include <MyParser.h>
    #include <MyParserSerial.h>
    #include <MySensor.h>
    #include <MySigning.h>
    #include <MySigningAtsha204.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningNone.h>
    #include <MyTransport.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <Version.h>
    
    #include <NewPing.h>
    
    #include <MyConfig.h>
    #include <MyHw.h>
    #include <MyHwATMega328.h>
    #include <MyHwESP8266.h>
    #include <MyMessage.h>
    #include <MyParser.h>
    #include <MyParserSerial.h>
    #include <MySensor.h>
    #include <MySigning.h>
    #include <MySigningAtsha204.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningNone.h>
    #include <MyTransport.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <Version.h>
    
    #include <MyConfig.h>
    #include <MyHw.h>
    #include <MyHwATMega328.h>
    #include <MyHwESP8266.h>
    #include <MyMessage.h>
    #include <MyParser.h>
    #include <MyParserSerial.h>
    #include <MySensor.h>
    #include <MySigning.h>
    #include <MySigningAtsha204.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningNone.h>
    #include <MyTransport.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <Version.h>
    
    /**
    * 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>
    *
    * 
    * 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.
    * 
    *
    * COMPILING WIZNET (W5100) ETHERNET MODULE
    * > Edit MyConfig.h in (libraries\MySensors\) to enable softspi (remove // before "#define SOFTSPI").
    *
    * COMPILING ENC28J60 ETHERNET MODULE
    * > Use Arduino IDE 1.5.7 (or later) 
    * > Disable DEBUG in Sensor.h before compiling this sketch. Othervise the sketch will probably not fit in program space when downloading. 
    * > Remove Ethernet.h include below and include UIPEthernet.h 
    * > Remove DigitalIO include 
    * Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which means you have to choose a static IP for that module)
    *
    * VERA CONFIGURATION:
    * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. 
    * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
    *
    * LED purposes:
    * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
    * - 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.
    *
    */
    #define DEBUG 1
    #define NO_PORTB_PINCHANGES 
    
    #include <DigitalIO.h>     // This include can be removed when using UIPEthernet module  
    #include <SPI.h>  
    
    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>
    
    #include <MyParserSerial.h>  
    #include <MySensor.h>  
    #include <stdarg.h>
    #include <PinChangeInt.h>
    #include "GatewayUtil.h"
    
    
    // Use this if you have attached a Ethernet ENC28J60 shields  
    // #include <UIPEthernet.h>  
    
    // Use this for WizNET W5100 module and Arduino Ethernet Shield 
    #include <Ethernet.h>   
    
    
    #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
    #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
    
    #define RADIO_CE_PIN        7  // radio chip enable
    #define RADIO_SPI_SS_PIN    8  // radio SPI serial select
    
    #define RADIO_ERROR_LED_PIN 7  // Error led pin
    #define RADIO_RX_LED_PIN    8  // Receive led pin
    #define RADIO_TX_LED_PIN    9  // the PCB, on board LED
    
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW);  
    //MyTransportRFM69 transport;
    
    // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    //MySigningNone signer;
    //MySigningAtsha204Soft signer;
    //MySigningAtsha204 signer;
    
    // 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
    
    
    #define IP_PORT 5003        // The port you want to open 
    IPAddress myIp (192, 168, 1, 89);  // Configure your static ip-address here    COMPILE ERROR HERE? Use Arduino IDE 1.5.7 or later!
    
    // 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.
    byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x45, 0x5F };  // DEAD BEEF FEED
    
    // a R/W server on the port
    EthernetServer server = EthernetServer(IP_PORT);
    // handle to open connection
    EthernetClient client = EthernetClient();
    
    char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
    int inputPos = 0;
    bool sentReady = false;
    
    void output(const char *fmt, ... )
    {
      va_list args;
      va_start (args, fmt );
      vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
      va_end (args);
      Serial.print(serialBuffer);
      server.write(serialBuffer);
    }
    
    void setup()  
    { 
     Serial.begin(115200);//MT: Without this, I don't get any debug msgs on the serial port.
    
     Ethernet.begin(mac, myIp);
    
     setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
    
     // Add interrupt for inclusion button to pin
     PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
    
     // give the Ethernet interface a second to initialize
     delay(1000);
    
     // Initialize gateway at maximum PA level, channel 70 and callback for write operations 
     gw.begin(incomingMessage, 0, true, 0);
     
     // start listening for clients
     server.begin();
    }
    
    void loop()
    {
     gw.process();  
     
     checkButtonTriggeredInclusion();
     checkInclusionFinished();
    
     // if an incoming client connects, there will be
     // bytes available to read via the client object
     EthernetClient newclient = server.available();
     // if a new client connects make sure to dispose any previous existing sockets
     if (newclient)
     {
         if (client != newclient)
         {
          client.stop();
          client = newclient;
          output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
        }
      }
    
      if (client)
      {
        if (!client.connected())
        {
          client.stop();
        }
        else if (client.available())
        { 
          // read the bytes incoming from the client
          char inChar = client.read();
          if (inputPos<MAX_RECEIVE_LENGTH-1)
          { 
            // if newline then command is complete
            if (inChar == '\n')
            {  
              Serial.println("Finished");
               // a command was issued by the client
               // we will now try to send it to the actuator
               inputString[inputPos] = 0;
         
               // echo the string to the serial port
               Serial.print(inputString);
         
               parseAndSend(gw, inputString);
         
               // clear the string:
               inputPos = 0;
            }
            else
            {  
              // add it to the inputString:
              inputString[inputPos] = inChar;
              inputPos++;
            }
         }
         else
         {
            // Incoming message too long. Throw away 
            inputPos = 0;
         }
       }
     }
    }
    

    MyConfig.h :

    /**
     * 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.
     */
    
    
    #ifndef MyConfig_h
    #define MyConfig_h
    #include <stdint.h>
    
    // Enable debug flag for debug prints. This will add a lot to the size of the final sketch but good
    // to see what is actually is happening when developing
    #define DEBUG
    
    // Disable this line, If you are using TX(1), RX(0) as normal I/O pin
    #define ENABLED_SERIAL
    
    // Serial output baud rate (for debug prints and serial gateway)
    #define BAUD_RATE 115200
    
    
    /**********************************
    *  Over the air firmware updates
    ***********************************/
    
    // The following define enables the safe over-the-air firmware update feature
    // which requires external flash and the DualOptiBoot bootloader.
    // Note: You can still have OTA FW updates without external flash but it
    // requires the MYSBootloader and disabled MY_OTA_FIRMWARE_FEATURE
    //#define MY_OTA_FIRMWARE_FEATURE
    // Slave select pin for external flash
    #define MY_OTA_FLASH_SS 8
    // Flash jdecid
    #define MY_OTA_FLASH_JDECID 0x1F65
    
    
    /**********************************
    *  Information LEDs blinking
    ***********************************/
    // This feature enables LEDs blinking on message receive, transmit
    // or if some error occured. 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.
    
    //#define WITH_LEDS_BLINKING
    
    // The following setting allows you to inverse the blinking feature WITH_LEDS_BLINKING
    // When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
    // off when blinking
    
    //#define WITH_LEDS_BLINKING_INVERSE
    
    
    // default LEDs blinking period in milliseconds
    #define DEFAULT_LED_BLINK_PERIOD 300
    // The RX LED default pin
    #define DEFAULT_RX_LED_PIN 6
    // The TX LED default pin
    #define DEFAULT_TX_LED_PIN 5
    // The Error LED default pin
    #define DEFAULT_ERR_LED_PIN 4
    
    
    /**********************************
    *  Message Signing Settings
    ***********************************/
    // Disable to completly disable signing functionality in library
    //#define MY_SIGNING_FEATURE
    
    // 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.
    #define MY_VERIFICATION_TIMEOUT_MS 5000
    
    // Enable to turn on whitelisting
    // When enabled, a signing node will salt the signature with it's unique signature and nodeId.
    // 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.
    // 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.
    // 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)
    //#define MY_SECURE_NODE_WHITELISTING
    
    // MySigningAtsha204 default setting
    #define MY_ATSHA204_PIN 17 // A3 - pin where ATSHA204 is attached
    
    // MySigningAtsha204Soft default settings
    #define MY_RANDOMSEED_PIN 6 // A7 - Pin used for random generation (do not connect anything to this)
    
    // Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes)
    #define MY_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
    
    /**********************************
    *  NRF24L01 Driver Defaults
    ***********************************/
    #define RF24_CE_PIN		   7
    #define RF24_CS_PIN		   8
    #define RF24_PA_LEVEL 	   RF24_PA_MAX
    #define RF24_PA_LEVEL_GW   RF24_PA_LOW
    // RF channel for the sensor net, 0-127
    #define RF24_CHANNEL	   76
    //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
    #define 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.
    #define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL)
    
    // Enable SOFTSPI for NRF24L01 when using the W5100 Ethernet module
    #define SOFTSPI
    #ifdef SOFTSPI
    	  // Define the soft SPI pins used for NRF radio
    	  const uint8_t SOFT_SPI_MISO_PIN = 12;
        const uint8_t SOFT_SPI_MOSI_PIN = 11;
        const uint8_t SOFT_SPI_SCK_PIN = 13;
    #endif
    
    
    /**********************************
    *  RFM69 Driver Defaults
    ***********************************/
    // Default network id. Use the same for all nodes that will talk to each other
    #define RFM69_NETWORKID     100
    
    // Default frequency to use. This must match the hardware version of the RFM69 radio (uncomment one):
    // #define RFM69_FREQUENCY   RF69_433MHZ
    #define RFM69_FREQUENCY   RF69_868MHZ
    //#define FREQUENCY     RF69_915MHZ
    
    // Enable this for encryption of packets
    //#define RFM69_ENABLE_ENCRYPTION
    #define RFM69_ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
    
    
    
    
    #endif
    


  • @Tias
    Your Arduino is Mega?????



  • @anibaldiniz
    Nope, it's an Arduino Ethernet (there's a link to it in my OP above).



  • @Tias
    Right, I gave up and got an Arduino Nano to use as a Serial gateway instead.

    It's initializing ok and entering the loop() but presents other issues, however, that's for another thread.

    Cheers & thanks !
    /T


Log in to reply
 

Suggested Topics

  • 3
  • 6
  • 1
  • 2
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts