1

I am using a Raspberry Pi Zero W. I have succeeded in connecting the Pi to my Android Device on startup of Pi. Then I turn on Internet Sharing to make sure my Pi has an internet connection. I want to make an application which can receive data from Android Device and run preexisting scripts based on it without using ssh, if possible.

I normally use Juice SSH on my android phone to run scripts on the Pi but that involves manual work like finding and executing the script which I do not want my user to do.

The script I want to run is a Google Directions Python Script. I have the script ready, it just takes input of Origin and Destination from the user. After that it fetches the Direction Response and starts showing instructions on a screen connected to the Pi.

TLDR: I would like to know a way to initiate a python script on a Raspberry Pi from an Android Device connected via Bluetooth. Do I need to make a server? Is it possible using Firebase?

  • Does ur Pi has wifi module? If so, I suggest u to open a http server in Pi, that's the simple, fast and easiest way. – Lau Real Jan 14 '19 at 06:26
  • Thanks for the reply. My Pi does have a Wifi module. Would a simple HTTP server suffice? Or do you recommend something like NodeJS? – LearnEveryday Jan 14 '19 at 06:34
  • I think python http server, like web.py, flask, tornado is enough to meet ur needs. – Lau Real Jan 14 '19 at 06:39

2 Answers2

0

I actually mounted something very similar not too long ago. You may be able to get around various ways but I think some sort of server is going to be needed any way.

Take a look at my public repository in github!

  1. git clone https://github.com/NanoSpicer/XpressShutdown

You could then modify my index.js file like so:

#!/usr/bin/node
const command = 'python yourscript.py';
const proc = require('child_process');
const express = require('express');
const app = new express();
const router = express.Router();

router.get('/customComand', (request, response) => {
    // you could even catch parameters with this, edit your command string and pass them into the script
    proc.exec(command, (err, stdout, stderr) => {
        response.json({output: stdout});
    });
});

app.use('/raspi', router);
app.listen(80);
console.log('Server is running');
  1. Get that server up and running as a background process with:

    chmod +x index.js

    ./index.js & # you can do this because of the shebang

  2. Make the HTTP request like http://{your-raspi-IP-address}/raspi/customComand

And now you could run your command wherever in the world if you can perform an http request to your raspi!

Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
0

I solved this problem by using the Jsch Library for Android. It is quite simple and well documented. It allows me to start a SSH connection with a set command that I want to execute on the Server.