UIPEthernet to etherShield library

Hi everyone! I am using this code to post data to MySql database every 10 seconds by executing insert_mysql.php, this one works perfectly. But what I want now is to use the library etherShield.h and ETHER_28j60.h. Is there any equivalent code for this that works with those 2 libraries? I want to change the library that I am using because I am having problems when I use the UIPEhthernet library. For example: when i used the UIP library to control an LED using a browser, there is a delay when I pressed the ON or OFF button and sometimes the browser is just loading and unable to control the LED but when I used the etherShield and ETHER_28j60 library, controlling the LED using a browser works perfectly without delay.

Is it possible to combine a web server (controlling LED using web browser) and web client (POST data to MySQL)??? If yes, do you have any example using the library etherShield.h and ETHER_28j60.h THANKS :slight_smile:

#include <UIPEthernet.h>

long previousMillis = 0;
long interval = 10000;  

EthernetClient client;
char server[] = "192.168.10.4"; 
IPAddress ip(192, 168, 10, 5);
String yourdatacolumn = "yourdata=";
String yourdata;

void setup()                    // run once, when the sketch starts
{
  uint8_t mac[6] = {
    0x00,0x01,0x02,0x03,0x04,0x05  };
  Ethernet.begin(mac);
}
void loop()                     // run over and over again
{

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;

    yourdata = yourdatacolumn ;
    client.connect(server, 80);
    Serial.println("Connecting to server database...");
    client.println("POST /arduino/insert_mysql.php HTTP/1.1");
    client.println("Host:192.168.10.4 ");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(yourdata.length());
    client.println();
    client.println(yourdata); 
    Serial.println("Connection Successful!");
    client.stop();
  }

}

adding a call to Ethernet.maintain() to loop, outside the 'if(currentMillis - previousMillis > interval) {...}' block might solve your issues.

But that is just a guess as you do not include the complete code (including the LED-control you mention in your post).

Okay. Ill try that one.
Is it possible to use those library at the same time?

Sometimes I also get request time out and destination host unreachable reply from my arduino ethernet shield

You want to know whether it's possible to use UIPEthernet and Ethershield in the same sketch? No, you cannot - they will certainly conflict on enc28j60 internal memory.

  • Norbert

No, you cannot

okay, In that case, is it possible to convert these codes that uses etherShield.h and ETHER_28j60.h library.

#include <UIPEthernet.h>

long previousMillis = 0;
long interval = 10000;  

EthernetClient client;
char server[] = "192.168.10.4"; 
IPAddress ip(192, 168, 10, 5);
String yourdatacolumn = "yourdata=";
String yourdata;

void setup()                    // run once, when the sketch starts
{
  uint8_t mac[6] = {
    0x00,0x01,0x02,0x03,0x04,0x05  };
  Ethernet.begin(mac);
}
void loop()                     // run over and over again
{

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;

    yourdata = yourdatacolumn ;
    client.connect(server, 80);
    Serial.println("Connecting to server database...");
    client.println("POST /arduino/insert_mysql.php HTTP/1.1");
    client.println("Host:192.168.10.4 ");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(yourdata.length());
    client.println();
    client.println(yourdata); 
    Serial.println("Connection Successful!");
    client.stop();
  }

}

I want to merge the codes above with this one

#include "etherShield.h"
#include "ETHER_28J60.h"

int led2 = 7;
int led1 = 6;


static uint8_t mac[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xBB, 0xAA};   // this just needs to be unique for your network,
                                                                // so unless you have more than one of these boards
                                                                // connected, you should be fine with this value.
                                                          
static uint8_t ip[4] = {192, 168, 0, 15};                       // the IP address for your board. Check your home hub
                                                                // to find an IP address not in use and pick that
                                                                // this or 10.0.0.15 are likely formats for an address
                                                                // that will work.
static uint16_t port = 80;                                      // Use port 80 - the standard for HTTP

ETHER_28J60 e;

void setup()
{
    e.setup(mac, ip, port);
   
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
   
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);

 
}

void loop()
{
  char* params;
  if (params = e.serviceRequest())
  {
    if (strcmp(params, "?cmd=1") == 0)
    {
          digitalWrite(led1, HIGH);
    }
    if (strcmp(params, "?cmd=2") == 0)
    {
          digitalWrite(led1, LOW);
         
    }
    if (strcmp(params, "?cmd=3") == 0)
    {
          digitalWrite(led2, HIGH);
    }
    if (strcmp(params, "?cmd=4") == 0)
    {
          digitalWrite(led2, LOW);
         
    }
   
    e.respond();
  }
}

I prefer to use etherShield.h and ETHER_28j60.h instead of using UIPEthernet.h

Can you give me sketch that will execute a PHP file using etherShield.h and ETHER_28J60.h library. I really need to merge this 2 sketches. thankyou so much.

Sometimes I also get request time out and destination host unreachable reply from my arduino ethernet shield

What will I do with this one? is it possible to reconnect the arduino ethernet shield to the network without restarting it? I mean, ones it got disconnected to the network I want it to reconnect automatically.

jason2015:
is it possible to reconnect the arduino ethernet shield to the network without restarting it? I mean, ones it got disconnected to the network I want it to reconnect automatically.

generally speaking a restart is not required to reconnect.

jason2015:
Can you give me...

may I ask you do do some of my work if I do?

may I ask you do do some of my work if I do?

I mean, if you have any link or tutorials that can help me with my problem. I will really appreciate it.

generally speaking a restart is not required to reconnect.

I wait for a long time for the arduino to reconnect but it didnt but after restarting it I can ping it again. Maybe because of this:

void setup()                    // run once, when the sketch starts
{
  uint8_t mac[6] = {
    0x00,0x01,0x02,0x03,0x04,0x05  };
  Ethernet.begin(mac);
}

It needs to initialize again the ethernet shield for it to reconnect. is that right?

What will I do to merge those 2 sketches using etherShield.h and ETHER_28J60.h

jason2015:
I wait for a long time for the arduino to reconnect but it didnt but after restarting it I can ping it again.[...]It needs to initialize again the ethernet shield for it to reconnect. is that right?

No that is not right. From my understanding you should be just fine testing the return-value of 'client.connect() > 0' and only write to client if connect succeeded. It is possible that in your case the connect-method itself takes very long to return (the tcp-timeouts is several minutes which may be longer than you expect ...)

regards,

Norbert

the tcp-timeouts is several minutes which may be longer than you expect

do you mean i just need to wait longer for it to reconnect?

What will I do to merge those 2 sketches using etherShield.h and ETHER_28J60.h

Do you have any link or tutorials that uses etherShield or ETHER_28j60 library for executing PHP file similar to what I have posted but using UIPEthernet library. I really need it. thanks for the help

Do you have any link or tutorials that uses etherShield or ETHER_28j60 library for executing PHP file similar to what I have posted but using UIPEthernet library. I really need it. thanks for the help