Page 1 of 4

Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:21 am
by DrewPalmer04
Ok I have an open port on 80 and my IP is set. But I can not get the portal to find my ethernet board? "Unreachable" Do I have to use 2000?

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:28 am
by rimai
I split your post to separate the two options.
Yes, just change the code to 2000 instead of 80...
Make sure you have port forwarding on your router or the server won't be able to connect to your board.
Simplest way to test is just to browse http://IPADDRESS:PORT
This should give you "Reef Angel Controller Web Server"

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:35 am
by DrewPalmer04
Ok I've changed to 2000...port is open and pointed to 192.168.1.114...still "unreachable" I tested with http://192.168.1.114:2000 and I get the Reef Angel Controller Web Server with no problem

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:36 am
by rimai
What do you get browsing:
http://192.168.1.114:2000/r99

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:37 am
by DrewPalmer04
There is a problem:
This page contains the following errors:

error on line 1 at column 161: Opening and ending tag mismatch: WMA line 0 and PMA
Below is a rendering of the page up to the first error.

81169977586224802550000

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:40 am
by rimai
Seems you are getting data corruption somehow.
Can you sniff the packets and send me the capture or PM me your wan ip?

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:46 am
by DrewPalmer04
how do I sniff the packets?

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:49 am
by rimai

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 11:51 am
by DrewPalmer04
ok working on it...I can see the issue by refreshing the r99 page...I recognize the ATOHIGH, etc etc but it's failing

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 12:02 pm
by DrewPalmer04
PM SENT

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 12:08 pm
by rimai
I can see it's getting corrupted towards the end of the string.

Code: Select all

<RA><T1>804</T1><T2>698</T2><T3>773</T3><PH>862</PH><R>248</R><RON>0</RON><ROFF>255</ROFF><ATOLOW>0</ATOLOW><ATOHIGH>0</ATOHIGH><EM>0</EM><REM>0</REM><PWMA>84/PWM><PWM>76<PWMD</RA
It starts messing up when it reaches PWMA

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 12:11 pm
by DrewPalmer04
What to do?

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 12:32 pm
by rimai
Try increasing this:

Code: Select all

if (millis()-lastmillisin>2000)
to like 3000 or 4000
There are 2 places to change.

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 2:35 pm
by DrewPalmer04
Tried 3000 and 4000 and no change.

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 3:31 pm
by DrewPalmer04
I've messed with it quite a bit. Random data corruption. Weird

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 3:33 pm
by DrewPalmer04
Here's what I have now.

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[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0x28, 0x0E };
IPAddress ip(192,168,1,200);
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(2000);

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()){
        char c = Serial.read();
        client.print(c);
        if (millis()-lastmillisin>4000)
        {
          Serial.println("Timeout incoming");
          Serial.flush();
          lastmillisin=millis();
          client.stop();
        }
      }
      if (millis()-lastmillisin>4000)
      {
        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, 2000)) 
        {
          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: Wed Jan 02, 2013 5:16 pm
by DrewPalmer04
Any thoughts? Could it be the code itself? Cable? The RA head unit?

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 6:55 pm
by rimai
I don't know man...
It must be something in the serial stream or possibly baud rate mismatch.
This is probably caused by a slight shift in the crystal oscillator, which will cause the baud rate to shift slightly too, but if two are communicating a a preset value, the shift may be too much.
I'll see if I can load my board again during the weekend.

Re: Ethernet with Arduino board

Posted: Wed Jan 02, 2013 7:16 pm
by DrewPalmer04
Cool. I'll keep playing with it

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 1:26 pm
by DrewPalmer04
Just wanted to check what my board type should be. Should I set to arduino UNO Ethernet or? That could be my issue even though I have no trouble uploading code. ?

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 1:30 pm
by rimai
It doesn't make a difference... the mcu is the same.
Your Arduino IDE doesn't even have Arduino boards listed.

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 1:55 pm
by DrewPalmer04
ok...with the stock webserver sketch I can get the output to work perfectly...but it's not the correct format...so I know it has to do with the code you supplied earlier..I'm just trying to figure out what part is wrong

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 3:46 pm
by DrewPalmer04
Are the //GET commands correct? I was about to look into those

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 3:51 pm
by rimai
Should be

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 4:10 pm
by DrewPalmer04
Ok I'll keep looking.

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 4:47 pm
by DrewPalmer04
Everything looks perfect in the code...dang... I'm not sure what's going on here. but I'll just have to wait and see what you come up with :(

Re: Ethernet with Arduino board

Posted: Thu Jan 03, 2013 6:18 pm
by DrewPalmer04
Thought! Anyway to increase the delay of serial read and the write or print? If we increase the delay there is less chance of corruption.

So not the frequency of the read (milli) but a delay between read/write

Re: Ethernet with Arduino board

Posted: Fri Jan 04, 2013 8:28 am
by DrewPalmer04
Just an update: I plugged in the USB to TTL cable, launched command GET /r99 and returns the proper format with no errors on the serial monitor..so the ethernet module is to blame not the RA itself.

Re: Ethernet with Arduino board

Posted: Fri Jan 04, 2013 9:02 am
by rimai
Did you try decreasing the baud rate?
You will need to decrease on both boards.
In RA code, I'm pretty sure you can just end and begin a new rate like this:

Code: Select all

Serial.end();
Serial.begin(19200);
It must be in the setup() and it must be after ReefAngel.Init()

Re: Ethernet with Arduino board

Posted: Fri Jan 04, 2013 9:02 am
by DrewPalmer04
That's a good point. Trying now