简体   繁体   English

使用Android应用程序将命令发送到Raspberry PI

[英]Sending a command to Raspberry PI using an Android App

I'm currently working on a small project of simply controlling the lights in my apartment. 我目前正在从事一个仅控制公寓灯光的小型项目。 I have a Raspberry Pi setup to control the lights with a 433 Mhz transmitter. 我有一个Raspberry Pi装置,可以用433 Mhz发射器控制灯光。 I can send on/off commands to the lights using a "send code " command through the command line on the PI. 我可以通过PI上的命令行使用“发送代码”命令向灯光发送开/关命令。 I'm looking to create an Android App to do this for me, and I'm looking for a way to make this happen. 我正在寻找一个Android应用程序来为我完成此任务,并且正在寻找一种方法来实现这一目标。

The Raspberry Pi is always connected to the internet, so I was thinking about hosting an Apache Webserver on it, and then somehow sending it commands from the app. Raspberry Pi始终连接到Internet,因此我正在考虑在其上托管Apache Web服务器,然后以某种方式从应用程序发送命令。 Would anyone know how to go about doing this? 有人知道该怎么做吗? I have little knowledge about Apache or webservers to begin with, but my basic google searches have pulled up ideas about using http posts. 我对Apache或网络服务器一无所知,但是我的基本Google搜索已经提出了有关使用http帖子的想法。

Would figuring out how to use an HTTP post be the best course of action, or is there an easier way? 搞清楚如何使用HTTP帖子是最好的做法,还是有更简单的方法?

There are many options but probably some Python web framework running on your Raspberry PI will do the job (Twisted, Django or many other). 有很多选择,但可能是在Raspberry PI上运行的某些Python Web框架可以完成此任务(Twisted,Django或许多其他工具)。 Python is preinstalled in the PI so it could be the easier choice. Python已预先安装在PI中,因此可能更容易选择。

Your Android app will then run HTTP requests (using HttpClient or something more elaborated) to the Python web server that will run in response the bash code. 然后,您的Android应用将向Python Web服务器运行HTTP请求(使用HttpClient或更详细的方法),以响应bash代码而运行。

The real problem comes when you will want to secure your end point (via login or whatever secret sent via Https) to be sure you are the only one switching on/off your lights :) 真正的问题是当您想要保护端点(通过登录或通过Https发送的任何秘密)以确保您是唯一打开/关闭灯的人时:)

Personally I'd use an SSH library such as jsch to create a simple android app that sends the desired commands to your raspberry pi, on the press of a button. 我个人会使用SSH库(例如jsch)来创建一个简单的android应用,只需按一下按钮,即可将所需的命令发送到您的raspberry pi。 Of course, if you need to learn how to make an android app, have a look here first. 当然,如果您需要学习如何制作android应用,请先在这里看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM