I am working on a project to transmit data over ble as a beacon. The data is supposed to be in the major and minor fields. Right now I am having trouble with getting the arduino to run without the mBed OS crashing. The below code is one that I am running just to troubleshoot and see where I could get to but it runs a few cycles and the L led goes into the 4 fast 4 slow error mode for the mBed OS crash. From what I was reading this is typically caused by writing to too many pins at once but I am not sure how I would be doing that here. The other odd thing is if I change the UUID to something stupid like "test" it will run fine.
#include <ArduinoBLE.h>
#include <BeaconNano.h>
BeaconNano Beacon;
int count = 0;
void setup() {
Beacon.setUuid("A495BB20C5B14B44B5121370F02D74DE");
}
void loop() {
unsigned int major = count;
unsigned int minor = count;
Beacon.setMajor(major);
Beacon.setMinor(minor);
Beacon.startBeacon();
delay(5000);
Beacon.stopBeacon();
count = count + 1;
delay(5000);
}
The other thing that I changed in the BeaconNano library is the way that data is broken up. Since it was only supporting a single byte for major and minor (I need two bytes for at least the minor field) I had to edit the BeaconNano.cpp file as follows. I am looking for guidance on how I am causing the device to crash or if its a possible hardware issue.
Original:
void BeaconNano::startBeacon(){
if (!BLE.begin()) {
while (1);
}
byte uuidByte[16],majByte[2],minByte[2];
convertStringToByte(_uuid,uuidByte);
byte data[25]={
0X4C,0x00, //setting for iBeacons
0x02,0x15,
uuidByte[0],
uuidByte[1],
uuidByte[2],
uuidByte[3],
uuidByte[4],
uuidByte[5],
uuidByte[6],
uuidByte[7],
uuidByte[8],
uuidByte[9],
uuidByte[10],
uuidByte[11],
uuidByte[12],
uuidByte[13],
uuidByte[14],
uuidByte[15],
0,
_major,
0,
_minor,
_tx
};
BLE.setManufacturerData(data, 25);// AGGIUNGE IL MANUFACT
BLE.advertise();
My Edits:
byte uuidByte[16],majByte[2],minByte[2];
majByte[0] = (_major >>8) ,majByte[1] =_major, minByte[0] =(_minor >>8), minByte[1] = _minor;
convertStringToByte(_uuid,uuidByte);
byte data[25]={
0x4C,0x00,0x02,0x15,
uuidByte[0],
uuidByte[1],
uuidByte[2],
uuidByte[3],
uuidByte[4],
uuidByte[5],
uuidByte[6],
uuidByte[7],
uuidByte[8],
uuidByte[9],
uuidByte[10],
uuidByte[11],
uuidByte[12],
uuidByte[13],
uuidByte[14],
uuidByte[15],
majByte[0],
majByte[1],
minByte[0],
minByte[1],
_tx
};
BLE.setManufacturerData(data, 25);// AGGIUNGE IL MANUFACT
BLE.advertise();
}