AliOS-Things--EMW3060使用笔记--网关、一键配网

源码下载alios-things的release版本:https://github.com/alibaba/AliOS-Things/releases

配网开发

4种配网模式

alios-things支持的配网模式有以下4种:

  • 一键配网(Smartconfig)/手机热点配网(phone-config) App直接给设备配网
  • 路由器热点配网(router-config)
  • 零配(zero-config) 已配网设备为待配网设备配网
  • 蓝牙配网(ble-config) 借助BT/BLE为设备配网

alios-things里面的配网代码没有开源,使用库文件的形式提供给上层应用使用。库文件位于AliOS-Things/framework/ywss4linkkit/lib/中。

配网API

配网的api有以下几个:源码路径(V2.0.0)为:AliOS-Things-2.0.0\middleware\linkkit\sdk-c\src\services\awss\awss.h

  • 启动配网服务:int awss_start()
  • 停止配网服务:int awss_stop()
  • 确认进行配网:int awss_config_press()
  • 发送token到云服务器:int awss_report_cloud()
  • 配网重置:void awss_report_reset

配网事件:

enum awss_event_t {
    AWSS_START = 0x1000,       // AWSS start without enbale, just supports device discover
    AWSS_ENABLE,               // AWSS enable
    AWSS_LOCK_CHAN,            // AWSS lock channel(Got AWSS sync packet)
    AWSS_CS_ERR,               // AWSS AWSS checksum is error
    AWSS_PASSWD_ERR,           // AWSS decrypt passwd error
    AWSS_GOT_SSID_PASSWD,      // AWSS parse ssid and passwd successfully
    AWSS_CONNECT_ADHA,         // AWSS try to connnect adha (device discover, router solution)
    AWSS_CONNECT_ADHA_FAIL,    // AWSS fails to connect adha
    AWSS_CONNECT_AHA,          // AWSS try to connect aha (AP solution)
    AWSS_CONNECT_AHA_FAIL,     // AWSS fails to connect aha
    AWSS_SETUP_NOTIFY,         // AWSS sends out device setup information (AP and router solution)
    AWSS_CONNECT_ROUTER,       // AWSS try to connect destination router
    AWSS_CONNECT_ROUTER_FAIL,  // AWSS fails to connect destination router.
    AWSS_GOT_IP,               // AWSS connects destination successfully and got ip address
    AWSS_SUC_NOTIFY,           // AWSS sends out success notify (AWSS sucess)
    AWSS_BIND_NOTIFY,          // AWSS sends out bind notify information to support bind between user and device
    AWSS_RESET = 0x3000,            // Linkkit reset success (just got reset response from cloud without any other operation)
};

有没有例程呢?

在linkkit_gateway工程中

D:.
│  app_entry.c                 # 这个文件中有awss_start()函数,说明这里可以使用一键配网的功能
│  app_entry.h
│  k_app_config.h
│  linkkit_example_gateway.c   # 该文件中又利用宏定义把启动文件“转到”了 /newapi/gateway.c
│  linkkit_gateway.mk          # makefile文件,确定了启动文件为linkkit_example_gateway.c
│  ucube.py
│
├─newapi
│      gateway.c               # 这里并没有看到一键配网的功能函数
│
└─simulate_subdev
        testcmd.c
        testcmd.h
        testcmd_lock.c
        testcmd_lock.h

在linkkit_example_gateway.c中的开头就是:

#ifndef DEPRECATED_LINKKIT
#include "newapi/gateway.c" // 这一行不是灰的
#else
......  // 这里的一整片的代码都是有点灰色的
#endif

然后为了使用一键配网的功能我将其改成了:

#ifndef DEPRECATED_LINKKIT
#include "app_entry.c" // app_entry.c中有一键配网的功能函数
#else
......  // 这里的一整片的代码都是有点灰色的
#endif

这种宏定义“转”到XX文件中去启动的方法我还是第一次使用的。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值