hello,
i'm trying to send DHT11 data to a website with this code
#include <EtherCard.h>
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 5
#define key "energyWayArduino" // put your key here
#define ethCSpin 10 // imposta il pin per il CS dell'ethernet (io uso sempre il 10)
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; //impostiamo il valore MAC del dispositivo (deve essere unico nella LAN)
const char website[] PROGMEM = "servizi.vilfredo.it/dataReceiverArduino/ard_data";
byte Ethernet::buffer[500];
uint32_t timer;
Stash stash;
byte session;
//impostiamo una variabile di tempo
int res = 100;
void setup () {
Serial.begin(9600);
Serial.println("\n[inizio caricamento]");
initialize_ethernet(); //inizializziamo la connessione con ethernet
}
void loop () {
int chk;
chk = DHT.read(DHT11_PIN); // READ DATA
if (res > 220){ //se non riceviamo una risposta corretta facciamo ripartire la connessione
initialize_ethernet();
}
res = res + 1;
ether.packetLoop(ether.packetReceive());
//200 res = 10 secondi (50ms ogni ciclo res)
if (res == 200) {
byte sd = stash.create();
stash.print("field1=");
stash.print((float)DHT.humidity);
stash.print("&field2=");
stash.print((float)DHT.temperature);
stash.print("&unit_code=arduino01");
stash.save();
//stampiamo a monitor seriale i valori del DHT11
Serial.println((float)DHT.humidity);
Serial.println((float)DHT.temperature);
//generiamo gli header che vengono stampati anche a monitor seriale
Stash::prepare(PSTR("POST /update HTTP/1.1" "\r\n"
"Host: $F" "\r\n"
"Connection: close" "\r\n"
"password: $F" "\r\n"
"Content-Type: application/x-www-form-urlencoded" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, PSTR(key), stash.size(), sd);
// spedisce il pacchetto tcp
session = ether.tcpSend();
int freeCount = stash.freeCount();
if (freeCount <= 3) { Stash::initMap(56); }
}
const char* reply = ether.tcpReply(session);
if (reply != 0) {
res = 0;
Serial.println(F(" >>>REPLY recieved...."));
Serial.println(reply);
}
delay(300);
}
void initialize_ethernet(void){
for(;;){
if (ether.begin(sizeof Ethernet::buffer, mymac, ethCSpin) == 0){
Serial.println( "Failed to access Ethernet controller");
continue;
}
if (!ether.dhcpSetup()){
Serial.println("DHCP failed");
continue;
}
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
//fa ripartire il conteggio per il reset
res = 180;
break;
}
}
but it doesn't upload data and it sends me this error:
>>>REPLY recieved....
HTTP/1.1 400 Bad Request
Server: nginx
Date: Sat, 30 Apr 2016 07:05:41 GMT
Content-Type: text/html
Content-Length: 166
Connection: close
400 Bad Request
400 Bad Request
nginx
i'm using the sketch that i used for Thingspeak, and with this website it works...
i'm using an arduino uno with enc28j60 ethernet module.
thank you for your support.