From 14619889e48b3f1587ea85e18413dafd2d696256 Mon Sep 17 00:00:00 2001
From: Zoe Pfister <zoe.pfister@student.uibk.ac.at>
Date: Thu, 6 Oct 2022 12:48:13 +0200
Subject: [PATCH] WIP: replace pack solution of Message transfer to JSON
 solution using ArduinoJson.

---
 client/client/include/ForteSensor.hpp         |  6 +-
 client/client/include/Protocol.hpp            | 14 +++
 client/client/lib/caching/src/ram_caching.cpp | 47 +++++-----
 client/client/lib/caching/src/ram_caching.hpp |  6 +-
 client/client/lib/dr26_analogue/src/dr26.cpp  | 12 ++-
 client/client/lib/dr26_analogue/src/dr26.hpp  |  7 +-
 client/client/lib/drs26_digital/drs26.cpp     | 24 +++---
 client/client/lib/drs26_digital/drs26.hpp     | 16 +++-
 client/client/lib/espnow/README               |  2 +-
 .../lib/espnow/src/ClientDataPackage.hpp      | 46 ++++++++--
 client/client/lib/espnow/src/Message.cpp      | 86 +++++++++++++------
 client/client/lib/espnow/src/Message.hpp      | 17 ++--
 client/client/lib/ina219/ina219.cpp           | 10 ++-
 client/client/lib/ina219/ina219.hpp           |  5 +-
 client/client/lib/scd30/scd30.cpp             | 10 ++-
 client/client/lib/scd30/scd30.hpp             |  5 +-
 client/client/platformio.ini                  | 27 +++---
 client/client/src/main.cpp                    |  4 +-
 client/client/test/TestClientDataPackage.cpp  | 19 ++++
 client/client/test/TestClientDataPackage.hpp  | 14 +++
 client/client/test/TestMessage.cpp            | 24 ------
 client/client/test/TestMessage.hpp            |  8 --
 client/client/test/main.cpp                   |  5 +-
 23 files changed, 268 insertions(+), 146 deletions(-)
 create mode 100644 client/client/include/Protocol.hpp
 create mode 100644 client/client/test/TestClientDataPackage.cpp
 create mode 100644 client/client/test/TestClientDataPackage.hpp
 delete mode 100644 client/client/test/TestMessage.cpp
 delete mode 100644 client/client/test/TestMessage.hpp

diff --git a/client/client/include/ForteSensor.hpp b/client/client/include/ForteSensor.hpp
index d322213..1db845d 100644
--- a/client/client/include/ForteSensor.hpp
+++ b/client/client/include/ForteSensor.hpp
@@ -2,12 +2,14 @@
 #define _FORTE_SENSOR
 
 #include "Message.hpp"
+#include "Protocol.hpp"
 template <class T>
 class Forte_Sensor {
   public:
-	virtual T read_data() = 0;
+	virtual T readData() = 0;
 	virtual void setup() = 0;
-	virtual Message build_message() = 0;
+	virtual Message buildMessage() = 0;
+	virtual Protocol getProtocol() = 0;
 
   private:
 };
diff --git a/client/client/include/Protocol.hpp b/client/client/include/Protocol.hpp
new file mode 100644
index 0000000..2bcdab9
--- /dev/null
+++ b/client/client/include/Protocol.hpp
@@ -0,0 +1,14 @@
+//
+// Created by zoe on 10/5/22.
+//
+
+#ifndef CLIENT_PROTOCOL_HPP
+#define CLIENT_PROTOCOL_HPP
+
+#include <map>
+enum Protocol { I2C, RS485, Analog };
+
+// protocol to string
+static std::map<Protocol, const char *> protocolToString = {{I2C, "I2C"}, {RS485, "RS485"}, {Analog, "Analog"}};
+
+#endif // CLIENT_PROTOCOL_HPP
diff --git a/client/client/lib/caching/src/ram_caching.cpp b/client/client/lib/caching/src/ram_caching.cpp
index f5ebd71..b7df125 100644
--- a/client/client/lib/caching/src/ram_caching.cpp
+++ b/client/client/lib/caching/src/ram_caching.cpp
@@ -1,27 +1,28 @@
 #include "ram_caching.hpp"
 
 static const char* TAG = "CACHING";
+const int NUM_SENSORS = 10;
 
-RTC_DATA_ATTR int cachedAmount = -1;
-RTC_DATA_ATTR ClientDataPackage backup[NUM_SENSORS];
-
-ClientDataPackage ram_cache_pop()
-{
-	return backup[cachedAmount--];
-}
-
-void ram_cache_push(ClientDataPackage data)
-{
-	backup[++cachedAmount] = data;
-	ESP_LOGI(TAG, "ClientDataPackage saved");
-}
-
-bool ram_cache_is_empty()
-{
-	return cachedAmount == -1;
-}
-
-bool ram_cache_is_full()
-{
-	return cachedAmount == 9;
-}
\ No newline at end of file
+//RTC_DATA_ATTR int cachedAmount = -1;
+//RTC_DATA_ATTR ClientDataPackage backup[NUM_SENSORS];
+//
+//ClientDataPackage ram_cache_pop()
+//{
+//	return backup[cachedAmount--];
+//}
+//
+//void ram_cache_push(ClientDataPackage data)
+//{
+//	backup[++cachedAmount] = data;
+//	ESP_LOGI(TAG, "ClientDataPackage saved");
+//}
+//
+//bool ram_cache_is_empty()
+//{
+//	return cachedAmount == -1;
+//}
+//
+//bool ram_cache_is_full()
+//{
+//	return cachedAmount == 9;
+//}
\ No newline at end of file
diff --git a/client/client/lib/caching/src/ram_caching.hpp b/client/client/lib/caching/src/ram_caching.hpp
index 3ade962..f4152ce 100644
--- a/client/client/lib/caching/src/ram_caching.hpp
+++ b/client/client/lib/caching/src/ram_caching.hpp
@@ -1,12 +1,12 @@
 #ifndef _RAM_CACHE
 #define _RAM_CACHE
-#include "ClientDataPackage.hpp"
+//#include "ClientDataPackage.hpp"
 #include "esp_log.h"
 #include <ESP32Time.h>
 
 bool ram_cache_is_empty();
 bool ram_cache_is_full();
-void ram_cache_push(ClientDataPackage data);
-ClientDataPackage ram_cache_pop();
+//void ram_cache_push(ClientDataPackage data);
+//ClientDataPackage ram_cache_pop();
 
 #endif
\ No newline at end of file
diff --git a/client/client/lib/dr26_analogue/src/dr26.cpp b/client/client/lib/dr26_analogue/src/dr26.cpp
index c2cec29..626203d 100644
--- a/client/client/lib/dr26_analogue/src/dr26.cpp
+++ b/client/client/lib/dr26_analogue/src/dr26.cpp
@@ -17,7 +17,7 @@ void Forte_DR26 ::setup()
 	delay(100);
 }
 
-float Forte_DR26 ::read_data()
+float Forte_DR26 ::readData()
 {
 	float volts = 0;
 	for (int i = 0; i < 10; i++) {
@@ -44,12 +44,16 @@ float Forte_DR26 ::read_data()
 // GAIN_FOUR       // 4x gain   +/- 1.024V  1 bit = 0.03125mV
 // GAIN_EIGHT      // 8x gain   +/- 0.512V  1 bit = 0.015625mV
 // GAIN_SIXTEEN    // 16x gain  +/- 0.256V  1 bit = 0.0078125mV
-void Forte_DR26 ::change_Gain(adsGain_t gain)
+void Forte_DR26 ::changeGain(adsGain_t gain)
 {
 	ads.setGain(gain);
 }
 
-Message Forte_DR26::build_message()
+Message Forte_DR26::buildMessage()
 {
 	throw "Not implemented";
-}
\ No newline at end of file
+}
+Protocol Forte_DR26::getProtocol()
+{
+	return Analog;
+}
diff --git a/client/client/lib/dr26_analogue/src/dr26.hpp b/client/client/lib/dr26_analogue/src/dr26.hpp
index b06c420..9c9efa5 100644
--- a/client/client/lib/dr26_analogue/src/dr26.hpp
+++ b/client/client/lib/dr26_analogue/src/dr26.hpp
@@ -11,9 +11,10 @@
 class Forte_DR26 : public Forte_Sensor<float> {
   public:
 	void setup() override;
-	float read_data() override;
-	void change_Gain(adsGain_t gain);
-	Message build_message() override;
+	float readData() override;
+	void changeGain(adsGain_t gain);
+	Message buildMessage() override;
+	Protocol getProtocol() override;
 
   private:
 };
diff --git a/client/client/lib/drs26_digital/drs26.cpp b/client/client/lib/drs26_digital/drs26.cpp
index f6f97ca..9e77230 100644
--- a/client/client/lib/drs26_digital/drs26.cpp
+++ b/client/client/lib/drs26_digital/drs26.cpp
@@ -1,6 +1,6 @@
 #include <drs26.hpp>
 
-static const char* TAG = "DRS26";
+static const std::string TAG = "DRS26";
 /*
 It happens for some reason that the sensor cant get reached every 2 time
 Because the sensor use sdi12 protocoll we have to wait aproxemettly 1 secound between the commands
@@ -12,7 +12,7 @@ void Forte_DRS26 ::setup()
 	drs26.begin(4);
 }
 
-out_data_drs26 Forte_DRS26 ::read_data()
+out_data_drs26 Forte_DRS26 ::readData()
 {
 	String sdiResponse = "";
 	String measurement_command =
@@ -36,16 +36,20 @@ out_data_drs26 Forte_DRS26 ::read_data()
 
 	if (sdiResponse.length() > 1) {
 		data.id = sdiResponse.substring(0, 8).toInt();
-		data.circumference = sdiResponse.substring(9, 15).toFloat();
-		data.temperatur = sdiResponse.substring(16, 22).toFloat();
+		data.circumferenceIncrement = sdiResponse.substring(9, 15).toFloat();
+		data.temperature = sdiResponse.substring(16, 22).toFloat();
 	}
 	return data;
 }
 
-Message Forte_DRS26 ::build_message()
+Message Forte_DRS26 ::buildMessage()
 {
-	 auto message = Message();
-	 message.add_data(12.12, 1);
-	 ESP_LOGE(TAG, "test");
-	 return message;
-}
\ No newline at end of file
+	auto message = Message();
+	message.addData(12.12, measurementTypeToString[MeasurementType::TEMPERATURE], TAG, 4);
+	ESP_LOGE(TAG.c_str(), "test");
+	return message;
+}
+Protocol Forte_DRS26::getProtocol()
+{
+	return I2C;
+}
diff --git a/client/client/lib/drs26_digital/drs26.hpp b/client/client/lib/drs26_digital/drs26.hpp
index 6a64da5..153371d 100644
--- a/client/client/lib/drs26_digital/drs26.hpp
+++ b/client/client/lib/drs26_digital/drs26.hpp
@@ -7,22 +7,30 @@
 #include "esp_log.h"
 #include "pinout.hpp"
 #include <SDI12.h>
+#include <map>
 
 struct out_data_drs26 {
 	int id;
-	float circumference;
-	float temperatur;
+	float circumferenceIncrement;
+	float temperature;
 };
 
 class Forte_DRS26 : public Forte_Sensor<out_data_drs26> {
   public:
 	void setup() override;
-	out_data_drs26 read_data() override;
-	Message build_message() override;
+	out_data_drs26 readData() override;
+	Message buildMessage() override;
+	Protocol getProtocol() override;
 
   private:
 	SDI12 drs26;
 	out_data_drs26 data;
+	enum class MeasurementType { TEMPERATURE, CIRCUMFERENCE_INCREMENT };
+
+	// enum to string
+	std::map<MeasurementType, const char *> measurementTypeToString = {
+	    {MeasurementType::TEMPERATURE, "TEMPERATURE"},
+	    {MeasurementType::CIRCUMFERENCE_INCREMENT, "CIRCUMFERENCE_INCREMENT"}};
 };
 
 #endif
\ No newline at end of file
diff --git a/client/client/lib/espnow/README b/client/client/lib/espnow/README
index 55f89c0..bbf1db0 100644
--- a/client/client/lib/espnow/README
+++ b/client/client/lib/espnow/README
@@ -1,7 +1,7 @@
 # basic usage
 
 To send data using espnow, create a new Message object,
-then use the add_data(value, identifier) method for every value
+then use the addData(value, identifier) method for every value
 to fill the message.
 when every value is added, use the send() method to send the data
 to the host (fipy). If the esp client has never recieved a config
diff --git a/client/client/lib/espnow/src/ClientDataPackage.hpp b/client/client/lib/espnow/src/ClientDataPackage.hpp
index 52f2be6..727127d 100644
--- a/client/client/lib/espnow/src/ClientDataPackage.hpp
+++ b/client/client/lib/espnow/src/ClientDataPackage.hpp
@@ -1,14 +1,46 @@
 #pragma once
 
-#define NUM_SENSORS 10
-// packing the struct without padding, makes reading it on the fipy easier
-#pragma pack(1)
+#include "ArduinoJson.h"
+#include "Protocol.hpp"
+#include <list>
+#include <string>
+#include <utility>
+
+struct MeasurementData {
+	double value;
+	int channel;
+	std::string measurementType; // TODO: consider using an enum
+};
 
 // having the data be a struct of basic types makes sending easier,
 // otherwise we would have to serialize the data before sending
-struct ClientDataPackage {
-	int identifiers[NUM_SENSORS];
-	float values[NUM_SENSORS];
-	int amountData;
+class ClientDataPackage {
+  private:
+	MeasurementData value;
+	std::string sensorName;
+	std::string protocol;
 	long timestamp; // maybe make this array
+
+  public:
+	ClientDataPackage(MeasurementData value, std::string sensorName, long timestamp, Protocol protocol)
+	    : value(std::move(std::move(value))), sensorName(std::move(sensorName)), timestamp(timestamp),
+	      protocol(protocolToString[protocol])
+	{
+	}
+
+	std::string getDataPackageAsMinifiedJsonString()
+	{
+		StaticJsonDocument<250> document; // 250 byte is the max send size of espnow
+
+		document["sensorName"] = sensorName;
+		document["timestamp"] = timestamp;
+		document["protocol"] = protocol;
+		document["value"] = value.value;
+		document["channel"] = value.channel;
+		document["measurementType"] = value.measurementType;
+
+		std::string jsonString;
+		serializeJson(document, jsonString);
+		return jsonString;
+	}
 };
diff --git a/client/client/lib/espnow/src/Message.cpp b/client/client/lib/espnow/src/Message.cpp
index 447242c..4a23314 100644
--- a/client/client/lib/espnow/src/Message.cpp
+++ b/client/client/lib/espnow/src/Message.cpp
@@ -2,51 +2,89 @@
 
 static const char *TAG = "MESSAGE";
 
-void Message::add_data(float value, int identifier)
+void Message::addData(float value, int identifier)
 {
-	if (data.amountData < NUM_SENSORS) {
-		data.values[data.amountData] = value;
-		data.identifiers[data.amountData] = identifier;
-		data.amountData++;
-	}
+	StaticJsonDocument<100> document;
+	document["value"] = value;
+	document["identifier"] = identifier;
+	data["values"].add(document);
+	ESP_LOGD(TAG, "Added data: %s", getMessageAsMinifiedJsonString().c_str());
+}
+
+void Message::addData(float value, const std::string &measurementType, const std::string &sensorName)
+{
+	StaticJsonDocument<100> document;
+
+	document["sensorName"] = sensorName;
+	document["measurementType"] = measurementType;
+	data["values"].add(document);
+
+	ESP_LOGD(TAG, "Added data: %s", getMessageAsMinifiedJsonString().c_str());
+}
+
+/**
+ * Add data to a message that originates from an analog sensor with multiple channels
+ * @param value Value of the measurement
+ * @param measurementType Type of the measurement
+ * @param sensorName Name of the sensor
+ * @param channel Connected analog channel
+ */
+void Message::addData(float value, const std::string &measurementType, const std::string &sensorName, int channel)
+{
+	StaticJsonDocument<100> document;
+
+	document["sensorName"] = sensorName;
+	document["channel"] = channel;
+	document["measurementType"] = measurementType;
+	document["value"] = value;
+	data["values"].add(document);
+
+	ESP_LOGD(TAG, "Added data: %s", getMessageAsMinifiedJsonString().c_str());
 }
 
 esp_err_t Message::send()
 {
 	ESP_LOGI(TAG, "Sending message");
 	esp_err_t success;
-	success = esp_now_send(recipient, (uint8_t *)&data, sizeof(data));
-	// if(success != ESP_OK){
-	//     if(!ram_cache_is_full()){
-	//         ram_cache_push(*data);
-	//     }
-	// }
-	for (int i = 0; i < data.amountData; i++) {
-		ESP_LOGD(TAG, "Sent data: %i", data.values[i]);
+	auto messageData = getMessageAsMinifiedJsonString();
+	success = esp_now_send(recipient, (uint8_t *)&messageData, sizeof(data));
+	if (success != ESP_OK) {
+		// TODO REWRITE FOR JSON
+//		if (!ram_cache_is_full()) {
+//			//			ram_cache_push(messageData);
+//		}
 	}
+	ESP_LOGD(TAG, "Sent data: %s", messageData.c_str());
 
-	ESP_LOGD(TAG, "time sent: %l", data.timestamp);
+	std::string timestampString = data["timestamp"];
+	ESP_LOGD(TAG, "time sent: %s", timestampString.c_str());
 	ESP_LOGD(TAG, "send status: %d", success);
 
 	return success;
 }
 
+StaticJsonDocument<256> Message::getData()
+{
+	return data;
+}
+
 Message ::Message()
 {
 	// check for existing host mac address, use broadcast otherwise
 	get_host_mac(recipient);
-
-	data.amountData = 0;
-	data.timestamp = esptime::rtc.getMillis(); // I am assuming we are not sending data from Unix Epoch
+	data["values"] = JsonArray();
+	addTimestamp();
 }
 
-Message ::Message(ClientDataPackage old_data)
+std::string Message::getMessageAsMinifiedJsonString()
 {
-	data = old_data;
-	// memcpy(&data, &old_data, sizeof(data));
-	get_host_mac(recipient);
+	std::string minimizedJson;
+	serializeJson(data, minimizedJson);
+	return minimizedJson;
 }
-ClientDataPackage Message::getData()
+void Message::addTimestamp()
 {
-	return data;
+	// TODO: if we are not time synced (i.e. didn't reach the host for current time, use another value like number of
+	// reboots of the ESP)
+	data["timestamp"] = esptime::rtc.getMillis();
 }
diff --git a/client/client/lib/espnow/src/Message.hpp b/client/client/lib/espnow/src/Message.hpp
index 101f754..8a26ea7 100644
--- a/client/client/lib/espnow/src/Message.hpp
+++ b/client/client/lib/espnow/src/Message.hpp
@@ -5,6 +5,7 @@
 #include "Time.hpp"
 #include "esp_log.h"
 #include <Arduino.h>
+#include <ArduinoJson.h>
 #include <ESP32Time.h>
 #include <esp_now.h>
 
@@ -12,13 +13,19 @@
 // if more things are sent from the host the name might not be accurate anymore
 class Message {
   public:
+	void addData(float value, int identifier);
+	void addData(float value, const std::string &measurementType, const std::string &sensorName);
+	void addData(float value, const std::string &measurementType, const std::string &sensorName, int channel);
+
 	Message();
-	explicit Message(ClientDataPackage old_data);
-	void add_data(float value, int identifier);
+
 	esp_err_t send();
-	ClientDataPackage getData();
+	StaticJsonDocument<256> getData();
+	std::string getMessageAsMinifiedJsonString();
 
   private:
-	ClientDataPackage data;
-	uint8_t recipient[6];
+	StaticJsonDocument<256> data;
+	void addTimestamp();
+	//	ClientDataPackage data;
+	uint8_t recipient[6]{};
 };
\ No newline at end of file
diff --git a/client/client/lib/ina219/ina219.cpp b/client/client/lib/ina219/ina219.cpp
index 7c9360c..5d1ff38 100644
--- a/client/client/lib/ina219/ina219.cpp
+++ b/client/client/lib/ina219/ina219.cpp
@@ -12,7 +12,7 @@ void Forte_INA219 ::setup()
 	}
 }
 
-out_data_ina219 Forte_INA219 ::read_data()
+out_data_ina219 Forte_INA219 ::readData()
 {
 	if (!ina219.getOverflow()) {
 		data.shuntVoltage_mV = ina219.getShuntVoltage_mV();
@@ -27,7 +27,11 @@ out_data_ina219 Forte_INA219 ::read_data()
 		return data;
 }
 
-Message Forte_INA219::build_message()
+Message Forte_INA219::buildMessage()
 {
 	throw "Not yet implemented";
-}
\ No newline at end of file
+}
+Protocol Forte_INA219::getProtocol()
+{
+	return I2C;
+}
diff --git a/client/client/lib/ina219/ina219.hpp b/client/client/lib/ina219/ina219.hpp
index 64e8728..cfcb01d 100644
--- a/client/client/lib/ina219/ina219.hpp
+++ b/client/client/lib/ina219/ina219.hpp
@@ -20,8 +20,9 @@ struct out_data_ina219 {
 class Forte_INA219 : public Forte_Sensor<out_data_ina219> {
   public:
 	void setup() override;
-	out_data_ina219 read_data() override;
-	Message build_message() override;
+	out_data_ina219 readData() override;
+	Message buildMessage() override;
+	Protocol getProtocol() override;
 
   private:
 	INA219_WE ina219;
diff --git a/client/client/lib/scd30/scd30.cpp b/client/client/lib/scd30/scd30.cpp
index 0ad4f2c..eb7e743 100644
--- a/client/client/lib/scd30/scd30.cpp
+++ b/client/client/lib/scd30/scd30.cpp
@@ -12,7 +12,7 @@ void Forte_SCD30 ::setup()
 	}
 }
 
-out_data_scd30 Forte_SCD30 ::read_data()
+out_data_scd30 Forte_SCD30 ::readData()
 {
 	if (airSensor.dataAvailable()) {
 		data.C02 = airSensor.getCO2();
@@ -25,7 +25,11 @@ out_data_scd30 Forte_SCD30 ::read_data()
 	// return out_data_scd30{-1, -1, -1};
 }
 
-Message Forte_SCD30::build_message()
+Message Forte_SCD30::buildMessage()
 {
 	throw "Not yet implemented";
-}
\ No newline at end of file
+}
+Protocol Forte_SCD30::getProtocol()
+{
+	return I2C;
+}
diff --git a/client/client/lib/scd30/scd30.hpp b/client/client/lib/scd30/scd30.hpp
index dcd05a4..a1fa290 100644
--- a/client/client/lib/scd30/scd30.hpp
+++ b/client/client/lib/scd30/scd30.hpp
@@ -18,8 +18,9 @@ struct out_data_scd30 {
 class Forte_SCD30 : public Forte_Sensor<out_data_scd30> {
   public:
 	void setup() override;
-	out_data_scd30 read_data() override;
-	Message build_message() override;
+	out_data_scd30 readData() override;
+	Message buildMessage() override;
+	Protocol getProtocol() override;
 
   private:
 	SCD30 airSensor;
diff --git a/client/client/platformio.ini b/client/client/platformio.ini
index 8b0ba57..a28a589 100644
--- a/client/client/platformio.ini
+++ b/client/client/platformio.ini
@@ -13,16 +13,17 @@ platform = espressif32
 board = esp32-c3-devkitm-1
 framework = arduino
 monitor_speed = 115200
-build_flags =
-    -I include
-    -DCORE_DEBUG_LEVEL=5
-lib_deps =
-    sparkfun/SparkFun SCD30 Arduino Library@^1.0.18
-    Wire
-    adafruit/Adafruit ADS1X15@^2.4.0
-    wollewald/INA219_WE@^1.3.1
-    adafruit/Adafruit BusIO@^1.13.2
-    Adafruit_I2CDevice
-    SPI
-    envirodiy/SDI-12@^2.1.4
-    fbiego/ESP32Time@^2.0.0
+build_flags = 
+	-I include
+	-DCORE_DEBUG_LEVEL=5
+lib_deps = 
+	sparkfun/SparkFun SCD30 Arduino Library@^1.0.18
+	Wire
+	adafruit/Adafruit ADS1X15@^2.4.0
+	wollewald/INA219_WE@^1.3.1
+	adafruit/Adafruit BusIO@^1.13.2
+	Adafruit_I2CDevice
+	SPI
+	envirodiy/SDI-12@^2.1.4
+	fbiego/ESP32Time@^2.0.0
+	bblanchon/ArduinoJson@^6.19.4
diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp
index 266c4c7..fe98c19 100644
--- a/client/client/src/main.cpp
+++ b/client/client/src/main.cpp
@@ -24,8 +24,8 @@ void loop()
 
 	try {
 		espnow_setup();
-		//			data = drs26.read_data();
-		auto message = drs26.build_message();
+		//			data = drs26.readData();
+		auto message = drs26.buildMessage();
 		message.send();
 	} catch (const NoDataAvailableException &e) {
 		std::cerr << e.what() << '\n';
diff --git a/client/client/test/TestClientDataPackage.cpp b/client/client/test/TestClientDataPackage.cpp
new file mode 100644
index 0000000..bae42a2
--- /dev/null
+++ b/client/client/test/TestClientDataPackage.cpp
@@ -0,0 +1,19 @@
+//
+// Created by zoe on 10/6/22.
+//
+
+#include "TestClientDataPackage.hpp"
+#include "Protocol.hpp"
+#include <vector>
+
+void test_export_to_json()
+{
+	ClientDataPackage dataPackage = ClientDataPackage(MeasurementData{1.1, 0, "TEMPERATURE"}, "DRS26", 0, Analog);
+
+	std::string json = dataPackage.getDataPackageAsMinifiedJsonString();
+	// expected
+	std::string expected =
+	    R"({"sensorName":"DRS26","timestamp":0,"protocol":"Analog","value":1.1,"channel":0,"measurementType":"TEMPERATURE"})";
+
+	TEST_ASSERT_EQUAL_STRING(expected.c_str(), json.c_str());
+}
\ No newline at end of file
diff --git a/client/client/test/TestClientDataPackage.hpp b/client/client/test/TestClientDataPackage.hpp
new file mode 100644
index 0000000..74a7b90
--- /dev/null
+++ b/client/client/test/TestClientDataPackage.hpp
@@ -0,0 +1,14 @@
+//
+// Created by zoe on 10/6/22.
+//
+
+#ifndef CLIENT_TESTCLIENTDATAPACKAGE_HPP
+#define CLIENT_TESTCLIENTDATAPACKAGE_HPP
+
+#include <unity.h>
+#include <Arduino.h>
+#include <ClientDataPackage.hpp>
+
+void test_export_to_json();
+
+#endif // CLIENT_TESTCLIENTDATAPACKAGE_HPP
diff --git a/client/client/test/TestMessage.cpp b/client/client/test/TestMessage.cpp
deleted file mode 100644
index 56b7ccc..0000000
--- a/client/client/test/TestMessage.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "TestMessage.hpp"
-
-void test_on_data_recv()
-{
-	Message message = Message{};
-
-	TEST_ASSERT_EQUAL(0, message.getData().amountData);
-}
-
-void test_new_message_filled()
-{
-	Message message = Message{};
-
-	message.add_data(1.1, 0);
-	message.add_data(1.2, 1);
-	message.add_data(1.3, 2);
-
-	float expectedValuesArray[] = {1.1, 1.2, 1.3};
-	int expectedIdentifiersArray[] = {0, 1, 2};
-
-	TEST_ASSERT_EQUAL(3, message.getData().amountData);
-	TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedValuesArray, message.getData().values, 3);
-	TEST_ASSERT_EQUAL_INT_ARRAY(expectedIdentifiersArray, message.getData().identifiers, 3);
-}
\ No newline at end of file
diff --git a/client/client/test/TestMessage.hpp b/client/client/test/TestMessage.hpp
deleted file mode 100644
index 80d5be0..0000000
--- a/client/client/test/TestMessage.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-#include <Arduino.h>
-#include <ESPNow.hpp>
-#include <unity.h>
-
-void test_on_data_recv();
-
-void test_new_message_filled();
\ No newline at end of file
diff --git a/client/client/test/main.cpp b/client/client/test/main.cpp
index 82d6881..b4aedce 100644
--- a/client/client/test/main.cpp
+++ b/client/client/test/main.cpp
@@ -1,7 +1,7 @@
 #include "TestESPNow.hpp"
-#include "TestMessage.hpp"
 #include <Arduino.h>
 #include <unity.h>
+#include "TestClientDataPackage.hpp"
 
 void setup()
 {
@@ -9,8 +9,7 @@ void setup()
 
 	UNITY_BEGIN();
 	RUN_TEST(test_on_data_recv_valid_config);
-	RUN_TEST(test_on_data_recv);
-	RUN_TEST(test_new_message_filled);
+	RUN_TEST(test_export_to_json);
 	UNITY_END();
 }
 
-- 
GitLab