ESP32とスマホを接続した際のデータ取得トラブル

実現したいこと

ESP32をsoftAPで動作させてスマホから遠隔操作したいと考えています。
ボタンの押下時の動作は実現しましたが、数値入力の取得で躓いてしまい困っています。

前提

ESP32にスマホで遠隔操作します。接続はsoftAPで1:1接続です。
各種ボタンを押すとI/Oに出力が出る様にし、数値入力した場合はその数値を内部計算用に使用します。

発生している問題・エラーメッセージ

数値は取得できているようですが、何故かURLがエンコードされてしまうのか%**と言う文字に化けてしまい正常に取得できません。

#include <WiFi.h> const char ssid[] = "**********"; const char pass[] = "**********"; const IPAddress ip(192, 168, **, *); const IPAddress subnet(255, 255, 255, 0); String setno; String currentLine; const String html = R"rawliteral( <!DOCTYPE html><html lang='ja'><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style>input {color:white;margin:10px;text-align:center;font-size:20pt;background-color:rgba(0, 0, 0, 1);border-radius:10px;} div {font-size:26pt;color:red;text-align:center;}</style> <title>Controller</title></head> <body><div> <form method='get'> <input type='number' name='no'min="0" max="70" /> </form></div> <form method='get'> <input type='submit' name='aa' value='111' /> <input type='submit' name='bb' value='SET' /> <input type='submit' name='cc' value='222' /> <input type='submit' name='dd' value='333' /> <input type='submit' name='ee' value='緊急停止' /><br> </form></div> </body> )rawliteral"; void stop() { digitalWrite(15, LOW); digitalWrite(16, LOW); digitalWrite(17, LOW); digitalWrite(21, LOW); digitalWrite(22, LOW); } WiFiServer server(80); void setup() { Serial.begin(115200); WiFi.softAP(ssid, pass); delay(100); WiFi.softAPConfig(ip, ip, subnet); IPAddress myIP = WiFi.softAPIP(); pinMode(15, OUTPUT); pinMode(16, OUTPUT); pinMode(17, OUTPUT); pinMode(21, OUTPUT); pinMode(22, OUTPUT); delay(10); server.begin(); Serial.print("SSID: "); Serial.println(ssid); Serial.print("AP IP address: "); Serial.println(myIP); Serial.println("Server start!"); } void loop() { WiFiClient client = server.available(); if (client) { Serial.println("New Client."); while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); if (c == '\n') { if (currentLine.length() == 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); client.print(html); client.println(); break; } else { currentLine = ""; } } else if (c != '\r') { currentLine += c; } //numberが押されたら if (currentLine.endsWith("GET /?no")) { stop(); digitalWrite(15, HIGH); delay(500); stop(); } if (currentLine.endsWith("GET /?aa")) { stop(); digitalWrite(15, HIGH); delay(500); stop(); } if (currentLine.endsWith("GET /?bb")) { stop(); digitalWrite(16, HIGH); delay(500); stop(); } if (currentLine.endsWith("GET /?cc")) { stop(); digitalWrite(17, HIGH); delay(500); stop(); } if (currentLine.endsWith("GET /?dd")) { stop(); digitalWrite(21, HIGH); delay(500); stop(); } if (currentLine.endsWith("GET /?ee")) { stop(); digitalWrite(22, HIGH); delay(500); stop(); } } } client.stop(); Serial.println("Client Disconnected."); } }

コメントを投稿

0 コメント