- Learning AWS IoT
- Agus Kurniawan
- 153字
- 2021-06-30 19:26:06
Building an AWS IoT program
After we have configured our AWS IoT and added the IoT device, we can develop a program to access AWS IoT. In this scenario, our computer is used as an IoT thing. We also used Node.js to access AWS IoT, so we need to install AWS IoT SDK for JavaScript. For testing, we will build a Node.js application to access AWS IoT for such purposes as connecting, sending, and receiving.
Now, create a file called comp-demo.js. Then, write the following Node.js scripts:
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-'
});
device
.on('connect', function() {
console.log('connected');
device.subscribe('topic_1');
device.publish('topic_1', JSON.stringify({ test_data: 1}));
});
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
Please change the path and certificate files from your AWS IoT on parameters such as keyPath, certPath, caPath, host, and region. Save this file.
推薦閱讀
- Articulate Studio Cookbook
- Excel函數辭典
- Excel 2010辦公應用實戰從入門到精通(超值版)
- PPT制作應用大全2019
- 非常Easy:Excel財務高效管理
- 新編Word/Excel/PPT 2016高效辦公三合一(全彩版)
- MATLAB技術大全
- Office 2003辦公軟件實用教程
- 巧學巧用Excel函數:掌握核心技能,秒變數據分析高手
- 一看即會:新手學網上開店與經營(超值視頻教學版)
- Word/Excel/PowerPoint三合一應用大全
- Excel市場分析應用之道
- 新編PowerPoint 2016從入門到精通
- Word/Excel/PPT 2007入門與提高
- Excel VBA應用案例速查手冊