linkkitapp例程中,主要有两个c文件
- linkkit_entry.c
- linkkit_sample_solo.c
可以这么理解,整个工程编译后,程序运行时,linkkit_entry.c中的文件将会调用linkkit_sample_solo.c中的函数。
linkkitapp.mk
linkkit_entry.c
linkkit_sample_solo.c
make.settings
ucube.py
一、修改四元组
在工程下的linkkit_sample_solo.c中修改。具体怎么获取,省略。
二、下载程序–配网
1、第一个坑:原以为上电就可以扫码配网的,原来还要进入配网模式才可以!
把程序下载到ESP8266上面之后,复位开始运行,波特率921600,串口调试助手里面是这个样子的:
empty
Wifi init success!!
mode : softAP(ce:50:e3:04:d4:16)
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
add if1
bcn 100
trace should have cli to control!!!
[000110]<V> aos framework init.
[000110]<V> ============free heap size =39528==========
Hello liefyuan
[000120]<V> IOTX_AWSS_START
awss version: smarthome-bd18d6d[37m<DEBUG> [zconfig_init#2115] : awss lib smarthome-bd18d6d
[0m
bcn 0
del if1
usl
sul 0 0
mode : sta(cc:50:e3:04:d4:16)
add if0
chan 1
[1] ssid:沉迷于上班无法自拔, mac:488ad29ead62, chn:1, auth:wpa2-psk, aes, aes, rssi:-84, adha:0
[2] ssid:1318, mac:34967240f2d8, chn:1, auth:wpa2-psk, aes, aes, rssi:-65, adha:0
[3] ssid:ChinaNet-VcEF, mac:cc90e83a23b7, chn:1, auth:wpa2-psk, aes, tkip, rssi:-83, adha:0
[4] ssid:iTV-7903, mac:38e595d60f49, chn:1, auth:wpa2-psk, aes, tkip, rssi:-76, adha:0
[5] ssid:ChinaNet-7903, mac:38e595d60f48, chn:1, auth:wpa2-psk, aes, tkip, rssi:-76, adha:0
chan 6
[6] ssid:AFFCOOL, mac:8c2505d70cc0, chn:6, auth:wpa2-psk, aes, aes, rssi:-73, adha:0
[7] ssid:Mellerio, mac:b0958eaf568b, chn:6, auth:wpa2-psk, aes, tkip, rssi:-80, adha:0
[8] ssid:360鍏嶈垂WiFi-BD, mac:00367657ecbd, chn:6, auth:wpa2-psk, aes, aes, rssi:-82, adha:0
[9] ssid:meilele1, mac:dcfe187ecdfe, chn:6, auth:wpa2-psk, aes, aes, rssi:-82, adha:0
[10] ssid:DSJ, mac:d076e75e20dd, chn:7, auth:wpa2-psk, aes, tkip, rssi:-74, adha:0
[11] ssid:CMCC-WEB, mac:5866ba6f6220, chn:6, auth:open, none, none, rssi:-83, adha:0
[12] ssid:joyce0725, mac:b0d59d47cf9d, chn:6, auth:wpa2-psk, aes, aes, rssi:-79, adha:0
chan 11
[13] ssid:ChinaNet-yWMh, mac:f092b41b7929, chn:10, auth:wpa2-psk, aes, tkip, rssi:-56, adha:0
[14] ssid:mei5, mac:282cb2ff49ae, chn:11, auth:wpa2-psk, aes, aes, rssi:-63, adha:0
[15] ssid:DIRECT-KFDESKTOP-E35402EmsMJ, mac:24fd52933a9a, chn:11, auth:wpa2-psk, aes, aes, rssi:-54, adha:0
[16] ssid:BIHEE, mac:0c4b544944b9, chn:11, auth:wpa2-psk, aes, aes, rssi:-81, adha:0
[17] ssid:CMCC, mac:5866ba6f5f11, chn:11, auth:wpa2-8021x, aes, aes, rssi:-84, adha:0
[18] ssid:and-Business, mac:5866ba6f5f12, chn:11, auth:open, none, none, rssi:-82, adha:0
chan 1
chan 2
以上信息代表模块正处于一种“无所适从的扫描SSID的状态”扫到最后,什么结果都没有。如果尝试现在给它使用APP扫二维码、配网,你会发现模块毫无反应,它还是在扫描SSID。
2、进入配网模式才可以扫描配网
在linkkit_entry.c中的int application_start(int argc, char **argv)函数中
有这样一行:
aos_register_event_filter(EV_KEY, linkkit_key_process, NULL);
从函数名上看,这是一个注册事件过滤器的,过滤的目标是按键点击事件,并处理按键点击事件的,“linkket按键处理”。
同一个C文件下有它的定义:
- 需要知道AliOS定义的按键对应,自己的板子上的哪个引脚。
- 点击了AliOS配置的VALUE_KEY_CLICK按键将进入awss配网模式
- 点击了AliOS配置的VALUE_KEY_LTCLICK按键将进行awss复位操作
void linkkit_key_process(input_event_t *eventinfo, void *priv_data)
{
if (eventinfo->type != EV_KEY) { // 事件类型过滤处理按键事件:EV_KEY
return;
}
LOG("awss config press %d\n", eventinfo->value); // 传入参数事件值
if (eventinfo->code == CODE_BOOT) { // 根据传入参数判断是否点击了 CODE_BOOT这一个类型的引脚
if (eventinfo->value == VALUE_KEY_CLICK) { // 如果点击了VALUE_KEY_CLICK这个按键就进入awss配网模式
do_awss_active();
} else if (eventinfo->value == VALUE_KEY_LTCLICK) { // 否则如果点击了VALUE_KEY_LTCLICK这个按键就进入awss复位模式
do_awss_reset();
}
}
}
函数中的第一个传入参数的定义是这样的:
typedef struct {
/* The time event is generated, auto filled by aos event system */
uint32_t time;
/* Event type, value < 0x1000 are used by aos system */
uint16_t type;
/* Defined according to type */
uint16_t code;
/* Defined according to type/code */
unsigned long value;
/* Defined according to type/code */
unsigned long extra;
} input_event_t;
从命名上看:输入事件,在配网的过程中是按键输入事件。
再看看按键定义的如何,嗯,很简洁!
/** General key define */
#define EV_KEY 0x0201
#define CODE_RECORD 1
#define CODE_VOLUME 2 /* Reserve */
#define CODE_VOLUME_INC 3
#define CODE_VOLUME_DEC 4
#define CODE_PLAY_PAUSE 5
#define CODE_MUTE 6
#define CODE_CHANNEL 7
#define CODE_NEXT 8
#define CODE_RECORD_PRE 9
#define CODE_RESET 0x1001
#define CODE_STATUS 11
#define CODE_ELINK 12
#define CODE_BOOT 13
/** General key value */
#define VALUE_KEY_UP 0
#define VALUE_KEY_DOWN 1
#define VALUE_KEY_CLICK 2
#define VALUE_KEY_LTCLICK 3
#define VALUE_KEY_LLTCLICK 4
#define VALUE_KEY_DBCLICK 5
/** General channel value */
#define VALUE_SYS_CHN_CONNECTED 0
#define VALUE_SYS_CHN_CONNECTING 1
#define VALUE_SYS_CHN_DISCONNECTED 2
没有眉目,那就只能在板子上试了!引脚都试了,除了GPIO14是有反应外其他的都没反应(复位引脚除外:=)。
所以可以确定了
ESP8266的GPIO14是awss的配置引脚
使用一个跳线,先把GPIO14接GND,再接V3.3,打印出以下信息:
- 由这段代码可以知道:
LOG("awss config press %d\n", eventinfo->value);
- 当我按下连接GPIO14引脚的按键是,触发按键事件,并且事件值为:3
- 由定义:
#define VALUE_KEY_LTCLICK 3
和函数void linkkit_key_process(input_event_t *eventinfo, void *priv_data)
可以知道将执行awss复位操作!由打印信息确实可以确认是执行了复位操作。
chan 3
chan 4
chan 6
chan 7
chan 11
[051960]<V> awss config press 3
[37m<DEBUG> [awss_report_reset_to_cloud#362] : report reset:{"id":"0", "version":"1.0", "method":"thing.reset", "params":{}}
[0m
chan 13
chan 1
chan 6
chan 11
chan 1
chan 2
chan 3
chan 4
chan 5
reboot!
??????????????????????
当我再次在GPIO14上模拟一个按键点击操作时,它却如下所示:
- 再次点击GPIO14,点击事件值变成了:2
- 由定义:
#define VALUE_KEY_CLICK 2
和函数void linkkit_key_process(input_event_t *eventinfo, void *priv_data)
可以知道将执行awss配网操作!由打印信息确实可以确认
chan 7
chan 8
chan 9
chan 10
chan 11
chan 12
chan 13
[068100]<V> awss config press 2
[068100]<V> do_awss_active 1
enable awss
[068100]<V> IOTX_AWSS_ENABLE
chan 1
chan 2
chan 3
chan 4
chan 6
3、终于配网成功了
chan 8
chan 9
chan 10
chan 11
chan 12
chan 13
chan 1
[008370]<V> awss config press 2
[008370]<V> do_awss_active 0
enable awss
[008370]<V> IOTX_AWSS_ENABLE
chan 2
chan 3
chan 6
[24] ssid:CMCC, mac:5866ba6f6221, chn:6, auth:wpa2-8021x, aes, aes, rssi:-79, adha:0
[25] ssid:and-Business, mac:5866ba6f6222, chn:6, auth:open, none, none, rssi:-77, adha:0
chan 7
chan 10
chan 11
chan 13
chan 1
[010020]<V> ============free heap size =29200==========
[37m<DEBUG> [aes_decrypt_string#109] : security level: 3[0m
[37m<DEBUG> [zconfig_callback_channel_locked#1209] : channel lock @ 1
[0m
[010080]<V> IOTX_AWSS_LOCK_CHAN
[010080]<V> IOTX_AWSS_GOT_SSID_PASSWD
[37m<DEBUG> [aws_main_thread_func#410] : [channel scanning] 10090 ms
[0m
[37m<DEBUG> [aws_main_thread_func#416] : final channel 1
[0m
[37m<DEBUG> [aws_main_thread_func#434] : [channel recving] 10090 ms
[0m
[010130]<V> IOTX_AWSS_CONNECT_ROUTER
scandone
state: 0 -> 2 (b0)
[016010]<V> ============free heap size =35304==========
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 20
pm open phy_2,type:2 0 0
cnt
connected with 1318, channel 1
dhcp client start...
[WiFi] event 1
ip:192.168.0.127,mask:255.255.255.0,gw:192.168.0.1
[WiFi] event 4
[017090]<I> Got ip : 192.168.0.127, gw : 192.168.0.1, mask : 255.255.255.0
[017090]<I> Let's post GOT_IP event.
smart_config_stop 545
[017090]<V> wifi_service_event config.ssid 1318
[017090]<V> ============free heap size =34328==========
linkkit_main|1024 :: start!
linkkit_example|915 :: linkkit start
[dbg] _dm_mgr_search_dev_by_devid(52): Device Not Found, devid: 0
[inf] iotx_cm_init(77): cm verstion 0.3
[inf] iotx_device_info_init(39): device_info created successfully!
[dbg] iotx_device_info_set(49): start to set device info!
[dbg] iotx_device_info_set(63): device_info set successfully!
[inf] guider_print_dev_guider_info(279):