Skip to content

Commit d6cca8d

Browse files
Teddy-1000fjugipe
andauthored
Set mqtt v5 (#279)
* Add option to set mqtt version * Update readme * Update ingest/README.md Co-authored-by: Jukka Pelli <132542798+fjugipe@users.noreply.github.com> * Add MQTT protocol version to docker compose * Remove broken hadolint * Set a deafult mqtt protcol version in compose --------- Co-authored-by: Jukka Pelli <132542798+fjugipe@users.noreply.github.com>
1 parent 0ed1946 commit d6cca8d

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ repos:
6565
args: ["--ignore=W503", "--max-line-length=120"]
6666

6767
# hadolint ~ Docker linter
68-
- repo: https://github.com/hadolint/hadolint
69-
rev: v2.13.1-beta
70-
hooks:
71-
- id: hadolint-docker
72-
args: [
73-
"--ignore=DL3008", # Pin versions in apt get install.
74-
]
68+
#- repo: https://github.com/hadolint/hadolint
69+
# rev: v2.13.1-beta
70+
# hooks:
71+
# - id: hadolint-docker
72+
# args: [
73+
# "--ignore=DL3008", # Pin versions in apt get install.
74+
# ]
7575

7676
# ShellCheck ~ Gives warnings and suggestions for bash/sh shell scripts
7777
- repo: https://github.com/koalaman/shellcheck-precommit

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ services:
113113
- MQTT_PASSWORD=${MQTT_PASSWORD}
114114
- MQTT_PORT=${MQTT_PORT:-1883}
115115
- MQTT_TLS=${MQTT_TLS:-False}
116+
- MQTT_PROTOCOL_VERSION=${MQTT_PROTOCOL_VERSION:-5}
116117
- MQTT_TOPIC_PREPEND=${MQTT_TOPIC_PREPEND:-'TEMP_TOPIC'}
117118
- WIS2_TOPIC=${WIS2_TOPIC:-'TEMP_TOPIC'}
118119
- WIS2_MQTT_HOST=${MQTT_HOST:-mqtt_wis2}

ingest/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
| `INGEST_LOGLEVEL` | | Logging level for the ingestion process. |
2222
| `GUNICORN_CMD_ARGS` | | Command-line arguments for configuring Gunicorn, a Python WSGI HTTP Server. |
2323
| `FASTAPI_ROOT_PATH` | | If this api is behind proxy, this need to be set to the root path |
24+
| `MQTT_PROTOCOL_VERSION` | 5 | Set the MQTT protocol version. Defaults to v5. Available protocols are v3.1, v3.1.1 and v5 |
2425

2526
## Dev install
2627

@@ -34,9 +35,10 @@ To install in dev mode run `pip install --editable .` from the top level of this
3435
| rapidjson-dev | 1.1.0 |
3536
| pybind11-dev | 2.9.1 |
3637

37-
3838
## Prerequisites of running locally
39+
3940
Move the `std_unit_names.json`to the ingest/api folder with
41+
4042
```bash
4143
just copy-units
4244
```

ingest/api/send_mqtt.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
logger = logging.getLogger(__name__)
88

9+
10+
mqtt_protocols = {
11+
"3.1": mqtt_client.MQTTv31,
12+
"3.1.1": mqtt_client.MQTTv311,
13+
"5": mqtt_client.MQTTv5,
14+
}
15+
916
mqtt_topic_prepend = os.getenv("MQTT_TOPIC_PREPEND", "")
1017
if not mqtt_topic_prepend or mqtt_topic_prepend == "/":
1118
mqtt_topic_prepend = ""
@@ -24,7 +31,10 @@ def on_connect(client, userdata, flags, rc, properties=None):
2431
def on_disconnect(client, userdata, flags, rc, properties):
2532
logger.warning(f"Disconnected from MQTT broker with result code {str(rc)}")
2633

27-
client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION2)
34+
client = mqtt_client.Client(
35+
mqtt_client.CallbackAPIVersion.VERSION2,
36+
protocol=mqtt_protocols[os.getenv("MQTT_PROTOCOL_VERSION", "5")],
37+
)
2838
client.enable_logger(logger)
2939
client.username_pw_set(mqtt_conf["username"], mqtt_conf["password"])
3040

0 commit comments

Comments
 (0)