Completed lessons information

Lets do it!

Lessons links


Introduce and how to connect external JS script

Introduce & Wialon based feature - ext JS script

Hi everyone! First I would like to introduce my self. My name is Diana, I'm working at Development Department on Gurtam, my position is quite especial, I'm Wialon Hosting Expert. Yes, the main is expert.

As I expert I know something about Wialon programming, and moreover I'm passing this way by myself, as pilgrim.That is why I had idea to create such virtual lessons.I will try to tell you and explain more about Wialon API.

Ok, let start! And first lesson which I would like to represent you is about external JS link, to be more accurate, connection exteranl JS link on monitoring site.

There is Wialon feature which allows to connect some external JS link on login page or inside site. It's the same as some JS to HTML page via tag script.

So it's not possible to use internal Wialon elements (data), we can only use JS link as some additional visual information, like banners, pop-up, some external chats like JIVO.

Today I will tell you how to add banner with some info, for example of your company. It will be example for JS code which you can write, and then describe all next steps and final result.

First let look the example of our banner

Next the final result how this banner will look on login page.

The idea is clear, let go to write code.

As JS script is placed on head of HTML document, the browser will try to execute it first before HTML page is loaded. In case Wialon for example login page is loading. So we need to use self-invoking function to execute JS after full HTML page has been loaded.

Syntax:

(function () { 
          // function code
 }());

Token login

First we need to login into system before starting work with Wialon API

We will receive token via authorization form http://hosting.wialon.com/login.html

Get online current ignition state

Try to cathce events updates within example of Ingtion state (Off / On)

To control online current ignition state it can be used request events/check_updates

1. First (after login) it needs to add required units to session via request svc=events/update_units

              https://hst-api.wialon.com/wialon/ajax.html?svc=events/update_units¶ms={"mode":"add","units":[{"id":21080147,"detect":{"ignition":0}}]}&sid=02abb0c22bb8a9cc5df633a630bcbbfb

            

"units" - units array where 'id' - unit's id, 'detect' - required events types, in our case only "ignition":0;
0 means all ignition sensors, if you know that unit has only 1 ignition sensor, you can set up '0'.
If there is several ignition sensors it's better to set up sensor's id. But sure it depends on appropriate business task.

2. After required units has been added to session, we can monitor online ignition state via request events/check_updates which can be executed for example every 2 sec or rarely , it depends on how often the device sends data to the server

            //"detalization":3  means that server will return  JSON information for flags plus
            https://hst-api.wialon.com/wialon/ajax.html?svc=events/check_updates¶ms={"detalization":3}&sid=02abb0c22bb8a9cc5df633a630bcbbfb
          

First response

             {
  "21080147": [
    {
      "ignition": {
        "1": {
          "from": {
            "t": 1590045850,
            "y": 43.79845047,
            "x": -99.7432632446
          },
          "to": {
            "t": 1590046021,
            "y": 43.79845047,
            "x": -99.7432632446
          },
          "m": 1590046021,
          "f": 0,
          "state": 0,
          "type": 1,
          "hours": 175782,
          "switches": 2,
          "value": 0
        }
      }
    }
  ]
}
            

21 May 2020 07:24:10 - 21 May 2020 07:27:01 = time from / to
"state":0 - ignition is Off.
So during 2 min 51 sec ignition has being Off

Next request svc=events/check_updates
Response
{} - empty answer means nothing changes as there is not yet new messages coming

new message with time 05-21-2020 07:33:36 coming, due to several second event has been recalculated