sterretje:
Why not use pointers?
As far as I understand your code, store_buffer eventually contains the credentials in the format ssid=XYZ&pswd=ABC. So I would rename it to credential_buffer. Next use pointer to point to the credential values.
#define CREDENTIALSIZE 64
// buffer with credentials
char credential_buffer[CREDENTIALSIZE] = "ssid=XYZ&pswd=ABC";
// pointers to the actual credential values in the buffer
char *accSSID;
char *accPWD;
void setup()
{
Serial.begin(9600);
Serial.print("Received credentials: "); Serial.println(credential_buffer);
Serial.print("credential_buffer size: "); Serial.println(sizeof(credential_buffer));
Serial.print("credential size: "); Serial.println(strlen(credential_buffer));
// check if credentials contains 'ssid='
accSSID = strstr(credential_buffer, "ssid=");
if(accSSID == NULL)
{
// something wrong
Serial.println("'ssid=' not found");
// bail out
return;
}
// increment accSSID so it points to the data
accSSID += strlen("ssid=");
// check if credentials contains '&pswd='
accPWD = strstr(credential_buffer, "&pswd=");
if(accPWD == NULL)
{
// something wrong
Serial.println("'&pswd=' not found");
// bail out
return;
}
// accPWD points to '&'; replace by NUL character so SSID value is null terminated
*accPWD = '\0';
// accPWD points to '&'; increment so it points to the data
accPWD += strlen("&pswd=");
// display result
Serial.print("SSID: "); Serial.println(accSSID);
Serial.print("PWD: "); Serial.println(accPWD);
}
void loop()
{
}
Notes:
1)
the size of the credential_buffer is reduced to 64; adjust to your needs.
2)
the credential_buffer is 'corrupted'; if you print it after the processing, it will only print the part up to the SSID.
3)
The only real way to resize arrays is by dynamically allocating them (malloc, calloc, realloc, free). Stay away from it unless you absolutely know what you're doing.
Thanks! This really does help. However, how do I copy characters from the storebuffer to a new array? Would something like this work? Also how would I copy the PSWD characters to another buffer since there is now no termination character to compare to?
// accPWD points to '&'; replace by NUL character so SSID value is null terminated
*accPWD = '\0';
int i = 0;
while (*accSSID != '\0')
{
SSIDbuffer[i] = *accSSID; //declared another buffer to store the SSID data.
accSSID++;
i++;
}