自作楽器用音源モジュール作成(4)
Androidアプリの開発環境周辺で滞ってしまったので、ESP-WROOM-02のファームと半田付けを進めた。
Wifi-Serial Bridge
クエリはどうでもいいので受けたデータをそのまま数値変換してシリアルに流すモジュールにした。
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> /* Set these to your desired credentials. */ const char *ssid = "Wifi-Serial Bridge"; const char *password = "password"; ESP8266WebServer server(80); /* Just a little test message. Go to http://192.168.4.1 in a web browser * connected to this access point to see it. */ void handleRoot() { uint8_t argc = server.args(); for(uint8_t i = 0 ; i < argc ; ++i){ String data = server.arg(i); uint8_t num = 0x0; for(uint8_t i = 0 ; i < data.length() && i < 0xff ; ++i){ char c = data.charAt(i); if('0' <= c && c <= '9') num = (num << 4) | (c - '0'); else if('A' <= c && c <= 'F') num = (num << 4) | (c - 'A' + 0xa); else if('a' <= c && c <= 'f') num = (num << 4) | (c - 'a' + 0xa); else { server.send(200, "text/html", "NG"); return; } if(i & 0x1) { //Serial.print(num, HEX); Serial.write(num); num = 0x0; } } } server.send(200, "text/html", "OK"); } void setup() { delay(1000); Serial.begin(115200); Serial.println(); //Serial.print("Configuring access point..."); WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); //Serial.print("AP IP address: "); //Serial.println(myIP); server.on("/", handleRoot); server.begin(); //Serial.println("HTTP server started"); } void loop() { server.handleClient(); }
前回のソースから大した変更はなし。ひとまずこれで動ける。