From 45c99ff9cc8778d562a0292cfe72092c0cf1fac1 Mon Sep 17 00:00:00 2001
From: Jan Beinke <git@janbeinke.com>
Date: Sat, 13 Jun 2020 02:10:24 +0200
Subject: [PATCH] Move qthing includes to their own dir and clean up

---
 .gitignore                                    |  2 +-
 bin/set-environment                           |  6 ++---
 qthing/CMakeLists.txt                         |  3 +--
 qthing/color.cpp                              |  2 +-
 qthing/device.hpp                             |  6 -----
 qthing/event.cpp                              |  2 +-
 qthing/include/device.hpp                     |  3 +++
 qthing/{ => include}/event.hpp                | 11 ++++----
 qthing/{ => include}/io.hpp                   |  6 ++++-
 qthing/{peripherals => include}/led_strip.hpp |  2 +-
 qthing/{ => include}/measured.hpp             |  5 ++++
 qthing/{ => include}/mqtt.hpp                 | 11 ++++----
 qthing/{ => include}/mqtt_c.h                 |  7 ++---
 qthing/{ => include}/mqtt_common.h            |  5 +---
 qthing/{ => include}/mqtt_ota.hpp             | 12 ++++-----
 qthing/include/network.hpp                    | 26 +++++++++++++++++++
 qthing/{ => include}/oled_symbols.hpp         |  3 +++
 qthing/{ => include}/polyfill.hpp             |  6 +++++
 qthing/include/power.hpp                      |  7 +++++
 qthing/include/qthing                         | 11 ++++++++
 qthing/include/qthing.hpp                     | 11 ++++++++
 .../{qthing.hpp => include/qthing_legacy.hpp} | 22 ++--------------
 qthing/{ => include}/rc_433.hpp               | 11 ++++----
 qthing/{ => include}/sensor.hpp               |  9 ++++---
 qthing/{network => include}/udp.hpp           |  4 +++
 qthing/include/util.hpp                       |  7 +++++
 qthing/io.cpp                                 |  2 +-
 qthing/lcd.cpp                                |  4 ++-
 qthing/measured.cpp                           |  2 +-
 qthing/mqtt_ota.cpp                           |  2 +-
 qthing/network/network.cpp                    |  5 ++--
 qthing/network/network.hpp                    |  8 ------
 qthing/network/network_animation.cpp          |  5 ++--
 qthing/network/udp.cpp                        |  4 +--
 qthing/network/wifi.cpp                       |  3 ++-
 qthing/ntp.cpp                                |  2 +-
 qthing/oled.cpp                               |  3 ++-
 qthing/peripherals/button_panel_5x5.cpp       |  5 ++--
 qthing/peripherals/led_strip.cpp              |  3 ++-
 qthing/sensor.cpp                             | 12 ++++-----
 qthing/status.cpp                             |  3 ++-
 qthing/system/power.cpp                       |  6 ++++-
 qthing/util.cpp                               | 11 ++++----
 qthing/util.hpp                               |  6 -----
 44 files changed, 174 insertions(+), 112 deletions(-)
 delete mode 100644 qthing/device.hpp
 create mode 100644 qthing/include/device.hpp
 rename qthing/{ => include}/event.hpp (83%)
 rename qthing/{ => include}/io.hpp (79%)
 rename qthing/{peripherals => include}/led_strip.hpp (82%)
 rename qthing/{ => include}/measured.hpp (97%)
 rename qthing/{ => include}/mqtt.hpp (57%)
 rename qthing/{ => include}/mqtt_c.h (72%)
 rename qthing/{ => include}/mqtt_common.h (92%)
 rename qthing/{ => include}/mqtt_ota.hpp (67%)
 create mode 100644 qthing/include/network.hpp
 rename qthing/{ => include}/oled_symbols.hpp (97%)
 rename qthing/{ => include}/polyfill.hpp (74%)
 create mode 100644 qthing/include/power.hpp
 create mode 100644 qthing/include/qthing
 create mode 100644 qthing/include/qthing.hpp
 rename qthing/{qthing.hpp => include/qthing_legacy.hpp} (92%)
 rename qthing/{ => include}/rc_433.hpp (89%)
 rename qthing/{ => include}/sensor.hpp (58%)
 rename qthing/{network => include}/udp.hpp (60%)
 create mode 100644 qthing/include/util.hpp
 delete mode 100644 qthing/network/network.hpp
 delete mode 100644 qthing/util.hpp

diff --git a/.gitignore b/.gitignore
index 96d9a05..7c64978 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,4 @@ sdkconfig.old
 # This directory contains user-specific environment configurations
 /environments/*
 # Ignore symlink to current environment
-/qthing/environment.h
+/qthing/include/environment.h
diff --git a/bin/set-environment b/bin/set-environment
index 5c3e29e..51a8b19 100755
--- a/bin/set-environment
+++ b/bin/set-environment
@@ -17,9 +17,9 @@ function link_environment {
     else
         TARGET="../$1"
     fi
-    echo "Linking qthing/environment.h to $TARGET"
-    ln -snf "$TARGET" "qthing/environment.h"
-    touch --no-create "qthing/environment.h"
+    echo "Linking qthing/include/environment.h to $TARGET"
+    ln -snf "$TARGET" "qthing/include/environment.h"
+    touch --no-create "qthing/include/environment.h"
 }
 
 if [[ -z "$1" ]]; then
diff --git a/qthing/CMakeLists.txt b/qthing/CMakeLists.txt
index ffe1285..21a3d2c 100644
--- a/qthing/CMakeLists.txt
+++ b/qthing/CMakeLists.txt
@@ -6,8 +6,7 @@ idf_component_register(
   "system"
 
   INCLUDE_DIRS
-  "."
-  "network"
+  "include"
 
   REQUIRES
   ESP32-Digital-RGB-LED-Drivers
diff --git a/qthing/color.cpp b/qthing/color.cpp
index 82b3d97..b6ce54e 100644
--- a/qthing/color.cpp
+++ b/qthing/color.cpp
@@ -1,4 +1,4 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 #include <cmath>
 
 namespace qthing {
diff --git a/qthing/device.hpp b/qthing/device.hpp
deleted file mode 100644
index b6c6b72..0000000
--- a/qthing/device.hpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef DEVICE_H
-#define DEVICE_H
-
-void device_main();
-
-#endif
\ No newline at end of file
diff --git a/qthing/event.cpp b/qthing/event.cpp
index db915c8..f8b4a04 100644
--- a/qthing/event.cpp
+++ b/qthing/event.cpp
@@ -1,4 +1,4 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 #include "event.hpp"
 
 namespace qthing {
diff --git a/qthing/include/device.hpp b/qthing/include/device.hpp
new file mode 100644
index 0000000..ddab8cf
--- /dev/null
+++ b/qthing/include/device.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+void device_main();
diff --git a/qthing/event.hpp b/qthing/include/event.hpp
similarity index 83%
rename from qthing/event.hpp
rename to qthing/include/event.hpp
index a8e6090..9027847 100644
--- a/qthing/event.hpp
+++ b/qthing/include/event.hpp
@@ -1,13 +1,14 @@
-#ifndef EVENT_H
-#define EVENT_H
+#pragma once
 
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include <string>
 #include <functional>
 
 namespace qthing {
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
 using string_callback_t = std::function<void(const std::string&)>;
 
 void set_oled_log_callback(string_callback_t callback);
@@ -18,6 +19,6 @@ void update_eth_connection_status(connection_status_t status);
 
 void update_mqtt_connection_status(connection_status_t status);
 
-}
-
 #endif
+
+}
diff --git a/qthing/io.hpp b/qthing/include/io.hpp
similarity index 79%
rename from qthing/io.hpp
rename to qthing/include/io.hpp
index b2d94ca..3e1338d 100644
--- a/qthing/io.hpp
+++ b/qthing/include/io.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "qthing.hpp"
+#include "qthing_legacy.hpp"
 
 #include <stdint.h>
 #include <string>
@@ -10,8 +10,12 @@
 
 namespace qthing {
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
 void gpio_init_input(gpio_num_t gpio_num);
 void gpio_init_output(gpio_num_t gpio_num, uint32_t level);
 void pulse_relay(gpio_num_t gpio_off);
 
+#endif
+
 }
diff --git a/qthing/peripherals/led_strip.hpp b/qthing/include/led_strip.hpp
similarity index 82%
rename from qthing/peripherals/led_strip.hpp
rename to qthing/include/led_strip.hpp
index 47d28a4..b66eecc 100644
--- a/qthing/peripherals/led_strip.hpp
+++ b/qthing/include/led_strip.hpp
@@ -7,4 +7,4 @@
 
 #include "esp32_digital_led_lib.h"
 
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
diff --git a/qthing/measured.hpp b/qthing/include/measured.hpp
similarity index 97%
rename from qthing/measured.hpp
rename to qthing/include/measured.hpp
index b6dfb63..f714cbf 100644
--- a/qthing/measured.hpp
+++ b/qthing/include/measured.hpp
@@ -13,6 +13,8 @@
 
 namespace qthing {
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
     namespace measured {
 
         typedef struct {
@@ -55,4 +57,7 @@ namespace qthing {
             void mqtt(const std::vector<qthing::measured::sensor_data_t>& data);
         }
     }
+
+#endif
+
 }
diff --git a/qthing/mqtt.hpp b/qthing/include/mqtt.hpp
similarity index 57%
rename from qthing/mqtt.hpp
rename to qthing/include/mqtt.hpp
index 1482cab..1b8a506 100644
--- a/qthing/mqtt.hpp
+++ b/qthing/include/mqtt.hpp
@@ -1,15 +1,16 @@
-#ifndef MQTT_H
-#define MQTT_H
+#pragma once
 
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include <string>
 #include <functional>
 
 namespace qthing {
 
-void mqtt_client_start();
+#ifndef QTHING_HIDE_PRIVATE_API
 
-}
+void mqtt_client_start();
 
 #endif
+
+}
diff --git a/qthing/mqtt_c.h b/qthing/include/mqtt_c.h
similarity index 72%
rename from qthing/mqtt_c.h
rename to qthing/include/mqtt_c.h
index dd791e6..fc2e1aa 100644
--- a/qthing/mqtt_c.h
+++ b/qthing/include/mqtt_c.h
@@ -1,10 +1,11 @@
 // Include as extern "C"
 
-#ifndef MQTT_C_H
-#define MQTT_C_H
+#pragma once
 
 #include "mqtt_client.h"
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
 esp_mqtt_client_handle_t mqtt_client_start_c(mqtt_event_callback_t mqtt_event_handler);
 
-#endif
\ No newline at end of file
+#endif
diff --git a/qthing/mqtt_common.h b/qthing/include/mqtt_common.h
similarity index 92%
rename from qthing/mqtt_common.h
rename to qthing/include/mqtt_common.h
index 945f316..3400ea6 100644
--- a/qthing/mqtt_common.h
+++ b/qthing/include/mqtt_common.h
@@ -1,5 +1,4 @@
-#ifndef MQTT_COMMON_H
-#define MQTT_COMMON_H
+#pragma once
 
 #include "environment.h"
 #include "device_config.h"
@@ -20,5 +19,3 @@
 #define OTA_PROGRESS_TOPIC DEVICE_NAMESPACE "ota/progress"
 #define OTA_STATE_TOPIC    DEVICE_NAMESPACE "ota/state"
 #define OTA_ERROR_TOPIC    DEVICE_NAMESPACE "ota/error"
-
-#endif
diff --git a/qthing/mqtt_ota.hpp b/qthing/include/mqtt_ota.hpp
similarity index 67%
rename from qthing/mqtt_ota.hpp
rename to qthing/include/mqtt_ota.hpp
index f6c6a1f..f873256 100644
--- a/qthing/mqtt_ota.hpp
+++ b/qthing/include/mqtt_ota.hpp
@@ -1,14 +1,14 @@
-#ifndef MQTT_OTA_H
-#define MQTT_OTA_H
-
-#include <qthing.hpp>
+#pragma once
 
+#include "qthing_legacy.hpp"
 
 namespace qthing {
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
 void handle_ota_message(const multipart_message_t& message);
 void add_ota_event_callback(ota_event_callback_t handler);
 
-}
-
 #endif
+
+}
diff --git a/qthing/include/network.hpp b/qthing/include/network.hpp
new file mode 100644
index 0000000..4908436
--- /dev/null
+++ b/qthing/include/network.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+namespace qthing {
+
+
+void enable_wifi();
+connection_status_t get_wifi_connection_status();
+void add_wifi_connection_status_callback(connection_status_callback_t callback);
+void add_combined_mqtt_connection_status_callback(connection_status_callback_t handler);
+
+void enable_ethernet_lan8720();
+connection_status_t get_eth_connection_status();
+void add_eth_connection_status_callback(connection_status_callback_t callback);
+
+connection_status_t get_network_connection_status();
+void add_network_connection_status_callback(connection_status_callback_t callback);
+
+
+#ifndef QTHING_HIDE_PRIVATE_API
+
+void start_network_clients();
+void initialize_network();
+
+#endif
+
+}
diff --git a/qthing/oled_symbols.hpp b/qthing/include/oled_symbols.hpp
similarity index 97%
rename from qthing/oled_symbols.hpp
rename to qthing/include/oled_symbols.hpp
index 63e93c6..af8e406 100644
--- a/qthing/oled_symbols.hpp
+++ b/qthing/include/oled_symbols.hpp
@@ -1,3 +1,5 @@
+#ifndef QTHING_HIDE_PRIVATE_API
+
 #include "Arduino.h"
 
 const uint8_t wifi_connected_symbol[] PROGMEM = {
@@ -101,3 +103,4 @@ const uint8_t other_symbol[] PROGMEM = {
     B00000000
 };
 
+#endif
diff --git a/qthing/polyfill.hpp b/qthing/include/polyfill.hpp
similarity index 74%
rename from qthing/polyfill.hpp
rename to qthing/include/polyfill.hpp
index 84f38ef..87cc3ce 100644
--- a/qthing/polyfill.hpp
+++ b/qthing/include/polyfill.hpp
@@ -1,6 +1,10 @@
+#pragma once
+
 #include <string>
 #include <sstream>
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
 template <typename T>
 std::string to_string(T value)
 {
@@ -8,3 +12,5 @@ std::string to_string(T value)
     os << value ;
     return os.str() ;
 }
+
+#endif
diff --git a/qthing/include/power.hpp b/qthing/include/power.hpp
new file mode 100644
index 0000000..159cd15
--- /dev/null
+++ b/qthing/include/power.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+namespace qthing {
+
+void power_managment_max_power();
+
+}
diff --git a/qthing/include/qthing b/qthing/include/qthing
new file mode 100644
index 0000000..0f8fbdc
--- /dev/null
+++ b/qthing/include/qthing
@@ -0,0 +1,11 @@
+#pragma once
+
+#define QTHING_HIDE_PRIVATE_API
+
+#include "qthing_legacy.hpp"
+
+#include "network.hpp"
+#include "power.hpp"
+#include "util.hpp"
+
+#undef QTHING_HIDE_PRIVATE_API
diff --git a/qthing/include/qthing.hpp b/qthing/include/qthing.hpp
new file mode 100644
index 0000000..0f8fbdc
--- /dev/null
+++ b/qthing/include/qthing.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#define QTHING_HIDE_PRIVATE_API
+
+#include "qthing_legacy.hpp"
+
+#include "network.hpp"
+#include "power.hpp"
+#include "util.hpp"
+
+#undef QTHING_HIDE_PRIVATE_API
diff --git a/qthing/qthing.hpp b/qthing/include/qthing_legacy.hpp
similarity index 92%
rename from qthing/qthing.hpp
rename to qthing/include/qthing_legacy.hpp
index 6067cb8..c547cda 100644
--- a/qthing/qthing.hpp
+++ b/qthing/include/qthing_legacy.hpp
@@ -1,5 +1,4 @@
-#ifndef QTHING_H
-#define QTHING_H
+#pragma once
 
 #include <string>
 
@@ -46,19 +45,6 @@ namespace qthing {
     void enable_status_led(gpio_num_t gpio = GPIO_NUM_2, bool negated = false);
     void show_activity();
 
-    // network
-    void enable_wifi();
-    connection_status_t get_wifi_connection_status();
-    void add_wifi_connection_status_callback(connection_status_callback_t callback);
-    void add_combined_mqtt_connection_status_callback(connection_status_callback_t handler);
-
-    void enable_ethernet_lan8720();
-    connection_status_t get_eth_connection_status();
-    void add_eth_connection_status_callback(connection_status_callback_t callback);
-
-    connection_status_t get_network_connection_status();
-    void add_network_connection_status_callback(connection_status_callback_t callback);
-
     // mqtt
     void publish_message(const std::string& topic, const std::string& message);
     void add_message_callback(const std::string& topic, message_callback_t callback);
@@ -83,9 +69,6 @@ namespace qthing {
 
     void enable_lcd(const std::string& topic, uint8_t rs, uint8_t en, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
 
-    // power
-    void power_managment_max_power();
-
     // LED strips
     enum led_strip_types_t {
         LED_WS2812_V1,
@@ -262,11 +245,10 @@ namespace qthing {
         bool get_key_state(uint8_t x, uint8_t y);
         uint32_t get_key_activation_time(uint8_t x, uint8_t y);
     }
-}
 
 // utility
 std::string to_string(float value, int precision = 2);
 std::string to_string(uint32_t value);
 std::string to_string(struct sockaddr_in6 sourceAddr);
 
-#endif
+}
diff --git a/qthing/rc_433.hpp b/qthing/include/rc_433.hpp
similarity index 89%
rename from qthing/rc_433.hpp
rename to qthing/include/rc_433.hpp
index 2bf9316..7a1764e 100644
--- a/qthing/rc_433.hpp
+++ b/qthing/include/rc_433.hpp
@@ -1,12 +1,13 @@
-#ifndef RC_433_H
-#define RC_433_H
+#pragma once
 
 #include <string>
 
 #include "driver/gpio.h"
 
-
 namespace qthing {
+
+#ifndef QTHING_HIDE_PRIVATE_API
+
 void rc_switch_on(const std::string& code);
 void rc_switch_off(const std::string& code);
 void rc_switch(const std::string& code, bool state);
@@ -14,6 +15,6 @@ void rc_switch(const std::string& code, bool state);
 void rc_enable_send(const std::string& send_on_topic, const std::string& send_off_topic, gpio_num_t gpio);
 void rc_enable_receive(const std::string& topic, gpio_num_t gpio);
 
-}
-
 #endif
+
+}
diff --git a/qthing/sensor.hpp b/qthing/include/sensor.hpp
similarity index 58%
rename from qthing/sensor.hpp
rename to qthing/include/sensor.hpp
index 855b2a6..75ec461 100644
--- a/qthing/sensor.hpp
+++ b/qthing/include/sensor.hpp
@@ -1,10 +1,11 @@
-#ifndef SENSOR_H
-#define SENSOR_H
+#pragma once
 
 namespace qthing {
 
-void add_soil_moisture_sensor();
+#ifndef QTHING_HIDE_PRIVATE_API
 
-}
+void add_soil_moisture_sensor();
 
 #endif
+
+}
diff --git a/qthing/network/udp.hpp b/qthing/include/udp.hpp
similarity index 60%
rename from qthing/network/udp.hpp
rename to qthing/include/udp.hpp
index 880516b..2937cec 100644
--- a/qthing/network/udp.hpp
+++ b/qthing/include/udp.hpp
@@ -2,6 +2,10 @@
 
 namespace qthing {
 
+#ifndef QTHING_HIDE_PRIVATE_API
+
 void start_udp_server();
 
+#endif
+
 }
diff --git a/qthing/include/util.hpp b/qthing/include/util.hpp
new file mode 100644
index 0000000..a9e37f2
--- /dev/null
+++ b/qthing/include/util.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+namespace qthing {
+
+unsigned long millis();
+
+}
diff --git a/qthing/io.cpp b/qthing/io.cpp
index bb5db70..eda6533 100644
--- a/qthing/io.cpp
+++ b/qthing/io.cpp
@@ -1,4 +1,4 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include "io.hpp"
 #include "mqtt.hpp"
diff --git a/qthing/lcd.cpp b/qthing/lcd.cpp
index a08efc0..433de17 100644
--- a/qthing/lcd.cpp
+++ b/qthing/lcd.cpp
@@ -1,5 +1,7 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
+
 #include "mqtt.hpp"
+#include "network.hpp"
 
 #include <string>
 #include <vector>
diff --git a/qthing/measured.cpp b/qthing/measured.cpp
index e537a52..bcd3346 100644
--- a/qthing/measured.cpp
+++ b/qthing/measured.cpp
@@ -7,7 +7,7 @@
 #include "freertos/task.h"
 #include "esp_log.h"
 
-#include "qthing.hpp"
+#include "qthing_legacy.hpp"
 #include "mqtt_common.h"
 
 
diff --git a/qthing/mqtt_ota.cpp b/qthing/mqtt_ota.cpp
index 2f71521..39ed83c 100644
--- a/qthing/mqtt_ota.cpp
+++ b/qthing/mqtt_ota.cpp
@@ -6,7 +6,7 @@
 #include "esp_system.h"
 #include "esp_ota_ops.h"
 
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #define TAG "MQTT_OTA"
 
diff --git a/qthing/network/network.cpp b/qthing/network/network.cpp
index f2479e6..78ab9d8 100644
--- a/qthing/network/network.cpp
+++ b/qthing/network/network.cpp
@@ -1,10 +1,11 @@
-#include "qthing.hpp"
+#include "qthing_legacy.hpp"
+
 #include "io.hpp"
 #include "environment.h"
 #include "device_config.h"
 #include "event.hpp"
 #include "mqtt.hpp"
-#include "network/udp.hpp"
+#include "udp.hpp"
 
 #include "string.h"
 
diff --git a/qthing/network/network.hpp b/qthing/network/network.hpp
deleted file mode 100644
index 4105e51..0000000
--- a/qthing/network/network.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-
-namespace qthing {
-
-void start_network_clients();
-void initialize_network();
-
-}
diff --git a/qthing/network/network_animation.cpp b/qthing/network/network_animation.cpp
index 65a0c2f..6bc4219 100644
--- a/qthing/network/network_animation.cpp
+++ b/qthing/network/network_animation.cpp
@@ -1,5 +1,6 @@
-#import <qthing.hpp>
-#import "peripherals/led_strip.hpp"
+#import "qthing_legacy.hpp"
+
+#import "led_strip.hpp"
 #import <algorithm>
 #import <vector>
 
diff --git a/qthing/network/udp.cpp b/qthing/network/udp.cpp
index 350a321..24d948c 100644
--- a/qthing/network/udp.cpp
+++ b/qthing/network/udp.cpp
@@ -1,4 +1,4 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include <map>
 
@@ -74,7 +74,7 @@ static void udp_server_task(void *pvParameters)
             }
             // Data received
             else {
-                ESP_LOGI(TAG, "Received %d bytes from %s", len, to_string(sourceAddr).c_str());
+                ESP_LOGI(TAG, "Received %d bytes from %s", len, qthing::to_string(sourceAddr).c_str());
 
                 std::string payload_str(rx_buffer);
                 int16_t lenBestMatch = -1;
diff --git a/qthing/network/wifi.cpp b/qthing/network/wifi.cpp
index 53ecf21..fed1a75 100644
--- a/qthing/network/wifi.cpp
+++ b/qthing/network/wifi.cpp
@@ -1,4 +1,5 @@
-#include "qthing.hpp"
+#include "qthing_legacy.hpp"
+
 #include "network.hpp"
 #include "io.hpp"
 #include "environment.h"
diff --git a/qthing/ntp.cpp b/qthing/ntp.cpp
index 06f0859..3c6879d 100644
--- a/qthing/ntp.cpp
+++ b/qthing/ntp.cpp
@@ -1,6 +1,6 @@
 #undef __STRICT_ANSI__
 
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include <freertos/FreeRTOS.h>
 #include "freertos/task.h"
diff --git a/qthing/oled.cpp b/qthing/oled.cpp
index a9cc356..f8e1ea9 100644
--- a/qthing/oled.cpp
+++ b/qthing/oled.cpp
@@ -1,6 +1,7 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include "event.hpp"
+#include "network.hpp"
 
 #include "Arduino.h"
 #include "SSD1306Wire.h"
diff --git a/qthing/peripherals/button_panel_5x5.cpp b/qthing/peripherals/button_panel_5x5.cpp
index 2d1b615..10bcac1 100644
--- a/qthing/peripherals/button_panel_5x5.cpp
+++ b/qthing/peripherals/button_panel_5x5.cpp
@@ -1,5 +1,6 @@
-#include <qthing.hpp>
-#include <io.hpp>
+#include "qthing_legacy.hpp"
+
+#include "io.hpp"
 
 #include <array>
 #include <functional>
diff --git a/qthing/peripherals/led_strip.cpp b/qthing/peripherals/led_strip.cpp
index 53f62cd..caba405 100644
--- a/qthing/peripherals/led_strip.cpp
+++ b/qthing/peripherals/led_strip.cpp
@@ -1,6 +1,7 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include "led_strip.hpp"
+#include "power.hpp"
 
 #include <algorithm>
 
diff --git a/qthing/sensor.cpp b/qthing/sensor.cpp
index 61e329d..fa03f05 100644
--- a/qthing/sensor.cpp
+++ b/qthing/sensor.cpp
@@ -1,7 +1,9 @@
+#include "qthing_legacy.hpp"
+
 #include "mqtt.hpp"
+#include "polyfill.hpp"
 
 #include <string>
-#include "polyfill.hpp"
 
 #include "esp_log.h"
 #include <driver/adc.h>
@@ -10,8 +12,6 @@
 
 #define SLEEP_PERIOD 60 * 1000 / portTICK_PERIOD_MS
 
-namespace qthing {
-
 bool message = false;
 void soil_moisture_sensor_task(void* arg) {
     adc1_config_width(ADC_WIDTH_12Bit);
@@ -23,11 +23,11 @@ void soil_moisture_sensor_task(void* arg) {
             value += adc1_get_raw(ADC1_CHANNEL_4);
             vTaskDelay(1000 / 16 / portTICK_PERIOD_MS);
         }
-        publish_message("device/plant_auto/soil_moisture", to_string(value));
+        qthing::publish_message("device/plant_auto/soil_moisture", to_string(value));
         ESP_LOGI("SOIL_SENSOR", "%i", value);
 
         if (!message && value < 30000) {
-            publish_message("edi/cmd/say", "{\"args\": \"iiiiih, ich bin nass\"}");
+            qthing::publish_message("edi/cmd/say", "{\"args\": \"iiiiih, ich bin nass\"}");
             message = true;
         }
 
@@ -38,5 +38,3 @@ void soil_moisture_sensor_task(void* arg) {
 void add_soil_moisture_sensor() {
     xTaskCreate(soil_moisture_sensor_task, "soil_moisture_sensor_task", 2048, NULL, 4, NULL);
 }
-
-}
diff --git a/qthing/status.cpp b/qthing/status.cpp
index c8ce382..8b253bb 100644
--- a/qthing/status.cpp
+++ b/qthing/status.cpp
@@ -1,6 +1,7 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
 
 #include "io.hpp"
+#include "network.hpp"
 
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
diff --git a/qthing/system/power.cpp b/qthing/system/power.cpp
index 3e0152d..ded7b7d 100644
--- a/qthing/system/power.cpp
+++ b/qthing/system/power.cpp
@@ -1,4 +1,6 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
+
+#include "power.hpp"
 
 #include "esp_pm.h"
 #include "freertos/FreeRTOS.h"
@@ -8,6 +10,7 @@
 static bool max_power = false;
 
 namespace qthing {
+
   void power_managment_max_power() {
     if (!max_power) {
       max_power = true;
@@ -23,4 +26,5 @@ namespace qthing {
       vTaskDelay(200 / portTICK_PERIOD_MS);
     }
   }
+
 }
diff --git a/qthing/util.cpp b/qthing/util.cpp
index 8f1f820..436f0be 100644
--- a/qthing/util.cpp
+++ b/qthing/util.cpp
@@ -1,4 +1,5 @@
-#include <qthing.hpp>
+#include "qthing_legacy.hpp"
+
 #include "util.hpp"
 
 #include <sstream>
@@ -7,24 +8,24 @@
 #include "freertos/task.h"
 #include "lwip/sockets.h"
 
-unsigned long IRAM_ATTR millis() {
+unsigned long IRAM_ATTR qthing::millis() {
     return xTaskGetTickCount() * portTICK_PERIOD_MS;
 }
 
-std::string to_string(float value, int precision) {
+std::string qthing::to_string(float value, int precision) {
     std::stringstream stream;
     stream.precision(precision);
     stream << value;
     return stream.str();
 }
 
-std::string to_string(uint32_t value) {
+std::string qthing::to_string(uint32_t value) {
     std::stringstream stream;
     stream << value;
     return stream.str();
 }
 
-std::string to_string(struct sockaddr_in6 sourceAddr) {
+std::string qthing::to_string(struct sockaddr_in6 sourceAddr) {
     char addr_str[128];
 
     if (sourceAddr.sin6_family == PF_INET) {
diff --git a/qthing/util.hpp b/qthing/util.hpp
deleted file mode 100644
index 54a34a0..0000000
--- a/qthing/util.hpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef UTIL_H
-#define UTIL_H
-
-unsigned long millis();
-
-#endif
-- 
GitLab