Basic Bluetooth Example with the MDBT42Q Module

Posted on
  • Hi everyone,

    I'm very new to the Espruino platform and I got myself the above mentioned module, beacuse I want to create a very basic Bluetooth application. The module shall be a peripheral exposing the battery service and one custom service which contains two characteristics.

    I tried to use

    NRF.setServices
    

    via the NRF object and then flashed it onto the module via Serial, but it looks like the moment the code is activated the module is restarting several times and then no change to the software is visible. I guess I made a simple mistake, but I couldn't find a good full example explaining the way Bluetooth works on this platform.

    Can anyone help me out on this? I'm running firmware versio 2v00.136 btw.

    Thanks for any help!

  • Please could you post the code that you used, and what was printed onto the screen when you uploaded it?

    NRF.setServices is definitely the right thing - what happens if you use one of the examples from http://www.espruino.com/Reference#l_NRF_­setServices as-is? Do you see the services?

    Is it possible that you're not powering the module correctly? Normally it uses so little power that it could actually run off the power that's on the serial wires - but when it's doing work it might fail to get enough power and would then restart.

  • It seems like your guess with the power was correct. I was powering it over the 3V line of my TTL converter, switching to 5V fixed the issue of rebooting.

    A question arises for me though now. Will the NRF switch back to low power mode or do I have to trigger this myself then?
    And how do I set the services changed flag so iOS is triggering a rescan of the characteristics and services instead of chaching them?

    Thanks already!

  • Will the NRF switch back to low power mode or do I have to trigger this myself then?

    Yes and no. It'll automatically power save, but if you started it with the TTL converter on the serial port then serial will stay initialised, and that takes some power (~1mA?). You can use Serial1.unsetup() to disable it, or once you have saved your code just booting without the converter attached will mean that serial isn't initialised.

    And how do I set the services changed flag so iOS is triggering a rescan of the characteristics and services instead of chaching them?

    I'm afraid you can't. As far as I've seen iOS just caches the services and there's not that much that can be done about it - you just need to reboot the phone, or use an Android phone which won't cache them.

  • Okay great info thanks!

    I'm afraid you can't. As far as I've seen iOS just caches the services and there's not that much that can be done about it - you just need to reboot the phone, or use an Android phone which won't cache them.

    The sig has a gatt value called "Services Chagned" if this is set to true, the iPhone will reinit the cache. You might want to consider this for the future, I know nordic provides this falg to be set. https://www.bluetooth.com/specifications­/gatt/viewer?attributeXmlFile=org.blueto­oth.characteristic.gatt.service_changed.­xml

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Basic Bluetooth Example with the MDBT42Q Module

Posted by Avatar for binux @binux

Actions