From 0c03c052b49bb7409f80838a47bd46a316f75d6f Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 9 Apr 2025 13:14:11 +0200 Subject: [PATCH] fucking fixes i hate cpp --- hardware/include/json.hpp | 7 ++++--- hardware/include/main.hpp | 2 +- hardware/include/test.hpp | 0 hardware/src/json.cpp | 10 ++++++---- hardware/src/main.cpp | 14 +++++++++++++- hardware/src/rest.cpp | 5 +++-- hardware/src/test.cpp | 1 - hardware/src/wifi.cpp | 3 +-- 8 files changed, 28 insertions(+), 14 deletions(-) delete mode 100644 hardware/include/test.hpp delete mode 100644 hardware/src/test.cpp diff --git a/hardware/include/json.hpp b/hardware/include/json.hpp index b21cff0..374c239 100644 --- a/hardware/include/json.hpp +++ b/hardware/include/json.hpp @@ -1,7 +1,5 @@ #include -#include "HTTPClient.h" - -HTTPClient http; +#include String serializeSensorValue ( int sensorId, @@ -33,13 +31,16 @@ String serializeDevice ( ); void deserializeSensorValue ( + HTTPClient* http, int httpResponseCode ); void deserializeActuatorStatus ( + HTTPClient* http, int httpResponseCode ); void deserializeDevice ( + HTTPClient* http, int httpResponseCode ); \ No newline at end of file diff --git a/hardware/include/main.hpp b/hardware/include/main.hpp index af92752..e32c116 100644 --- a/hardware/include/main.hpp +++ b/hardware/include/main.hpp @@ -6,4 +6,4 @@ #include "test.hpp" #include "mqtt.hpp" -#define LED 2 \ No newline at end of file +uint32_t getChipID(); \ No newline at end of file diff --git a/hardware/include/test.hpp b/hardware/include/test.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/hardware/src/json.cpp b/hardware/src/json.cpp index b8af490..791a100 100644 --- a/hardware/src/json.cpp +++ b/hardware/src/json.cpp @@ -2,7 +2,6 @@ String response; - String serializeSensorValue(int sensorId, int deviceId, String sensorType, String unit, int sensorStatus, float temperature, float humidity, float carbonMonoxide, float lat, float lon, long timestamp) { DynamicJsonDocument doc(2048); @@ -59,7 +58,8 @@ String serializeDevice(int sensorId, int deviceId, String sensorType, int status return output; } -void deserializeSensorValue (int httpResponseCode){ +void deserializeSensorValue (HTTPClient http, int httpResponseCode) +{ if (httpResponseCode > 0) { @@ -101,7 +101,8 @@ void deserializeSensorValue (int httpResponseCode){ } } -void deserializeActuatorStatus (int httpResponseCode){ +void deserializeActuatorStatus (HTTPClient http, int httpResponseCode) +{ if (httpResponseCode > 0) { @@ -139,7 +140,8 @@ void deserializeActuatorStatus (int httpResponseCode){ } } -void deserializeDevice (int httpResponseCode){ +void deserializeDevice (HTTPClient http, int httpResponseCode) +{ if (httpResponseCode > 0) { diff --git a/hardware/src/main.cpp b/hardware/src/main.cpp index 98d2386..40fb98e 100644 --- a/hardware/src/main.cpp +++ b/hardware/src/main.cpp @@ -1,8 +1,20 @@ #include "main.hpp" - + +const uint32_t deviceId = getChipID(); + +uint32_t getChipID() +{ + uint32_t chipId; + for (int i = 0; i < 17; i = i + 8) { + chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } + return chipId; +} + void setup() { Serial.begin(9600); + // WiFi Connection if(setup_wifi() != 0) { Serial.print("Error connecting to WiFI"); diff --git a/hardware/src/rest.cpp b/hardware/src/rest.cpp index c20cfa8..6208078 100644 --- a/hardware/src/rest.cpp +++ b/hardware/src/rest.cpp @@ -1,4 +1,5 @@ #include "rest.hpp" -RestClient client = RestClient(SERVER_IP, SERVER_PORT); - \ No newline at end of file +HTTPClient httpClient; + + diff --git a/hardware/src/test.cpp b/hardware/src/test.cpp deleted file mode 100644 index ac97f27..0000000 --- a/hardware/src/test.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test.hpp" \ No newline at end of file diff --git a/hardware/src/wifi.cpp b/hardware/src/wifi.cpp index 7734e63..8b2cd6a 100644 --- a/hardware/src/wifi.cpp +++ b/hardware/src/wifi.cpp @@ -1,7 +1,6 @@ #include -WiFiClient espClient; -PubSubClient client(espClient); +WiFiClient wifiClient; int setup_wifi() {