2

I have multiple Raspberry Pi(RPis) using which I have to send data (wireless,using Long Range modules connected to TX RX of RPi) on just one Rpi.

All the RPis(Ones sending data) use different frequency so I thought that if receiver could switch between these frequencies quickly, they could receive data and hence I used threads to switch the receiver frequencies.

This is the code:

#!/usr/bin/env python
import loraset
import gatewaydict
import lorainit
import threading
import time

def freq1():
    while True:
        loraset.carrierfreq(gatewaydict.freqdict[1])
        data = lorainit.ser.read(100)
        print data
    return

def freq2():
    while True:
        loraset.carrierfreq(gatewaydict.freqdict[2])
        data = lorainit.ser.read(100)
        print data
    return 

def callthread():
    if gatewaydict.freqdict[1] != 'not assigned':
        t1 = threading.Thread(target = freq1)
        t1.start()

    if gatewaydict.freqdict[2] != 'not assigned':
        t2 = threading.Thread(target = freq2)
        t2.start()
return

But it shows the following error for each thread individually

1. 'device reports readiness to read but returned no data '
SerialException: device reports readiness to read but returned no data 
(device disconnected or multiple access on port?)

This method has failed, is there some other way to receive the data with above mentioned constraints or can this code be improved to work?

  • 1
    Just brainstorming - perhaps try multi-processing instead of multi-threading. – tlfong01 May 1 at 5:37
  • The error message is multiple access on port. I guess this means that your have only one serial port but two threads are accessing the same port. Since Rpi UART has only one pair of Rx, Tx. Are you using demux serial, software bit bang serial, USB to TTL adapter serial? I think USB/TTL is the easiest to debug. One other thing is that have you first tested the master Rpi and say two slave Rpi's locally, using physical wires instead of long range (ISM band?) modules? – tlfong01 May 1 at 6:44
  • I have connected the module to GPIO pins. The program works perfectly for one to one communication, which doesn't use threads or multiprocessing(but not many to one). I tried multiprocessing but it didn't help either – TotallyNoob May 1 at 6:51
  • Just another brainstorming idea. I have done mutliprocessing, built in uart, and USB/TTL adapter separately, but not everything together. What I am suggesting is the following. (1) use 2 separate USB/TTL adapters to get two extra serial ports for the slave Rpi's. (2) master Rpi yo send out bytes through built in serial port GPIO 14, 15, if I remember the numbers correctly. The 2 slave Rpi's will each connect their GPIO 14, 15 to one of the two USB aerial port. I am just doing some wild thinking. Don't laugh too loudly if I am making stupid mistakes. :) PS not sure I understood question – tlfong01 May 1 at 7:08
  • Sorry, earlier I was thinking too quickly and messed up about which Rpi uses which serial port. Let me think slowly. It should be like this: (1) master Rpi uses the two USB serial ports, one USB serial port to talk to slave Rpi number 1, another serial port to talk to slave Rpi number 2. On the slaves side, each slave uses its built in serial port (GPIO Tx, Rx = pin 14, 15) to talk to the USB serial port assigned to it. Yes, the master Rpi does not need to use its built in serial port. – tlfong01 May 1 at 8:01

Your Answer

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

Browse other questions tagged or ask your own question.