Ciao vorrei approfittarne per chiederti informazioni su come hai realizzato la prima parte del tuo progetto!
ieri sera ho provato a modificare un po di codice ma riesco solo ad uplodare su xively una sola volta i dati provenienti dal mio DHT22.
posto il cod!
Le funzione per la lettura prima le richiamavo nel loop poi ho pensato che potesse essere quello il prob e quindi gestisco l'acquisizione direttamente nella loop senza richiamare le funzione che quindi vanno tolte a questo punto.
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
#include <DHT22.h>
#define DHT22_PIN 8 //definizione pin sensore DHT22
DHT22 istanzaDHT22(DHT22_PIN); // creazione oggettodi tipo DHT22
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x74, 0x99 };
IPAddress ip(192,168,0,7);
IPAddress gateway(192,168,0, 1);
// Your Xively key to let you upload data
char xivelyKey[] = "fmhdslflsdlf";
//your xively feed ID
#define xivelyFeed 1212324234235
//datastreams
char TemperatureID[] = "Temperature";
char HumidityID[] = "Humidity";
// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
XivelyDatastream(TemperatureID, strlen(TemperatureID), DATASTREAM_FLOAT),
XivelyDatastream(HumidityID, strlen(HumidityID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);
EthernetClient client;
XivelyClient xivelyclient(client);
void setup() {
Serial.begin(9600);
Serial.println("Attempting to get an IP address using DHCP:");
if (!Ethernet.begin(mac)) {
Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip, gateway);
}
Serial.print("My address:");
Serial.println(Ethernet.localIP());
}//fine setup
/functions/
float temper(){
delay(1500);
istanzaDHT22.readData();
float temp = istanzaDHT22.getTemperatureC();
return temp;
}
float umid(){
delay (1500);
istanzaDHT22.readData();
float umid = istanzaDHT22.getHumidity();
return umid;
}
void loop() {
//adjust LED level. set from Xively
xivelyclient.get(feed, xivelyKey); //get data from xively
//read sensor values
istanzaDHT22.readData();
float temp = istanzaDHT22.getTemperatureC();
float hum = istanzaDHT22.getHumidity();
datastreams[0].setFloat(temp);
datastreams[1].setFloat(hum);
//print the sensor value on monitor
Serial.print("Read sensor temperature value ");
Serial.println(datastreams[0].getFloat());
Serial.print("Read sensor humidity value ");
Serial.println(datastreams[1].getFloat());
//send value to xively
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
//return message
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println("");
//delay between calls
delay(15000);
}
saluti
Francesco