# HTTP | Subscribe and Notify Mechanism

**Prerequisites**

1. Have NGROK software. If you don't have it yet, please go to the following [link NGROK](https://ngrok.com/download).
2. Have Node JS. If you don't have it yet, please go to the following[ link Node JS.](https://nodejs.org/en)
3. Have POSTMAN. If you don't have it yet, please go to the following[ link POSTMAN.](https://www.postman.com/downloads/)

#### Steps <a href="#langkah" id="langkah"></a>

1. Login to your Antares account via Antares Console [https://console.antares.id](https://console.antares.id/)<br>

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/fcKgf5Y2WWFwTfJvexcn/LOG%20IN.png" alt=""><figcaption></figcaption></figure>
2. Create an App, if you already have one, ignore it to proceed to the next process.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FMUiRhtueoDlfuiMo6Gx7%2Fimage.png?alt=media&#x26;token=3f6b845e-49f6-4742-a48b-6e10bc1835e2" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/9m1YIBAMwBKUnlBWNr0I/BUAT%20DEVICE.png" alt=""><figcaption></figcaption></figure>

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

   <pre class="language-javascript" data-line-numbers><code class="lang-javascript">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');
   });
   </code></pre>

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/GlXV4iXK7e7qyx1gTqML/image.png" alt=""><figcaption></figcaption></figure>
2. Open a command prompt (windows) or terminal (linux)

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/h42s0FosbBigwWTOuPxg/image.png" alt=""><figcaption></figcaption></figure>

   Enter the directory of the programme code file you saved earlier

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/9V0jkPiiRp2Ry6zOVYGS/image.png" alt=""><figcaption></figcaption></figure>
3. Run the programme code according to the image below.<br>

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/JKIyZN6up2jOcBFoEZng/image.png" alt=""><figcaption></figcaption></figure>

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

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/iDv1yr4we1LQiwZWkoYT/image.png" alt=""><figcaption></figcaption></figure>

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

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/M3FkTZyFHx6irqeCZ5od/image.png" alt=""><figcaption></figcaption></figure>

   Install packages that are not yet installed.

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/ROIx5FFyVkJHtA9NC2jQ/image.png" alt=""><figcaption></figcaption></figure>

   Allow Access when running the programme code.

   <figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/0LDYcgHruYZFYgxmpAOo/image.png" alt=""><figcaption></figcaption></figure>
4. 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.**

   ```java
   cd download-path/
   ```

   Run **NGROK** using port 9000 in the following way:

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

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FSxN2B8h88mfG2zjblQ1g%2Fimage.png?alt=media&#x26;token=9ded021f-f302-4c98-848a-83088e7f97cd" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F1I3zzzIrE0uq7bi0RNlU%2Fimage.png?alt=media&#x26;token=bb4dbe1f-2987-4728-9c91-ea00acdb744e" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FS1ienmRk1ZTCxDSOLZmb%2Fimage.png?alt=media&#x26;token=c1c25586-acc4-42cb-98d2-682a63ddd908" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://content.gitbook.com/content/7cujmJ5QHdJaAjH815aZ/blobs/pAqZAcjG6Pwcg2TWWk9c/image.png" alt=""><figcaption></figcaption></figure>

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

<table data-header-hidden><thead><tr><th width="111"></th><th width="569.3333333333334"></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Value</strong></td></tr><tr><td>URL</td><td><mark style="color:red;"><code>https://platform.antares.id:8443/~/antares-cse/antares-id/your-project-name/your-device-name</code></mark><br>or<br><mark style="color:red;"><code>https://platform.antares.id:8443/~/antares-cse/your-device-ID</code></mark><br><br>Note: <mark style="color:red;"><code>your-device-ID</code></mark> must be starting with <mark style="color:red;"><code>CNT</code></mark>. e.g. <mark style="color:red;"><code>CNT-842419289</code></mark></td></tr><tr><td>Method</td><td><code>POST</code></td></tr></tbody></table>

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.

<table data-header-hidden><thead><tr><th width="111"></th><th width="569.3333333333334"></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Value</strong></td></tr><tr><td>URL</td><td><code>https://platform.antares.id:8443/~/antares-cse/antares-id/your-project-name/your-device-name</code><br>or<br><code>https://platform.antares.id:8443/~/antares-cse/your-device-ID</code><br><br>Note: <code>your-device-ID</code> must be starting with <code>CNT</code>. e.g. <code>CNT-842419289</code></td></tr><tr><td>Method</td><td><code>POST</code></td></tr></tbody></table>

**Header**

|              |                                                         |
| ------------ | ------------------------------------------------------- |
| **Key**      | Value                                                   |
| X-M2M-Origin | <mark style="color:red;">`your-access-key`</mark>       |
| Content-Type | <mark style="color:red;">`application/json;ty=4`</mark> |
| Accept       | <mark style="color:red;">`application/json`</mark>      |

**Body**

```json
{
  {
  "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.**
