Hello
I try to connect an Adafruit M0 Ble to Android thru BLE
The Adafruit use a NORDIC RF51 for BLE.
My Arduino sketch use the Nordic UART service (UUID=6e400001-b5a3-f393-e0a9-e50e24dcca9e) and send evry second a value ("test")
With the Adafuit Android App, I receive the value "test" evry seconde. OK.
With B4A:
Scanning and Connection are OK.
I can retreive all BLE services (Access,Attribute,DFU,Info and UART)
I can read characteristics for Info and i receive the uuids and values.
For uart I receive the uuids but values are empty and the event DataAvailable is called only once.
Arduino sketch
B4A Sarter service for manager_Connected and manager_DataAvailable
Debug output for service info
and for UART service
There is surely something I do not understand
Do you have a solution ?
Thank you
I try to connect an Adafruit M0 Ble to Android thru BLE
The Adafruit use a NORDIC RF51 for BLE.
My Arduino sketch use the Nordic UART service (UUID=6e400001-b5a3-f393-e0a9-e50e24dcca9e) and send evry second a value ("test")
With the Adafuit Android App, I receive the value "test" evry seconde. OK.
With B4A:
Scanning and Connection are OK.
I can retreive all BLE services (Access,Attribute,DFU,Info and UART)
I can read characteristics for Info and i receive the uuids and values.
For uart I receive the uuids but values are empty and the event DataAvailable is called only once.
Arduino sketch
B4X:
#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_BLE.h>
#include <Adafruit_BluefruitLE_SPI.h>
#include <Adafruit_BluefruitLE_UART.h>
#define BLE_FACTORYRESET 1
#define BLE_BUFSIZE 128
#define BLE_VERBOSE true
#define BLUEFRUIT_SPI_CS 8
#define BLUEFRUIT_SPI_IRQ 7
#define BLUEFRUIT_SPI_RST 4
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
void setup(void)
{
while (!Serial);
delay(500);
Serial.begin(115200);
Serial.println("Initialising the Bluefruit LE module: ");
if ( !ble.begin(BLE_VERBOSE) )
{
Serial.println("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?");
}
Serial.println("OK!");
Serial.println("Performing a factory reset: ");
if (! ble.factoryReset() ){
Serial.println("Couldn't factory reset");
}
ble.echo(false);
Serial.println("Requesting Bluefruit info:");
ble.info();
ble.verbose(false);
Serial.println("Waiting for a BLE connection to continue ...");
while (! ble.isConnected()) {
delay(5000);
}
Serial.println("CONNECTED!");
Serial.println("**********");
}
void loop(void)
{
if (ble.isConnected())
{
ble.println("AT+BLEUARTTX=test");
if (! ble.waitForOK() ){
Serial.println("Failed to send value");
}else{
Serial.println("Sending value ok");
}
ble.println("AT+BLEUARTTX=\\r\\n");
if (! ble.waitForOK() )
{
Serial.println("Failed to send crlf");
}
delay(1000);
}
}
B4A Sarter service for manager_Connected and manager_DataAvailable
B4X:
Sub manager_Connected (Services As List)
Log("connected")
Dim i As Int
For i=0 To Services.Size-1
Log("service "&i&"="&Services.Get(i))
Next
'0000180a-0000-1000-8000-00805f9b34fb info service
'manager.ReadData(infoService)
'6e400001-b5a3-f393-e0a9-e50e24dcca9e nordic uart service
'TX characteristic = 6e400003-b5a3-f393-e0a9-e50e24dcca9e
'RX characteristic = 6e400002-b5a3-f393-e0a9-e50e24dcca9e
manager.ReadData(uartService)
End Sub
Sub Manager_DataAvailable (sid As String, Characteristics As Map)
Log("///////////////////////////////////////")
Log("sid="&sid)
Log("characteristics size="&Characteristics.Size)
Dim i As Int
For i=0 To Characteristics.Size-1
Log(Characteristics.GetKeyAt(i))
If Characteristics.Getvalueat(i)<>Null Then
Dim b() As Byte = Characteristics.Getvalueat(i)
Dim msg As String = BytesToString(b, 0, b.Length, "utf8")
Log("msg="&msg)
End If
Next
Log("//////////////////////////////////////////")
End Sub
Debug output for service info
B4X:
** Service (starter) Create **
** Service (starter) Start **
statechanged
scan
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
POWERED ON
Device found
Name=Adafruit Bluefruit LE
id=C4:84:96:26:0C:57
RSSI=-65
Discovering services.
connected
service 0=00001800-0000-1000-8000-00805f9b34fb
service 1=00001801-0000-1000-8000-00805f9b34fb
service 2=00001530-1212-efde-1523-785feabcd123
service 3=0000180a-0000-1000-8000-00805f9b34fb
service 4=6e400001-b5a3-f393-e0a9-e50e24dcca9e
///////////////////////////////////////
sid=0000180a-0000-1000-8000-00805f9b34fb
characteristics size=5
00002a29-0000-1000-8000-00805f9b34fb
msg=Adafruit Industries
00002a24-0000-1000-8000-00805f9b34fb
msg=BLESPIFRIEND
00002a28-0000-1000-8000-00805f9b34fb
msg=0.7.7 - Dec 13 2016
00002a26-0000-1000-8000-00805f9b34fb
msg=S110 8.0.0, 0.2
00002a27-0000-1000-8000-00805f9b34fb
msg=QFACA10
//////////////////////////////////////////
and for UART service
B4X:
** Service (starter) Create **
** Service (starter) Start **
statechanged
scan
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
POWERED ON
Device found
Name=Adafruit Bluefruit LE
id=C4:84:96:26:0C:57
RSSI=-62
Discovering services.
connected
service 0=00001800-0000-1000-8000-00805f9b34fb
service 1=00001801-0000-1000-8000-00805f9b34fb
service 2=00001530-1212-efde-1523-785feabcd123
service 3=0000180a-0000-1000-8000-00805f9b34fb
service 4=6e400001-b5a3-f393-e0a9-e50e24dcca9e
///////////////////////////////////////
sid=6e400001-b5a3-f393-e0a9-e50e24dcca9e
characteristics size=2
6e400003-b5a3-f393-e0a9-e50e24dcca9e
msg=
6e400002-b5a3-f393-e0a9-e50e24dcca9e
msg=
//////////////////////////////////////////
There is surely something I do not understand
Do you have a solution ?
Thank you