Ciao a tutti, vi chiedo cortesemente se potete aiutarmi col mio progetto. Voglio creare una piccola stazione meteo e seguendo anche dei progetti pubblicati su internet ho scritto il codice perfettamente funzionante. Il problema è che mi esce un errore quando vado a caricare i dati su Xively.
Il codice è:
#include "SPI.h"
#include "Ethernet.h"
#include "HttpClient.h"
#include "DataCoder.h"
#include "VirtualWire.h"
#include "Xively.h"
#include "DHT.h"
//definisco il pin 11 come rx dht type
//DHT dht(DHTPIN, DHTTYPE);
const int rx_pin = 11;
const int baudRate = 800;
const int led_pin = 13;
//indirizzo MAC ethernet shield
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
//API key per upload
char xivelyKey[] = "1cn34PkopBKCTNrdTumVtZZngfIqIM9YabU7FEAp68LvblH3";
//definisco le stringhe per il datastream
char tOUT[] = "Temperatura";
char hOUT[] = "Umidita";
XivelyDatastream datastreams [] = {
XivelyDatastream(tOUT, strlen(tOUT), DATASTREAM_FLOAT),
XivelyDatastream(hOUT, strlen(hOUT), DATASTREAM_FLOAT),
};
//inserisco il feed ID di xively e il numero di datastream da caricare
XivelyFeed feed(1070150508, datastreams, 2);
EthernetClient client;
XivelyClient xivelyclient(client);
void setup() {
Serial.begin(9600);
Serial.println("Inizio upload datastream su Xively...");
Serial.println();
Serial.print("Avvio lettura");
// dht.begin();
while (Ethernet.begin(mac) !=1)
{
Serial.println("Errore ricezione IP tramite DHCP, riprovo...");
delay(15000);
}
Serial.print("Il server è: ");
Serial.println(Ethernet.localIP());
SetupRFDataRxnLink(rx_pin, baudRate);
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
union RFData inDataSeq;//dove immagazzinare le informazioni ricevute da sensore esterno
float inArray[2];//dove immagazzinare le informazioni decodificate
if(RFLinkDataAvailable(buf, &buflen))
{
for(int i =0; i< buflen; i++)
{
inDataSeq.s[i] = buf[i];
}
DecodeRFData(inArray, inDataSeq);
float tOUT = inArray[0];
float hOUT = inArray[1];
datastreams[0].setFloat(tOUT);
datastreams[1].setFloat(hOUT);
Serial.println("Caricamento su Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned");
Serial.println(ret);
Serial.println("temperatura: ");
Serial.print(inArray[0]);
Serial.print(" °C Umidita: ");
Serial.print(inArray[1]);
}
}
Quando apro il monitor seriale mi appare que``sta scritta:
Inizio upload datastream su Xively...
Avvio letturaIl server è: 192.168.11.3
Caricamento su Xively
xivelyclient.put returned-3
temperatura:
21.10 °C Umidita: 26.00Caricamento su Xively
xivelyclient.put returned-3
Il problema è quella scritta: xivelyclient.put returned-3
Sono andato sulla libreria di xively e mi indica quanto segue:
This library uses amcewen/HttpClient which has following error codes:
HTTP_SUCCESS = 0 - no error
HTTP_ERROR_CONNECTION_FAILED = -1 - connection to api.xively.com has failed
HTTP_ERROR_API = -2 - a method of HttpClient class was called incorrectly
HTTP_ERROR_TIMED_OUT = -3 - connection with api.xively.com has timed-out
HTTP_ERROR_INVALID_RESPONSE = -4 - invalid or unexpected response from the server