Salve a tutti!
Ho collegato un sensore DHT11 ad una shield ethernet e volevo fare in modo che la temperatura venisse condivisa su un account privato su Twitter. Così, just for fun XD
Ho utilizzato la libreria di NeoCat e, dopo aver capito che dovevo convertire un float in char, twittare la temperatura è stato abbastanza semplice. Quello che non riesco a fare è aggiungere altri caratteri allo stesso tweet. Mi spiego meglio.
Al momento attuale riesco solo a passargli il valore della tamperatura, quindi il tweet risulta come “21” e basta, ma io vorrei qualcosa del tipo “la temperatura è di 21°”.
Ho provato varie soluzioni ma non ci sono riuscito, spero che voi possiate aiutermi
Vi allego il codice:
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 100 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("*************");
// Message to post
char msg[140];
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
Serial.println("DHT ready!");
dht.begin();
delay(1000);
Ethernet.begin(mac, ip);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
//delay(3600);
}
char _buffer[10];
dtostrf(t , 2, 0, _buffer);
Serial.println("connecting ...");
if (twitter.post(_buffer)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
delay(3600000);
}