Re-provisioning ESP32 chip using wifi provisioning example
Posted: Fri Mar 25, 2022 4:01 am
Using the example for wifi-provisioning to re-provision chip by implementing the following logic in custom_prov_data_handler:
The problem I encounter with this logic is that the response to my BLE.write command always returns in an error because before the chip is able to write a response back to the GATT characteristic, it gets instructions to stop provisioning, restore and restart provisioning. My question is - what function can I invoke before stopping/restarting provisioning that will allow the code to write a response to the GATT characteristic so my BLE.write command gets a response indicating that the peripheral device successfully wrote to the chip's GATT characteristic? While I can assume that an error response to BLE.write means that the chip is rebooting itself, it's a poor assumption to make because I can't tell for sure if the write error is a result of the reboot process or that something else went wrong with BLE.write that prevented the reboot instructions from being written to the ESP32 chip to begin with.
Code: Select all
esp_err_t custom_prov_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen,
uint8_t **outbuf, ssize_t *outlen, void *priv_data)
{ if (strncmp((char *)inbuf, "reboot", inlen) == 0) {
wifi_prov_mgr_stop_provisioning();
ESP_ERROR_CHECK(esp_wifi_restore());
char service_name[12];
get_device_service_name(service_name, sizeof(service_name));
wifi_prov_security_t security = WIFI_PROV_SECURITY_0;
const char *pop = "abcd1234";
const char *service_key = NULL;
ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key));
}
char response[] = "SUCCESS";
*outbuf = (uint8_t *)strdup(response);
if (*outbuf == NULL) {
ESP_LOGE(TAG, "System out of memory");
return ESP_ERR_NO_MEM;
}
*outlen = strlen(response) + 1; // +1 for NULL terminating byte
return ESP_OK;
}