Hi everyone!
This is my first post, I am trying to get some string values into Android app via BLE from an Arduino device(with an HM-10 module) . My problem is the string I received from Arduino will be split or merged together, while it need to be like a row of data with 11 numbers. I followed a topic from app inventor(Hm-10 sending string - Problems -) to try to solve this issue, but its not working.
Here is my Arduino code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include <SPI.h>
#include <SD.h>
RF24 radio(7, 8); //指定 Arduino Nano 腳位對應 nRF24L01 之 (CE, CSN)
const byte address[][6]={"1andy","2andy","3andy"}; //節點位址為 5 bytes + \0=6 bytes
float magval[3];
float gyrraw[3];
typedef struct
{
short gyrRawx;
short gyrRawy;
short gyrRawz;
long accRawx;
long accRawy;
long accRawz;
unsigned long runTime;
short magValuex;
short magValuey;
short magValuez;
}value;
value data;
String datos;
void setup() {
Serial.begin(115200);
radio.begin();
printf_begin();
radio.setPALevel(RF24_PA_LOW);
radio.setChannel(83);
radio.openReadingPipe(0, address[0]);
radio.openReadingPipe(1, address[1]);
radio.startListening();
radio.printDetails();
Serial.println("NRF24L01 receiver");
Serial.println("waiting...");
}
void loop()
{
uint8_t pipe_num;
if (radio.available(&pipe_num))
{
if(pipe_num==0||pipe_num==1)
{
radio.read(&data, sizeof(data));
if(data.gyrRawx!=0&&data.gyrRawy!=0&&data.gyrRawz!=0&&data.accRawx!=0&&data.accRawy!=0&&data.accRawz!=0&&data.runTime!=0)
{
datos = "B"+(String) data.gyrRawx + "," + (String) data.gyrRawy + "," + (String) data.gyrRawz+ "," + (String) data.accRawx+ "," + (String) data.accRawy+ "," + (String) data.accRawz+ "," + (String) data.magValuex+ "," + (String) data.magValuey+ "," + (String) data.magValuez+ "," + (String) data.runTime+ "," + (String) pipe_num;
Serial.print(datos.c_str());
}
}
else
{
radio.read(&data, sizeof(data));
}
}
}
And here is my code in MitApp
ble_HM10_version_3.aia (193.9 KB)
Please tell me how to solve this problem