当前位置:网站首页>odoo+物联网
odoo+物联网
2022-08-01 18:18:00 【姜振建 15954039008】
最好的框架ODOO+GO
IoT 驱动程序允许任何 Odoo 模块与连接到 IoT Box 的任何设备进行实时通信。与 IoT Box 的通信是双向的,因此 Odoo 客户端可以向任何受支持的设备发送命令并从其接收信息。
要添加对设备的支持,我们只需要:
- an Interface, 检测特定类型的连接设备( IoT Box)
- a Driver, 与单个设备通信
每次启动时,IoT Box 都会加载所有位于连接的 Odoo 实例上的接口和驱动程序。每个模块都可以包含一个 iot_handlers目录,该目录将被复制到 IoT Box。这个目录的结构如下
模块
├── ...
└── iot_handlers
├── drivers
│ ├── DriverName.py
│ └── ...
│
└── interfaces
├── InterfaceName.py
└── ...
检测设备
通过 检测连接到 IoT Box 的设备Interfaces。每种支持的连接类型(USB、蓝牙、视频、打印机、串行等)都有一个接口。该接口维护检测到的设备列表并将它们与正确的驱动程序相关联。
支持的设备将出现在您可以通过其 IP 地址访问的 IoT Box 主页上以及连接的 Odoo 实例的 IoT 模块中。
Interface 接口
接口的作用是维护通过确定的连接类型连接的设备列表。
- 扩展interface类
- 设置connection_type 类属性
- 执行get_devices 方法, 将会返回字典,包含每个检测到的设备的数据. 将提供此数据作为构造函数的参数和驱动程序的支持方法.
注意:
设置 _loop_delay 属性会修改两次调用get_devices之间的间隔时间. 通常情况下,间隔的采集时间为 3 秒.
from odoo.addons.hw_drivers.interface import Interface
class InterfaceName(Interface):
connection_type = 'ConnectionType'
def get_devices(self):
return {
'device_identifier_1': {
...},
...
}
Driver驱动程序
一旦接口程序发现设备列表,它将遍历具有相同connection_type属性的所有驱动程序,并在所有检测到的设备上测试其各自支持的方法。如果支持的驱动程序方法返回True,则将为相应设备创建此驱动程序的实例。
注意:
驱动程序的支持方法具有优先顺序。子类支持的方法将始终在其父类之一之前进行测试。可以通过修改驱动程序的优先级属性来调整该优先级。
建立一个新的设备需要:
扩展应用程序
设置connection_type class属性
设置 device_type, device_connection 和 device_name 属性.
定义相关的支持方法
from odoo.addons.hw_drivers.driver import Driver
class DriverName(Driver):
connection_type = 'ConnectionType'
def __init__(self, identifier, device):
super(NewDriver, self).__init__(identifier, device)
self.device_type = 'DeviceType'
self.device_connection = 'DeviceConnection'
self.device_name = 'DeviceName'
@classmethod
def supported(cls, device):
...
Communicate With Devices连接设备
一旦检测到新设备并显示在物联网模块中, 下一步就需要去链接它, 因为盒子只有一个本地IP地址,只能从同一个本地网络访问. 因此,通信需要在浏览器端用JavaScript进行.
该过程取决于通信的方向:: - 从浏览器到盒子, 通过 Actions - 从盒子到浏览器, 通过 Longpolling
两个通道都是从同一个JS对象访问, DeviceProxy, 使用IOT BOX的IP和设备标识符实例化。
var DeviceProxy = require('iot.DeviceProxy');
var iot_device = new DeviceProxy({
iot_ip: iot_ip,
identifier: device_identifier
});
Actions动作
用于告诉所选设备执行特定动作,例如拍照、打印收据等。
注意
必须注意的是,此路由上的IOT box不会发送“应答”,只有主动去请求状态。必须通过longpolling(长轮询)检索操作的结果(如果有的话)
可以在DeviceProxy对象上执行操作。
iot_device.action(data);
在驱动程序中,定义从Odoo模块调用时将执行的操作方法。它将调用期间提供的数据作为参数。
def action(self, data):
...
Longpolling(长轮询)
当odoo模块需要从特定设备上读取数据,通过监听来获取监听设备的数据变化,并以回调函数的形式返回。
iot_device.add_listener(this._onValueChange.bind(this));
_onValueChange: function (result) {
...
}
在驱动程序中, 事件通过从 event_manager调用device_changed 函数被释放. 设置在监听器上的所有回调将通过 self.data 作为参数被触发。
from odoo.addons.hw_drivers.event_manager import event_manager
class DriverName(Driver):
connection_type = ‘ConnectionType’
def methodName(self):
self.data = {
'value': 0.5,
...
}
event_manager.device_changed(self)
中亿丰数字 姜振建
边栏推荐
猜你喜欢

QT commonly used global macro definitions

Summer vacation second week wrap-up blog

2022年MySQL最新面试题

MySQL Lock wait timeout exceeded; try restarting transaction 锁等待

QT_QThread thread

粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)

JVM运行时数据区与JMM内存模型是什么

B005 - STC8 based single chip microcomputer intelligent street light control system

Leetcode75. 颜色分类

QT basic functions, signals, slots
随机推荐
opencv语法Mat类型总结
What is the implementation principle of Go iota keyword and enumeration type
暑假第二周总结博客
8月微软技术课程,欢迎参与
国标GB28181协议EasyGBS平台兼容老版本收流端口的功能实现
QT_QDialog 对话框
【Day_12 0507】二进制插入
塔防海岸线用户协议
Basic image processing in opencv
Leetcode74. Search 2D Matrix
How to make the fixed-point monitoring equipment display the geographic location on the EasyCVR platform GIS electronic map?
Topology零部件拆解3D可视化解决方案
Summer vacation second week wrap-up blog
行业沙龙第二期丨如何通过供应链数字化业务协同,赋能化工企业降本增效?
Go GORM事务实例分析
golang json returns null
加州大学|通过图抽象从不同的第三人称视频中进行逆强化学习
B005 – 基于STC8的单片机智能路灯控制系统
【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)
三维空间中点的插值