B4R Tutorial BLE (HM-10 module) - Broadcasting a single byte

Discussion in 'B4R Tutorials' started by Erel, Apr 13, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User


    In this example I'm using a BLE shield to broadcast the state of a connected button.

    The byte is sent as part of the advertising data so there is no need for a connection. Any device that scans for BLE peripherals will be able to detect it.

    The HM 10 module is connected as a serial device to pins 2 and 3. I'm using the new rSoftwareSerial library.

    The HM 10 module allows us to set the value of a single byte that will be sent as part of the advertising data. This is done with the AT+FLAG command.

    The B4R code is very simple:
    Sub Process_Globals
    Public Serial1 As Serial
    Private astream As AsyncStreams
    Private softserial As SoftwareSerial
    Private btn As Pin
    End Sub

    Private Sub AppStart
       btn.Initialize(btn.A0, btn.MODE_INPUT_PULLUP)
    End Sub

    Sub Btn_StateChanged (State As Boolean)
    Dim b As Byte
    If State Then b = 0 Else b = 1
    Array As Byte(b))
    End Sub

    Sub astream_NewData (Buffer() As Byte)
    Log("recieve: ", Buffer)
    End Sub
    The B4A and B4i projects are attached. There are some differences between the ways that the advertising data is parsed between Android and iOS. You can see it in the projects.
    The relevant advertising record starts with B000 and its type is 22 (this is the service data type).

    Attached Files:

  2. tufanv

    tufanv Expert Licensed User

    I could not find a shield in a store but there is a hm10 : See : http://urun.gittigidiyor.com/ev-ele...ble-hm-10-kablosuz-iletisim-arduino-211512177

    Is it ok for this example ? or do i need to have the same shield to make this work ?
  3. Erel

    Erel Administrator Staff Member Licensed User

    The link doesn't seem to work.

    It will work with any HM 10 module. Make sure that the module supports 5V.
  4. tufanv

    tufanv Expert Licensed User

    it says working voltage (dc) 3.3 - 6.0 V
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice