Notes: Getting Started with AWS IoT Services

(Illustration: Before setting up the Raspberry Pi, let’s have a raspberry cake and relax:p Image source: Photo by Josselyn Solorzano on Unsplash)

Notes taking about the video Getting Started with AWS IoT Services presented by Kevin Tinn and hosted by AWS Meetup Group (Denver) on August 5, 2020. (The meetup event page is here. The slide is here.)

Agenda

  • Overview of IoT Services
    • IoT Core
    • Greengrass
    • IoT Analytics
  • Raspberry Pi Setup
  • Demo: Communicating Directly with IoT Core
  • Connecting to cloud-based Data Pipeline
  • Configure Greengrass
  • Q&A


Repo Info

Overview of IoT Services

IoT Core

  • AWS IoT Core is a managed cloud service that lets connected devices easily and securely interact with cloud applications and other devices.
  • AWS IoT Core can support billions of devices and trillions of messages, and can process and route those messages to AWS endpoints and to other devices reliably and securly.
  • With AWS IoT Core, your applications can keep track of and communicate with all your devices, all the time, even when they aren’t connected.

Greengrass

  • AWS IoT Greengrass seamlessly extends AWS to edge devices so they can act locally on the data they generate, while still using the cloud for management, analytics, and durable storage.
  • With AWS IoT Greengrass, connected devices can run AWS Lambda functions, Docker containers, or both, execute predictions based on machine learning models, keep device data in sync, and communicate with other devices securely – even when not connected to the Internet.

IoT Analytics

  • AWS IoT Analytics is a fully-managed service that make it easy to run and operationalize sophisticated analytics on massive volumes of IoT data without having to worry about the cost and complexity typically required to build IoT analytics platform.
  • Data transformation and enrichment services that are optimized for IoT
    • Ad hoc query capabilities
    • Stored in time series database
    • Automated scaling

Raspberry Pi Setup

  • Format SD card
  • Extract OS
    • Use diskutil to get disk path using diskutil list
    • Mount disk using sudo mkdir /mnt && sudo mount -t msdos /dev/disk2 /mnt (please change /dev/disk2 to the result you got on previous step.)
    • Download OS
      • Noobs
      • Pi OS (Raspbian)
    • The openssh was not working in Pi OS in Kevin’s case.
  • Complete Pi setup and enable ssh
    • On the Pi: sudo raspi-config
    • Navigate to Interfacing Options and select P2 SSH
    • Restart the Pi: sudo restart
    • Get the hostname: hostname -I
    • Install vim: sudo apt install vim -y
    • Now we can connect to the Pi: ssh pi@your_pi_ip_address_here
  • Change the hostname on the Pi
    • sudo vim /etc/hostname –> change rsapberrypi to sensor-pi
    • sudo vim /etc/hosts –> uddate to 127.0.0.1 sensor-pi
    • sudo reboot

Demo: Communicating Directly with IoT Core

  • Create Policy:
    • IaC: Pulumi (repo)
    • or… Navigate to AWS IoT > Secure > Policies > Create:
    • Update the ARN to have the topic name we will use for sensor data
    • Name your policy, set Effect to Allow and Action to iot:*
  • Create IoT Core instance, create a IoT device, certificates, IAM policy, and attach policy to cert
    • Naviagate to AWS IoT > Manage > Things
    • Create > Single Thing
    • Name it and give it a type
    • Download the 3 certificate-related files (a certificate for this thing (device pem file, device.pem.crt), a public key, a private key (private.pem).)
      • Press the Activate button
      • Download the root CA file: curl https://www.amazontrust.com/repository/AmazonRootCA1.pem > AmazonRootCA1.pem
      • Put the thing pem and the private key files in the same dir as the CA file.
  • Associate the crtificate with the policy we created
  • Get your Thing Shadow: AWS IoT > Manage > Things > sensor-pi > Interact.
  • Copy the cert files to the sensor-pi using scp: scp AmazonRootCA1.pem priate.pem device.pem.crt pi@10.0.0.2:~
  • ssh into the sensor-pi: ssh pi@10.0.0.2
  • Verify openssl is available within python
    • python
    • import ssl
    • ssl.OPENSSL_VERSION
    • quit()
  • Get producer source code:
    • git clone https://github.com/kevasync/aws-meetup-group-data-services.git
    • cd aws-meetup-group-data-services/pi

Demo: Get Py MQTT lib and run producer

  • Setup AWS IoT Py SDK
    • mkdir sdk && cd sdk
    • curl -o aws-iot-sdk.zip https://s3.amazonaws.com/aws-iot-device-sdk-python/aws-iot-device-sdk-pythod-latest.zip
    • unzip aws-iot-sdk.zip
    • sudo python setup.py install
    • cd ..
    • cp -rf ./sdk/AWSIoTPythonSDK ./
  • Run the producer with your interaction url:
    • python pi-sensor-producer.py <identifier>-ats.iot.<region>.amazonaws.com

Demo: Connecting Sensor to Pi

  • Working with DHT22 digital humidity and temperature sensor.
  • Connect to sensor-pi and prepare it to get sensors readings in our pi-producer code
    • ssh pi@10.0.0.2
    • cd aws-meetup-group-data-services/pi
    • sudo apt-get update && sudo apt-get upgrade
    • sudo pip3 install Adafruit_Python_DHT
    • cp pi-sensor-producer.py pi-sensor-producer-dht22.py
    • vim pi-sensor-producer-dht22.py

Demo: Connecting to cloud-based Data Pipeline

  • Connect this sensor data to the data pipeline we created a few Meetups ago.
  • Create IoT rule with action to send data to Kinesis. AWS IoT > Acts > Rules.
  • There are multiple existing actions can be chosen from a long list.

(I skipped taking notes about the part about Kinesis.)

Configure Greengrass

Loading comments…