FreeIOE开发文档
  • Introduction
  • 基础介绍
    • FreeIOE是什么
    • 名词解释
  • 开发引导
    • 开发入门
    • 环境搭建
      • 使用网关产品
      • 使用虚拟网关
      • 使用VSCode插件开发
      • 其他应用开发方式
    • 应用开发
      • 应用是什么
      • 快速构建应用
        • 数据采集
        • 数据上云
        • 边缘计算
        • 设备通讯
      • 深入理解应用
        • 应用本质
        • 从零构造
        • 应用配置可视化
      • 注意事项
      • 应用示例
    • 发布应用
      • 申请账户
      • 新建应用
      • 克隆应用
      • 应用打包
      • 应用上传
  • 接口文档
    • 应用接口
      • 应用基础类模块
        • 应用基础类
        • MQTT应用基础类
      • 系统接口
      • 基础接口
      • 设备对象
      • 统计接口
      • 日志接口
      • 事件类型和等级
      • 云配置接口
      • 云配置帮助接口
      • 数据通讯模块
        • 端口模块
        • 帮助模块
        • 端口超时封装
      • 工具类模块
        • 数据订阅计算
        • 数据拼接
        • 数据流缓存
    • 系统服务接口
      • 配置服务
      • 软件分发服务
      • 扩展管理服务
      • 应用管理服务
      • 缓存服务
    • 其它资料 & 文档
      • Lua语言学习
      • 二进制数据操作
      • 文件操作
      • 模块列表
      • IOE模块
      • 串口操作模块
      • 累计量计算模块
      • 工具模块
        • helper模块
        • leds模块
        • gpios模块
        • sysinfo模块
        • 周期计时模块
Powered by GitBook
On this page
  • 边缘计算
  • 要实现什么?
  • 构造边缘计算应用
  • 初始化计算模块
  • 数据计算
  • 示例代码

Was this helpful?

  1. 开发引导
  2. 应用开发
  3. 快速构建应用

边缘计算

Previous数据上云Next设备通讯

Last updated 5 years ago

Was this helpful?

边缘计算

此章将介绍如何开发一个边缘计算应用。此应用将根据其他应用采集到的设备数据,根据数据的当前值,来触发一个自动化控制策略。

要实现什么?

我们假设的场景是:

  1. 当温度传感器数据超过40度时,打开一个 DO 输出项(驱动风扇开关)

  2. 当温度传感器数据降低到30度时,关闭 DO 输出

构造边缘计算应用

local app_base = require 'app.base'

local app = app_base:subclass('EXAMPLE_CALC_APP_IN_GUIDE')
app.static.API_VER = 5

初始化计算模块

跟采集应用相比,我们在应用初始化时需要初始化计算模块:

function app:on_init()
    -- 计算帮助模块初始化
    local calc = self:create_calc()
end

数据计算

计算模块提供了监听方式的计算回调:

  1. 当所有所需数据就绪时,进行逻辑回调

  2. 当任一数据发生变化时,进行逻辑回调

function app:on_start()
    local source_device_sn = 'xxxxxxxxxxxxx.xxx'
    self._calc:add('unique_name_for_calc', {
        { sn = source_device_sn, input = 'temperature', prop='value'}
    }, function(temperature)
        if temperature > 40 then
            ---  turn the fan on
            self:control_fan(true)
            self._fan_on = true
            return
        end
        if self._fan_on and temperature < 30 then
            --- turn the fan off
            self:control_fan(false)
            self._fan_on = false
            return
        end
    end)
end

示例代码

local app_base = require 'app.base'

local app = app_base:subclass('EXAMPLE_CALC_APP_IN_GUIDE')
app.static.API_VER = 5

function app:on_init()
    -- 计算帮助模块初始化
    local calc = self:create_calc()
    self._fan_on = false
end

function app:on_start()
    local source_device_sn = 'xxxxxxxxxxxxx.xxx'
    self._calc:add('unique_name_for_calc', {
        { sn = source_device_sn, input = 'temperature', prop='value'}
    }, function(temperature)
        if temperature > 40 then
            ---  turn the fan on
            self:control_fan(true)
            self._fan_on = true
            return
        end
        if self._fan_on and temperature < 30 then
            --- turn the fan off
            self:control_fan(false)
            self._fan_on = false
            return
        end
    end)
end

function app:control_fan(on_off)
    local control_device_sn = 'xxxxxxxxxxxxxxxx.xxx'
    local device = self._api:get_device(control_device_sn)
    if device then
        local out_value = on_off and 1 or 0
        return device:set_output_prop('set_f', 'value', out_value)
    end
end

return app

FreeIOE 提供的应用基础类模块,提供了进行边缘计算的接口和功能。本章将基于此模块来构建应用。

手册
边缘计算