Internet of Things
IoT Drivers allow any Odoo module to communicate in real-time with any device connected to the IoT Box. Communication with the IoT Box goes both ways, so the Odoo client can send commands to and receive information from any of the supported devices.
To add support for a device, all we need is:
Interface, to detect connected devices of a specific type
Driver, to communicate with an individual device
At each boot, the IoT Box will load all of the Interfaces and Drivers that can be located on the connected Odoo instance. Each module can contain an
iot_handlers directory that will be copied to the IoT Box. The structure of this directory is the following
Devices connected to the IoT Box are detected through
Interfaces. There is an Interface for each supported connection type (USB, Bluetooth, Video, Printers, Serial, etc.). The interface maintains a list of detected devices and associates them with the right Driver.
Supported devices will appear both on the IoT Box Homepage that you can access through its IP address and in the IoT module of the connected Odoo instance.
The role of the Interface is to maintain a list of devices connected through a determined connection type. Creating a new interface requires
get_devicesmethod, that should return a dictionary containing data about each detected device. This data will be given as argument to the constructors and
supportedmethod of the Drivers.
Once the interface has retrieved the list of detected devices, it will loop through all of the Drivers that have the same
connection_type attribute and test their respective
supported method on all detected devices. If the supported method of a Driver returns
True, an instance of this Driver will be created for the corresponding device.
Creating a new Driver requires:
Communicate With Devices
Both channels are accessed from the same JS object, the
DeviceProxy, which is instantiated using the IP of the IoT Box and the device identifier.
Actions are used to tell a selected device to execute a specific action, such as taking a picture, printing a receipt, etc.
An action can be performed on the DeviceProxy Object.
In your driver, define an
action method that will be executed when called from an Odoo module. It takes the data given during the call as argument.
When any module in Odoo wants to read data from a specific device, it creates a listener identified by the IP/domain of the box and the device identifier and passes it a callback function to be called every time the device status changes. The callback is called with the new data as argument.
In the Driver, an event is released by calling the
device_changed function from the
event_manager. All callbacks set on the listener will then be called with
self.data as argument.