'Convert String to uint8_t for Arduino C++

I'm trying to send a user input String type over Bluetooth with function

BluetoothSerial SerialBT;
SerialBT.write()

But the function won't accept String, but instead it accepts uint8_t. I tried some conversions like

char buf[packet.length()];
memcpy(buf, packet.c_str(), packet.length());
SerialBT.write(buf, packet.length());

But it shows an error

invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

Could please someone show me how to convert it right? Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source