Skip to content

Contextual associations store and API for context-aware physical spaces. We believe in an open Internet of Things.

License

Notifications You must be signed in to change notification settings

reelyactive/chickadee

Repository files navigation

chickadee

chickadee is a contextual associations store and hyperlocal context API for Pareto Anywhere open source IoT middleware.

Overview of chickadee

Specifically, chickadee associates wireless device identifiers with metadata such as a URL, a tag, a directory, and/or a position. Additionally, it provides a contextual API when coupled with live data from a barnacles instance and optional chimps instance. And finally, it provides an API to store and retrieve GeoJSON features. chickadee can run standalone, although it is usually run together with its peer modules.

Installation

npm install chickadee

Hello chickadee!

npm start

Browse to localhost:3001/associations/001bc50940810000/1 to see if there are any associations for the device with EUI-64 identifier 00-1b-c5-09-40-81-00-00. By default, this should return Not Found. Interact with chickadee through the REST API described below.

REST API

chickadee's REST API includes the following three base routes:

  • /associations for retrieving/specifying metadata associations with devices
  • /context for retrieving the context of specific devices
  • /features for retrieving/specifying GeoJSON features

GET /associations[?]

Retrieve all associations, with optional query string.

Example request

Method Route Content-Type
GET /associations application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/associations"
    }
  },
  "associations": {
    "001bc50940810000/1": {},
    "001bc50940820000/1": {}
  }
}

By default, each association will be returned as an empty object. To include one or more association properties, use a query string as specified below.

Query strings

The following query string parameters are supported:

  • tag to filter on a specific tag
  • directory to filter on a specific directory
  • include to include a specific property in each returned association

For example GET /associations?tag=animal&include=url would return all associations with "animal" among their tags, and include only the url property, if any, of each association.

It is possible to search on multiple tag, directory and include parameters, for instance GET /associations?tag=new&tag=improved would return all associations with either "new", "improved", or both, among their tags.

The directory parameter is hierarchical. For instance GET /associations?directory=parc would return associations with directory "parc", "parc:office", "parc:lounge", and so on.

GET /associations/{id}/{type}

Retrieve the associations for the given device id and type.

Example request

Method Route Content-Type
GET /associations/001bc50940810000/1 application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/associations/001bc50940810000/1"
    }
  },
  "associations": {
    "001bc50940810000/1": {
      "url": "https://www.reelyactive.com",
      "directory": "parc:office",
      "tags": [ "new", "improved" ],
      "position": [ 0.0, 0.0 ]
    }
  }
}

Single-property routes

The following routes are also supported:

  • GET /associations/{id}/{type}/url
  • GET /associations/{id}/{type}/directory
  • GET /associations/{id}/{type}/tags
  • GET /associations/{id}/{type}/position

In each case, the response is as above, but includes only the property specified by the route.

PUT /associations/{id}/{type}

Replace, or create, the associations for the given device id and type.

Example request

Method Route Content-Type
PUT /associations/001bc50940810000/1 application/json
{
  "url": "https://www.reelyactive.com",
  "directory": "parc:office",
  "tags": [ "new", "improved" ],
  "position": [ 0.0, 0.0 ]
}

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/associations/001bc50940810000/1"
    }
  },
  "associations": {
    "001bc50940810000/1": {
      "url": "https://www.reelyactive.com",
      "directory": "parc:office",
      "tags": [ "new", "improved" ],
      "position": [ 0.0, 0.0 ]
    }
  }
}

Single-property routes

The following routes are also supported:

  • PUT /associations/{id}/{type}/url
  • PUT /associations/{id}/{type}/directory
  • PUT /associations/{id}/{type}/tags
  • PUT /associations/{id}/{type}/position

In each case, the request and response are as above, however only the property specified by the route will be considered in the request.

DELETE /associations/{id}/{type}

Remove the associations for the given device id and type.

Example request

Method Route Content-Type
DELETE /associations/001bc50940810000/1 application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/associations/001bc50940810000/1"
    }
  }

Single-property routes

The following routes are also supported:

  • DELETE /associations/{id}/{type}/url
  • DELETE /associations/{id}/{type}/directory
  • DELETE /associations/{id}/{type}/tags
  • DELETE /associations/{id}/{type}/position

In each case, the response is as above.

GET /context

Retrieve the context of all active devices.

Example request

Method Route Content-Type
GET /context application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/context"
    }
  },
  "devices": {
    "fee150bada55/2": {
      "nearest": [
        {
          "device": "001bc50940810000/1",
          "rssi": -72
        },
        {
          "device": "001bc50940820000/1",
          "rssi": -85
        }
      ],
      "dynamb": {
        "timestamp": 1624714123456,
        "batteryPercentage": 67,
        "acceleration": [ -0.15625, -0.94921875, 0.109375 ]
      },
      "spatem": {
        "timestamp": 1624714123456,
        "type": "position",
        "data": {
          "type": "FeatureCollection",
          "features": [
            {
              "type": "Feature",
              "properties": {
                "isDevicePosition": true,
                "positioningEngine": "External"
              },
              "geometry": {
                "type": "Point",
                "coordinates": [ -73.57123, 45.50883 ]
              }
            }
          ]
        }
      },
      "statid": {
        "uuids": [ "feaa" ],
        "uri": "https://sniffypedia.org/Product/Google_Eddystone/",
        "deviceIds": [ "7265656c652055554944/000000000d09" ]
      },
      "url": "https://www.reelyactive.com/team/obelix/",
      "tags": [ "animal" ]
    },
    "001bc50940810000/1": {
      "directory": "parc:office",
      "tags": [ "reelceiver" ]
    },
    "001bc50940820000/1": {
      "directory": "parc:lounge",
      "tags": [ "OiO" ]
    }
  }
}

GET /context/device/{id}/{type}

Retrieve the context of the active device with the given id and type.

Example request

Method Route Content-Type
GET /context/device/fee150bada55/2 application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/context/device/fee150bada55/2"
    }
  },
  "devices": {
    "fee150bada55/2": {
      "nearest": [
        {
          "device": "001bc50940810000/1",
          "rssi": -72
        },
        {
          "device": "001bc50940820000/1",
          "rssi": -85
        }
      ],
      "dynamb": {
        "timestamp": 1624714123456,
        "batteryPercentage": 67,
        "acceleration": [ -0.15625, -0.94921875, 0.109375 ]
      },
      "spatem": {
        "timestamp": 1624714123456,
        "type": "position",
        "data": {
          "type": "FeatureCollection",
          "features": [
            {
              "type": "Feature",
              "properties": {
                "isDevicePosition": true,
                "positioningEngine": "External"
              },
              "geometry": {
                "type": "Point",
                "coordinates": [ -73.57123, 45.50883 ]
              }
            }
          ]
        }
      },
      "statid": {
        "uuids": [ "feaa" ],
        "uri": "https://sniffypedia.org/Product/Google_Eddystone/",
        "deviceIds": [ "7265656c652055554944/000000000d09" ]
      },
      "url": "https://www.reelyactive.com/team/obelix/",
      "tags": [ "animal" ]
    },
    "001bc50940810000/1": {
      "directory": "parc:office",
      "tags": [ "reelceiver" ]
    },
    "001bc50940820000/1": {
      "directory": "parc:lounge",
      "tags": [ "OiO" ]
    }
  }
}

GET /context/directory/{directory}

Retrieve the context of all active devices with (and within) the given directory. As directories are hierarchical, specifying the directory parc would include all subdirectories such as parc:office and parc:lounge.

Example request

Method Route Content-Type
GET /context/directory/parc application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/context/directory/parc"
    }
  },
  "devices": {
    "fee150bada55/2": {
      "nearest": [
        {
          "device": "001bc50940810000/1",
          "rssi": -72
        },
        {
          "device": "001bc50940820000/1",
          "rssi": -85
        }
      ],
      "dynamb": {
        "timestamp": 1624714123456,
        "batteryPercentage": 67,
        "acceleration": [ -0.15625, -0.94921875, 0.109375 ]
      },
      "spatem": {
        "timestamp": 1624714123456,
        "type": "position",
        "data": {
          "type": "FeatureCollection",
          "features": [
            {
              "type": "Feature",
              "properties": {
                "isDevicePosition": true,
                "positioningEngine": "External"
              },
              "geometry": {
                "type": "Point",
                "coordinates": [ -73.57123, 45.50883 ]
              }
            }
          ]
        }
      },
      "statid": {
        "uuids": [ "feaa" ],
        "uri": "https://sniffypedia.org/Product/Google_Eddystone/",
        "deviceIds": [ "7265656c652055554944/000000000d09" ]
      },
      "url": "https://www.reelyactive.com/team/obelix/",
      "tags": [ "animal" ]
    },
    "001bc50940810000/1": {
      "directory": "parc:office",
      "tags": [ "reelceiver" ]
    },
    "001bc50940820000/1": {
      "directory": "parc:lounge",
      "tags": [ "OiO" ]
    }
  }
}

GET /context/tag/{tag}

Retrieve the context of all active devices with the given tag.

Example request

Method Route Content-Type
GET /context/tag/animal application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/context/tag/animal"
    }
  },
  "devices": {
    "fee150bada55/2": {
      "nearest": [
        {
          "device": "001bc50940810000/1",
          "rssi": -72
        },
        {
          "device": "001bc50940820000/1",
          "rssi": -85
        }
      ],
      "dynamb": {
        "timestamp": 1624714123456,
        "batteryPercentage": 67,
        "acceleration": [ -0.15625, -0.94921875, 0.109375 ]
      },
      "spatem": {
        "timestamp": 1624714123456,
        "type": "position",
        "data": {
          "type": "FeatureCollection",
          "features": [
            {
              "type": "Feature",
              "properties": {
                "isDevicePosition": true,
                "positioningEngine": "External"
              },
              "geometry": {
                "type": "Point",
                "coordinates": [ -73.57123, 45.50883 ]
              }
            }
          ]
        }
      },
      "statid": {
        "uuids": [ "feaa" ],
        "uri": "https://sniffypedia.org/Product/Google_Eddystone/",
        "deviceIds": [ "7265656c652055554944/000000000d09" ]
      },
      "url": "https://www.reelyactive.com/team/obelix/",
      "tags": [ "animal" ]
    },
    "001bc50940810000/1": {
      "directory": "parc:office",
      "tags": [ "reelceiver" ]
    },
    "001bc50940820000/1": {
      "directory": "parc:lounge",
      "tags": [ "OiO" ]
    }
  }
}

POST /features

Create the GeoJSON feature, which will return a unique id, which is a random RFC 4122 version 4 UUID, without dashes.

Example request

Method Route Content-Type
POST /features application/json
{
  "type": "Feature",
  "properties": { "name": "triangle" },
  "geometry": {
    "type": "Polygon",
    "coordinates": [ [ [ 0, 1 ], [ 1, 0 ], [ 0, 0 ], [ 0, 1 ] ] ]
  }
}

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/features/"
    }
  },
  "features": {
    "df52b802f4054bdb815102be1d76f8ab": {
      "type": "Feature",
      "id": "df52b802f4054bdb815102be1d76f8ab",
      "properties": { "name": "triangle" },
      "geometry": {
        "type": "Polygon",
        "coordinates": [ [ [ 0, 1 ], [ 1, 0 ], [ 0, 0 ], [ 0, 1 ] ] ]
      }
    }
  }
}

GET /features/{id}

Retrieve the GeoJSON feature with for the given id.

Example request

Method Route Content-Type
GET /features/df52b802f4054bdb815102be1d76f8ab application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/features/df52b802f4054bdb815102be1d76f8ab"
    }
  },
  "features": {
    "df52b802f4054bdb815102be1d76f8ab": {
      "type": "Feature",
      "id": "df52b802f4054bdb815102be1d76f8ab",
      "properties": { "name": "triangle" },
      "geometry": {
        "type": "Polygon",
        "coordinates": [ [ [ 0, 1 ], [ 1, 0 ], [ 0, 0 ], [ 0, 1 ] ] ]
      }
    }
  }
}

DELETE /features/{id}

Remove the GeoJSON feature with the given id.

Example request

Method Route Content-Type
DELETE /features/df52b802f4054bdb815102be1d76f8ab application/json

Example response

{
  "_meta": {
    "message": "ok",
    "statusCode": 200
  },
  "_links": {
    "self": {
      "href": "http://localhost:3001/features/df52b802f4054bdb815102be1d76f8ab"
    }
  }

Socket.IO

When initialised with a Socket.IO server as an option, chickadee supports the following namespace:

  • /context/device/{id}/{type}

When a change in context for the given device is detected, a devices event is emitted. For an example of the devices JSON structure, see the sample response of the /context REST API above.

chickadee logo

What's in a name?

The Cornell Lab of Ornithology explains: "The Black-Capped Chickadee hides seeds and other food items to eat later. Each item is placed in a different spot and the chickadee can remember thousands of hiding places." Not only does it have an outstanding associative memory, it is also "almost universally considered cute thanks to its oversized round head, tiny body, and curiosity about everything, including humans."

If you were entrusting a bird to associate your wireless device with your online stories you'd want it to be cute and friendly enough to eat out of your hand, right? We could have named this package Clark's Nutcracker, the bird with arguably the best associative memory, but the whole nut-cracking thing doesn't inspire the same level of friendliness now does it?

One more fun fact that we feel compelled to pass along: "Every autumn Black-capped Chickadees allow brain neurons containing old information to die, replacing them with new neurons so they can adapt to changes in their social flocks and environment even with their tiny brains." Wow, that's database efficiency that we can aspire to!

Project History

chickadee v1.0.0 was released in July 2019, superseding all earlier versions, the latest of which remains available in the release-0.4 branch and as [email protected] on npm.

chickadee v1.4.0 migrates to ESMapDB from NeDB. If upgrading from a previous version, any stored associations will need to be recreated.

Contributing

Discover how to contribute to this open source project which upholds a standard code of conduct.

Security

Consult our security policy for best practices using this open source software and to report vulnerabilities.

License

MIT License

Copyright (c) 2015-2024 reelyActive

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Contextual associations store and API for context-aware physical spaces. We believe in an open Internet of Things.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published