Ho capito!
Un macello, ho smontato tutto ho invertito le schede nuovamente ... etc...etc... ed alla fine ho capito dov'è il problema del refresh con tempi abissali!
/* IDE 1.01
Ethernet shield attached to pins 10, 11, 12, 13
Arduino uno
This code is in the public domain.
*/
#include <SPI.h>
#include <Ethernet.h>
#define APIKEY "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // replace your Cosm api key here
#define FEEDID XXXXX // replace your feed ID
#define USERAGENT "TEST 2" // user agent is the project name
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,1,22);
// initialize the library instance:
EthernetClient client;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
// IPAddress server(216,52,233,121); // numeric IP for api.cosm.com
char server[] = "api.cosm.com"; // name address for Cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 1; //delay between updates to Cosm.com
int caldaiaON = 0; //INGRESSO ANALOGICO PER CONTROLLO WEB STATO CALDAIA
int Ventola = 0; //INGRESSO ANALOGICO PER CONTROLLO WEB STATO CALDAIA
float tempAria = 0.0; //sensore di temperatura LM35DZ ARIA
float tempAcqua = 0.0; // sensore di temperatura LM35DZ ACQUA
int sensorReading = 0;
String dataString = "";
int otherSensorReading = 0;
int otherSensorReadingAria = 0;
int otherSensorReadingCaldaia = 0;
void setup() {
pinMode(5, OUTPUT); //USCITA IN PARALLELO AL RELE CALDAIA PER VISUALIZZAZIONE WEB STATO CALDAIA
pinMode(6, OUTPUT); //USCITA IN PARALLELO AL RELE CALDAIA PER VISUALIZZAZIONE WEB STATO CALDAIA
pinMode(8, OUTPUT); //relay controllo ACQUA
pinMode(9, OUTPUT); //relay controllo ARIA
// start serial port:
Serial.begin(9600);
// give the ethernet module time to boot up:
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
Ethernet.begin(mac, ip);
}
}
void loop() {
caldaiaON = analogRead(A0); //INGRESSO ANALOGICO PER CONTROLLO WEB STATO CALDAIA
Ventola = analogRead(A2); //INGRESSO ANALOGICO PER CONTROLLO WEB STATO CALDAIA
// read the analog sensor:
tempAria = analogRead(A1) * 0.5; //sensore di temperatura LM35DZ ARIA
sensorReading = tempAria;
Serial.print ("Temp. Aria: ");
Serial.println (tempAria);
dataString = "sensor1,";
dataString += sensorReading;
if ((tempAria > 0) and (tempAria < 27)){
Serial.println("Aria fredda");
digitalWrite(9, LOW); //VENTILAZIONE DISATTIVATA
digitalWrite(5, LOW); //VENTILAZIONE DISATTIVATA
Serial.print ("Ventola Spenta ");
Serial.println (Ventola, DEC);
}
else if ((tempAria > 27) and (tempAria < 100)){
Serial.println ("Aria calda");
digitalWrite(9, HIGH); //VENTILAZIONE ATTIVATA
digitalWrite(5, HIGH); //VENTILAZIONE ATTIVATA
Serial.print ("Ventola Accesa ");
Serial.println (Ventola,DEC);
}
otherSensorReadingAria = Ventola;
dataString += "\nsensor2,";
dataString += otherSensorReadingAria;
// you can append multiple readings to this String if your
// Cosm feed is set up to handle multiple values:
tempAcqua = (analogRead(A3) * 0.5) + 4; // sensore di temperatura LM35DZ ACQUA
otherSensorReading = tempAcqua;
Serial.print("Temp. Acqua: ");
Serial.println(tempAcqua);
dataString += "\nsensor3,";
dataString += otherSensorReading;
if ((tempAcqua > 0) and (tempAcqua < 42)) {
Serial.println("Acqua fredda");
digitalWrite(8, HIGH); // ACCENSIONA CALDAIA
digitalWrite(6, HIGH); //USCITA IN PARALLELO AL SEGNALE CALDAIA PER TELECONTROLLO
Serial.print("Caldaia Accesa ");
Serial.println(caldaiaON, DEC);
}
else if ((tempAcqua > 42) and (tempAcqua < 100)){
delay(2000);
Serial.println ("Acqua Calda");
digitalWrite(8, LOW); //SPEGNIMENTO CALDAIA
digitalWrite(6, LOW); //USCITA IN PARALLELO AL SEGNALE CALDAIA PER TELECONTROLLO
Serial.print("Caldaia Spenta ");
Serial.println(caldaiaON, DEC);
}
otherSensorReadingCaldaia = caldaiaON;
dataString += "\nsensor4,";
dataString += otherSensorReadingCaldaia;
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting...");
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if (millis() < lastConnectionTime) lastConnectionTime = millis(); // evita il blocco dopo 50gg poiché millis() si azzera
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(dataString);
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request:
client.print("PUT /v2/feeds/");
client.print(FEEDID);
client.println(".csv HTTP/1.1");
client.println("Host: api.cosm.com");
client.print("X-ApiKey: ");
client.println(APIKEY);
client.print("User-Agent: ");
client.println(USERAGENT);
client.print("Content-Length: ");
client.println(thisData.length());
// last pieces of the HTTP PUT request:
client.println("Content-Type: text/csv");
client.println("Connection: close");
client.println();
// here's the actual content of the PUT request:
client.println(thisData);
Serial.println(thisData);
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
Serial.println();
Serial.println("disconnecting...");
client.stop();
}
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}
Accade che se l'acqua all'interno del bollitore è ad una temperatura <42°C va tutto bene perché non è impostato nessun delay, se invece l'acqua ha una temperatura >42°C il codice è:
else if ((tempAcqua > 42) and (tempAcqua < 100)){
delay(2000);
Serial.println ("Acqua Calda");
digitalWrite(8, LOW); //SPEGNIMENTO CALDAIA
digitalWrite(6, LOW); //USCITA IN PARALLELO AL SEGNALE CALDAIA PER TELECONTROLLO
Serial.print("Caldaia Spenta ");
Serial.println(caldaiaON, DEC);
}
ed il delay(2000) sullo spegnimento della caldaia mi manda in crisi tutto e per non so quale motivo il refresh avviene ogni 20/30min circa.
Il delay per lo spegnimento della caldaia è molto importante per evitare che per differenze di 0,5°C o di 1°C la caldaia si accenda e si spenga in continuazione.
A questo punto non ho la minima idea di come risolvere la cosa...
P.S. x Ettore: Ho provato il nuovo codice ma continuo ad avere letture di temperatura completamente sballate. Io però non sono in grado di capirne il motivo...