Ethernet with Arduino board

Expansion modules and attachments
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

Also on 00Warpig00 I noticed you had him pointing to an external IP of the server on port 80. Should I try this too?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

That command returns nothing but doing this I get this:

EthernetClient clientout; HTTP/1.0
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Ethernet with Arduino board

Post by rimai »

Huh? Doing what?
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

By typing EThernetClient clientout(); it returned HTTP/1.0

GET /\n returns nothing.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Ethernet with Arduino board

Post by rimai »

EThernetClient clientout(); is not even a valid HTTP request.
http://en.wikipedia.org/wiki/Hypertext_ ... r_Protocol
You need to send something like this:

Code: Select all

 GET /index.html HTTP/1.1
 Host: www.example.com
But in our case, we don't care about the host, since we send to a single host anyway.
Also, looking at the code again, you do need to use host ip 198.171.134.6 or it won't work.

Code: Select all

IPAddress remoteserver(198,171,134,6); // www.reefangel.com
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

Oh duh HTTP protocol. Sorry. I guess I didn't fully understand what you needed me to do. Ok I'll change the remote IP
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Ethernet with Arduino board

Post by rimai »

Ah, one more thing...
If using the Serial Monitor, you need to make sure you set to send Both CR & LF. I forgot \n doesn't work in there.
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

Ok :)
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

Wow. That simple change worked. 100% functional. I had the wrong address for the remote server. Geeze
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

But BIG THANKS to Roberto :)!!!!!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Ethernet with Arduino board

Post 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!!
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

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
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post 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.
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
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Ethernet with Arduino board

Post by rimai »

Awesome!!! :)
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

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
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Ethernet with Arduino board

Post 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
180G FOWLR
20GH QT#1
29G QT#2

Image
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

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
MDN
Posts: 33
Joined: Wed Jan 09, 2013 8:18 pm

Re: Ethernet with Arduino board

Post 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
----------------------------------
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
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post 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"
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Ethernet with Arduino board

Post 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
180G FOWLR
20GH QT#1
29G QT#2

Image
pandimus
Posts: 213
Joined: Mon Apr 01, 2013 7:58 pm

Re: Ethernet with Arduino board

Post 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
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post 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
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
pandimus
Posts: 213
Joined: Mon Apr 01, 2013 7:58 pm

Re: Ethernet with Arduino board

Post by pandimus »

Can it do both I/e pwm and Ethernet?
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

Yes. It's in the other thread on this fourm
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
Drs1210

Re: Ethernet with Arduino board

Post by Drs1210 »

Does anybody else have this running on their RA? I'm experiencing problems when I hook it up the the RA. :?
Drs1210

Re: Ethernet with Arduino board

Post by Drs1210 »

Anybody?
User avatar
arch
Posts: 20
Joined: Sun Mar 10, 2013 12:22 am

Re: Ethernet with Arduino board

Post 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?
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Ethernet with Arduino board

Post 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.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
Drs1210

Re: Ethernet with Arduino board

Post by Drs1210 »

I also had my red status light blinking, and my ph would bounce a little bit.
User avatar
arch
Posts: 20
Joined: Sun Mar 10, 2013 12:22 am

Re: Ethernet with Arduino board

Post 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
Post Reply