Take a smartphone that will emulate an IoT device with temperature, humidity and pressure sensors and send readings to the Amazon IoT platform. On the platform, we will establish a rule that upon receipt of data from our device will call a notification service, which in turn will send an e-mail with the received data.
Such a system, of course, carries little practical value, but it allows you to understand how everything works:
Why Amazon’s IoT Platform? And why do you need to understand how IoT platforms work?
M2M - IoT - IoE
There are more and more IoT devices in the world, both analytical agencies and world statistics speak about this.
We ourselves can clearly see that more and more systems are connected to the Internet and are controlled automatically or by people: smart homes, cars, wearable devices. And now they are talking not just about IoT, but about IoE (Internet of Everything), because devices that connect to platforms are used not only in industrial systems, but also by people.
Therefore, we need to understand the principles of work ourselves, at least in order to understand how you can effectively use your devices or what are the limitations and nuances of security.
Why amazon?
Amazon creates services taking into account global trends and as a result “universal” systems are obtained, the basic principles of which are used by all manufacturers. The cloud platform has an even bigger plus - this is the ability to deploy the system on your own in a couple of hours without involving corporate IT service and security)
Why a smartphone, not some IoT Starter Kit?
On closer inspection, the smartphone emulates the IoT device well:
- It has Linux on which to run applications;
- There is a mobile connection to the Internet;
- Using software, you can emulate sensor readings.
Those. working with a real IoT device will be no different from working with a smartphone, except for using a specific SDK to get sensor readings. All other communications will be similar.
Let me skip the section with standards, analytics and marketing research - at the end of the article I will give some relevant links. I’m eager to do something interesting)
AWS IoT Platform
Amazon draws a fairly clear diagram of its platform:
Here, in general, everything is clear:
- (1) There are devices that interact with the IoT platform using the SDK.
- (2) Devices send messages that are verified by the authentication and authorization service.
- (3) Messages arrive at Device Gateway using different protocols and then go to the rules handler (4.1) and are copied (4.2) to Device Shadows.
- (4.2) Device Shadows are digital doubles that store the current state of devices that are always available to applications. On the other hand, in the absence of communication with the device, Device Shadow executes control commands from applications and, when reconnecting, synchronizes the current state with the device.
- (4.1) Depending on the data received, the rules handler performs predetermined actions (5.1), for example, saves data in DB, sends SMS or e-mail notification, calls HTTP API, sends data to analytics system, etc.
- (5.2) Applications use this data to control and manage devices using the AWS API (6)
- Information on all devices is stored on the AWS IoT platform (7).
We begin to understand, the scheme is a little complicated:
Appear:
Jobs - perform standard actions on devices, for example, install applications, update firmware, reboot devices, etc.
Topics - the essence of the MQTT protocol. Messages from IoT devices are sent to specific topics.
IAM Roles - AWS users on behalf of whom the rules are executed and who have access to the necessary AWS resources.
Rules consist of:
- Filter - message filter for processing. Set as an SQL query.
- Action - the action to be performed.
- Role - one or more IAM roles.
Certificate - uploaded to the IoT device, with their help authentication of devices on the AWS platform occurs. Consist of:
- X.509 device certificate
- Private key
- AWS Root Certificate
Policy - policies are attached to certificates that determine what actions the device can perform. Policies authorize devices.
Details AWS services that receive information from the IoT platform: Analytics, DB, SNS notification service.
We connect the device
I will not fully give instructions on connecting the IoT device to the Amazon platform: Getting Started with AWS IoT . But to understand the scope of the task, I will list the steps that need to be taken in order for the scheme to work:
- Create my-iot-dev device on the platform
- We get the device certificate X.509, private key, public key
- Obtain the root certificate of the AWS platform (Root CA for AWS IoT)
- Create the my-iot-dev-policy policy. For our demos, we allow all actions: iot: *
- Attach the policy to the certificate
- Attach the certificate to the device
- As a result, we received a certificate with the device and policy:
- Create a rule. The rule will call the AWS SNS (Simple Notification Service) notification service to send e-mail. Therefore, you must first create a topic in AWS SNS (my-iot-dev-sns-topic):
- Now we configure what exactly this topic will do when receiving data. To do this, create a subscription to the topic (Subscribe to the Amazon SNS topic), enter the destination e-mail address, wait for the verification letter, confirm the e-mail.
Now create the rule itself (my_iot_dev_rule), which will call the created topic:
- Filter: SELECT * FROM 'my / dev-topic' - the filter is triggered when any message in the topic named 'my / dev-topic' is received;
- Action: sending a message to the previously created SNS topic “arn: aws: sns: eu-central-1: 1219xxx34064: my-iot-dev-sns-topic”;
- IAM role: create the my-dev-role role with access to SNS topics.
- All logical entities for our device are created. Now you can test that the scheme works theoretically. To do this, AWS has a test tool that allows you to send and receive messages similar to real devices. We launch it, subscribe to topic (my / dev-topic) and send a “Hello World!” Message:
- We check that the e-mail with the message “Hello World!” Has arrived and we conclude that the scheme works.
Smartphone Configuration
It's time to configure the IoT device, which will be my smartphone. To do this, use the AWS SDK JavaScript instruction . To turn a smartphone into an IoT device you need:
- Copy to device: private key, X.509 and “Root CA for AWS” certificates;
- Install Node.js and npm package manager;
- Install AWS SDK;
- Install and run the test program.
In our case, everything will be a little easier, because I put the certificates, AWS SDK and test program on GitHub and you can just clone the IoT-Sensors repository . If someone wants to use my test program, then they will need to put their certificates in the / IoT / certs directory and write in the / server / src / services / IoT-AOI-Server file the actual Rest API Endpoint:
device = deviceModule({ … host: 'a2lqo1xxx4zydi-ats.iot.eu-central-1.amazonaws.com', … })
The Rest API Endpoint is taken from the device settings:
If you want to try something standard, then you can use the test programs from the AWS SDK.
Android is the same Linux, but with its limitations, so to run JS applications you need to install a special terminal, for example, Termux .
For the initial development of Termux, there are a number of articles, for example: Launching a NodeJS application on Android . But by and large, after installing Termux, you need to execute only a few magic commands:
git clone https://github.com/AlexeySushkov/IoT-Sensors.git
Server installation
cd ~/IoT-Sensors/server npm install npm start
If everything went well, the line will appear in the terminal:
Server started on port: 8081
Live it looks like this:
Client Installation
cd ~/IoT-Sensors/client npm install npm run serve
If everything went well, the line will appear in the terminal:
App running at port: 8080
Next, in the smartphone browser, enter: http: // localhost: 8080
And a test application will appear on the screen:
Press the “INIT DEV” button. This authenticates and authorizes the IoT device on the AWS IoT platform. If successful, the status becomes “Init OK”.
Next, enter the values of the temperature, humidity and pressure sensors, for example:
Temperature: 23
Humidity: 65
Pressure: 787
And press the “SEND DATA” button.
After that, the application adds a timestamp and sends the data in the form of MQTT messages to the topic “my / dev-topic”. The IoT platform receives a message and activates a rule that sends a message to the AWS SNS notification service, which sends an e-mail with the received data in JSON format:
{"time":"Mon, 30 Sep 2019 13:54:52 GMT", "temperature":"23", "humidity":"65", "pressure":"787"}
If the message is sent successfully, then the status changes to: “publish OK” and an e-mail is sent to the mail:
The AWS IoT platform has a monitoring system that shows the number of connections and messages from IoT devices, statistics on protocols, message types, etc.:
So now everything is working for real!
Conclusion
We built a small but real IoT using a platform from Amazon. All platforms are built on the same principles, so if the question arises of choosing an IoT system, we will be ready to ask the following questions. And then, knowing the answers from Amazon, we can conclude how mature the platform is offered:
Devices
- How are devices added to the system?
- How is device authentication and authorization ensured?
- Does encryption of data sent to the platform occur?
Platform
- How are keys and certificates protected on the platform?
- How are the rules formed?
- What actions can the rules follow?
- How are devices monitored and managed?
- Are there any shadows (digital doubles) of devices on the platform?
- What reports and analytics are available?
Interaction
- What protocols are used to connect devices?
- How is the interaction of applications with the device?
- How is the interaction logic tested?
As promised, I will provide some relevant links to standards and analytics:
IoT Standards
Surprisingly, the standardization giants ( ISO / IEC , IEEE , ITU-T ) have lost interest in IoT after 2016. They, of course, are doing something, but somehow without a twinkle). NIST also released its Networks of 'Things' study, but after 2016 there is nothing more interesting.
Telecommunication institutes look better, which is not surprising since without connectivity, IoT is not an IoT. TM-Forum, under its umbrella, collects cases and projects of IoE & Digital Ecosystems , ETSI is easier and joined OneM2M .
And now we come to two organizations that were formed relatively recently, but already determine the world direction of IoT development:
OneM2M
OneM2M is an association of standardization organizations , telecommunication companies and manufacturers from different countries. They have dozens of relevant documents in the public domain that warm the soul with architectural models and functional diagrams .
IIC
IIC (Industrial Internet Consortium) - an organization for standardizing the industrial Internet of things - these are mainly manufacturers of software and devices . They also release their reference architectures. In general, there is where to look at the perfect world! )
IoT Analytics
All of our favorite analytic agencies release IoT research, but not all are freely available. As an example, I’ll give a few relevant articles that demonstrate optimistic forecasts for the development of IoT:
- Gartner, about IoT is in the article: 5 Trends Appear on the Gartner Hype Cycle for Emerging Technologies, 2019
It's only the beginning!