当前位置:网站首页>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 ︎
边栏推荐
- Sweet cool girl jinshuyi was invited to be the spokesperson for the global finals of the sixth season perfect children's model
- Detailed explanation of memory leak check tools
- Ndk20b ffmpeg4.2.2 compilation and integration
- Easyexcel read file
- One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
- cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
- socket demo01
- Abnova CSV monoclonal antibody solution
- Connectez Le projecteur
- NDK20b FFmpeg4.2.2 编译和集成
猜你喜欢
随机推荐
Sweet girl lisixia was invited to be the little host of the global finals of the sixth season perfect child model
-- EGFR FISH probe solution
Visual studio 2013 redistributable is installed, but MySQL installation fails
其他代码,,vt,,,k
启牛推荐的证券账户安全吗?
qtvtkvs2015测试代码
字节序问题
Is the securities account recommended by qiniu safe?
17.11 std:: atomic continuation, std:: async in-depth discussion
如何高效的完成每日的任务?
Gun make (3) Rules for makefile
Differences and functions of export set env in makefile
树莓派 + AWS IoT 入门实验
The first intimate contact of caching technology
連接投影儀
关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法
关于strlen与sizeof的区别
如何制定可实现中长期目标?
Meaning of each state in TCP network communication
cv==biaoding---open----cv001








