B4R Question Send AT command to AT-09 BLE module ?

Cain Soft

Member
Licensed User
Hi All,
How can I send AT command to AT-09 (HM-10 clone) BLE module ?
The Arduino code is :
B4X:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);
  delay(200);
  mySerial.println("AT+NAMEdemoBleX");
  while (mySerial.available())
  {
    Serial.write(mySerial.read());
  }
  delay(200);
}
void loop()
{
}
Bluetooth device name is changed successfully
On B4R I tried these:
B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("appstart")
    softserial.Initialize(9600, 2, 3)
    astream.Initialize(softserial.Stream, "astream_newdata", Null)
'test 1  
    'astream.Write("AT+NAMEbleDemoBR".GetBytes) '-> receive ERR
    'astream.Write("AT+NAMEbleDemoBR") '-> receive ERR
    'astream.Write("AT+NAMEbleDemoBR\r\n".GetBytes) '-> receive ERR
'test 2  
    'Dim message As String
    'message = "AT+NAMEbleDemoBR" + CRLF
    'astream.Write(message.GetBytes) '-> no answer, no change BLE name
'test3  
    'astream.Write("AT+NAMEbleDemoBR".GetBytes)
    'astream.Write(Array As Byte(10))
    'astream.Write(Array As Byte(13)) '-> receive ERR
'test4
    Dim buffer() As Byte
    Dim message As String
    message = "AT+NAMEbleDemoBR"
    buffer = message.GetBytes
    astream.Write(buffer) '-> receive ERR
  
    Log("AppStart End")
  
End Sub
Sub astream_NewData (Buffer() As Byte)
    Log("recieve: ", Buffer)
End Sub
An error message arrives "ERR" or nothing happens
Thanks.
 
Last edited:

Cain Soft

Member
Licensed User
Thanks Erel!
It's working now (+ delay).
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private astream As AsyncStreams
    Private softserial As SoftwareSerial
    Private Timer1 As Timer
End Sub
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("appstart")
    softserial.Initialize(9600, 2, 3)
    astream.Initialize(softserial.Stream, "astream_newdata", Null)
    Timer1.Initialize("Change_BLEname", 200)
    Timer1.Enabled = True
End Sub
Sub Change_BLEname
    astream.Write("AT+NAMEbleDemoBRnewXX".GetBytes)
    astream.Write(CRLF)
    Timer1.Enabled = False
End Sub
Sub astream_NewData (Buffer() As Byte)
    Log("recieve: ", Buffer)
End Sub
 
Upvote 0

Cain Soft

Member
Licensed User
This is even better, thank you!
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private astream As AsyncStreams
    Private softserial As SoftwareSerial
End Sub
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("appstart")
    softserial.Initialize(9600, 2, 3)
    astream.Initialize(softserial.Stream, "astream_newdata", Null)
    CallSubPlus("Change_BLEname", 200, 0)
End Sub
Sub Change_BLEname(input As Byte)
    astream.Write("AT+NAMEbleDemoBR_V2".GetBytes)
    astream.Write(CRLF)
End Sub
Sub astream_NewData (Buffer() As Byte)
    Log("recieve: ", Buffer)
End Sub
 
Upvote 0
Top