当前位置:网站首页>Raspberry pie + AWS IOT introductory experiment
Raspberry pie + AWS IOT introductory experiment
2022-06-26 02:06:00 【DexterLien】
Preface
It's been a long time since I tossed the hardware , Turn over and eat ashes 1 Years of raspberry pie 3B Experience with AWS IoT Linkage of the Internet of things , Refer to official documentation :
https://docs.aws.amazon.com/iot/latest/developerguide/connecting-to-existing-device.html
AWS preparation
AWS IoT Communication with hardware depends on X.509 The certificate is encrypted and passed policy The policy of , So we need to AWS The console does the following preparations :
establish policy
open Amazon IoT Console , successively Security - Policies - Create policy

Add respectively iot:Coonect, iot:Receive, iot:Publish, iot:Subscribe Of Allow jurisdiction , For the convenience of experiment , resource No specific restrictions , direct * Pass through

establish thing
Create good policy Then go back to the left navigation bar All devices - Things - Create things

Because the experiment is just a device , So choose Create single thing

Name it , Note that this name cannot be modified , Others keep the default settings and continue

Select the recommended auto generate certificate

Check the... You just created policy continue

Download the certificate / secret key
Download the generated certificate and key file respectively , Note that public and private key files can only be downloaded from this interface , You can't download it after you close it , Need to regenerate new .

Altogether 5 File , Corresponding description :
| file name | explain |
|---|---|
| xxxx-certificate.pem | Equipment certificate , Used to bind to the target physical device |
| xxxx-private.pem | Private key |
| xxxx-public.pem | Public key |
| AmazonRootCA1.pem | Amazon trust services endpoint Root certificate (RSA 2048 bit) |
| AmazonRootCA3.pem | Amazon trust services endpoint Root certificate (ECC 256 bit) |
What will be used in this experiment is RSA 2048 bit Algorithm AmazonRootCA1.pem File as root certificate , You also need xxxx-certificate.pem Equipment certificates and xxxx-private.pem Private key , These three files will be used later . After downloading, click Done Close the pop-up window .
Go back to the bottom of the left navigation bar again Settings, Copy Endpoint The corresponding web address will be used behind the Notepad . IoT The preparation of the console has come to an end .
Hardware preparation
I don't remember the raspberry pie TF What's in the card , Direct use Raspberry Pi Imager Redrawn the latest version of Raspberry Pi OS Lite (32-bit), This version is based on Debian 11 Bullseye Demonic . SSH Connect to start the following operation :
# Replace the domestic image first
sudo sed -i 's|raspbian.raspberrypi.org|mirrors.ustc.edu.cn/raspbian|g' /etc/apt/sources.list
sudo sed -i 's|//archive.raspberrypi.org|//mirrors.ustc.edu.cn/archive.raspberrypi.org|g' /etc/apt/sources.list.d/raspi.list
# Update and install dependencies
sudo apt update
sudo apt upgrade -y
sudo apt install -y cmake libssl-dev git python3-pip
# Use bean petals pip Mirror image
pip config set global.index-url https://pypi.doubanio.com/simple
# install AWS IoT Device SDK
cd ~
pip install awsiotsdk
git clone https://github.com/aws/aws-iot-device-sdk-python-v2.git
# github If you have difficulty accessing, you can use the following gitee Image on
# git clone https://gitee.com/mirrors_aws/aws-iot-device-sdk-python-v2.git
Hello IoT World
IoT Communication uses MQTT agreement 1 The following test program will use MQTT Create a library called topic_1 The theme of , And send the 10 Messages to this topic .
MQTT(Message Queuing Telemetry Transport, Message queuing telemetry transmission protocol ), It's based on publishing / subscribe (publish/subscribe) Mode " Lightweight " Communication protocol , The agreement is built on TCP/IP Agreement on , from IBM stay 1999 Released in .MQTT The biggest advantage is , With very little code and limited bandwidth , Provide real-time and reliable message services for connecting remote devices . As a low cost 、 Low bandwidth instant messaging protocol , Make it in the Internet of things 、 Small equipment 、 Mobile applications are widely used .
First, put the first step in AWS Three certificates generated in the console / Upload the key file to raspberry pie ~/certs In the folder , It is convenient to rename later :
| file name | explain |
|---|---|
| certificate.pem | Equipment certificate , Used to bind to the target physical device |
| private.pem | Private key |
| AmazonRootCA1.pem | Amazon trust services endpoint Root certificate (RSA 2048 bit) |
/home/pi/certs/
├── AmazonRootCA1.pem
├── certificate.pem.crt
└── private.pem.key
call aws-iot-device-sdk-python-v2 Demo application included in , Pay attention to your-iot-endpoint Replace with the first step at AWS Console preparation final Settings The URL copied to notepad in
cd ~/aws-iot-device-sdk-python-v2/samples
python3 pubsub.py --topic topic_1 --ca_file ~/certs/AmazonRootCA1.pem --cert ~/certs/certificate.pem.crt --key ~/certs/private.pem.key --endpoint your-iot-endpoint
The following information is output successfully :
go back to AWS IoT The console checks the messages sent by raspberry pie , Left navigation bar : MQTT test client - Topic filter Input topic_1 - Subscribe, Subscribe again after the raspberry pie SSH Execute the above test procedure in , It can be observed that the console synchronously receives the Hello World news .
summary
This experiment only carried out the most basic physical equipment and AWS IoT Interconnected and through MQTT Protocol delivery / Receive a message , For practical application scenarios, more commercial hardware devices have been packaged with simpler configuration interfaces , The whole idea is the same , Mainly in AWS The console is well configured policy, Definition / add to thing, Create a certificate and associate it correctly on the device .
MQTT Protocol is introduced https://www.runoob.com/w3cnote/mqtt-intro.html ︎
边栏推荐
- One stop solution EMQ for hundreds of millions of communication of Internet of things
- How to set an achievable annual goal?
- Dataframe extracts data from a column and converts it into a list
- Record a weird picture upload problem
- 如何使用命令将文件夹中的文件名(包括路径)写入到txt文件中
- buffer
- Calibration...
- 連接投影儀
- 跨域问题的一种解决方案
- The first intimate contact of caching technology
猜你喜欢

shell学习记录(四)

Playful girl wangyixuan was invited to serve as the Promotion Ambassador for the global finals of the sixth season perfect children's model

关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法

Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou

NDK20b FFmpeg4.2.2 编译和集成

One minute to understand the difference between synchronous, asynchronous, blocking and non blocking

Abnova CSV monoclonal antibody solution

readv & writev

V4l2+qt video optimization strategy

One stop solution EMQ for hundreds of millions of communication of Internet of things
随机推荐
vs2015+PCL1.8.1+qt5.12-----(1)
如何使用命令将文件夹中的文件名(包括路径)写入到txt文件中
将lua print输出到cocos2d控制台输出窗口中
如何制定可实现中长期目标?
创建OpenGl窗口
字节序问题
Input 3 integers and output them from large to small
recvmsg & sendmsg
LeetCode 31 ~ 40
Pointnet/Pointnet++学习
Chrome浏览器开发者工具使用
Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
Redis-链表
VTK initialization code learning 1
SDRAM控制器——添加读写FIFO
Dazhou suggested that we media bloggers do these four things in the early stage
Use of static library and dynamic library
qtvtkvs2015测试代码
Disruptor (I) sequence
The first intimate contact of caching technology