Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To develop a client application in Javascript, you must previously have the following JS files in the application directory:

You can find these Javascript here: https://github.com/onesaitplatform/onesait-cloud-platform-clientlibraries/tree/master/javascript-client/js

Example

The images shown in the tutorial use an additional file called JsonEditor.js to show the response more esthetically, but it is not strictly needed.

...

var config = {};

  • config['url'] = "http://wwwlab.onesaitplatform.onlinecom/iot-broker/message";

  • config['deviceTemplate'] = 'Ticketing App'; (Must be the same as the template you defined in IoTClient)

  • config['token'] = 'e7ef0742d09d4de5a3687f0cfdf7f626'; (deviceTemplate token)

  • config['device'] = 'Web'; (Name you will give to the device)

...

Once this step is done, you can invoke all the methods that are implemented in the OPClient object:

  • Join

  • Query

  • Insert

  • Update

  • UpdateById

  • Remove

  • RemoveById

  • Subscriptions

JOIN

The Join operation will be the first action to be made, because it allows you to connect to the defined IoTClient. If everything is OK, it will return the sessionKey, identifying the current session.

...

QUERY

The Query operation allows to get the data that were stored and associated to a given ontology. You must specify the ontology associated to the IoTClient/deviceTemplate in the ControlPanel.

Both Native and SQL queries are accepted. You can also perform SQL queries including SELECT/UPDATE/DELETE.

...

Native

...

SQL

...

Image RemovedImage Added


TO-DO (EXAMPLE UPDATE/DELETE)

INSERT

The Insert operation allows you to insert new data into the ontology, make sure the data has the structure defined in the ontology JSON Schema, otherwise it won't pass Schema validation. To ensure that the format is correct, the best choice is copying it directly from the Ontology Schema. It returns the inserted instance's id.

...

This operation will return the ID (or IDs in case data it's an array), which you can use later to perform operations 'by id'.

UPDATE

To update an existing instance, you can either update the whole instance or update selected fields.

...


For the second case, you may use 'update' function. This function only accepts Native queries. If you want to make SQL Updates, make use of the query function.

...

DELETE

If you want to delete a single instance, you may use 'removeById'.

...

on the other hand, if you want to delete all instances matching a particular filter, use 'remove' function. This function, as the update one, only accepts native queries.

...

SUBSCRIPTIONS

This API allows you to subscribe to an Ontology. When subscribed, any insert/update related to the subscribed ontology, will notify your client, resulting in an execution of your callback function passed to handle subscription notifications.

...

If you click in the example on 'subscribe', and then perform and insertion, if you go back to the subscribe tab, you will se that you received the instance you just inserted.

...

Full Example

...