wemosでalexaデバイス その10

# 概要
wemos d1で、alexaデバイスを作ってみる。
突然ですが、アレクサでwemosのLチカに、成功しましたので、報告します。
alexaアプリは、使いません。

# 環境
alexa echo dot 第三世代
wemos d1 r1

# 使用したライブラリー

fauxmoESP v3.5
ESPAsyncTCP

# 設定
v1.4 Higher Bandwidth
tcp port 80

# サンプルコード

```
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#include "credentials.h"

fauxmoESP fauxmo;
#define SERIAL_BAUDRATE	 	115200
#define LED_YELLOW		  	4
#define LED_GREEN		   	5
#define LED_BLUE			0
#define LED_PINK			2
#define LED_WHITE		   	15
#define ID_YELLOW		   	"yellow lamp"
#define ID_GREEN			"green lamp"
#define ID_BLUE			 	"blue lamp"
#define ID_PINK			 	"pink lamp"
#define ID_WHITE			"white lamp"

void wifiSetup() {
	WiFi.mode(WIFI_STA);
	Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
	WiFi.begin(WIFI_SSID, WIFI_PASS);
	while (WiFi.status() != WL_CONNECTED)
	{
		Serial.print(".");
		delay(100);
	}
	Serial.println();
	Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
void setup() {
	Serial.begin(SERIAL_BAUDRATE);
	Serial.println();
	Serial.println();
	pinMode(LED_YELLOW, OUTPUT);
	pinMode(LED_GREEN, OUTPUT);
	pinMode(LED_BLUE, OUTPUT);
	pinMode(LED_PINK, OUTPUT);
	pinMode(LED_WHITE, OUTPUT);
	digitalWrite(LED_YELLOW, LOW);
	digitalWrite(LED_GREEN, LOW);
	digitalWrite(LED_BLUE, LOW);
	digitalWrite(LED_PINK, LOW);
	digitalWrite(LED_WHITE, LOW);
	wifiSetup();
	fauxmo.createServer(true);
	fauxmo.setPort(80);
	fauxmo.enable(true);
	fauxmo.addDevice(ID_YELLOW);
	fauxmo.addDevice(ID_GREEN);
	fauxmo.addDevice(ID_BLUE);
	fauxmo.addDevice(ID_PINK);
	fauxmo.addDevice(ID_WHITE);
	fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
		Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
		if (strcmp(device_name, ID_YELLOW) == 0)
		{
			digitalWrite(LED_YELLOW, state ? HIGH : LOW);
		}
		else if (strcmp(device_name, ID_GREEN) == 0)
		{
			digitalWrite(LED_GREEN, state ? HIGH : LOW);
		}
		else if (strcmp(device_name, ID_BLUE) == 0)
		{
			digitalWrite(LED_BLUE, state ? HIGH : LOW);
		}
		else if (strcmp(device_name, ID_PINK) == 0)
		{
			digitalWrite(LED_PINK, state ? HIGH : LOW);
		}
		else if (strcmp(device_name, ID_WHITE) == 0)
		{
			digitalWrite(LED_WHITE, state ? HIGH : LOW);
		}
	});
}
void loop() {
	fauxmo.handle();
	static unsigned long last = millis();
	if (millis() - last > 5000)
	{
		last = millis();
		Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
	}
}





```

# 実行結果

「アレクサ、デバイスを探して」

```

[WIFI] Connecting to  ....................................
[WIFI] STATION Mode, SSID: ****, IP address: 192.168.0.104
[FAUXMO] Enabled
[FAUXMO] UDP server started
[FAUXMO] Device 'yellow lamp' added as #0
[FAUXMO] Device 'green lamp' added as #1
[FAUXMO] Device 'blue lamp' added as #2
[FAUXMO] Device 'pink lamp' added as #3
[FAUXMO] Device 'white lamp' added as #4
[MAIN] Free heap: 49336 bytes
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Client #0 connected
[FAUXMO] Handling /description.xml request
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling devicetype request
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "yellow lamp", uniqueID = "60:01:94:70:31:F8:00:00-00"
[FAUXMO] Sending device info for "green lamp", uniqueID = "60:01:94:70:31:F8:00:00-01"
[FAUXMO] Sending device info for "blue lamp", uniqueID = "60:01:94:70:31:F8:00:00-02"
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Sending device info for "white lamp", uniqueID = "60:01:94:70:31:F8:00:00-04"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling devicetype request
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "yellow lamp", uniqueID = "60:01:94:70:31:F8:00:00-00"
[FAUXMO] Sending device info for "green lamp", uniqueID = "60:01:94:70:31:F8:00:00-01"
[FAUXMO] Sending device info for "blue lamp", uniqueID = "60:01:94:70:31:F8:00:00-02"
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Sending device info for "white lamp", uniqueID = "60:01:94:70:31:F8:00:00-04"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "yellow lamp", uniqueID = "60:01:94:70:31:F8:00:00-00"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "green lamp", uniqueID = "60:01:94:70:31:F8:00:00-01"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "blue lamp", uniqueID = "60:01:94:70:31:F8:00:00-02"
[FAUXMO] Client #0 disconnected
[MAIN] Free heap: 48480 bytes
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "white lamp", uniqueID = "60:01:94:70:31:F8:00:00-04"
[FAUXMO] Client #0 disconnected
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "yellow lamp", uniqueID = "60:01:94:70:31:F8:00:00-00"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "green lamp", uniqueID = "60:01:94:70:31:F8:00:00-01"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "blue lamp", uniqueID = "60:01:94:70:31:F8:00:00-02"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "white lamp", uniqueID = "60:01:94:70:31:F8:00:00-04"
[FAUXMO] Client #0 disconnected
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Responding to M-SEARCH request
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes


```

「新しいデバイスを５個、登録しました。」
「アレクサ、ピンクのランプを点けて」
「はい」
「アレクサ、ピンクのランプを消して」
「はい」


```

[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[FAUXMO] Client #0 connected
[FAUXMO] Handling state request
[MAIN] Device #3 (pink lamp) state: ON value: 255
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling state request
[MAIN] Device #3 (pink lamp) state: ON value: 254
[FAUXMO] Client #0 disconnected
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Client #0 disconnected
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "yellow lamp", uniqueID = "60:01:94:70:31:F8:00:00-00"
[FAUXMO] Client #0 disconnected
[MAIN] Free heap: 48832 bytes
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "white lamp", uniqueID = "60:01:94:70:31:F8:00:00-04"
[FAUXMO] Client #0 disconnected
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "pink lamp", uniqueID = "60:01:94:70:31:F8:00:00-03"
[FAUXMO] Client #0 disconnected
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[MAIN] Free heap: 48832 bytes
[FAUXMO] Client #0 connected
[FAUXMO] Handling list request
[FAUXMO] Sending device info for "blue lamp", uniqueID = "60:01:94:70:31:F8:00:00-02"

```

以上。