Python API Troubleshooting using macOS

Python, Java, Android OS, etc.
Posts: 1
Joined: Thu Jul 13, 2017 7:31 am

Python API Troubleshooting using macOS

Postby DiogoC » Fri Jul 14, 2017 4:07 pm

Dear BITalino's team
I'm having trouble connecting and acquiring data form my BITalino using Python's API on my Mac.

I'm using a BITalino (r)evolution with regular BT, a MacBook Pro with macOS 10.12.5 (Bluetooth 2.1 i guess). I've installed revolution-python-api and I've tried to run both on Python 2.7 and 3.6 the Example in the API page and i'm getting multiple errors when executing, including:

print device.battery(batteryThreshold)
SyntaxError: invalid syntax

Traceback (most recent call last):
File "", line 1, in <module>
from bitalino import *
File "/Users/username/anaconda3/lib/python3.6/site-packages/", line 29
except Exception, e:
SyntaxError: invalid syntax

I solve (1) by commenting out the lines. Then error (2) appears. And I don't know how to solve it.

I just want to collect data using Python, either to print it on the terminal or saving it in some file for further analysis.
In addition, my Mac keeps disconnecting after few seconds from the BITalino. I have to reconnect it every try, not very convenient.

Thanks in advance!

Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Python API Troubleshooting using macOS

Postby BITalino » Sat Jul 15, 2017 2:22 am

Hi there,

From the errors you're reporting it seems like the application is being executed using Python 3.6, in which the syntax of the language was changed to introduce a few restrictions (e.g. the print and except statements require the arguments the be placed between brackets).

If you change print ... to print(...) and except ...: to except (...): it should solve those errors. If you use Python 2.7 it should run without any issues. Let us know in case you experience any additional problems.

Note that, as described in the documentation, on Mac OS the connection is made using the Virtual COM Port (VCP) and not the Bluetooth socket. This means that instead of the MAC address in the constructor you'll need to use the VCP pathname.

The VCP pathname should be something like /dev/tty.BITalino-XX-XX-DevB, where XX-XX are the last four heaxadecimal digits on the MAC address of your device. Note also that the device needs to be paired with the computer (PIN: 1234).

Upon pairing you'll see that the connection state is "Connected" and after a few minutes without the device being used it will change to "Not connected"... this is the expected behavior and you don't need to do anything.

Mac OS manages the connection state automatically, and whenever a connection to the device is attempted (e.g. from your Python code base), Mac OS will change the connection state to "Connected" again and the communication with the device should be successful.

Best regards,
The BITalino Team

Return to “Programming APIs”