This documentation is for WSO2 IoT Server 3.1.0. View the documentation for the latest release.
Creating a Fire Alarm Device Type via the Console - IoT Server 3.1.0 - WSO2 Documentation
           
||
Skip to end of metadata
Go to start of metadata

In this tutorial, you are going to create a new fire alarm device type, enroll a fire alarm using the device management console, and start using the device. A sample Python agent is used to make the use case interesting.

 

Before you begin

  • Install Python.

  • Install pip.

    • Enter pip -V in your terminal to check the current version of pip in your machine.

    • If it is already installed you will get a message similar to what is shown below:
      pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
      Else you will get the following message:
      The program 'pip' is currently not installed. You can install it by typing:
      sudo apt install python-pip

  • Install Paho-MQTT. Paho-MQTT It is the MQTT client library for Python.
    You need to have pip installed before installing Paho-MQTT.

    sudo pip install paho-mqtt
    The above command works for Python 2.X. If you have installed Python 3.X, you need to replace pip with pip3.
    To know the version of Python you have installed use python -V.
    sudo pip3 install paho-mqtt

    If you are running on windows, remove the sudo prefix from the above command. Instead, you need to run the command in the command prompt as an administrator

  • You need to start the WSO2 IoT Serve's broker, core, and analytics profiles.

    cd <IOTS_HOME>/bin  
    ------Linux/Mac OS/Solaris ----------
    ./broker.sh
    ./iot-server.sh
    ./analytics.sh
      
    -----Windows-----------
    broker.bat
    iot-server.bat
    analytics.bat

Let's get started!

Creating the fire alarm device type

  1. Sign in to the WSO2 Device Management Console.

    If you are an administrator, sign into the device management console using admin as the username and admin as the password. If you want to register with WSO2 IoT Server, see Registering with WSO2 IoT Server.

  2. Click  > DEVICE TYPE MANAGEMENT > CREATE DEVICE TYPE.

    WSO2 IoT Server has the Android, Windows, Raspberry Pi, Arduino, Android Sense and iOS sample device types by default. If you have not run the <IOTS_HOME>/samples/device-plugins-deployer.xml file, you will only have the Android, Android Sense, and Windows device type by default.

  3. Enter the following details to add a new device type and click Add Device Type.

    Make sure to enter the values given below. Else, you are not able to complete the tutorial successfully.

    Namefirealarm
    DescriptionThis is a device used for testing.
    Push Notification TransportMQTT
    Feature namemsg
    Feature codemsg
    Feature descriptionMessage from the server to the device.

    For more information about each field, see Creating a New Device Type via the Device Management Console.

  4. Create the event stream to gather the sensor readings or data from the device, and click Add.
    Enter the following values:

    Make sure to enter the values given below. Else, you are not able to complete the tutorial successfully.

    TransportMQTT
    Event nametemperature
    Event data typeINT

    For more information about each field, see Creating a New Device Type via the Device Management Console.

    Opt to navigate to the enrollment page when prompted. 

Enrolling a fire alarm

Follow the steps given below to enroll a fire alarm for the device type you just created:

  1. On the Enroll Device page, click on the fire alarm device type.
  2. Click + Create Device.
  3. Enter the details to create the device and click Create Device.

    Make sure to enter the values given below. Else, you are not able to complete the tutorial successfully.

    NameAlarm1
    Device Identifier123456
    DescriptionEnrolling a device for testing.

    For more information about each field, see Creating a New Device Type via the Device Management Console.

    The 123456.json file downloads automatically.

  4. Download the SampleApp.zip file to a preferred location. This directory is referred to as <SAMPLE_APP> throughout this document. Next, unzip the SampleApp.zip.

    unzip <SAMPLE_APP>/SampleApp.zip

    Additionally, you can find the sample app code on Git Hub too.

  5. Rename the downloaded 123456.json file to config.json and copy it to the <SAMPLE_APP>/Configuration directory.

  6. Navigate to the <SAMPLE_APP> directory via the command prompt and run the python script.

    cd <SAMPLE_APP>
    python SampleClient.py

    The above command works for Python 2.X. If you have installed Python 3.X, you need to replace python with python3.
    To know the version of Python you have installed use python -V.

    python3 SampleClient.py

    The sample starts.

    If the sample successfully connects to WSO2 IoT Server, you will see the Connected with result code 0 message in the terminal and the app starts pushing data to WSO2 IoT Server.

Viewing the data gathered from the fire alarm

Click   > DEVICE MANAGEMENT, and click on the fire alarm device you just enrolled to view the real-time and historical data that was pushed from the fire alarm to WSO2 IoT Server.

Real-time data

You see the real-time data pushed to WSO2 IoT Server as shown below:

The current temperature is 46. 

Historical data

Click View Device Analytics to view the historical temperature readings of the fire alarm.

Sending a Message to the fire alarm

Follow the steps given below to send a message to the fire alarm. You configured the fire alarm device type to have the messaging feature when creating the new fire alarm device type.

  1. Click the msg operation.
  2. Enter the message you want to send, and click Send to device.

    Go to the terminal where you were running the sample. The following message is shown if the message was successfully delivered to the fire alarm.
  • The access token generated to access the fire alarm expires in an hour. Therefore, you are not able to use the SimpleClient.py script after an hour.
  • To overcome this, you can use the SampleClient2.py script. Similarly, if you want to make changes to the current script and try many things with WSO2 IoT Server.
  • No labels