当前位置:网站首页>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)
中亿丰数字 姜振建
边栏推荐
- 中信证券是国内十大券商吗?怎么开户安全?
- 8月微软技术课程,欢迎参与
- 成都理工大学&电子科技大学|用于强化学习的域自适应状态表示对齐
- Live chat system technology (8) : vivo live IM message module architecture practice in the system
- 使用设备树时对应的驱动编程
- 【Error】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat’)
- Leetcode74. 搜索二维矩阵
- How to build a CMDB driven by consumption scenarios?
- SQL的ROUND函数用法及其实例
- 塔防海岸线用户协议
猜你喜欢
How to use the Golang coroutine scheduler scheduler
QT基础功能,信号、槽
Detailed explanation of DBPack SQL Tracing function and data encryption function
三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.
Zabbix6.0 DingTalk robot alarm
后台管理系统的权限思路
Leetcode75. Color Classification
解决MySQL插入不了中文数据问题
【Day_12 0507】查找组成一个偶数最接近的两个素数
B005 – 基于STC8的单片机智能路灯控制系统
随机推荐
AntDB database appeared in the 24th high-speed exhibition, helping smart high-speed innovative applications
QT basic functions, signals, slots
123123123123
University of California | Inverse Reinforcement Learning from Different Third-Person Videos via Graph Abstraction
Summer vacation first week wrap-up blog
opencv real-time face detection
MySQL 45 讲 | 09 普通索引和唯一索引,应该怎么选择?
How many steps does it take to convert an ENS domain name into music?
B011 - 51-based multifunctional fingerprint smart lock
SQL的substring_index()用法——MySQL字符串截取
QT_Event class
ACID Characteristics and Implementation Methods of MySQL Relational Database Transactions
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
How to build a CMDB driven by consumption scenarios?
C language theory--a solid foundation for the written test and interview
【Error】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat’)
SQL的ROUND函数用法及其实例
计算IoU(D2L)
2022年MySQL最新面试题
Clip-on multimeter use method, how to measure the voltage, current, resistance?