Jump to content

Start python script via phone

Dazzlock

I don't know if this is the right place to post, but anyways. I'm trying to start a script on my raspberry pi, that will then start a stepper motor, via my phone.

 

If anyone has a solution, please share and have a nice day!

 

Link to comment
Share on other sites

Link to post
Share on other sites

If the issue is how to get a set up a UI on your phone, one way that you could do this is to:

  1. Set up a basic webpage with a button (and whatever other UI you want)
  2. Then have that UI send requests to the Rasp Pi.

That would also let you run the script from any device with an internet connection.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, August Garcia said:

If the issue is how to get a set up a UI on your phone, one way that you could do this is to:

  1. Set up a basic webpage with a button (and whatever other UI you want)
  2. Then have that UI send requests to the Rasp Pi.

That would also let you run the script from any device with an internet connection.

Hmm, yes that would work, but I should probably explain what I want a bit further. So when I set an alarm on my phone I have an app that returns a variable with the timestamp of that alarm. I want to automatically send that variable to my pi so that it knows when to start the motor that will roll up my blinds about 5 minutes before the alarm goes off. Would that work with the method you talked about?

Link to comment
Share on other sites

Link to post
Share on other sites

If you don't need a UI, it would probably be easiest to look into how to send SSH commands from android/iOS/whatever you're using on your phone.

 

Pseudocode would be something like:

//  [Some Imports Here, Probably]
function alarm_app() {
  // Your current code
  return $some_time_stamp;
}
function main() {
  $timestamp = alarm_app();

  $user     = "john";
  $password = "mypassword";
  $host     = "192.168.100.23";
  $port     = 22;

  // Concatenate your timestamp into the command that you're running via SSH
  $command  = "sudo python start_motor.py " . $timestamp+(5*60);

  $ssh_session = start_session($user, $password, $host, $port);
  $ssh_session.send_command($command);
}
Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, August Garcia said:

If you don't need a UI, it would probably be easiest to look into how to send SSH commands from android/iOS/whatever you're using on your phone.

 

Pseudocode would be something like:


//  [Some Imports Here, Probably]
function alarm_app() {
  // Your current code
  return $some_time_stamp;
}
function main() {
  $timestamp = alarm_app();

  $user     = "john";
  $password = "mypassword";
  $host     = "192.168.100.23";
  $port     = 22;

  // Concatenate your timestamp into the command that you're running via SSH
  $command  = "sudo python start_motor.py " . $timestamp+(5*60);

  $ssh_session = start_session($user, $password, $host, $port);
  $ssh_session.send_command($command);
}

Thank you very much August Garcia! I will look into this. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×