Ethernet Issues

Expansion modules and attachments
Post Reply
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Ethernet Issues

Post by tanked_kiwi »

Hi everyone,

This is my first post here, I have had my RA up and running for about a week now, but have been reading on here for a while before I purchased.

I decided to forgo the wifi attachment when I bought my RA for 3 reasons, wifi strength where the tank is located is flakey, I already had a couple spare uno's lying round and the extra cost would've thrown my total over the customs tax threshold (NZ).

I have a switch 3m from the tank next to the computer so Ethernet seemed like the perfect choice.... perhaps not.

Ethernet seems to work for the most part, I can use the portal from home or away (Static Wan IP), likewise with the android app. Problem is I seem to get alot of errors using the portal, android app or xxx.xxx.xxx.xxx:2000/wifi. Sometimes loads fast, other times incredibly slow.

Also, my web chart and relay activity have never shown anything, they always remain blank.

Below is the Ethernet Code I'm using on my Uno:

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[] = { 
  0x08, 0xCE, 0x4C, 0xC4, 0x11, 0xC8 };
IPAddress ip(192,168,1,113);
IPAddress remoteserver(198,171,134,6);
EthernetClient clientout;
unsigned long lastmillisout=millis();
unsigned long lastmillisin=millis();
boolean sending=false;
char strout[600];

// 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()){
        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)-1);
      int b=Serial.readBytesUntil('\n',strout,sizeof(strout)-1);
      Serial.flush();
//      Serial.println(b);
//      Serial.println("Connecting");
      if (b>10)
      {
        sending=true;
//        Serial.println(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.println(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;
  }

}


And my RA Sketch:

Code: Select all

#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>

////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.SetTemperatureUnit( Celsius );  // set to Celsius Temperature

    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port3Bit | Port5Bit | Port6Bit | Port8Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port2Bit | Port4Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;


    // Ports that are always on
    ReefAngel.Relay.On( Port6 );
    ReefAngel.Relay.On( Port8 );

    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.ActinicLights( Port2 );
    ReefAngel.ActinicLights( Port4 );
    ReefAngel.SingleATO( true,Port5,10,1 );
    ReefAngel.StandardHeater( Port7 );    
    ReefAngel.PWM.Channel0PWMParabola();
    ReefAngel.PWM.Channel1PWMParabola();
    ReefAngel.PWM.Channel2PWMParabola();
    ReefAngel.PWM.Channel3PWMParabola();
    ////// Place your custom code below here
    

    ////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "tanked_kiwi" );
    ReefAngel.ShowInterface();
}


Any help would be much appreciated.

Evan
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Ethernet Issues

Post by rimai »

I remember at some point in the past I changed my code.
You can try my version:

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(198,171,134,6); // www.reefangel.com
EthernetClient clientout;
unsigned long lastmillisout=millis();
unsigned long lastmillisin=millis();
boolean sending=false;
char strout[600];

// 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()){
        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)-1);
      int b=Serial.readBytesUntil('\n',strout,sizeof(strout)-1);
      Serial.flush();
//      Serial.println(b);
//      Serial.println("Connecting");
      if (b>10)
      {
        sending=true;
//        Serial.println(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.println(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 /index.html HTTP/1.0

//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.
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Re: Ethernet Issues

Post by tanked_kiwi »

Ok thanks, have uploaded it now so I'll see how it runs. Still not seeing anything under relay activity or web chart on the portal though.
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Re: Ethernet Issues

Post by tanked_kiwi »

Still having the same issues with this.

What would cause the relay activity and web chart to be blank, even though everything else works?

Also, although it'd be a really expensive "upgrade" would the wifi module give me less grief? It usually takes 5-6 attempts to get the portal to display correctly, what would cause this?
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Ethernet Issues

Post by sabo »

That kinda sounds like a firewall issue. You've opened the port for incoming, but the 5 minute outbound update is getting blocked maybe?
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Re: Ethernet Issues

Post by tanked_kiwi »

Sounds possible, how would I deal with that?
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Ethernet Issues

Post by sabo »

Check your router/modem settings. If it has a firewall built in, try disabling it to see if the portal updates.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Ethernet Issues

Post by rimai »

I see data in your charts now :)
What did you do?
Roberto.
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Re: Ethernet Issues

Post by tanked_kiwi »

Ha, I was powering this off USB while I was messing with it. Last night I plugged the wall adapter into it as I needed my usb cable for something else. It seems it wasn't getting enough power to consistently update.

Has been working really well since. Good thing I needed that cable or I might never have figured it out..
SUCCESS!!

Thank you both for the help.
Post Reply