From a59c42e5caa76a5ea1d5e79b7820a1a012f9a3a4 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 14 Nov 2020 15:21:53 +0100 Subject: MQTT backend skeleton --- backends/mqtt.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 backends/mqtt.h (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h new file mode 100644 index 0000000..165f2ba --- /dev/null +++ b/backends/mqtt.h @@ -0,0 +1,48 @@ +#include "midimonster.h" + +MM_PLUGIN_API int init(); +static int mqtt_configure(char* option, char* value); +static int mqtt_configure_instance(instance* inst, char* option, char* value); +static int mqtt_instance(instance* inst); +static channel* mqtt_channel(instance* inst, char* spec, uint8_t flags); +static int mqtt_set(instance* inst, size_t num, channel** c, channel_value* v); +static int mqtt_handle(size_t num, managed_fd* fds); +static int mqtt_start(size_t n, instance** inst); +static int mqtt_shutdown(size_t n, instance** inst); + +#define MQTT_PORT "1883" +#define MQTT_TLS_PORT "8883" + +enum { + MSG_RESERVED = 0x00, + MSG_CONNECT = 0x10, + MSG_CONNACK = 0x20, + MSG_PUBLISH = 0x30, + MSG_PUBACK = 0x40, + MSG_PUBREC = 0x50, + MSG_PUBREL = 0x60, + MSG_PUBCOMP = 0x70, + MSG_SUBSCRIBE = 0x80, + MSG_SUBACK = 0x90, + MSG_UNSUBSCRIBE = 0xA0, + MSG_UNSUBACK = 0xB0, + MSG_PINGREQ = 0xC0, + MSG_PINGRESP = 0xD0, + MSG_DISCONNECT = 0xE0, + MSG_AUTH = 0xF0 +}; + +typedef struct /*_mqtt_instance_data*/ { + uint8_t tls; + char* host; + char* port; + + char* user; + char* password; + + size_t nchannels; + char** channel; +} mqtt_instance_data; + +//per-channel +//qos, subscribe -- cgit v1.2.3 From fdb0bf2e86693f99550f6e21de85023188ac5b03 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 5 Dec 2020 14:27:23 +0100 Subject: Implement basic MQTT connection startup --- backends/mqtt.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index 165f2ba..1c8b47d 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -12,6 +12,8 @@ static int mqtt_shutdown(size_t n, instance** inst); #define MQTT_PORT "1883" #define MQTT_TLS_PORT "8883" +#define MQTT_BUFFER_LENGTH 8192 +#define MQTT_KEEPALIVE 10 enum { MSG_RESERVED = 0x00, @@ -39,9 +41,12 @@ typedef struct /*_mqtt_instance_data*/ { char* user; char* password; + char* client_id; size_t nchannels; char** channel; + + int fd; } mqtt_instance_data; //per-channel -- cgit v1.2.3 From e248f0c5778f73988477ba73174c91b7085c232c Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 18 Dec 2020 22:31:14 +0100 Subject: Implement MQTT connect --- backends/mqtt.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index 1c8b47d..df63319 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -14,6 +14,7 @@ static int mqtt_shutdown(size_t n, instance** inst); #define MQTT_TLS_PORT "8883" #define MQTT_BUFFER_LENGTH 8192 #define MQTT_KEEPALIVE 10 +#define MQTT_VERSION 0x05 enum { MSG_RESERVED = 0x00, @@ -47,6 +48,8 @@ typedef struct /*_mqtt_instance_data*/ { char** channel; int fd; + uint8_t receive_buffer[MQTT_BUFFER_LENGTH]; + size_t receive_offset; } mqtt_instance_data; //per-channel -- cgit v1.2.3 From cbef6a61a92453afba5005c287873001354f5090 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 9 Jan 2021 11:36:09 +0100 Subject: Implement keepalive and protocol fallback --- backends/mqtt.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index df63319..a0f5356 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -14,7 +14,7 @@ static int mqtt_shutdown(size_t n, instance** inst); #define MQTT_TLS_PORT "8883" #define MQTT_BUFFER_LENGTH 8192 #define MQTT_KEEPALIVE 10 -#define MQTT_VERSION 0x05 +#define MQTT_VERSION_DEFAULT 0x05 enum { MSG_RESERVED = 0x00, @@ -39,6 +39,7 @@ typedef struct /*_mqtt_instance_data*/ { uint8_t tls; char* host; char* port; + uint8_t mqtt_version; char* user; char* password; @@ -50,6 +51,8 @@ typedef struct /*_mqtt_instance_data*/ { int fd; uint8_t receive_buffer[MQTT_BUFFER_LENGTH]; size_t receive_offset; + + uint64_t last_control; } mqtt_instance_data; //per-channel -- cgit v1.2.3 From 6334a78d0c475ebfa76a739577a561bded135086 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 10 Jan 2021 09:42:54 +0100 Subject: Subscribe to input channels --- backends/mqtt.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index a0f5356..c9bce81 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -16,6 +16,8 @@ static int mqtt_shutdown(size_t n, instance** inst); #define MQTT_KEEPALIVE 10 #define MQTT_VERSION_DEFAULT 0x05 +#define MQTT5_NO_LOCAL 0x04 + enum { MSG_RESERVED = 0x00, MSG_CONNECT = 0x10, @@ -25,7 +27,7 @@ enum { MSG_PUBREC = 0x50, MSG_PUBREL = 0x60, MSG_PUBCOMP = 0x70, - MSG_SUBSCRIBE = 0x80, + MSG_SUBSCRIBE = 0x82, MSG_SUBACK = 0x90, MSG_UNSUBSCRIBE = 0xA0, MSG_UNSUBACK = 0xB0, @@ -35,6 +37,13 @@ enum { MSG_AUTH = 0xF0 }; +//qos, subscribe +typedef struct /*_mqtt_channel*/ { + char* topic; + uint16_t topic_alias; + uint8_t flags; +} mqtt_channel_data; + typedef struct /*_mqtt_instance_data*/ { uint8_t tls; char* host; @@ -46,14 +55,12 @@ typedef struct /*_mqtt_instance_data*/ { char* client_id; size_t nchannels; - char** channel; + mqtt_channel_data* channel; int fd; uint8_t receive_buffer[MQTT_BUFFER_LENGTH]; size_t receive_offset; uint64_t last_control; + uint16_t packet_identifier; } mqtt_instance_data; - -//per-channel -//qos, subscribe -- cgit v1.2.3 From 983313fe782047a5fe84314fafa2eb0b56e0e3a1 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 6 Feb 2021 22:51:54 +0100 Subject: Implement MQTT output --- backends/mqtt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index c9bce81..6483364 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -40,7 +40,8 @@ enum { //qos, subscribe typedef struct /*_mqtt_channel*/ { char* topic; - uint16_t topic_alias; + uint16_t topic_alias_sent; + uint16_t topic_alias_rcvd; uint8_t flags; } mqtt_channel_data; -- cgit v1.2.3 From fdd8f8075fbcb22d349135bd87bf95b8ce88c8e1 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 13 Feb 2021 16:58:12 +0100 Subject: Implement basic MQTT reception --- backends/mqtt.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index 6483364..0cb2617 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -18,6 +18,15 @@ static int mqtt_shutdown(size_t n, instance** inst); #define MQTT5_NO_LOCAL 0x04 +enum /*_mqtt_property_storage_classes*/ { + STORAGE_U8, + STORAGE_U16, + STORAGE_U32, + STORAGE_VARINT, + STORAGE_PREFIXED, + STORAGE_PREFIXPAIR +}; + enum { MSG_RESERVED = 0x00, MSG_CONNECT = 0x10, -- cgit v1.2.3 From 670f3ff21f30b8aae765d61a38a7269d0eaab19d Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 14 Feb 2021 00:21:47 +0100 Subject: Implement MQTT5 topic aliases --- backends/mqtt.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index 0cb2617..d40e83d 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -73,4 +73,6 @@ typedef struct /*_mqtt_instance_data*/ { uint64_t last_control; uint16_t packet_identifier; + uint16_t server_max_alias; + uint16_t current_alias; } mqtt_instance_data; -- cgit v1.2.3 From fca46bef7dd8448216d44f0777f0b5ef31ac5883 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 27 Feb 2021 16:54:06 +0100 Subject: Implement input/output mapping --- backends/mqtt.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'backends/mqtt.h') diff --git a/backends/mqtt.h b/backends/mqtt.h index d40e83d..c684f99 100644 --- a/backends/mqtt.h +++ b/backends/mqtt.h @@ -46,12 +46,21 @@ enum { MSG_AUTH = 0xF0 }; -//qos, subscribe +typedef struct /*_mqtt_value_mapping*/ { + double min; + double max; + double normal; + char* discrete; +} mqtt_channel_value; + typedef struct /*_mqtt_channel*/ { char* topic; uint16_t topic_alias_sent; uint16_t topic_alias_rcvd; uint8_t flags; + + size_t values; + mqtt_channel_value* value; } mqtt_channel_data; typedef struct /*_mqtt_instance_data*/ { -- cgit v1.2.3