ESP8266 SDK开发之编写自己的AT指令3

 

使用AT指令调用自己写的功能函数方便自己调试。源码:https://download.csdn.net/download/c1063891514/10970771

user_main.c


extern void at_exeCmdCiupdate(uint8_t id);


at_funcationType at_custom_cmd[] = {
		{"+TEST", 5, NULL, NULL, NULL, myTest_init},//连接服务端,并注册相应回调。
	    {"+TESA", 5, NULL, NULL, NULL, myTest1},//打印ok
	    {"+TESB", 5, NULL, NULL, NULL, myTest2},//打印自己ip地址
	    {"+TESC", 5, NULL, NULL, NULL, myTest3},//获取已连接WiFi名字密码。有问题
		{"+TESD", 5, NULL, NULL, NULL, myTest4},//发送数据测试,使用之前需要调用myTest_init
	    {"+TESE", 5, NULL, NULL, NULL, myTest5},

};


void ICACHE_FLASH_ATTR
user_init(void)
{
    char buf[64] = {0};
    at_customLinkMax = 5;
    at_init();
    os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
    at_set_custom_info(buf);
    at_port_print("\r\nready\r\n");
    at_cmd_array_regist(at_custom_cmd, sizeof(at_custom_cmd));
	at_port_print("\r\n***==================================***");
	at_port_print("\r\n***  Welcome to at espconn demo!!!   ***");
	at_port_print("\r\n*** Please create a TCP Server on PC,***");
	at_port_print("\r\n*** then enter command AT+TEST.      ***");
	at_port_print("\r\n***==================================***\r\n");
	user_set_station_config_STA();
}

具体函数如下:

打印本设备信息

设备ip,MAC等

/*
 * 1、配置连接固定网络
 * 2、命令测试
 * 		myTest2 打印自己IP地址
 *
 * */


 void ICACHE_FLASH_ATTR  myTest1(uint8_t id)
{
	at_response_ok();
	at_response_ok();

}
#define  MY_PRINTF(buf,aa,data) os_sprintf(buf,"esp8266 %s is:%d.%d.%d.%d\r\n",aa,(u8)data,(u8)(data>>8),(u8)(data>>16),(u8)(data>>24));

 void ICACHE_FLASH_ATTR  myTest2(uint8_t id)
{
	char buf[32];
	uint32 data;
	at_response_ok();
	os_sprintf(buf,"esp8266 port is:%d\r\n",espconn_port());
	at_port_print(buf);
	struct ip_info ipconfig;
	wifi_get_ip_info(STATION_IF, &ipconfig);
	MY_PRINTF(buf,"gw",ipconfig.gw.addr);
	at_port_print(buf);
	MY_PRINTF(buf,"ip",ipconfig.ip.addr);
	at_port_print(buf);
	MY_PRINTF(buf,"netmask",ipconfig.netmask.addr);
	at_port_print(buf);

}

 


 void ICACHE_FLASH_ATTR  myTest3(uint8_t id)
{
		char buf[128];
		uint8 ssid[32] = "fdasghtfsd";
		bool flag= false;
		struct station_config *sta_config;
		at_port_print("set data\r\n");
		os_sprintf(buf,"wifi_opmode is %d \r\n",wifi_get_opmode ());
		at_port_print(buf);
		flag = wifi_station_get_config_default(sta_config);
		if(flag== false)
			at_port_print("get false\r\n");
		//os_memcpy(ssid ,&sta_config->ssid ,32);
		os_sprintf(ssid,"%s",&sta_config->ssid);
		os_sprintf(buf,"wifi_config ssidi: %s\t \r\n",ssid);
		at_port_print(buf);
		
}

上电设置连接固定WiFi


 void ICACHE_FLASH_ATTR  user_set_station_config_STA(void)
{

	 char ssid[32] = "chang";
	 char password[64] = "iFlyte";
	 struct station_config stationConf;
	 wifi_set_opmode(STATION_MODE); //Set softAP + station mode

	 stationConf.bssid_set = 0; //need not check MAC address of AP
	 os_memcpy(&stationConf.ssid, ssid, 32);
	 os_memcpy(&stationConf.password, password, 64);
	 wifi_station_set_config(&stationConf);

}

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值