Ethernet with Arduino board
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
no good. I think this has to do more with a out-of-memory condition? I mean an array of 400 and only 2,000RAM? What's the need for the large array?
(yes I've been doing a lot of research lol)
(yes I've been doing a lot of research lol)
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
would we need to change the code IF I added an SD card? This might help with the memory condition?
Re: Ethernet with Arduino board
SD Card would only help if we stored data on the device. The memory is RAM built on board of the device. No way to increase that unless you physically changed the device or bought one with larger RAM on it.DrewPalmer04 wrote:would we need to change the code IF I added an SD card? This might help with the memory condition?
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Correct. So we need to reduce the RAM use age. I think that's causing corruption.
Re: Ethernet with Arduino board
Yeah, it can and does cause corruption. I've encountered that first hand.DrewPalmer04 wrote:Correct. So we need to reduce the RAM use age. I think that's causing corruption.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
I've messed with the code a lot. So I'm not sure how to get by this issue.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Any chance you had to mess with your Ethernet module Roberto?
Re: Ethernet with Arduino board
Try this:
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, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress ip(192,168,1, 177);
IPAddress remoteserver(69,198,171,165); // forum.reefangel.com
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);
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);
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.flush();
// 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))
{
// 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");
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
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Thanks to Roberto. The Arduino ethernet module is an official "add-on." Connected to the portal, fully functional (minus web banners?), and I thank Roberto so much.
I'll be testing stability for the next few weeks and report back.
I'll be testing stability for the next few weeks and report back.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Ethernet with Arduino board
Another "DUH" question...I'd added the ReefAngel.Portal("DrewPalmer04"); to the RA and no banner updates...thoughts? Last update was from the COM port and the Client Suite
- 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 !!!!!