Page 2 of 4

Re: Ethernet with Arduino board

Posted: Fri Jan 04, 2013 9:39 am
by DrewPalmer04
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)

Re: Ethernet with Arduino board

Posted: Fri Jan 04, 2013 12:18 pm
by DrewPalmer04
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

Posted: Sat Jan 05, 2013 8:00 am
by binder
DrewPalmer04 wrote:would we need to change the code IF I added an SD card? This might help with the memory condition?
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.

Re: Ethernet with Arduino board

Posted: Sat Jan 05, 2013 8:23 am
by DrewPalmer04
Correct. So we need to reduce the RAM use age. I think that's causing corruption.

Re: Ethernet with Arduino board

Posted: Sat Jan 05, 2013 8:42 am
by binder
DrewPalmer04 wrote:Correct. So we need to reduce the RAM use age. I think that's causing corruption.
Yeah, it can and does cause corruption. I've encountered that first hand.

Re: Ethernet with Arduino board

Posted: Sat Jan 05, 2013 8:44 am
by DrewPalmer04
I've messed with the code a lot. So I'm not sure how to get by this issue.

Re: Ethernet with Arduino board

Posted: Sun Jan 06, 2013 7:45 am
by DrewPalmer04
Any chance you had to mess with your Ethernet module Roberto?

Re: Ethernet with Arduino board

Posted: Sun Jan 06, 2013 5:17 pm
by rimai
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


Re: Ethernet with Arduino board

Posted: Mon Jan 07, 2013 6:31 am
by DrewPalmer04
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.

Re: Ethernet with Arduino board

Posted: Mon Jan 07, 2013 10:53 am
by DrewPalmer04
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

Re: Ethernet with Arduino board

Posted: Mon Jan 07, 2013 11:42 am
by rimai
I don't see any of your connections....
Can you sniff?

Re: Ethernet with Arduino board

Posted: Mon Jan 07, 2013 12:12 pm
by DrewPalmer04
email sent

Re: Ethernet with Arduino board

Posted: Mon Jan 07, 2013 8:25 pm
by DrewPalmer04
Do you see any data now?

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 2:07 pm
by DrewPalmer04
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)

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 3:12 pm
by rimai
\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.

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 3:39 pm
by DrewPalmer04
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');

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 3:53 pm
by rimai
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.

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 3:56 pm
by DrewPalmer04
Do this through the serial monitor with it hooked up to my USB to TTL cable?

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 3:57 pm
by rimai
yeap

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 4:01 pm
by DrewPalmer04
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%

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 4:07 pm
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?

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 4:29 pm
by DrewPalmer04
That command returns nothing but doing this I get this:

EthernetClient clientout; HTTP/1.0

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 4:44 pm
by rimai
Huh? Doing what?

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 4:54 pm
by DrewPalmer04
By typing EThernetClient clientout(); it returned HTTP/1.0

GET /\n returns nothing.

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 4:59 pm
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

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 5:01 pm
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

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 5:04 pm
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.

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 5:10 pm
by DrewPalmer04
Ok :)

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 5:45 pm
by DrewPalmer04
Wow. That simple change worked. 100% functional. I had the wrong address for the remote server. Geeze

Re: Ethernet with Arduino board

Posted: Tue Jan 08, 2013 5:50 pm
by DrewPalmer04
But BIG THANKS to Roberto :)!!!!!