13.- HM-10 sends a long text to app.
p110_UNO_HM10_TextoLargo.aia (185.3 KB)
- HM-10 sends five random numbers with decimals, each random delay (500 - 1000 ms)
- It sends the data separated by commas and ends the message with the '#' character.
// Juan A. Villalpando
// http://kio4.com/arduino/161_HM10_BLE.htm
#include <SoftwareSerial.h>
// El TXD del módulo al pin 2 (RX) del Arduino.
// El RXD del módulo al pin 3 (TX) del Arduino.
SoftwareSerial BLE1(2, 3);
long previousMillis_BLE1 = 0;
int interval_BLE1 = 1000;
void setup(){
Serial.begin(9600);
BLE1.begin(9600);
}
void loop(){
unsigned long currentMillis = millis();
if(currentMillis - previousMillis_BLE1 > interval_BLE1) {
previousMillis_BLE1 = currentMillis;
SendTo_BLE1();
interval_BLE1 = random(500,1000);
}
}
void SendTo_BLE1(){
float x1 = random(10,60000)/1000.0; // 3 decimals
float x2 = random(5,99000)/100.0; // 2 decimals
float x3 = random(5,99000)/10.0; // 1 decimal
float x4 = random(50,990000)/1000.0; // 3 decimals
float x5 = random(500,990000)/1000.0; // 3 decimals
BLE1.print(x1,3);
BLE1.print(",");
BLE1.print(x2,2);
BLE1.print(",");
BLE1.print(x3,1);
BLE1.print(",");
BLE1.print(x4,3);
BLE1.print(",");
BLE1.print(x5,3);
BLE1.print(",");
BLE1.print("#"); // End Of Message.
}
- App receives this information in packets of 20 characters in stringValues, for example:
(19.650,729.62,4154.3)(,584.019,279.315,#)
19.650,729.62,4154.3,584.019,279.315, #
(19.650 729.62 4154.3 584.019 279.315 #)
(*)
Another way, send the last number using println()
BLE1.println(x5,3);
// BLE1.print(",");
// BLE1.print("#"); // End Of Message.
and modify the block piece: \n