Multi DIO
The Multi DIO application demonstrates simple digital input and output that can be built for one to seven channels. It is the simplest of the IzoT SDK example applications, and is a good starting point to learn about IzoT Python and LonTalk/IP. 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.
The Multi DIO example application runs on a Raspberry Pi device with a PiFace Digital I/O Board installed. The PiFace Digital I/O 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. The Multi DIO application uses the pushbuttons and the relay outputs.
The Multi DIO application is used for the IzoT Device Stack Hands-on Lab. You can take a look at the Hands-on Lab Instruction Manual for more details.
Using the Multi DIO application, you can control each pushbutton switch directly or via the IzoT network using the demo Web pages, as shown in the Dashboard Web page.
The following video describes how to create a network with the Multi DIO application:
The Multi DIO application toggles the state of LED 1, 2, or 3 each time you press the corresponding Button 1, 2, or 3. When LED 1 or LED 2 toggle, Relay 1 or Relay 2 also toggle since they are attached to the same outputs as LED 1 and 2. There is no relay for Button 3.
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 Multi DIO application 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 Multi DIO devices in your community acts as a host for all the Multi DIO connections. You will need to modify the application on one of your Multi DIO devices to act as a host. To do this, change the value of is_host_device in the Multi DIO application to True.
is_host_device = True    # Set to True if this device is a host
Once you have multiple Multi DIO applications running, 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 the Multi DIO applications on your multiple Pi devices, the Multi DIO applications will connect to each other. By pressing the first pushbutton on one Pi device, you may notice that the state of LED 1 of the other Pi devices are changing.
You can change the number of DIO blocks on your device. By default the Multi DIO application implements three DIO blocks. To change the number of DIO blocks on your device from three to two, modify the value for DIO_COUNT in the Multi DIO Python application from "3" to "2".
DIO_COUNT = 2Â Â Â Â Â Â Â Â Â Â Â Â Â #Â Number of DIOs; can be 1 to 7 with the PiFace
This section consists of the following:
Hardware
The Multi DIO example application works with the following hardware:
- Raspberry Pi
- PiFace Digital -- the PiFace Digital is a digital I/O board with the following inputs and outputs:
- 8 digital inputs
- 8 digital outputs
- 8 LEDs that indicate the state of the 8 digital outputs
- 2 relays
- 4 pushbutton switches connector to the first four digital inputs.
The Multi DIO examples uses one pushbutton switch and one LED indicator for the Connect light and Connect button. You can configure the Multi DIO example to use up to three pushbutton switches to control three LEDs.
Running the Multi DIO Application
You can start the Multi DIO example application as a service and optionally enable it to automatically run on boot, or you can run it from the command line. Running from the command line is useful for doing interactive testing and debugging. Running as a service is useful for setting up working networks and demonstrations.
To start the Multi DIO example application as a service and enable it to run on boot, enter the following command:
izot_enable dio
To stop the Multi DIO example application and disable it from running on boot, enter the following command:
izot_disable dio
To start the Multi DIO example application without changing its boot status, enter the following command:
izot_start dio
To stop the Multi DIO example application without changing its boot status, enter the following command:
izot_stop dio
To display the status of all IzoT services, enter the following command.
izot_stat
To run the Multi DIO example application from the command line, change to the Multi DIO example directory at $IZOT/izot/examples/multi_dio and enter the following command at the Linux shell prompt:
supy multi_dio.py[-D] [-d DEVICE] [-h] [-I] [-i] [-l LOG] [-m] [-n NVD] [-p PROGRAM_ID] [-v] [-rRESET_TYPE]
The following table summarizes the command-line flags and options:​
Flag / Option | Description |
---|---|
-C | Enables debugging with the PyCharm IDE. |
-D | Runs the Touch Keypad example applicaiton in debug mode. The log level is increased for both the console log and the application log. |
-d DEVICE | Sets the device URI, e.g., uc://10.0.1.12:1628. If not specified the default URI is used. |
-h | Displays the available flags and options. |
-I | Disables ISI. Without ISI, the application requires installation by a network management tool such as the IzoT Commissioning Tool. |
-i | Runs the Touch Keypad without any attached I/O hardware. This is useful for running the Touch Keypad on platforms that do not have the Touch Keypad I/O hardware. |
-l LOG | Sets the path and filename for log files. If not specified, the default path is the Touch Keypad example directory, and the filename is 3-chan-dio. |
-m | Runs the Touch Keypad in demo mode. In demo mode, periodic ISI messaging is increased to speed up device and connection discovery. The result is that more bandwidth is consumed for ISI messaging provide faster discovery at the expense of less bandwidth for application data. |
-n NVD | Specifies the path for the non-volatile data directory. If not specified the default directory is 3-chan-dio-nvd in the Touch Keypad example directory. |
-p PROGRAM_ID | Specifies a program ID for this running instance of the application. PROGRAM_ID is a 16-digit hex value described in the Defining the Program ID. If not specified the default program ID for the Environment Sensor example application is 9F:FF:FF:05:00:51:00:31. Specify a different program ID if you have modified the IzoT interface for the example application and you need to load a different device class file for the modified application. |
-r RESET_TYPE | Clears persistent data. Set RESET_TYPE to 0 to clear all persistent data; set RESET_TYPE to 1 to clear all persistent data except for the device unique ID. RESET_TYPE 1 is useful to prevent a change in unique ID which will result in a new discovery of the device by the IzoT Server. |
-v | Runs the Touch Keypad example application in verbose mode. The log level is increased to the maximum level for both the console log and the application log. |
Once launched, the multi DIO application will toggle the state of LED 1 each time you press Button 1.  Relay 1 will also toggle since it is attached to the same output as LED 1.  The Buttons 2 and 3 will also control LEDs 2 and 3.  Button 2 will control Relay 2. There is no relay for Button 3.
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. You will need to modify the application on one of your DIO devices to act as a host. To do this you just need to change the value of is_host_device to True.
is_host_device = True    # Set to True if this device is a host
Once multiple Multi DIO applications are running, 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 multiple Pis, the Multi DIO applications will connect to each other. By pressing the first pushbutton on one Pi device, you may notice that the state of LED 1 of the other Pi devices are changing.
You can change the number of DIO blocks on your device. By default the Multi DIO application implements three DIO blocks. To change the number of DIO blocks on your device from three to two, modify the value for DIO_COUNT in the Multi DIO Python application from "3" to "2".
DIO_COUNT = 2Â Â Â Â Â Â Â Â Â Â Â Â Â # Number of DIOs; can be 1 to 7 with the PiFace