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 »

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)
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 »

would we need to change the code IF I added an SD card? This might help with the memory condition?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Ethernet with Arduino board

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

Re: Ethernet with Arduino board

Post by DrewPalmer04 »

Correct. So we need to reduce the RAM use age. I think that's causing corruption.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Ethernet with Arduino board

Post 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.
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've messed with the code a lot. So I'm not sure how to get by this issue.
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 »

Any chance you had to mess with your Ethernet module Roberto?
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 »

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.
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 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.
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 »

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
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 »

I don't see any of your connections....
Can you sniff?
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 »

email sent
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 »

Do you see any data now?
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 »

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)
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 »

\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.
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 »

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');
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 »

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.
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 »

Do this through the serial monitor with it hooked up to my USB to TTL cable?
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 »

yeap
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 »

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%
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 »

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