2.- Final character of a message is NULL.
p110i_UNO_HM10_ble_enviar.aia (183.8 KB)
- We are going to send a message (abcdefghijk) and get the bytes obtained in Arduino UNO.
// 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 HM10(2, 3);
#define LED13 13
byte caracter = "";
// char caracter = "";
String mensaje = "";
void setup(){
Serial.begin(9600);
HM10.begin(9600);
pinMode(LED13, OUTPUT);
}
void loop(){
if(HM10.available()) {
caracter = HM10.read();
Serial.println(caracter);
mensaje = mensaje + caracter;
if(caracter == NULL ) {
Serial.println(mensaje);
if (mensaje.indexOf("on13")>= 0){digitalWrite(LED13, HIGH);}
if (mensaje.indexOf("off13")>= 0){digitalWrite(LED13, LOW);}
mensaje = "";
delay(100);
}
}
}
-
Look
byte caracter = "";
-
The extension sends the message and at the end the NULL character.
-
To obtain the characters we change these lines.
// byte caracter = "";
char caracter = "";
- BluetoothLE extension adds a NULL character by default
We can remove this feature using the block NullTerminateStrings = false