conwetlab / ngsijs Goto Github PK
View Code? Open in Web Editor NEWJavaScript library for the FIWARE Context Broker services (web browsers & Node.js)
JavaScript library for the FIWARE Context Broker services (web browsers & Node.js)
Found using the batchUpdate
method, although it happens also using other POST
methods. The reported error was {"error":"ParseError","description":"Errors found in incoming JSON buffer"}
Currently, tests are only executed on firefox/chrome (using Karma and Travis CI). Those test should be also executed using node.
Dear Developers,
I've already wrote you about a problem with "getEntityAttribute". Thank you very much for fixing this. However now I faced new difficulty with following method:
"batchQuery"
The problem is something is wrong with connection and request processing, the curl:
curl -s -H "Content-Type: application/json" -X POST -d '{"bodyParams": {"options": {}}}' http://localhost:3000/accessfunctionality/orion/batchQuery
Error:
{"status":"error","message":"Unexpected error code: 400"}
NGSI.Connection:
batchQuery(connection, params){
return new Promise(function(resolve, reject){
console.log('NGSI function call: batchQuery');
connection.v2.batchQuery(params.options).then(
(response) => {
resolve(response);
}, (error) => {
reject(error);
}
);
});
}
Tried some testing:
batchQuery(connection, params){ return new Promise(function(resolve, reject){ console.log('NGSI function call: batchQuery'); console.log(params); connection.v2.batchQuery(params.options).then( (response) => { console.log("correct"); resolve(response); }, (error) => { console.log("error error error error"); reject(error); } ); }); }
Result:
controller: AccessFunctionality NGSI connection NGSI function call: batchQuery { options: {} } error error error error POST /accessfunctionality/orion/batchQuery 200 155.687 ms - 57 Executing (default): INSERT INTO "Performances" ("id","component","name","service","executionTime","status","errorMessage","createdAt") VALUES (DEFAULT,'Enabler','orion','batchQuery',76.60613,'Error','Unexpected error code: 400','2017-11-13 15:54:20.210 +00:00') RETURNING *; Executing (default): INSERT INTO "Performances" ("id","component","service","executionTime","status","createdAt") VALUES (DEFAULT,'Enablers Framework','/accessfunctionality/orion/batchQuery',158.707139,'Success','2017-11-13 15:54:20.214 +00:00') RETURNING *;
When testing without parameters:
` batchQuery(connection, params){
return new Promise(function(resolve, reject){
console.log('NGSI function call: batchQuery');
connection.v2.batchQuery().then(
(response) => {
resolve(response);
}, (error) => {
reject(error);
}
);
});
}`
Throws an error (as also stated in documentation: "query is empty" - this part is working well according docs):
{"status":"error","message":"missing query parameter"}
I will be grateful, if you could help me, and point what is wrong. Thank you in advance!
N.B.
"batchUpdate" works well, I already tested it, but has an additional parameter "changes". And entities to be updated can be delivered inside this parameter.
Currently, the ngsijs library uses a contextValue
attribute for providing new values when using the updateAttributes
and the addAttributes
methods. The name of this attribute comes from the name of the XML element used in the initial payloads. On the current JSON payload, this attributes is called value
, so seems more natural to use this name instead of contextValue
. Anyway, we have to continue supporting the use of the contextValue
attribute for allowing a soft migration.
When using the node-js client with Orion, I get the following:
time=2016-05-11T11:36:53.780UTC | lvl=WARNING | corr=a8d4baac-176c-11e6-9e73-029d61bc569f | trans=1462965567-845-00000000086 | srv= | subsrv= | from=127.0.0.1 | function=badInputReset | comp=Orion | msg=AlarmManager.caising alarm BadInput 127.0.0.1: no valid 'Accept-format' found
This is caused by the fact the Accept format is set to applicaiton/xml, which is not supported by Orion
NGSIv2 RC-2018.04 added the following registration management operations:
GET /v2/registrations
POST /v2/registrations
GET /v2/registrations/{id}
PATCH /v2/registrations/{id}
DELETE /v2/registrations/{id}
Add NGSIv2 support (RC-2016.10):
Entities:
Types:
Subscriptions:
Batch Operations:
Sometimes, the requestFunction can provide a better error description than the NGSI.js library. E.g. when using this NGSI library from WireCloud, some errors come from the WireCloud proxy.
in ngsi_build_update_context_request:
if (contextValue.trim() === '') { attributeElement.valuecontextValue = 'emptycontent'; }
should be
if (contextValue.trim() === '') { contextValue = 'emptycontent'; }
No tests failing?
<script type="text/javascript">
$(document).ready(function() {
console.log('Ready disparado');
window.connection = new NGSI.Connection("http://ip_address:1026");
console.log(connection);
connection.v2.listEntities().then((result) => {
response.results.forEach((entity) => {
console.log(entity.id);
});
});
});
</script>
Uncaught TypeError: this.makeRequest is not a function
at NGSIConnection.makeJSONRequest2 (NGSI.js:206)
at V2.listEntities (NGSI.js:2604)
at HTMLDocument.<anonymous> (index.html:15)
at j (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
at HTMLDocument.I (jquery.min.js:2)
Hi all !
I have an error during execute the command npm run start.
I'm using npm v1.1.4, nodejs v.0.6.12 on Ubuntu v.12.04
See the full error in the following link: http://pastebin.com/2Btp2zKx
Thanks in advance!
I'm strongly opting for including a function for retrieving tokens from the public ORION implementation, since the tokens are only valid for one hour.
status code is not provided when InvalidResponseError is obtained
Lines 1687 to 1691 in 59ce53e
InvalidResponseError could happens for example when PEP responses 401
Not sure if is really a bug or maybe just something that could be improved.
Others errors like InvalidRequestError are providing status code:
Lines 1624 to 1629 in 59ce53e
According to documentation at http://conwetlab.github.io/ngsijs/stable/NGSI.Connection.html#.%22v2.listEntities%22__anchor, the supported options are:
attrs (String): Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order.
correlator (String): Transaction id
count (Boolean; default: false): Request total count
id (String): A comma-separated list of entity ids to retrieve. Incompatible with the idPattern option.
idPattern (String): A correctly formated regular expression. Retrieve entities whose ID matches the regular expression. Incompatible with the id option
limit (Number; default: 20): This option allow you to specify the maximum number of entities you want to receive from the server
offset (Number; default: 0): Allows you to skip a given number of elements at the beginning
metadata (String): A comma-separated list of metadata names to include in the response
mq (String): A query expression for attribute metadata, composed of a list of statements separated by semicolons (;)
orderBy (String): Criteria for ordering results
q (String): A query expression, composed of a list of statements separated by semicolons (;)
service (String): Service/tenant to use in this operation
servicepath (String): Service path to use in this operation
type (String): A comma-separated list of entity types to retrieve. Incompatible with the typePattern option.
typePattern (String): A correctly formated regular expression. Retrieve entities whose type matches the regular expression. Incompatible with the type option.
unique (Boolean): Represent entities as an array of non-repeated attribute values.
values (Boolean): Represent entities as an array of attribute values
However, what about geometry, georel and coords? They aren't in the list and are needed to get advantages of one of the most important features of Orion Context Broker: geo queries.
Is this a gap in the current implementation of the library? Or a gap in the documentation?
Thanks!
Allow to retrieve details about the context broker server by using the /version
endpoint.
Dear Developers,
when implementing connection class https://conwetlab.github.io/ngsijs/stable/NGSI.Connection.html faced with some difficulties, namely by implementing following methods in NGSIv2:
getEntityAttribute
Properties "attribute" and "id" are not marked as required, while they are. By sending the following curl:
curl -s -H "Content-Type: application/json" -X POST -d '{"bodyParams": {"options": {"attribute": "brightness", "id": "LED002", "type": "LED"}}}' http://localhost:3000/accessfunctionality/orion/getEntityAttribute
Get an error:
{"status":"error","message":"Cannot create property 'search' on string 'http://xxxxxxxx/v2/entities/LED002/attrs/brightness'"}
NGSI.Connection:
getEntityAttribute(connection, params){
return new Promise(function(resolve, reject){
console.log('NGSI function call: getEntityAttribute');
connection.v2.getEntityAttribute(params.options).then(
(response) => {
resolve(response);
}, (error) => {
reject(error);
}
);
});
}
The same difficulties I faced with some other methods:
replaceEntityAttributeValue
replaceEntityAttribute
deleteEntityAttribute
getEntityAttribute
Some testing:
getEntityAttribute(connection, params){
return new Promise(function(resolve, reject){
console.log('NGSI function call: getEntityAttribute');
console.log(params);
connection.v2.getEntityAttribute(params.options).then(
(response) => {
console.log("correct");
resolve(response);
}, (error) => {
console.log("error");
reject(error);
}
);
});
}
Result:
-> controller: AccessFunctionality NGSI connection NGSI function call: getEntityAttribute { options: { attribute: 'brightness', id: 'LED002', type: 'LED' } } POST /accessfunctionality/orion/getEntityAttribute 200 115.451 ms - 138 Executing (default): INSERT INTO "Performances" ("id","component","name","service","executionTime","status","errorMessage","createdAt") VALUES (DEFAULT,'Enabler','orion','getEntityAttribute',4.087831,'Error','Cannot create property ''search'' on string ''http://xxxxxxxx/v2/entities/LED002/attrs/brightness''','2017-11-07 16:37:06.750 +00:00') RETURNING *; Executing (default): INSERT INTO "Performances" ("id","component","service","executionTime","status","createdAt") VALUES (DEFAULT,'Enablers Framework','/accessfunctionality/orion/getEntityAttribute',118.999163,'Success','2017-11-07 16:37:06.755 +00:00') RETURNING *;
I will really appreciate, if you could help me. Thank you in advance!
Use Travis to pass karma tests instead of using jenkins.
Create a bower.json
file and publish this library on bower.
Add the required code for supporting NGSI-LD
hello, i am new to fiware and wanted to ask which library i should use to communicate with the context broker.
According to the documentation fiware refers to the ngsi-parser and ocb-sender (https://ngsi-js-library.readthedocs.io/en/latest/).
but these libraries were last updated 3-4 years ago.
this library (ngsijs) I see is still relatively up to date.
so my question: should i use ngsijs or the other one?
thanks in advance!
I want to use this library for backend, nodejs.
The createSubscription
method only pass the e
argument to the onFailure
callback if you don't use a ngsi-proxy or if the error comes from the proxy.
Make the needed modifications into Gruntfile.js
to provide a minimized version of the library (including a source map file).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.