ArduinoUNO and ENC28J60

Hello, I’m trying send data to my remote database.

I’m using ArduinoUNO and ENC28J60, following this tutorial

php tested from browser and working…

but I can’t send data from my arduino…
also tried client.println("GET /xxx/arduinoconectarsql.php?valor=17");

anyone have an idea about why I can’t send data to my MySQL data base.

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

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// estoy usando el pin8=CS 
// 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[] = "www.antu.co.nz"; // IP Adres (or name) of server to dump data to
int  interval = 5000; // Wait between dumps
int valor = 0;

void setup() {
  //valor =50;
  Serial.begin(9600);
  Ethernet.begin(mac, 8);
  
  Serial.println("        Test_Sensor - v1.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());   
  Serial.println("****************************************\n");


   
}

void loop() {
  valor = 50;
  // if you get a connection, report back via serial:
  Serial.println("connecting...");
  if (client.connect(server,3306)) {
   Serial.println("-> Connected");
   //client.println("GET /xxxxx/arduinoconectarsql.php?valor=17");
   client.print("GET /xxxxxx/arduinoconectarsql.php?");
   client.print( "valor=");
   client.print( "19");
   client.print( " HTTP/1.1");
   client.println();
   client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  delay(interval);
}
Ethernet.begin(mac, 8);

What do you expect that '8' to be? It's definitely not an IP address as the library expects.

thanks

when using Ethernet.begin(mac);
in serial monitor I see

****************************************

IP Address        : 0.0.0.0
Subnet Mask       : 0.0.0.0
Default Gateway IP: 0.0.0.0
DNS Server IP     : 0.0.0.0
****************************************

connecting...
-> Connected

but if using
byte ip = { 10, 12, 1, 177 };
Ethernet.begin(mac, ip);
in serial monitor I see

****************************************

IP Address        : 10.12.1.177
Subnet Mask       : 255.255.255.0
Default Gateway IP: 10.12.1.1
DNS Server IP     : 10.12.1.1
****************************************
connecting...
-> Connected

Do I have to use Ethernet.begin(mac); ?
What am I doing wrong?

Do I have to use Ethernet.begin(mac); ?

That depends on how your network is set up. The above version gets it's IP using DHCP. If your network doesn't support that (almost any internet router supports it) you have to specify the IP yourself. If you supply just the IP the library code calculates the gateway and DNS IPs itself with some assumptions. If you have a non-default network setup you have to specify all these values yourself to the begin() method.

from my laptop I checked: Link-local IPv4 Address . . . . . : fe80::64ed:b8b0:5e4b:3da4%11 IPv4 Address. . . . . . . . . . . : 10.12.1.107 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . :10.12.1.200

from wifi IPv6 Address. . . . . . . . . . . : 10.12.6.36

then I'm using Ethernet.begin(mac, ip); getting in serial monitor:

****************************************

IP Address        : 10.12.1.177
Subnet Mask       : 255.255.255.0
Default Gateway IP: 10.12.1.1
DNS Server IP     : 10.12.1.1
****************************************

connecting...
-> Connected

but yet without send data to MySQL, it looks like that "connected" isn't true or not working

I found this

1.Directly connecting router to Arduino has 
no success if you are manually setting the IP address, 
BUT when you use "Ethernet.begin(mac)" 
to obtain ip address by directly connecting 
Arduino to router( and not through network Switch) 
everything works perfectly. Earlier when I was using
 "Ethernet.begin(mac)" I was connecting through network Switch.

from here

I'll check it tomorrow, no one is here now to check the cable coming from. I hope the code is OK

Hi again,

Finally.. the code was OK, all working now. The problem was with the hosting/server (I think).

Tips: Run and wait to connect. In serial monitor should show something like below:

IP Address : 10.12.1.111 Subnet Mask : 255.255.255.0 Default Gateway IP: 10.12.1.200 DNS Server IP : 10.12.1.200

take this ip 10.12.1.111 and add it in the hosting to remote access.

Link-local IPv4 Address . . . . . : fe80::64ed:b8b0:5e4b:3da4%11

This seems to be an IPv6 address.

IPv6 Address. . . . . . . . . . . : 10.12.6.36

But that's definitely an IPv4 address.

You must have a strange OS on that laptop...

As you seem to have a non-default local network setup you have to use the begin() method with all parameters:

byte ip[] = { 10, 12, 1, 177 };
byte gw[] = { 10, 12, 1, 200 };
byte dns[] = { 10, 12, 1, 200 };
Ethernet.begin(mac, ip, dns, gw);

IPs mm maybe..

thanks

byte ip[] = { 10, 12, 1, 177 }; byte gw[] = { 10, 12, 1, 200 }; byte dns[] = { 10, 12, 1, 200 }; Ethernet.begin(mac, ip, dns, gw);

anyway from here looks like that we don't need add anything manually only the mac when using the library UIPEthernet.h

Setup(): Next we’re initializing our Ethernet Shield.... We’re using DHCP! ....Just provide the Mac Address and everything will be taken care of. ..... DHCP will handle this just fine and automatically........ .

Thanks again Pylon!!