Optimizing Network Configuration and Indicator Functions

Optimizing Network Configuration and Indicator Functions

Skip this section if processing by the Wi-Fi module is used. When protocol migration is successful, the network configuration command and indicator function need to be optimized for network configuration. In mode of cooperative processing by the Wi-Fi module and MCU, the MCU can select the network configuration triggering and indication modes based on actual requirements. Typically, network configuration is triggered by the Wi-Fi reset button and indicated by quick or slow blinking of the Wi-Fi indicator. We recommend that you enable both network configuration modes for your product. Smart network configuration mode: The operation is simple and convenient, and the Wi-Fi indicator blinks quickly. AP network configuration mode: Network configuration is reliable, and the Wi-Fi indicator blinks slowly.

1. Network configuration command

The network configuration command can be implemented by the mcu_reset_wifi() and mcu_set_wifi_mode() functions. Typically, these two functions are invoked in the button processing function after the button is pressed for network configuration. After mcu_reset_wifi() is invoked, the Wi-Fi module is reset and the previous network configuration information is cleared. The function invoking also triggers a switchover between the AP and smart network configuration modes.

After mcu_set_wifi_mode() with parameter SMART_CONFIG or AP_CONFIG is invoked, the network configuration information is cleared, and smart or AP network configuration mode is used. This function has the same function as the mcu_reset_wifi() function. You can select one as needed.

2. Network configuration indication

Typically, the mcu_get_wifi_work_state() function is invoked at while(1) to return the Wi-Fi status. Then, you write the indicator blinking mode in based on the Wi-Fi status.

Device Network Connection Status Description Status Value LED Indicator Status
State 1 Smart network configuration 0x00 The indicator blinks at 250 ms intervals.
State 2 AP network configuration 0x01 The indicator blinks at 1500 ms intervals.
State 3 The Wi-Fi is configured. However, the device fails to connect to the router. 0x02 The indicator is off.
State 4 The Wi-Fi is configured, and the device successfully connects to the router. 0x03 The indicator is steady on.
State 5 The device connects to the router and cloud. 0x04 The indicator is steady on.
State 6 The Wi-Fi device is in low power consumption mode. 0x05 The indicator is off.

Invoke the mcu_get_wifi_work_state() function to obtain the Wi-Fi status. The function architecture is as follows:

void main(void)
{	
	...	

	while(1)
	{
		switch(mcu_get_wifi_work_state())
		{
			case SMART_CONFIG_STATE:
			//smart config configuration state: LED flash quickly; the user needs to complete the configuration
			break;
			case AP_STATE:
			//AP configuration state: LED flash slowly
			break;
			case WIFI_NOT_CONNECTED:
			//WIFI configuration is finished; the router is being connected to; LED keeps long dark
			break;
			case WIFI_CONNECTED:
			//The router is successfully connected to; LED keeps long bright
			break;
			default:break;
		}	
		...	
	}	
}

400 Call

Consult

400-881-8611