- 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());
});
推薦閱讀
- 隨身查:從原始數據到完美Excel圖表
- Adobe Premiere Pro 2020基礎培訓教材
- Excel公式與函數從入門到精通
- Project 2010企業項目管理實踐
- 非常Easy:Excel財務高效管理
- 對比Excel,輕松學習Python報表自動化
- Office 2007辦公軟件應用立體化教程
- 精通Excel數據統計與分析
- Excel高效辦公:VBA范例應用(修訂版)
- PPT多媒體課件制作從新手到高手
- 中文PowerPoint 2003應用基礎
- 左手Excel右手Tableau數據分析可視化實戰案例視頻精講
- LoadRunner性能測試巧匠訓練營
- 電腦上網技巧現用現查
- 炫舞Power Point:PPT動畫創意設計