diff --git a/0BUILD b/0BUILD
index 33ae0eb..e344b4f 100644
--- a/0BUILD
+++ b/0BUILD
@@ -91,6 +91,9 @@
plugindir gwengui-fox16
+
+ aqdatabase_typemakerdir
+
diff --git a/aqhome/0BUILD b/aqhome/0BUILD
index a2eb2d2..62adbdf 100644
--- a/aqhome/0BUILD
+++ b/aqhome/0BUILD
@@ -65,6 +65,7 @@
mqtt
http
hexfile
+ data
@@ -75,10 +76,12 @@
aqhmqtt
aqhhttp
aqhhexfile
+ aqhdata
$(gwenhywfar_libs)
+ $(aqdatabase_libs)
diff --git a/aqhome/data/0BUILD b/aqhome/data/0BUILD
new file mode 100644
index 0000000..4c7218f
--- /dev/null
+++ b/aqhome/data/0BUILD
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+ $(gwenhywfar_cflags)
+ $(aqdatabase_cflags)
+ -I$(topsrcdir)
+ -I$(topbuilddir)
+
+
+
+ --include=$(builddir)
+ --include=$(srcdir)
+ --include=$(aqdatabase_AQDATABASE_TYPEMAKERDIR)/c
+
+
+
+
+
+ $(visibility_cflags)
+
+
+
+ --api=AQHOME_API
+
+
+
+ room.t2d
+ device.t2d
+ mqtttopic.t2d
+ value.t2d
+ datapoint.t2d
+
+
+
+ room.c
+ device.c
+ mqtttopic.c
+ value.c
+ datapoint.c
+
+
+
+ room.h
+ device.h
+ mqtttopic.h
+ value.h
+ datapoint.h
+
+
+
+
+ room_p.h
+ device_p.h
+ mqtttopic_p.h
+ value_p.h
+ datapoint_p.h
+
+
+
+
+ $(local/built_headers_pub)
+
+
+
+
+ storage.h
+
+
+
+
+ storage_p.h
+
+
+
+
+ $(local/typefiles)
+
+ storage.c
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aqhome/data/README b/aqhome/data/README
new file mode 100644
index 0000000..7cee608
--- /dev/null
+++ b/aqhome/data/README
@@ -0,0 +1,79 @@
+
+room:
+- id
+- name
+- description
+- colour
+
+
+device
+- id
+- name
+- room
+- location
+- description
+
+mqtt-topic:
+- id
+- deviceId
+- mqttTopic
+- mqttDataType (num, json)
+
+
+value:
+- id
+- topicId
+- value type (temp, humidity, speed, door, length, width, counter, gauge)
+- units
+- dataPath (for JSON)
+
+
+
+
+datapoint:
+- value id
+- timestamp
+- value
+
+
+lastDatapoint: (DB: no rollback, otherwise db would double in size)
+- module id
+- timestamp
+- value
+
+
+
+Processing MQTT publish messages:
+- create data point
+- set timestamp in data point
+- find MQTT_TOPIC for topic string
+ - mqttType:
+ - num:
+ - lookup first value
+ - store data in data point
+ - json: parse data
+ - for every VALUE assigned to that topic:
+ - store data in data point
+- write data point to long term db
+- write data point to lastValues db
+
+
+Storage API:
+- handleMqttPublish(AQH_STORAGE *st, const char *topic, const char *value)
+
+- addDevice(AQH_STORAGE *st, AQH_DEVICE *dev)
+- getDeviceList(const AQH_STORAGE *st)
+- getDeviceById(const AQH_STORAGE *st, uint32_t id)
+
+- addMqttTopic(AQH_STORAGE *st, AQH_MQTT_TOPIC *t);
+- getMqttTopicList(const AQH_STORAGE *st)
+- getMqttTopicById(const AQH_STORAGE *st, uint32_t id)
+- getMqttTopicByTopic(const AQH_STORAGE *st, const char *topic)
+
+- addValue(AQH_STORAGE *st, AQH_VALUE *value)
+- getValueList(const AQH_STORAGE *st)
+- getValueById(const AQH_STORAGE *st, uint32_t id)
+
+
+
+
diff --git a/aqhome/data/datapoint.t2d b/aqhome/data/datapoint.t2d
new file mode 100644
index 0000000..31233a7
--- /dev/null
+++ b/aqhome/data/datapoint.t2d
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+ AQH_DATAPOINT
+ AQH_DataPoint
+ datapoint
+
+
+ with_list1
+ with_list2
+ with_xml
+ with_object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+ with_getbymember
+ public
+
+
+
+ 0
+ 0
+
+ public
+
+
+
+ public
+ with_sortbymember
+ 0
+ 0
+
+
+
+ public
+ own with_sortbymember
+ const dup
+ const
+ NULL
+ NULL
+
+
+
+
+
+
+
+
diff --git a/aqhome/data/device.t2d b/aqhome/data/device.t2d
new file mode 100644
index 0000000..11ec699
--- /dev/null
+++ b/aqhome/data/device.t2d
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+ AQH_DEVICE
+ AQH_Device
+ device
+
+
+ with_xml
+ with_db
+ with_list1
+ with_list2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+ public
+ with_getbymember
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+
+
+
+
+
diff --git a/aqhome/data/mqtttopic.t2d b/aqhome/data/mqtttopic.t2d
new file mode 100644
index 0000000..6f1ddfb
--- /dev/null
+++ b/aqhome/data/mqtttopic.t2d
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+ AQH_MQTT_TOPIC
+ AQH_MqttTopic
+ mqtttopic
+
+
+ with_xml
+ with_db
+ with_list1
+ with_list2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+ public
+ with_getbymember
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+ with_getbymember
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+
+
+
+
+
diff --git a/aqhome/data/mqttvalue.t2d b/aqhome/data/mqttvalue.t2d
new file mode 100644
index 0000000..ef234a1
--- /dev/null
+++ b/aqhome/data/mqttvalue.t2d
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+ AQH_VALUE
+ AQH_Value
+ value
+
+
+ with_xml
+ with_db
+ with_list1
+ with_list2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aqhome/data/room.t2d b/aqhome/data/room.t2d
new file mode 100644
index 0000000..3effc18
--- /dev/null
+++ b/aqhome/data/room.t2d
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+ AQH_ROOM
+ AQH_Room
+ room
+
+
+ with_xml
+ with_db
+ with_list1
+ with_list2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+ public
+ with_getbymember
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+ 0
+ 0
+ public
+
+
+
+
+
+
+
+
+
diff --git a/aqhome/data/storage.c b/aqhome/data/storage.c
new file mode 100644
index 0000000..8fb712c
--- /dev/null
+++ b/aqhome/data/storage.c
@@ -0,0 +1,158 @@
+/****************************************************************************
+ * This file is part of the project Gwenhywfar.
+ * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
+ *
+ * The license for this file can be found in the file COPYING which you
+ * should have received along with this file.
+ ****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "aqhome/data/storage_p.h"
+
+#include
+
+
+
+/* ------------------------------------------------------------------------------------------------
+ * forward declarations
+ * ------------------------------------------------------------------------------------------------
+ */
+
+
+
+
+
+
+/* ------------------------------------------------------------------------------------------------
+ * implementations
+ * ------------------------------------------------------------------------------------------------
+ */
+
+
+AQH_STORAGE *AQH_Storage_new(void)
+{
+ AQH_STORAGE *sto;
+
+ GWEN_NEW_OBJECT(AQH_STORAGE, sto);
+ sto->deviceList=AQH_Device_List_new();
+ sto->mqttTopicList=AQH_MqttTopic_List_new();
+ sto->valueList=AQH_Value_List_new();
+
+ return sto;
+}
+
+
+
+void AQH_Storage_free(AQH_STORAGE *sto)
+{
+ if (sto) {
+ AQH_Value_List_free(sto->valueList);
+ AQH_MqttTopic_List_free(sto->mqttTopicList);
+ AQH_Device_List_free(sto->deviceList);
+
+ GWEN_FREE_OBJECT(sto);
+ }
+}
+
+
+
+void AQH_Storage_AddDevice(AQH_STORAGE *sto, AQH_DEVICE *dev)
+{
+ if (sto && dev) {
+ uint64_t id;
+
+ id=++(sto->lastDeviceId);
+ AQH_Device_SetId(dev, id);
+ AQH_Device_List_Add(dev, sto->deviceList);
+ }
+}
+
+
+
+AQH_DEVICE_LIST *AQH_Storage_GetDeviceList(const AQH_STORAGE *sto)
+{
+ return sto?sto->deviceList:NULL;
+}
+
+
+
+AQH_DEVICE *AQH_Storage_GetDeviceById(const AQH_STORAGE *sto, uint64_t id)
+{
+ return sto?AQH_Device_List_GetById(sto->deviceList, id):NULL;
+}
+
+
+
+void AQH_Storage_AddMqttTopic(AQH_STORAGE *sto, AQH_MQTT_TOPIC *t)
+{
+ if (sto && t) {
+ uint64_t id;
+
+ id=++(sto->lastTopicId);
+ AQH_MqttTopic_SetId(t, id);
+ AQH_MqttTopic_List_Add(t, sto->mqttTopicList);
+ }
+}
+
+
+
+AQH_MQTT_TOPIC_LIST *AQH_Storage_GetMqttTopicList(const AQH_STORAGE *sto)
+{
+ return sto?sto->mqttTopicList:NULL;
+}
+
+
+
+AQH_MQTT_TOPIC *AQH_Storage_GetMqttTopicById(const AQH_STORAGE *sto, uint64_t id)
+{
+ return sto?AQH_MqttTopic_List_GetById(sto->mqttTopicList, id):NULL;
+}
+
+
+
+AQH_MQTT_TOPIC *AQH_Storage_GetMqttTopicByTopic(const AQH_STORAGE *sto, const char *topic)
+{
+ return sto?AQH_MqttTopic_List_GetByMqttTopic(sto->mqttTopicList, topic):NULL;
+}
+
+
+
+void AQH_Storage_AddValue(AQH_STORAGE *sto, AQH_VALUE *value)
+{
+ if (sto && value) {
+ uint64_t id;
+
+ id=++(sto->lastValueId);
+ AQH_Value_SetId(value, id);
+ AQH_Value_List_Add(value, sto->valueList);
+ }
+}
+
+
+
+AQH_VALUE_LIST *AQH_Storage_GetValueList(const AQH_STORAGE *sto)
+{
+ return sto?sto->valueList:NULL;
+}
+
+
+
+AQH_VALUE *AQH_Storage_GetValueById(const AQH_STORAGE *sto, uint64_t id)
+{
+ return sto?AQH_Value_List_GetById(sto->valueList, id):NULL;
+}
+
+
+
+void AQH_Storage_HandleMqttPublish(AQH_STORAGE *sto, const char *topic, const char *value)
+{
+ /* TODO */
+}
+
+
+
+
+
diff --git a/aqhome/data/storage.h b/aqhome/data/storage.h
new file mode 100644
index 0000000..b4e461b
--- /dev/null
+++ b/aqhome/data/storage.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * This file is part of the project Gwenhywfar.
+ * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
+ *
+ * The license for this file can be found in the file COPYING which you
+ * should have received along with this file.
+ ****************************************************************************/
+
+#ifndef AQH_STORAGE_H
+#define AQH_STORAGE_H
+
+
+#include
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct AQH_STORAGE AQH_STORAGE;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#include "aqhome/data/room.h"
+#include "aqhome/data/device.h"
+#include "aqhome/data/mqtttopic.h"
+#include "aqhome/data/value.h"
+#include "aqhome/data/datapoint.h"
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+/**
+ */
+AQHOME_API AQH_STORAGE *AQH_Storage_new(void);
+AQHOME_API void AQH_Storage_free(AQH_STORAGE *sto);
+
+AQHOME_API void AQH_Storage_AddDevice(AQH_STORAGE *sto, AQH_DEVICE *dev);
+AQHOME_API AQH_DEVICE_LIST *AQH_Storage_GetDeviceList(const AQH_STORAGE *sto);
+AQHOME_API AQH_DEVICE *AQH_Storage_GetDeviceById(const AQH_STORAGE *sto, uint64_t id);
+
+AQHOME_API void AQH_Storage_AddMqttTopic(AQH_STORAGE *sto, AQH_MQTT_TOPIC *t);
+AQHOME_API AQH_MQTT_TOPIC_LIST *AQH_Storage_GetMqttTopicList(const AQH_STORAGE *sto);
+AQHOME_API AQH_MQTT_TOPIC *AQH_Storage_GetMqttTopicById(const AQH_STORAGE *sto, uint64_t id);
+AQHOME_API AQH_MQTT_TOPIC *AQH_Storage_GetMqttTopicByTopic(const AQH_STORAGE *sto, const char *topic);
+
+AQHOME_API void AQH_Storage_AddValue(AQH_STORAGE *sto, AQH_VALUE *value);
+AQHOME_API AQH_VALUE_LIST *AQH_Storage_GetValueList(const AQH_STORAGE *sto);
+AQHOME_API AQH_VALUE *AQH_Storage_GetValueById(const AQH_STORAGE *sto, uint64_t id);
+
+
+AQHOME_API void AQH_Storage_HandleMqttPublish(AQH_STORAGE *sto, const char *topic, const char *value);
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
+
diff --git a/aqhome/data/storage_p.h b/aqhome/data/storage_p.h
new file mode 100644
index 0000000..c10e234
--- /dev/null
+++ b/aqhome/data/storage_p.h
@@ -0,0 +1,31 @@
+/****************************************************************************
+ * This file is part of the project Gwenhywfar.
+ * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
+ *
+ * The license for this file can be found in the file COPYING which you
+ * should have received along with this file.
+ ****************************************************************************/
+
+#ifndef AQH_STORAGE_P_H
+#define AQH_STORAGE_P_H
+
+
+#include "aqhome/data/storage.h"
+
+
+
+struct AQH_STORAGE {
+ AQH_DEVICE_LIST *deviceList;
+ AQH_MQTT_TOPIC_LIST *mqttTopicList;
+ AQH_VALUE_LIST *valueList;
+
+ uint64_t lastDeviceId;
+ uint64_t lastTopicId;
+ uint64_t lastValueId;
+};
+
+
+
+#endif
+
+
diff --git a/aqhome/data/value.t2d b/aqhome/data/value.t2d
index 2966b6a..9198386 100644
--- a/aqhome/data/value.t2d
+++ b/aqhome/data/value.t2d
@@ -29,8 +29,15 @@
-
-
+
+
+ 0
+ 0
+ public
+ with_getbymember
+
+
+
0
0
public
@@ -44,14 +51,14 @@
-
+
0
0
public
-
+
0
0
public
@@ -59,6 +66,7 @@
+