0

Preview I'm working on a ROV project and there are 3 Raspberry Pi, cameras sensors and motor drivers which are controlling from Raspi. I need to control them via my laptop and I don't have internet connection so I installed RaspAP and created a hotspot so 3 Raspis can connect the same network. The Raspi that raspap installed will be connected my laptop via ethernet (since wifi or other wireless signals blow underwater. )

Problem : I can access the raspi that raspap installed with ssh and from that raspi I can access another raspi with ssh since they are in the same LAN but I need to control them with one gui from my laptop. The commands I want to send like: "ChangeDutyCycle(n)" and receive sensor data but I couldn't find out how to send this commands. Some of the topics said "use web server" but I want to use desktop GUI (That I built with python-Tkinter)

Summary of the question : How can i control multiple raspis with one gui, without internet connection (LAN provided) ?

*Gui is like : Simplified GUI example

  • I can control all raspis one by one connecting from my pc but I cant connect and send-receive data simultaneously from all raspis
4

Both pigpio and gpiozero provide Python modules which can run on any Python capable machine (e.g. Windows, Macs, Linux etc).

Both pigpio and gpiozero allow you to control and monitor the GPIO of one or more networked Pis.

The pigpio daemon must be running on each Pi.


The following example is for a pigpio script.

#!/usr/bin/env python

import time
import pigpio

# connect to pis

pi_tom = pigpio.pi('tom')  # pi_tom accesses tom's GPIO

if not pi_tom.connected:
   print("connection to tom failed")
   exit()

pi_dick = pigpio.pi('dick') # pi_dick accesses dick's GPIO

if not pi_dick.connected:
   pi_tom.stop()
   print("connection to dick failed")
   exit()

pi_harry = pigpio.pi('harry') # pi_harry accesses harry's GPIO

if not pi_harry.connected:
   pi_tom.stop()
   pi_dick.stop()
   print("connection to harry failed")
   exit()

tom_dc = 0
dick_dc = 50
harry_dc = 100

PWM_GPIO = 18

pi_tom.set_mode(PWM_GPIO, pigpio.OUTPUT)
pi_dick.set_mode(PWM_GPIO, pigpio.OUTPUT)
pi_harry.set_mode(PWM_GPIO, pigpio.OUTPUT)

while True:

   try:

      pi_tom.set_PWM_dutycycle(PWM_GPIO, tom_dc)
      pi_dick.set_PWM_dutycycle(PWM_GPIO, dick_dc)
      pi_harry.set_PWM_dutycycle(PWM_GPIO, harry_dc)

      tom_dc += 1
      harry_dc += 2
      dick_dc += 4

      if tom_dc > 255:
         tom_dc = 0

      if dick_dc > 255:
         dick_dc = 0

      if harry_dc > 255:
         harry_dc = 0

      time.sleep(0.1)

   except KeyboardInterrupt:
      break

print("\nTidying up")

pi_tom.stop()
pi_dick.stop()
pi_harry.stop()
  • I made research about pigpio and looked the official examples but couldn't figured out how to reach gpio controls over lan. There are no tutorial or example. What must my code include to say "<ip>:port gpio.setup(18,gpio.OUT)" or <ip>:port gpio.PWM(18,1000) " or "<ip>:port ChangeDutyCycle(50)" – CanSevgi Aug 24 '18 at 17:13
  • @CanSevgi Added example to answer. – joan Aug 24 '18 at 17:38
1

Python has a class, socketserver, to help make simple tcp/ip servers. This link is the documentation for python 3. If you're using python 2, then this is the link.

I would strongly suggest first making a simple server that runs on your Pi and merely writes text to the console. On the PC side, I would use miniterm or hyperterm to send commands to your server.

An easier solution might be to use an MQTT server such as mosquitto (sudo apt install mosquito). This is a very simple publish/subscribe protocol.

Since I already have mosquito running on one of my Pi's, I would probably use this.

Your PC program would use an MQTT client library too access the server. You would create a topic and send messages with that topic.

The receiving computer would subscribe to this topic and would use a MQTT client library to get the messages.

Only after you are sending and receiving messages reliably should you worry about the GPIO commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.