Wifi credentialing over BLE with Ionic Capacitor Bluetooth LE pllug-in

karunt
Posts: 93
Joined: Sat Apr 03, 2021 7:58 am

Wifi credentialing over BLE with Ionic Capacitor Bluetooth LE pllug-in

Postby karunt » Sun Aug 15, 2021 5:56 am

Trying to send esp32 chip wifi credentials from android app (built with ionic). Using Ionic capacitor/bluetooth-le plug in to write to esp32, using the write function:

Code: Select all

await BleClient.write(device.deviceId, GATT Service ID, Characteristic ID, textToDataView('wifi_ssid,wifi_password'));
Code for BleClient.write:

Code: Select all

async write(deviceId: string, service: string, characteristic: string, value: DataView): Promise<void> {
    service = validateUUID(service);
    characteristic = validateUUID(characteristic);
    return this.queue(async () => {
      if (!value?.buffer) {
        throw new Error('Invalid data.');
      }
      let writeValue: DataView | string = value;
      if (Capacitor.getPlatform() !== 'web') {
        // on native we can only write strings
        writeValue = dataViewToHexString(value);
      }
      await BluetoothLe.write({
        deviceId,
        service,
        characteristic,
        value: writeValue,
      });
    });
  }
How can I pass wifi credentials as value argument to the write function so it's correctly received by ESP32? On the ESP32 side, I'm using the wifi_prov_mgr example code, which in turn uses google protocol buffer (I'm very new to protobuf and don't really understand how it works). ESP uses wifi_config.c (Espressif wifi_provisioning component). When I send wifi credentials from the app using BleClient.write, it shows up in wifi_config.c as inbuf with value "wifi_ssid,wifi_password:��Z�?�Z�?" and I get error from wifi_config.c: "Unable to unpack config data".

Here's the relevant code for wifi_config.c:

Code: Select all

esp_err_t wifi_prov_config_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, uint8_t **outbuf, ssize_t *outlen, void *priv_data)
{
    ESP_LOGI(TAG ,"Wifi config payload inbuf value: %s", inbuf);
    WiFiConfigPayload *req;
    WiFiConfigPayload resp;
    esp_err_t ret;
    req = wi_fi_config_payload__unpack(NULL, inlen, inbuf);
    if (!req) {
        ESP_LOGE(TAG, "Unable to unpack config data");
        return ESP_ERR_INVALID_ARG;
    }
I'm having a very hard time understanding how wi_fi_config_payload_unpack processes the inbuf argument. This is where the code gets into protobuf code generated by the proto files. The proto file for wifi config data looks like this:

Code: Select all

message CmdSetConfig {
    bytes ssid = 1;
    bytes passphrase = 2;
    bytes bssid = 3;
    int32 channel = 4;
}

message WiFiConfigPayload {
    WiFiConfigMsgType msg = 1;
    oneof payload {
        CmdGetStatus cmd_get_status = 10;
        RespGetStatus resp_get_status = 11;
        CmdSetConfig cmd_set_config = 12;
        RespSetConfig resp_set_config = 13;
        CmdApplyConfig cmd_apply_config = 14;
        RespApplyConfig resp_apply_config = 15;
    }
}
So my question is - how do I pass the wifi credentials in BleClient.write so it is correctly recognized by wifi_config.c on the ESP32 side?

I thought about using the Android app developed by Espressif to pass wifi credentials to the ESP32 chip, but then I don't know how to integrate native Android code with ionic code, since I need my app to do more than just credential the ESP32.

djoshi
Posts: 53
Joined: Wed Jan 12, 2022 9:59 pm

Re: Wifi credentialing over BLE with Ionic Capacitor Bluetooth LE pllug-in

Postby djoshi » Tue Nov 29, 2022 10:35 pm

Hi

I have you manged to get it working with Capacitor Bluetooth plugin?

karunt
Posts: 93
Joined: Sat Apr 03, 2021 7:58 am

Re: Wifi credentialing over BLE with Ionic Capacitor Bluetooth LE pllug-in

Postby karunt » Thu Dec 29, 2022 12:33 pm

Yes.

djoshi
Posts: 53
Joined: Wed Jan 12, 2022 9:59 pm

Re: Wifi credentialing over BLE with Ionic Capacitor Bluetooth LE pllug-in

Postby djoshi » Thu Dec 29, 2022 1:43 pm

Same here i am using Blufi example

mikado
Posts: 1
Joined: Fri Feb 03, 2023 1:01 pm

Re: Wifi credentialing over BLE with Ionic Capacitor Bluetooth LE pllug-in

Postby mikado » Fri Feb 03, 2023 1:04 pm

Hi,
I'm trying to provisioning using the Capacitor Bluetooth LE plug-in.
Can you share how you get it working please ?

Thanks

Who is online

Users browsing this forum: No registered users and 38 guests