Ethernet with Arduino board

Expansion modules and attachments
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Jan 08, 2013 6:22 pm
Congrats! So now there are two different methods for creating an ethernet interface? Curious to hear what the build/cost/part will be for those looking to reproduce. Or will we be seeing an ethernet module in the store soon. Will be great to have both options available for people at checkout!!! One more reason to go Reef Angel!!
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Tue Jan 08, 2013 7:12 pm
I'll be doing a build list and pricing. :) I hope it will be an option for people too!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Wed Jan 09, 2013 9:56 am
For those who wish to do this build: BUILD LIST/Instructions

Item list:
Arduino Ethernet w/o POE:$54.95 + $12.54 shipping:Link to buy Arduino Ethernet (or your favorite retailer).
Wifi cable: $13/shipped (via Roberto)
Ethernet cable to reach the distance for your application: $10+
Router able to port forward to your ethernet module's assigned IP: $?
Coding: FREE :)

First thing is first:
You can upload your code via the USB to TTL cable that came with your RA or get the USB to Serial adaptor breakout for the Ethernet module. (Additional $15-ish) I used the breakout method.

Overall, I did this build for $105.49 but you could do it cheaper. I wasn't looking to save money. I just wanted the stability :geek:

Connecting module with RA:
Image
Connect the module with the wifi cable with the black cable to the outermost right side. Ignore the LED. I'm doing some testing...

Image

Do the same on the RA head unit with the black to the outermost right.
Test that your Ethernet module powers up and then we are ready for uploading!! (NO my status light isn't on :lol: )

Remove module from that end of the wifi cable and prep for upload on your computer via which method you'd like.

You will need to download the arduino software from here: http://arduino.cc/en/Main/Software

Here is the 100% working code: Stable for days and because it assigns a static IP, I think I'll be golden! Check the //comments within the code to give you direction of what to modify for your network.
Code: Select all
/*
  Web Server

A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

*/

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // your mac address on the back sticker of the module
IPAddress ip(192,168,1, 113);
IPAddress remoteserver(198,171,134,6); // forum.reefangel.com (correct address)
EthernetClient clientout;
unsigned long lastmillisout=millis();
unsigned long lastmillisin=millis();
boolean sending=false;
char strout[400];

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80); // must be port forwarding 80 to the IP address of the module. IE: 192.168.1.113

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
//  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
//    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      while (client.available()) {
        char c = client.read();
        if (sending==false) Serial.write(c);
        lastmillisin=millis();       
      }
      while (Serial.available()){
        memset(strout,0,sizeof(strout));
        int b=Serial.readBytesUntil('>',strout,sizeof(strout));
//        Serial.flush();
        client.print(strout);
        client.print(">");
//        char c = Serial.read();
//        client.print(c);
        if (millis()-lastmillisin>2000)
        {
//          Serial.println("Timeout incoming");
          Serial.flush();
          lastmillisin=millis();
          client.stop();
        }
      }
      if (millis()-lastmillisin>2000)
      {
//        Serial.println("Timeout incoming");
        Serial.flush();
        lastmillisin=millis();
        client.stop();
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    //    Serial.println("client disonnected");
  }
  else
  {
    if (Serial.available())
    {
      memset(strout,0,sizeof(strout));
      int b=Serial.readBytesUntil('\n',strout,sizeof(strout));
     
//      Serial.println(b);
//      Serial.println("Connecting");
      if (b>10)
      {
        sending=true;
        Serial.print(strout);
        Serial.println(" HTTP/1.0");
        Serial.println();
        if (clientout.connect(remoteserver, 80)) //port 80 here again! remote server is the RA forum above
        {
//          Serial.println("Connected");
          //        while (Serial.available()){
          //          char c = Serial.read();
          //          clientout.print(c);
          //        }
          clientout.print(strout);
          clientout.println(" HTTP/1.0");
          clientout.println();
          lastmillisout=millis();
        }
      }
    }
    while (clientout.available()) {
      char c = clientout.read();
      Serial.print(c);
      if (millis()-lastmillisout>8000)
      {
//        Serial.println("Timeout connected");
        lastmillisout=millis();
        clientout.stop();
        sending=false;
      }
    }
    if (!clientout.connected())
    {
      clientout.stop();
      sending=false;
    }
  }
  if (millis()-lastmillisout>8000)
  {
//    Serial.println("Timeout global"); //can remove comment if you'd like timeouts via serial monitor
    lastmillisout=millis();
    clientout.stop();
    sending=false;
  }

}

//GET /status/submitp.aspx?t1=806&t2=0&t3=0&ph=441&id=test&em=0&rem=0&key=&atohigh=0&atolow=0&r=0&ron=0&roff=255 HTTP/1.0

//GET /status/submitp.asp?t1=806&t2=0&t3=0&ph=441&id=test&em=0&rem=0&key=&atohigh=0&atolow=0&r=0&ron=0&roff=255 HTTP/1.0
//Host: forum.reefangel.com
//
//GET /status/submitp.aspx?t1=806&t2=0&t3=0&ph=441&id=test&em=0&rem=0&key=&atohigh=0&atolow=0&r=0&ron=0&roff=255 HTTP/1.0
//Host: forum.reefangel.com
//Connection: Keep-Alive


Plug module back into wifi cable and log into portal to see if your banner and (live) portal is working.
ON REEFANGEL SIDE of code...

If not...add
Code: Select all
ReefAngel.Portal("username");


OR

Use below for security option (IF needed):
"key" must match on code and portal
Code: Select all
ReefAngel.Portal("username","key");


to your existing RA code at the end of your loop but NOT after ReefAngel.ShowInterface();

Now, change your portal Reef Angel wifi address to your EXTERNAL WAN IP + port: [IE: 108.176.200.90:0080]
(0080 avoids portal "bug" because it is expecting a four digital number IE: 2000)

You're now set up and have the stability of the ethernet connection.
Last edited by DrewPalmer04 on Fri Mar 29, 2013 8:35 am, edited 11 times in total.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative

Posts: 12507
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Wed Jan 09, 2013 10:02 am
Awesome!!! :)
Roberto.
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Wed Jan 09, 2013 10:07 am
Thanks...BIG thanks to Roberto for being patient with me...I learned a lot!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative

Posts: 289
Joined: Wed May 16, 2012 9:52 pm
PostPosted: Wed Jan 09, 2013 6:36 pm
So thats all there is to it...
Buy an Arduino Ethernet board
modify code to reflect your network settings
upload modified code using USB TTL cable to Ethernet module
plug in to your RA and your ethernet
test?

Thats allot easier than the Wiznet module if you are already experienced enough with the RA or Arduino to upload the code to the Ethernet board.

Seems price of Arduino Ethernet module is nearly the same as the two boards needed to do the Wiznet 105SR module and no soldering or electronics experience needed.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Wed Jan 09, 2013 6:39 pm
I agree. Because they are both arduino based it makes things a lot more simple.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative

Posts: 33
Joined: Wed Jan 09, 2013 8:18 pm
PostPosted: Fri Jan 11, 2013 7:54 am
DrewPalmer04,
So this is great - having more options is always a good thing. But I have a question, you mention you want something more reliable. Is the wireless module really that unreliable ? Have you tested it ?
I know wireless is wireless and never as guaranteed as a wired connection but these days wireless is pretty stable, at least in your own home.
Just wanted to get your thoughts.
Thanks
----------------------------------
75G with 30G sump | 52 LED - RapidLED Lighting (DIY) |
ReefAngel for Meanwell ELN-D Drivers | Reef Octopus HOB-1000
Way to much time and money invested.....

Image
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Fri Jan 11, 2013 7:57 am
The wifi IS getting better with firmware updates and changes as they come available. But because I had an Ethernet jack near my tank. I figured. "why not"
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative

Posts: 289
Joined: Wed May 16, 2012 9:52 pm
PostPosted: Fri Jan 11, 2013 11:08 pm
Not sure exactly what the issue is with the wireless disconnecting and failing to reconnect. Roving Networks has confirmed a flaw in the firmware that has not been officially resolved yet. It does not appear that this issue effects ALL users of the wifi module. Seems very hit or miss. I travel allot for work and my number one reason for a controller was to have peace of mind when I'm away. I happen to be one of the unlucky ones who has chronic issues with my wifi module loosing connection and this issue has been a huge repeated cause of frustration to me. Is it the fact that I have many RA add on's? maybe... Is it the WiFi module? maybe... The router? maybe... I do have a high density of Wifi AP's in my area... interference with other wifi routers? Maybe... a combination of things? maybe... they sure don't seem to like each other at times, but it also seems others have no trouble at all! I have also now have an Ethernet setup on my RA for over a week without a single issue with my connection thus far. I cant say for sure the wifi module is bad... but mine sure as hell doesn't like to work with the reliability I expect out of a network connection of any sort. The most reliable connection is ALWAYS a hard connection. In my case reliability is #1 Hopefully the two Ethernet Mods that are working at this point will at least give those that ARE experiencing Wifi connection issues an alternative... Before there really wasn't much of an alternative.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
PreviousNext

Return to Addons

Who is online

Users browsing this forum: No registered users and 3 guests

cron