EtherCard ошибка HTTP/1.1 404 Not Found
- Войдите на сайт для отправки комментариев
Втр, 14/05/2013 - 21:37
Помогите разобраться с проблемой
Задача: собирать показания датчиков и передавать на сервер
Скетч
#include <EtherCard.h>
#include "DHT.h"
#include <Wire.h>
#include <BMP085.h>
#define DHTPIN 8
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BMP085 dps = BMP085();
long pr = 0, al = 0, tm = 0;
unsigned long time1=0;
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
char website[] PROGMEM = "192.168.1.110";
static byte hisip[] = {192,168,1,110};
boolean use_hisip = true;
// ether.hisip[0] = 192;
// ether.hisip[1] = 168;
//ether.hisip[2] = 1;
// ether.hisip[3] = 110;
// called when the client request is complete
static void my_callback (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(57600);
Wire.begin();
Serial.println("\n[webClient]");
dht.begin();
dps.init(MODE_STANDARD, 19000, true);
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
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);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 3000;
int t = dht.readTemperature();
int h = dht.readHumidity();
dps.getPressure(&pr);
int p = pr/133.322368;
dps.getAltitude(&al);
int a = al/100;
char buff[1];
sprintf(buff, "?t=%d&h=%d&a=%d&p=%d", t, h, a, p);
Serial.println();
Serial.println(buff);
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/update.php"), buff, website, my_callback);
}
}
При запуске получаю ошибку
?t=27&h=36&a=195&p=754
<<< REQ >>>
HTTP/1.1 404 Not Found
Connection: close
Content-Type: text/plain
Transfer-Encoding: chunked
Изменив в коде строчку
sprintf(buff, "?t=%d&h=%d&a=%d&p=%d", t, h, a, p);
на
sprintf(buff, "?t=%d&h=%d&a=%d", t, h, a);
все работает
Где ошибка? Как поправить?
Как минимум одна ошибка - в объявлении
charbuff[1];Следующей строкой sprintf в этот буфер выводит явно больше одного символа, т.е. банально перетирает память, следующую за этой переменной. Надо вместо единицы указать реально необходимый размер буфера, подсчитав предварительно размер выводимой строки в байтах.
FYI: работающий пример скетча-сервера для EtherCard + DS18B20 можно посмотреть, например, здесь.