Provisioning fixes for: 1.Space 2.Provisioned (#4291)
This commit is contained in:
parent
1fd5cd79c5
commit
9d547a8a44
@ -24,13 +24,13 @@ A function with following signature
|
||||
|
||||
## 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
|
||||
|
||||
* prov_scheme : choose the mode of transfer
|
||||
* WIFI_PROV_SCHEME_BLE - Using BLE
|
||||
* WIFI_PROV_SCHEME_SOFTAP - Using SoftAP
|
||||
* function pointer : choose the mode of transfer
|
||||
* provSchemeBLE - Using BLE
|
||||
* provSchemeSoftAP - Using SoftAP
|
||||
|
||||
* 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.
|
||||
@ -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.
|
||||
|
||||
* 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
|
||||
|
||||
@ -63,7 +63,7 @@ WiFi.beginProvision(scheme prov_scheme, wifi_prov_scheme_event_handler_t scheme_
|
||||
* scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE
|
||||
* security = WIFI_PROV_SECURITY_1
|
||||
* pop = "abcd1234"
|
||||
* service_name = "WiFi_XXX"
|
||||
* service_name = "PROV_XXX"
|
||||
* service_key = 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
|
||||
service_name : WIFI_XXX
|
||||
service_name : PROV_XXX
|
||||
password : 123456789
|
||||
pop : abcd1234
|
||||
|
||||
@ -100,7 +100,7 @@ Provisioning Ends
|
||||
|
||||
```
|
||||
[I][WiFiProv.cpp:115] beginProvision(): Starting AP using BLE
|
||||
service_name : BLE_XXX
|
||||
service_name : PROV_XXX
|
||||
pop : abcd1234
|
||||
|
||||
Provisioning started
|
||||
@ -119,8 +119,8 @@ Provisioning Ends
|
||||
## Credentials are available on device
|
||||
|
||||
```
|
||||
[I][WiFiProv.cpp:125] beginProvision(): Aleardy Provisioned, starting Wi-Fi STA
|
||||
[I][WiFiProv.cpp:126] beginProvision(): CONNECTING ACCESS POINT CREDENTIALS :
|
||||
[I][WiFiProv.cpp:126] beginProvision(): SSID : GIONEE M2
|
||||
|
||||
[I][WiFiProv.cpp:146] beginProvision(): Aleardy Provisioned, starting Wi-Fi STA
|
||||
[I][WiFiProv.cpp:150] beginProvision(): SSID : Wce*****
|
||||
[I][WiFiProv.cpp:152] beginProvision(): CONNECTING TO THE ACCESS POINT :
|
||||
Connected IP address : 192.168.43.120
|
||||
```
|
||||
|
@ -56,7 +56,7 @@ void setup() {
|
||||
/* uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf,
|
||||
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };*/
|
||||
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() {
|
||||
|
@ -27,19 +27,19 @@
|
||||
#include <esp_event_loop.h>
|
||||
#include <esp32-hal.h>
|
||||
|
||||
#include <nvs_flash.h>
|
||||
#include <wifi_provisioning/scheme_ble.h>
|
||||
#include <wifi_provisioning/scheme_softap.h>
|
||||
#include <wifi_provisioning/manager.h>
|
||||
#undef IPADDR_NONE
|
||||
#include "WiFi.h"
|
||||
|
||||
wifi_prov_mgr_config_t config;
|
||||
scheme_t prov_scheme;
|
||||
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,
|
||||
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, };
|
||||
|
||||
#define SERV_NAME_PREFIX_BLE "BLE_"
|
||||
#define SERV_NAME_PREFIX_WIFI "WIFI_"
|
||||
#define SERV_NAME_PREFIX_PROV "PROV_"
|
||||
|
||||
bool WiFiProvClass::prov_enable = true;
|
||||
|
||||
@ -48,6 +48,18 @@ bool WiFiProvClass::isProvEnabled()
|
||||
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)
|
||||
{
|
||||
if (!event) {
|
||||
@ -87,33 +99,23 @@ 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];
|
||||
WiFi.macAddress(eth_mac);
|
||||
if(prov_scheme == WIFI_PROV_SCHEME_BLE) {
|
||||
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]);
|
||||
}
|
||||
snprintf(service_name, max, "%s%02X%02X%02X",SERV_NAME_PREFIX_PROV, 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;
|
||||
bool provisioned = false;
|
||||
wifi_prov_mgr_config_t config;
|
||||
scheme_cb();
|
||||
config.scheme_event_handler = scheme_event_handler;
|
||||
config.app_event_handler = {
|
||||
.event_cb = prov_event_handler,
|
||||
.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.mode(WIFI_MODE_AP);
|
||||
@ -129,7 +131,7 @@ void WiFiProvClass :: beginProvision(scheme prov_scheme, wifi_prov_event_handler
|
||||
|
||||
if(service_name == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -150,12 +152,13 @@ void WiFiProvClass :: beginProvision(scheme prov_scheme, wifi_prov_event_handler
|
||||
wifi_prov_mgr_deinit();
|
||||
WiFi.mode(WIFI_MODE_STA);
|
||||
log_i("Aleardy Provisioned, starting Wi-Fi STA");
|
||||
log_i("CONNECTING ACCESS POINT CREDENTIALS : ");
|
||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
|
||||
wifi_config_t conf;
|
||||
esp_wifi_get_config(WIFI_IF_STA,&conf);
|
||||
log_i("SSID : %s\n",conf.sta.ssid);
|
||||
#endif
|
||||
log_i("CONNECTING TO THE ACCESS POINT : ");
|
||||
WiFi.begin();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,18 @@
|
||||
|
||||
#include "wifi_provisioning/manager.h"
|
||||
#include "wifi_provisioning/scheme_ble.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "SimpleBLE.h"
|
||||
//Select the scheme using which you want to provision
|
||||
enum scheme
|
||||
typedef enum
|
||||
{
|
||||
WIFI_PROV_SCHEME_BLE,
|
||||
WIFI_PROV_SCHEME_SOFTAP,
|
||||
WIFI_PROV_SCHEME_CONSOLE
|
||||
};
|
||||
WIFI_PROV_SCHEME_SOFTAP
|
||||
}scheme_t;
|
||||
|
||||
extern void provSchemeSoftAP();
|
||||
extern void provSchemeBLE();
|
||||
|
||||
//Provisioning class
|
||||
class WiFiProvClass
|
||||
{
|
||||
@ -42,7 +44,7 @@ class WiFiProvClass
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user