We have moved at community.getvera.com

Author Topic: EthernetGateway  (Read 28114 times)

Offline hek

  • Moderator
  • Hero Member
  • *****
  • Posts: 714
  • Karma: +60/-1
EthernetGateway
« on: February 07, 2014, 05:02:24 pm »
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
https://github.com/mysensors/Vera/blob/master/L_Arduino.lua

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 - http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5575069610&toolid=10001&campid=5337433187&customid=&icep_item=390686500452&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg

WizNET - http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5575069610&toolid=10001&campid=5337433187&customid=&icep_item=280924809892&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg

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


Below is the header of EthernetGateway.ino (contains connect/compile-instructions)
Code: [Select]
/*
 * 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
 */

 
« Last Edit: February 08, 2014, 12:32:28 pm by hek »

Offline korttoma

  • Hero Member
  • *****
  • Posts: 729
  • Karma: +26/-5
Re: EthernetGateway
« Reply #1 on: February 08, 2014, 01:49:00 am »
Great work hek!
- Tomas

Offline aPL

  • Developers
  • Jr. Member
  • *****
  • Posts: 74
  • Karma: +1/-2
Re: EthernetGateway
« Reply #2 on: February 08, 2014, 06:30:45 pm »
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?
working @ Vera / MiOS | anything stated is my own opinion and does not reflect the thoughts and opinions of my employer

Offline MDoc

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +3/-3
Re: EthernetGateway
« Reply #3 on: February 08, 2014, 06:58:24 pm »
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).

Offline aPL

  • Developers
  • Jr. Member
  • *****
  • Posts: 74
  • Karma: +1/-2
Re: EthernetGateway
« Reply #4 on: February 08, 2014, 07:04:40 pm »
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...
« Last Edit: February 08, 2014, 07:07:42 pm by aPoundOfLaughter »
working @ Vera / MiOS | anything stated is my own opinion and does not reflect the thoughts and opinions of my employer

Offline aPL

  • Developers
  • Jr. Member
  • *****
  • Posts: 74
  • Karma: +1/-2
Re: EthernetGateway
« Reply #5 on: February 08, 2014, 07:11:29 pm »
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...
working @ Vera / MiOS | anything stated is my own opinion and does not reflect the thoughts and opinions of my employer

Offline MDoc

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +3/-3
Re: EthernetGateway
« Reply #6 on: February 08, 2014, 07:15:02 pm »
@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

Offline aPL

  • Developers
  • Jr. Member
  • *****
  • Posts: 74
  • Karma: +1/-2
Re: EthernetGateway
« Reply #7 on: February 08, 2014, 07:30:45 pm »
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!
working @ Vera / MiOS | anything stated is my own opinion and does not reflect the thoughts and opinions of my employer

Offline MDoc

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +3/-3
Re: EthernetGateway
« Reply #8 on: February 08, 2014, 11:09:54 pm »
Using a wiznet 5100 arduino module and an arduino uno (assuming they are compatible with the arduino nano sketch), are these the correct pins?

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



Offline MDoc

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +3/-3
Re: EthernetGateway
« Reply #9 on: February 09, 2014, 05:04:59 pm »
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. 

Offline hek

  • Moderator
  • Hero Member
  • *****
  • Posts: 714
  • Karma: +60/-1
Re: EthernetGateway
« Reply #10 on: February 09, 2014, 05:09:25 pm »
Ok, that is bad behavior.

Anyone up for debugging Ethernet?

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 872
  • Karma: +66/-8
Re: EthernetGateway
« Reply #11 on: February 09, 2014, 05:46:04 pm »
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.


Offline MDoc

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +3/-3
Re: EthernetGateway
« Reply #12 on: February 09, 2014, 06:05:02 pm »
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

Offline mikewop

  • Sr. Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
Re: EthernetGateway
« Reply #13 on: February 11, 2014, 08:54:47 am »
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.

@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.


Offline a-lurker

  • Hero Member
  • *****
  • Posts: 872
  • Karma: +66/-8
Re: EthernetGateway
« Reply #14 on: February 11, 2014, 02:50:53 pm »
No need to power off anything. Just hit the reset button on the gateway and then restart the Luup engine.