[Solved] Program execution hangs while copying char array

Hello,
I'm building this sketch to control a DSRL camera using a microcontroller through normal/bluetooth serial. It uses CmdMessenger to communicate with the controller.
The plain serial version already works, however, as I received my new bluetooth serial module, I wanted to add a few methods to change the bluetooth settings remotely.

It works this way: the computer sends any of the chname, chpin, chbaud commands with the new value, which is stored in SRAM, and then sends the commit command, which puts the bt module in AT mode, stores the information and resets the MCU (watchdog reset).

The chpin and chbaud functions work, however when chname is called, the microcontroller prints "BAU" on serial and simply hangs (sending "cuccia" didn't work :smiley: :stuck_out_tongue: ).

This is the function: https://gist.github.com/Davideddu/2728fbb6cfcfd7f3d533#file-blueos-ino-L368

I believe this is caused by CmdMessenger.copyStringArg. The method accepts a pointer to a char array and an integer (len). It reads a string argument from serial then runs strlcpy on it to copy len bytes into my char array.

I tried checking the program over and over to reduce the SRAM usage, and I actually did reduce it, but the program still crashes at that point.

Thank you in advance for your help, I hope you have a nice day.

Post your code.
This is the Programming section, not the vague hand-waving section.

AWOL: Read better. https://gist.github.com/Davideddu/2728fbb6cfcfd7f3d533#file-blueos-ino-L368

I'm sorry, that should have read "post your code"

Hello,

Try change

char* bt_newname;

to

char bt_newname[16]; // change 16 to your desired max name length

guix:
Hello,

Try change

char* bt_newname;

to

char bt_newname[16]; // change 16 to your desired max name length

I tried setting the length that way (I set it to 30 as that's the maximum the BT modules is supposed to accept), but maybe it's too long. I'll try with 16 and see what happens.

I was probably doing something wrong, it seems to work now.
I made it

char bt_newname[30];

and used strlcpy in btReset to copy the default name to the buffer (it would complain as the sizes of the two arrays were different).

Thank you very much, have a nice day.

No problem

uint8_t len = cmdMessenger.readInt16Arg();
cmdMessenger.copyStringArg(bt_newname, len);

Maybe you should make sure that "len" is never greater than the size of "bt_newname" :wink:

guix:
No problem

uint8_t len = cmdMessenger.readInt16Arg();

cmdMessenger.copyStringArg(bt_newname, len);



Maybe you should make sure that "len" is never greater than the size of "bt_newname" ;)

Yes, thank you! I'm constraining it to 0, 30 :wink: