- Learning AWS IoT
- Agus Kurniawan
- 135字
- 2021-06-30 19:26:06
How to work with the program?
Now we will review our program, comp-demo.js. The following is a list of steps for the program:
- Firstly, we apply the required library from AWS IoT SDK for JavaScript. Then, we declare our device based on our IoT thing from AWS IoT:
var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({
keyPath: 'cert/macos-computer.private.key',
certPath: 'cert/macos-computer.cert.pem',
caPath: 'cert/root-CA.crt',
host: 'xxxxxxx.iot.ap-southeast-1.amazonaws.com',
clientId: 'user-testing',
region: 'ap-southeast-'
});
- We try to connect to AWS IoT. After we are connected, we subscribe a specific topic, for instance, topic_1. Then, we send a message by calling the publish() function:
device
.on('connect', function() {
console.log('connected');
device.subscribe('topic_1');
device.publish('topic_1', JSON.stringify({ test_data: 1}));
});
- To receive an incoming message from AWS IoT, we listen to the message event as follows:
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
推薦閱讀
- Word/Excel/PowerPoint 2013三合一高效辦公超級手冊
- Word/Excel 2016高效辦公從入門到精通
- 用友ERP-U8(8.72版)標準財務模擬實訓
- 遠程辦公效率手冊
- Keynote:超越PPT的蘋果商業幻燈片(第2版)
- Word-Excel-PowerPoint 2007三合一辦公應用實戰從入門到精通(超值版)
- 新編電腦選購、組裝、維護與故障處理從入門到精通
- 從零開始學Arduino電子設計:創意案例版
- Office 2013中文版從入門到精通
- Word/Excel/PowerPoint三合一辦公應用
- PPT制作應用大全
- Excel高手捷徑 一招鮮 吃遍天
- 一看即會:新手學網上開店與經營(超值視頻教學版)
- 用圖表說話:Excel精美實用圖表大制作
- Word/Excel/PowerPoint三合一應用大全