connect two raspberry pi call python function - python

I have two raspberry pi's connected to a hub
One is the server and one is the client. what i want to do is run 2 python scripts on both raspberry pi's
Then call function on each raspberry so the server needs to call functions in the script that is running on the client and vice versa
But how can i do that because i dont really understand socket communication
I had a bit of code that worked but i needed the IP of both raspberry's all the time.
So hope someone can help so i can call functions on other raspberry pi's

Related

Remote GPIO (Pigpio) with input from laptop and output from Raspberry Pi

I'm working on an object detection project for IoT using a webcam and servo. In short, when the object detected by the webcam matches the data in the system, the servo will move. Can the webcam be connected to the laptop, and the servo on the Raspberry Pi? So the input is from the laptop and the output is on the Raspberry Pi using pi-gpio (Remote GPIO). How to? Thanks.
This link shows the GPIO Zero library being used with pigpio to allow remote control of the GPIO pins, from either another raspberry pi - or a PC. Once you configure GPIO Zero to use the pigpio library and connect, I believe you can just use the GPIO Zero libraries as per normal to control the Servo. (though I have not tried this myself!)
However I would probably use MQTT to decouple the two systems. If you run an MQTT broker on the Raspberry Pi (eg. Mosquitto) then the webcam software can publish a message to the MQTT broker, and the raspberry pi software can subscribe and act accordingly.
You can also run this with a cloud based MQTT system (eg. HiveMQ) so the Raspberry Pi and the PC with the Webcam don't even have to be in the same location.
A quick way is to use the Python socket library. Both devices need to be connected to the same network, and the sender needs to know the IP address of the receiver.

Calling Additional Scripts from Arduino-Cli when uploading to a board

I have a Raspberry Pi connected to an Arduino Mini that it normally communicates with over I2C. But I'd also like to be able to reflash the Mini with new code using Arduino-Cli from the Raspberry Pi (kinda rhymes!). This would involve connecting the Raspberry Pi's GPIO serial port to the Arduino's serial port. Additionally, the Arduino Mini requires a manual reset to be applied before its code can be reflashed, which is something the Raspberry Pi can do by toggling a GPIO pin attached to the Mini's reset line. I can do this with a simple Python script. The question is: is there a way for Arduino-Cli to call additional scripts as part of the upload command?

Run python public server with sockets from Raspberry Pi access point

I have a router that makes it extremely difficult to run port-forwarding through it. Plus, I would rather be able to just pretty much plug my Pi in and have my server running. Setting up a Raspberry Pi as a wireless access point is pretty easy and straight forward. I would like to have a python server, which runs on the same Raspberry Pi, that allows me to run a public server off of the access point. So basically instead of having to use port forwarding with my router, the server made with sockets in python uses the access point to be public. is this something that sounds possible?
update This is NOT for local use, I want it to be a server that I could connect to states away

Hide Database Credentials in Python Code on Raspberry Pi

I want to use Raspberry Pis to communicate collected Data via Python (Modbus TCP and RTU) scripts to a Database. These scripts are constantly running on the Pi and are connected to the Products where the data is coming from.
Consequently, we have to ship the already set up Raspberry Pi to the Customer. Now the Problem occurs, that the Database Credentials are stored in the Python Scripts running on the Raspberry Pi.
Is there a possibility to overcome this Problem?
Naive solution: Store database credentials on your server (or somewhere on internet) so every time Raspberry Pi run the script, it connect to the server to get the credentials first.
My recommended solution: Create an API (may be web API) to communicate with database and Rasp Pi only work with this API. By this way, the client side doesn't know about database's credentials and some private things you want to hide also.

Raspberry Pi custom commands in a scripting language through tcp/ip connection

I'm currently working on a project that requires me to control a step motor using a raspberry pi. I finished the motor control part of the raspberry pi, but I am not really sure on how to continue on the tcp/ip connection part of the project.
I am meaning to connect a client through the tcp/ip connection and letting the client upload a code that lets the client control the motor, in which there should already be custom commands implemented (e.g. "clockwise ": turns the motor a number of steps clockwise. "set 1": sets the gpio pin to 1, and etc.)
I apologize because my knowledge in raspberry pi and tcp/ip connections are really limited.
Can someone point me a way in the right direction? Thanks in advance.
If you are looking for a scripting solution you can do TCP/IP part using ssh. Client can use ssh to log into the RPi and run the commands. It can use scp for pushing updated code/script.
For automating you can look into Pexpect that lets you script your steps.

Categories