Good evening,
I am used to using String in other languages, so I started using it in my Arduino project, but I just read a few topics explaining that it's bad practice in Arduino, so I'm moving away from it.
I've read :
http://forum.arduino.cc/index.php?topic=396099.msg2726746#msg2726746
http://forum.arduino.cc/index.php?topic=382944.msg2640860#msg2640860
I'm trying to advertise a Bluetooth Service on the Adafruit Feather 32u4 board, and I was running this code which worked perfectly fine, but used Strings :
String advertisingInstruction = "AT+GAPSETADVDATA=";
String advertisingCustomServiceFlags = "02-01-06";
String advertisingCustomServiceUUIDS = "-11-06-B8-C7-D7-BA-B6-AE-B1-A9-CD-40-BF-41-0E-D0-3D-06";
String advertisingCustomService = advertisingCustomServiceFlags + advertisingCustomServiceUUIDS;
String advertising = advertisingInstruction + advertisingCustomService;
ble.sendCommandCheckOK(advertising.c_str());
From the last link I read, I tried to convert it to this :
char advertisingInstruction[] = "AT+GAPSETADVDATA=";
char advertisingCustomServiceFlags[] = "02-01-06";
char advertisingCustomServiceUUIDS[] = "-11-06-B8-C7-D7-BA-B6-AE-B1-A9-CD-40-BF-41-0E-D0-3D-06";
char advertisingCustomService[] = "";
strcat(advertisingCustomService, advertisingCustomServiceFlags);
strcat(advertisingCustomService, advertisingCustomServiceUUIDS);
char advertising[] = "";
strcat(advertising, advertisingInstruction);
strcat(advertising, advertisingCustomService);
ble.sendCommandCheckOK(advertising);
The code compiled without any error showing up, but the Serial would not output anything, and then I could not upload any Sketch to the board without resetting it manually. After reverting the code to use String again, and after resetting the board, the Serial does print my Services and Characteristics.
According to this Adafruit's page, those symptoms mean that the board is in a crashed state :
My guess is that I'm not using c_string properly, but as I'm doing what the previous article recommends (or so I think), I'd appreciate if somebody could explain what I'm doing wrong here.
My full project (which is just a communication test between an iOS app and this board, so it's rather small) is attached to this post in case more context is needed.
heartratemonitor.zip (5.96 KB)