3.1.7.4 Provisioning Service

The provisioning service helps to configure the Wi-Fi interface credentials. It supports TCP tunnel and Web server based provisioning services. It implements or handles all the required AT commands to start the module in Access Point mode and open up a TCP tunnel or serve a HTML web page to receive the Wi-Fi credentials. The provisioning service call API syntax is provided below:
RNWF_RESULT_t RNWF_PROV_SrvCtrl(RNWF_PROV_SERVICE_t request, void *input)
The provisioning service provides the following options for the user:
Table 3-8. Provisioning Options
OptionsInputsRemarks
RNWF_PROV_ENABLENoneEnables the provisioning service
RNWF_PROV_DISABLENoneDisables the provisioning service
RNWF_PROV_SET_CALLBACKCallback handlerRegisters the application callback function to report the provisioning status
The following list captures the provisioning service callback event codes and their arguments
Table 3-9. Callback Event Codes
EventResponse ComponentsRemarks
RNWF_PROV_COMPLTEMode, SSID, Passphrase, Security, AutoenableProvisioning complete and returns the provisioned Access Point credentials. User application can store it securely for auto reconnection on every boot up
RNWF_PROV_FAILURENoneProvisioning failure
The provisioning service sequence is provided below:
Figure 3-21. Provisioning Service Sequence

Following example code showcases the use of provisioning service

/*
    Provisioning application
*/
void APP_WIFI_Callback(RNWF_WIFI_EVENT_t event, uint8_t *p_str)
{            
    switch(event)
    {
        case RNWF_CONNECTED:
            printf("Wi-Fi Connected\n");            
            break;
        case RNWF_DISCONNECTED:
            printf("Wi-Fi Disconnected\nReconnecting... \n");
            RNWF_WIFI_SrvCtrl(RNWF_STA_CONNECT, NULL);
            break;
        case RNWF_DHCP_DONE:
            printf("DHCP IP:%s\n", &p_str[2]);      
            break;
        default:
            break;                    
    }    
}
void APP_PROV_Callback(RNWF_PROV_EVENT_t event, uint8_t *p_str)
{
    switch(event)
    {
        case RNWF_PROV_COMPLTE:
        {
            RNWF_PROV_SrvCtrl(RNWF_PROV_DISABLE, NULL);           
            RNWF_WIFI_SrvCtrl(RNWF_WIFI_SET_CALLBACK, APP_WIFI_Callback);
            // Application can save the configuration in NVM
            RNWF_WIFI_SrvCtrl(RNWF_SET_WIFI_PARAMS, (void *)p_str);                        
        }    
        break;
        case RNWF_PROV_FAILURE:
            break;
        default:
            break;        
    }
   
}

int main(void)
{   
    SYSTEM_Initialize();
    RNWF_IF_Init();      

    // Enable Provisioning Mode
    RNWF_PROV_SrvCtrl(RNWF_PROV_ENABLE, NULL);
    RNWF_PROV_SrvCtrl(RNWF_PROV_SET_CALLBACK, (void *)APP_PROV_Callback);        
    while(1)
    {                
        RNWF_EVENT_Handler();
    }      
}