Ethernet with Arduino board
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
email sent
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Do you see any data now?
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Could you explain? Why \n here?
memset(strout,0,sizeof(strout));
int b=Serial.readBytesUntil('\n',strout,sizeof(strout));
// Serial.println(b);
// Serial.println("Connecting");
if (b>10)
memset(strout,0,sizeof(strout));
int b=Serial.readBytesUntil('\n',strout,sizeof(strout));
// Serial.println(b);
// Serial.println("Connecting");
if (b>10)
Re: Ethernet with Arduino board
\n means new line character.
So, the function is reading bytes until it finds \n, which means basically read the first line.
Because how HTTP protocol is structured, we only need to read the first line...
Everything else is just garbage to us. We are not interested.
But this section of the code deals with incoming connections and not outgoing.
Your incoming connection is good since you said that you can connect to RA just fine and the Portal also retrieves data just fine.
It's the outgoing that is not working.
You need to check if the board can even connect, because I don't see anything in the server logs.
So, the function is reading bytes until it finds \n, which means basically read the first line.
Because how HTTP protocol is structured, we only need to read the first line...
Everything else is just garbage to us. We are not interested.
But this section of the code deals with incoming connections and not outgoing.
Your incoming connection is good since you said that you can connect to RA just fine and the Portal also retrieves data just fine.
It's the outgoing that is not working.
You need to check if the board can even connect, because I don't see anything in the server logs.
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
I have two theories.
Either A: I need to add my gateway and sub net into the code
Or B: EthernetClient clientout; isn't outputting anything with clientout.print('strout');
Either A: I need to add my gateway and sub net into the code
Or B: EthernetClient clientout; isn't outputting anything with clientout.print('strout');
Re: Ethernet with Arduino board
Try using the clientout all by itself and send a string to any server and see if you get responses.
Send "GET /\n"to get the home page of the site.
Send "GET /\n"to get the home page of the site.
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Do this through the serial monitor with it hooked up to my USB to TTL cable?
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
I'll do this ASAP. I'm sure it's clientout related. Because I know the Ethernet board is connected. I have incoming control 100%. Output 0%
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Also on 00Warpig00 I noticed you had him pointing to an external IP of the server on port 80. Should I try this too?
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
That command returns nothing but doing this I get this:
EthernetClient clientout; HTTP/1.0
EthernetClient clientout; HTTP/1.0
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
By typing EThernetClient clientout(); it returned HTTP/1.0
GET /\n returns nothing.
GET /\n returns nothing.
Re: Ethernet with Arduino board
EThernetClient clientout(); is not even a valid HTTP request.
http://en.wikipedia.org/wiki/Hypertext_ ... r_Protocol
You need to send something like this:
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.
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
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.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
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
Re: Ethernet with Arduino board
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.
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.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Wow. That simple change worked. 100% functional. I had the wrong address for the remote server. Geeze
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
But BIG THANKS to Roberto !!!!!
Ethernet with Arduino board
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!!
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
I'll be doing a build list and pricing. I hope it will be an option for people too!
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
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
Connecting module with RA:
Connect the module with the wifi cable with the black cable to the outermost right side. Ignore the LED. I'm doing some testing...
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 )
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.
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
OR
Use below for security option (IF needed):
"key" must match on code and portal
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.
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
Connecting module with RA:
Connect the module with the wifi cable with the black cable to the outermost right side. Ignore the LED. I'm doing some testing...
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 )
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
ON REEFANGEL SIDE of code...
If not...add
Code: Select all
ReefAngel.Portal("username");
Use below for security option (IF needed):
"key" must match on code and portal
Code: Select all
ReefAngel.Portal("username","key");
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.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Thanks...BIG thanks to Roberto for being patient with me...I learned a lot!
-
- Posts: 289
- Joined: Wed May 16, 2012 9:52 pm
Re: Ethernet with Arduino board
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
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
20GH QT#1
29G QT#2
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
I agree. Because they are both arduino based it makes things a lot more simple.
Re: Ethernet with Arduino board
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
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.....
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.....
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
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"
-
- Posts: 289
- Joined: Wed May 16, 2012 9:52 pm
Re: Ethernet with Arduino board
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
Nick
180G FOWLR
20GH QT#1
29G QT#2
20GH QT#1
29G QT#2