Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
22e505b
[12.0][ADD] iot_input
etobella Mar 6, 2020
6d2948c
[UPD] Adds new fields, multi_input controller, views
diggy128 Jul 24, 2020
a87852b
[FIX][iot_input] Allow passing number as address
diggy128 Sep 26, 2020
6acc656
[12.0][UPD]iot,iot_input: set order,skip inactive inputs
diggy128 Jan 21, 2021
04c5d81
[IMP] iot_input_oca: black, isort, prettier
olgamarcocb Jun 9, 2021
426ae6e
[MIG] iot_input_oca: Migration to 13.0
olgamarcocb Jun 9, 2021
2c96824
[IMP] iot_input_oca: Improve views, Allow to pass multiple parameters…
etobella Dec 11, 2021
0660271
[FIX] iot_input_oca: Do not pass the input if the device is not active
etobella Dec 16, 2021
25c6eca
[IMP] iot_input_oca: black, isort, prettier
etobella Dec 19, 2021
f6bf5c5
[MIG] iot_input_oca: Migration to 14.0
etobella Dec 19, 2021
0fef843
[MIG] iot_input_oca: Migration to 15.0
olgamarcocb May 11, 2022
3d7ce4e
[UPD] Update iot_input_oca.pot
May 12, 2022
8bbd0b9
[UPD] README.rst
OCA-git-bot May 12, 2022
22de573
Added translation using Weblate (Catalan)
jabelchi Jun 3, 2022
28c3238
Translated using Weblate (Catalan)
jabelchi Jun 3, 2022
a27f73b
Added translation using Weblate (Italian)
mymage Mar 23, 2023
46eec8f
Translated using Weblate (Italian)
mymage Mar 23, 2023
1132fae
Translated using Weblate (Italian)
mymage Mar 23, 2023
ccc8c2c
[MIG] iot_input_oca: Migration to 16.0
mostafabarmshory Jun 14, 2023
b263f84
[UPD] Update iot_input_oca.pot
Jun 15, 2023
ab36a55
[UPD] README.rst
OCA-git-bot Jun 15, 2023
cc546fe
Update translation files
weblate Jun 15, 2023
a16b650
Translated using Weblate (Italian)
mymage Jul 18, 2023
6277c96
Added translation using Weblate (Spanish)
Ivorra78 Aug 22, 2023
6a48bd3
[UPD] README.rst
OCA-git-bot Sep 3, 2023
93cae35
Translated using Weblate (Spanish)
Ivorra78 Aug 22, 2023
f99d25c
Added translation using Weblate (Persian)
mostafabarmshory Oct 4, 2023
d6a603b
Translated using Weblate (Persian)
mostafabarmshory Oct 4, 2023
72e4b49
Update translation files
weblate Oct 9, 2023
65f0de5
[IMP] iot_input_oca: pre-commit auto fixes
FernandoRomera Aug 5, 2024
11326fe
[MIG] iot_input_oca: Migration to 17.0
FernandoRomera Aug 5, 2024
6ee2f03
[UPD] Update iot_input_oca.pot
Aug 6, 2024
7f86e73
[BOT] post-merge updates
OCA-git-bot Aug 6, 2024
d1c9860
Update translation files
weblate Aug 6, 2024
0f79410
Translated using Weblate (Italian)
mymage Aug 30, 2024
33111a2
[MIG] iot_input_oca: Migration to 18.0
JordiBForgeFlow Jul 21, 2025
6d9de1c
[FIX] iot_input_oca: avoid readonly environment in test
MiquelRForgeFlow Jul 21, 2025
57ee9ad
[FIX] iot_input_oca: ignore _logging.warning in tests
MiquelRForgeFlow Jul 21, 2025
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
165 changes: 165 additions & 0 deletions iot_input_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
=========
IoT Input
=========

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

.. |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/licence-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": "18.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
105 changes: 105 additions & 0 deletions iot_input_oca/controller/iot_input_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# 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,
)
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,
)
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": _("Passphrase is required")}
)
if not values:
_logger.warning("Values is required")
return json.dumps({"status": "error", "message": _("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": _("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": _("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