The Things Network LoRaWAN Stack V3 学习笔记 2.3 使用 CLI 在 Stack 上创建 DEMO 应用

前言

前两篇笔记将 Stack 跑起来并且登录上去,那接下来就可以创建应用,再之后让网关和节点连接上来。

本节记录如何使用 CLI 工具在 Stack 上创建 DEMO 应用。

可参考官方的 guide

小能手这段时间在学习 The Things Network LoRaWAN Stack V3,从使用和代码等角度对该 Stack 进行了分析,详细可点此查看

1 网关注册

$ ./ttn-lw-cli gateway create ttgtw1 --user-id ttn-1 --frequency-plan-id CN_470_510_FSB_11 --gateway-eui 33800000A0000001 --enforce-duty-cycle
{
  "ids": {
    "gateway_id": "ttgtw1",
  },
  "created_at": "2019-03-22T06:20:23.795Z",
  "updated_at": "2019-03-22T06:20:23.795Z",
  "version_ids": {

  },
  "frequency_plan_id": "CN_470_510_FSB_11",
  "antennas": [
    {
      "location": {
        "source": "SOURCE_REGISTRY"
      }
    }
  ],
  "enforce_duty_cycle": true
}

注意 frequency-plan-id 是摘取自 https://github.com/TheThingsNetwork/lorawan-frequency-plans。

可能有如下几种错误的情况:

i. 所使用的用户不对 默认是 admin,需要和自己之前登录的帐号的保持一致。

$ ./ttn-lw-cli gateway create gtw1 --user-id admin --
frequency-plan-id CN_470_510_FSB_11 --gateway-eui 00800000A00009EF --enforce-dut
y-cycle
  WARN Finished unary call                      duration=67.694297ms error=rpc error: code = PermissionDenied desc = error:pkg/auth/rights:no_user_rights (no ri
ghts for user `admin`) error_correlation_id=ccd15b415f99417dbb75e7d4e83e5aca err
or_name=no_user_rights error_namespace=pkg/auth/rights grpc_code=PermissionDenie
d grpc_method=Create grpc_service=ttn.lorawan.v3.GatewayRegistry namespace=grpc
error:pkg/auth/rights:no_user_rights (no rights for user `admin`)
    uid=admin
    correlation_id=ccd15b415f99417dbb75e7d4e83e5aca

ii. 网关名 已经被注册过。

$ ./ttn-lw-cli gateway create gtw1 --user-id ttn-1 --frequency-plan-id CN_470_510_FSB_11 --gateway-eui 00800000A00009EF --enforce-duty-cycle
error:pkg/identityserver/store:id_taken (ID already taken)
    correlation_id=732bb95a240b48e69d6349fd408e8374
[root@txiot1 lorawan-stack]# ./ttn-lw-cli gateway create gtw1 --user-id ttn-1 --
frequency-plan-id CN_470_510_FSB_11 --gateway-eui 10800000A00009EF --enforce-dut
y-cycle
error:pkg/identityserver/store:id_taken (ID already taken)
    correlation_id=192c8609e404401a9ace68e883249f9b

当然,也可以把网关现有的ID直接更新进去。

./ttn-lw-cli gateway update ttgtw1 --user-id ttn-1 --frequency-plan-id CN_470_510_FSB_11 --gateway-eui 33800000A0000001 --enforce-duty-cycle

2 注册应用

$ ./ttn-lw-cli app create ttapp1 --user-id ttn-1
{
  "ids": {
    "application_id": "ttapp1"
  },
  "created_at": "2019-03-22T06:48:27.776Z",
  "updated_at": "2019-03-22T06:48:27.776Z"
}

3 创建设备

$ ./ttn-lw-cli end-devices create ttapp1 ttdev1 --dev-eui 3304A30B001C0530 --join-eui 800000000000000C --frequency-plan-id CN_470_510_FSB_11 --root-keys.app-key.key 752BAEC23EAE7964AF27C325F4C23C9A --lorawan-phy-version 1.0.2-b --lorawan-version 1.0.2
{
  "ids": {
    "device_id": "ttdev1",
    "application_ids": {
      "application_id": "ttapp1"
    },
    "dev_eui": "3304A30B001C0530",
    "join_eui": "800000000000000C"
  },
  "created_at": "2019-03-22T06:56:08.419Z",
  "updated_at": "2019-03-22T06:56:08.419Z",
  "attributes": {
  },
  "network_server_address": "localhost:8884",
  "application_server_address": "localhost:8884",
  "join_server_address": "localhost:8884",
  "lorawan_version": "1.0.2",
  "lorawan_phy_version": "1.0.2-b",
  "frequency_plan_id": "CN_470_510_FSB_11",
  "supports_join": true,
  "root_keys": {
    "app_key": {
      "key": "dSuuwj6ueWSvJ8Ml9MI8mg=="
    }
  }
}

4 链接应用程序

按照设计,需要把 AS 链接到 NS 上。

首先,给 AS 创建 API key。

$ ./ttn-lw-cli app api-keys create --application-id ttapp1 --right-application-link
  INFO API key ID: DOTYLMFWUNF2YZNR2QZBXQCFXPKFAUVY26CJOFA
  INFO API key value: NNSXS.DOTYLMFWUNF2YZNR2QZBXQCFXPKFAUVY26CJOFA.7E4HX57SMVLEQD6B2X5OTFYYZ4GMBJE4GKO4JUFDBPVBEDY5I6LQ
  WARN The API key value will never be shown again
  WARN Make sure to copy it to a safe place
{
  "id": "DOTYLMFWUNF2YZNR2QZBXQCFXPKFAUVY26CJOFA",
  "key": "NNSXS.DOTYLMFWUNF2YZNR2QZBXQCFXPKFAUVY26CJOFA.7E4HX57SMVLEQD6B2X5OTFYYZ4GMBJE4GKO4JUFDBPVBEDY5I6LQ",
  "rights": [
    "RIGHT_APPLICATION_LINK"
  ]
}

其次,将 AS 链接到 NS。

$ ./ttn-lw-cli app link set ttapp1 --api-key NNSXS.DOTYLMFWUNF2YZNR2QZBXQCFXPKFAUVY26CJOFA.7E4HX57SMVLEQD6B2X5OTFYYZ4GMBJE4GKO4JUFDBPVBEDY5I6LQ

至此,整个设备和应用的创建过程就完成了。后面我们就让网关以及设备逐个上线,观察上下行流程。

END


The Things Network LoRaWAN Stack V3 学习笔记 2.3 使用 CLI 在 Stack 上创建 DEMO 应用

上一篇:一分*最高最火的邀请码22110100


下一篇:Alios things学习——helloworld