B4R Question How to scan and BLE devices currently In Range Using HM10 BLE

AndroidMadhu

Active Member
Licensed User
Hello,

I want to scan BLE beacons which is currently active and in range by using HM10 BLE [Working as Master].

But not sure as how to scan and get the BLE beacons ID


My Connection is as follows

NodeMCU D5 (RX) ---> HM10 --> TX
NodeMCU D6 (TX) ---> HM10 -->RX
NodeMCU 3.3V ---> HM10 -->VCC
NodeMCU GND ---> HM10 --> GND

Current Sketch:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    If wifi.Connect2("xxxxxx", "xxxxxxx") Then
        Log("Connected to network")
    Else
        Log("Failed to connect to network")
    End If
    timer1.Initialize("CheckConnStat",2000)
    timer1.Enabled=True
    'Initialize the Pins
    D5.Initialize(dpins.D5,D5.MODE_INPUT)  'This PIN is for RX
    D6.Initialize(dpins.D6, D6.MODE_OUTPUT)   ''This PIN is for TX
    astream.Initialize("D5.DigitalWrite","astream_NewData",Null)
End Sub

Private Sub CheckConnStat
    If wifi.IsConnected Then
        'Do Nothing
        Log("Already Connected")
    Else
        wifi.Connect2("xxxx", "xxxx")
    End If
End Sub

please suggest

Thanks
 

AndroidMadhu

Active Member
Licensed User
I ran the below sketch. But nothing showing at the Log...
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private timer1 As Timer
    Private astream As AsyncStreams
    Private myserial As SoftwareSerial
    Private dpins As D1Pins   'Maps the pins of WeMos boards.
    Private D5,D6 As Pin
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    If wifi.Connect2("xxxxxx", "xxxxxx") Then
        Log("Connected to network")
    Else
        Log("Failed to connect to network")
    End If
    timer1.Initialize("CheckConnStat",2000)
    timer1.Enabled=True
    'Initialize the Pins
    D5.Initialize(dpins.D5,D5.MODE_INPUT)  'This PIN is for RX
    D6.Initialize(dpins.D6, D6.MODE_OUTPUT)   ''This PIN is for TX
    'initialize software serial
    myserial.Initialize(115200,dpins.D5,dpins.D6)
    astream.Initialize(myserial.Stream,"astream_NewData",Null)
    'One time for testing
    astream.Write("AT".GetBytes)
    astream.Write(CRLF)
End Sub

Private Sub CheckConnStat
    If wifi.IsConnected Then
        'Do Nothing
        Log("Already Connected")
    Else
        wifi.Connect2("xxxx", "xxxx")
    End If
End Sub
Private Sub astream_NewData(Buffer() As Byte)
    Log("receive: ", Buffer)
End Sub
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Read the specs. There are three commands that you need to send.
I have read the specs. But I am lost what are the three commands I need to sent.
What I did as below :
1. send AT--> received OK --> As HM10 is not connected to remote device. --> Done manually
2. I set the Role [AT+ROLE1] and made HM10 master manually. --> Connected HM10 with TTL with my PC and done manually
3. Then I set AT+PWRM1 -> AUTO sleep mode when power is off --> Connected HM10 with TTL with my PC and done manually
4. AT+IMME1 --> Stops the Auto connect with slaves --> Connected HM10 with TTL with my PC and done manually

But when I am firing the AT command from code, there is nothing showing up at the below log...[Atleast the log will show OK]
B4X:
Private Sub astream_NewData(Buffer() As Byte)
    Log("receive: ", Buffer)
End Sub


Please advice where I done any wrong..

Thanks
 
Last edited:
Upvote 0

AndroidMadhu

Active Member
Licensed User
I have checked.....
Instead I will use the below

B4X:
astream.Write(Array As Byte(b))

Let me test the same and update
I believe I found the problem....
In HM10, do not send the command
B4X:
<AT>+carriage Return
. As this will give you error.
1664279720406.png


Now make the configuration as no Line Ending at Serial Monitor at Arduino..

1664279815838.png


But how to implement No line Ending at B4R? Could anyone please suggest

Thanks
 
Upvote 0
Top