- 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.
推薦閱讀
- 辦公軟件高級應(yīng)用實用教程
- Excel讓辦公如此簡單
- Word/Excel/PPT 2013辦公應(yīng)用從入門到精通
- Excel 2007數(shù)據(jù)處理與分析范例應(yīng)用
- Office 2016三合一職場辦公效率手冊
- WPS Office商務(wù)辦公從新手到高手
- Office 2016入門與提高
- Excel 2019公式、函數(shù)應(yīng)用大全
- Excel 2013超級應(yīng)用大全(實戰(zhàn)案例版)
- 我的世界:Minecraft模組開發(fā)指南
- 和秋葉一起學(xué):秒懂WPS文字處理
- Power BI企業(yè)級分析與應(yīng)用
- Excel市場分析應(yīng)用之道
- 掌中寶:Word辦公應(yīng)用技巧
- 精P之道:高效溝通PPT