V 1.2.0 - Aussen-Temp/Humi dazu

This commit is contained in:
rxf
2024-07-21 14:25:28 +02:00
parent e40034213e
commit ad9d426a23
6 changed files with 263 additions and 201 deletions

View File

@@ -8,38 +8,41 @@
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8)) #define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4]; uint32_t draw_buf[DRAW_BUF_SIZE / 4];
static lv_obj_t * chart; static lv_obj_t *chart;
static lv_coord_t bmewert[MAXREADINGS]; static lv_coord_t bmewert[MAXREADINGS];
static lv_coord_t bmewert_hum[MAXREADINGS]; static lv_coord_t bmewert_hum[MAXREADINGS];
void setup_grafik(void) { void setup_grafik(void)
lv_init(); {
lv_display_t * disp; lv_init();
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf)); 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; 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_obj_set_size(arc.arc, arc.size, arc.size);
lv_arc_set_bg_angles(arc.arc, 0, 180); lv_arc_set_rotation(arc.arc, 180);
lv_arc_set_value(arc.arc, arc.value); lv_arc_set_bg_angles(arc.arc, 0, 180);
lv_obj_align(arc.arc, LV_ALIGN_LEFT_MID, arc.x, arc.y); lv_arc_set_value(arc.arc, arc.value);
lv_obj_remove_style(arc.arc, NULL, LV_PART_KNOB); lv_obj_align(arc.arc, LV_ALIGN_LEFT_MID, arc.x, arc.y);
lv_obj_remove_style(arc.arc, NULL, LV_PART_KNOB);
// Style this arc // Style this arc
static lv_style_t style_arc; static lv_style_t style_arc;
lv_style_init(&style_arc); lv_style_init(&style_arc);
lv_style_set_arc_width(&style_arc, 20); lv_style_set_arc_width(&style_arc, 20);
lv_style_set_arc_rounded(&style_arc, false); lv_style_set_arc_rounded(&style_arc, false);
lv_obj_add_style(arc.arc, &style_arc, LV_PART_MAIN); lv_obj_add_style(arc.arc, &style_arc, LV_PART_MAIN);
lv_obj_add_style(arc.arc, &style_arc, LV_PART_INDICATOR); lv_obj_add_style(arc.arc, &style_arc, LV_PART_INDICATOR);
lv_obj_t * low_label = lv_label_create(arc.arc); lv_obj_t *low_label = lv_label_create(arc.arc);
char valuelow[10]; char valuelow[10];
sprintf(valuelow, "%d", arc.lowvalue); sprintf(valuelow, "%d", arc.lowvalue);
lv_label_set_text(low_label, valuelow); lv_label_set_text(low_label, valuelow);
@@ -49,7 +52,7 @@ void buildarc(ARC arc) {
lv_style_set_text_font(&style_low_label, &lv_font_montserrat_10); lv_style_set_text_font(&style_low_label, &lv_font_montserrat_10);
lv_obj_add_style(low_label, &style_low_label, 0); lv_obj_add_style(low_label, &style_low_label, 0);
lv_obj_t * value_label = lv_label_create(arc.arc); lv_obj_t *value_label = lv_label_create(arc.arc);
char value[10]; char value[10];
sprintf(value, arc.valformat, arc.value); sprintf(value, arc.valformat, arc.value);
// Serial.println(value); // Serial.println(value);
@@ -60,7 +63,7 @@ void buildarc(ARC arc) {
lv_style_set_text_font(&style_value_label, &lv_font_montserrat_18); lv_style_set_text_font(&style_value_label, &lv_font_montserrat_18);
lv_obj_add_style(value_label, &style_value_label, 0); lv_obj_add_style(value_label, &style_value_label, 0);
lv_obj_t * high_label = lv_label_create(arc.arc); lv_obj_t *high_label = lv_label_create(arc.arc);
char valuehigh[10]; char valuehigh[10];
sprintf(valuehigh, "%d", arc.highvalue); sprintf(valuehigh, "%d", arc.highvalue);
lv_label_set_text(high_label, valuehigh); lv_label_set_text(high_label, valuehigh);
@@ -70,17 +73,33 @@ void buildarc(ARC arc) {
lv_style_set_text_font(&style_high_label, &lv_font_montserrat_10); lv_style_set_text_font(&style_high_label, &lv_font_montserrat_10);
lv_obj_add_style(high_label, &style_high_label, 0); lv_obj_add_style(high_label, &style_high_label, 0);
/* lv_obj_t * unit_label = lv_label_create(arc.arc); /* lv_obj_t * unit_label = lv_label_create(arc.arc);
lv_label_set_text(unit_label, arc.unit); lv_label_set_text(unit_label, arc.unit);
lv_obj_align(unit_label, LV_ALIGN_LEFT_MID, 48, 8); lv_obj_align(unit_label, LV_ALIGN_LEFT_MID, 48, 8);
static lv_style_t style_unit_label; static lv_style_t style_unit_label;
lv_style_init(&style_unit_label); lv_style_init(&style_unit_label);
lv_style_set_text_font(&style_unit_label, &lv_font_montserrat_12); lv_style_set_text_font(&style_unit_label, &lv_font_montserrat_12);
lv_obj_add_style(unit_label, &style_unit_label, 0); lv_obj_add_style(unit_label, &style_unit_label, 0);
*/ */
} }
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 // Create a text label aligned on top: https://docs.lvgl.io/master/widgets/label.html
time_label = lv_label_create(lv_screen_active()); time_label = lv_label_create(lv_screen_active());
@@ -111,7 +130,7 @@ void lv_create_main_gui(void) {
*/ */
// Text als Überschrift an die Axen // Text als Überschrift an die Axen
lv_obj_t * feuchte_label = lv_label_create(lv_screen_active()); lv_obj_t *feuchte_label = lv_label_create(lv_screen_active());
lv_label_set_text(feuchte_label, "Feuchte"); lv_label_set_text(feuchte_label, "Feuchte");
lv_obj_align(feuchte_label, LV_ALIGN_RIGHT_MID, -3, 20); lv_obj_align(feuchte_label, LV_ALIGN_RIGHT_MID, -3, 20);
@@ -121,7 +140,7 @@ void lv_create_main_gui(void) {
lv_style_set_text_font(&style_feuchte_label, &lv_font_montserrat_10); lv_style_set_text_font(&style_feuchte_label, &lv_font_montserrat_10);
lv_obj_add_style(feuchte_label, &style_feuchte_label, 0); lv_obj_add_style(feuchte_label, &style_feuchte_label, 0);
lv_obj_t * temp_label = lv_label_create(lv_screen_active()); lv_obj_t *temp_label = lv_label_create(lv_screen_active());
lv_label_set_text(temp_label, "Temperatur"); lv_label_set_text(temp_label, "Temperatur");
lv_obj_align(temp_label, LV_ALIGN_LEFT_MID, 3, 20); lv_obj_align(temp_label, LV_ALIGN_LEFT_MID, 3, 20);
@@ -131,158 +150,160 @@ void lv_create_main_gui(void) {
lv_style_set_text_font(&style_temp_label, &lv_font_montserrat_10); lv_style_set_text_font(&style_temp_label, &lv_font_montserrat_10);
lv_obj_add_style(temp_label, &style_temp_label, 0); lv_obj_add_style(temp_label, &style_temp_label, 0);
/*Create an Arc*/ /*Create an Arc*/
lv_obj_t * aTemp = lv_arc_create(lv_screen_active()); lv_obj_t *aTemp = lv_arc_create(lv_screen_active());
arcTemp.arc = aTemp; arcTemp.arc = aTemp;
buildarc(arcTemp); buildarc(arcTemp);
lv_obj_t * aHum = lv_arc_create(lv_screen_active()); lv_obj_t *aHum = lv_arc_create(lv_screen_active());
arcHum.arc = aHum; arcHum.arc = aHum;
buildarc(arcHum); buildarc(arcHum);
lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN); 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; int r = arc.highvalue - arc.lowvalue;
arc.value = v; int v = (value - arc.lowvalue) * 100 / r;
lv_arc_set_value(arc.arc, arc.value); arc.value = v;
lv_obj_t * value_label = lv_obj_get_child(arc.arc, 1); lv_arc_set_value(arc.arc, arc.value);
char valuestr[10]; lv_obj_t *value_label = lv_obj_get_child(arc.arc, 1);
sprintf(valuestr, arc.valformat, value); char valuestr[10];
lv_label_set_text(value_label, valuestr); 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) {
{ if (value < arc.green)
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_GREEN), LV_PART_INDICATOR); {
} lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_GREEN), LV_PART_INDICATOR);
else if (value < arc.yellow) }
{ else if (value < arc.yellow)
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_YELLOW), LV_PART_INDICATOR); {
} lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_YELLOW), LV_PART_INDICATOR);
else }
{ else
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_RED), LV_PART_INDICATOR); {
} lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_RED), LV_PART_INDICATOR);
} }
}
} }
#define CONTAINER_WIDTH SCREEN_WIDTH #define CONTAINER_WIDTH SCREEN_WIDTH
#define CONTAINER_HEIGHT SCREEN_HEIGHT-145 #define CONTAINER_HEIGHT SCREEN_HEIGHT - 145
#define LEFTAXIS_WIDTH 25 #define LEFTAXIS_WIDTH 25
#define RIGHTAXIS_WIDTH 15 #define RIGHTAXIS_WIDTH 15
#define CHART_WIDTH (CONTAINER_WIDTH - LEFTAXIS_WIDTH - RIGHTAXIS_WIDTH - 40) #define CHART_WIDTH (CONTAINER_WIDTH - LEFTAXIS_WIDTH - RIGHTAXIS_WIDTH - 40)
#define CHART_HEIGHT (CONTAINER_HEIGHT) #define CHART_HEIGHT (CONTAINER_HEIGHT)
void drawChart() { void drawChart()
Serial.println("draw_chart "); {
Serial.println("draw_chart ");
// Create a container to display the chart and scale // Create a container to display the chart and scale
lv_obj_t * container_row = lv_obj_create(lv_screen_active()); lv_obj_t *container_row = lv_obj_create(lv_screen_active());
lv_obj_set_size(container_row, CONTAINER_WIDTH, CONTAINER_HEIGHT); lv_obj_set_size(container_row, CONTAINER_WIDTH, CONTAINER_HEIGHT);
lv_obj_align(container_row, LV_ALIGN_BOTTOM_MID, 0, 0); lv_obj_align(container_row, LV_ALIGN_BOTTOM_MID, 0, 0);
// Set the container in a flexbox row layout aligned center // Set the container in a flexbox row layout aligned center
lv_obj_set_flex_flow(container_row, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(container_row, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(container_row, LV_FLEX_ALIGN_CENTER,LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_set_flex_align(container_row, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_scrollbar_mode(container_row, LV_SCROLLBAR_MODE_OFF); lv_obj_set_scrollbar_mode(container_row, LV_SCROLLBAR_MODE_OFF);
static lv_style_t style_container_row; static lv_style_t style_container_row;
lv_style_set_pad_row(&style_container_row, 0); lv_style_set_pad_row(&style_container_row, 0);
//lv_style_set_bg_color(&style_container_row, lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 4)); // lv_style_set_bg_color(&style_container_row, lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 4));
lv_obj_add_style(container_row, &style_container_row, 0); lv_obj_add_style(container_row, &style_container_row, 0);
lv_obj_set_style_border_side(container_row, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN); 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); 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);
lv_scale_set_mode(scaleT, LV_SCALE_MODE_VERTICAL_LEFT);
// linke Axe static const char *scaleT_labels[5] = {"10°C", "15°C", "20°C", "25°C", "30°C"};
lv_obj_t * scaleT = lv_scale_create(container_row); lv_scale_set_text_src(scaleT, scaleT_labels);
lv_obj_set_size(scaleT, 30, 75); lv_scale_set_label_show(scaleT, true);
lv_scale_set_mode(scaleT, LV_SCALE_MODE_VERTICAL_LEFT);
static const char * scaleT_labels[5] = {"10°C", "15°C", "20°C", "25°C", "30°C"}; lv_scale_set_total_tick_count(scaleT, 21);
lv_scale_set_text_src(scaleT, scaleT_labels); lv_scale_set_major_tick_every(scaleT, 5);
lv_scale_set_label_show(scaleT, true);
lv_scale_set_total_tick_count(scaleT, 21); lv_obj_set_style_length(scaleT, 0, LV_PART_ITEMS);
lv_scale_set_major_tick_every(scaleT, 5); lv_obj_set_style_length(scaleT, 0, LV_PART_INDICATOR);
lv_obj_set_style_line_width(scaleT, 0, LV_PART_ITEMS);
lv_obj_set_style_line_width(scaleT, 0, LV_PART_INDICATOR);
lv_obj_set_style_line_width(scaleT, 0, LV_PART_MAIN);
lv_scale_set_range(scaleT, 10, 30);
lv_obj_set_style_length(scaleT, 0, LV_PART_ITEMS); static lv_style_t style_scaleT;
lv_obj_set_style_length(scaleT, 0, LV_PART_INDICATOR); lv_style_init(&style_scaleT);
lv_obj_set_style_line_width(scaleT, 0, LV_PART_ITEMS); lv_style_set_text_font(&style_scaleT, &lv_font_montserrat_10);
lv_obj_set_style_line_width(scaleT, 0, LV_PART_INDICATOR); lv_style_set_text_color(&style_scaleT, lv_color_hex(0x0000FF));
lv_obj_set_style_line_width(scaleT, 0, LV_PART_MAIN); // lv_style_set_bg_color(&style_scaleT, lv_color_hex(0xFF00FF));
lv_scale_set_range(scaleT, 10, 30); lv_obj_add_style(scaleT, &style_scaleT, 0);
static lv_style_t style_scaleT; // Create a chart
lv_style_init(&style_scaleT);
lv_style_set_text_font(&style_scaleT, &lv_font_montserrat_10);
lv_style_set_text_color(&style_scaleT, lv_color_hex(0x0000FF));
// lv_style_set_bg_color(&style_scaleT, lv_color_hex(0xFF00FF));
lv_obj_add_style(scaleT, &style_scaleT, 0);
chart = lv_chart_create(container_row);
lv_obj_set_size(chart, CHART_WIDTH, CHART_HEIGHT);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
lv_chart_set_point_count(chart, MAXREADINGS);
lv_chart_set_div_line_count(chart, 5, 5);
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 40, 100);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 30);
lv_obj_set_style_size(chart, 0, 0, LV_PART_INDICATOR); // No points on line
lv_obj_set_scrollbar_mode(chart, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_style_border_width(chart, 0, LV_PART_MAIN); // No border
lv_obj_set_style_bg_color(chart, lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN);
// Create a chart // lv_obj_set_style_pad_right(chart, -10, LV_PART_MAIN); // No border
/*Add data series*/
lv_chart_series_t *ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_set_ext_y_array(chart, ser1, (lv_coord_t *)bmewert);
chart = lv_chart_create(container_row); lv_chart_series_t *ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_SECONDARY_Y);
lv_obj_set_size(chart, CHART_WIDTH, CHART_HEIGHT); lv_chart_set_ext_y_array(chart, ser2, (lv_coord_t *)bmewert_hum);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
lv_chart_set_point_count(chart, MAXREADINGS);
lv_chart_set_div_line_count(chart, 5, 5);
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 40, 100);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 30);
lv_obj_set_style_size(chart, 0, 0, LV_PART_INDICATOR); // No points on line
lv_obj_set_scrollbar_mode(chart, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_style_border_width(chart, 0, LV_PART_MAIN); // No border
lv_obj_set_style_bg_color(chart, lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN);
// lv_obj_set_style_pad_right(chart, -10, LV_PART_MAIN); // No border lv_chart_refresh(chart); /*Required after direct set*/
/*Add data series*/
lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_set_ext_y_array(chart, ser1, (lv_coord_t *)bmewert);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_SECONDARY_Y); // rechte Axe
lv_chart_set_ext_y_array(chart, ser2, (lv_coord_t *)bmewert_hum); lv_obj_t *scale = lv_scale_create(container_row);
lv_obj_set_size(scale, 30, 75);
lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_RIGHT);
lv_chart_refresh(chart); /*Required after direct set*/ static const char *scale_labels[5] = {"40%", "55%", "70%", "85%", "100%"};
lv_scale_set_text_src(scale, scale_labels);
lv_scale_set_label_show(scale, true);
// rechte Axe lv_scale_set_total_tick_count(scale, 21);
lv_obj_t * scale = lv_scale_create(container_row); lv_scale_set_major_tick_every(scale, 5);
lv_obj_set_size(scale, 30, 75);
lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_RIGHT);
static const char * scale_labels[5] = {"40%", "55%", "70%", "85%", "100%"}; lv_obj_set_style_length(scale, 0, LV_PART_ITEMS);
lv_scale_set_text_src(scale, scale_labels); lv_obj_set_style_length(scale, 0, LV_PART_INDICATOR);
lv_scale_set_label_show(scale, true); lv_obj_set_style_line_width(scale, 0, LV_PART_ITEMS);
lv_obj_set_style_line_width(scale, 1, LV_PART_INDICATOR);
lv_obj_set_style_line_width(scale, 0, LV_PART_MAIN);
lv_obj_set_style_bg_color(scale, lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN);
lv_scale_set_range(scale, 40, 100);
lv_scale_set_total_tick_count(scale, 21); static lv_style_t style_scale;
lv_scale_set_major_tick_every(scale, 5); lv_style_init(&style_scale);
lv_style_set_text_font(&style_scale, &lv_font_montserrat_10);
lv_style_set_text_color(&style_scale, lv_color_hex(0xFF0000));
lv_obj_add_style(scale, &style_scale, 0);
lv_obj_set_style_length(scale, 0, LV_PART_ITEMS); /* // Label an der Axe
lv_obj_set_style_length(scale, 0, LV_PART_INDICATOR); lv_obj_t * unitxAx_label = lv_label_create(container_row);
lv_obj_set_style_line_width(scale, 0, LV_PART_ITEMS); lv_label_set_text(unitxAx_label, "°C");
lv_obj_set_style_line_width(scale, 1, LV_PART_INDICATOR); lv_obj_align(unitxAx_label, LV_ALIGN_TOP_RIGHT, -20, 8);
lv_obj_set_style_line_width(scale, 0, LV_PART_MAIN); static lv_style_t style_unitxAx_label;
lv_obj_set_style_bg_color(scale, lv_color_hex(BACKGROUND_COLOR), LV_PART_MAIN); lv_style_init(&style_unitxAx_label);
lv_scale_set_range(scale, 40, 100); lv_style_set_text_font(&style_unitxAx_label, &lv_font_montserrat_12);
lv_obj_add_style(unitxAx_label, &style_unitxAx_label, 0);
static lv_style_t style_scale; */
lv_style_init(&style_scale); /* ganz rechts unten die Version anzeigen */
lv_style_set_text_font(&style_scale, &lv_font_montserrat_10); lv_obj_t *version_label = lv_label_create(chart);
lv_style_set_text_color(&style_scale, lv_color_hex(0xFF0000));
lv_obj_add_style(scale, &style_scale, 0);
/* // Label an der Axe
lv_obj_t * unitxAx_label = lv_label_create(container_row);
lv_label_set_text(unitxAx_label, "°C");
lv_obj_align(unitxAx_label, LV_ALIGN_TOP_RIGHT, -20, 8);
static lv_style_t style_unitxAx_label;
lv_style_init(&style_unitxAx_label);
lv_style_set_text_font(&style_unitxAx_label, &lv_font_montserrat_12);
lv_obj_add_style(unitxAx_label, &style_unitxAx_label, 0);
*/
/* ganz rechts unten die Version anzeigen */
lv_obj_t * version_label = lv_label_create(chart);
char ver[20]; char ver[20];
sprintf(ver, "V %s %s", VERSION, VDATE); sprintf(ver, "V %s %s", VERSION, VDATE);
lv_label_set_text(version_label, ver); lv_label_set_text(version_label, ver);
@@ -294,20 +315,34 @@ void setValuetoArc(ARC arc, float value) {
lv_style_set_text_font(&style_version_label, &lv_font_montserrat_8); 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_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); 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++) { int i = 0;
bmewert[i] = bmewert[i + 1]; for (i = 0; i < MAXREADINGS - 1; i++)
bmewert_hum[i] = bmewert_hum[i + 1]; {
} bmewert[i] = bmewert[i + 1];
bmewert[MAXREADINGS - 1] = value; bmewert_hum[i] = bmewert_hum[i + 1];
bmewert_hum[MAXREADINGS - 1] = humvalue; }
bmewert[MAXREADINGS - 1] = value;
bmewert_hum[MAXREADINGS - 1] = humvalue;
lv_chart_refresh(chart); 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);
}
} }

View File

@@ -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}; ARC arcHum = {NULL, "humi", 170, -1, 110, 60.0, "%.0f%%", "%", 40, 100, 65, 70, 2};
lv_obj_t * date_label; lv_obj_t * date_label;
lv_obj_t * time_label; lv_obj_t * time_label;
lv_obj_t * ta_label;
lv_obj_t * fa_label;
#else #else
extern ARC arcTemp; extern ARC arcTemp;
extern ARC arcHum; extern ARC arcHum;
extern lv_obj_t * date_label; extern lv_obj_t * date_label;
extern lv_obj_t * time_label; extern lv_obj_t * time_label;
extern lv_obj_t * ta_label;
extern lv_obj_t * fa_label;
#endif #endif
@@ -54,6 +58,9 @@ void lv_create_main_gui(void);
void setValuetoArc(ARC arc, float value); void setValuetoArc(ARC arc, float value);
void drawChart(); void drawChart();
void updatechartData(float value, float value_hum); void updatechartData(float value, float value_hum);
void setAussenDataValues(float val, bool what);

View File

@@ -68,6 +68,7 @@ void setup() {
connectToWifi(); connectToWifi();
// Start MQTT // Start MQTT
setupMQTT();
connectToMqtt(); connectToMqtt();
Serial.println("MQTT started"); Serial.println("MQTT started");
@@ -86,21 +87,10 @@ void setup() {
// Function to draw the GUI // Function to draw the GUI
lv_create_main_gui(); lv_create_main_gui();
Serial.println("Main GUI created"); Serial.println("Main GUI created");
*/
delay(1000); 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() { void loop() {

View File

@@ -6,8 +6,8 @@ extern "C" {
#include "freertos/timers.h" #include "freertos/timers.h"
} }
#define VERSION "1.1.0" #define VERSION "1.2.0"
#define VDATE "2024-07-11" #define VDATE "2024-07-21"
//#define MAXREADINGS 224 //#define MAXREADINGS 224
#define MAXREADINGS 200 #define MAXREADINGS 200

View File

@@ -1,7 +1,22 @@
#define MQTT #define MQTT
#include "grafik.h"
#include "mqtt.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() { void connectToMqtt() {
Serial.println("Connecting to MQTT..."); Serial.println("Connecting to MQTT...");
mqttClient.connect(); mqttClient.connect();
@@ -13,7 +28,11 @@ void onMqttConnect(bool sessionPresent) {
Serial.println(sessionPresent);*/ Serial.println(sessionPresent);*/
// Subscribe to topic "message" when it connects to the broker // 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.print("Subscribing at QoS 2, packetId: ");
//Serial.println(packetIdSub); //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) { 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 // Do whatever you want when you receive a message
// Save the message in a variable // Save the message in a variable
Serial.println(topic);
String received_message; String received_message;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Serial.println((char)payload[i]);
received_message += (char)payload[i]; received_message += (char)payload[i];
} }
// Display the text message on the display receive from the MQTT topic "message" // Display the text message on the display receive from the MQTT topic "message"
if (strcmp(topic, MQTT_TOPIC_MESSAGE) == 0) { float wert;
// deserializeJson(doc, received_message); bool what;
// String temp = doc["temperature"]; if (strcmp(topic, MQTT_TOPIC_T) == 0) {
// String hum = doc["humidity"]; deserializeJson(doc, received_message);
// received_message = "Temperature: " + temp + "°C\nHumidity: " + hum + "%"; Serial.print("AT: ");
// lv_label_set_text(mqtt_text_label, received_message.c_str()); 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);
}

View File

@@ -12,7 +12,9 @@
#define BROKER_USER "rxf" #define BROKER_USER "rxf"
#define BROKER_PASS "Tux4S!ech" #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 #ifdef MQTT
AsyncMqttClient mqttClient; AsyncMqttClient mqttClient;
@@ -20,6 +22,7 @@ AsyncMqttClient mqttClient;
extern AsyncMqttClient mqttClient; extern AsyncMqttClient mqttClient;
#endif #endif
void setupMQTT();
void connectToMqtt(); void connectToMqtt();
void onMqttConnect(bool sessionPresent); void onMqttConnect(bool sessionPresent);
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason); void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);