Overview

We will undertake the architectural design of an IoT solution through system analysis, integration, programming, and prototyping using industry standard protocols and tools. We will build upon the following components and technologies in the course of developing an end-to-end IoT solution.

IoT Definition

So what is the Internet of Things (IoT)?
One definition might be that IoT encompasses any sensor that can be controlled and is connected to the internet.

Another IoT Definition: http://www.mckinsey.com/industries/high-tech/our-insights/the-internet-of-things "In what's called the Internet of Things, sensors and actuators embedded in physical objects, from roadways to pacemakers, are linked through wired and wireless networks, often using the same Internet Protocol (IP) that connects the Internet."

So you can think of it as: a combination of a physical object + a controller/sensor/actuator + the Internet

Hardware/Sensors/Actuators

Most of the hardware in the course, other than the raspberry pi itself (like the Vilros Kit), is from Dexter Industries, which makes Grove Sensor Modules for the Raspberry Pi like the ones listed below that use the GrovePi+ Starter Kit:

Software

Python for writing scripts for the hardware control and following APIs:

Programming and Markup Languages utilized for Application development using the Meteor and bootstrap frameworks:

including exploring the HTTP protocols, especially in the context of using a REST-ful API.

Integration

Publishing data using Mosquito MQTT and also the Node-RED GUI utilizing:

The following diagram illustrates major components and data flow of a potential application using such sensors:

The Python code interacts with the sensors and will collect and publish the data using MQTT to a mosquito broker. Node-RED nodes will be used for integration flow and, on the receiving end,MongoDB and Meteor will be used to store and visualize the data, respectively. The main work will be with the temperature and humidity sensors but some of the additional sensors utilized can be sensors like:

We can leverage tools such as Node-RED to build flows utilizing built-in nodes to save time by not having to code from scratch. We can use Meteor to build a real-time app utilizing its rich collection of libraries and packages and use MongoDB for data collection and storage. We mainly concentrate on development and architecture and allow for additional projects to explore security, robust application development, and code optimization. In particular, a lack of strong security is a serious threat in IoT and exploring top IoT security concerns, standards, and tools would be a great extension.

Sample code for these new sensors would be like so:

IoT devices help shape the connected world but, even as we enjoy the benefits offered by this new technology, security concerns abound, as well. Currently, the key focus of these IoT devices is on making like easer and simpler which, unfortunately, usually results in sacrificing security. As more devices come online and more sensitive data is passed on the wire, this will become an increasingly important problem. Embedding countermeasures and following best practices from the beginning is the key to counter this trend. As the IoT market starts to explode, we hear about more and more IoT breaches every day. Investing in security measures is no longer just a should and has instead become a must. Some of the security concerns listed on cso.com are:

Insecure web interface

Insecure Cloud Interface

Insufficient Authentication/Authorization

Insecure Mobile Interface

Insecure Network Services

Insufficient Security Configurability

Lack of Transport Encryption

Insecure Software/Firmware

Privacy Concerns

Poor Physical Security

Some of the countermeasures include:

Password hardening

Two factor authentications

Role base access control

Logging

Network ports hardening

Ability to securely update

Data encryption (Rest and transit)

Fuzz tested

De-identify data

Securing physical access 9USB, Storage media etc..)




Module By Module Overview of Activities

Module 1

For the first week, you have to setup the Raspberry Pi and GrovePi+:

  1. First, you'll likely have to download the software to the SD card, so you can install the OS to the Raspberry Pi 3. You can get the software and installation guide from Raspberrypi.org, where you can also download NOOBS and RASPBIAN.

  2. You can optionally enable Wi-Fi on there
  3. Next, you'll have to install the Grove Pi software; you can use the software setup guide from dexterindustries.com and do the software update via something like:
    sudo curl -kL dexterindustries.com/update_grovepi | bash
    sudo reboot
    
  4. After rebooting, you can start working on the temperature & humidity sensor by following the instructions from the dexterindustries.com
  5. If you get -1 c and -1 % on the LCD screen, try placing the sensor on the different port D8 and change the code from 7 to 8 on this line, e.g.: dht_sensor_port = 7 # connect the DHT sensor to port 7
  6. If that doesn't work, you'll likely have to do a firmware update and reboot
  7. Next, you can run the Home_Weather_Display.py and see if you're getting correct readings for temperature and humidity, which you can convert from Celcius to Fahrenheit using F = C*9/5+32. You'll have to change the value that's printed within the loop at t=str(temp)

Module 2

The main goal for this module is to install MQTT on Raspberry Pi and send the sensor data from module one to http://test.mosquitto.org Some of the key activities will entail:

  1. Installing SSH and VNC on Raspberry Pi (ssh can be optional, I suppose)
  2. Installing the Mosquito message broker and testing messages (e.g., you might open two terminals and see if you can see a test "Hi there, I am the second terminal session" message on the second terminal)
    1. Install mosquitto server and start the local broker as a service or as a daemon: https://randomnerdtutorials.com/testing-mosquitto-broker-and-client-on-raspbbery-pi/ and https://theembeddedlab.com/tutorials/install-mosquitto-on-a-raspberry-pi/
    2. Start a command-line subscriber using mosquitto_sub to the local broker
    3. Start a command-line publisher using mosquitto_pub to the local broker
  3. Installing and testing the Paho Python client. This will involve creating a mqtt_test.py file and testing to see if you get a message like "Hi there, I am a python MQTT client".
    1. Then, you can start the Python publisher and test with the command-line subscriber
  4. Publishing data from project one to the remote broker http://test.mosquitto.org and test it locally using something like this command-line subscriber mosquitto_sub -h test.mosquitto.org -t "SCHOOL/COURSE/NAME/sensor/data/json" -v
  5. Publishing data that also has the Timestamp, Temperature, and Humidity
  6. Publishing data that is also in the JSON format.
  7. Publishing data to the topic SCHOOL/COURSE/NAME/sensor/data/json
  8. Subscribing to the published data and checking to see if the data is correct as well as checking for latency.

Module 3

Some of the key activities for week 3 are:

  1. Installing chromium-browser on the Raspberry Pi (optional)
  2. Installing Node-Red and required packages (dashboard package) on the Raspberry Pi
  3. Install and Update npm (install might be optional if it's already on there)
  4. Set Node-Red to auto start at every boot
  5. Check and test Node-Red by going to http://localhost:1880/
  6. Setup some nodes to read data from the MQTT broker as a subscriber and check values received via MQTT messages using a debugger node:
  7. Parse out the Temperature and Humidity values using custom JavaScript functions:
  8. Display the received and parsed Temperature and Humidity data in the dashboard:

Module 4

Some of the key activities for week 4 are:

  1. Install the Blue LED and the Potentiometer onto the Raspberry Pi
  2. Run the default led_fade.py program provided by GrovePI in the GrovePi/Projects folder to test the LED
  3. Move the potentiometer to see if the LED level changes
  4. Create a new program call led_fadeMQTT
  5. Use Node-Red to create a new flow called Blue LED control with three inject nodes pre-configured for the values On (255), 50% (128), and Off (0)
  6. Check and test the Blue LED flow by deploying it

  7. Setup the UI in the Node-red flow by adding a Slider UI Node; we can then access the UI from http://localhost :1880/ui/#/0 and control the LED on the Pi via either the Slider UI or the 3 Inject Nodes directly in Node-Red
  8. Add a POST Input HTTP node and a GET Input HTTP node to Set and Get the LED values respectively:
  9. Test the POST and GET interfaces by sending data to them using Postman. Also check the data by using the Ui and see the value on Postman

Module 5

Some of the key activities for Week 5 where we will create a web application using Meteor are:

  1. Install Chocolatey, a Windows package manager, on a Windows PC (we need to install this application before we can install Meteor)
  2. Once Chocolatey is installed, we can install Meteor using the command choco install meteor
  3. Now we can use Meteor to create a simple-todos app; let's first check the app by going to http://localhost:3000
  4. Modify the HTML code to create the Todo List as seen below:
  5. Setup mongoDB for the collection
  6. Use the command db.tasks.insert({ text: "Hello world!", createdAt: new Date() }); to check the mongoDB; this should add something like this:
  7. Modify the code to show the task list
  8. Modify the code to add the delete function in the app
  9. Modify the code to see incomplete tasks
  10. Modify the code to create a user account as follows:
  11. Add publish and subscribe functions to the app:

Module 6

Some of the key activities for week six are learning how to connect Node-Red to MongoDB and send the data to test the mosquito website:

  1. Installing Node-Red and required packages (dashboard package) on the Windows PC
  2. Install and Update npm on the Windows PC
  3. On the Windows PC, set Node-Red to auto start at every boot and Check and test Node-Red by going to http://localhost:1880/
  4. Test Node-Red connection to MongoDB
  5. Debug display of MQTT messages on Node-Red
  6. Setup a local connection to the raspberry Pi
  7. Run the program from Lab two to check the data
  8. Check to see if we are getting in Node-Red from raspberry pi
  9. Check meteor mongo for data
  10. Send data received from raspberry pi to test.mosquitto.org
  11. Install netifaces in Raspberry Pi

Module 7

In Week 7, we continue from Week 6 and will learn how to acquire sensor data from test.mosuitto.org using UUID and display the data to a new website we created using Meteor. Some of the key activities in week 7 are:

  1. Use Meteor to create a new IOT app
  2. Install bootstrap
  3. Remove insecure and autopublish
  4. Delete all of the project boilerplate files from the IOT folder
  5. Create dashboard.css in client folder
  6. Create html in client folder
  7. Create router.js in client folder
  8. Create main-layput.html in client folder
  9. Create topNav.html in client folder
  10. Create sideNav.html in client folder
  11. Create home.html in client folder
  12. Create dashboard.html in client folder
  13. Create sensor-table.html in client folder
  14. Create sensor-table.js in client folder
  15. Create collections.js in collections folder
  16. Create new flow in node-red
  17. Run new meteor software and check the webpage (http://localhost:3000/dashboard)

Module 8

This week we will focus on projects of interest so the weekly assignment is relatively light. This week's example demonstrates a generic IoT device architecture that supports dynamic reprogramming (at run time) using Node-RED. For example, we can setup a water detector where we'll use a water sensor for the raspberry pi (this is just a sample and you can pursue any variant you desire, of course!). The provided example features working with various GrovePi inputs and outputs, the creation of files using Python code, and Node-Red flows.

Some of the key activities for week eight will then be:

  1. Copy and clean the code samples from Module 8 example to be able to run the example as needed; this involves typing the code for ports.py, IoTDevice.py, and GroveDevices.py
    1. Note: the maximum value of the potentiometer is 1023 and the maximum value that can be recognized by the LED is 255
  2. Create new python file call water_sensor.py
  3. Install the water sensor to D2 on grovepi
  4. Power up the unit and test the water sensor
  5. Add example Node-RED and verify functionality

Once you get the interface face working, you can add things such as email alarms and a fancy web interface using Node-Red. Please remember, this water sensor project is just a sample and you're free to pursue your own completely different project this week!

Some Helpful Resources

Some Essential Tutorials

Learning Python Online

Here are some nice links for first learning Python:

What is a Full-Stack Developer

Full Stack Developer is familiar with all layers of software development:

What is a REST-ful API

REST is less robust than Simple Object Access Protocol (SOAP) but uses less bandwidth, which is a benefit for web applications.

A RESTful API (REpresentational State Transfer) is an architecture that has the following properties and usually builds upon HTTP:

  1. Client-server:
  2. Stateless:
  3. Cacheable, Layered System:
  4. Code on demand:
  5. Uniform Interface: things are required to make it a REST API or RESTful interface:

Tips for Cracking Technical Interviews

SNHU Tips for Cracking the Technical Interview

Tips for Approaching Tough Programs

Our class can get quite frustrating, especially for students who don't have an extensive background in programming. The best approach to dealing with issues and errors in such cases is to start with very simple but fully functional code and then slowly adding changes to avoid an accumulation of errors.

The overall approach I might recommend is:

  1. List the functionality of what you want the code to do
  2. Outline, in pseudocode or a bulleted list format only, the structure of your solution
  3. Then, implement only the first one or two things and ensure it's functional and runs without errors after each small change

If you still run into issues, the next step would be to search for the specific error online to see if there are helpful posts on stackoverflow or other such sites on the Web. If that fails, as well, you can post in the discussion forums online with the following:

  1. List what you're trying to do
  2. Post the specific code and also what you expected it to do
  3. Give the full error stacktrace and also your guess on what might be going wrong

Tips for Seeking Help: The First Step

Step 1: If you run into any problems at all, please start by searching for that issue on Google! You might be amazed at how almost all of the problems you come across were already asked and resolved on the web.

And, failing that, please post in our class forums. When you do post, please do feel free to include screenshots from the raspberry pi to help give details of the issue. Almost all of these hints are garnered from a combination of online forums, class forums, and voodoo programming. :)