Skip to content

reelyactive/bins-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bins-webhook

Webhook to forward the identifiers of detected bins to a remote server.

Quick Start

Clone this repository, install package dependencies with npm install, and then from the root folder run at any time:

npm start

if using UDP raddecs as a data source, or:

npm run csl

if using a CSL reader as a data source.

Configuration

Create a file called options.json in the /config folder and include any of the properties of the following JSON:

{
    "hostname": "localhost",
    "port": 3001,
    "useHttps": false,
    "customHeaders": {},
    "heartbeatMilliseconds": 60000,
    "mixingDelayMilliseconds": 10000,
    "numberOfDecodingsThreshold": 5,
    "signalAppearanceMilliseconds": 5000,
    "cs463SignalAppearance": false
}

the default values of the properties are shown above. Each of the start scripts will reference this file, if present.

Bin Identifier Forwarding

bins-webhook will POST an array of bin identifiers to the /bins route of the hostname/port specified in the config/options.json file every heartbeatMilliseconds. In the default configuration, bins-webhook will POST to http://localhost:3001/bins every minute (60000ms).

To point the webhook to a different server, update the hostname, port and useHttps values in the options.json file as required. For example:

{
    "hostname": "192.168.0.123",
    "port": 8080,
    "useHttps": true
}

would POST to https://192.168.0.123:8080/bins.

The target server should accept application/json on the /bins route, and expect, as the body, an array of hexadecimal strings, each representing a bin identifier. If there are no bins, bins-webhook will POST an empty array. The following example includes two 96-bit EPC identifiers.

[ "3074257bf7194e4000001a84", "3074257bf7194e4000001a85" ]

Bin Decoding

bins-webhook handles decodings from a barnowl instance which interprets data from the underlying hardware into raddec objects which contain, among other things, a transmitterId and numberOfDecodings by receiverId.

The mixingDelayMilliseconds parameter determines for how long the barnowl instance will combine bin decodings into a single raddec to be processed by the bins-webhook logic.

bins-webhook maintains a Map of bins (devices) in memory with the bin identifier (transmitterId) as key and the number of decodings (cumulative over all receivers) as value. Whenever a bin is decoded, the Map is updated to increment the number of decodings.

Every heartbeatMilliseconds, bins-webhook iterates over the Map of bins and forwards those which have a number of decodings greater than or equal to numberOfDecodingsThreshold, after which the Map is cleared.

Signal Appearance

The detection (appearance) of a new bin can optionally be signalled on a general-purpose output of the CS463 reader by setting the cs463SignalAppearance option to true.

In this case, GPO1 will be closed when a new bin appears and opened after signalAppearanceMilliseconds. If multiple bins appear within the signal window, GPO1 will be opened signalAppearanceMilliseconds after the last bin appears within the window.

Note that toggling GPO1 on the CS463 may require additional permissions which can be set with the following commands (on the CS463 itself):

sudo chmod 755 /opt/inf_out_set
sudo chmod 666 /sys/class/gpio/gpio205/value

To ensure these additional permissions apply each time the CS463 reboots, add the two commands above to the end of the /etc/rc.local file.

License

MIT License

Copyright (c) 2023-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

Webhook to forward the identifiers of detected bins. We believe in an open Internet of Things.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published