Skip to content

Commit ef02f01

Browse files
committed
Merge remote-tracking branch 'origin/main' into add-option-for-custom-openapi-metadata
2 parents 3a4f6f1 + d6cca8d commit ef02f01

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@
66

77
logger = logging.getLogger(__name__)
88

9-
if "MQTT_TOPIC_PREPEND" in os.environ:
10-
mqtt_topic_prepend = os.getenv("MQTT_TOPIC_PREPEND", "")
9+
10+
mqtt_protocols = {
11+
"3.1": mqtt_client.MQTTv31,
12+
"3.1.1": mqtt_client.MQTTv311,
13+
"5": mqtt_client.MQTTv5,
14+
}
15+
16+
mqtt_topic_prepend = os.getenv("MQTT_TOPIC_PREPEND", "")
17+
if not mqtt_topic_prepend or mqtt_topic_prepend == "/":
18+
mqtt_topic_prepend = ""
19+
logger.error("MQTT_TOPIC_PREPEND cannot be just a '/'. Setting topic prepend to empty string.")
20+
else:
1121
mqtt_topic_prepend = mqtt_topic_prepend if mqtt_topic_prepend.endswith("/") else mqtt_topic_prepend + "/"
1222

1323

@@ -21,7 +31,10 @@ def on_connect(client, userdata, flags, rc, properties=None):
2131
def on_disconnect(client, userdata, flags, rc, properties):
2232
logger.warning(f"Disconnected from MQTT broker with result code {str(rc)}")
2333

24-
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+
)
2538
client.enable_logger(logger)
2639
client.username_pw_set(mqtt_conf["username"], mqtt_conf["password"])
2740

0 commit comments

Comments
 (0)