atlas0fd00m / rfcat

RfCat - swiss-army knife of ISM band radio
Other
553 stars 116 forks source link

Error: Resource busy // AttributeError: RfCat instance has no attribute 'chipnum' #51

Closed ssbernabeu closed 5 years ago

ssbernabeu commented 5 years ago

I have the following error when trying to use the YS1 to transmit more than once within the same script. I am not a pro at this so I think I'm just missing something after it transmits that does not make it crash when it goes into the loop for the second time (it always goes in the first time and listens with no problem). I have checked other related issues but I have not found anything that really applies to this case (most problems seemed to be after firmware updates bout I have not done any)

Error claiming usb interface:USBError(16, 'Resource busy') Error in resetup():ChipconUsbTimeoutException() Traceback (most recent call last): File "project/master.py", line 113, in inboundmessage = listen_with_timeout() File "project/master.py", line 13, in listen_with_timeout d = RfCat() File "/usr/local/lib/python2.7/dist-packages/rflib/chipcon_nic.py", line 304, in init self.mhz = CHIPmhz.get(self.chipnum) AttributeError: RfCat instance has no attribute 'chipnum'

I am using two different YS1 with the following RadioConfig:

== Hardware == Dongle: YARDSTICKONE Firmware rev: 0543 Compiler: SDCCv350 Bootloader: CC-Bootloader

== Software == rflib rev: 464

== Hardware == Dongle: YARDSTICKONE Firmware rev: 0348 Compiler: Not found! Update needed! Bootloader: CC-Bootloader

== Software == rflib rev: 464

edit: I updated the YS1 with no compiler to the following: == Hardware == Dongle: YARDSTICKONE Firmware rev: 5535 Compiler: SDCCv350 Bootloader: CC-Bootloader

== Software == rflib rev: 464

And the code I am using to listen is:

def listen_with_timeout():

setup the radio

d = RfCat()
d.setFreq(435000000)
d.setMdmSyncWord(0x1985)
d.setMdmModulation(MOD_GFSK)
d.setMdmDRate(1200)
decoded_pkt = ""
pkt = ""
begintime = time.time()
maxtimewaitingforamessage = 5
try:
    print("Starting to listen at time "+str(time.time()-begintime))
    d.setModeTX()
    pkt, _ = d.RFrecv(timeout=5000)
    d.setModeIDLE()
    print("Ended listening at time "+str(time.time()-begintime))
    print(pkt)
except (ChipconUsbTimeoutException, TypeError):
    pass
print("**Power cycling YS1**")
os.system("sudo /home/pi/uhubctl/./uhubctl -a cycle -p 2") # this power cycles the YS1 (well, the whole USB hub)
# done to avoid ---> Error in resetup():USBError(110, u'Operation timed out')
time.sleep(1)
return pkt

Thank you so much!!

ssbernabeu commented 5 years ago

I solved this problem by not using d.cleanup() and not running any transmit and listen actions as subprocesses or functions (def, etc). Some information for anyone that may need help in the future, as I had a hard time finding any:

I was trying to run a listen and transmit script on a loop. Some conclusions I have come to are: the chipcon error is always expected to appear when using RFrecv(time_in_miliseconds) if nothing is heard so use a try-except to pass the error so your program does not crash. When something was heard there seemed to be no problem at all! I also got the chipcon error when listening and then trying to transmit but it seems this was caused by the function d.cleanup() so if you are using this you are gonna want to either delete it or put it at the very end of the script, outside of any while loops. I thought it only emptied variables and queues but I probably missed something.

As well, using d.setModeTX(), d.setModeRX() and d.setModeIDLE() makes no difference at all, as it only sets a predetermined state. I have seen other posts that claim that this solves the ChipconUsbTimeoutException error.

Sergio

atlas0fd00m commented 5 years ago

thank you, @ssbernabeu ! yes, this is helpful to have written up.

i'm not sure this is what caused the original problem, which was "USBError: timeout"... but that can be caused by numerous things, including the USB bus itself. i hope you have resolved that problem as well, but if it comes back, i'm happy to help you troubleshoot.

as for power-cycling the YS1 from within the python script, that's a new one i've not done before, and i'd have to give it a little consideration. RfCat attempts to reconfigure the dongle if it gets unplugged and replugged, or some other reset... and it happens in "resetup()". there may be some nuance to it, tho. please let me know if you get a solid solution working for this.

thanks, @