如何使用Amazon Alexa访问本地API

编程入门 行业动态 更新时间:2024-10-06 01:41:06
本文介绍了如何使用Amazon Alexa访问本地API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我打算为 Amazon Alexa 构建一套技能,这些技能将与

我正在努力弄清楚如何使Echo / Dot本身对树莓派进行API调用。

直接-无需通过Internet,因为目标设备将仅具有 Intranet 连接-它将能够从本地网络上的设备接收命令,但无法通过世界访问。

据我了解,典型的工作流程如下

回声-> Alexa服务-> Lambda

其中Lambda函数会将一滴数据返回到智能家居设备;使用此返回值

是否有可能,如何使Alexa设备本身向本地网络上的设备发出API请求,收到lambda的回复后?

解决方案

我遇到了同样的问题,我的解决方法是将SQS用作消息总线,这样我的RaspberryPi不需要从互联网上访问。

Echo<- > Alexa服务<-> Lambda-> SQS-> RaspberryPi A | + ------ SQS< ----- +

此只要在以下条件下工作正常:

  • 您在RaspberryPi上启用了SQS的长轮询(20秒)并将每个请求的最大消息设置为1
  • 您在Alexa和RaspberryPi之间没有来回并发消息

提供以下好处:

  • 最大消息大小为1,队列中只有一条消息可用时,SQS请求将返回,甚至在长轮询超时未得到满足之前
  • 在整个月中一次只向SQS进行一次长轮询,这符合100万次SQS免费套餐的要求
  • 没有特殊的防火墙权限,无法从互联网访问您的RaspberryPi,因此从lambda进行RaspberryPi的连接始终有效
  • 比将RaspberryPi暴露于互联网更安全没有开放的开放端口可用于苹果攻击性程序

I intend to build a set of skills for Amazon Alexa that will integrate with a custom software suite that runs on a RaspberryPi in my home.

I am struggling to figure out how I can make the Echo / Dot itself make an API call to the raspberry pi directly - without going through the internet, as the target device will have nothing more then an intranet connection - it will be able to receive commands from devices on the local network, but is not accessible via the world.

From what I have read, the typical workflow is as follows

Echo -> Alexa Service -> Lambda

Where a Lambda function will return a blob of data to the Smart Home device; using this return value

Is it possible, and how can I make the Alexa device itself make an API request to a device on the local network, after receiving a response from lambda?

解决方案

I have the same problem and my solution is to use SQS as the message bus so that my RaspberryPi doesn't need to be accessible from the internet.

Echo <-> Alexa Service <-> Lambda -> SQS -> RaspberryPi A | +------ SQS <-----+

This works fine as long as:

  • you enable long polling (20sec) of SQS on the RaspberryPi and set the max messages per request to 1
  • you don't have concurrent messages going back and forth between Alexa and the RaspberryPi

This give the benefit of:

  • with a max message size of 1 the SQS request will return as soon as one message is available in the queue, even before the long poll timeout is met
  • with only 1 long polling at a time to SQS for the entire month this fit under the SQS free tier of 1 million requests
  • no special firewall permission for accessing your RaspberryPi from the internet, so the RaspberryPi's connection from the lambda always "just works"
  • more secure than exposing your RaspberryPi to the internet since there are no open ports exposed for malicious programs to attack

更多推荐

如何使用Amazon Alexa访问本地API

本文发布于:2023-11-28 03:30:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640785.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   Amazon   API   Alexa

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!