UNO + ENC28J60
- Войдите на сайт для отправки комментариев
Сб, 11/08/2018 - 15:47
Приветствую друзья. Большая просьба подсказать.
Стоит две задачи
1. Отправлять запрос на сайт вида http://shop.igri-razuma.ru/ym.php?number=10 , где последние две циры - это переменная. Правильный url я смог сформировать, но возвращается ошибка BAD REQUIEST. Если url ввожу в ручную - все работает.
2. Забрать данные с сайта. Здесь пока никаких продвижений, подскажите примерчик пожалуйста.
Надеюсь на Вашу помощь.
#include <SPI.h>
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500];
static uint32_t timer;
const char website[] PROGMEM = "shop.igri-razuma.ru";
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("...");
}
static void get_time (char number) {
Serial.println();
Serial.print("<<< REQ ");
char url[] = "/ym.php?number=???????";
char * nHolder = strchr(url, '=') + 1;
dtostrf(10, -1, 0, nHolder );
Serial.print("URL=");
Serial.println(url);
// с этой строкой работает
//ether.browseUrl(PSTR("http://shop.igri-razuma.ru/ym.php?number=52"),"", website, my_callback);
//а с этой не хочет, хотя url верный
//ether.browseUrl(url,"", website, my_callback);
}
void setup() {
Serial.begin(9600);
// 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() {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
get_time("52");
}
}
// с этой строкой работает
ether.browseUrl(PSTR("/ym.php?number=52"),"", website, my_callback);
Когда вывожу через такой код
ether.browseUrl(PSTR("/ym.php?number=52"),"", website, my_callback);Ответ такой:
Когда вывожу через такой код:
char url[] = "/ym.php?number=???????"; char * temperatureHolder = strchr(url, '=') + 1; dtostrf(10, -1, 0, temperatureHolder); Serial.print("URL="); Serial.println(url); ether.browseUrl(url,"", website, my_callback);Ответ такой:
Проблему 1 решил следующим кодом:
static void get_time (char * number) { Serial.println(); Serial.print("<<< REQ "); char url[] = "?number=???????"; number = strchr(url, '=') + 1; dtostrf(10, -1, 0, number); Serial.print("URL="); Serial.println(url); ether.browseUrl(PSTR("/ym.php"),url, website, my_callback);Проблема 2 остается. Подскажите пожалуйста как вытащить нужную информацию с ответа.