Ciao a tutti,
ho scritto uno sketch che mi dovrebbe permettere di controllare i parametri del mio impianto termosolare dalla pagina web "gelholder" del sito www.cosm.com.
Sto inviando i dati di 2 sensori LM35DZ e di 2 ingressi analogici (il cui segnare arriva da due uscite digitali, in parallelo con le uscite che mi controllano una ventola e la caldaia, attraverso una resistenza da 1Kohm) a cosm (ex Pachube).
Quando ho provato il programma con 1 solo sensore il refresh dei dati era ogni 30 sec, adesso mi trovo che l'aggiornamento avviene mimino ogni 20 min, ma a volte anche dopo ore.
La mia linea internet mi sembra ok in quanto, con un altro arduino, nella stessa pagina di coms ho caricato un'altro sketch che mi controlla la temperatura dello studio usando una sonda ds18b20 e vedo che il refresh dei dati è molto veloce.
Da cosa può dipendere?
Mi piacerebbe avere un aggiornamento al massimo ogni 30 sec.
Il mio username si www.cosm.com è gelholder
Grazie
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 "xxxxxxxxxxxxxxxxxxxxx" // 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(10,0,1,20);
// 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 = 10*1000; //delay between updates to Cosm.com
void setup() {
// 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() {
int caldaiaON=analogRead(A0); //INGRESSO ANALOGICO PER CONTROLLO WEB STATO CALDAIA
int Ventola=analogRead(A2); //INGRESSO ANALOGICO PER CONTROLLO WEB STATO CALDAIA
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
// read the analog sensor:
float tempAria = analogRead(A1)*0.5; //sensore di temperatura LM35DZ ARIA
int sensorReading = tempAria;
Serial.print ("Temp. Aria: ");
Serial.println (tempAria);
String dataString = "sensor1,";
dataString += sensorReading;
if ((tempAria>0) and (tempAria<35)){
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>35) 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);
}
int 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:
float tempAcqua = (analogRead(A3)*0.5)+4; // sensore di temperatura LM35DZ ACQUA
int 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);
}
int 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(!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);
}
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();
}