chickadee is a contextual associations store and hyperlocal context API for Pareto Anywhere open source IoT middleware.
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.
npm install 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.
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
Retrieve all associations, with optional query string.
Method | Route | Content-Type |
---|---|---|
GET | /associations | application/json |
{
"_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.
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.
Retrieve the associations for the given device id and type.
Method | Route | Content-Type |
---|---|---|
GET | /associations/001bc50940810000/1 | application/json |
{
"_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 ]
}
}
}
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.
Replace, or create, the associations for the given device id and type.
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 ]
}
{
"_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 ]
}
}
}
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.
Remove the associations for the given device id and type.
Method | Route | Content-Type |
---|---|---|
DELETE | /associations/001bc50940810000/1 | application/json |
{
"_meta": {
"message": "ok",
"statusCode": 200
},
"_links": {
"self": {
"href": "http://localhost:3001/associations/001bc50940810000/1"
}
}
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.
Retrieve the context of all active devices.
Method | Route | Content-Type |
---|---|---|
GET | /context | application/json |
{
"_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" ]
}
}
}
Retrieve the context of the active device with the given id and type.
Method | Route | Content-Type |
---|---|---|
GET | /context/device/fee150bada55/2 | application/json |
{
"_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" ]
}
}
}
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.
Method | Route | Content-Type |
---|---|---|
GET | /context/directory/parc | application/json |
{
"_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" ]
}
}
}
Retrieve the context of all active devices with the given tag.
Method | Route | Content-Type |
---|---|---|
GET | /context/tag/animal | application/json |
{
"_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" ]
}
}
}
Create the GeoJSON feature, which will return a unique id, which is a random RFC 4122 version 4 UUID, without dashes.
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 ] ] ]
}
}
{
"_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 ] ] ]
}
}
}
}
Retrieve the GeoJSON feature with for the given id.
Method | Route | Content-Type |
---|---|---|
GET | /features/df52b802f4054bdb815102be1d76f8ab | application/json |
{
"_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 ] ] ]
}
}
}
}
Remove the GeoJSON feature with the given id.
Method | Route | Content-Type |
---|---|---|
DELETE | /features/df52b802f4054bdb815102be1d76f8ab | application/json |
{
"_meta": {
"message": "ok",
"statusCode": 200
},
"_links": {
"self": {
"href": "http://localhost:3001/features/df52b802f4054bdb815102be1d76f8ab"
}
}
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.
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!
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 chickadee@0.4.10 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.
Discover how to contribute to this open source project which upholds a standard code of conduct.
Consult our security policy for best practices using this open source software and to report vulnerabilities.
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.