简体   繁体   中英

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. I can send on/off commands to the lights using a "send code " command through the command line on the 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.

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. 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.

Would figuring out how to use an HTTP post be the best course of action, or is there an easier way?

There are many options but probably some Python web framework running on your Raspberry PI will do the job (Twisted, Django or many other). Python is preinstalled in the PI so it could be the easier choice.

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.

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 :)

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. Of course, if you need to learn how to make an android app, have a look here first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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