WIP_20240708_1558
This commit is contained in:
@@ -42,7 +42,7 @@ void buildarc(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);
|
||||||
lv_obj_align(low_label, LV_ALIGN_LEFT_MID, 0, 8);
|
lv_obj_align(low_label, LV_ALIGN_LEFT_MID, 5, 8);
|
||||||
static lv_style_t style_low_label;
|
static lv_style_t style_low_label;
|
||||||
lv_style_init(&style_low_label);
|
lv_style_init(&style_low_label);
|
||||||
lv_style_set_text_font(&style_low_label, &lv_font_montserrat_10);
|
lv_style_set_text_font(&style_low_label, &lv_font_montserrat_10);
|
||||||
@@ -81,27 +81,27 @@ void buildarc(ARC arc) {
|
|||||||
|
|
||||||
void lv_create_main_gui(void) {
|
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
|
||||||
lv_obj_t * date_label = lv_label_create(lv_screen_active());
|
time_label = lv_label_create(lv_screen_active());
|
||||||
lv_label_set_text(date_label, "17:30");
|
lv_label_set_text(time_label, "17:30");
|
||||||
lv_obj_align(date_label, LV_ALIGN_TOP_MID, 0, 10);
|
lv_obj_align(time_label, LV_ALIGN_TOP_MID, 0, 10);
|
||||||
|
|
||||||
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
|
|
||||||
static lv_style_t style_date_label;
|
|
||||||
lv_style_init(&style_date_label);
|
|
||||||
lv_style_set_text_font(&style_date_label, &lv_font_montserrat_28);
|
|
||||||
lv_obj_add_style(date_label, &style_date_label, 0);
|
|
||||||
|
|
||||||
// Create a text label aligned on top: https://docs.lvgl.io/master/widgets/label.html
|
|
||||||
lv_obj_t * time_label = lv_label_create(lv_screen_active());
|
|
||||||
lv_label_set_text(time_label, "Dienstag, 12. Dezember 2024");
|
|
||||||
lv_obj_align(time_label, LV_ALIGN_TOP_MID, 0, 40);
|
|
||||||
|
|
||||||
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
|
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
|
||||||
static lv_style_t style_time_label;
|
static lv_style_t style_time_label;
|
||||||
lv_style_init(&style_time_label);
|
lv_style_init(&style_time_label);
|
||||||
lv_style_set_text_font(&style_time_label, &lv_font_montserrat_12);
|
lv_style_set_text_font(&style_time_label, &lv_font_montserrat_28);
|
||||||
lv_obj_add_style(time_label, &style_time_label, 0);
|
lv_obj_add_style(time_label, &style_time_label, 0);
|
||||||
|
|
||||||
|
// Create a text label aligned on top: https://docs.lvgl.io/master/widgets/label.html
|
||||||
|
date_label = lv_label_create(lv_screen_active());
|
||||||
|
lv_label_set_text(date_label, "Dienstag, 12. Dezember 2024");
|
||||||
|
lv_obj_align(date_label, LV_ALIGN_TOP_MID, 0, 40);
|
||||||
|
|
||||||
|
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
|
||||||
|
static lv_style_t style_date_label;
|
||||||
|
lv_style_init(&style_date_label);
|
||||||
|
lv_style_set_text_font(&style_date_label, &lv_font_montserrat_12);
|
||||||
|
lv_obj_add_style(date_label, &style_date_label, 0);
|
||||||
|
|
||||||
/* Refresh-Symbol anzeigen
|
/* Refresh-Symbol anzeigen
|
||||||
lv_obj_t * refresh_label = lv_label_create(lv_screen_active());
|
lv_obj_t * refresh_label = lv_label_create(lv_screen_active());
|
||||||
lv_label_set_text(refresh_label, LV_SYMBOL_REFRESH);
|
lv_label_set_text(refresh_label, LV_SYMBOL_REFRESH);
|
||||||
@@ -181,7 +181,7 @@ void setValuetoArc(ARC arc, float value) {
|
|||||||
// Axen
|
// Axen
|
||||||
lv_obj_t * scale = lv_scale_create(container_row);
|
lv_obj_t * scale = lv_scale_create(container_row);
|
||||||
lv_obj_set_size(scale, 15, 75);
|
lv_obj_set_size(scale, 15, 75);
|
||||||
lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_RIGHT);
|
lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_LEFT);
|
||||||
|
|
||||||
lv_scale_set_label_show(scale, true);
|
lv_scale_set_label_show(scale, true);
|
||||||
|
|
||||||
@@ -200,6 +200,15 @@ void setValuetoArc(ARC arc, float value) {
|
|||||||
lv_style_set_text_font(&style_scale, &lv_font_montserrat_10);
|
lv_style_set_text_font(&style_scale, &lv_font_montserrat_10);
|
||||||
lv_obj_add_style(scale, &style_scale, 0);
|
lv_obj_add_style(scale, &style_scale, 0);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,15 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef MAIN
|
#ifdef MAIN
|
||||||
ARC arcTemp = {NULL, "temp", 30, 0, 110, 30.0, "%.1f", "°C", 10, 30, 20, 25};
|
ARC arcTemp = {NULL, "temp", 40, 0, 110, 30.0, "%.1f", "°C", 10, 30, 20, 25};
|
||||||
ARC arcHum = {NULL, "humi", 180, 0, 110, 60.0, "%.0f", "%",0, 100, 65, 70};
|
ARC arcHum = {NULL, "humi", 170, 0, 110, 60.0, "%.0f", "%",0, 100, 65, 70};
|
||||||
|
lv_obj_t * date_label;
|
||||||
|
lv_obj_t * time_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 * time_label;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
39
src/main.cpp
39
src/main.cpp
@@ -28,11 +28,17 @@
|
|||||||
#include "grafik.h"
|
#include "grafik.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
long repeatTime = 10000; // alle 1sec messen
|
#define BMWREADTIME 10000
|
||||||
long lastTime = 0;
|
#define NTPREADTIME 1000
|
||||||
|
|
||||||
|
long bmeReadtimer = 0;
|
||||||
|
long ntpReadtimer = 0;
|
||||||
|
|
||||||
BME280Data bmedata;
|
BME280Data bmedata;
|
||||||
|
|
||||||
|
int currentSecond = -1;
|
||||||
|
|
||||||
|
void showDateTime(struct tm tinfo);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
|
// String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
|
||||||
@@ -61,9 +67,11 @@ void setup() {
|
|||||||
connectToMqtt();
|
connectToMqtt();
|
||||||
Serial.println("MQTT started");
|
Serial.println("MQTT started");
|
||||||
|
|
||||||
|
timeinfo = gettheTime(NTPREADTIME);
|
||||||
lastTime = millis();
|
showDateTime(timeinfo);
|
||||||
|
|
||||||
|
bmeReadtimer = millis();
|
||||||
|
|
||||||
drawChart();
|
drawChart();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -92,14 +100,27 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (millis() - lastTime > repeatTime) {
|
timeinfo = gettheTime(NTPREADTIME);
|
||||||
lastTime = millis();
|
if (timeinfo.tm_sec == 0) { // minute over
|
||||||
|
showDateTime(timeinfo);
|
||||||
|
printLocalTime();
|
||||||
|
}
|
||||||
|
if (millis() - bmeReadtimer > BMWREADTIME) {
|
||||||
|
bmeReadtimer = millis();
|
||||||
bmedata = readBME280();
|
bmedata = readBME280();
|
||||||
setValuetoArc(arcTemp, bmedata.temp);
|
setValuetoArc(arcTemp, bmedata.temp);
|
||||||
setValuetoArc(arcHum, bmedata.hum);
|
setValuetoArc(arcHum, bmedata.hum);
|
||||||
updatechartData(bmedata.hum, bmedata.temp);
|
}
|
||||||
}
|
|
||||||
lv_task_handler(); // let the GUI do its work
|
lv_task_handler(); // let the GUI do its work
|
||||||
lv_tick_inc(5); // tell LVGL how much time has passed
|
lv_tick_inc(5); // tell LVGL how much time has passed
|
||||||
delay(5); // let this time pass
|
delay(5); // let this time pass
|
||||||
|
}
|
||||||
|
|
||||||
|
void showDateTime(struct tm tinfo) {
|
||||||
|
char time[6];
|
||||||
|
char date[50];
|
||||||
|
strftime(time, 6, "%H:%M", &tinfo);
|
||||||
|
strftime(date, 50, "%A, %d %B %Y", &tinfo);
|
||||||
|
lv_label_set_text(time_label, time);
|
||||||
|
lv_label_set_text(date_label, date);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,45 @@
|
|||||||
#include "weifi.h"
|
#include "weifi.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
struct tm gettheTime(int repeat) {
|
||||||
|
if(!getLocalTime(&timeinfo)){
|
||||||
|
Serial.println("Failed to obtain time");
|
||||||
|
}
|
||||||
|
return timeinfo;
|
||||||
|
}
|
||||||
|
void printLocalTime(){
|
||||||
|
struct tm timeinfo;
|
||||||
|
if(!getLocalTime(&timeinfo)){
|
||||||
|
Serial.println("Failed to obtain time");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||||
|
Serial.print("Day of week: ");
|
||||||
|
Serial.println(&timeinfo, "%A");
|
||||||
|
Serial.print("Month: ");
|
||||||
|
Serial.println(&timeinfo, "%B");
|
||||||
|
Serial.print("Day of Month: ");
|
||||||
|
Serial.println(&timeinfo, "%d");
|
||||||
|
Serial.print("Year: ");
|
||||||
|
Serial.println(&timeinfo, "%Y");
|
||||||
|
Serial.print("Hour: ");
|
||||||
|
Serial.println(&timeinfo, "%H");
|
||||||
|
Serial.print("Hour (12 hour format): ");
|
||||||
|
Serial.println(&timeinfo, "%I");
|
||||||
|
Serial.print("Minute: ");
|
||||||
|
Serial.println(&timeinfo, "%M");
|
||||||
|
Serial.print("Second: ");
|
||||||
|
Serial.println(&timeinfo, "%S");
|
||||||
|
|
||||||
|
Serial.println("Time variables");
|
||||||
|
char timeHour[3];
|
||||||
|
strftime(timeHour,3, "%H", &timeinfo);
|
||||||
|
Serial.println(timeHour);
|
||||||
|
char timeWeekDay[10];
|
||||||
|
strftime(timeWeekDay,10, "%A", &timeinfo);
|
||||||
|
Serial.println(timeWeekDay);
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
void connectToWifi() {
|
void connectToWifi() {
|
||||||
Serial.println("Connecting to Wi-Fi...");
|
Serial.println("Connecting to Wi-Fi...");
|
||||||
@@ -13,8 +52,12 @@ void connectToWifi() {
|
|||||||
}
|
}
|
||||||
Serial.print("Connected to the WiFi with IP: ");
|
Serial.print("Connected to the WiFi with IP: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
|
||||||
|
printLocalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void WiFiEvent(WiFiEvent_t event) {
|
void WiFiEvent(WiFiEvent_t event) {
|
||||||
Serial.printf("[WiFi-event] event: %d\n", event);
|
Serial.printf("[WiFi-event] event: %d\n", event);
|
||||||
|
|||||||
16
src/weifi.h
16
src/weifi.h
@@ -2,17 +2,33 @@
|
|||||||
#define WEIFI_H
|
#define WEIFI_H
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
#ifdef MAIN
|
||||||
|
struct tm timeinfo;
|
||||||
|
#else
|
||||||
|
extern struct tm timeinfo;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WEIFI
|
#ifdef WEIFI
|
||||||
const char* ssid = "Mizar";
|
const char* ssid = "Mizar";
|
||||||
const char* password = "RingNebelM57";
|
const char* password = "RingNebelM57";
|
||||||
|
const char *ntpServer = "pool.ntp.org";
|
||||||
|
const long gmtOffset_sec = 3600;
|
||||||
|
const int daylightOffset_sec = 3600;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// #warning "You need to set the SSID and PASSWORD in weifi.h"
|
// #warning "You need to set the SSID and PASSWORD in weifi.h"
|
||||||
|
|
||||||
void connectToWifi();
|
void connectToWifi();
|
||||||
|
struct tm gettheTime(int repeat);
|
||||||
|
void printLocalTime();
|
||||||
|
|
||||||
|
|
||||||
// void WiFiEvent(WiFiEvent_t event);
|
// void WiFiEvent(WiFiEvent_t event);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user