Webduino симуляция post запроса.
- Войдите на сайт для отправки комментариев
Пт, 11/07/2014 - 16:37
Использую https://github.com/sirleech/Webduino
Отрыков POST
void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool){
if (type == WebServer::POST) {
bool repeat;
char name[16], value[16];
do {
/* readPOSTparam returns false when there are no more parameters
* to read from the input. We pass in buffers for it to store
* the name and value strings along with the length of those
* buffers. */
repeat = server.readPOSTparam(name, 16, value, 16);
/* this is a standard string comparison function. It returns 0
* when there's an exact match. We're looking for a parameter
* named red/green/blue here. */
if (strcmp(name, "red") == 0) {
/* use the STRing TO Unsigned Long function to turn the string
* version of the color strength value into our integer red/green/blue
* variable */
red = strtoul(value, NULL, 10);
}
if (strcmp(name, "green") == 0) {
green = strtoul(value, NULL, 10);
}
if (strcmp(name, "blue") == 0) {
blue = strtoul(value, NULL, 10);
}
} while (repeat);
// after procesing the POST data, tell the web browser to reload
// the page using a GET method.
server.httpSeeOther(PREFIX);
return;
}
Подскажите как-то можно в loop(){ *** } симулировать\отправить POST,
например вот такой: blue=12
IPAddress server(10,0,0,138); String PostData = "blue=12"; if (client.connect(server, 80)) { client.println("POST /youscript.php HTTP/1.1"); client.println("Host: 10.0.0.138"); client.println("User-Agent: Arduino/1.0"); client.println("Connection: close"); client.print("Content-Length: "); client.println(PostData.length()); client.println(); client.println(PostData); }Нет. Это не совсем то.
Я хочу например написав в loop:
sendPost("blue", "12");После чего срабатывает этот участок кода:
if (strcmp(name, "blue") == 0) { blue = strtoul(value, NULL, 10); }Я не знаю как понятней объяснить. Что-то подобное реально реализовать?
Вы начните с того, что уточните "кто на ком стоял".
Вы хотите отправить поста запрос
1.НА ардуино, или ИЗ ардуины?
2. У вас проблема его "принять" или "отправить"?
это?
это?
Есть подозрение что все еще проще и ответом будет
Я не Русский, мне иногда сложно сформулировать задачу.
Вот другой код:
void processCommand(char* command) { if (strcmp(command, "l2-1") == 0) { digitalWrite(PinGa2, LOW); VRelayLamp=0; VTimeLamp2=GlolTime; } else if (strcmp(command, "le1-10") == 0) { digitalWrite(PinGa2, LOW); VRelayLamp=0; VTimeLamp2=GlalTime; VTimeAutoOffLamp2=10; } else if (strcmp(command, "le2-1-30") == 0) { digitalWrite(PinGa2, LOW); VRelayLamp=0; VTimeLamp2=GloTime; VTimeAutoOffLamp2=30; }Если мы в loop напишем:
processCommand("le1-10");У нас сработают вот эти строчки кода:
digitalWrite(PinGa2, LOW); VRelayLamp=0; VTimeLamp2=GlalTime; VTimeAutoOffLamp2=10;Подскажите как сделать тоже самое, но с кодом который я показал выше.
я тоже не русский. я Вам ссылку на функции выше давал.