Community discussions

MikroTik App
 
project25
just joined
Topic Author
Posts: 12
Joined: Thu Aug 18, 2016 9:04 pm

KNOT Questions (Indoor Location related)

Tue Sep 13, 2022 12:27 am

I've been trying to evaluate the KNOT for a BLE gateway application and keep running into some hang ups. I should start off by stating the application is indoor location tracking but unlike what I've seen most setups, our is a live tracking solution (accurate down to ~2 m depending on how many beacons you have installed) and our BLE tags (the devices we are tracking) currently advertise every 366 ms. The existing gateways are OpenWRT based but the manufacturer has ended production of the device so we've been looking at alternates. Bring in the KNOT.

Most BLE gateways I've researched don't publish JSON to the broker in a format that is useful to the location engine. Instead, most devices (including the KNOT's base scrip provided via the docs) publish to a static topic as a message via the gateway's MAC address with objects defining information about the device and then arrays (including more objects) for the detected tags.

For example, here is the KNOT's MQTT output (topic = KNOT/dataTopic/$[/inteface/bridge get bridge1 mac-address]):
{
  "clientId": "",
  "t": 0,
  "v": 1,
  "OldestAdvertisementTimestamp": 1660501370957,
  "locs": [
    {
      "id": "{KNOT MAC-ADDR}",
      "tags": [
        {
          "id": "D425CC700308",
          "ts": 1660501371617,
          "rssi": -41,
          "ed": {
            "ad": "0201061aff4c00021571001fb8dc554dde81e5fc389e3cb9f1cc700308d4"
          }
        },
        {
          "id": "6B137570A5DE",
          "ts": 1660501371543,
          "rssi": -34,
          "ed": {
            "ad": "02011a020a080aff4c0010053518788fa9"
          }
        },
        {
          "id": "53C1C883FE77",
          "ts": 1660501371346,
          "rssi": -56,
          "ed": {
            "ad": "03039ffe17169ffe027650536b5f6351636359490000018331d228d0"
          }
        },
        {
          "id": "E7C4D4C7328A",
          "ts": 1660501370957,
          "rssi": -32,
          "ed": {
            "ad": "07ff4c0012020003"
          }
        }
      ],
      "ed": {
        "model": "RB924iR-2nD-BT5&BG77",
        "sn": "HCF08D6F5DP",
        "ros": "7.4",
        "cpu": 12,
        "umem": 42737664,
        "fmem": 24371200,
        "psu": 45.9,
        "temp": 43
      }
    }
  ]
}
Here is the output from another device I am evaluating (topic = dev1/dataTopic/{dev_mac}):
{
  "dev_ble_mac": "{dev-mac}",
  "dev_sn": "{dev-sn}",
  "dev_id": "1C35310",
  "dev_version": "2.3.1",
  "dev_list": [
    {
      "mac": "6B1B93B1A71C",
      "rssi": -19,
      "ad": "02011A020A080AFF4C0010053018547737",
      "ts": 861437395
    },
    {
      "mac": "D425CC700309",
      "rssi": -43,
      "n": "BC Beacon",
      "ad": "0201061AFF4C00021571001FB8DC554DDE81E5FC389E3CB9F1CC700309D40A08424320426561636F6E0302C4FE",
      "ts": 861437563
    },
    {
      "mac": "D425CC700308",
      "rssi": -35,
      "n": "BC Beacon",
      "ad": "0201061AFF4C00021571001FB8DC554DDE81E5FC389E3CB9F1CC700308D40A08424320426561636F6E0302C4FE",
      "ts": 861437613
    },
    {
      "mac": "D425CC700308",
      "rssi": -35,
      "n": "BC Beacon",
      "ad": "0201061AFF4C00021571001FB8DC554DDE81E5FC389E3CB9F1CC700308D40A08424320426561636F6E0302C4FE",
      "ts": 861437761
    },
    {
      "mac": "6B1B93B1A71C",
      "rssi": -21,
      "ad": "02011A020A080AFF4C0010053018547737",
      "ts": 861437950
    },
    {
      "mac": "589412C4E15C",
      "rssi": -72,
      "ad": "03039FFE17169FFE027650536B5F6351636359490000018331D228D009FFE0000CF5CA5AF08F",
      "ts": 861437997
    }
  ],
  "dev_list_len": 6,
  "publish_ts": 861438198
}
Due to how the location engine works though, the data structure is much different ( topic = gw/{dev-mac}/lo/{tag-mac}):
{
  "jsonVer": 5,
  "edgeMAC": "{gw-mac}",
  "devId": 12067344,
  "mac": "D425CC700308",
  "rssi": -41,
  "ts": "2022-09-12T21:08:06.114585Z",
  "iBeac": "71001FB8DC554DDE81E5FC389E3CB9F1CC700308",
  "btAddr": "D425CC700308",
  "adData": "0201061AFF4C00021571001FB8DC554DDE81E5FC389E3CB9F1CC700308D4"
}
So clearly I need to change the time stamp object around (the some objects are not actually needed) but my biggest issue is how I'd get the topic format set the way I'm looking for in Mikrotik's scripting language (i.e. gw/{dev-mac}/lo/{tag-mac}) so each BLE tag is a sub-topic under the gateway's topic. Would this be some very annoying nested for loop?

My second big issue appears to be how BLE scanning is done. The Mikrotik scrip executes every second so would the keep newest filter be best? I think the current gateway scans every 33.125 ms (KNOT defaults to 10 ms) but my question is how do I ensure that I'm not resending messages that have already been sent as they just happen to still be in the KNOT's buffer?

Is the KNOT even the right tool for this task?

Who is online

Users browsing this forum: mkx, mtkvvv, xstrid3rx and 94 guests