johnny cigar
johnny cigar

Reputation: 119

raspberry pi and android phone communication

I want to run python scripts on raspberry pi and control this process with my android phone. Now, I can run python scripts on rpi3 from my phone via ssh. I have 2 questions:

  1. If a python script on the pi runs how could I stop running the script with my phone?

  2. How can I send back a message to my phone that the script-running has ended?

Thanks

Upvotes: 1

Views: 602

Answers (1)

campovski
campovski

Reputation: 3163

The easiest way would be to use Flask. Flask is a Python library that basically runs a website server for you. Then you can create a website with Flask in which you have some buttons or switches. You can add actions to buttons (they are basically HTML buttons). So if you want to for example run a python script or stop it, you can just set the button's action to that. I advise you to read documentation for more.

  1. As for how to execute commands, I found you similar post to yours on Stack Overflow
  2. Then when the function you executed terminates, you can just redirect back to homepage (of course don't forget to implement that website will include data about running scripts or something so you know which are running and when you kill one script, the redirect will get you back to homepage and now there won't be any sign of that script anymore).

Now mind, that Flask is really lightweight, so if you plan to be extending your project significantly, you may want to consider using Nginx or Apache as a website back-end server, because they are more powerfull and Raspberry Pi can handle both easily (I am currently running Nginx on mine, was previously running Apache 2). In this case you might need to know a bit of JavaScript or PHP to be able to execute commands or if you don't mind learning, you can get yourself into Django, a pure-python front-end webserver which you combine with Nginx or Apache. I am running Nginx + Django for all dynamic-content sites I have/develop. There are lots of tutorials on YouTube snd documentation is among the best out there. Everything explained in great detail (some things aren't though, but great majority is) with lots of examples.

Upvotes: 3

Related Questions