ENC28J60 Arduino Nano Web Client Problem

Hi! I am trying to send some data to php page but I couldn’t do this

The working statement is
http://192.168.0.31/sensorupdate.php?id=2&temp=20&hum=60&air=90

I want to do the same thing with my arduino,

I tried two different code blocks but none of them are worked :frowning:
Code 1 :

#include <UIPEthernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.31"; // IP Adres (or name) of server to dump data to
int  interval = 5000; // Wait between dumps

void setup() {

  Serial.begin(9600);
  Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
}

void loop() {
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET sensorupdate.php?");
    client.print("id=2&temp=20&hum=60&air=90");
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  delay(interval);
}

OUTPUT:

Tweaking4All.com - Temperature Drone - v2.0
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

IP Address        : 192.168.0.28
Subnet Mask       : 255.255.255.0
Default Gateway IP: 192.168.0.1
DNS Server IP     : 46.197.15.60
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected

Code 2 :

#include <UIPEthernet.h>

long previousMillis = 0;
long interval = 10000;

EthernetClient client;
char server[] = "192.168.0.31";
IPAddress ip(192, 168, 0, 66);
String sensorData = "?id=2&temp=23&hum=63&air=93";

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);
  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;

    Serial.println("Connecting to server database...");
    if (client.connect(server, 80))
    {
      client.println("POST /sensorupdate.php?id=2&temp=20&hum=60&air=90 HTTP/1.1");
      client.println("Host:192.168.0.31");
      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(sensorData.length());
      client.println();
      client.println(sensorData);
      client.println();
      */
      Serial.println("Connection Successful!");
      client.stop();
    }
    else
    {
      Serial.println("Connection Not Successful!");
    }

  }

}

It also did not worked :frowning:

What is wrong with this code ?

My shield is :

Thanks a lot

OK I forgot the “/” :slight_smile:

The working code is here:

#include <UIPEthernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.31"; // IP Adres (or name) of server to dump data to
int  interval = 5000; // Wait between dumps

void setup() {

  Serial.begin(9600);
  Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
}

void loop() {
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /sensorupdate.php?");
    client.print("id=1&temp=20&hum=60&air=90");
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  delay(interval);
}

boraciner:
OK I forgot the “/” :slight_smile:

The working code is here:

#include <UIPEthernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                     
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server = “192.168.0.31”; // IP Adres (or name) of server to dump data to
int  interval = 5000; // Wait between dumps

void setup() {

Serial.begin(9600);
  Ethernet.begin(mac);

Serial.println(“Tweaking4All.com - Temperature Drone - v2.0”);
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask      : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP    : ");
  Serial.println(Ethernet.dnsServerIP());
}

void loop() {
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( “GET /sensorupdate.php?”);
    client.print(“id=1&temp=20&hum=60&air=90”);
    client.println( " HTTP/1.1");
    client.print( “Host: " );
    client.println(server);
    client.println( “Connection: close” );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn’t get a connection to the server:
    Serial.println(”–> connection failed/n");
  }

delay(interval);
}

I get connected to server after that enc28j60 isn’t calling the php file please help…