esp8266 nvs应用
一个芯片,做成一个产品,都会需要在断定的时候对一些数据进行保存,以esp8266为例,需要连接网络,所以设备必须能够保存ssid,password,否则设备如何联网,本文就结合上篇文章at命令的开发,通过at命令将ssid,password调用nvs接口,将数据保存起来,设备开机,直接读取后进行联网操作。
1.增加at命令方法
1.at命令增加到列表
atcmd_table_t at_table[] = {
{"AT+TEST",at_test_fun},
{"AT+CONNECTWIFI",at_connect_wifi_fun},
};
2.实现at命令处理函数at_connect_wifi_fun
联网(写ssid,password):AT+CONNECTWIFI=1234,12345678[回车]
读取ssid.password:AT+CONNECTWIFI=read[回车]
void at_connect_wifi_fun(int argc,char * argv)
{
wifi_msg_t wifi_msg_new;
char msg_str[64];
char *p;
nvs_handle handle_wifi;
int len = 0;
int rc;
memset(&wifi_msg_new,0,sizeof(wifi_msg_new));
memset(msg_str,0,64);
//argc 参数长度,argv内容
if(0 != strncmp(argv,"read",4))
{
printf("---write\n");
//写wifi ssid password
memcpy(msg_str,argv,argc);
printf("at parameter:%s\n",msg_str);
p = strchr(msg_str,',');
//提取ssid'
memcpy(wifi_msg_new.ssid,msg_str,(p-msg_str));
//