Dear experts
I am still a beginner and I have created an (MIT) Android App where I select/configure the ESP32 MAC addresses for my ESP NOW (one to many) broadcast network. The App is connected using Bluetooth Classic to one ESP Now Sender Module.
The App sends a string (in variable lengths) with multiple MAC addresses (from none to a total of twelve MAC addresses).
Example of a transmitted string with three MAC addresses: <3F4C5D026611, 3F4C5D026622, 3F4C5D026633>
With this code I am receiving the string:
void recPeerList() // Reveive MAC Address from APP
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial_BT.available() > 0 && newData_Peer == false)
{
rc = Serial_BT.read();
if (recvInProgress == true)
{
if (rc != endMarker)
{
receivedChars_Peer[ndx] = rc;
ndx++;
if (ndx >= numChars_Peer)
{
ndx = numChars_Peer - 1;
}
}
else
{
receivedChars_Peer[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData_Peer = true;
}
}
else if (rc == startMarker)
{
recvInProgress = true;
}
}
}
According to the Serial Monitor the sting is received correctly in receivedChars_Peer. I am trying now to convert and assign the received string to variables respectively arrays.
Examples for desired format required for ESP Now transmission:
broadcastAddress1 = {0x3F, 0x4C, 0x5D, 0x02, 0x66, 0x11}
broadcastAddress2 = {0x3F, 0x4C, 0x5D, 0x02, 0x66, 0x22}
etc.
Now I am trying to change the format and assign each MAC address to a variable/array as described above but how I don’t know how to achieve this?
if (new_Peer_List_rcvd == (true))
{
Serial.println(receivedChars_Peer);
uint8_t bytes[6];
int values[6];
int i;
if (6 == sscanf(receivedChars_Peer, "%x:%x:%x:%x:%x:%x%*c",
&values[0], &values[1], &values[2],
&values[3], &values[4], &values[5]))
{
/* convert to uint8_t */
for (i = 0; i < 6; ++i)
bytes[i] = (uint8_t)values[i];
}
else
{
/* invalid mac */
}
Thank you very much for your help, hints and tips.
Victor