ESP8266 - 设备不支持

物联网 亚历克斯 亚马逊回声
2021-05-29 07:55:39

我正在按照一些教程使用并尝试使用新的 Echo Dot 代(第 3 代)来控制 ESP8266。现在我只想使用SetBinaryState操作更改继电器的状态但是在发现设备后,如果我尝试将其打开,则会收到“设备不支持该设备”的响应。

我找到的教程是针对前几代的,数据包似乎有所不同,因为我必须在发现过程中修复一些问题。但是在设置状态时我无法弄清楚问题出在哪里,因为我还没有看到任何与此相关的文档。这是setup.xml

"<serviceList>"
    "<service>"
        "<serviceType>urn:Belkin:service:basicevent:1</serviceType>"
        "<serviceId>urn:Belkin:serviceId:basicevent1</serviceId>"
        "<controlURL>/upnp/control/basicevent1</controlURL>"
        "<eventSubURL>/upnp/event/basicevent1</eventSubURL>"
        "<SCPDURL>/eventservice.xml</SCPDURL>"
    "</service>"
"</serviceList>"

这些是我得到的日志:

Received packet of size 94
From 192.168.1.3, port 50000
Request:
M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
MX: 3
ST: ssdp:all


Responding to search request ...

Sending response to 192.168.1.3
Port : 50000
Response sent!

Received packet of size 101
From 192.168.1.3, port 50000
Request:
M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
MX: 3
ST: upnp:rootdevice


Responding to search request ...

Sending response to 192.168.1.3
Port : 50000
Response sent!

Responding to setup.xml ...
Sending :<?xml version="1.0"?><root><device><deviceType>urn:Belkin:device:controllee:1</deviceType><friendlyName>Living room light</friendlyName><manufacturer>Belkin International Inc.</manufacturer><modelName>Emulated Socket</modelName><modelNumber>3.1415</modelNumber><UDN>uuid:Socket-1_0-38323636-4558-4dda-9188-cda0e616a12b</UDN><serialNumber>221517K0101769</serialNumber><binaryState>0</binaryState><serviceList><service><serviceType>urn:Belkin:service:basicevent:1</serviceType><serviceId>urn:Belkin:serviceId:basicevent1</serviceId><controlURL>/upnp/control/basicevent1</controlURL><eventSubURL>/upnp/event/basicevent1</eventSubURL><SCPDURL>/eventservice.xml</SCPDURL></service></serviceList></device></root>

Responding to  /upnp/control/basicevent1...
Request: <?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:GetBinaryState></s:Body></s:Envelope>

Responding to  /upnp/control/basicevent1...
Request: <?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:GetBinaryState></s:Body></s:Envelope>

然后是大量的这些数据包:

Received packet of size 278
From 192.168.1.1, port 1900
Request:
NOTIFY * HTTP/1.1 
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age=3000
Location: http://192.168.1.1:5431/igdevicedesc.xml
SERVER: Router UPnP/1.0 miniupnpd
NT: uuid:f5c1d177-62e5-45d1-a6e7-9446962b761e
USN: uuid:f5c1d177-62e5-45d1-a6e7-9446962b76

我注意到的一件事是eventservice.xml永远不会被调用,但我不确定这是否正确。

1个回答

摆弄之后我发现看起来你必须在每次SetBinaryState请求后发送设备状态

因此,如果 ESP 节点收到SetBinaryState命令,它将必须以GetBinaryState.

void Light::_handleCommands()
{
  Serial.println("Responding to /upnp/control/basicevent...1");      

  String request = server->arg(0); 

  if (request.indexOf("SetBinaryState") >= 0) 
  {
    if (request.indexOf("<BinaryState>1</BinaryState>") >= 0) 
    {
        Serial.println(" - Got Turn on request");
        lightStatus= turnOnLight();

        sendLightStatus();
    }

    if (request.indexOf("<BinaryState>0</BinaryState>") >= 0) 
    {
        Serial.println(" - Got Turn off request");
        lightStatus= turnOffLight();

        sendLightStatus();
    }
  }

  if (request.indexOf("GetBinaryState") >= 0) 
  {
    Serial.println(" - Got light state request");

    sendLightStatus();
  }

  server->send(200, "text/plain", "");
}

最重要的是,看起来响应必须“有意义”,即。如果收到打开请求,它必须在GetBinaryState. 否则 Alexa 会说设备没有响应或出现故障。