hello everyone in today's video we'll 大家好，在今天的视频中，我们将
connect an iot device
a raspberry pi in our case to aws's 在我们的案例中将物联网设备和树莓派连接到 aws 的
ecosystem 生态系统物
iot core to be specific so in this video 联网核心，因此在本视频中
first we'll look at an introduction to 首先我们将介绍
all the technologies we'll use in 我们将在今天的视频中使用的所有技术，
today's video
including aws iot core internet of 包括 aws iot 核心
things 物联网
and mqtt then we'll look at the 和 mqtt 然后我们将看看
architecture of today's demo 今天演示的架构，
and also we'll take a peek at all the 并且我们将看看
steps we need to take 我们需要采取的所有步骤
in order to connect an iot device ，以便连接物联网设备，否则我们最终将其称为物联网设备
otherwise known as a thing
finally we'll get on to the interactive 将继续进行交互式
demo in which we'll connect 演示，在该演示中我们将
raspberry pi to aws iot core and send raspberry pi 连接到 aws iot 核心
messages back and forth 并来回发送消息，
so let's look at the introduction first 所以让我们先看看介绍，
we'll talk about iot so iot or internet 我们将讨论 iot，因此 iot 或
of things is a system 物联网是一个系统
of a bunch of devices working in 在今天的视频中，
conjunction with each other
all of the device and the sensors can 所有设备和传感器都可以通过
kind of talk to the cloud 某种连接与云通信
through some kind of connectivity in ，
today's video
we'll use our iot device which is the 我们将使用我们的物联网设备，即
raspberry pi 树莓派，
and make it talk to aws iot core service 并使其与 aws 物联网核心通信 服务
so aws iot core is a cloud service 如此 aws iot core 是
provided by amazon's cloud ecosystem 亚马逊云生态系统提供的云服务
and it lets you easily interact with ，它让您可以轻松地与连接的设备进行交互。
connected devices
it's scalable as with most cloud 它与大多数云服务一样具有可扩展性，
services
because it can support billions and even 因为它可以支持数十亿甚至数
trillions of messages 万亿条
the aws iot message broker 消息 aws iot 消息代理
implementation
is based on mqtt so let's see what that 实现基于 mqtt 所以让我们看看 那
is 就是
mqtt stands for message queuing mqtt 代表消息队列
telemetry transport 遥测传输
and it's a lightweight messaging ，它是一个轻量级消息传递
protocol used in aws iot core 协议，用于 aws iot 核心，
to interact with other devices which in 用于与其他设备进行交互，在
this case is the raspberry pi 这种情况下是树莓派，
so let's see how it actually works so 所以让我们看看它实际上是如何工作的，所以
mqtt would be the broker in this case 在这种情况下 mqtt 将成为代理
and input devices or devices that can 和 输入设备或可以提供输入的设备
give an input
would publish data to the broker or mqtt 会将数据发布到代理或 mqtt，
then output devices or input and output 然后输出设备或输入和输出
devices 设备
will subscribe to a certain topic in the 将订阅代理中的某个主题，作为
broker and in return
the broker or mqtt would publish data 回报，代理或 mqtt 会将数据发布
to the output device or the input output 到输出设备或 输入输出
device here's an example 设备这里是一个示例
temperature sensor could send out 温度传感器可以将
temperature data to the broker 温度数据发送到经纪人
or mqtt and the nest thermostat 或 mqtt 和巢热水瓶
that has subscribed to the service uses 已订阅该服务的 tat 使用
this information 此信息
to turn on or off based on the 根据温度打开或关闭
temperature
another implementation could be a gps 另一个实现可能是 gps
location tracker 位置跟踪
that can tell nest if the owner is 器，它可以告诉 Nest 所有者是
inside the house or outside 在屋内还是屋外，
and based on that nest can also take a 并且基于该鸟巢也可以
decision of turning on or off the ac 做出决定 在打开或关闭交流
unit a motion detection sensor right 单元时，此处的运动检测传感器
here
publishes information to the mqtt broker 会向 mqtt 代理发布
that motion was detected and a cctv 检测到运动的信息，闭路电视
camera 摄像机
can start recording the video footage 可以开始录制视频片段
and finally a soil moisture detection ，最后土壤湿度检测
sensor 传感器
can publish moisture data to mqtt broker 可以向 mqtt 代理发布水分数据，
and the sprinkler will subscribe to that 然后 喷水器将订阅该
topic and that'll take 主题，并根据需要采取
action as needed all right let's see the 行动让我们看看
architecture of today's demo 今天演示的架构，
so we'll configure aws iot core to 因此我们将配置 aws iot 核心以
create new certificates 创建新证书
and attach policies to them so that 并将策略附加到它们，以便
anonymous users will be able to access 匿名用户能够访问
iot core iot core
with the right certificates then we'll 和正确的证书然后我们
copy the certificates onto our raspberry 将证书复制到我们的树莓
pi 派上
and write a small python program that 并编写一个小的 python 程序来
publishes messages 发布
as well as reads the messages finally 消息 除了最终读取消息之外，
it can also subscribe to the messages 它还可以订阅消息
and read them too 并读取它们，
so ideally we should be sending actual 因此理想情况下，我们应该发送实际
data 数据，
such as temperature sensor data but in 例如温度传感器数据，但在
this video we'll send 此视频中，我们将来回发送
a simple text message back and forth and 一条简单的文本消息
the last thing we'll do before the demo ，最后一件事 我们将在演示之前
is check out what steps we have to take 检查我们必须采取哪些步骤
in order to successfully connect our aws 才能将我们的 aws iot 核心成功连接
iot core
to raspberry pi every input output iot 到树莓派，每个输入输出 iot
device is called a thing 设备都称为一个事物
and we have to register all the things ，我们必须注册所有事物，
then we can download our iot core 然后我们可以下载我们的 将物联网核心
certificates onto the raspberry pi 证书放到树莓
we then need to configure a cognito to 派上，然后我们需要配置一个 Cognito 以
allow 允许
anonymous users with certificates 匿名用户使用证书，
then we'll create and associate some 然后我们将创建并关联一些
policies
after that we'll make a python program 策略，然后我们将制作一个 python 程序
to connect these two 来连接这两个
and finally we'll subscribe to all the ，最后我们将订阅所有
topics and publish 主题并
messages with our python program so 使用我们的python程序发布消息，所以
let's implement these steps 让我们实现这些步骤，
so the first thing we're going to do is 所以我们要做的第一件事就是
register an iot core 注册一个物联网核心
thing which is the raspberry pi in this 东西，在这种情况下是树莓派，
case
so i'll go to my aws iot core 所以我会去 我的 aws iot 核心
and let me sign into my console ，让我登录到我的控制台
and okay so here it is iot core ，好的，所以这里是 iot 核心
and it'll redirect me to aws iot ，它会将我重定向到 aws iot，
so here i can register an iot 因此我可以在这里注册一个物联网
thing so i'll go to manage and go to 事物，因此我将去管理和处理
things 事物，
and i'm going to press register a thing 然后我' 我要按注册一个东西
because we want to register a new one 因为我们想注册一个新的
if you're making a product and you want 如果你正在制作一个产品并且你
to apply the same certificates to 想将相同的证书应用到
hundreds of different devices 数百种不同的设备
you can bulk register many aws iot 你可以批量注册许多 aws 物
things 联网东西
but i'm only going to register one 但我只会 注册一个
raspberry pi so i'll say create a single 树莓派，所以我会说创建一个单一的
thing 东西
and now you can add your device to the ，现在你可以将你的设备添加到
thing registry so i'll call mine 事物注册表，所以我会调用我的
raspberry pi 树莓派，
because i'm using the raspberry pi 因为我使用的是树莓派
and pretty much everything you can just 和几乎所有你可以
keep default 保持默认的东西
and i'll press next i'm just going to ， 我将按下下一步 我将
use the one click certificate 使用一键式证书
creation so i'm just going to press 创建，所以我将按下
create certificate 创建证书
and we need to download all of these the ，我们需要下载所有这些
public key the private key 公钥、私钥
and just the regular certificate for 和这件事的常规证书，
this thing so i'll press 所以 我会按
download and then download download 下载然后下载下载
and the last thing you'll need to 和最后一个 您需要
download is a root ca for aws 下载的是 aws iot 的根 ca，
iot since it uses ssl we'll need to 因为它使用 ssl 我们需要
securely connect raspberry pi to aws iot 将 raspberry pi 安全地连接到 aws iot，
so i'll just press download here and 所以我只需在此处按下载，
this has changed in 这在去年发生了变化，
the last year so it takes us to our 因此需要我们 到我们的
amazon documentation and since i'm using 亚马逊文档，因为我正在使用
amazon trust services 亚马逊信任服务，
i'm going to download this one so i'll 所以我要下载这个，所以我会
click it 点击它，
so here we have a root ca certificate 所以这里我们有一个根 ca 证书
and i can just say file and then save ，我可以说文件，然后将
page as 页面另存为
and it'll save it as a certificate file 将它保存为我们的证书文件
for us so i'll go to my correct folder ，所以我将转到我正确的文件夹
raspberry files here we go and i'll call raspberry 文件，我们开始，我将其称为
it
root dash ca root dash ca
dot pem not dot pem 不是
pem okay now let's save it and then it pem 现在让我们保存它然后它
just saves it for us 只是为我们保存它
and since i need to copy these three ，因为 我需要将这三个
files into my 文件复制到我
right folder i'll just say show in 正确的文件夹中，我只是说在
finder finder
and that'll open up the folder for me so 中显示，这将为我打开文件夹，所以
here we have 这里我们有
our keys so i'll just select 我们的密钥，所以我只需选择
this and then copy them and then i'll 它，然后复制它们，然后我' 我
just paste them into 只是将它们粘贴到
my folder and here it copied both of 我的文件夹中，在这里它复制了它们两个，
them
but it's missing one it has the keys it 但缺少一个它有
just needs the certificate so i'll open 它只需要证书的密钥 所以我
this in finder also 也会在 finder 中打开它
and i believe it shows it here yes we'll ，我相信它会显示在这里 是的，我们将
copy this 复制它
and we'll paste it into here okay ，然后将其粘贴到此处
so now we can rename all these files
so i'll just take out the device id of 的
these so that it looks a bit nicer 这些，以便它
here we'll just take that out and it'll 在这里看起来更好一点，我们将把它去掉，它
just be public and private.pem.key 只是 public 和 private.pem.key
okay and this is optional i'm just 好的，这是可选的，我只是
taking it out so that it's easier for us 把它去掉，以便我们以后更容易
later on now we'll want to take these 现在我们要获取这些
local files 本地文件
and push them to our raspberry pi and to 并将它们推送到我们的树莓派，为此
do that
i'm going to use filezilla here we go 我将在这里使用 filezilla 我们去
filezilla is an ftp client and it helps filezilla 是一个 ftp 客户端，它可以帮助
you 您
upload and download files what from one 将文件从一台服务器上传和下载
server to another in this case 到另一台服务器 在这种情况下，
it's our macbook to the raspberry pi 它是我们的 macbook 到 raspberry pi
so i'm going to connect to my raspberry 所以我要连接到我的树莓
pi i've already configured all the 派我已经配置了所有
details 细节
so i'm just going to press connect and 所以我只是要按连接
it's connecting to my raspberry pi 它正在连接到我的树莓
all right now it connected to our 派 现在它已连接 到我们的
raspberry pi so i'm just going to 树莓派，所以我只是要
drag over the files but first i want to 拖过文件，但首先我想
create a new
directory in my raspberry pi so i'll 在我的 rasp 中创建一个新目录 berry pi 所以我会
right click and say create directory and 右键单击并说创建目录，
the
directory name is going to be aws iot 目录名称将是 aws iot
and then i'll press ok so it creates our 然后我会按确定所以它现在创建我们的
directory 目录
now i just have to go into that folder 我只需要进入那个文件夹
uh
yeah there it is okay so i'll double 嗯是的，没关系所以 我会
click to go inside 双击进去
and here we're in the folder now so now ，现在我们在文件夹中，所以现在
i can take 我可以把
my files all these four files 我的文件所有这四个文件，
so i'll just select them and then drag 所以我只需选择它们，然后将
them over into here 它们拖到这里
and there it transferred into our 和那里它转移到我们的
raspberry pi okay that worked 树莓派 好的，工作
alright so we've completed steps one 正常，所以我们已经完成了第一到第三步，
through three
now we have to create a cognito and 现在我们必须创建一个认知和
associate policies 关联策略，
so let's do it alright so i'll go back 所以让我们做吧，所以我会回到 aws
to aws
and i'm actually going to create a ，我实际上要先创建一个
policy first because we have to 策略，因为我们已经
associate some stuff 关联一些东西，
so i'll go to secure and policies 所以我会去安全和政策
and right now i don't have any so i'll ，现在我没有，所以我会
create a policy
for the name it can be anything i'll 为这个名字创建一个政策它可以是任何
just call it raspberry pi policy 我称之为树莓派政策
and actions and actions will just tell 和行动和行动将 只需告诉
what kind of actions the policy can do 策略可以执行哪种操作
for example publish or subscribe to a ，例如发布或订阅
topic if i wanted to i could just 如果我想，我可以
individually say publish and subscribe 单独说发布和订阅，
but i'll say iot 但我会说 iot
colon star that'll just say it can do 冒号星，它只会说它可以做
anything
and everything and it creates an arn for 任何事情，它为我们创建了一个 arn，
us
so instead of just doing one specific 所以我不只是做一个特定的
errand 差事
i'm gonna give it access to anything by 将通过说星号来授予它访问任何东西的权限
saying star
and then for effect i'll say allow and ，然后实际上我会说允许，
now we can create our policy 现在我们可以创建我们的策略
and here it shows us we created our ，在这里它向我们显示我们创建了我们的
policy so we've created a policy 策略，所以我们已经创建了一个策略，
but now i need to associate it with my 但现在我需要将它与我的
certificate and associate this 证书并将此
certificate to my thing which is the 证书关联到我的东西，即
raspberry pi 树莓派，
so i'll go to certificates and here we 所以我会去证书，这里我们
have our certificates 有我们的证书，
so i'll right click and say attach 所以我会右键单击并在此处说附加
policy 策略
here we can attach our created policy ，我们可以附加我们创建的策略
which is raspberry pi policy ，即树莓派策略
and i'll press attach and we also want ，我 将按附加，我们
to attach a thing to it which is 还想附加一个东西，它是
our raspberry pi device so i'll press 我们的树莓派设备，所以我将按
attach 附加
and yes now it's connected to our policy ，是的，现在它已连接到我们的策略
and our iot device and now before 和我们的物联网设备，现在在
creating an 创建
incognito i'm going to activate my 隐身之前，我要激活 我的
certificate 证书
so now it's activated and now we can 所以现在我 t 已激活，现在我们可以
create a cognito 创建一个 Cognito，
so how i'm going to do that is by going 所以我将通过访问服务和 Cognito 来实现这一点，
to services
and cognito so i'll just search it 所以我将在此处搜索它，
right here so i'll open it in a new tab 然后在新选项卡中打开它
and it'll take us to our amazon cognito ，它会带我们去 对于我们的 amazon cognito
here we're going to manage our identity 此处，我们将管理我们的身份
pools and create a new federated 池并创建一个新的联合
identity 身份，
so i'll press create new identity pool 因此我将按创建新身份池
and for the name ，对于名称，
i'll call it aws identity pool 我将其称为 aws 身份池，
okay and i'm just going to enable access 好吧，我将要启用 访问
to unauthenticated identities 未经身份验证的身份
and everything else should be default so 和其他一切都应该是默认的，所以
i'll just press create pool 我只需按创建池
and it's creating it for us ，它就会为我们创建它，
okay so it we can view the details 这样我们就可以查看详细信息
and what i'm gonna do is for the role ，我要做的是角色
summary i'm gonna 摘要，我
the bottom one i'm going to view the 要去底部 一个我要查看
policy document 政策文件
and here it shows us the policy now i ，在这里它向我们展示了政策，现在我
want to add the resource arn 想添加
of my thing so i'll press edit 我的东西的资源，所以我会按编辑
and i'll just press ok so now we can ，我会按确定，所以现在我们可以
edit it 编辑它
and in here in the resource we'll add 并在这里 在资源中，我们将
the arn 添加 arn，
so i'm going to go back to aws iot and 因此我将返回 aws iot，然后
i'll go to my things and we can see the 我将查看我的东西，我们可以在其中看到
ar in here ar 在这里，
we just click it and then here's the arn 我们只需单击它，然后这里是 arn，
we'll just copy 我们将
all the way to raspberry pi there we go 一路复制到 raspberry pi 那里我们去
and i'll go back here and inside ，我会回到这里，在
resource 资源中
we'll paste it 我们将粘贴它
now we can press allow and it'll create 现在我们可以按允许它会创建
it for us 它 对我们来说，
it says successful and now we can just 它说成功了，现在我们可以
go back to aws iot and continue 回到 aws iot 并继续
all right so we've associated our policy 一切正常，所以我们已经关联了我们的策略
and created a cognito 并创建了一个 Cognito
now we're going to create a python 现在我们将创建一个 python
program to subscribe to a topic 程序来订阅一个主题
and publish data so this is the page 并发布数据所以这 是
that i kind of used as the skeleton for 我用作 python 程序框架的页面，
my python program
it's just amazon's documentation on 它只是亚马逊关于
a little python program with mqtt mqtt 和 aws iot 的小型 python 程序的文档，
and in aws iot so here's kind of the 所以这里是
most of the code that i'm going to use 我将要使用的大部分代码，
and yeah let's remote into our raspberry 是的，让我们远程 现在进入我们的树莓派，
pi now
so that we can code it so here's my vnc 以便我们可以对其进行编码，这是我的 vnc
viewer and i'm going to remote into my 查看器，我将远程访问我的
raspberry pi 树莓派
okay so it's asking me for passwords so
i'll just enter it in
and here now we have a raspberry pi and
i've already created a file here 我已经在这里创建了一个文件
aws iot core dot pi and i'll show you aws iot core dot pi，我将向您展示
the folder structure 文件夹结构，
so in home slash pi i have a folder 所以在主斜杠 pi 中，我有一个名为 aws iot 的文件夹
called aws iot
and inside of that i have all of the ，在其中我拥有所有
certificates and my python program 证书和我的 python 程序，
all right so first i'll paste in the 所以首先我将粘贴
imports we're just importing time 导入，我们只是导入时间
and the aws iot mqtt client 和 aws iot mqtt 客户
all right now i'm going to paste in the 现在一切都好 我将粘贴
rest of this code so 此代码的其余部分 所以
here this might look a little 在这里这可能看起来有点
intimidating but it's easy once you 吓人但是一旦你想到它就很容易
think about it
so here we're just connecting to a 所以在这里我们只是连接到一个
client this is just a random key 客户端 这只是一个随机密钥
i just called it reshub client id but 我只是 将其称为 reshub 客户端 ID，但
you can really call it whatever you want 您实际上可以随心所欲地调用它，
so here we're configuring the endpoint 因此我们正在配置端点
it this is the ，这
default port number for ats and we 是 ats 的默认端口号，我们
actually have to configure the endpoint 实际上必须配置端点，
so what i'll do is i'll go to aws iot to 因此我要做的是我会去 到 aws iot
get the endpoint 获取端点，
so i'll go here and it's in settings so 所以我会去这里，它在设置中，所以
i'll go to settings 我会去设置
and here we have our endpoint so i'll ，这里我们有我们的端点，所以我
just copy this 会复制这个
and i'll put it in my code ，我会把它放在我的代码中
here now we have the endpoint and now ，现在我们有 端点，现在
we're configuring the credentials 我们在这里配置凭据
here we have our root ca permission file ，我们有我们的根 ca 权限文件
and the private key and the certificate a 找到私钥和证书
file 文件
so let me go to the folder to show you ，让我转到文件夹，在这里向您展示
here we have the private key 我们有
the root ca permission file 私钥、根 ca 权限文件
and the certificate file we're all we're 和证书文件
using all these in our python code
so let's go back and 回来，
all of this is just trying to connect to 所有这一切只是试图连接到
the
aws iot core and then it's just printing aws iot 核心，然后它只是打印
initiating iot core topic and it's 启动 iot 核心主题，
connecting if all this 如果所有这些
gets done correctly then it'll connect 都正确完成，它将连接
to 到
my mqtt so now i want to subscribe to a 我的 mqtt，所以现在我想订阅一个
topic 主题
how i'm going to do that is i said my 我将如何做到这一点，我说我的
mqtt client mqtt 客户端点
dot which is a variable we defined up 是我们在此处定义的变量，
here so i'm going to say that again 因此我将再次说
my mqtt client 我的 mqtt 客户端点
dot
and then subscribe because we want to ，然后订阅，因为我们想
subscribe to a certain topic 订阅某个主题
subscribe and then in that we can define subscribe 和 然后我们可以
the topic 定义主题
i'll say home 我会说主
slash hello world i'll just call the 斜杠你好世界我只会称这个
topic hello world 主题你好世界
we didn't define a topic yet but we will 我们还没有定义一个主题但是我们会
in a bit 在一点
and then i'm gonna pass in some more 然后我会传递一些更多的
parameters i'll add one 参数 我将添加一个
and hello world which is a function 和 hello world 这是一个
we'll define in a second 我们将在其中定义的函数 econd
hello world okay so now let's define hello world 好的，现在让我们
that hello world function so 定义 hello world 函数，所以
i'll put it at the top because we're 我将它放在顶部，因为我们
defining it down here 在这里定义它，
because we're mentioning it down there 因为我们在那里提到它，
sorry 抱歉，
so here i'll paste it in 所以在这里我将其粘贴到
and here it is so we're defining hello 这里 所以我们
world with these parameters 用这些参数定义 hello world
and then we're printing received message 然后我们打印
from aws iot core this is optional 从 aws iot core 收到的消息这是可选
and then we're printing the topic and 的然后我们打印主题
the payload which is the actual 和有效负载，
messages that was received from aws 这是从 aws
iot core all right now this code is iot core 收到的实际消息 现在此代码已
ready to run 准备好运行，
so i'll go to terminal to run our code 所以我将转到终端运行我们的代码
and first i need to get into the ，首先我需要进入
desired directory all right now we can 所需的目录，现在我们可以
run our code 运行我们的代码，
you might need to install a few packages 您可能需要安装一些软件包
and modules but i've already done all 和模块，但我已经 已经完成了所有这些
that ，
so i'll just say python3 aws 所以我只想说 python3 aws
iot core dot pi let me just check if iot core dot pi 让我检查这是否
that's the correct file name yep 是正确的文件名是的，
okay here we go let's run it 好的，我们开始吧，让我们运行它，
okay it's saying initiating iot core 它说启动 iot 核心
topic 主题
and then it just stopped the program ，然后它只是停止了程序，
alright it stopped because we didn't add 好吧 停止是因为我们没有
a loop to wait it just stops the program 向 wa 添加循环 它只是
after printing that so let's create a 在打印后停止程序，所以让我们创建一个
loop 循环，
i'll go back to my python code and let's 我将回到我的 python 代码，让我们
edit this 编辑
all right so after all of this 它，然后
we can create a while loop i'll just 我们可以创建一个 while 循环，我将它
paste it in 粘贴在
it's saying while true time dot sleep 它说 while 真正的时间点
for five seconds 睡眠五秒钟
wait i indented this okay there we go 等我缩进这个好的我们
now we can save this and let's run it 现在我们可以保存它让我们再次运行它
again
now it'll just keep waiting and it'll 现在它会继续等待它
have a five second break in between 之间会有五秒钟的休息
so let's just run that code again 所以让我们再次运行该代码
and now it's saying initiating iot core 现在它说启动物联网核心
topic and then it's just waiting 主题然后它只是在等待
that's because we don't have a we didn't 那是因为我们还
publish anything to iot core yet so 没有向物联网核心发布任何内容所以
let's do that 让我们这样做
so i've just resized my screen so that 所以我刚刚调整了我的屏幕大小以便
we can publish some data and see it on 我们可以发布一些数据 并在两个屏幕上都看到它，
both
screens so in aws iot core i'll just go 所以在 aws iot core 中，我只是
to test 去测试
and here we want to publish to a topic ，在这里我们想要发布到一个主题，
so the topic we specified in my python 所以我们在我的 python 代码中指定的主题
code
was home slash hello world 是主斜杠 hello world，
so we're just going to keep that topic 所以我们将保留它 主题
and the message should be aws 和消息应该是
hello from aws iot console you can make 来自 aws iot 控制台的 aws hello 您可以使
the
message anything you want but i'm just 发送任何你想要的消息，但我只是
going to keep it default 将它保持默认状态
and now i'll press publish to topic it ，现在我将按发布到主题，它
says published 说已发布
and here we go almost instantaneously ，在这里我们几乎
it showed the topic and it shows the 立即显示了主题，它显示了
payload 有效负载，
it's saying a message is hello from aw 它说消息是来自
aws iot console okay that worked aws 的 hello 物联网控制台可以
perfectly 完美运行，
so in this example we just printed a 所以在这个例子中我们只是打印了一条
hello world message but in real life hello world 消息，但在现实生活中的
project we would actually be doing some 项目中，我们实际上会做一些
actions such as turning on an ac 操作，例如打开交流电
or a motor or something like that i'm 或电机或类似的东西，我
not going to get too deep into it 不会得到太多 深入研究它
and we also published a message from iot ，我们还发布了一条来自 iot core 的消息
core
and it printed it here in a raspberry pi ，它在树莓派中打印出来，
now we're going to do the opposite we're 现在我们要做相反的
going to publish it from raspberry pi 事情，我们将从 raspberry pi 发布它
and it should print it in iot core ，它应该在 iot 核心中打印出来，
alright let's do that 好吧，让我们 这样做没问题，
all right so first i'll stop this 所以首先我会停止这个
program and then i'm gonna go to my code 程序，然后我要去这里我的代码
here
and now i want to publish the data to ，现在我想将数据发布到
aws io decor aws io 装饰，
so i'm just gonna comment out this 所以我只是要注释掉这个
and i'm also gonna comment out this line ，我也要去 注释掉这一行，
because i don't want 因为我不想要
uh the raspberry pi to subscribe to aws 树莓 pi 订阅 aws
iot core i want the opposite to happen iot core 我希望相反的情况发生，
now we can write our code for publishing 现在我们可以编写我们的发布代码，
so just
so that i know it's publishing some data 这样我就知道它正在发布一些数据，
i'm going to say print and publishing 我要说的是来自 rpi 的打印和发布
message from 消息，
rpi which is raspberry pi 这是树莓
that's just so that i know it's 派 我知道它正在
publishing 发布
and now i can see just like i said my ，现在我可以看到就像我说我的
mqtt client mqtt 客户端点
dot subscribe i can say the same for 订阅我可以说同样的
publish 发布
my mqtt client dot 我的 mqtt 客户端点
publish 发布
and then the parameters so inside here 然后参数所以在这里
i'll just paste this in here 我只是将它粘贴在这里
here this indentation is wrong give me a 这里这个缩进是 错了给我一
second 秒钟
okay so the first one is the topic again 好吧，所以第一个是主题，
it's home slash hello world 它是斜线你好世界
and then this is the quality of service ，然后这是服务质量，
if you want to change it you can check 如果你想改变它，你可以
out some documentation 查看一些文档，
i'm going to keep it as one and the 我将把它作为一个和
payload is again this is just the 有效载荷再次这只是
message 消息
this is in simple json format for the 这是简单的json格式的
message i'll say 消息我会说
message by rpi rpi的消息
and if you want you can you could you 如果你愿意你可以你
could add more parameters like some 可以添加更多参数，比如一些
sensor data or something like that but 传感器数据或类似的东西，但
i'm just going to keep it simple 我只是 打算保留 很简单，
so now we can save it and that should be 所以现在我们可以保存它，应该
it
okay so i've cleared my screen and i've 没问题，所以我清除了我的屏幕，我
again 再次
positioned these wind tabs and again 定位了这些风标签，再次
i've positioned these windows so that i 定位了这些窗口，以便我
can see both of them 可以
and before running our program i'm going 在运行我们的之前看到它们 程序 我将
to have to just like i subscribe to aws 不得不像我
i o decor from the raspberry pi 从 raspberry pi 订阅 aws io 装饰一样
i'm going to have to subscribe to the 我将不得不
raspberry pi from aws iot 从 aws iot 订阅 raspberry pi
so i'm going to say subscribe to a topic 所以我要说
up here and home slash hello world 在这里和家里订阅一个主题 slash hello world
i'll press subscribe and hear it 我将按下订阅并听到它
subscribe to our topic 订阅我们的主题
and now we can run our program ，现在我们可以运行我们的程序，
so python3 aws iot chord upi oh it's 所以 python3 aws iot chord upi 哦，它
giving us an error 给了我们一个错误，
let me check the code and oh yeah 让我检查代码，哦，是的，
here there's an extra bracket whoops 这里有一个额外的括号，哎呀，
okay let's save that and now we can run 好吧，让我们 保存它，现在我们可以
it again 再次运行它
now it should work okay 现在它应该可以正常工作
it's saying initiating and here it shows 它说正在启动，在这里它
the message 显示消息
message is message by rpa which is what 消息是 rpa 的消息，这是
we specified in the code 我们在代码中指定的
and it also said publishing message from ，它还说从 rpa 发布消息
rpa
okay that worked great we successfully 好，我们成功了
published messages back and forth from 已发布的消息和 从
aws iot core service aws iot 核心服务
and our raspberry pi using subscription 和我们使用订阅
topics 主题
in this video we sent a simple message 的树莓派发出，我们从树莓派向 iot 核心来回发送一条简单的消息
back and forth to iot core from our
raspberry pi
and real projects could have multiple ，实际项目可以
sensor data published through different 通过不同的主题发布多个传感器数据
topics
and event-based actions could be taken ，基于事件的操作可能是
by various subscriber devices 由各种订户设备拍摄，
such as turning ac on if the temperature 例如如果温度过高则打开交流电
is too high
i'll also post this code on one of my 我也会将此代码发布到我的
github repositories github 存储库之一
check it out if you want to download 如果您想下载此代码，请检查一下
this code thanks very much for watching
if you all had any doubts please comment 如果你们有任何疑问，非常感谢观看 请
down below i would love to help you out 在下面发表评论，
if you're stuck with any iot core or 如果您遇到任何物联网核心或
raspberry pi questions or issues please 树莓派问题或问题，我很乐意帮助您，
like subscribe all that jazz 请订阅所有爵士乐，
until then you can learn anything 直到那时您可以学到任何东西