Python – HC-06 (BT module) becomes un-responsive after ~20 minutes

arduinobluetoothpython

I am seeing the following behavior on a HT-06 BT module (http://www.amazon.com/gp/product/B009DZQ4MG/ref=od_aui_detailpages00?ie=UTF8&psc=1) wired to an Arduino Uno.

The module works great for ~20m and then fails (the unit appears to shutdown – no lights are illuminated on the BT device). Arduino continues to run fine.

I am periodically querying the device from Python (PySerial) running on an OSX/MB through integrated bluetooth. Here is a log of the communication and you can see the failure after 20m.

[!] 2015-03-05 15:15:01.344719
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
[x] Blocking on recv
[x] Closing socket
^@^@^@^@^@
[!] 2015-03-05 15:20:00.766638
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
[x] Blocking on recv
[x] Closing socket
^@^@^@^@^@
[!] 2015-03-05 15:25:01.265796
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
[x] Blocking on recv
[x] Closing socket
^@^@^@^@
[!] 2015-03-05 15:30:00.787703
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
[x] Blocking on recv
[x] Closing socket
^@^@^@^@^@^@
[!] 2015-03-05 15:35:00.795710
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
Traceback (most recent call last):
  File "/Users/test.py", line 28, in <module>
    raise serr
socket.error: [Errno -536870195] Cannot connect to 1 on 30:14:12:19:26:86
^@^@^@^@^@
[!] 2015-03-05 15:40:01.194140
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
Traceback (most recent call last):
  File "/Users/test.py", line 28, in <module>
    raise serr
socket.error: [Errno -536870195] Cannot connect to 1 on 30:14:12:19:26:86
^@^@^@^@^@
[!] 2015-03-05 15:45:00.857675
[x] Finding device and service port
[x] Attempting connection: (30:14:12:19:26:86) on (1)
Traceback (most recent call last):
  File "/Users/test.py", line 28, in <module>
    raise serr
socket.error: [Errno -536870195] Cannot connect to 1 on 30:14:12:19:26:86

As you can see, once it fails, it never recovers. Anyone have ideas how to remedy this. I'll attempt to diagnose with another BT module (I have a few) to see if this is errant behavior of a bad device or an issue in my overall architecture.

TIA! (thanks in advance!)

UPDATE

It seems to have nothing to do with time and more to do with number of requests before failing. For example, I increased the frequency to run every 2minutes and you can see after 4x attempts the BT board fails:

[!] 2015-03-05 19:16:00.679951
[x] Finding device and service port
[x] Attempting connection: (30:14:10:14:11:85) on (1)
[x] Blocking on recv
[x] Closing socket
[x] Nothing consumed (0), exit
^@^@
[!] 2015-03-05 19:18:00.835225
[x] Finding device and service port
[x] Attempting connection: (30:14:10:14:11:85) on (1)
[x] Blocking on recv
[x] Closing socket
[x] Nothing consumed (0), exit
^@^@
[!] 2015-03-05 19:20:01.161330
[x] Finding device and service port
[x] Attempting connection: (30:14:10:14:11:85) on (1)
[x] Blocking on recv
[x] Closing socket
[x] Nothing consumed (0), exit
^@
[!] 2015-03-05 19:22:01.499951
[x] Finding device and service port
[x] Attempting connection: (30:14:10:14:11:85) on (1)
[x] Blocking on recv
[x] Closing socket
[x] Nothing consumed (0), exit
^@^@
[!] 2015-03-05 19:24:01.119598
[x] Finding device and service port
[x] Attempting connection: (30:14:10:14:11:85) on (1)
Traceback (most recent call last):
  File "/Users/test.py", line 28, in <module>
    raise serr
socket.timeout: connect timed out
^@/Library/Python/2.7/site-packages/lightblue/_lightblue.py:88: UserWarning: findservices() couldn't get services for : Timed out getting services for
  warnings.warn(msg)

Again, once it fails, it never will recover.

Best Answer

Sounds like a fault in the firmware of the HC-06 module. If you issue the "AT+VERSION" command, what version do you see running on your module? It might be worth contacting the vendor with the version you have and what you're seeing. They may be aware of the issue and could tell you how to either upgrade the firmware of your module or send you a new one.

Good luck, it seems unlikely you're doing something wrong.

In the meantime, and this is a hack, but you could power the module through a transistor or FET that the Arduino could control from one of its pins. Every 10 minutes (or however long you think it will be until a fault) it toggles the pins to power the HC-06 adapter on and off. :/ Not great but might at least keep it from failing and never recovering.

Related Topic