can anyone finds why arduino older code is not working with newer arduino version?
... program works in arduino but won`t get connections with sensors...
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
#include <SD.h>
dht11 DHT11;
#define nSensores 3
int puertos[nSensores];
float fHumedades[nSensores];
float fTemperaturas[nSensores];
int nFilas=0;
int nFiles=0;
File file;
int iNVisitas=0;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xEE, 0xEE };
byte ip[] = { 192,168,1, 177 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(666);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(115200);
int puertos[]={2,3,4};
pinMode(10, OUTPUT);
if (!SD.begin(4))
{
Serial.println("Error inicializando SD");
nFiles=-1;
}
else
{
nFiles=0;
Serial.println("SD initializada.");
}
}
void getdata(int iIndice)
{
int chk = DHT11.read(puertos[iIndice]);
fHumedades[iIndice]=-1;
fTemperaturas[iIndice]=-1;
Serial.print("Sensor ");
Serial.print(iIndice);
Serial.print(" ");
switch (chk)
{
case 0:
fHumedades[iIndice]=(float)DHT11.humidity;
Serial.print(fHumedades[iIndice], 2);
Serial.print(" % ");
fTemperaturas[iIndice]=(float)DHT11.temperature;
Serial.print(fTemperaturas[iIndice], 2);
Serial.println(" o C");
break;
case -1: Serial.println(" Checksum error"); break;
case -2: Serial.println(" Time out error"); break;
default: Serial.println(" Unknown error"); break;
}
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for(int i=0;i<nSensores;i++){
// for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("sensor ");
client.print(i);
client.print(": ");
if(fHumedades[i]==-1)
client.print(" error leyendo el sensor");
else
{
client.print(fHumedades[i], 2);
client.print(" % ");
client.print(fTemperaturas[i], 2);
client.println(" o C");
}
client.println("
");
}
client.print((iNVisitas++)/2);
client.println(" visitas
");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
else
{
//if(nFiles>=0 && file)
{
file= SD.open("datalog.txt", FILE_WRITE);
}
String data="";
for(int i=0;i<nSensores;i++)
{
getdata(i);
data+=String(nFilas)+";"+String(i)+";"+String((int)fHumedades[i])+";"+String((int)fTemperaturas[i])+"\n";
}
if(file)
{
file.print(data);
Serial.print(data);
file.close();
nFilas++;
}
delay(200);
}
}