Git Product home page Git Product logo

iot_system's Introduction

System Integration: Arm Mbed & Amazon Web Services

This repository contains all of the software resources used in the Project for my Master Thesis.

  • Section 1 -> Documents: Contains the report and presentation. (Documents Folder)
  • Section 2 -> System Evaluation: Contains the report and presentation. (SystemTest Folder)
  • Section 3 -> Smart Home Application: Contains the report and presentation. (SmartHome Folder)

System

System Evaluation

This repository contains the code and resources to run the experiments described on the Chapter 3.2 of my X Thesis

The hardware components used for the evaluation are:

The Software required to be installed in the Windows PC is:

The Accounts required are:

Path I: Mbed Device and Gateway

This example is based on this project from the Arm Team.

  1. Device A Setup (Nucleo board with BLE Shield)
    1. Download folder .\SystemTest\Nucleo_Code\DeviceA_Program into the PC’s directory.
    2. Open the main.cpp file and go through the test configuration as that of section
    3. Run mbed deploy (downloads the necessary Libraries)
    4. Connect the Nucleo board to the PC and run mbed compile -f (this should flash the program to the device, you should see the RGB LED in the Nucleo Board).
    5. Debugging.
      1. Use the nRF Connect App on your Android or iOS smartphone to find the BLE Device PING
      2. Use Tera Term to see the serial output of the device. (Baud Rate 115200)
  2. Gateway Setup (Raspberry Pi): The Pi is setup as shown in the DeviceLink Project. Skip section “Building a BLE device”. Once the two scripts Linux_Devicelink and Bluetooth_Devicelink are running and the local web application localhost:3000 can be opened from your web Browser, do as follows:
    1. Connect to the PING BLE Device.
    2. Substitute the functions in the two squares with those from file DeviceLink_Functions.txt in .\SystemTest\Test_Resources.
    3. Debug:
      1. Check messages in the Linux Terminals.
      2. Check Mbed Device Connector where you should see a new device connected.

Path II: Mbed Device with Mbed Client

This code is based on the mbed_os_example_client.

  1. Download folder .\SystemTest\Nucleo_Code\DeviceB_Program to your PC.
  2. Get the credentials from Mbed Device Connector
    1. Go to Mbed Device Connector and log in with your mbed account.
    2. On mbed Device Connector, go to My Devices > Security credentials, and get new credentials for your device by clicking the Get my device security credentials button.
    3. Store the credentials in security.h.
  3. Open the mbed_app.json file
    1. insert the SSID Name and password for your LAN or mobile hotspot.
  4. Open the main.cpp file and go through the test configuration as that of section
  5. Run mbed deploy in the cmd line to download the libraries
  6. Connect the Nucleo board to the PC and run mbed compile -f (this should flash the program to the device, you should see the RGB LED in the Nucleo Board flash).
  7. Debugging
    1. Use Tera Term to see the serial output of the device. (Baud Rate 115200)
    2. Use the Mbed Device Connector Website and the Console to observe the resources.

Path III: Mbed Device connected IoT AWS

This Path follows the configuration steps from the Project by Klikka. Follow the tutorial to learn how to configure the device, specially to get the security credentials. Device C Setup (Nucleo board with Wifi Shield)

  1. Download folder .\SystemTest\Nucleo_Code\DeviceC_Program into the PC’s directory.
  2. Run mbed deploy (downloads the necessary Libraries)
  3. Put your SSID and password for your LAN or hotspot as explained in the Tutorial.
  4. Put the Credentials as explained in the Tutorial.
  5. Open the main.cpp file and go through the test configuration as that of section
  6. Connect the Nucleo board to the PC and run mbed compile -f (this should flash the program to the device, you should see the RGB LED in the Nucleo Board).
  7. Debugging:
    1. Use Tera Term to see the serial output of the device. (Baud Rate 115200)
    2. Note that the program has trouble connecting to the network and that it restarts several times before it actually manages to connect successfully. See the Project for more info.

The Topics to which the device is subscribed and publishes to is shown here:

#define TOPIC_SUB_START	"Nucleo/direct/start"
#define TOPIC_SUB_RECV	"Nucleo/direct/ping-in"
#define TOPIC_PUB_SEND	"Nucleo/direct/ping-out"
#define TOPIC_PUB_TIME	"Nucleo/direct/time"

Setup Bridge Connector.

Follow this Project from Mbed Team to connect Mbed Device Connector with AWS. Skip Section Getting the sample application on your device. Follow the rest of the steps to generate the AWS credentials and setup the Docker Application. For a device registered in Mbed Device Connector, the Bridge Connector creates and registers a device in IoT AWS and publishes and subscribes to a set of MQTT Topics that allow you to interact with the Mbed Device. You can subscribe to the “mbed/#” to subscribe to all topics created by the Brige Connector.

Cloud Actions for Lambda Functions

There is one Lambda function for Path I and II and a different one for Path III. Each must be attached to the appropriate Topic as described in the Table above. To learn more about how to setup the Lambda function, read the Lambda AWS Documentation and follow the Quiklab Tutorial and here on how to create a lambda function.

To set the actions in the AWS cloud you have to be familiar with AWS IoT Rules and AWS IoT Actions.

In section 2.2.4 of the report, I show the Topics created by the Bridge Connector to which messages from the mbed device to AWS IoT.

  1. Create Two Lambda Functions in .\SystemTest\Test_Resources :
    1. Use the function in file LambdaBouncer_1.txt for Path I
    2. Use the function in file LambdaBouncer_2.txt for Path II
    3. Use the function in file LambdaBouncer_3.txt for Path III
  2. Create the IoT Rules. In the topics below substitute the [endpoint-type] and [endpoint-name]
    1. For Path I
      1. Topic Filter: the notification Topic of the ping_out Topic: mbed/notify/[endpoint-type]/[endpoint-name]/a000/0/a001
      2. Action: trigger Lambda Function 1.
    2. For Path II
      1. Topic Filter: the notification Topic of the ping_send Topic: mbed/notify/[endpoint-type]/[endpoint-name]/1/0/1
      2. Action: trigger Lambda Function 2.
    3. For Path III
      1. Topic Filter: the notification Topic of the pub_send Topic: Nucleo/direct/ping-out
      2. Action: trigger Lambda Function 3.

Python Scripts

The python scripts in the folder \SystemTest\Test_Resources, control the start of the test as well as take measurements or are part of the system by bouncing the message back. Other considerations to take are:

  • Script 1,3 and 4 you must open the script and fill in the token variable with your own. It can be obtained from the Access Keys Tab in the Mbed Device Connector.
  • Script 2 and 3 IoT AWS credentials. This script is based on the “PubSub” example code from AWS and to get the credentials and how to run the script, see this section. Put the credentials obtained in the .\SystemTest\Test_Resources\Certificates folder.
  • For Script 3, you need to find the Certificate ID for the credentials we just created for this Scripts in this previous point.
    • Go to the Thing created.
    • Click on the Security Tab
    • Copy the Name of the Certificate (the Long ID).
    • Paste this name inside the Script in the certificateId variable in the script.
  • Script 4 can run in two modes: This script bounces the messages in Test 4. When running the test with Device A (BLE), run the program with the argument ble and when running the test with Device B (Wifi), then run the program with the argument wifi.

Test Configuration

For the three device implementations (A,B and C) we have to configure the test parameters. The test runs through a set of modes, in which you can choose: the periodicity with which ping times are sent (in milliseconds).

  • The size of the data packet being sent:
    • False: minimum data packet (the counter of messages that have been sent)
    • True: maximum data packet (the maximum of this path)
      • Path I (BLE) – 26 bytes.
      • Path II (CoAP) – 1000 bytes.
      • Path III (MQTT) – 300 bytes. The Values that can be modified (labelled in red in the example code below) are:
  • VALUES_PER_MODE:
  • TEST_N: The number of modes to test.
  • period[TESTS_N]: the period at which messages are sent for each mode.
  • bw[TESTS_N]: the data packet size for each mode. So for the example below, the device will send 50 messages every second with minimum data packet and then another 50 messages every five seconds with maximum data packet.
/************************ Test Configuration ************************//

#define TEST_DONE -1

#define VALUES_PER_MODE 50
#define TESTS_N 2
#define MIN_T 10

int period[TESTS_N]	= {	1000,	5000};
bool bw[TESTS_N]	= {	false,	true};

/*********************************************************************//

Smart Home Application

This repository contains the code and resources to run the Smart Home Application described on the Chapter 4 of the report.

The hardware components used for the evaluation are:

The Software required to be installed in the Windows PC is:

The Accounts required are:

Device Configuration.

This code is based on the mbed_os_example_client

  1. Download folder .\SmartHome\m2A_MbedDevice to your PC.
  2. Get the credentials from Mbed Device Connector
    1. Go to mbed Device Connector 9 and log in with your mbed account.
    2. On mbed Device Connector, go to My Devices > Security credentials, and get new credentials for your device by clicking the Get my device security credentials button.
    3. Store the credentials as security.h in this project's directory.
  3. Open the mbed_app.json file
    1. insert the SSID Name and password for your LAN or mobile hotspot.
  4. Run mbed deploy in the cmd line to download the libraries.
  5. Connect the Nucleo board to the PC and run mbed compile -f (this should flash the program to the device, you should see the RGB LED in the Nucleo Board flash).
  6. Connect the RGB LED to pins PB_2(red), PB_15 (green) and PB_1 (blue) (Check pin layout here. 1
  7. Debugging
    1. Use Tera Term to see the serial output of the device. (Baud Rate 115200)
    2. Use the Mbed Device Connector Website and the Console to observe the resources.

Application Configuration.

  1. Open the m2A_PythonApp.py file.
  2. Get the Token from mbed Device Connector
    1. Go to [mbed Device Connector] 12 and log in with your mbed account.
    2. On mbed Device Connector, go to My Applications > Access keys, and generate Access Token and copy it into the token variable.
  3. Get the endpoint name of your device
    1. On [mbed Device Connector] 12, go to My Devices > Connected Devices, and you should see a device listed in the table.
    2. Copy the name in the list on the endpoint variable of the file
  4. On the root of the folder, run python m2A_PythonApp.py in the terminal.

Setup Bridge Connector.

Follow this Project from Mbed Team to connect Mbed Device Connector with AWS. Skip Section Getting the sample application on your device. Follow the rest of the steps to generate the AWS credentials and setup the Docker Application. For a device registered in Mbed Device Connector, the Bridge Connector creates and registers a device in IoT AWS and publishes and subscribes to a set of MQTT Topics that allow you to interact with the Mbed Device. You can subscribe to the “mbed/#” to subscribe to all topics created by the Bridge Connector.

Cloud Actions

To set the actions in the AWS cloud you have to be familiar with AWS IoT Rules and AWS IoT Actions. We also have to create a Lambda function for the comfort prediction. To learn more about how to setup the Lambda function, read the Lambda AWS Documentation and follow the Quiklab Tutorial and here on how to create a lambda function. In section 2.2.4 of the report, I show the Topics created by the Bridge Connector to which messages from the Mbed device get to AWS IoT

  1. Email Alert when motion is detected
    1. Topic Filter: the notification Topic of the motion resource.
    2. Condition: equals true
    3. Action: trigger SNS AWS
  2. Store temperature in DynamoDB
    1. Topic Filter: the notification Topic of the motion resource.
    2. Action: trigger DynamoDB
  3. Comfort Zone Prediction
    1. Train ML Model: follow this example by AWS if you are not familiar on how to.
      1. Go to .\SmartHome\m2A_CloudResources\ML_DataSets and use EXL_TA_RH.csv to create your Model.
      2. Select all variables as numeric
      3. Select ‘ASH’ as the target
      4. When Generated find the
    2. Create Lambda Function:
      1. Activate real-time predictions
      2. Create a function from scratch
      3. Copy the code from file LambdaFunction_PredML.txt in ./MbedToAWS\m2A_CloudResources
      4. Find the ID for your model and substitute it in the code.
    3. AWS IoT Rule.
      1. Topic Filter: the notification Topic of the current conditions prediction resource.
      2. Action: trigger Lambda Function.

ML Dataset

The .\MbedToAWS\m2A_CloudResources\ML_DataSets folder contains the Files from the ASHRAE project and the python scripts to manipulate the data using the csv Library.

  1. 1_merge.py : merges all 52 files together, adds a climate field, fixes the times column and clears the files with dots.
  2. 2_select.py: for a given excel, selects specific columns. To choose columns select the fields from “headers/categ_cl.csv” that you want to select and put them in “headers/categ_sel.csv”
  3. 3_delete.py: For a given excel, deletes the rows that have a missing value.

iot_system's People

Contributors

smysergio avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.