Skip to content

Commit

Permalink
ntp time update
Browse files Browse the repository at this point in the history
  • Loading branch information
lefty01 committed Dec 9, 2023
1 parent 3f57a3f commit f513ce7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
6 changes: 6 additions & 0 deletions code/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
// DST delta to apply
#define TIMEZONE_DST_SEC 0 //3600 FIXME does DST work?! doesnt look like

// configure NTP
// https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
#define MY_NTP_SERVER "de.pool.ntp.org"
#define MY_TZ "CET-1CEST,M3.5.0,M10.5.0/3"


// How long are informational messages kept on screen
#define LOG_MESSAGE_PERSISTENCE_MSEC 30000

Expand Down
2 changes: 1 addition & 1 deletion code/include/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _PROG_VERSION_H__
#define _PROG_VERSION_H__

const char* PROG_VERSION = "0.1.3";
const char* PROG_VERSION = "0.1.3b";

#endif
1 change: 1 addition & 0 deletions code/src/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void displayClock() {
int hh = timeinfo.tm_hour;
int mm = timeinfo.tm_min;
int ss = timeinfo.tm_sec;
Serial.printf("%d:%d:%d\n", hh, mm, ss);
delay(500);

if (clockStartingUp) { // If we didn't have a previous time. Just draw it without morphing.
Expand Down
31 changes: 21 additions & 10 deletions code/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ void setup(){
logStatusMessage("WiFi connected!");

logStatusMessage("NTP time...");
configTime(TIMEZONE_DELTA_SEC, TIMEZONE_DST_SEC, NTP_SERVER);

configTime(0, 0, MY_NTP_SERVER); // 0, 0 because we will use TZ in the next line
setenv("TZ", MY_TZ, 1); // Set environment variable with your time zone
tzset();

lastNTPUpdate = millis();
logStatusMessage("NTP done!");

Expand Down Expand Up @@ -156,8 +160,15 @@ void loop() {

// Periodically refresh NTP time
if ((millis() - lastNTPUpdate) > (1000 * NTP_REFRESH_INTERVAL_SEC)) {
logStatusMessage("NTP Refresh");
configTime(TIMEZONE_DELTA_SEC, TIMEZONE_DST_SEC, NTP_SERVER);
logStatusMessage("No NTP Refresh");
//configTime(0, 0, MY_NTP_SERVER); // 0, 0 because we will use TZ in the next line
//tzset();

int hh = timeinfo.tm_hour;
int mm = timeinfo.tm_min;
int ss = timeinfo.tm_sec;
Serial.printf("%d:%d:%d\n", hh, mm, ss);

lastNTPUpdate = millis();
}

Expand Down Expand Up @@ -227,7 +238,7 @@ void loop() {
//drawHeartBeat(); // TODO: config option heartbeat

if ((millis() - lastI2cSensorRead) > (1000 * I2C_READ_INTERVAL_SEC)) {
lightUpdate();
//lightUpdate();
i2cSensorUpdate();
lastI2cSensorRead = millis();
}
Expand All @@ -252,13 +263,13 @@ void displayUpdater() {
}

void i2cSensorUpdate() {
float lightData = getLightData();
float tempdata = getTempData();
float pressuredata = getPressureData();

Serial.print("temp: "); Serial.println(tempdata);
Serial.print("pressure: "); Serial.println(pressuredata);
float lightData = getLightData();
float tempData = getTempData();
float pressureData = getPressureData();

Serial.print("temp: "); Serial.println(tempData);
Serial.print("pressure: "); Serial.println(pressureData);
Serial.print("light: "); Serial.println(lightData);
}

void lightUpdate() {
Expand Down
19 changes: 12 additions & 7 deletions code/src/rgb_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ void displaySensorData() {
Serial.printf("[%d] value int: %d\n", i, mySensors[i].val_i);
Serial.printf("[%d] value float: %f\n", i, mySensors[i].val_f);
}
//
//
//mySensors[i].newData = false;
//}
//
//
//mySensors[i].newData = false;
//}
}
// for (int i; i = 0; ++i) {
// int val = s[i].val_i;
Expand Down Expand Up @@ -159,18 +159,23 @@ void displayLightData(float luxValue) {
void displayWeatherData(const struct city_info &info) {
Serial.printf("displayWeatherData: temp=%2.1f, humi=%d\n",
info.forecasts[0].temp, info.forecasts[0].humidity);

fixme ...
dma_display->fillRect(SENSOR_DATA_X, SENSOR_DATA_Y,
SENSOR_DATA_WIDTH, SENSOR_DATA_HEIGHT, 0);
dma_display->setTextSize(1); // size 1 == 8 pixels high
dma_display->setTextWrap(false); // Don't wrap at end of line - will do ourselves
dma_display->setTextColor(SENSOR_DATA_COLOR);
//dma_display->setFont(&FreeSerifBold12pt7b);

dma_display->setCursor(SENSOR_DATA_X, SENSOR_DATA_Y);
dma_display->setCursor(SENSOR_1_DATA_X, SENSOR_1_DATA_Y);
dma_display->printf("%2.1f", info.forecasts[0].temp);
dma_display->setCursor(SENSOR_DATA_X, SENSOR_DATA_Y + 8);

dma_display->setCursor(SENSOR_2_DATA_X, SENSOR_2_DATA_Y);
dma_display->printf("%3d%%", info.forecasts[0].humidity);

dma_display->setCursor(SENSOR_3_DATA_X, SENSOR_3_DATA_Y);
dma_display->printf("%4d%", info.forecasts[0].grnd_level);

// Draw the degree symbol manually
dma_display->fillRect(SENSOR_DATA_X + 25, SENSOR_DATA_Y, 2, 2, SENSOR_DATA_COLOR);

Expand Down
11 changes: 5 additions & 6 deletions code/src/weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,39 +283,38 @@ int accuWeatherIconMapping(int icon) {
if (icon <= 32) return 2;
return 0;
}

// FIXME: pressure overwrite old value ... clear area.

/* Start of code to get data from openweathermap - based on work by https://github.com/lefty01
*/
int getOpenWeatherData(uint32_t loc_id, const char *units, const char *appid,
struct city_info *info)
struct city_info *info)
{
StaticJsonDocument<272> filter;
filter["city"] = true;

JsonObject filter_list_0 = filter["list"].createNestedObject();
filter_list_0["dt"] = true;
filter_list_0["wind"]["speed"] = true;

JsonObject filter_list_0_weather_0 = filter_list_0["weather"].createNestedObject();
filter_list_0_weather_0["icon"] = true;
filter_list_0_weather_0["id"] = true;
filter_list_0["wind"]["speed"] = true;

JsonObject filter_list_0_main = filter_list_0.createNestedObject("main");
filter_list_0_main["temp"] = true;
filter_list_0_main["temp_min"] = true;
filter_list_0_main["temp_max"] = true;
filter_list_0_main["pressure"] = true; // Atmospheric pressure on the sea level, hPa
filter_list_0_main["grnd_level"] = true; // Atmospheric pressure on the ground level, hPa

filter_list_0_main["humidity"] = true;

char url[128];

// sanity check units ...
// strcmp(units, "standard") ... "metric", or "imperial"
snprintf(url, 128, "http://api.openweathermap.org/data/2.5/forecast?id=%u&units=%s&appid=%s",
loc_id, units, appid);
loc_id, units, appid);

// Allocate the largest possible document (platform dependent)
// DynamicJsonDocument doc(ESP.getMaxFreeBlockSize());
Expand All @@ -327,7 +326,7 @@ int getOpenWeatherData(uint32_t loc_id, const char *units, const char *appid,
http.GET();

DeserializationError error = deserializeJson(doc, http.getStream(),
DeserializationOption::Filter(filter));
DeserializationOption::Filter(filter));
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
Expand Down

0 comments on commit f513ce7

Please sign in to comment.