| 45 | シリアルコンソールを開き、リモコンを赤外線リモコン受信モジュールに向けて電源ボタンを押します。[[BR]] |
| 46 | すると下図の様にリモコンのコードが表示されます。SHARPのリモコンなのですがPANASONICと表示されていますね。ライブラリとサンプルスケッチを確認してみるとSHARPリモコンの判定は未実装の様でした。(2016/06/13現在)ここではライブラリの中身の話は本筋ではありませんので、とりあえずこのまま表示された情報を使用します。[[BR]] |
| 47 | [[Image(2740-11.jpg,300)]][[BR]] |
| 48 | |
| 49 | 電源ボタンのコードが判明したので、次のようなスケッチを作成します。電源ボタンと音量の上下ボタンを実装しました。[https://github.com/SWITCHSCIENCE/samplecodes/tree/master/ESPr-IR/ESPrIR-Server サンプルスケッチ(GitHub)][[BR]] |
| 50 | {{{ |
| 51 | |
| 52 | #include <ESP8266WiFi.h> |
| 53 | #include <WiFiClient.h> |
| 54 | #include <ESP8266WebServer.h> |
| 55 | #include <ESP8266mDNS.h> |
| 56 | #include <IRremoteESP8266.h> |
| 57 | |
| 58 | const char *ssid = "ssid"; |
| 59 | const char *password = "password"; |
| 60 | |
| 61 | ESP8266WebServer server ( 80 ); |
| 62 | IRsend irsend(14); |
| 63 | |
| 64 | void setup() { |
| 65 | Serial.begin(115200); |
| 66 | WiFi.begin(ssid, password); |
| 67 | irsend.begin(); |
| 68 | Serial.println(""); |
| 69 | |
| 70 | //wait for connection |
| 71 | while( WiFi.status() != WL_CONNECTED){ |
| 72 | delay(500); |
| 73 | Serial.print("."); |
| 74 | } |
| 75 | Serial.println(""); |
| 76 | Serial.print("Connected to "); |
| 77 | Serial.println(ssid); |
| 78 | Serial.print("IP address: "); |
| 79 | Serial.println(WiFi.localIP()); |
| 80 | |
| 81 | server.on("/",handleRoot); |
| 82 | server.onNotFound(handleNotFound); |
| 83 | server.begin(); |
| 84 | Serial.println("HTTP server started"); |
| 85 | } |
| 86 | |
| 87 | void loop() { |
| 88 | server.handleClient(); |
| 89 | } |
| 90 | |
| 91 | void handleRoot() { |
| 92 | char temp[800]; |
| 93 | int sec = millis() / 1000; |
| 94 | int min = sec / 60; |
| 95 | int hr = min / 60; |
| 96 | |
| 97 | char message[20]; |
| 98 | String(server.arg(0)).toCharArray(message,20); |
| 99 | |
| 100 | if(server.arg(0).indexOf("Power") != -1){ |
| 101 | Serial.println("Power"); |
| 102 | irsend.sendPanasonic(0x555A,0xF148688B); |
| 103 | delay(10); |
| 104 | irsend.sendPanasonic(0x555A,0xF148688B); |
| 105 | } |
| 106 | else if(server.arg(0).indexOf("Vol UP") != -1){ |
| 107 | Serial.println("Vol UP"); |
| 108 | irsend.sendPanasonic(0x555A,0xF148288F); |
| 109 | } |
| 110 | else if(server.arg(0).indexOf("Vol Down") != -1){ |
| 111 | Serial.println("Vol Down"); |
| 112 | irsend.sendPanasonic(0x555A,0xF148A887); |
| 113 | } |
| 114 | |
| 115 | snprintf ( temp, 800, |
| 116 | |
| 117 | "<html>\ |
| 118 | <head>\ |
| 119 | <title>ESPr IR Demo</title>\ |
| 120 | <style>\ |
| 121 | body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\ |
| 122 | </style>\ |
| 123 | </head>\ |
| 124 | <body>\ |
| 125 | <h1>ESPr IR DEMO</h1>\ |
| 126 | <p>Uptime: %02d:%02d:%02d</p>\ |
| 127 | <p>BUTTON :%s</p>\ |
| 128 | <form action=\"/\" method=\"post\">\ |
| 129 | <input type=\"submit\" name=\"button1\" value=\"Power\" style=\"width:30%; height:100px\">\ |
| 130 | <input type=\"submit\" name=\"button2\" value=\"Vol UP\" style=\"width:30%; height:100px\">\ |
| 131 | <input type=\"submit\" name=\"button3\" value=\"Vol Down\" style=\"width:30%; height:100px\">\ |
| 132 | </form>\ |
| 133 | </body>\ |
| 134 | </html>", |
| 135 | |
| 136 | hr, min % 60, sec % 60 ,message |
| 137 | |
| 138 | ); |
| 139 | server.send ( 200, "text/html", temp ); |
| 140 | } |
| 141 | |
| 142 | void handleNotFound() { |
| 143 | |
| 144 | String message = "File Not Found\n\n"; |
| 145 | message += "URI: "; |
| 146 | message += server.uri(); |
| 147 | message += "\nMethod: "; |
| 148 | message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; |
| 149 | message += "\nArguments: "; |
| 150 | message += server.args(); |
| 151 | message += "\n"; |
| 152 | |
| 153 | for ( uint8_t i = 0; i < server.args(); i++ ) { |
| 154 | message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; |
| 155 | } |
| 156 | server.send ( 404, "text/plain", message ); |
| 157 | |
| 158 | } |
| 159 | }}} |
| 160 | |
| 161 | |