Details
-
Type: Monitor
-
Status: Closed
-
Priority: Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: FIWARE-TECH-HELP
-
Labels:
Description
Created question in FIWARE Q/A platform on 26-03-2023 at 17:03
Please, ANSWER this question AT https://stackoverflow.com/questions/75849244/fail-subscription-to-orion-change-contest-from-node-server
Question:
Fail subscription to Orion change contest from Node Server
Description:
I am developing a simple project in which I made a list of entities that I put on Orion-LD. Now I would like to make a server that allows to receive notifications whenever the state of an entity attribute changes. i chose to use Node.JS Express for ease but it is not mandatory.
I am leaving here the simple code used to implement my server.
const express = require('express');
const request = require('request');
const app = express();
const PORT = 3000;
//Subscription on batteryLevel changes of device 9845A
app.get('/subscribe', (req, res) => {
const data = {
"description": "Subscription",
"subject": {
"entities": [
],
"condition":
},
"notification": {
"http": {
"url": `http://localhost:$
},
"attrsFormat" : "keyValues"
}
};
const options = {
headers: { 'Content-Type': 'application/json', },
json: data
};
request.post('http://localhost:1026/v2/subscriptions', options, (error, response, request) => { console.log(response.body); res.end("Succesfully subscribed!"); });
});
// Listen on notification
app.post('/notification', (req, res) => {
console.log('Notification received:', req.body);
res.sendStatus(200);
});
app.listen(PORT, () => {
console.log(`Example app listening on port ${PORT}
`)
});
The problem is that if I subscribe to an existing entity properly, it reports a "status": "failed" in the subscription and therefore I cannot receive notifications about the status. Reading the Orion LD logs, it seems that it can't communicate with my server at port 3000, but I can't figure out why. Can anyone help me with this?
2023-03-27 05:31|CREATED monitor | # answers= 0, accepted answer= False