HTTP | Subscribe and Notify Mechanism

Prerequisites

  1. Have NGROK software. If you don't have it yet, please go to the following link NGROK.

  2. Have Node JS. If you don't have it yet, please go to the following link Node JS.

  3. Have POSTMAN. If you don't have it yet, please go to the following link POSTMAN.

Steps

  1. Login to your Antares account via Antares Console https://console.antares.id

  2. Create an App, if you already have one, ignore it to proceed to the next process.

  3. Create Device, if you already have one, ignore it to proceed to the next process.

  4. Start by writing the programme code to get data from ANTARES. You can use the following programme code: Copy the program code to your computer's local storage then save it in .js extension format. In this tutorial, we save it with monitor.js

    var express = require('express');
    var app = express();
    var server = require('http').createServer(app);
    var bodyParser = require('body-parser');
    var util = require('util')
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    
    app.post('/monitor', function(req, res, next) {
      console.log(util.inspect(req.body, false, null));
      res.send('ack');
    });
    
    
    server.listen(9000, function() {
      console.log('App listening on port 9000');
    });
  5. Open a command prompt (windows) or terminal (linux)

    Enter the directory of the programme code file you saved earlier

  6. Run the programme code according to the image below.

    The successful programme code can be seen as in the following image.

    Having problems? If yes, execute the following syntax. Otherwise, ignore this process.

    Install packages that are not yet installed.

    Allow Access when running the programme code.

  7. Start running NGROK. NGROK will help you to open your localhost to the public domain. Firstly, go to the NGROK directory. Make sure you have extracted it, so that it is in .exe file format.

    cd download-path/

    Run NGROK using port 9000 in the following way:

    ngrok.exe port 9000
  8. Open the Device that you have created earlier. Click the Subscribe button and a pop up menu will appear.

    Add /monitor to the end of the NGROK URL as below.

    When you have successfully subscribed to it, a pop up will appear.

  9. Let's check if your server is getting notifications with an emulator device using POSTMAN. Please open POSTMAN, and fill in all the parameters with the following information.

Let's check if your server is getting notifications with an emulator device using POSTMAN. Please open POSTMAN, and fill in all the parameters with the following information.

Header

Body

{
  {
  "m2m:cin": {
    "xmlns:m2m": "http://www.onem2m.org/xml/protocols",
    "cnf": "application/json",
    "con": "{\"temperature\":30.3, \"humidity\":35.1}"
  }
}

As long as you send data, your monitor server application will get the data that the server gets. The data can be seen as follows.

Congratulations! You have just received a data notification.

Last updated