Как отправить данные формы через script в arduino
- Войдите на сайт для отправки комментариев
Чт, 15/01/2015 - 13:07
При обращении к серверу ардуино используется блок
if (StrContains(HTTP_req, "ajax_inputs")) {
// send rest of HTTP header
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
SetOtoplenieOn();
SetLEDs();
// send XML file containing input states
XML_response(client);
}
else { // web page request
// send rest of HTTP header
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
}
// display received HTTP request on serial port
Serial.println(HTTP_req);
Запросы передаются через HTTP_req
В index.htm есть форма
<form method=get name=ptemp>
<div class="Усть-right">
<div class="input-block">
<label id="input">Верхний порог температуры</label>
<input id="tempv" name=toptemp type=text value="">
</div>
<div class="input-block">
<label id="input">Нижний порог температуры</label>
<input id="tempv" название=bottomtemp type=text value="">
</div>
<div class="input-block">
<label id="input">Состояние тэнов</label>
</div>
</div>
<div class="Усть-left">
<div class="input-block">
<label id="input">Температура в котле</label>
<span id="temp-Валь" class="temp-воды">...</span>
</div>
<div class="input-block">
<label id="input">Порог включения насоса</label>
<input id="tempv" name=tvodi type=text value="">
</div>
<div class="input-block">
<label id="input">Состояние насоса</label>
</div>
</div>
<div class="ok">
<input id="кнопка- "ок" type=submit value= "OK">
</div>
</form>
При отправки данных формы формируется вот такая строка
GET /?toptemp=25&bottomtemp=18&tvodi=40 HTTP/1.1
и сервер не понимает данной строки, он понимает только строку вида
GET /ajax_inputs&nocache=878146.679373458 HTTP/1.
Как правильно передать данные этой формы в переменные
strVerhniyPorogTemp = "";
strNijniyPorogTemp = "";
strTempVklNasosa = "";
в строку
request.open("GET", "ajax_inputs" + strOtoplenieON + strNagrevatelOn + strLED1 + strVerhniyPorogTemp + strNijniyPorogTemp + strTempVklNasosa + nocache, true);
При отправки данных формы формируется вот такая строка
GET /?toptemp=25&bottomtemp=18&tvodi=40 HTTP/1.1
и сервер не понимает данной строки, он понимает
Спрашиваю чисто из интереса, что мешает формировать строку так, как указано ниже?
только строку вида
Не понял - что у вас сервер ? Судя по коду arduino, получив запрос он пытается назад отправить содержимое файла index.htm. Тогда где вы хотите сформировать запрос и какому серверу ?
Сам разобрался
это в index.htm
function JsSendUSART(){ VerhniyPorogTemp_value = document.getElementById("VerhniyPorogTemp").value; strVerhniyPorogTemp = "&VPT=" + VerhniyPorogTemp_value; NijniyPorogTemp_value = document.getElementById("NijniyPorogTemp").value; strNijniyPorogTemp = "&NPT=" + NijniyPorogTemp_value; TempVklNasosa_value = document.getElementById("TempVklNasosa").value; strTempVklNasosa = "&TVN=" + TempVklNasosa_value;это в скетче
void SetUstanovki(void) { //(strstr(HTTP_req, "&NPT"))[0] = 0; if(strstr(HTTP_req, "VPT")>0){ //(strstr(HTTP_req, "&NPT"))[0] = 0; VerhniyPorogTemp = ((strstr(HTTP_req, "&VPT")+5)); Serial.print ("Temperature verhego predela HTTP: "); Serial.println(VerhniyPorogTemp); Serial.println(); } if(strstr(HTTP_req, "NPT")>0){ NijniyPorogTemp =(strstr(HTTP_req, "&NPT")+5); Serial.print ("Temperature nignego predela HTTP: "); Serial.println(NijniyPorogTemp); Serial.println(); } if(strstr(HTTP_req, "TVN")>0){ TempVklNasosa =(strstr(HTTP_req, "&TVN")+5); Serial.print ("Temperature nignego predela HTTP: "); Serial.println(TempVklNasosa); Serial.println(); } }все заработало как хотел