Giter VIP home page Giter VIP logo

sigfox-callback-demo's Introduction

Sigfox Node.js Callback Demo

Purpose

  • Logs the message sent by your Sigfox objects in an SQL database
  • Display a table of received messages, with their unique id, data payload and relevant metadata

This is a Node.js + hapi application, with three routes:

  • GET / to display the dashboard
  • POST /uplink to log an uplink callback
  • POST /downlink to log a downlink request, and send a reply back to the device

Installation

Dependencies

Before installing the app itself, check that the main dependencies are installed on your system

Node.js

To install, the better is probably to use nvm (Node version manager) that will let you switch between version of Node.

As of July 2019, the LTS version of Node.js is v10.16.0

PostgreSQL

Follow the instructions on the PostgreSQL website.

Environnment vars

Env vars

  • DATABASE_URL : URL of the PostgreSQL database. Ex postgres://user:password@localhost/sigfox
  • PORT: the port your app will be listening to. Defaults to 8000

Either set them in the env, or use a config.local.js file, that will be used to populate process.env

File structure: module.exports={ DATABASE_URL: 'postgres://user:password@localhost/sigfox' };

Install

$ npm install

A post install script will init a callbacks database

Test requests

Check your dashboard

Navigate to http://localhost:8000/ in your browser.

Table will be empty by default

Uplink callback

$ curl -X POST http://localhost:8000/uplink -H "Content-Type:application/json" -d '{"device":"1234", "data":"0", "station":"0001", "rssi":null, "duplicate":false}'

Downlink callback

$ curl -X POST http://localhost:8000/downlink -H "Content-Type:application/json" -d '{"device":"1234", "data":"0", "station":"04E0", "rssi":-122, "duplicate":false}'

Callback setup on Sigfox Cloud

  • Log into your Sigfox backend account
  • In the device type section, access to the device type of the object you want to track
  • In the sidebar, click on the Callbacks option
  • Click the New button
  • Choose "Custom callback"

Callback type selection

Uplink

Set your callback as following

  • Type: DATA UPLINK
  • Channel: URL
  • Url pattern : http://{your URL}/uplink
  • HTTP method: POST
    • Content-Type : application/json
    • Body : {"device":"{device}", "data":"{data}", "station":"{station}", "rssi":"{rssi}", "duplicate":"{duplicate}"}
  • Click OK

Uplink Callback configuration

Downlink

Set your callback as following:

  • Type: DATA BIDIR
  • Channel: URL
  • Url pattern : http://{your URL}/uplink
  • HTTP method: POST
    • Content-Type : application/json
    • Body : {"device":"{device}", "data":"{data}", "station":"{station}", "rssi":"{rssi}", "duplicate":"{duplicate}"}
  • Click OK

Downlink Callback configuration

By default, new downlink callbacks are inactive.
You need to explicitly activate them, by clicking on the empty disc in the Downlink column

Downlink Enablement Downlink Activation

Once activated, your downlink callback will have a blue disk displayed in the Downlink column: Downlink Activation

Easy deploy to Heroku

If you have an Heroku account, you can easily deploy this demo application online:

  • Create a new application
  • Attach a PostgreSQL addon. This will populate the DATABASE_URL env var, pointing to your new database
  • Deploy the application & start it
	$ heroku apps:create
	$ heroku addons:create heroku-postgresql:hobby-dev
	$ git push heroku master
	$ heroku ps:scale web=1
	$ heroku open

Nota bene

This tutorial aims to help you discover the uplink and downlink capabilities.

Please, be aware messages will be duplicated in the PostgreSQL database as the message "data" is saved when both uplink and downlink callbacks are called.

You could only use the BIDIR callback which enables to:

  • save the uplink frame in a database (using the "data" parameter containing the payload)
  • send a downlink frame to a device by filtering the "ack" boolean parameter (which tells if the device is asking for one)

sigfox-callback-demo's People

Contributors

dependabot[bot] avatar nicolsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.