Street Lighting

Learn how to use IoTIFY network simulator to virtually deploy and manage smart street lighting infrastructure.

Introduction

Traditional street lighting is usually based on a simple principle of operation, where a few luminosity sensors act as switches for nearby light poles, so that lamps are turned on at dusk, when ambient light falls below a certain threshold, and are turned off at dawn. This type of operation is potentially highly inefficient, because in most streets there is no need to have all lamps lighting the underlying area at full brightness all night long. The capability of modern LED equipment to be switched on and off and dimmed repeatedly without increasing the risk of premature failures allows street lamps to be operated dynamically based on the actual need, resulting in increased energy efficiency and reduced maintenance costs.

Smart street lamps can increase and decrease dynamically their brightness based on whether there is someone in their area of lighting; this can be done for example via cameras with integrated movement detection algorithms, or via cheaper equipment such as movement sensors. In addition, if light poles are connected to the internet, they can report their status to a central server and can also be operated remotely, for example to override their default behavior or change their operating parameters.

Smart lighting infrastructure can be simulated with IoTIFY network simulator and can be monitored and operated via online dashboards. In this article, we will explain how to set up IoTIFY network simulator to create virtual light poles that detect movements in their lighting area, adjust their brightness based on detected movements, and can be optionally be configured remotely to keep a fixed brigthness value; also we will explain how to integrate these simulated light poles in the Losant IoT platform.

1. Set up a Losant application

As a first step, we are going to set up a Losant application to control our simulated light poles. After logging in to Losant (a free account can be created at this link), click on the Applications tab in the upper menu and then Create Application; in the following screen, insert a name for your application (for example “Street Lighting”) and then click the Create Application button at the bottom of the screen. Now we need to define devices for this application, so that our simulated light poles can connect and be recognized by the Losant MQTT broker. Since we will create more than one device of the same type, it’s easier to first create a device recipe and then instantiate devices from the recipe. To create a new recipe, click on the Recipes tab in the application home page, then click the Add Recipe button on the top right corner of the page. In the New Device Recipe screen, insert a name for the recipe (for example, “Light Pole”), and select the option “Set my own default names, tags and attributes”:

Click Create Recipe. In the next screen, we are going to define the common properties for all devices that will be created from this recipe: in the DEVICE TYPE section, select Standalone:

Our smart light poles will be sending their physical location, their current operating mode (“automatic” or “manual”), the fixed brigtness value used in case of manual mode operation, and the current brightness value. All this data needs to be modeled in the Losant device type, so that it can be recognized and parsed when messages are received from a light pole: in the DEVICE ATTRIBUTES section, add four attributes, one with data type “GPS string” and the other three with data type “Number”, and give them the names shown in the following screenshot:

The names assigned to the above attributes must correspond to the data sent by simulated light poles, which we are going to configure later when creating our network simulator templates. After saving the newly created recipe, click the Devices entry in the upper menu, then Add Device:

In the New Device screen, select the Light Pole recipe and click Create from Recipe, then in the device creation screen assign a unique name to the device, for example “LightPole001”, and click Save Device:

Repeat the above steps to create more light pole devices; in this example, we will be simulating 3 devices:

Any device, in order to be able to connect to Losant, needs to provide authentication credentials. Detailed instructions on how to create an access key in a Losant application can be found in other articles in this section, such as the article describing a waste management application.

2. Set up a Losant dashboard

We are now going to create a dashboard to be able to visualize graphically data coming from our simulated light poles and to adjust with a few clicks the brightness of a lamp.

From the home page of your Losant account, click the Dashboards item in the top menu, then click Create Dashboard; in the next screen, choose a name for your dashboard, for example “Street Lighting”, then click Create Dashboard at the bottom of the page.

The first item we will add to the dashboard is a map that indicates the physical location of each light pole. To create the map, click Customize in the GPS HISTORY block; in the block definition screen, select the Street Lighting application, select “Last received data point” in the Duration drop-down list, select “DeviceRecipe=Light Pole” in the “Device IDs/Tags” drop-down list, and then select the “location” attribute:

To enhance the user experience of our map, we want additional information to be displayed when we click on a light pole shown in the map: more specifically, we want to see the identifier of the light pole, its location and its current settings; to configure the widget to display this information, write the following text in the Popup Template text box:

{{format deviceName}}
Location ({{format latitude}}, {{format longitude}})
Manual Mode {{format data.manual}}%
Manual Brightness {{format data.manual_light}}%
Current Brightness {{format data.light}}%

Finally, click Add Block to add the map to the dashboard.

Now we will add a widget to display the brightness value of a given lamp. In the dashboard page, click the settings icon at the top right corner and then click Add Block:

Select the INDICATOR block from the list of widgets, then in the next screen choose a meaningful text (for example, “Light Pole 001”) for the block header, select the Street Lighting application, select “Last received data point” in the Duration drop-down list, select the first light pole device in the “Device IDs/Tags” drop-down list, and then select the “light” attribute:

We can show visually the brightness level with different shades of gray by defining a set of conditions that cause the indicator widget to change its appearance; for example, we can set the widget color to black if current brightness of a lamp is less than 20%, gray if it’s between 20% and 80%, and white if it’s more than 80%.

To define the first condition, click Add Condition, then insert the text {{value-0}} < 20 in the Expression text box, insert the text {{value-0}}% (in order to display the exact brightness value in the widget) in the Label text box, and select the black color. Similarly, to define the second condition, click Add Condition, insert the text {{value-0}} < 80 in the Expression text box, insert the text {{value-0}}% in the Label text box, and select a gray color:

For the third condition, we can simply set the default label and color:

Click Add Block to add the widget to the dashbaord. To visualize the brightness value of the other lamps, you can define other indicator widgets in a similar manner.

Finally, we want to be able to control remotely our light poles, for example to override their default behavior and set a fixed brightness value. To do so, we use the input controls widget for the Losant dashboard. For controlling the first light pole, click Add Block, select INPUT CONTROLS, then in the next screen insert a text such as “Light Pole 001” for the block header and select the Street Lighting application. Our simulated poles will have two remotely configurable settings: the operating mode (“automatic” or “manual”) and the fixed brightness value used when in manual mode; for the first setting we will use a toggle widget: in the input control definition screen, click Add Control and then select Toggle Input:

Insert “Manual Mode” in the label text box, then insert “manual” as Template ID; in the Default Value section, select Dynamic Value, select the first light pole device in the “Device IDs / Tags” drop-down list, and select the “manual” attribute:

For setting the fixed brightness value used when in manual mode, we will use a slider widget: click Add Control and select Range Input from the list, then insert “Manual Brightness” in the label text box, insert “manual_light” as Template ID, put 0 and 100 as minimum and maximum values, respectively, and put 1 as step value; in the Default Value section, select Dynamic Value, select the first light pole device in the “Device IDs / Tags” drop-down list, and select the “manual_light” attribute:

Finally, we need a button to trigger a command to be sent to our light poles to configure its settings according to the status of the above widgets: click Add Control and select Button Trigger from the list; enter a descriptive text (e.g. “Configure”) for the button label, select the “Send Device Command” option, select the first light pole device, insert “configure” as command name, and insert the following text in the payload text box:

{
"manual": {{manual}},
"manual_light": {{manual_light}}
}

In the above text, the strings inside double braces must correspond to the template IDs configured for the previous widgets.

Click Add Block to add this set of widgets to the dashboard. We can repeat the same procedure to add widgets to control the other light poles. To control all light poles at the same time, we can add a new input controls block with the same set of widgets and with the same settings, except that the button must be configured to send the command to all poles by selecting “DeviceRecipe=Light Pole” in the “Device IDS / Tags” drop-down list.

3. Create IoTIFY network simulator templates

Now we are going to define the templates in the network simulator to be able to simulate a set of light poles. Since each device has its own identifier, we will need to create a template for each device.

Go to IoTIFY network simulator, select the Templates tab, and click on Create a new Template; in the template definition screen, give a name to the template (for example, “lightpole001”) and select MQTT as network connection type; in the MQTT parameters section, select “mqtt (TCP)” as protocol, insert “broker.losant.com” as endpoint URL, and the device ID of the first Losant light pole device in the ClientID text field (the ID of a device in the Losant application can be retrieved by clicking on the Devices menu and then on View all Devices); in the credentials section, insert the username and password corresponding to your access key (for more information on Losant access keys, check out other articles in this section, such as the article describing a waste management application); in the message contents section, insert a topic with the format “losant/<device-id>/state”, then enable the JSON checkbox and insert the following text in the message text box:

{
"time" : { "$date" : "{{moment.now()}}" },
"data" : {
"location": "48.1353, 11.5819",
"manual": "{{last.data ? last.data.manual : false}}",
"manual_light": "{{last.data ? last.data.manual_light : 0}}",
"light": "{{(last.data ? last.data.manual : false) ? last.data.manual_light : (chance.bool({likelihood: 30}) ? 100 : 20)}}"
}
}

The above template contains all the data sent by our smart light poles at each message: the “location” attribute has a fixed value and contains the GPS coordinates of the pole, the “manual” attribute has a boolean value indicating whether the lamp is operating in manual mode (default value: false), the “manual_light” attribute contains the fixed brightness value (expressed in percentage points) used when the lamp is in manual mode (default value: 0), and finally the “light” attribute indicates the current brightness of the lamp. The value of the “light” attribute simulates the behavior of our smart light poles: if the operating mode is manual, then the brightness is fixed, otherwise the brightness values is set to either 20% or 100% depending on whether some movement has been detected by a virtual movement sensor in the lighting area of the pole; to simulate a dynamic scenario, we use the chance.bool() function, with a 30% probability of a true return value, so in our simulated street there will be some movement for 30% of the time.

To make our light pole able to receive and act upon commands sent via the Losant dashboard, enable the Subscription checkbox in the network simulator template, and insert the following text in the handler function text box:

{
var cmd = JSON.parse(message);
if (cmd.name == 'configure') {
last.data.manual = cmd.payload.manual;
last.data.manual_light = cmd.payload.manual_light;
}
}

The body of the above function should be self-explanatory: when the device receives a command with name “configure”, it updates its settings with those contained in the command payload; make sure that the command name and payload attributes in the handler function correspond to the settings of the input controls blocks in the Losant dashboard.

Save your template and you are ready to simulate your first light pole; if you want to simulate other light poles, create additional templates like the one above, using the other device IDs and changing the value of the “location” attribute in the MQTT message contents so that the different poles are located near each other (in this example we are using “48.1356, 11.5823” and “48.1359, 11.5820” for the location of the two remaining poles).

4. Simulate a smart street lighting system

Now, everything is set up to simulate our street lighting system.
To start simulating a light pole, click the Simulate tab in IoTIFY network simulator, choose the relevant template, insert 1 as number of clients, and click the Start button. Repeat this procedure with the other templates to start simulating the other light poles.

While the simulations are running, go to the Losant dashboard and you will see the different light poles located in the map, and for each lamp the corresponding indicator will show the current brightness level:

Clicking on a light pole in the map will show a popup widget with all the operating parameters of the pole:

To change the brightness value of a lamp, click the unlock widget on the toolbar of the corresponding input controls block, toggle the Manual Mode switch, set the Manual Brightness slider to the desired level, and click Configure:

When the next message from the light pole will arrive, the dashboard will be updated to reflect the new state of the lamp:

We can change the state of all lamps at the same time by operating the corresponding input controls block: for example, we can set all lamps at a 50% brightness level:

With simple Javascript code you can adapt the network simulator template to your needs, changing the parameters of the smart light pole algorithm or creating other algorithms.