Page 3 of 4

Ethernet with Arduino board

Posted: Tue Jan 08, 2013 6:22 pm
by lnevo
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!!

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 7:12 pm
by DrewPalmer04
I'll be doing a build list and pricing. :) I hope it will be an option for people too!

Re: Ethernet with Arduino board

Posted: Wed Jan 09, 2013 9:56 am
by DrewPalmer04
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.

Re: Ethernet with Arduino board

Posted: Wed Jan 09, 2013 10:02 am
by rimai
Awesome!!! :)

Re: Ethernet with Arduino board

Posted: Wed Jan 09, 2013 10:07 am
by DrewPalmer04
Thanks...BIG thanks to Roberto for being patient with me...I learned a lot!

Re: Ethernet with Arduino board

Posted: Wed Jan 09, 2013 6:36 pm
by 00Warpig00
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

Re: Ethernet with Arduino board

Posted: Wed Jan 09, 2013 6:39 pm
by DrewPalmer04
I agree. Because they are both arduino based it makes things a lot more simple.

Re: Ethernet with Arduino board

Posted: Fri Jan 11, 2013 7:54 am
by MDN
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

Re: Ethernet with Arduino board

Posted: Fri Jan 11, 2013 7:57 am
by DrewPalmer04
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"

Re: Ethernet with Arduino board

Posted: Fri Jan 11, 2013 11:08 pm
by 00Warpig00
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

Re: Ethernet with Arduino board

Posted: Thu Apr 04, 2013 10:54 am
by pandimus
A few questions regarding this thread.. First off good job both of you. lots of hard work. My question is. Are you using the arduino board for pwm also? Like dimming LED's? Are you fully comunicating with the arduino board, i/e can do more stuff with its processor?

thank you

Johnny

Re: Ethernet with Arduino board

Posted: Thu Apr 04, 2013 2:49 pm
by DrewPalmer04
Not fully communication. It's a stand alone. But look at my other thread PWM output on Ethernet module and it contains my simple code for PWM output/LED control

Re: Ethernet with Arduino board

Posted: Thu Apr 04, 2013 3:52 pm
by pandimus
Can it do both I/e pwm and Ethernet?

Re: Ethernet with Arduino board

Posted: Thu Apr 04, 2013 3:58 pm
by DrewPalmer04
Yes. It's in the other thread on this fourm

Re: Ethernet with Arduino board

Posted: Wed Jun 26, 2013 11:23 am
by Drs1210
Does anybody else have this running on their RA? I'm experiencing problems when I hook it up the the RA. :?

Re: Ethernet with Arduino board

Posted: Thu Jun 27, 2013 12:42 am
by Drs1210
Anybody?

Re: Ethernet with Arduino board

Posted: Sun Jun 30, 2013 3:32 am
by arch
I built one this evening. Though I used an arduino uno and ethernet shield I had for another project.
Seems to all be working OK. What's the problem?

Re: Ethernet with Arduino board

Posted: Sun Jun 30, 2013 7:09 am
by DrewPalmer04
He has a spastic water level expansion when the Ethernet option is plugged in. This option is pretty universal with any Ethernet shield combo.

Re: Ethernet with Arduino board

Posted: Sun Jun 30, 2013 9:37 am
by Drs1210
I also had my red status light blinking, and my ph would bounce a little bit.

Re: Ethernet with Arduino board

Posted: Sun Jun 30, 2013 7:22 pm
by arch
Those using an Arduino without a 6 pin connector (i.e. not linked to the RA using the wifi cable - as recommended by DrewPalmer04), might find the following useful:

The wiring to connect the RA to the Ethernet add-on is as follows:

RA Pin 1 (on RHS of controller) - GND (Black WIFI Cable) – to Arduino GND
RA Pin 4 - RX (Blue WIFI Cable) – to Arduino TX (Digital Pin 1)
RA Pin 5 – TX (Yellow WIFI Cable) – to Arduino RX (Digital Pin 0)
RA Pin 7 - 5V (Red WIFI Cable) – to Arduino 5V

Re: Ethernet with Arduino board

Posted: Sun Jun 30, 2013 7:33 pm
by arch
Everything is working nicely with my new Ethernet add-on so far (thanks DrewPalmer04) ....except....

I can't control the RA with the iphone app (which was working with wifi - now get "Error Unable to connect"). The portal and android app seem to work fine - any ideas what the difference might be?

Re: Ethernet with Arduino board

Posted: Mon Jul 01, 2013 6:28 am
by DrewPalmer04
Double check WAN IP and port under "settings" at the bottom

Re: Ethernet with Arduino board

Posted: Tue Jul 02, 2013 2:15 pm
by arch
Yeah IP is fine.

I see over at the iphone app thread you're reporting the same problem.

Must be the new tags - I'd just attributed it to the ethernet add-on because I started having problems when I swapped over.

Re: Ethernet with Arduino board

Posted: Tue Jul 02, 2013 2:46 pm
by DrewPalmer04
Yes...just encountered the issue. I'm thinking XML tags. I wish I had a dev account :( hope the others come up with a release ASAP.

Re: Ethernet with Arduino board

Posted: Wed Jul 03, 2013 4:18 pm
by arch
Well i reconnected my wifi module and the iphone app works again - so if it is the extra xml tags, it appears to effect the ethernet add-on specifically?

I've actually had another related issue to contend with too - my dyndns hostname expired. Apparently dyn.com have changed their policies re free accounts - you now need to login to their website monthly to keep it active "using an update client will no longer suffice for this monthly login".

Re: Ethernet with Arduino board

Posted: Wed Jul 03, 2013 6:31 pm
by DrewPalmer04
I've tried resets and my WAN IP and dyndns and after a couple days of testing it would consistently crash...now today...working perfectly. Lol sooooooo weird!!!!

Re: Ethernet with Arduino board

Posted: Wed Jul 03, 2013 6:36 pm
by DrewPalmer04
It is definitely app specific. I've never lost data to the RA server. So it's not the Ethernet module... I've had a consistent data pool throughout.

Re: Ethernet with Arduino board

Posted: Tue May 20, 2014 10:52 am
by carlii
So I have a question for those using the RJ45 Ethernet module. What are you using as a case to protect the module?

Re: Ethernet with Arduino board

Posted: Tue May 20, 2014 9:09 pm
by paulvisco

Re: Ethernet with Arduino board

Posted: Wed May 21, 2014 4:44 am
by carlii
Thanks.