simonedegiacomi/EV3-API

Bluetooth support

simonedegiacomi opened this issue · 2 comments

According to the ev3 firmware development kit from lego, the bluetooth is implemented using Bluez.
Moreover, in the same document, it is said that the ev3 firmware has some shared libraries that implement all the robot functionalities. In particular, libc_com is responsible for the bluetooth.
The shared libraries are used by the lms2012 process, which is the program that displays the ev3 interface and implements the virtual machine capable of interpreting the byte code documented in the document.

Given the statements above, I see the following possibilities to add the bluetooth functionalities to this library:

  • talk to Bluez using the C API
  • talk to Bluez using the dbus API (or using the gdbus wrapper)
  • use the libc_com library
  • write a program in lms (ev3 vm byte code) and use the documented API

After some experiments I arrived at the following conclusions:

Using the C API
Using this code examples I was able to connect the EV3 to another device (I tried with an HC-06) and it worked as long as the EV3 was not connected to it before starting the program.
I was also able to connect to the ev3 from my laptop, but I had to take care of the problem that the robot is already listening for incoming connections, even when my program is not running.
This can easily be seen, since who is listening (lms or d_bt??) has also registered the service to the sdp server of the robot.

image

So I started a server listening to channel 2 and wrote a program for my laptop to connect to that channel and it worked.

libc_com
It is not possible to use the libc_com library, at least while lms2012 is running. Many of the functions will print to stdout "Agent is already running".
If I understood it correctly, the libc_com library is not intended to be used from any other program except for lms2012. This would explain why there isn't a documentation about it and why it given errors when trying to use it.

lms language
Writing a program in lms that uses the bluetooth seems to work without any trouble; a solution could be to create a lms program that talks to the library (and connect the two programs).

Bluetooth implemented using the c API