Skip to content Skip to sidebar Skip to footer

What Is The Best Way To Give A Linux Command From One Machine To A Different Machine?

I have a Django project on my laptop. It works perfectly fine on my machine. This web app takes input from the user in the form of an image and reads the content in it. If the cont

Solution 1:

Solution 1: use SSH pre-shared key to login via SSH without a password. See this link for how to do it. After you have configured it properly, you are able to run a command on your server:

ssh hostname-or-ip-of-the-raspi command arg1 arg2 ...

and will execute command arg1 arg2 ... on the Raspberry PI, without being prompted for a password.

Solution 2: use TCP communication, and write a server for the Raspberry PI and a client for your server. You can use raw sockets, or some high level library such as zmq.


Solution 2:

I am considering you are a simple intermediate programmer and based on that giving you two solutions with their pros and cons.

Solution 1: Using a simple Flask app on Raspberry PI

You can modify the following code to request a simple app running on PI to perform any actions.

Code:

from flask import Flask
app = Flask(__name__)

@app.route('/runMotor')
def hello_world():
    runMotor()
    # Run any script here
    return "Motor Ran"

You can then use your raspberry to call something like:

<your_rasp_ip>:<port>/runMotor

Pros: Easy to implement, You can even move it further to be used from outside your firewall.

Cons: Slow and would not be suitable for very rapid concurrent request. Concurrency is the downfall (or you can queue the requests and then keep a check for this issue)

Solution 2 Using MQTT: MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.

You can play with your code, checkout example here

Pros: Extremely lightweight and removes concurrency overhead, MQTT is an asynchronous messaging protocol. This is best used for real time systems.

Cons: MQTT is a very light messaging protocol and cannot support heavy payloads.


Post a Comment for "What Is The Best Way To Give A Linux Command From One Machine To A Different Machine?"