Provisioning fixes for: 1.Space 2.Provisioned (#4291)

This commit is contained in:
Sweety 2020-08-25 13:33:06 +05:30 committed by GitHub
parent 1fd5cd79c5
commit 9d547a8a44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 38 deletions

View File

@ -24,13 +24,13 @@ A function with following signature
## WiFi.beginProvision() ## WiFi.beginProvision()
WiFi.beginProvision(scheme prov_scheme, wifi_prov_scheme_event_handler_t scheme_event_handler, wifi_prov_security_t security, char * pop, char * service_name, char * service_key, uint8_t * uuid); WiFi.beginProvision(void ( * scheme_cb)(), wifi_prov_scheme_event_handler_t scheme_event_handler, wifi_prov_security_t security, char * pop, char * service_name, char * service_key, uint8_t * uuid);
#### Parameters passed #### Parameters passed
* prov_scheme : choose the mode of transfer * function pointer : choose the mode of transfer
* WIFI_PROV_SCHEME_BLE - Using BLE * provSchemeBLE - Using BLE
* WIFI_PROV_SCHEME_SOFTAP - Using SoftAP * provSchemeSoftAP - Using SoftAP
* security : choose security type * security : choose security type
* WIFI_PROV_SECURITY_1 - It allows secure communication which consists of secure handshake using key exchange and proof of possession (pop) and encryption/decryption of messages. * WIFI_PROV_SECURITY_1 - It allows secure communication which consists of secure handshake using key exchange and proof of possession (pop) and encryption/decryption of messages.
@ -48,7 +48,7 @@ WiFi.beginProvision(scheme prov_scheme, wifi_prov_scheme_event_handler_t scheme_
* pop : It is the string that is used to provide the authentication. * pop : It is the string that is used to provide the authentication.
* service_name : Specify service name for the device, if it is not specified then default chosen name via SoftAP is WIFI_XXX and via BLE is BLE_XXX where XXX are the last 3 bytes of the MAC address. * service_name : Specify service name for the device, if it is not specified then default chosen name is PROV_XXX where XXX are the last 3 bytes of the MAC address.
* service_key : Specify service key, if chosen mode of provisioning is BLE then service_key is always NULL * service_key : Specify service key, if chosen mode of provisioning is BLE then service_key is always NULL
@ -63,7 +63,7 @@ WiFi.beginProvision(scheme prov_scheme, wifi_prov_scheme_event_handler_t scheme_
* scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE * scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE
* security = WIFI_PROV_SECURITY_1 * security = WIFI_PROV_SECURITY_1
* pop = "abcd1234" * pop = "abcd1234"
* service_name = "WiFi_XXX" * service_name = "PROV_XXX"
* service_key = NULL * service_key = NULL
* uuid = NULL * uuid = NULL
@ -79,7 +79,7 @@ https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provis
``` ```
[I][WiFiProv.cpp:117] beginProvision(): Starting AP using SOFTAP [I][WiFiProv.cpp:117] beginProvision(): Starting AP using SOFTAP
service_name : WIFI_XXX service_name : PROV_XXX
password : 123456789 password : 123456789
pop : abcd1234 pop : abcd1234
@ -100,7 +100,7 @@ Provisioning Ends
``` ```
[I][WiFiProv.cpp:115] beginProvision(): Starting AP using BLE [I][WiFiProv.cpp:115] beginProvision(): Starting AP using BLE
service_name : BLE_XXX service_name : PROV_XXX
pop : abcd1234 pop : abcd1234
Provisioning started Provisioning started
@ -119,8 +119,8 @@ Provisioning Ends
## Credentials are available on device ## Credentials are available on device
``` ```
[I][WiFiProv.cpp:125] beginProvision(): Aleardy Provisioned, starting Wi-Fi STA [I][WiFiProv.cpp:146] beginProvision(): Aleardy Provisioned, starting Wi-Fi STA
[I][WiFiProv.cpp:126] beginProvision(): CONNECTING ACCESS POINT CREDENTIALS : [I][WiFiProv.cpp:150] beginProvision(): SSID : Wce*****
[I][WiFiProv.cpp:126] beginProvision(): SSID : GIONEE M2 [I][WiFiProv.cpp:152] beginProvision(): CONNECTING TO THE ACCESS POINT :
Connected IP address : 192.168.43.120
``` ```

View File

@ -56,7 +56,7 @@ void setup() {
/* uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, /* uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf,
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };*/ 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };*/
WiFi.onEvent(SysProvEvent); WiFi.onEvent(SysProvEvent);
WiFi.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, "abcd1234", "BLE_XXX", NULL, NULL); WiFi.beginProvision(provSchemeBLE, WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, "abcd1234", "PROV_XXX", NULL, NULL);
} }
void loop() { void loop() {

View File

@ -27,19 +27,19 @@
#include <esp_event_loop.h> #include <esp_event_loop.h>
#include <esp32-hal.h> #include <esp32-hal.h>
#include <nvs_flash.h>
#include <wifi_provisioning/scheme_ble.h> #include <wifi_provisioning/scheme_ble.h>
#include <wifi_provisioning/scheme_softap.h> #include <wifi_provisioning/scheme_softap.h>
#include <wifi_provisioning/manager.h> #include <wifi_provisioning/manager.h>
#undef IPADDR_NONE #undef IPADDR_NONE
#include "WiFi.h" #include "WiFi.h"
wifi_prov_mgr_config_t config;
scheme_t prov_scheme;
extern esp_err_t postToSysQueue(system_prov_event_t *); extern esp_err_t postToSysQueue(system_prov_event_t *);
static const uint8_t custom_service_uuid[16] = { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, static const uint8_t custom_service_uuid[16] = { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf,
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, }; 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, };
#define SERV_NAME_PREFIX_BLE "BLE_" #define SERV_NAME_PREFIX_PROV "PROV_"
#define SERV_NAME_PREFIX_WIFI "WIFI_"
bool WiFiProvClass::prov_enable = true; bool WiFiProvClass::prov_enable = true;
@ -48,6 +48,18 @@ bool WiFiProvClass::isProvEnabled()
return prov_enable; return prov_enable;
} }
void provSchemeBLE()
{
prov_scheme = WIFI_PROV_SCHEME_BLE;
config.scheme = wifi_prov_scheme_ble;
}
void provSchemeSoftAP()
{
prov_scheme = WIFI_PROV_SCHEME_SOFTAP;
config.scheme = wifi_prov_scheme_softap;
}
static void prov_event_handler(void *user_data, wifi_prov_cb_event_t event, void *event_data) static void prov_event_handler(void *user_data, wifi_prov_cb_event_t event, void *event_data)
{ {
if (!event) { if (!event) {
@ -87,34 +99,24 @@ static void prov_event_handler(void *user_data, wifi_prov_cb_event_t event, void
} }
} }
static void get_device_service_name(scheme prov_scheme, char *service_name, size_t max) static void get_device_service_name(char *service_name, size_t max)
{ {
uint8_t eth_mac[6]; uint8_t eth_mac[6];
WiFi.macAddress(eth_mac); WiFi.macAddress(eth_mac);
if(prov_scheme == WIFI_PROV_SCHEME_BLE) { snprintf(service_name, max, "%s%02X%02X%02X",SERV_NAME_PREFIX_PROV, eth_mac[3], eth_mac[4], eth_mac[5]);
snprintf(service_name, max, "%s%02X%02X%02X",SERV_NAME_PREFIX_BLE, eth_mac[3], eth_mac[4], eth_mac[5]);
} else {
snprintf(service_name, max, "%s%02X%02X%02X",SERV_NAME_PREFIX_WIFI, eth_mac[3], eth_mac[4], eth_mac[5]);
}
} }
void WiFiProvClass :: beginProvision(scheme prov_scheme, wifi_prov_event_handler_t scheme_event_handler, wifi_prov_security_t security, const char * pop, const char *service_name, const char *service_key, uint8_t * uuid) void WiFiProvClass :: beginProvision(void (*scheme_cb)(), wifi_prov_event_handler_t scheme_event_handler, wifi_prov_security_t security, const char * pop, const char *service_name, const char *service_key, uint8_t * uuid)
{ {
prov_enable = true; prov_enable = true;
bool provisioned = false; bool provisioned = false;
wifi_prov_mgr_config_t config; scheme_cb();
config.scheme_event_handler = scheme_event_handler; config.scheme_event_handler = scheme_event_handler;
config.app_event_handler = { config.app_event_handler = {
.event_cb = prov_event_handler, .event_cb = prov_event_handler,
.user_data = NULL .user_data = NULL
}; };
if(prov_scheme == WIFI_PROV_SCHEME_BLE) {
config.scheme = wifi_prov_scheme_ble;
} else {
config.scheme = wifi_prov_scheme_softap;
}
wifi_prov_mgr_init(config); wifi_prov_mgr_init(config);
WiFi.mode(WIFI_MODE_AP); WiFi.mode(WIFI_MODE_AP);
wifi_prov_mgr_is_provisioned(&provisioned); wifi_prov_mgr_is_provisioned(&provisioned);
@ -129,7 +131,7 @@ void WiFiProvClass :: beginProvision(scheme prov_scheme, wifi_prov_event_handler
if(service_name == NULL) { if(service_name == NULL) {
char service_name_temp[12]; char service_name_temp[12];
get_device_service_name(prov_scheme,service_name_temp,sizeof(service_name_temp)); get_device_service_name(service_name_temp,sizeof(service_name_temp));
service_name = (const char *)service_name_temp; service_name = (const char *)service_name_temp;
} }
@ -150,12 +152,13 @@ void WiFiProvClass :: beginProvision(scheme prov_scheme, wifi_prov_event_handler
wifi_prov_mgr_deinit(); wifi_prov_mgr_deinit();
WiFi.mode(WIFI_MODE_STA); WiFi.mode(WIFI_MODE_STA);
log_i("Aleardy Provisioned, starting Wi-Fi STA"); log_i("Aleardy Provisioned, starting Wi-Fi STA");
log_i("CONNECTING ACCESS POINT CREDENTIALS : ");
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
wifi_config_t conf; wifi_config_t conf;
esp_wifi_get_config(WIFI_IF_STA,&conf); esp_wifi_get_config(WIFI_IF_STA,&conf);
log_i("SSID : %s\n",conf.sta.ssid); log_i("SSID : %s\n",conf.sta.ssid);
#endif #endif
log_i("CONNECTING TO THE ACCESS POINT : ");
WiFi.begin();
} }
} }

View File

@ -19,16 +19,18 @@
#include "wifi_provisioning/manager.h" #include "wifi_provisioning/manager.h"
#include "wifi_provisioning/scheme_ble.h" #include "wifi_provisioning/scheme_ble.h"
#include "esp_wifi.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "SimpleBLE.h" #include "SimpleBLE.h"
//Select the scheme using which you want to provision //Select the scheme using which you want to provision
enum scheme typedef enum
{ {
WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_BLE,
WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_SOFTAP
WIFI_PROV_SCHEME_CONSOLE }scheme_t;
};
extern void provSchemeSoftAP();
extern void provSchemeBLE();
//Provisioning class //Provisioning class
class WiFiProvClass class WiFiProvClass
{ {
@ -42,7 +44,7 @@ class WiFiProvClass
bool isProvEnabled(); bool isProvEnabled();
void beginProvision(scheme prov_scheme = WIFI_PROV_SCHEME_SOFTAP, wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL, const char * service_key = NULL, uint8_t *uuid = NULL); void beginProvision(void (*scheme_cb)() = provSchemeSoftAP, wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL, const char * service_key = NULL, uint8_t *uuid = NULL);
}; };
/* /*