Giter VIP home page Giter VIP logo

jooby-rest-server's Introduction

Jooby REST Server

It is a JavaScript application that provides a REST API using the jooby-codec library. This application allows you to easily decode data.

Table of Contents

Usage

Starting the server

git clone https://github.com/jooby-dev/jooby-rest-server.git
cd jooby-rest-server
npm ci
npm start

Running with Docker

You can also run jooby-rest-server using Docker. Ensure you have Docker installed on your machine, and then use the following command:

docker pull joobydev/jooby-rest-server

docker run \
    --restart unless-stopped \
    --network host \
    --name jooby-rest-server \
    joobydev/jooby-rest-server

Environment Variables

Available environment variables:

Name Default value Description
NODE_ENV node environment setup
LOG_LEVEL info pino log levels
HTTP_HOST 0.0.0.0
HTTP_PORT 3000
API_KEY if set, checks all requests with header validation for the presence of the specified value
CHIRPSTACK_REST_API_URL ChirpStack REST API url
CHIRPSTACK_API_KEY ChirpStack API KEY generated from admin panel

Routes

Method Path Description
POST /v1/decoder General decoder route. Requires to specify protocol in the requests body.
POST /v1/decoder/analog Decoder for the analog protocol based devices.
POST /v1/decoder/mtx Decoder for the mtx protocol based devices.
POST /v1/decoder/mtxLora Decoder for the mtxLora protocol based devices.
POST /v1/decoder/obisObserver Decoder for the obisObserver protocol based devices.
POST /v1/encoder General encoder route. Requires to specify protocol in the requests body.
POST /v1/encoder/analog Encoder for the analog protocol based devices.
POST /v1/encoder/mtx Encoder for the mtx protocol based devices.
POST /v1/encoder/mtxLora Encoder for the mtxLora protocol based devices.
POST /v1/encoder/obisObserver Encoder for the obisObserver protocol based devices.

POST request parameters

Framing format

Name Value Description
NONE 0 no framing
HDLC 1 HDLC frame format

Default value: 0.
Example: framingFormat: 1.

Bytes conversion format

Name Value Description
HEX 1 data treats as hex string
BASE64 2 data threats as base64 string

Default value: 1.
Example: bytesConversionFormat: 1.

Direction

Name Value Description
AUTO 0 auto detection
DOWNLINK 1 the path of data transmission from the device to the user
UPLINK 2 the path of data transmission from the user to the device

Note: direction is not utilized for the obisObserver based devices. Default value: 0.
Example: direction: 1.

Protocols

Value Description
analog analog protocol based devices
mtx mtx protocol based devices
mtxLora mtxLora protocol based devices
obisObserver obisObserver protocol based devices

Example: protocol: obisObserver.

Dlms conversion

Valid for the mtxLora based devices. OBIS codes used as fields in decoder reports.

Example: dlms: true.

Examples

Decoder

Analog module
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 1, "bytesConversionFormat": 1,"data": "1f020048"}' \
    http://localhost:3000/v1/decoder/analog
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "analog", "direction": 1, "bytesConversionFormat": 1,"data": "1f020048"}' \
    http://localhost:3000/v1/decoder
Mtx
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 1, "bytesConversionFormat": 2,"data": "ARAQBwAAQg=="}' \
    http://localhost:3000/v1/decoder/mtx
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "mtx", "direction": 1, "bytesConversionFormat": 2,"data": "ARAQBwAAQg=="}' \
    http://localhost:3000/v1/decoder
MtxLora
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 1, "bytesConversionFormat": 2, "data": "HgkjkSMQEAcAAADU"}' \
    http://localhost:3000/v1/decoder/mtxLora
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "mtxLora", "direction": 1, "bytesConversionFormat": 2, "data": "HgkjkSMQEAcAAADU"}' \
    http://localhost:3000/v1/decoder
MtxLora (dlms)

Segment 1:

curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 2, "dlms": "true", "data": "1e28c4314d1010796430280fff011d00000008001a00000008001d00000008011d00000008001a00000033"}' \
    http://localhost:3000/v1/decoder/mtxLora

Segment 2:

curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 2, "dlms": "true", "data": "1e28c43208001d00000008011d00000008001a00000008001d00000008011d00000008001a00000008009d"}' \
    http://localhost:3000/v1/decoder/mtxLora

Segment 3:

curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 2, "dlms": "true", "data": "1e21c4b31d00000008013a00000008013a00000008013a00000008013a00000008000063d0b9e5e7"}' \
    http://localhost:3000/v1/decoder/mtxLora
Obis observer
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "data": "04050108080001"}' \
    http://localhost:3000/v1/decoder/obisObserver
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "obisObserver", "data": "04050108080001"}' \
    http://localhost:3000/v1/decoder

Encoder

Analog module
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 1, "commands": [{"id": 7}]}' \
    http://localhost:3000/v1/encoder/analog
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "analog", "direction": 1, "commands": [{"id": 7}]}' \
    http://localhost:3000/v1/encoder
Mtx
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 1, "messageId": 2, "commands": [{"id": 7}]}' \
    http://localhost:3000/v1/encoder/mtx
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "mtx", "direction": 1, "messageId": 2, "commands": [{"id": 7}]}' \
    http://localhost:3000/v1/encoder
MtxLora
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "direction": 1, "messageId": 2, "segmentationSessionId": 2, "commands":[{"id":7}]}' \
    http://localhost:3000/v1/encoder/mtxLora
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "mtxLora", "direction": 1, "messageId": 2, "segmentationSessionId": 2, "commands":[{"id":7}]}' \
    http://localhost:3000/v1/encoder
Obis observer
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "commands":[{"requestId": 2, "id":5}]}' \
    http://localhost:3000/v1/encoder/obisObserver
curl -X POST -H "Content-Type: application/json" \
    -d '{"deviceEUI": "001a79881701b63c", "protocol": "obisObserver", "commands":[{"requestId": 2, "id":5}]}' \
    http://localhost:3000/v1/encoder/obisObserver

jooby-rest-server's People

Contributors

deadbyelpy avatar pnom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.