Ciao, sto cercando di inviare i dati della temperatura di un sensore DHT11 al un database mysql su un server online.
Nel server ho creato un file add.php che riceve i dati e li salva sul database (testato tramite browser e funziona).
Nell'arduino ho questo codice:
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
const char website[] PROGMEM = "dominio.server.it";
static void datiInviati (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
}
void setup() {
Serial.begin(9600);
dht.begin();
// Change 'SS' to your Slave Select pin, if you arn't using the default pin
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
#if 1
// use DNS to resolve the website's IP address
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
#elif 2
// if website is a string containing an IP address instead of a domain name,
// then use it directly. Note: the string can not be in PROGMEM.
char websiteIP[] = "192.168.1.1";
ether.parseIp(ether.hisip, websiteIP);
#else
// or provide a numeric IP address instead of a string
byte hisip[] = { 192,168,1,1 };
ether.copyIp(ether.hisip, hisip);
#endif
ether.printIp("SRV: ", ether.hisip);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
ether.packetLoop(ether.packetReceive());
String temp = String(t);
String umid = String(h);
String uno = "add.php?temp=";
String due = "&umid=";
uno += temp;
uno += due;
uno += umid;
if (millis() > timer) {
timer = millis() + 10000;
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/arduino/"), uno, website, datiInviati);
}
}
Compilandolo mi da un errore che non riesco a capire, sembra che non gli vada bene la variabile uno. L'errore è:
no matching function for call to 'EtherCard::browseUrl(const char*, String&, const char [16], void (&)(byte, word, word))'
Se al posto di quella variabile faccio un test dichiarando la variabile uno così:
char uno[] = "add.php?temp=5&umid=6";
allora funziona
è come se stessi concatenando le stringhe in modo sbagliato.
Mi sapete dire dove sto sbagliando?
Grazie