EthernetGateway

A new gateway option has been added. You can now use Ethernet instead of serial link. This means free placement of your gateway anywhere in your house (near ethernet connector) and that you can use any Arduino board (not just Nano) for your gateway (by adding Ethernet module).

You should be able to use both the WizNet or the ENC28J60 module (I have only verified with ENC28J60)

You will need to update the Vera plugin with a new “L_Arduino.lua”-file

Install the latest MySensors-library:
https://github.com/mysensors/Arduino/tree/master/libraries/MySensors

If your using ENC28J60-module install the provided UIPEthernet-library into Arduino-IDE.
https://github.com/mysensors/Arduino/tree/master/libraries/UIPEthernet

The gateway sketch can be found here:
https://github.com/mysensors/Arduino/tree/master/EthernetGateway

Vera Configuration:
Enter “ip-number:port” in the ip-field of the Arduino GW device(advanced tab). This will override any serial configuration for the Vera plugin. E.g. If you want to use the default values in this sketch enter: 192.168.178.66:5003

Ebay:
ENC28J60 - Electronics, Cars, Fashion, Collectibles & More | eBay

WizNET - Electronics, Cars, Fashion, Collectibles & More | eBay

@A-lurker, thanks for providing your example-code!

Below is the header of EthernetGateway.ino (contains connect/compile-instructions)

[code]/*

  • Copyright (C) 2013 Henrik Ekblad henrik.ekblad@gmail.com
  • Contribution by a-lurker
  • 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.
  • 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
  • You must make sure to disable DEBUG in Sensor.h before compiling this sketch. Othervise the sketch won’t fit in program space when downloading.
  • For UIPEthernet(ENC28J60) usage: Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which meas you ave to choose a static IP)
  • For WizNET usage: Do not install the provided UIPEthernet-library. Remove UIPEthernet-include below and uncomment the Ethernet.h.
  • 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 default values in this sketch enter: 192.168.178.66:5003
  • LED purposes:
    • 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
  • ----------- Connection guide ---------------------------------------------------------------------------
  • 13 Radio & Ethernet SPI SCK
  • 12 Radio & Ethernet SPI MISO (SO)
  • 11 Radio & Ethernet SPI MOSI (SI)
  • 10 Ethernet SPI Slave Select (CS) Pin 10, the SS pin, must be an o/p to put SPI in master mode
  • 9 Radio TX LED using on board LED (optional) +5V → LED → 270-330 Ohm resistor → pin 9.
  • 8 Radio RX LED (optional) +5V → LED → 270-330 Ohm resistor → pin 8.
  • 7 Radio error LED (optional) +5V → LED → 270-330 Ohm resistor → pin 7.
  • 6 Radio SPI Slave Select
  • 5 Radio Chip Enable
  • 3 Inclusion mode button (optional), 10K pull down to GND, button to VCC)
  • 2 Radio IRQ pin (optional), W5100 Int, if linked to pin 2)

  • Powering: both NRF24l01 radio and Ethernet(ENC28J60) uses 3.3V
    */

[/code]

Great work hek!

What would you say the advanges are of running ethernet versus serial? would serial be much faster? Could multiple vera talk to the ethernet gateway at one time? Or a vera talk to multiple ethernet gateways at one time?

There’s no speed improvement. In my case, there are several advantages though It allows me to locate the Gateway any place there’s an Ethernet connection… I no longer have to tie the Gateway to the Vera. I’ve also had occasional problems with the USB port loosing connection to the Gateway if Vera looses power (I’m hoping the Ethernet connection will help this).

I have a few mr3020 lying around and was thinking of using their wifi to build a wireless mesh (2 mb/s speed are achievable with a mesh network), and the expose serial gateway over an ip port.

SoC: Atheros AR9330 rev 1
802.11 b/g/n 150 Mbps
Powered via USB B-Mini (5 Volts)
Tiny form factor
5.7 cm x 5.7 cm PCB
6.7 cm x 7.4 cm x 2.2 cm case

This would allow the nodes to be wifi-capable and only one node would have to be tied into the lan. It would make the WAF (wife acceptance factor) increase tenfold at least :). And i would rather spend 15-20$ for a mr3020 instead of 10-15$ for an ethernet module.

On the other hand, using an ethernet connection to the mr3020 and using the mr3020 as a bridge only would remove the need to write a serial-to-usb interface on the little router.

Darn, i’ve just finished making a pcb to plug the nano and everthing else and bought a case… back to the drawing board again…

And i’m guessing using an ethernet gateway would allow me to use an arduino mega, uno or anything else as long as it’s fast enough and has enough memory ? This would allow me to keep my nano and mini pro’s for actual sensors…

@hek & @a-lurker… Nice Job!

I’ve got everything switched over to Ethernet and all is working well.

I’m using the ENC28J60

For those who are switching over… There are two radio signals (CE & CSN) as well as the LED’s (if you use em’) that are now different from the default USB sketch when adding the ENC28J60.

If you used the default pins published in the USB Gateway Sketch, the changes are summarized below:

           Moves From                  To

CE Pin 9 Pin 5
CSN Pin 10 Pin 6
Rx LED Pin 6 Pin 8
Tx LED Pin 5 Pin 9
Err LED Pin 4 Pin 7

Using a wiznet 5100 arduino module and an arduino uno (assuming they are compatible with the arduino nano sketch), are these the correct pins? I’m trying to make sure i don’t fry anything…

gnd /1 - gnd
vcc /2 - 3.3v
ce /3 - digital 5
csn /4 - digital 6
sck /5 - digital 13
mosi/6 - digital 11
miso/7 - digital 12
irq /8 - digital 2

Thank you for your time!

You’ve got some radio signals and some Wiznet signals listed. You’d connect as follows:

Radio UNO
Gnd Gnd
Vcc 3.3v
CE Pin 5
CSN Pin 6
SCK. Pin 13
MOSI. Pin 11
MISO. Pin 12
IRQ. Pin 2

Wiznet. UNO
Gnd. Gnd
3v3d 3.3v
MOSI Pin 11
MISO Pin 12
SCLK. Pin 13
SCSn. Pin 10

I lost connection with the gateway today. When I pinged the Gateway there was no response until I cycled the power. I’ve been having problems with my cable modem resetting so I suspected the Gateway got lost when the network went down. I recreated the problem by disconnecting the Ethernet cable from the Gateway for 30 seconds and trying to ping… no response until I cycle the power.

Ok, that is bad behavior.

Anyone up for debugging Ethernet?

This is the down side of using the luup io module to communicate with a device. If the power fails on the remote device, then the link cannot be re-established once power is restored, unless Vera is restarted. This is a major Vera problem. More here:

http://forum.micasaverde.com/index.php/topic,18469.msg155683.html#msg155683

Due to this limitation, users may be better off having the Arduino Gateway act as a web server? You would command with GETs or POSTs and receive data in say json. However it requires polling be used. I have taken this approach here:

http://forum.micasaverde.com/index.php/topic,23079.msg156151.html#msg156151

The ow server plugin also acts in this manner and works perfectly.

@MDoc I was a bit surprised to read that just unplugging the cable and plugging it back in caused a failure. Have you the latest firmware and which Ethernet interface are you using? Also worth a look at:

http://bugs.micasaverde.com/view.php?id=2282

In summary however, their is no doubt that if the power is lost to your gateway, you need to restart the Vera Luup engine once power is restored. Otherwise you’re hosed.

Thanks @a-lurker,

I’m using the ENC28J60 and running the code hek put up yesterday.
I’ll do some more testing to see if I can track down what’s happening and post back.

Thanks,
Mike

@MDoc,

did you mean cycle the power of the Gateway (Arduino + Ethernet module) or power cycle the Vera itself?
Sorry that wasn’t clear to me since a-lurker seemed to talk about having to restart the Vera.

No need to power off anything. Just hit the reset button on the gateway and then restart the Luup engine.

Yeah… I’m having problems with my cable modem and loosing the internet several time a day. Since I’ve switched over to Ethernet, I’ve not gotten though a day without loosing contact with the Gateway. As @a-lurker said, I just need to cycle power to the Gateway (because it’s in an enclosed box) or hit the reset button to re-sync with the Vera.

Weird that your local network is affected by fluctuating internet access.

Is it possible to detect loss of connectivity from the gateway itself somehow?

In that case we could probably just update booloader to one that support WDT (Watch Dog Timer).
I.e. Google Code Archive - Long-term storage for Google Code Project Hosting.
With WDT we could to make the arduino automatically reset when it loses contact.

@MDoc After restarting the gateway, do you also have to do a Luup restart or is the the gateway restart alone sufficient to get the comms going again?

Nope… If I ping the gateway there’s no response (obviously, also if I scan the network there the gateway IP is not present). Once I reset the Gateway (without restarting Luup) I’m reconnected and start getting sensor updates.

@hek, I agree about the cable modem… Don’t see why the modem should affect network devices… But at this point it’s the only thing I can hang my hat on. I replaced my modem tonight so I should know by tomorrow if it makes a difference. I’ll let you know.

I believe the problem is that I’m using a 3.3V 328P Nano as my Gateway. I’ve got the ENC28J60 connected to the 3.3V output. The FDTI output (FT233RL) can only supply 50ma while the ENC28J60 pulls 160ma when transmitting and 125ma at idle. I’ll switch over to a separate 3.3V source and re-post.

Hey… at least the new cable model fixed my resetting problems :wink: