I have 3 Pi's on a network that need to scan one GPIO on each, and if that GPIO changes, broadcast to the other two so they can trigger another GPIO as an output to trip a local relay. HELP??
Because of a lack of details, I'm going to give you some pseudo-code that should get you pointed in the right direction...
I'm going to assume you can make system calls and that you have netcat installed (comes installed by default with Raspbian).
#!/bin/bash # Notifier script to send notifications of state changes written in # bash pseudo-code. # your code that watches for interrupts on a given GPIO pin # An iterrupt has been triggered, send notification notification="your message" # note: due to the nature of netcat, you're only going to be able to send single-line messages notifyees="192.168.1.100 192.168.1.110 192.168.1.120" # a string of space-separated IP addresses for RPi's that need to be aware of the GPIO state change notificationPort=8081 # should be the same in both scripts # send notification to each notifyee for notifyee in $notifyees do echo $notification | nc $notifyee $notificationPort done # congratulations, you've communicated the change in GPIO state to all notifyees
#!/bin/bash # Notifyee script to receive notifications of state changes written in # bash pseudo-code. notificationPort=8081 # should be the same in both scripts # start an infinite loop so that we can listen for multiple messages while : do # listen for message on network stateChange=$(nc -l $notificationPort) # We received a message, now process that message # for the sake of security, you may want to implement message signing # with gpg to ensure that only valid messages are processed case "$stateChange" in # state option) # code to run for state option ;; *) # code to run if state not matched ;; esac done