digidotcom / xbee-python

Python library to interact with Digi International's XBee radio frequency modules.
Mozilla Public License 2.0
185 stars 93 forks source link

Recovery after manual reset ('RESET' pin to low) #215

Closed ibantxo closed 2 years ago

ibantxo commented 3 years ago

Hi,

I have launch my "sender" program. That is a loop that sends 1 message, waits 10 seconds, and sends another message.... Then, when I put RESET pin to 0, the chip then resets correctly.

The "modem_status_received_callback" function detects --> [0] "Device was reset" How could I recover the communication via serial with the chip? I have tried: device.reset(), device.close(), device.open(), del device... but no working... The program logs some of the next messages, depending on code changes:

Only exit the python program and launch again solves the problem.

How could I recover the communication without exit the program?

Many Thanks in advance

Iban

tatianaleon commented 3 years ago

Hi @ibantxo,

What is managing the RESET pin? the same application? Could you send a code example where this issue is reproducible?

Best Regards

ibantxo commented 3 years ago

Hi @tatianaleon !!

Thank you for the response. Yes, the RESET (hardware) is an input pin (for example, the 6th in the Xbee SX 868). "Drive low to reset device". (min 100ns)

I am writting a script to work 24x7. With a frequency of 1/10s the 'TX node' sends a message to 'RX node'. Everything was OK, but sometimes the system stop working: the script goes on with its infinite loop, but the device.reset() does not working. So... I decided to try a "hard RESET" (using the pin). A 0V in tha pin resets the Xbee with no problem, but my python program cannot connect again. The program detects the reset via "modem_status_received_callback" function detects --> [0] "Device was reset". I have tried to reconnect but I have not got it.

When this happens, if I stop the script and launch it again, everything works great again. So the target is to ensure I can reset the hardware and the communication to continue sending messages.

The TX script is in the file attached --> testing_TX.txt

Many thanks in advance

Iban

tatianaleon commented 3 years ago

Hi @ibantxo:

In your example, I cannot see anything resetting the XBee (nor software nor hardware reset) I only see the function my_modem_status_callback that is not registered.

    # Define the callback.
    def my_modem_status_callback(status):
        print("Modem status: [%s] %s" % (status.code, status.description))
        if status.code == 0:
            if device is not None and device.is_open():
                print("Detected as open")
                device.close()

This function is closing the connection with the XBee and it is never opened again, so, in case it is registered, things are not going to work: the next time the application tries to send anything, it will throw an exception because the connection is closed.

I do not think that a software reset (device.reset()) or a hardware reset (Pin 6 RESET, https://www.digi.com/resources/documentation/Digidocs/90001538/#reference/r_pinouts.htm) have a high impact in your application (the boot time of the XBee firmware application is really short).

Best Regards