Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Introduction

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.

...

Next, you need to create an object where you will store the config parameters (In this case, those of the selected example):

var config = {};

  • config['url'] = "http://

    www

    lab.onesaitplatform.

    online

    com/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)

This variable will be passed as a parameter to the previously defined client object using the configure() method:

...

Lastly, you must connect with the platform using the connect method:

client.connect();Image Removed

...

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.

Image Removed

Image Removed

...

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.Image Removed

...

Image Removed

NativeImage Removed

...

SQLImage Removed

...

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.Image Removed

...

Image Removed

It's important to note that you can pass to the function an array of Ontology instances as data, for example:Image Removed

...

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.

In the first case you may want to use 'updateById'. It works similar to insert function.

Image Removed

Image Removed

...


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.

Image Removed

Image Removed

Image Removed

...

DELETE

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

Image Removed

Image Removed

Image Removed

...

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.

Image Removed

Image Removed

...

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.

...

Take a look at the subscribe function:Image Removed

...

The first callback function will return as response the message with the subscription ID associated.

The second callback function will be executed each time a subscription notification/message arrives.Image Removed

...

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.

Image Removed

...