Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f9a4312
[ADD] iot_base
etobella Jul 17, 2018
898d78f
Added translation using Weblate (Spanish)
etobella Aug 28, 2018
68ab858
[IMP] iot: views
etobella Mar 18, 2019
8b64034
[MIG][12.0] iot
etobella Feb 20, 2020
b1630d2
[UPD] Adds new fields, multi_input controller, views
diggy128 Jul 24, 2020
6a5b807
[IMP] iot_oca: black, isort, prettier
olgamarcocb Jun 8, 2021
27aeac3
[MIG] iot_oca: Migration to 13.0
olgamarcocb Jun 8, 2021
f7236c2
[IMP] iot_oca: Add tags, groups and new menus
etobella Dec 9, 2021
c21bab1
[IMP] iot_oca: Improve view
etobella Dec 11, 2021
93ce9e0
[IMP] iot_oca: Add Device Image
etobella Dec 16, 2021
2479121
[IMP] iot_oca: Set a default icon
olgamarcocb Dec 17, 2021
1ab8690
[MIG] iot_oca: Migration to 14.0
etobella Dec 17, 2021
6df4cff
[MIG] iot_oca: Migration to 15.0
olgamarcocb May 11, 2022
2b6f23d
[UPD] Update iot_oca.pot
May 11, 2022
df982a9
[UPD] README.rst
OCA-git-bot May 11, 2022
e1ba2ff
Added translation using Weblate (Catalan)
jabelchi Jun 3, 2022
7e009c6
Added translation using Weblate (Italian)
mymage Mar 22, 2023
7a92f1f
[MIG] iot_oca: migration to 16.0
mostafabarmshory May 9, 2023
3573bf6
[UPD] Update iot_oca.pot
May 11, 2023
953c676
[UPD] README.rst
OCA-git-bot May 11, 2023
aced054
Update translation files
weblate May 11, 2023
b26c8f4
Translated using Weblate (Italian)
francesco-ooops Jul 12, 2023
a5babbe
[UPD] README.rst
OCA-git-bot Sep 3, 2023
81e199f
Translated using Weblate (Spanish)
Ivorra78 Aug 22, 2023
991d463
Added translation using Weblate (Persian (fa_IR))
mostafabarmshory Oct 4, 2023
dbf9867
Added translation using Weblate (Persian)
mostafabarmshory Oct 4, 2023
51f7158
Translated using Weblate (Persian)
mostafabarmshory Oct 4, 2023
ea8991b
Translated using Weblate (Italian)
francesco-ooops Oct 13, 2023
570b3c6
Translated using Weblate (Italian)
mymage Jan 10, 2024
31ffd81
Translated using Weblate (Persian)
mostafabarmshory Apr 3, 2024
9dad140
[IMP] iot_oca: pre-commit auto fixes
FernandoRomera Jul 23, 2024
35491f2
[MIG] iot_oca: Migration to 17.0
FernandoRomera Jul 23, 2024
e9e2ea6
[UPD] Update iot_oca.pot
Jul 28, 2024
1be8f27
[BOT] post-merge updates
OCA-git-bot Jul 28, 2024
952e89e
Update translation files
weblate Jul 28, 2024
992ae68
Translated using Weblate (Italian)
mymage Jun 21, 2025
095b6fe
[MIG] iot_oca: Migration to 18.0
JordiBForgeFlow Jul 21, 2025
ac8e6b2
[MIG] iot_oca: Migration to 18.0
JordiBForgeFlow Jul 21, 2025
42a2721
[FIX] iot_oca: kanban-box is deprecated
MiquelRForgeFlow Jul 21, 2025
831f0b0
[UPD] Update iot_oca.pot
Jul 26, 2025
fa95a98
[BOT] post-merge updates
OCA-git-bot Jul 26, 2025
50420d4
[IMP] iot_oca: update icon to align with v17+ style
LoisRForgeFlow Oct 24, 2025
44d5997
[BOT] post-merge updates
OCA-git-bot Oct 27, 2025
589d91c
[MIG] iot_oca: Migration to 19.0
MiquelRForgeFlow Sep 30, 2026
1d1b28f
[MIG] iot_input_oca: Migration to 19.0
Nov 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions iot_input_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========
IoT Input
=========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:712a7f4515d804c522f60180687a68c12af9368ed547a48debfc6d67197e3e5a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fiot-lightgray.png?logo=github
:target: https://github.com/OCA/iot/tree/18.0/iot_input_oca
:alt: OCA/iot
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/iot-18-0/iot-18-0-iot_input_oca
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/iot&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon allows to use a device in order to input data to odoo
automatically.

It opens a URL that a device can use to connect (with a password) that
can only execute an specific action.

Inputs are useful when a device wants to communicate to odoo for a
single and simple action. This way, the device does not need to be
configured with a odoo user and password, it is handled by odoo devices.

Examples:

- Sending the temperature every three minutes.
- Sending the RFID that the device has received in order to perform some
action

**Table of contents**

.. contents::
:local:

Usage
=====

There are two endpoints you can use: Endpoint 1: /iot/<serial>/action

Takes application/x-www-form-urlencoded parameters: passphase, value
(where value is a JSON object)

1. Create a Device on IoT > Config Devices
2. Access the Inputs section of the device
3. Create an input. You must define a serial, passphrase, function and
model

The function that the system will call must be of the following kind:

::

@api.model
def call_function(self, key):
return {}

Where key is the input string send by the device and the result must be
a dictionary that will be responded to the device as a JSON.

Endpoint 2: /iot/<device_identification>/multi_input It can be used to
send values with multiple data in one POST request such as: - Values for
inputs of the same device with different address (multi input) - Values
for inputs of the same device with same address, different values (multi
event) - Mix of the above (multi input, multi event)

Takes application/x-www-form-urlencoded parameters: passphase, values (a
JSON array of JSON objects)

It is called using device_identification and passing two POST
parameters: device passphrase and a JSON string containing an array of
values for input - The value for the address key can be a string or a
numeric (to conserve bytes in memory restricted devices when creating
the JSON object) and is converted to string when parsing. - The value
for the value key can either be string, number or boolean according to
JSON specs. You can see an example of a valid JSON input object in the
examples folder, using a few combinations.

It requires the function that the system will call must be of the
following kind:

::

@api.model
def call_function(self, key):
'do something
if err:
return {'status': 'error', 'message': 'The error message you want to send to the device'}
return {'status': 'ok', 'message': 'Optional success message'}

Where key is a dict send by the device having at least value for keys:
'address', 'value'

The function must always return a JSON with status and message. If value
contains a value with 'uuid' as key, it is returned along with the
object for the IoT device to identify success/failure per record.

It has full error reporting and the return value is a JSON array of
dicts containing at least status and message. Error message respose is
at some points generic, though extended logging is done in Odoo server
logs.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/iot/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/iot/issues/new?body=module:%20iot_input_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Creu Blanca

Contributors
------------

- Enric Tobella <etobella@creublanca.es>
- Dimitrios Tanis <dtanis@tanisfood.gr>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px
:target: https://github.com/etobella
:alt: etobella

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-etobella|

This module is part of the `OCA/iot <https://github.com/OCA/iot/tree/18.0/iot_input_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions iot_input_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controller
19 changes: 19 additions & 0 deletions iot_input_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "IoT Input",
"version": "19.0.1.0.0",
"author": "Creu Blanca, Odoo Community Association (OCA)",
"category": "IoT",
"license": "AGPL-3",
"installable": True,
"summary": "IoT Input module",
"depends": ["iot_oca"],
"website": "https://github.com/OCA/iot",
"maintainers": ["etobella"],
"data": [
"security/ir.model.access.csv",
"views/iot_device_views.xml",
"views/iot_device_input_views.xml",
],
}
1 change: 1 addition & 0 deletions iot_input_oca/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import iot_input_controller
107 changes: 107 additions & 0 deletions iot_input_oca/controller/iot_input_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import json
import logging

from odoo import http

_logger = logging.getLogger(__name__)


class CallIot(http.Controller):
@http.route(
["/iot/<serial>/action"],
type="http",
auth="none",
methods=["POST"],
csrf=False,
readonly=False,
)
def call_unauthorized_iot(self, serial, passphrase=False, *args, **kwargs):
request = http.request
if not request.env:
return json.dumps(False)
return json.dumps(
request.env["iot.device.input"]
.sudo()
.get_device(serial, passphrase)
.call_device(**kwargs)
)

@http.route(
["/iot/<serial>/multi_input"],
type="http",
auth="none",
methods=["POST"],
csrf=False,
readonly=False,
)
def call_unauthorized_iot_multi_input(
self, serial, passphrase=False, values=False, *args, **kwargs
):
"""Controller to write multiple input data to device inputs

:param string passphrase:
Device passphrase in POST data.

:param string values:
JSON formatted string containing a JSON an array of JSON objects.
"""
request = http.request
if not request.env:
_logger.warning("env not set")
return json.dumps({"status": "error", "message": "Server Error"})
if not passphrase:
_logger.warning("Passphrase is required")
return json.dumps(
{"status": "error", "message": request.env._("Passphrase is required")}
)
if not values:
_logger.warning("Values is required")
return json.dumps({"status": "error", "message": request.env._("Values is required")})
# Decode JSON object here and use pure python objects in further calls
try:
if isinstance(values, str):
values = json.loads(values)
if not isinstance(values, list):
raise SyntaxError
except json.decoder.JSONDecodeError:
_logger.warning("Values is not a valid JSON")
return json.dumps(
{"status": "error", "message": request.env._("Values is not a valid JSON")}
)
except SyntaxError:
_logger.warning("Values should be a JSON array of JSON objects")
return json.dumps(
{
"status": "error",
"message": request.env._("Values should be a JSON array of JSON objects"),
}
)
# Encode response to JSON and return
result = (
request.env["iot.device.input"]
.sudo()
.get_device(serial, passphrase)
.call_device(values=values)
)
if result["status"] != "ok":
return json.dumps({"status": result["status"]})
return json.dumps(result["result"])

@http.route(
["/iot/<serial>/check"], type="http", auth="none", methods=["POST"], csrf=False
)
def check_unauthorized_iot(self, serial, *args, **kwargs):
request = http.request
if not request.env:
return json.dumps(False)
device = (
request.env["iot.device.input"]
.sudo()
.get_device(serial, kwargs["passphrase"])
)
if device:
return json.dumps({"state": True})
return json.dumps({"state": False})
19 changes: 19 additions & 0 deletions iot_input_oca/examples/multi_input_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"address": "ZMPT101B_1",
"value": 230
},
{
"address": 1,
"value": true
},
{
"address": 2,
"value": "Door opened",
"uuid": "abcde"
},
{
"address": 10,
"value": -18.5
}
]
Loading
Loading