Open pymenow opened 1 year ago
Disconnecting established connections and calling power_off
is a good way to gracefully terminate. There should be more examples of that in the code base, I'll try to add some.
It is normal that you'd observe a reason=22
event when you disconnect: when disconnecting explicitly, you can send a reason code to the peer, and they'll see that code in their disconnection event. Then the caller gets an event for the disconnection on its end, with reason=22 (HCI_CONNECTION_TERMINATED_BY_LOCAL_HOST_ERROR)
, meaning that you got disconnected because you asked for it. By default, the reason you send to the peer is HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR
, but you can send other reasons if you want as well.
Thanks, one of the reasons for asking is, after terminating the script, when I scan for devices I do see the device name in the list of devices found.
I just checked, and indeed, the power_off()
method doesn't reset the controller, so if it was advertising, it will continue to do so, so you'll see it from other devices (but any connection attempt will fail). For now, I recommend doing a reset()
before shutting down if you want to avoid that, but I really should have power_off()
do the reset automatically, since it doesn't make sense to power off the device yet leave the controller in an active state. PR coming shortly.
perfect thanks ! I had included reset() , as the power_on() method calls this first .
Here is what I do for graceful exit, now. disconnect devices if connected. device.power_off() device.host.reset()
With the scripts running , what would be a graceful way to terminate and exit ? Here is what i am doing -
BTW irrespective of what reason i give for the disconnect device , the disconnect reason is always 22 .