Can someone please help me, please. here is my code. I just want to see the valeus of Q and Calc on the LightBlue App, not the serial monitor. Please Please help me.
#include <ArduinoBLE.h>
int NbTopsFan; // Nombre de tours d'hélices
float Calc; // Calculer du volume
float Q; // Calculer du débit
int hallsensor = 2; // PIN DIGITALE 2
BLEService dataService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Random 128-bit UUID for the service
BLEFloatCharacteristic dataCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // Random 128-bit UUID for the characteristic
void rpm() {
NbTopsFan++;
}
void blePeripheralConnectHandler(BLEDevice central) {
Serial.print("Connecté à l'appareil central : ");
Serial.println(central.address());
}
void setup() {
Serial.begin(9600);
while (!Serial); // on attend que le port série soit ouvert
pinMode(hallsensor, INPUT);
attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);
if (!BLE.begin()) {
Serial.println("Erreur BLE");
while (1);
}
BLE.setDeviceName("Arduino Nano BLE");
BLE.setLocalName("NanoBLE");
BLE.setAdvertisedService(dataService); // Annoncez le service personnalisé
dataService.addCharacteristic(dataCharacteristic); // Ajouter la caractéristique personnalisée au service
BLE.addService(dataService); // Ajouter le service personnalisé
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
// Add the BLE connection event handler here
BLE.advertise(); // Démarrez la publicité BLE
Serial.println("En attente de connexion BLE...");
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connecté à ");
Serial.println(central.address());
while (central.connected()) {
NbTopsFan = 0;
//sei();
//delay (1000);
//cli();
Q = (NbTopsFan / 9.5);
Calc = (Q / 60) + Calc;
dataCharacteristic.writeValue(Calc); // Write the value to the characteristic
Serial.println(Calc);
}
Serial.print("Déconnecté de ");
Serial.println(central.address());
}
}
I've had some experience sending data over BLE, and I can tell you right now, you are starting with a FLOAT, and you are trying to cast it as a STRING. I have not found a way to send float over serial communication.
You may try truncating the data so that the decimal is not included, then cast as an INT or cast directly to CHAR or STRING. If you require 1 or more decimal place for Calc and Q, try multiplying the float by 10 or 100, then truncate, then cast to CHAR, then manually insert a decimal point, then send the data.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
The LightBlueApp does not support reading the four byte binary data format(IEEE754) and displaying it as a decimal number. You can send the floating point value as text.
#include <ArduinoBLE.h>
int NbTopsFan; // Nombre de tours d'hélices
float Calc; // Calculer du volume
float Q; // Calculer du débit
int hallsensor = 2; // PIN DIGITALE 2
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;
BLEService dataService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Random 128-bit UUID for the service
BLECharacteristic dataCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead, 20); // Random 128-bit UUID for the characteristic
void rpm() { NbTopsFan++;}
void setup() {
Serial.begin(9600);
pinMode(hallsensor, INPUT);
attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);
pinMode(ledPin1, OUTPUT); // Première Led
pinMode(ledPin2, OUTPUT); // Deuxième Led
pinMode(ledPin3, OUTPUT); // Troisième led
pinMode(ledPin4, OUTPUT); // Quatrième led
pinMode(ledPin5, OUTPUT); // Cinquième led
if (!BLE.begin()) {
Serial.println("Erreur BLE");
while (1);}
BLE.setLocalName("NanoBLE");
BLE.setAdvertisedService(dataService); // Annoncez le service personnalisé
dataService.addCharacteristic(dataCharacteristic); // Ajouter la caractéristique personnalisée au service
BLE.addService(dataService); // Ajouter le service personnalisé
// Add the BLE connection event handler here
BLE.advertise(); // Démarrez la publicité BLE
Serial.println("En attente de connexion BLE...");}
void loop() {
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connecté à : ");
Serial.println(central.address());
while (central.connected()) {
NbTopsFan = 0;
delay(1000);
Q = (NbTopsFan / 9.5);
Calc = (Q / 60) + Calc;
String To_App = String(Calc, 3) + "," + String(Q, 3);
Serial.println(To_App);
dataCharacteristic.writeValue(To_App.c_str(), To_App.length());
delay(200);
if(Calc>=1){
digitalWrite(ledPin1,LOW);
}
else{
digitalWrite(ledPin1,HIGH);
}
if(Calc>5){
digitalWrite(ledPin2,LOW);
}
else{
digitalWrite(ledPin2,HIGH);
}
if(Calc>7){
digitalWrite(ledPin3,LOW);
}
else{
digitalWrite(ledPin3,HIGH);
}
if(Calc>8){
digitalWrite(ledPin4,LOW);
}
else{
digitalWrite(ledPin4,HIGH);
}
if(Calc>9){
digitalWrite(ledPin5,LOW);
}
else{
digitalWrite(ledPin5,HIGH);
}
}
Serial.print("Déconnecté de : ");
Serial.println(central.address());}
}
Here is my current code and here is what I can see on my bluelight App. But I wan to see :
Volume (L): "Calc Value''
Flowrate (L/min) : " Q value".
Can you please help me i have tried and I didn't succeed.
You are going to run into packet size issues if you try to send more than 20 characters.
I think that the BLE library will send multiple packets, but I don't know about getting Light Blue and Android to deal with them. Data Length Extension is a complicated issue. BLE is really designed for short bursts of data.
In your specific case, you may want to think about using two characteristics, one for Flow Rate, and one for Volume so the message length for each can be kept at 20 characters. You will have to switch between the characteristics in Light Blue.
EDIT: This will work as one chunk depending on the length of your data