Ciao a tutti,
sto provando a creare una piccola stazione meteo per monitorare la temperatura e umidità.
Sto utilizzando il sensore DHT11 e il modulo ethernet con la libreria EtherCard.h.
Ho creato un form su docs.google per poter salvare i dati che dovrebbero arrivare da Arduino.
Il mio problema è che non riesco ad inviare i dati al form di google.
Il codice utilizzato è il seguente:
#include <dht11.h>
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
static byte dnsip[] = {8, 8, 8, 8};
byte Ethernet::buffer[500];
BufferFiller bfill;
char formkey[] = "1yhgvwojiefF6uYtv8G-cfpEQt_DLa8PD7ZiwEG1MsDw"; //Replace with your Key
const char website[] PROGMEM = "docs.google.com";
char form1[] = "entry.1690769701";
char form2[] = "entry.775590075";
#define dhtPinInput 7
dht11 dht;
void setup () {
Serial.begin(57600);
Serial.println("\n[Temperatura]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("My IP: ", ether.myip);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);
}
void postTemperature() {
char website[] PROGMEM = "docs.google.com";
char url[] PROGMEM = "/forms/d/1yhgvwojiefF6uYtv8G-cfpEQt_DLa8PD7ZiwEG1MsDw/formResponse?ifq&";
String web = "";//"/forms/d/1yhgvwojiefF6uYtv8G-cfpEQt_DLa8PD7ZiwEG1MsDw/formResponse?ifq&";
web += "entry.1690769701=";
web += dht.temperature;
web += "&entry.775590075=";
web += dht.humidity;
web += "&submit=Submit";
char cx[60];
web.toCharArray(cx, 60);
Serial.print(website);
Serial.print(url);
Serial.println(cx);
ether.httpPost(url, website, cx, NULL, &post_callback);
}
void post_callback(uint8_t statuscode, uint16_t datapos, uint16_t dlen) {
Serial.println("post_callback");
// TODO: What to do on response? Check its OK
//Serial.print("callback pos: ");
//Serial.print(datapos,DEC);
//Serial.print(" status: ");
//Serial.print(statuscode,DEC);
//Serial.print(" Data: ");
Serial.println((char *) & (Ethernet::buffer[datapos]));
}
void loop () {
int chk = dht.read(dhtPinInput);
Serial.println("Posting data");
postTemperature();
delay(10000);
}
Il programma riesce a collegarsi ad internet, riuscendo a risolvere con il dns il sito passato.
La string complessiva data da website+url+cx nel metodo postTemperature crea l'url corretto (utilizzando in un browser mi memorizza correttamente i dati)
Vi ringrazio
Ciao