About this blog post

In this post we describe how to install and use a simple bus monitoring application that combines the capabilities of Eurotech’s Everyware platform with some of scriptr.io’s features. The application mainly consists of a dashboard that displays real-time metrics sent by Eurotech PCN devices installed on a bus, and their historical values. For the sake of simplicity, we will replace the physical devices with virtual devices defined using a simulator provided by Eurotech.

You can watch the video on Youtube

The bus monitoring application

Bus metrics are published by the PCN device (or the simulator) to the Everyware platform via mqtt. There are two categories of metrics:

  • Location and speed data, published while the bus is “moving”
  • Bus load data (passengers getting off, getting on, current number of passengers), published while the bus is “stationary”

The application – running on scriptr.io creates an mqtt subscription to the Everyware platform and automatically receives any value that is published to it, in real-time. Received values are persisted in scriptr.io’s data store and published to the dashboard.

Figure 1 – logical blocs of the application

Figure 2 – dashboard sample

Pre-requisites
You need an Everyware account (sandbox or production).

Creating the devices in Everyware

We will use Eurotech’s simulator to create a device in our Everyware account. Sign in to the simulator using your Everyware credentials, then fill the “create device” form by entering an – mqtt – client id and a display name for the device (note that “start terminal” and “end terminal” fields are optional and can be left blank).

Create a scriptr.io account and deploy the application

Open a browser tab and open the scriptr.io registration page,  and type the following in the address field: https://www.scriptr.io/register?promocode=eurotech.
Fill the registration form (or sign up using your Facebook, Twitter or Github credentials). Once you are through the registration process, sign in to your newly created scriptr.io account. You will notice that the application has automatically been deployed.

Configure the application

From your scriptr.io Workspace, open the /installer/config script from the tree view on the left side of the screen, and bring the following changes to it:

  • Set the value of eurotechAccount to the name of your Everyware account
  • Set the value of deviceId to the client id you specified when creating the device (see above)
  • Set the value of username in endpointConfig to a valid Everyware username
  • Set the value of password in endpointConfig to the password matching the username

You do not need to modify anything else for now, as default values will be applied. Once you are done customizing the /installer/config file:

  • Save your changes by clicking Save on the toolbar,
  • Open the /installer/install script and run it by clicking Run on the toolbar.

Check the output of the console (at the bottom of the Workspace). It should mention that installation was successful. If this is not the case, please check the error messages and see if this is something you can fix. Otherwise, do not hesitate to send a message to support@scriptr.io or to create a support ticket from the Workspace (click Resources from the menu bar, then click Support).

Running the application

Sign in to the simulator and select the device you previously created.

Configure the simulator

You need to enter some data for the simulator. Best option is to copy/paste the below values:

27.986519,-82.733574,pcn
27.961201,-82.762928
27.938304,-82.746792
27.938304,-82.750397,pcn,paxin=2,paxout=1
27.938304,-82.75692
27.938304,-82.762585
27.943612,-82.763271,pcn,paxin=1,paxout=2
27.948919,-82.7631
27.954378,-82.762756
27.959837,-82.762413,pcn
27.96393,-82.762756
27.967418,-82.7631
27.972269,-82.763443,pcn
27.977878,-82.763443
27.984852,-82.763443,pcn
27.991825,-82.763443,pcn
27.997433,-82.763443
28.001374,-82.762928,pcn,paxin=5,paxout=1
28.004708,-82.762756
28.008194,-82.762585
28.01168,-82.762756,pcn
28.013347,-82.759151
28.016681,-82.75898,pcn
28.019712,-82.75898
28.019257,-82.754345,pcn
28.019105,-82.750053
28.015771,-82.747135
28.012437,-82.746277,pcn
28.009406,-82.744217
28.006072,-82.742157,pcn
28.001525,-82.742157
27.996372,-82.742157
27.991218,-82.742157,pcn
27.989854,-82.747307
27.989399,-82.752113,pcn
27.989551,-82.75486
27.992886,-82.755032,pcn
27.994098,-82.751083,pcn

If you wish, you can also configure the frequency at which messages will be published to Everyware, as well as the max number of passenger, etc. Once ready, click on Start sending messages.

Open the dashboard in the browser

Once data starts being generated, it automatically flows into your scriptr.io account and is reflected in real-time in the dashboard. To open the dashboard, go back to your scriptr.io Workspace:

  • From the tree view, expand the code tree on your left and open the /eurotech_simpleapp/view/dashboard script
  • Click View in the toolbar to open the dashboard in the browser.

About the code

If you are interested, you can check the explanations given in this short document and you also can read the comments in the code itself.

If you wish to start implementing your own IoT applications using scriptr.io, we suggest that you go through this list of short tutorials that will ramp you up in no time.

You can watch the video on Youtube