通过 IFTTT 在树莓派中运行 bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43292901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
run bash script in raspberry pi via IFTTT
提问by kuruvi
I have a raspberry pi running Alexa (amazon echo) that can instantly push a trigger to IFTTT, for an example I say "Alexa, trigger email to blablabla" and I immediately receive an email.
我有一个运行 Alexa(亚马逊回声)的树莓派,它可以立即将触发器推送到 IFTTT,例如我说“Alexa,将电子邮件触发到 blablabla”,然后我立即收到一封电子邮件。
My GoalI want to execute a bash script on the same raspberry pi with voice command (by Alexa) via IFTTT. Is there any IFTTT recipe that can instantly push a trigger to my raspberry pi? (so that I can instantly run a bash script) (Note: Dropbox doesn't support raspberry pi, though there is an uploader/downloader and the below script uses it with cronjob).
我的目标我想通过 IFTTT 使用语音命令(由 Alexa)在同一个树莓派上执行 bash 脚本。是否有任何 IFTTT 配方可以立即触发我的树莓派?(以便我可以立即运行 bash 脚本)(注意:Dropbox 不支持 raspberry pi,尽管有一个上传器/下载器,并且下面的脚本将它与 cronjob 一起使用)。
I found one (Raspi Runner) that runs cronjob every few minutes, but I'm not sure if I can setup cronjob for every second and use this script!!
我发现一个(Raspi Runner)每隔几分钟运行一次 cronjob,但我不确定我是否可以每秒设置一次 cronjob 并使用这个脚本!!
How can I do this?
我怎样才能做到这一点?
回答by alok
Short Answer:
IF
This - Alexa
Then
That - Adafruit/Maker Webhook
答案很简单:
IF
牛逼了- Alexa的
牛逼母鸡
牛逼帽子- Adafruit的/设备网络挂接
Longer Answer:
There are two options:
1)Alexa will notify IFTTT that trigger event has occurred. Against which, the action chosen is publishing an MQTTmessage. This MQTT channel is created by Adafruit. Needless to say, you need to write an MQTT feed reader at the RPi.
2) Maker web-hooks. You expose your RPi to the web, keep a server running on it. Expose a web-service which may be called from the Maker Webhook. This is personally my preferred option, but setup could be a pain, i.e. port forwarding from modem, router etc.
References:
1) Adafruit Official Site
2) MQTT Java Library
3) Hackster Tutorial - With option #1
4) Hackster Tutorial - With option #2
更长的答案:
有两种选择:
1)Alexa 会通知 IFTTT 触发事件已经发生。与之相反,选择的操作是发布MQTT消息。这个 MQTT 通道是由 Adafruit 创建的。不用说,您需要在 RPi 上编写一个 MQTT 提要阅读器。
2) Maker web-hooks。您将您的 RPi 暴露给网络,让服务器在其上运行。公开一个可以从Maker Webhook调用的网络服务。这是我个人的首选选项,但设置可能很麻烦,即从调制解调器、路由器等进行端口转发。
参考资料:
1) Adafruit 官方网站
2) MQTT Java 库
3) Hackster 教程 - 使用选项 #1
4)Hackster 教程 - 使用选项 #2