Android Serial over BT?
  • 0
  • Hey,

    Just got my CBT and updated the firmware connected it to my phone and launched one of the many available Serial over BT apps and it wont connect. Any one had any luck with getting their phone to connect? If yes, what app did you use?

    Also, does the CBT need to be connected to the car before it will communicate via BT? I'm only connected to my laptop via USB.

    Cheers,
    TheBlackMini

  • 0
  • I think the Problem is that BT is not fully integrated at this time.

    Derek is working on it.

  • 0
  • Oh, that would explain that then.

  • 0
  • administrators

    BT works, but it cannot dump all the can packets from your car as it's too slow. The idea is the MCU processes the packets and uses BT to send sensor data or whatever to your phone. I'm implementing stuff in the firmware to filter packets on the MCU so you can get can over bt if you know what message id you want. But out of the box you can use BT to talk to the MCU and send commands with a generic BT LE app like Lightblue for iOS. I'm yet to find a good one for Android. The docs list some of the BT LE characteristics and what they do.

    On the USB Serial thing, I'm willing to bet whatever software you're using doesn't recognize the USB vid/pid. I had to wrestle with that in the mobile app to get it working. But USB serial to android does work.

    Still working on all this software so it will get easier soon, and still be open for people who wish to dive deeper.

  • 0
  • I have the same problem and this question wasn't answered. I'm modifying a Android BT serial app that I've used before to talk to the CBT. It won't connect. Does the bluegiga ble112 need to be flashed? is is it already flashed? what is the UUID of the radio?

  • 0
  • P.S. the baudrate of the BLE112 is up to 2Mps http://www.mouser.com/ds/2/52/Bluegiga_Technologies_BLE112_Datasheet-293747.pdf which is plenty. From the schematic I see you just went with the generic 16Mhz crystal instead of matching it to the serial output, this will cause a lot of corrupted data.

  • 0
  • The overall throughput of LE is at best 1MBps and probably less even if the UART baud rate can be higher.
    It cannot send all the bytes of a full CAN bus (even in Binary), but might be able to do something if there were compression (with loss in the first few packets to establish the dictionary). There are usually few CAN addresses, and often data doesn't change at all or only a few bits.

  • 0
  • administrators

    The BLE112 is flashed and ready to use. If you use a LE scan tool such as LightBlue it will find the CBT BLE112. Right now I'm processing the CAN packets on the MCU and sending the computed values to one of 8 'sensor' characteristics. Their is also a characteristic for reading and writing to the UART. You can find the specific UUIDs here:
    https://github.com/CANBus-Triple/CBT-BLE112-Firmware/blob/master/gatt.xml

  • 0
  • Derek can you please confirm that BT filtering is functional in 0.4.4. Using Light Blue I'm able to talk to the MCU UART port no problem.. I can send 01 01 and 01 10 01 to my heart's content and receive valid responses while subscribing.

    However, I can't get BT filtering to send anything over at all... I've got a simple register I monitor over USB that I filter with 03 01 01 28 but when I try 04 01 28 (or any number of other filters that are completely valid over USB) I do not get any data back.

    It's almost like BT filtering isn't implemented.

  • 0
  • I'm trying to implement bluetooth communication with CBT on Android, too.
    I'm developing an OBD diagnostic app with <a href="http://www.ionicframework.com/">Ionic framework</a> (borrowing the idea and structure from @Derek‌ offical app) and currently I'm able to connect to CBT, and successfully send / receive data with an Android smartphone. I can share the code if anyone is interested.
    I'm also able to activate DFU mode on BLE chip (writing to the specific characteristic).
    The app can send log commands and CAN packets but sometimes it gets corrupted data.

    One thing that seems strange to me, and could be the cause of corrupted data, is the timer event in BLE code, which is responsible to take data received on UART from MCU and send it over bluetooth (see <a href="https://github.com/CANBus-Triple/CBT-BLE112-Firmware/blob/master/script.bgs#L155">hardware_soft_timer event</a> in BLE firmware script).
    This timer is activated when a device is connected via bluetooth, on <a href="https://github.com/CANBus-Triple/CBT-BLE112-Firmware/blob/master/script.bgs#L207">line 207 of the bgscript</a>:

    <blockquote>call hardware_set_soft_timer((32768/1000) * conn_interval / 4, 2, 0)</blockquote>

    The first argument is the time interval (expressed in 1/32768 seconds) on which the timer event will be fired.
    Its value depends on <i>conn_interval</i> variable, which is set by the connected device. Android set this value to 7.5ms (see http://stackoverflow.com/questions/21398766/android-ble-connection-time-interval), so the resulting interval will be less than 2ms!
    So apparently the <i>hardware_soft_timer</i> event may be firing too fast.

    I will try to change its value, but until now I was not able to update firmware to BLE chip.

  • 0
  • I was finally able to flash BLE firmware, and discovered that <i>conn_interval</i> is 39ms on my Android Phone, so the problem is not in that parameter.

  • 0
  • I suggest a custom middleware implementation. I am having good results unleashing 0x03 0x01 0x01, suppressing Serial1 output in SerialCommand.h, and constructing custom results for just the data I want in my own middleware class.

  • 0
  • administrators

    Good stuff going on in this thread!

    Yeah connection interval should be around 40ms, it's controlled by the host OS.

  • 0
  • @Emanuele‌ - if you could share some code as to how you connected to the CBT over bluetooth that would be great.

    I am able to connect to the device and discover the services, both using debug tools and the iOS app I'm testing, but I just can't get any data from the CBT.

    I tried modifying the BLE112 firmware to add a serial RX characteristic but that didn't help.

    I need to be able to pass serial data between the CBT and the connected Bluetooth device using Serial1 on the CBT.

    Any help you can offer would be most appreciated!

  • 0
  • @Emanuele‌ - if you're still having trouble updating the BLE firmware, and you're trying to follow the steps on Derek's page to update over USB, I found the way to get it working was to send the 0802 command to the CBT over USB serial BEFORE sending the '1' to the DFU characteristic over Bluetooth. That's contrary to the order on Derek's instruction page, but swapping that order worked for me.

  • 0
  • I haven't had to touch the embedded BT firmware.

    Grab Derek's latest commit from master. He's improved BT throttling considerably over the past week.

    Use x03 x01 for filtering. The x04 stuff is abandoned.

  • 0
  • Thanks @ShellDude‌ - are you using your own (developed) app/code to connect to the CBT over bluetooth, or Derek's standard app?

  • 0
  • I'm using his app on OSX for sniffing over USB and my own Android app for final implementation using BTLE.

    I'll be publishing full source, including my custom CBT middleware shortly.

  • 0
  • My app is working quite well now. I am implementing some OBD II communication through CAN messages, following Wikipedia Article on OBD II (https://en.wikipedia.org/wiki/OBD-II_PIDs).
    If I've time I will publish the code during this weekend.
    I used this library (Cordova plugin) for BLE: https://github.com/randdusing/BluetoothLE

  • 0
  • I have to say the same ... CBT is the car hacking tool of 21st century!

    I say this only having hacked into a single bus. Just wait till I'm opening windows and doors from my watch!

  • 0
  • One additional note.. I'm not using cross platform stuff.

    All my work ioutside of ardruino is pure Android because I loathe iOS.

    Ironically I absolutely love OSX.

  • 27
    Posts
  • 10285
    Views
  • Log in to reply