Publish函数(Hi3861)+小程序端(shadow-query)

Hi3861学习笔记

Publish函数(Hi3861)

要发布一个信息,命名为’‘warning_state’',
首先需要在函数 IotPublishSample 里定义
.reportAction.subDeviceActionWarning = “warning_state”,
.reportAction.lightIntensityActionData = 1, /* 1 : safe */

hi_void IotPublishSample(void)
{
 /* reported attribute */
 WeChatProfile weChatProfile = {
     .subscribeType = "type",
     .status.subState = "state",
     .status.subReport = "reported",
     .status.reportVersion = "version",
     .status.Token = "clientToken",
     
     .reportAction.subDeviceActionWarning = "warning_state",
     .reportAction.lightIntensityActionData = 1, /* 1 : safe */
}

然后在配置文件src\applications\sample\wifi-iot\app\iottencent_demo\iot_profile.h
找到type WeChatProfileReporte, 加入以下两条语句:

typedef struct {
    int warningstateActionData;
    const char *subDeviceActionWarning;
}WeChatProfileReporte;

然后调用主函数里的IoTProfilePropertyReport函数进行上报。

小程序端(shadow-query)

通过调用云函数iothub-shadow-query来获取云端的影子设备信息,其中stateReported: deviceData.payload.state.reported即为转译过来的对应信息。例如:stateReported.warning_state即对应的上方publish的信息。

wx.cloud.callFunction({
      name: 'iothub-shadow-query',
      data: {
        ProductId: app.globalData.productId,
        DeviceName: app.globalData.deviceName,
        SecretId: app.globalData.secretId,
        SecretKey: app.globalData.secretKey,
      },
      success: res => {
        wx.showToast({
          icon: 'none',
          title: 'Subscribe完成,获取云端数据成功',
        })
        //JSON转译回来 成为deviceData
        let deviceData = JSON.parse(res.result.Data)

        this.setData({
          stateReported: deviceData.payload.state.reported
        })
        console.log("result:", deviceData)
      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值