V 1.2.0 - Aussen-Temp/Humi dazu
This commit is contained in:
@@ -12,18 +12,21 @@ static lv_obj_t * chart;
|
||||
static lv_coord_t bmewert[MAXREADINGS];
|
||||
static lv_coord_t bmewert_hum[MAXREADINGS];
|
||||
|
||||
void setup_grafik(void) {
|
||||
void setup_grafik(void)
|
||||
{
|
||||
lv_init();
|
||||
lv_display_t *disp;
|
||||
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
|
||||
|
||||
for (int i = 0; i < MAXREADINGS; i++) {
|
||||
for (int i = 0; i < MAXREADINGS; i++)
|
||||
{
|
||||
bmewert[i] = 0;
|
||||
bmewert_hum[i] = 30;
|
||||
}
|
||||
}
|
||||
|
||||
void buildarc(ARC arc) {
|
||||
void buildarc(ARC arc)
|
||||
{
|
||||
lv_obj_set_size(arc.arc, arc.size, arc.size);
|
||||
lv_arc_set_rotation(arc.arc, 180);
|
||||
lv_arc_set_bg_angles(arc.arc, 0, 180);
|
||||
@@ -80,7 +83,23 @@ void buildarc(ARC arc) {
|
||||
*/
|
||||
}
|
||||
|
||||
void lv_create_main_gui(void) {
|
||||
void showAussenData(float val, bool what)
|
||||
{
|
||||
ta_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(ta_label," ");
|
||||
|
||||
fa_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(fa_label," ");
|
||||
|
||||
static lv_style_t style_ta_label;
|
||||
lv_style_init(&style_ta_label);
|
||||
lv_style_set_text_font(&style_ta_label, &lv_font_montserrat_16);
|
||||
lv_obj_add_style(ta_label, &style_ta_label, 0);
|
||||
lv_obj_add_style(fa_label, &style_ta_label, 0);
|
||||
}
|
||||
|
||||
void lv_create_main_gui(void)
|
||||
{
|
||||
|
||||
// Create a text label aligned on top: https://docs.lvgl.io/master/widgets/label.html
|
||||
time_label = lv_label_create(lv_screen_active());
|
||||
@@ -141,10 +160,12 @@ void lv_create_main_gui(void) {
|
||||
|
||||
lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN);
|
||||
|
||||
|
||||
showAussenData(0, true);
|
||||
showAussenData(0, false);
|
||||
}
|
||||
|
||||
void setValuetoArc(ARC arc, float value) {
|
||||
void setValuetoArc(ARC arc, float value)
|
||||
{
|
||||
int r = arc.highvalue - arc.lowvalue;
|
||||
int v = (value - arc.lowvalue) * 100 / r;
|
||||
arc.value = v;
|
||||
@@ -154,7 +175,8 @@ void setValuetoArc(ARC arc, float value) {
|
||||
sprintf(valuestr, arc.valformat, value);
|
||||
lv_label_set_text(value_label, valuestr);
|
||||
|
||||
if( strcmp(arc.name, "humi") == 0) {
|
||||
if (strcmp(arc.name, "humi") == 0)
|
||||
{
|
||||
if (value < arc.green)
|
||||
{
|
||||
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_GREEN), LV_PART_INDICATOR);
|
||||
@@ -176,7 +198,8 @@ void setValuetoArc(ARC arc, float value) {
|
||||
#define CHART_WIDTH (CONTAINER_WIDTH - LEFTAXIS_WIDTH - RIGHTAXIS_WIDTH - 40)
|
||||
#define CHART_HEIGHT (CONTAINER_HEIGHT)
|
||||
|
||||
void drawChart() {
|
||||
void drawChart()
|
||||
{
|
||||
Serial.println("draw_chart ");
|
||||
|
||||
// Create a container to display the chart and scale
|
||||
@@ -194,7 +217,6 @@ void setValuetoArc(ARC arc, float value) {
|
||||
lv_obj_set_style_border_side(container_row, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(container_row, lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN);
|
||||
|
||||
|
||||
// linke Axe
|
||||
lv_obj_t *scaleT = lv_scale_create(container_row);
|
||||
lv_obj_set_size(scaleT, 30, 75);
|
||||
@@ -221,7 +243,6 @@ void setValuetoArc(ARC arc, float value) {
|
||||
// lv_style_set_bg_color(&style_scaleT, lv_color_hex(0xFF00FF));
|
||||
lv_obj_add_style(scaleT, &style_scaleT, 0);
|
||||
|
||||
|
||||
// Create a chart
|
||||
|
||||
chart = lv_chart_create(container_row);
|
||||
@@ -294,12 +315,13 @@ void setValuetoArc(ARC arc, float value) {
|
||||
lv_style_set_text_font(&style_version_label, &lv_font_montserrat_8);
|
||||
lv_style_set_text_color(&style_version_label, lv_palette_main(LV_PALETTE_GREY));
|
||||
lv_obj_add_style(version_label, &style_version_label, LV_PART_MAIN);
|
||||
|
||||
}
|
||||
|
||||
void updatechartData(float value, float humvalue) {
|
||||
void updatechartData(float value, float humvalue)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < MAXREADINGS - 1; i++) {
|
||||
for (i = 0; i < MAXREADINGS - 1; i++)
|
||||
{
|
||||
bmewert[i] = bmewert[i + 1];
|
||||
bmewert_hum[i] = bmewert_hum[i + 1];
|
||||
}
|
||||
@@ -309,5 +331,18 @@ void updatechartData(float value, float humvalue) {
|
||||
lv_chart_refresh(chart);
|
||||
}
|
||||
|
||||
void setAussenDataValues(float val, bool what)
|
||||
{
|
||||
if (what)
|
||||
{
|
||||
lv_label_set_text_fmt(ta_label,"Ta:\n%.1f °C", val);
|
||||
lv_obj_align(ta_label, LV_ALIGN_TOP_LEFT, 10, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
lv_label_set_text_fmt(fa_label,"Fa:\n%.0f %%", val);
|
||||
lv_obj_align(fa_label, LV_ALIGN_TOP_RIGHT, -10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,11 +41,15 @@ ARC arcTemp = {NULL, "temp", 40, -1, 110, 30.0, "%.1f°C", "°C", 10, 30, 20, 25
|
||||
ARC arcHum = {NULL, "humi", 170, -1, 110, 60.0, "%.0f%%", "%", 40, 100, 65, 70, 2};
|
||||
lv_obj_t * date_label;
|
||||
lv_obj_t * time_label;
|
||||
lv_obj_t * ta_label;
|
||||
lv_obj_t * fa_label;
|
||||
#else
|
||||
extern ARC arcTemp;
|
||||
extern ARC arcHum;
|
||||
extern lv_obj_t * date_label;
|
||||
extern lv_obj_t * time_label;
|
||||
extern lv_obj_t * ta_label;
|
||||
extern lv_obj_t * fa_label;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -54,6 +58,9 @@ void lv_create_main_gui(void);
|
||||
void setValuetoArc(ARC arc, float value);
|
||||
void drawChart();
|
||||
void updatechartData(float value, float value_hum);
|
||||
void setAussenDataValues(float val, bool what);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
16
src/main.cpp
16
src/main.cpp
@@ -68,6 +68,7 @@ void setup() {
|
||||
connectToWifi();
|
||||
|
||||
// Start MQTT
|
||||
setupMQTT();
|
||||
connectToMqtt();
|
||||
Serial.println("MQTT started");
|
||||
|
||||
@@ -86,21 +87,10 @@ void setup() {
|
||||
// Function to draw the GUI
|
||||
lv_create_main_gui();
|
||||
Serial.println("Main GUI created");
|
||||
|
||||
*/
|
||||
delay(1000);
|
||||
|
||||
mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
|
||||
wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
mqttClient.onConnect(onMqttConnect);
|
||||
mqttClient.onDisconnect(onMqttDisconnect);
|
||||
mqttClient.onSubscribe(onMqttSubscribe);
|
||||
mqttClient.onUnsubscribe(onMqttUnsubscribe);
|
||||
mqttClient.onMessage(onMqttMessage);
|
||||
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
|
||||
mqttClient.setCredentials(BROKER_USER, BROKER_PASS);
|
||||
connectToWifi();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
@@ -6,8 +6,8 @@ extern "C" {
|
||||
#include "freertos/timers.h"
|
||||
}
|
||||
|
||||
#define VERSION "1.1.0"
|
||||
#define VDATE "2024-07-11"
|
||||
#define VERSION "1.2.0"
|
||||
#define VDATE "2024-07-21"
|
||||
|
||||
//#define MAXREADINGS 224
|
||||
#define MAXREADINGS 200
|
||||
|
||||
43
src/mqtt.cpp
43
src/mqtt.cpp
@@ -1,7 +1,22 @@
|
||||
#define MQTT
|
||||
|
||||
#include "grafik.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
void setupMQTT() {
|
||||
mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
|
||||
// wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
|
||||
// WiFi.onEvent(WiFiEvent);
|
||||
mqttClient.onConnect(onMqttConnect);
|
||||
mqttClient.onDisconnect(onMqttDisconnect);
|
||||
mqttClient.onSubscribe(onMqttSubscribe);
|
||||
mqttClient.onUnsubscribe(onMqttUnsubscribe);
|
||||
mqttClient.onMessage(onMqttMessage);
|
||||
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
|
||||
mqttClient.setCredentials(BROKER_USER, BROKER_PASS);
|
||||
// connectToWifi();
|
||||
}
|
||||
|
||||
void connectToMqtt() {
|
||||
Serial.println("Connecting to MQTT...");
|
||||
mqttClient.connect();
|
||||
@@ -13,7 +28,11 @@ void onMqttConnect(bool sessionPresent) {
|
||||
Serial.println(sessionPresent);*/
|
||||
|
||||
// Subscribe to topic "message" when it connects to the broker
|
||||
uint16_t packetIdSub = mqttClient.subscribe(MQTT_TOPIC_MESSAGE, 2);
|
||||
char topic[50];
|
||||
strcpy(topic, MQTT_TOPIC);
|
||||
strcat(topic,"/+");
|
||||
Serial.println(topic);
|
||||
uint16_t packetIdSub = mqttClient.subscribe(topic, 2);
|
||||
//Serial.print("Subscribing at QoS 2, packetId: ");
|
||||
//Serial.println(packetIdSub);
|
||||
}
|
||||
@@ -45,17 +64,25 @@ JsonDocument doc;
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
// Do whatever you want when you receive a message
|
||||
// Save the message in a variable
|
||||
Serial.println(topic);
|
||||
String received_message;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Serial.println((char)payload[i]);
|
||||
received_message += (char)payload[i];
|
||||
}
|
||||
// Display the text message on the display receive from the MQTT topic "message"
|
||||
if (strcmp(topic, MQTT_TOPIC_MESSAGE) == 0) {
|
||||
// deserializeJson(doc, received_message);
|
||||
// String temp = doc["temperature"];
|
||||
// String hum = doc["humidity"];
|
||||
// received_message = "Temperature: " + temp + "°C\nHumidity: " + hum + "%";
|
||||
// lv_label_set_text(mqtt_text_label, received_message.c_str());
|
||||
float wert;
|
||||
bool what;
|
||||
if (strcmp(topic, MQTT_TOPIC_T) == 0) {
|
||||
deserializeJson(doc, received_message);
|
||||
Serial.print("AT: ");
|
||||
wert = doc["val"];
|
||||
what = true;
|
||||
} else if (strcmp(topic, MQTT_TOPIC_H) == 0) {
|
||||
deserializeJson(doc, received_message);
|
||||
Serial.print("AF: ");
|
||||
wert = doc["val"];
|
||||
what = false;
|
||||
}
|
||||
Serial.println(wert);
|
||||
setAussenDataValues(wert, what);
|
||||
}
|
||||
@@ -12,7 +12,9 @@
|
||||
#define BROKER_USER "rxf"
|
||||
#define BROKER_PASS "Tux4S!ech"
|
||||
|
||||
#define MQTT_TOPIC_MESSAGE "zigbee2mqtt/Temp_Feuchte_Mini"
|
||||
#define MQTT_TOPIC "hm/status/Aussen_Temp:1"
|
||||
#define MQTT_TOPIC_T "hm/status/Aussen_Temp:1/TEMPERATURE"
|
||||
#define MQTT_TOPIC_H "hm/status/Aussen_Temp:1/HUMIDITY"
|
||||
|
||||
#ifdef MQTT
|
||||
AsyncMqttClient mqttClient;
|
||||
@@ -20,6 +22,7 @@ AsyncMqttClient mqttClient;
|
||||
extern AsyncMqttClient mqttClient;
|
||||
#endif
|
||||
|
||||
void setupMQTT();
|
||||
void connectToMqtt();
|
||||
void onMqttConnect(bool sessionPresent);
|
||||
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
|
||||
|
||||
Reference in New Issue
Block a user