Is it possible to define an extra payload fields directly from TTN application different per device like an API Key

It works for me:

  1. Downloaded the latest version for the Mac and renamed the unzipped executable to ttnctl.
  2. Followed the instructions to log in.
  3. Listed the applications: ttnctl applications list
  4. Followed the instructions to select the active application for the subsequent commands: ttnctl applications select
  5. Listed the active application’s devices: ttnctl devices list
  6. Executed:
    • ttnctl devices set my-device-id --attr-set my1stkey:my1stvalue
    • ttnctl devices set my-device-id --attr-set my2ndkey:"my 2nd value"
    • ttnctl devices set my-device-id --attr-set "my 3rd key":"my 3rd value"
    • ttnctl devices set my-device-id --attr-set "my 4th key:my 4th value"
    • ttnctl devices set my-device-id --attr-set my5thkey:123

…and am nicely getting the additional attributes in each uplink I see using mosquitto_sub -h eu.thethings.network -u my-app-id -P ttn-account-v2.w1...Gk -t my-app-id/devices/+/+

{
   "app_id": "my-app-id",
   "dev_id": "my-device-id",
   ...
   "payload_raw": "By4HLgkSKXUpmSnKACEAIQApYQ==",
   "metadata": {
      "time": "2018-10-27T11:35:41.447910401Z",
      ...
   },
   "attributes": {
      "my 3rd key": "my 3rd value",
      "my 4th key": "my 4th value",
      "my1stkey": "my1stvalue",
      "my2ndkey": "my 2nd value",
      "my5thkey": "123"
   }
}

Also, running ttnctl devices info my-device-id nicely shows:

 Attributes:
          my 3rd key: my 3rd value
          my 4th key: my 4th value
            my1stkey: my1stvalue
            my2ndkey: my 2nd value
            my5thkey: 123

So:

  • ttnctl is quite lenient when it comes to quoting whitespace.
  • All values are string values, even when they could be numeric.
  • Beware that at most 5 attributes are supported: Could not set device on Handler: Maximum number of custom attributes (5) exceeded.
4 Likes