烟感器设备接入AWS IOT的一种方法

阅读: 评论:0

烟感器设备接入AWS IOT的一种方法

烟感器设备接入AWS IOT的一种方法

      最近和同事一起做了一个烟感器接入 AWS IOT 的Demo ,遇到一些问题,想记录下来,以备日后查阅。

需求:

1. 烟感器(WIFI方案)接入AWS IOT core 平台,APP端也接入AWS IOT 端。

2. 烟感器收发消息数据(jason格式)通过AWS IOT 与APP互动。

3.APP端可以控制烟感器端状态,并获取烟感器端的history Data.

环境:

1.device 端是使用的Free RTOS,下载AWS IOT 嵌入式C sdk

2.APP端 是IOS ,用的objective-C 开发。

3.注册AWS 账号(注意是Global Account),选择地域。

架构示意图:

一些要点:

1. 基于MQTT 3.1.1协议 通过Subscribe/Publish 进行消息订阅和发布。

2.以 $aws/*  开头的是AWS 预留主题$aws/things/SmokeSensor_Demo/shadow/update

3. 创建Things +Policy +Crt  注意policy 的权限设置。

一些实验:

1.      模拟Device接入AWS IOT

 

步骤:

1. 在AWS IOT 端创建Things +Policy +Crt ,并将root-CA,  ,Things.private.pem 下方给Device 端。

 2. Device 端配置接入。可以在此验证接入状态:

3. APP 端 通过AWS Cognito 的Identity pool 进行身份认证,然后调用AWS 的Device shadow RestfulAPI 进行subscribed/Publish .

4.  在Rule Engine 中进行操作,数据流:Device-->AWS IOT--->Rule --->Lambda---->SNS(Topic)--->APP(SMS/SES/APNS)

5. Lambda 配置示例:

console.log('Loading function');
    // Load the AWS SDK
    var AWS = require("aws-sdk");
    
    // Set up the code to call when the Lambda function is invoked
    exports.handler = (event, context, callback) => {
        // Load the message passed into the Lambda function into a JSON object
        var eventText = JSON.stringify(event, null, 4);
        
        // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console or in the CloudWatch Logs console
        console.log("Received event:", eventText);
        
    
        
        // Create a string extracting the click type and serial number from the message sent by the AWS IoT button
        var messageText = " CODensity is: " + event.state.desired.CODensity + "   BatteryCapacity is: " + event.state.desired.BatteryCapacity ;
        //CODensity is: undefined   BatteryCapacity is: undefined

        
        // Write the string to the console
        console.log("Message to send: " + messageText);
        
        // Create an SNS object
        var sns = new AWS.SNS();
        
        // Populate the parameters for the publish operation
        // - Message : the text of the message to send
        // - TopicArn : the ARN of the Amazon SNS topic to which you want to publish
        var params = {
            Message: messageText,
            TopicArn: "arn:aws:sns:us-west-2:71******1465:lambda-x-account"
         };
         sns.publish(params, context.done);
    };

 

6. Topic  示例:

7. device 端update 到"Reported": 字段 ,APP端从Reported 字段获取信息,并通过修改Desired 字段的参数值 来控制device 端的状态 。 device 端通过Subscribed  $aws/***/update/delta 来获取app端修改的值,然后在update 新的值 给Reported 字段。并重置Desired:null 

 

本文发布于:2024-01-31 02:28:22,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170663930324682.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:方法   设备   烟感器   IOT   AWS
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23