Hello there
I had the same problem some days ago but with a Arduino Uno and a ws5100.
Now I want to send the measurements to a server with a Arduino Nano and a enc28j60.
Still i get the error “0” on the method : “client.connect(mac)” or “client.connect(mac, ip ,dnsip , gateway, subnet)”.
Here is my Code:
#include <UIPEthernet.h>
#include <OneWire.h>//Used for measurements
#include <DallasTemperature.h>//Used for measurements
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x31, 0x31 };
// MAC in decimal{ 84, 52, 65, 48, 49, 49 };
#define ONE_WIRE_BUS 9
#define TEMPERATURE_PRECISION 9
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
//Black and Red Cable from the sensor get connected to GND. Together
//White Cable gets connected to port 9.
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
IPAddress server(192, 168, 0, 184);//The Server who will get the data
IPAddress subnet(255, 255, 255, 0);//This depends on your network
IPAddress ip(192, 168, 0, 243);//Depends on your network
IPAddress gateway(192, 168, 0, 1);//depends on your network
IPAddress dnsserver(192, 168, 0, 8);//depends on your network
EthernetClient client;
int interval = 5000; // Wait between dumps
int x = 6;//The Variable that catches the Error (If its 6 nothing was returned cause 6 is an invalid Error)
float tempC;
void setup() {
digitalWrite( 8 , LOW ); //This is allows you to put the sensor directly into the arduino without any resistors.
pinMode( 8 , OUTPUT );
digitalWrite( 10 , LOW );
pinMode( 10 , OUTPUT );
Ethernet.begin(mac, ip);
Serial.begin(9600);
while(!Serial) //This is to ensure that the information will get displayed after the display is ready.
{
}
delay(1000);
//Here you can cehck if your arduino gets the correct information for LAN
Serial.println("Arduino Temperaturmessungen per LAN versenden.");
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("");
}
void loop() {
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
// For testing purposes, reset the bus every loop so we can see if any devices appear or fall off
sensors.begin();
// Grab a count of devices on the wire
numberOfDevices = sensors.getDeviceCount();
Serial.print("Nummer:");
Serial.print(numberOfDevices, DEC);
Serial.print(" von ");
Serial.print(numberOfDevices);
sensors.requestTemperatures(); // Send the command to get temperatures
// Loop through each device, print out temperature data
for(int i=0;i<numberOfDevices; i++)
{
// Search the wire for address
if(sensors.getAddress(tempDeviceAddress, i))
{
// Output the measurements
Serial.print(" | Temperatur in Celsius ");
Serial.print("= ");
tempC = sensors.getTempC(tempDeviceAddress);
while (tempC > 84 && tempC < 86) //Sometimes the sensor send 85 as an wrong measruement. So if this happens it should just measure again til its not 85
{
tempC = sensors.getTempC(tempDeviceAddress);
}
Serial.print(tempC);
}
}
Serial.println("");
delay(1000);
Serial.print("connecting to ");
Serial.println(server);
client.connect(server, 80);
delay(1000);
if(client.connected() == false) //Loop til you can connect to the server
{
x = client.connect(server, 80); //Catches the error and prints it on the serial display
Serial.println("Failed trying again...");
delay(1000);
Serial.println(x);
}
else
{
Serial.println("-> Connected"); //Informs you that you are connected
// Make a HTTP request:
client.print( "GET /add.php?"); //Opens the PHP Document which puts data in the SQL Database
client.print("temp="); //The GET variable that your document requires
client.print( tempC );
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop(); //Stops the connection and opens it again in the next loop
Serial.println("Data sent. Waiting a bit to reconnect.");
delay(60000); //The delay it waits to reconnect and send data (60 000 is 60 seeconds so 1 minute)
x = 6;
}
}
The IP’s are correct.
The connections of the chips i mad like in this picture:
enc28j60 > arduino nano
SI > D11
CS > D8
VCC > 3V3
SO > D12
SCK > D13
GND > GND
I think th eproblem is at my soldering skill or in the code. I checked the sold spots but I’m going to do this again, sine i don’t trust them.
Thank you verry much for any help.