I am trying to communicate between a pair of RPi's both with Ciseco XRF Radios on Slice of Pi's.
My end goal is for RPi1 to send a specific phrase to RPi2 which will pick it up, perform some actions(collecting data from some sensors) and send a response; I figured serialport.read/write is the best way to do this.
I'm working on the very basic stage of this which is simply RPi2 listening to the serial port and printing whatever it recieves. My code is as follows:
import serial
while True:
serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5)
command = serialport.read()
print str(command)
I can run this fine and it picks things up that I type/paste into RPi1 but not reliably; for example if I paste 'hello world' into the terminal on RPi1 I get:
l
l
o
appearing at RPi2. If I add a time delay (time.sleep(3) for example) I get nothing. My guess is that it is only picking up data if it is sent at the same time as it is reading.
Is there some way to reliably read everything that comes out of the serial port? (Maybe RPi2 store the input somewhere and read everything since its last read or something.)