[英]Alexa smart home skill: problem with discover devices
I have problems with the discovery of devices of my Alexa Smart Home skill.我在发现 Alexa Smart Home 技能的设备时遇到问题。
Steps which work:工作步骤:
My problem: After the Alexa Skill returns from discovery of devices task, no new devices are visible in the Alexa Skill.我的问题:在 Alexa Skill 从发现设备任务返回后,Alexa Skill 中看不到新设备。
When I use the code from the sample (where no request to an external Rest API happens), the device is visible in the Alexa skill after the Alexa discovery task.当我使用示例中的代码时(没有对外部 Rest API 的请求),在 Alexa 发现任务之后,该设备在 Alexa 技能中可见。
var https = require('https'); const AWS = require('aws-sdk'); exports.handler = function(request, context) { var options = { method: 'GET', hostname: 'xyz.azurewebsites.net', path: '/devices', headers: { Authorization: 'Bearer ' + request.directive.payload.scope.token, 'Content-Type': 'application/json' } }; var req = https.get(options, (response) => { var data = ''; response.setEncoding('utf8'); response.on('data', function(x) { data += x; } ); response.on('error', console.error); response.on('end', () => { var dataObj = JSON.parse(data); console.log("Retrieved response: " + JSON.stringify(dataObj.items)); const payload = { "endpoints": [] }; dataObj.items.forEach(item => { const device = { "endpointId": item.id, "manufacturerName": item.manufacturer, "friendlyName": item.displayName, "description": item.description, "displayCategories": ["SWITCH"], "cookie": { "key1": "arbitrary key/value pairs for skill to reference this endpoint.", "key2": "There can be multiple entries", "key3": "but they should only be used for reference purposes.", "key4": "This is not a suitable place to maintain current endpoint state." }, "capabilities": [ { "type": "AlexaInterface", "interface": "Alexa", "version": "3" }, { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "supported": [{ "name": "powerState" }], "retrievable": true } } ] }; payload.endpoints.push(device); }); console.log('payload ' + JSON.stringify(payload)); var header = request.directive.header; header.name = "Discover.Response"; console.log("DEBUG", "Discovery Response: ", JSON.stringify({ header: header, payload: payload })); //NEXT LINE IS EXECUTED WITHOUT ANY ERROR context.succeed({ event: { header: header, payload: payload } }); }); }); req.on('error', (e) => { console.log('problem with request: ' + e.message); }); };
I found the problem... The value of the property 'endpointId' contained a '@'.我发现了问题...属性“endpointId”的值包含一个“@”。 Then I changed the name to only letters, and it worked.
然后我将名称更改为仅字母,并且它起作用了。 Although in this article it says '@' can be used, the discovery of devices then has problems.
虽然在这篇文章中它说可以使用“@”,但设备的发现却有问题。 Hope this answer helps others from wasting time...
希望这个答案可以帮助其他人不要浪费时间......
I found another cause for the same symptom: for the entity's additionalAttributes (manufacturer, model etc.), one cannot use non-English characters.我发现了相同症状的另一个原因:对于实体的附加属性(制造商、型号等),不能使用非英文字符。 You can actually use any character ASCII from 32 to 126 (space to tilde), but you cannot use the backslash.
您实际上可以使用从 32 到 126(空格到波浪号)的任何字符 ASCII,但不能使用反斜杠。 So, no accent characters (international or extended ASCII) allowed.
因此,不允许使用重音字符(国际或扩展 ASCII)。
On the other hand, I could include a entity with '@' inside its endpointId.另一方面,我可以在其 endpointId 中包含一个带有“@”的实体。 I cannot explain why you couldn't.
我无法解释为什么你不能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.