Vous êtes sur la page 1sur 40

Table of Contents

Introduction to the Echelon IzoT Platform Hands on Lab .................................................................... 2


The Echelon IzoT Platform .................................................................................................................. 2
Device Stacks................................................................................................................................... 3
Chips ................................................................................................................................................ 4
Control Services .............................................................................................................................. 4
Example Applications .......................................................................................................................... 5
Lab Configuration .................................................................................................................................... 6
Get Started .............................................................................................................................................. 6
Part I: IzoT Device Stack EX Setup ....................................................................................................... 7
Part II. IzoT Device Stack EX Hands on Lab....................................................................................... 16
Part II-A. Starting the Mulit-DIO Python Application ................................................................... 16
Part II-B. Testing the DIO Python Application with the IzoT Device Browser .............................. 18
Part II-C. Testing Automatic Peer-to-Peer Communication ......................................................... 21
Part II-D Changing the Number of DIOs for Your Application .................................................... 21
Part II-E. Starting the 2-Channel DIO Python Application ............................................................ 22
Part II-F. Testing the Multi DIO Python Application ..................................................................... 23
Part II-G. Testing Manual Peer-to-Peer Communication ............................................................. 23
Part II-H. Adding a new Output Datapoint ................................................................................... 24
Part II-I. Testing the Multi DIO with Analog Output Application ................................................. 25
Part III. IzoT Server Stack Setup ....................................................................................................... 26
Part IV. IzoT Server Hands on Lab .................................................................................................... 31
Part IV-A. Determine the Datapoint IDs for your Pi Using the IzoT Device Browser ................... 31
Part IV-B. Check Your Lab Web Page ........................................................................................... 32
Part IV-C. Change the Lab Web Page Datapoint IDs .................................................................... 33
Part IV-D. Test the Web Page ....................................................................................................... 37
Part IV-E. Add a Second Clickable LED to the Web Page ............................................................. 38
Part IV-F. Periodically Get Datapoint Values with a Refresh Timer ............................................. 38
Part IV-G. Add a Feedback Delay.................................................................................................. 39
Part IV-H. Improve Performance With an HTML Timestamp Filter ............................................. 39

Copyright 2014 Echelon Corporation. All Rights Reserved.


1

Introduction to the Echelon IzoT Platform Hands on Lab


Using a step by step instruction methodology, this Hands-on Lab will provide you the basic skills
necessary to create and monitor an IzoT based control network. After completing this lab, you will
be able to:

Develop an IzoT-enabled device that communicates autonomously with other IzoT-enabled


devices
Create a network of IzoT-enabled devices
Create Web pages to monitor and control a network of IzoT-enabled devices

This manual contains instructions for two independent yet related labs; the IzoT Device Stack EX lab,
which allows you to create communities of autonomous devices that can interact without requiring
servers, routers, or head-end applications, and the IzoT Server lab for developing Web pages to
control and monitor your communities of devices. Both labs have been designed for expediency and
completion within a 60 minute session.

The Echelon IzoT Platform


Echelons IzoT Platform is an IP-enabled, multi-protocol, multi-media control and communications
platform specifically architected for the Industrial Internet of Things (IIoT). Comprised of a family of
chips, stacks, interfaces and management software, the IzoT Platform enables the development of
devices, peer-to-peer device communities, and applications for the IIoT. Unlike consumer-grade
platforms, the IzoT Platform comprehensively addresses the unique requirements of the IIoT:
autonomous control, industrial-strength reliability, legacy co-existence and evolution, and hardened
security.
Echelon provides three types of products for the IzoT Platform:
1. Chips, software stacks, and modules for developing IzoT-enabled devices that communicate
with the LonTalk/IP protocol. Options are provided for both wired and wireless
connectivity, providing the flexibility for each application to choose the best media or
combination of media.
2. Routers for interconnecting different IP links, and for serving Web pages and interfacing to
Web applications.
3. Cloud software for providing remote management, monitoring, and control of IzoT-enabled
devices from any location; for archiving data collected from those devices; and for analyzing
the collected data.

Device Stacks
The core of the IzoT Platform consists of the device stacks. The device stacks implement the
LonTalk/IP protocol that provides control services on top of IP. These IzoT Control Services enable
devices to discover each other and to easily and reliably exchange data.
There are three device stacks:

The full-featured EX stack


A smaller DX stack for memory-constrained devices
An optimized AX stack for the Series 6000 chips.

The EX stack is available as a free download from Echelon, and is also available in a paid Premium
Edition with enhanced functionality and including one-year of support. Using this stack, you can
develop IzoT-enabled applications in Python, C++, or C. Full source code for the stack is included in
both the free download and in the Premium Edition. A reference implementation is included that
runs on a Raspberry Pi, BeagleBone Black, or other ARM processors running Linux. You can also port
the stack to other 32-bit or 64-bit processors and operating systems. The stack includes a set of
example applications with full source code, schematics, and I/O board layouts for the Raspberry Pi
that provides the user with enough elements for a quick start trying the stack. The following figure
illustrates the components of the IzoT Device Stack EX.

Chips
You can use the EX or DX stack with the processor of your choice, or you can use one of Echelons
new Series 6000 chips for creating a low-cost IzoT-enabled device. To reduce installation cost, there
are versions of the Series 6000 chips that use a free topology twisted pair link. Free topology uses
simple twisted pair cable with multi-drop wiring that is easier and less expensive to install than
Ethernet cable. The Series 6000 chips all include four processor cores, with two dedicated to the
LonTalk/IP Protocol. They also include on-board memory and I/O to reduce device cost. The FT
6050 and FT 6010 add a free topology twisted pair transceiver. The Series 6000 chips are provided in
a compact 7mm by 7mm QFN package so you can build very small devices. The following figure
illustrates the architecture of the FT 6050 and FT 6010 chips.

Control Services
All three device stacks provide a common set of control services on top of IP called the IzoT Control
Services. These services enable devices to communicate with datapoints. The following figure
illustrates how a sending device uses datapoints to reliably exchange datapoints with multiple
receiving devices using peer-to-peer communication. When notification is required of datapoint
update delivery, the sending device can request acknowledgements from each of the destination
devices, and the device stack automatically manages retries to any devices that do not acknowledge
receipt.

A messaging interface is also provided for exchanging larger payloads of data. An IzoT application
can implement up to 4096 datapoints, providing support for complex control devices. The IzoT
Control Services support up to 32,385 devices in a community. Devices may be organized into
groups providing a way to control a large number of devices with a single network update. The IzoT
Control Services also provide services for reliable message delivery with acknowledged and
request/response services, with thousands of transactions per device active at the same time when
using the EX stack.

Example Applications
The IzoT SDK includes an example application that demonstrates how the SDK can be used with
Raspberry Pi devices to create a lighting system with color control. The example demonstrates both
peer-to-peer control as well as Web-based monitoring and control.
There are five example device applications:
1. An Environmental Sensor that measures and reports temperature, humidity, occupancy, and
light level.
2. A 2.5 touch screen keypad that can be used to control the lighting.
3. An LED Controller that controls up to two 3W RGB LEDs.
4. A digital I/O (DIO) application that can be built for one to seven channels that demonstrates
simple digital input and digital output. This example is used for the Hands-on Lab.
The examples support multiple instances of each device type, so you can have multiple
Environmental Sensors, Keypads, and DIOs controlling multiple LEDs. The following figure illustrates
three of the example device applications and Web pages included with the IzoT SDK.

The Web pages are all implemented using HTML5 and Javascript. They are compatible with all major
browsers, and are also optimized when displayed on an iPad.
The example includes source code for the device applications, schematics, and layouts for the I/O
hardware, and HTML5 and JavaScript code for the Web pages.

Lab Configuration
The DX and EX versions of the IzoT Device Stack, and the IzoT Server Stack are provided as source
code stacks so that you can port them to your choice of processor and operating system. In this lab
you will use the IzoT Device Stack EX running on a Raspberry Pi with Raspbian Linux, and you will
share a server running the IzoT Server Stack on a BeagleBone Black. If you are participating in a
scheduled lab session, each of you has a Raspberry Pi that has been pre-loaded with Raspbian Linux
and the IzoT Device Stack EX. In addition, a PiFace Digital I/O Board has been installed into each of
your Pis. This board has 8 digital inputs and 8 digital outputs. Four pushbuttons are provided that
control four of the digital inputs. Eight LEDs indicate the state of the eight digital outputs, and two
of the digital outputs are also connected to two relays. Our lab examples use the pushbuttons and
the relay outputs.
If you are doing this lab on your own, you will need to provide your own Raspberry Pi devices with
PiFace Digital I/O Boards, and one BeagleBone Black server. Set up your Pi devices as described in
Part I, and your BeagleBone Black server as described in Part III.

Get Started
The labs are organized into the following four parts.

Part IDownloading the IzoT SDK and installing it on a Raspberry Pi. The IzoT SDK includes
both the IzoT Device Stack EX and the IzoT Server Stack. It can be ported to many different
platforms, but the Raspberry Pi is a very low-cost ($35) and easy to set up platform for the
6

IzoT SDK. If you are attending an IzoT Hands-on-Lab, Part I has been completed for you prior
to the start of the lab. The instructions are included here so that you can set up your own
Raspberry Pis with the IzoT SDK at home or in your office.
Part IICreating an IzoT device, followed by creating a community of devices, using the IzoT
Device Stack EX on a Raspberry Pi. This is the hands-on portion of the IzoT Device Stack EX
Hands-on Lab. You can also follow these steps with Raspberry Pi devices that you have set
up yourself following Part I.
Part IIIDownloading the IzoT SDK and installing it on a BeagleBone Black. The BeagleBone
Black has about twice the performance of a Raspberry Pi, for about $10 more. While you
can run an IzoT Server on a Raspberry Pi, the BeagleBone Black is a better platform for the
IzoT Server because of the higher performance requirements of the server stack. The IzoT
Server includes an implementation of the IzoT Device Stack EX, and also includes a Web
server, a Web application server, a REST server, a LonTalk/IP network server, and a SQL
database. All these components run simultaneously, requiring more processor resources
than a typical IzoT device running just the IzoT Device Stack EX and a device application. If
you are attending an IzoT Hands-on-Lab, Part III has been completed for you prior to the
start of the lab. The instructions are included here so that you can set up your own
BeagleBone Blacks with the IzoT SDK at home or in your office.
Part IVCreating Web pages that interact with IzoT Devices using the IzoT REST API
provided by an IzoT Server. This is the hands-on portion of the IzoT Server Stack Hands-on
Lab. You can also follow these steps with a BeagleBone Black that you have set up yourself
following Part III.

Part I: IzoT Device Stack EX Setup


To get started with the IzoT Device Stack EX using a Raspberry Pi, follow these steps:
1. Download software for the Raspberry Pi:
a. Download the IzoT SDK from iiot.echelon.com/get-started.

b. Download the latest version of Raspbian Linux from www.raspberrypi.org/downloads

2. Download and install the following tools (Win32 Disk Imager is for Windows;
see www.raspberrypi.org for instructions for other platforms) :
a. SD Formatter from www.sdcard.org/downloads
b. Win32 Disk Imager from sourceforge.net/projects/win32diskimager/
c. Python 3.3.4 (or newer) from www.python.org/download/
d. PyCharm from www.jetbrains.com/pycharm/download/
3. Create an SD card with Raspbian Linux:
a. Insert 8 GB Samsung Class 10 Micro SD card into SD card adapter, and insert it into a PC
SD card slot.
b. Reformat the SD card with SDFormatter, selecting the options to Expand and do a Full
(Erase) format.

c. Start Win32DiskImager, select the image you downloaded in step 1b, select the SD
device primary partition, and then click Write to write the R-Pi image to the SD card (if
you have any mapped drives you may see an error at startupyou can ignore the error).

4. Start the Raspberry Pi:


a. Insert the SD card with Raspbian Linux in the Raspberry Pi.
b. Connect power to the Raspberry Pi with a Micro USB power cable and a 5V 1A minimum
power supply.
5. Get the IP address for the Raspberry Pi. If you are behind an accessible router, you can get the
IP address from the IP client list maintained by the router. For example, the following figure
shows the client device list for an Asus Wi-Fi router:

6. Start and configure PyCharm:


a. Start PyCharm

a. Click Create New Project. Enter a project name, select any location for your project, and
select Empty Project for the project type.
b. Click the arrow for Python Interpreter. If a Python 3.3.4 (or newer) local Python
interpreter is displayed in the list, click it and skip the next three steps.

10

c. If a Python 3.3.4 (or newer) Python interpreter is not displayed in the list, click the
browse button () to configure a new Python interpreter.

d. To configure a new Python interpreter, click the green + on the top-right of the dialog.
Select Local in the Select Interpreter Path dialog.

e. Browse to and select a Python 3.3 or newer interpreter on your computer. If the last
Python interpreter you installed was a Python 3.3 or newer interpreter, it may be
selected by default. Click OK to select the Python interpreter and close the Select
Python Interpreter dialog, and then click OK to add the new interpreter and close the
Python Interpreters dialog.

11

f.

Set the default encoding for SSH terminal windows to UTF-8: click File -> Settings;
click SSH Terminal; and then set Default Encoding to UTF-8.

7. Open a terminal window for the Pi:


a. Select Tools -> Start SSH Session; Click Edit Credentials; define a new SSH Session with
your host IP address from step 9, port 22, a user name of pi, and password of raspberry.

b. Click OK to ignore the authenticity warning.

8. Run raspi-config at the Linux shell prompt with: sudo raspi-config; in raspi-config, configure the
following:
a. Expand Filesystem
b. Internationalization Options -i. Locale: en_US.UTF-8 UTF-8 (leave en_GB.UTF-8, and make en_US.UTF-8 the
default)
ii. Timezone: US/Pacific-New
12

c. Advanced Options
i. Hostname -- e.g. DIO-51

9. To use a Wi-Fi link, configure WiFi from the command line as follows:
a. Edit the interfaces file with the following command:
sudo nano /etc/network/interfaces

b. Change the content to the following:


auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid "ssid"
wpa-psk "password"

c. Type Ctrl-X, answer "Y" to write the updates, and then press Enter to confirm the
filename.
d. Shutdown by entering the following command: sudo shutdown now.
e. Disconnect the power from the R-Pi.
f. Physically install the Wi-Fi adapter in the R-Pi.
g. Reconnect power to the R-Pi.
h. Find the new IP address of the R-Pi, using the same method as step 9.
i. Reserve a static IP address assignment for your Pi in your router.
j. Reboot, or enter the following commands at the Linux shell prompt to release and
renew the IP address:
sudo dhclient -r
sudo dhclient

13

10. Define a new server in PyCharm:


a. Enter File -> Settings, click SSH Terminal, and then click Configure Servers.
b. Select SFTP for the Type.
c. Enter the IP address for your Pi under SFTP Host.
d. Enter pi for Username and raspberry for Password.
e. Click OK.

11. Open a terminal window with Tools -> Start SSH Session and select the server you just
created. Click Yes at the authenticity prompt. Your new console session opens as a tab in the
Terminal pane. Enter the following commands:
a. Verify that the date and time are correct with the date command. Correct them if they
are wrong.
b. Update your Linux installation with the following commands:
sudo apt-get update
sudo apt-get upgrade

These commands may take a few minutes to complete. The upgrade command displays how much
additional flash drive space will be consumed by the upgrade and prompts you to verify that the
upgrade should proceed. Enter "Y" and then press Enter to proceed. A command prompt appears
when each is completed.
12. Copy the IzoT SDK to your R-Pi:
a. Right-click your Project directory and then click Show in Explorer on the shortcut
menu. Windows Explorer opens with your Project directory open. Copy the IzoT SDK
that you downloaded to this directory.

14

b. Browse your new server by entering the Tools -> Deployment -> Browse Remote
Host command. The Remote Host pane appears. Click Yes at the authenticity prompt if
it is displayed.
c. In the Remote Host pane for your R-Pi, expand the home directory, right-click your user
directory, which is pi by default, and then click Create Folder. Enter izot-sdk for your
folder name and then click OK.
d. Right-click the izot-sdk.tar.gz file in the Project pane and click Copy on the shortcut
menu; then right-click the izot-sdk folder in the Remote Host pane and then
click Paste. Wait for the transfer to complete.

13. Open the terminal window for your host and install the IzoT SDK by entering the following
commands at the shell prompt:
a. Change to your izot-sdk directory: cd izot-sdk.
b. Extract the files from the SDK archive: tar -xzf izot-sdk.tar.gz.
c. Delete the SDK archive: rm izot-sdk.tar.gz.
d. Run the bootstrap script: etc/bootstrap. An Internet connection is required for this
step. Depending on the speed of your connection, this script may take up to 90 minutes
to run. When the script completes it displays "Welcome to IzoT!", and you will see the
Linux shell prompt.
e. Log off with Ctrl-D and log back on. This will create the virtual environment required to
use the IzoT SDK.

15

Part II. IzoT Device Stack EX Hands on Lab


This part describes how you can create an IzoT device and how you can create a community of IzoT
devices, using the IzoT Device Stack EX on a Raspberry Pi for each device. This is the hands-on
portion of the IzoT Device Stack EX Hands-on Lab. You can also follow these steps with Raspberry Pi
devices that you have set up yourself following Part I.
If you are doing this lab as part of an Echelon-sponsored Hands on Lab event, you have a device that
consists of a Raspberry Pi with a PiFace Digital I/O Board in a clear plastic enclosure. On the outside
of the enclosure is a label with the unique hostname for your device. This name was assigned during
the setup for your lab. The last two numbers of the hostname are the last two numbers of youre
the IP address for your device. For example, the device with a label that reads DIO-52 has an IP
address of 192.168.1.52 for the lab. This address was assigned using a static IP address assignment
in the router as recommended in Part I of this lab.

Part II-A. Starting the Mulit-DIO Python Application


The Multi-DIO Python application is an example of a simple digital input/output device. You can use
this example to see how to monitor both a hardware digital input and a LonTalk/IP digital input
datapoint, and use them to control the state of a hardware digital output and a LonTalk/IP digital
output datapoint. To start the Multi-DIO application, follow these steps:
1. Open PyCharm.
2. If you have not already created a PyCharm project and configured PyCharm, follow the
procedure described in step 6 on page 10.
3. If you have not already created a remote host for your R-Pi, follow the procedure described in
step 10 on page 14.
4. Start an SSH terminal session by clicking Tools and then selecting Start SSH Session.

16

5. Enter the following command to restart the lab:


$ izot_lab_start

This command erases any previous student files and copies a fresh copy to an ~/izot-lab
directory, and then changes the current directory to the ~/izot-lab directory. You will be making
your changes to the copies in the izot-lab directory.
6. Enter the following command to start the multi_dio.py example application:
$ supy multi_dio.py -m

The supy command runs the specified application (multi_dio.py in this case) with the Python 3
interpreter running with root privileges. Many IzoT Device Stack EX applications require direct
access to I/O devices which is not allowed for applications running with user-level privileges.
The m flag runs the application in demo mode which speeds up discovery by four times.
17

7. Push Button 1 to confirm the application is running. The Multi-DIO application will toggle the
state of LED 1 each time you press Button 1 if the application is running. Relay 1 will also toggle
since it is attached to the same output as LED 1.

8. Push Buttons 2 and 3 to confirm that you can control LEDs 2 and 3. Button 2 will also control
Relay 2. There is no relay for Button 3.
Part II-B. Testing the DIO Python Application with the IzoT Device Browser
The IzoT Device Browser is a Web page included with the IzoT Server that you can use to test your
IzoT-enabled devices as you develop them. To start the IzoT Device Browser and use it to test your
DIO device, follow these steps:
1. Open the IzoT Device Browser
a. Open an Internet browser such as Chrome, and enter 192.168.1.19. The IzoT Server
home page opens.

18

b. Enter admin for the username and admin for password in the two boxes at the top-right
of the page, and then click Login.
c. Click the large green Example Dashboard (Local) button. The IzoT Dashboard opens.
The Dashboard is a custom interface for the device types implemented by the IzoT
Device Stack EX example applications. If you are viewing the Dashboard for an IzoT
Server attached to a network with multiple DIO devices, you will see all the DIO devices
in the network discovered by the server.

d. Push Button 1 on your DIO. The first box for your DIO on the Web page changes to
match your physical LED. This happens because the Javascript for the Dashboard Web
page monitors the IzoT Server for changes to the datapoints represented in the
Dashboard.
In the following example, the first box is illuminated for DIO-55 and DIO-57.

e. Click the first box on the webpage for your DIO. LED 1 on your DIO will change, and you
will hear the relay change state. This happens because your button press event is
translated to an update to the load control input for your selected device.
f. Click the Device Browser tab. The IzoT Device Browser appears. Unlike the Dashboard,
the browser can be used to monitor and control any device recognized by the IzoT
Server. When you first click the Device Browser tab, you will see a delay as the browser
gets a list of devices from the IzoT Server.

19

g. Find your device in the Device Browser and click it. There will be a brief delay as the
Device Browser queries the IzoT Server for all the datapoints on your device. The
webpage will automatically update when the Device Browser gets the response.

20

2. Use the state-1 box to monitor the output in the browser while changing the state via the first
pushbutton

3. Use the state-setting-1 box to change the state of the first digital output. Monitor the state
change by observing the LED 1 state. You will also hear the first relay turn on and off.

Part II-C. Testing Automatic Peer-to-Peer Communication


A key feature of the IzoT Platform is the capability for IzoT-enabled devices to autonomously
communicate without the use of servers or controllers. IzoT-enabled devices can periodically
broadcast information about their applications and available datapoints, and can monitor these
broadcasts to subscribe to datapoint updates from compatible devices. The DIO application you are
running broadcasts information that informs other IzoT-enabled devices that it has a digital input
that can be controlled via a datapoint, and it has a digital output that publishes the state of the
digital point.
To optimize network traffic, one of the DIO devices in your community acts as a host for all the DIO
connections. If you are working on this lab as part of structured event, your instructor has already
set up a DIO to act as a host. If you are doing this lab on your own, you will need to modify the
application on one of your DIO devices to act as a host. This step is described in the next part.
Once multiple DIO applications are running in the lab, and one of them is acting has a host, they will
discover each other and start to form connections, creating a community of devices. Within a few
minutes of starting multi_dio.py on your Pi, and your neighbors' starting it on their Pi devices, the
multi_dio.py applications will connect to each other. You can verify this by pressing the first
pushbutton on your Pi and watching your neighbors' Pi devices to see if they change. Or, you may
notice the state of your LED 1 changing when one of your neighbors pushes their pushbutton.
Part II-D Changing the Number of DIOs for Your Application
To learn how to modify the application for an IzoT-enabled device, you will change the number of
DIO blocks on your device from three to two. This will change the interface that your device
publishes on the network, and will disable the third pushbutton. To download the multi_dio.py
application from your R-Pi to your PyCharm computer and change it to support two DIOs, follow
these steps:
1. Exit the multi_dio.py application by typing exit and pressing Enter at the console window.
2. Open the Remote Host pane to browse your R-Pi server by entering the Tools -> Deployment ->
Browse Remote Host command. The Remote Host pane appears. Click Yes at the authenticity
prompt if it is displayed.
3. In the Remote Host pane, click the down arrow, and then click your R-Pi on the remote host list.
PyCharm reads the user directory from your R-Pi and displays it.
4. Expand the izot-lab directory in the Remote Host pane, right-click the multi_dio.py file, and then
click Download on the shortcut menu. PyCharm copies the multi_dio.py file from your R-Pi to
your PyCharm computer.
5. Browse to the multi_dio.py file on your PyCharm computer in PyCharm.
21

6. If you are doing this lab on your own, and as a result do not already have a DIO device set up as a
host for your DIO connections, search for the first instance of is_host_device. You will find it
near line 37. Change False to True for the first DIO that you startup in your network.
is_host_device = True

# Set to True if this device is a host

7. Search for the first instance of DIO_COUNT. You will find it near line 32. This will be the
statement just before the statement from the previous step. Change the value for DIO_COUNT
from 3 to 2.
DIO_COUNT = 2

# Number of DIOs; can be 1 to 7 with the PiFace


# One button/LED pair is reserved for the
# Connect LED

8. Right-click in the editing pane, click Upload To, and then select your remote host. PyCharm
copies your edited file from your PyCharm computer to the remote host.
Part II-E. Starting the 2-Channel DIO Python Application
To start your new 2-channel DIO application and verify it works, follow these steps:
1. Open the SSH Terminal window for your R-Pi and enter the following command at the command
line:
$ supy multi_dio.py m

Your modified 2-channel DIO application starts. The m flag accelerates discovery.

2. Push Button 1 to confirm the first DIO is still working.


3. Push Button 2 to confirm your second DIO is running.

22

Part II-F. Testing the Multi DIO Python Application


To test that your new Multi DIO application works over the network, follow these steps:
1. Open the IzoT Device Browser
2. Monitor the outputs in the browser while changing the state via Button 1 and Button 2. The
outputs are the state-1 and state-2 fields in the browser.

3. Monitor the LED 1 and LED 2 states while changing the states via the browser
Part II-G. Testing Manual Peer-to-Peer Communication
In your previous peer-to-peer testing, you verified that your R-Pi device automatically joins
connections with other DIO devices in your device community. Using IzoT Control Services, you can
also use manual connections to specify specific devices that should communicate. The DIO
application is configured to delete all automatic connections once a manual connection is requested,
so your automatic connection will be deleted as soon as anyone in the lab gets to this part of the lab.
To test your automatic connection and create a manual connection, follow these steps:
1. If automatic connections for the DIO devices are still enabled, within 20 seconds of starting up,
your 2-channel DIO device will join the connections with other DIO devices in the lab. Verify
peer-to-peer connections for both of your DIO blocks. Within a few minutes of starting
multi_dio.py on your Pi, and your neighbors' starting it on their Pi devices, the multi_dio.py
applications will connect the two DIO assemblies to the matching DIO assemblies on each
other. You can verify this by pressing Button 1 and Button 2 on your Pi and watching your
neighbors' R-Pi devices to see if they change. Or, you may notice the state of your LED 1 and LED
2 state changing when your neighbors push their pushbuttons. If you are ahead of your

23

2.

3.

4.

5.

6.

neighbors, you can test with the instructors R-Pi, which is running the instructors version of
multi_dio.py, as long as automatic connections are still enabled.
To manually create a connection, push the Connect button for one second. The Connect LED on
all the DIO devices in your community will illuminate, indicating that they are all deleting the
automatic connection. After the automatic connection is deleted, the Connect LED starts
flashing on all DIOs in the community, indicating which devices are available to join the
connection.
To add a DIO device to the new connection that you have started, briefly press the Connect
button on any other DIO device with a flashing Connect LED. The Connect LED will stop flashing
and turn on, indicating the DIO device is ready to join the connection.
To add more than one other DIO device to your connection, push additional Connect buttons.
The Connect LED will stop flashing and turn on for each of the devices as you press the Connect
buttons.
To confirm your new connection, briefly press the Connect button on the first DIO device you
used to start forming the manual connection. All the Connect LEDs will turn off, indicating that
you have created the manual connection.
Test your new manual connection by pressing Button 1 or Button 2 on any of the connected DIO
devices. The corresponding LED on all the connected DIO devices should turn on or off as you do
that. You will also see that any devices not in your manual connection will not respond to your
button presses.

Part II-H. Adding a new Output Datapoint


To learn how to add an output datapoint to an IzoT application, you will add an Analog Input block
with an analog output datapoint to the Multi DIO application. To add the Analog Input block and
analog output datapoint, follow these steps:
1. Search for the first instance of IzoT profiles. You will find it near line 29. Add the following
line in bold to import the Analog Input profile definition that you will be using for your new
block:
# IzoT profiles used by this application
from izot.resources.profiles.iotAnalogInput import iotAnalogInput
from izot.resources.profiles.iotKeypad import iotKeypad

2. Search for the first instance of is_host_device. You will find it near line 37. Add the following
line in bold to create a global variable that you will use for your new Analog Input block:
is_host_device = False
analog_input = None

# Set to True if this device is a host


# The host device will initiate auto enrollment
# Global for the Analog Input block

3. Search for the first instance of PROGRAM_ID = (with a space before the =). You will find it
near line 55. The program ID is used to look up the definition of the datapoints that are exposed
by the IzoT Server. This definition is contained in a file called the device class file. Change the
51 in the program ID to a 71 to specify an alternate device class file that is included with the
IzoT Server for this example device. The alternate device class file adds the definition for the
new analog output datapoint.
PROGRAM_ID = '9F:FF:FF:05:00:71:00:1' + str(DIO_COUNT)

24

4. Search for the first instance of dio_controllers.append. You will find it near line 90. This line
creates the DIO controller objects that implement the DIO functionality for this application. Add
the following lines in bold to create a new Analog Input block. The line with the call to
app.block() does all the work of creating a new block, including creating all the network inputs
and outputs required by the Analog Input profile. It also assigns analog_value as the network
visible name for the new block.

for i in range(DIO_COUNT):
dio_controllers.append(DioController(framework=framework, dio_index=i))
# Create an Analog Input functional block to publish a percentage output
global analog_input
analog_input = app.block(profile=iotAnalogInput(), ext_name='analog_value')

5. Search for the first instance of self._piface (with an underscore before piface. You will find
it near line 443. This statement turns on an LED on the PiFace board in response to a local
button being pressed. Add the following lines in bold to increment the analog output datapoint
value by one in response to any of the local buttons being pressed when their corresponding LED
is off.
if self._piface:
self._piface.output_pins[event.pin_num].turn_on()
# Increment the analog percentage output by one
global analog_input
if analog_input.nvoAnalog.data.present_value < 100:
analog_input.nvoAnalog.data.present_value += 1
else:
analog_input.nvoAnalog.data.present_value = 0

Part II-I. Testing the Multi DIO with Analog Output Application
Note: This part requires updated device class files included with version 1.01.27 or newer of the IzoT
SDK. You have to manually add the new device class files if you are using an earlier release.
To test that your new Multi DIO with Analog Output application works over the network, follow
these steps:
1. Open the IzoT Device Browser
2. Monitor the outputs in the browser while changing the state via Button 1 and Button 2. The
analog output is displayed in the analog_value field in the browser. It will increase by one each
time you press one of the local pushbuttons on the monitored Pi device. You will notice a delay
from the time you press the button until you see an update on the display. That is because you
have not yet connected this output to any inputs, so the value is only updated when the IzoT
Server polls the value. The polling rate configured for your network determines how long the
delay will be.

25

Part III. IzoT Server Stack Setup


This part describes how you can download the IzoT SDK and install it on a BeagleBone Black. The
BeagleBone Black has about twice the performance of a Raspberry Pi, for about $10 more. While
you can run an IzoT Server on a Raspberry Pi, the BeagleBone Black is a better platform for the IzoT
Server because of the higher performance requirements of the server stack. The IzoT Server
includes an implementation of the IzoT Device Stack EX, but also includes a Web server, a Web
application server, a REST server, an IzoT/IP network server, and a SQL database. All these
components run simultaneously, requiring more processor resources than a typical IzoT device
running just the IzoT Device Stack EX and a device application. If you are attending an IzoT Handson-Lab, Part III has been completed for you prior to the start of the lab.
To get started with the IzoT Server Stack using a BeagleBone Black, follow these steps:
1. Download software for the BeagleBone Black (this is the same software as the download for the
Raspberry Pi, so if you have already downloaded it you do not have to download it again):
a. Download the IzoT SDK from iiot.echelon.com/get-started.
b. Download the raring release of Ubuntu Linux for the BeagleBone Black
from http://www.armhf.com/index.php/boards/beaglebone-black/
2. Download and install the following tools (the first two are the same tools used to setup Raspbian
on a Rasberry Pi--Win32 Disk Imager is for Windows; see www.raspberrypi.org for instructions
for other platforms) :
a. SD Formatter from www.sdcard.org/downloads
b. Win32 Disk Imager from sourceforge.net/projects/win32diskimager/
c. XZ Utils from tukaani.org/xz/

26

3. Create a MicroSD card with Ubuntu Linux:


a. Insert an 8 GB Samsung Class 10 Micro SD card into SD card adapter, and insert it into a
PC SD card slot.
b. Reformat the SD card with SDFormatter, selecting the options to Expand and do a Full
(Erase) format.

c. Decompress the Ubuntu image using XZ Utils.

d. Start Win32DiskImager, select the image you downloaded in step 1b, select the SD
device primary partition, and then click Write to write the Ubuntu image to the SD
card (if you have any mapped drives you may see an error at startup--you can ignore the
error).

4. Start the BeagleBone Black:


a. Insert the MicroSD card with Ubuntu Linux in the BeagleBone Black.
b. While holding down the Boot button (next to the MicroSD card), apply power to the
board with a Micro USB power cable. Continue to hold the Boot button until the User
LEDs begin to flash.
5. Get the IP address for the BeagleBone Black. If you are behind an accessible router, you can get
the IP address from the IP client list maintained by the router. For example, the following figure
shows the client device list for an Asus Wi-Fi router:

27

6. Start and configure PyCharm (you can use any remote console application such as PuTTY):
a. Start PyCharm

b. Set the default encoding for SSH terminal windows to UTF-8: click File -> Settings;
click SSH Terminal; and then set Default Encoding to UTF-8.

28

c. Create a new project. Enter a project name and select the Python 3.3.4 (or newer) local
Python interpreter.

7. Open a terminal window for the BeagleBone Black:


a. Select Tools -> Start SSH Session; Click Edit Credentials; define a new SSH Session with
your host IP address from step 9, port 22, a user name of ubuntu, and password
of ubuntu.

b. Click OK to ignore the authenticity warning.

29

8. Expand the Linux file system to fill the MicroSD Card.


a. Open an su prompt with: sudo su
b. Check the available volumes with ll /dev/mmcblk*
c. Run fdisk on the MicroSD volume with: fdisk /dev/mmcblk0
i. Enter p to determine the device name for the Linux partition. It is
typically /dev/mmcblk0p2.
ii. Enter d for delete then press 2 for partition 2.
iii. Enter n for new partition, p for primary, 2 for partition 2, and then select the
default starting and ending sectors.
iv. Press p to confirm the new larger Linux partition.
v. Press w to commit the changes to the MicroSD card.
d. Reboot with: reboot
e. After rebooting, become superuser with sudo su, and then expand the root filesystem
with resize2fs /dev/mmcblk0p2. You can run df before and after to confirm the change.
9. Configure the Ethernet interface to use DHCP.
a. Determine whether your BeagleBone Black uses eth0 or eth1 with ifconfig -a
b. Edit the /etc/network/interfaces file: sudo nano /etc/network/interfaces
c. Add or edit the interface line with eth0 or eth1 to match the following
(change eth0 to eth1 if your BeagleBone Black uses eth0):
iface eth0 inet dhcp

10.

11.
12.

13.

d. Exit nano with Ctrl-X, and write the file.


e. Reboot with: reboot
Configure the date and time.
a. Set the time and date via NTP with: sudo ntpdate -b -s -u pool.ntp.org
b. Set up the NTP daemon with: sudo apt-get install ntp
c. To test an NTP server, enter: sudo ntpdate ntp.server.name
d. Delete the existing local time file: sudo rm /etc/localtime
e. Link the correct local time file: sudo ln -s /usr/share/zoneinfo/US/Pacific-New
/etc/localtime
Configure the locale with: sudo update-locale LANG=en_US.UTF-8
Change your hostname:
a. Edit the hostname file with: sudo nano /etc/hostname
b. Change the name to a unique hostname for your server.
c. Exit nano with Ctrl-X and write your changes.
Update your Linux installation with the following commands:
sudo apt-get update
sudo apt-get upgrade

These commands may take a few minutes to complete. The upgrade command displays how much
additional flash drive space will be consumed by the upgrade and prompts you to verify that the
upgrade should proceed. Enter "Y" and then press Enter to proceed. A command prompt appears
when each is completed.

30

Part IV. IzoT Server Hands on Lab


This part describes how you can create Web pages that interact with IzoT Devices using the IzoT
REST API provided by an IzoT Server. This is the hands-on portion of the IzoT Server Stack Hands-on
Lab.
For this lab you will be developing a static Web page, hosted on an IzoT Server for a single Pi with a
PiFace I/O board having the dual DIO application from Part II which uses two pushbuttons and two
LEDs on the PiFace board.
The Instructor will assign you a Pi device to use for this Lab and a work folder on the IzoT Server. The
Pi application uses two pushbutton-LED pairs. Each pushbutton-LED pair will be represented in the
Web page you are developing as a clickable LED element. There is a control datapoint state-setting# representing the pushbutton and a feedback datapoint state-# representing the LED state (on or
off). The Web page LED element color represents the state of the LED (or feedback) and clicking the
LED element will cause the Web page to toggle the control datapoint between on and off. The first
part of this lab is to identify the datapoint IDs that you will be using with your Web page.
Part IV-A. Determine the Datapoint IDs for your Pi Using the IzoT Device Browser
1. Open the IzoT Device Browser
a. Open an Internet browser such as Chrome, and enter 192.168.1.19. The IzoT Server
home page opens.

b. Click IzoT Example Web Pages and then Device Browser tab and the tab with your Pis
name

31

c. Write down the IDs for the following datapoints


SW1 - LED1:
state-setting-1

___

state-1 ___

___

state-2 ___

SW2 - LED2:
state-setting-2

2. Change to the IzoT Test Tab

a. Click the Get Request button and wait until you get a response in the text area at the
bottom of the web page. There may be a delay.
b. Click the Get Request arrow to select different Get Request and then press the Get
Request button. Try all the commands. Any command that has a number like
datapoints/4/ or devices/4/ in it you should replace the number with one of the
datapoint IDs or the device ID for your Pi.
c. Copy the following command into the Get Request textbox and change the 1,2,3,4 to the
ids in you wrote down above.
/api/datapoints/?ids=1,2,3,4

Part IV-B. Check Your Lab Web Page


1. In the Web browser go to the following address, filling in your folder number for <X>:
32

192.168.1.19/dashboard/izot-lab/<#>/lab.html
2. Press the Refresh button. You will either get an error message or you will see a GET response in
the trace Log. If you get an error message it means that the Web page datapoint IDs do not
match your or any other Pi device and you need to change the datapoint IDs in the Web page.
You can correct these in the next section.
Part IV-C. Change the Lab Web Page Datapoint IDs
1. Start and configure PyCharm:
a. Start PyCharm. Click Create new Project.

b. Enter a project name into the Create New Project dialog

c. Set the default encoding for SSH terminal windows to UTF-8: click File -> Settings;
click SSH Terminal; and then set Default Encoding to UTF-8. Next click the Configure
Server link.

33

d. If the IzoT server is not already listed in the Deployment pane then press the + to add
the IzoT server. Enter in the server name, IP address, and username and password and
press OK.

e. Select Tools -> Deployment -> Browse Remote Host; In the Remote Host pane select the
Beagle bone Server. Next click the button (the three dot button) in the Remote Host
pane

34

f.

Click the mapping Tab; In the Remote Host pane select the Beagle bone Server. Next
click the button (the three dot button) for Deployment path on server .

g. Navigate to the your assigned lab1. Then click the button (the three dot button) for
Deployment Path on Server.
For example if you were assigned lab1, you will want to click the following folder and click OK.
/home/ubuntu/izot-sdk/www/dashboard/izot-lab/lab1

35

h. Back in the Remote Host pane navigate to your assigned lab folder. Right click to and
select Download from Here to copy the files on the IzoT server to your computer.

i.

Expand your project folder and double click the lab.js file

36

Note: When you open the file in PyCharm you may see a lot of yellow warnings. In most cases
warnings can be ignored. If you see red errors you should look to see if you have a bug in your code.
Note: You should always make frequent backups of your Web page files when making changes as it is
not always easy to troubleshoot Web page issues.
j.

Go to the call to the addDisplayObj() function in the lab.js file. If the state-1 and statesetting-1 datapoint IDs do not match your Pi devices datapoint IDs, change the IDs to
ones your Pi uses. State-1 is the readDp and state-setting-1 is the writeDp. Write click
the file and select Upload To to copy the file from your computer to the Izot Server.

Part IV-D. Test the Web Page


Whenever you change a Web page you must refresh the browser in order to see the changes. In
some cases some of the files and graphics are cached in the browser and a simple refresh doesnt
clear it. Make sure the Browser Debugger window is closed before doing a refresh.
Internet Explorer: For Internet Explorer you must clear the cache (Click Settings -> Internet Options
-> General Tab and then click the temporary Internet Delete button). Almost every Web page
change requires you to delete the Temporary Internet files when using Internet Explorer.
FireFox: In many cases you can load a new Web page by closing the browser and reopening it.
Chrome: In most case a simple refresh works. In some cases just opening and closing the browser
clears the memory. If you still dont see the changes you can clear the Chrome cache. If you still
believe you are not seeing your changes, reboot your computer.
1. Go back to your Web browser. If you have the Web page debugger open close it and press F5 to
refresh.
37

2. On the lab Web page click the Refresh button. You should see the current state of LED #. Press
Button1 on the Pi and click the Refresh button again. If you dont see a change, wait a couple of
seconds and press the Refresh button again.
3. Click the LED shape, you should see the LED element in the Web page change color and in a
couple of seconds you should see the Pi LED toggle. Click the Refresh button again on the Web
and you should the new change.
Part IV-E. Add a Second Clickable LED to the Web Page
1. Add a second LED div structure in the lab.html file
a. Go back to PyCharm and open the HTML file. Find the <div> element with leddiv_1.
b. Copy the complete leddiv_1 <div> element and its subelement to just below its </div>.
c. In this new div element change all the _1 to _2 and change the toggleLedState(1) to
toggleLedState(2).
d. If you dont see any red warnings then right-click the page to upload the file to the IzoT
Server.
2. Open the lab.js file
a. Add a second addDisplayObj() function in the $(document).ready function. Remember
to use the correct display and datapoint IDs for the second pushbutton-led.
b. Un-comment setDisplayLedColor("unknown", "canvas_2", ""); in the init() function.
c. If you see no errors in PyCharm then upload the new .js file to the IzoT server.
3. Refresh your browser and see if the second LED appears. If so, after pressing the Refresh button
and verify that you see data for two sets of datapoints in the trace log. Click the second LED, and
verify that you see the LED on your Pi toggle. The clickable LEDs controls only that LED, but the
Master On and Master Off buttons control both LEDs.
Part IV-F. Periodically Get Datapoint Values with a Refresh Timer
1. In PyCharm, open the lab.js file
a. Change the enableUpdateTimerElements() parameter in the
(document).ready(function() from a 0 to a 1.
b. Upload the file to the IzoT server.
2. In the Web Browser make sure your change works.
a. Refresh the Web Browser.
You will notice that the Refresh button disappears as well as the trace log. The trace log is good
for debugging but when you are periodically getting information it will cause too much data to be
stored which could affect Web page performance.

b. Press the push button on the Pi and you should see the LED toggle on the web page after
a short time.
c. Click one of the LEDs on the Web page. Youll see the page change state quickly but
then change back to the original state, and then in a few seconds changes again.
This feedback delays happens due to the round trip delay between changing a control datapoint,
the Pi performing a function on the control datapoint update, the Pi changing the value of the
feedback datapoint, the IzoT Server seeing the feedback datapoint update and the Web page
polling the IzoT server for changes.

38

To reduce the chance of seeing the toggling affect we need to add a feedback delay between
changing the control datapoint and responding to a change in the feedback delay.

Part IV-G. Add a Feedback Delay


1. In PyCharm, open lab.js and set displayObjs[id].readDpFeedbackDelay, in addFeedbackDelay(),
to true. Upload file to the IzoT Server.
2. In the Web Browser, do a refresh and then click one of the clickable LEDs. The LED color should
change and not toggle. After you see the PiFace LED change, push the pushbutton on the PiFace
and you should see the LED change on the Web page.
Part IV-H. Improve Performance With an HTML Timestamp Filter
Timestamp filtering can make a difference on the IzoT response time when you are polling many
datapoints every couple seconds.
1. In PyCharm, open the lab.js file.
a. The processDatapointDataCallback() function processes all GET request responses.
When a datapoint is updated we want to update the HTTP request after the
timestamp to a new value. To do this add calculateNewLatestTimestamp(); to the
processDatapointDataCallback() function as shown below.
if(bAtLeastOneDpChanged) {
calculateNewLatestTimestamp();
}

// add this line of code

b. Upload file to the IzoT Server.


2. In the Web Browser, do a refresh and check if everything is still working.

39

Vous aimerez peut-être aussi