Browse Source

partial fix #468 MQTT

fix #466 calculation of sunrise and sunset
fix #463 Webserial Timestamp fix
pull/470/head^2
lumapu 2 years ago
parent
commit
28594aff4f
  1. 2
      src/defines.h
  2. 26
      src/publisher/pubMqtt.h
  3. 4
      src/utils/sun.h
  4. 2
      src/web/html/serial.html

2
src/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 44
#define VERSION_PATCH 45
//-------------------------------------
typedef struct {

26
src/publisher/pubMqtt.h

@ -47,7 +47,7 @@ class PubMqtt {
mSunrise = sunrise;
mSunset = sunset;
snprintf(mLwtTopic, MQTT_TOPIC_LEN + 7, "%s/status", mCfgMqtt->topic);
snprintf(mLwtTopic, MQTT_TOPIC_LEN + 5, "%s/mqtt", mCfgMqtt->topic);
#if defined(ESP8266)
mHWifiCon = WiFi.onStationModeGotIP(std::bind(&PubMqtt::onWifiConnect, this, std::placeholders::_1));
@ -358,10 +358,10 @@ class PubMqtt {
}
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->config->name);
snprintf(val, 40, "%s%s%s%s",
(status == MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not yet " : "",
(status == MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not " : "",
"available and ",
(status == MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "",
(status == MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "" : "producing"
"producing"
);
publish(topic, val, true);
@ -377,9 +377,19 @@ class PubMqtt {
// data
if(iv->isAvailable(*mUtcTimestamp, rec)) {
for (uint8_t i = 0; i < rec->length; i++) {
bool retained = false;
if (mSendList.front() == RealTimeRunData_Debug) {
switch (rec->assign[i].fieldId) {
case FLD_YT:
case FLD_YD:
retained = true;
break;
}
}
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->config->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]);
snprintf(val, 40, "%.3f", iv->getValue(i, rec));
publish(topic, val);
publish(topic, val, retained);
// calculate total values for RealTimeRunData_Debug
if (mSendList.front() == RealTimeRunData_Debug) {
@ -428,7 +438,7 @@ class PubMqtt {
}
snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]);
snprintf(val, 40, "%.3f", total[i]);
publish(topic, val);
publish(topic, val, true);
}
}
}
@ -449,9 +459,9 @@ class PubMqtt {
subscriptionCb mSubscriptionCb;
// last will topic and payload must be available trough lifetime of 'espMqttClient'
char mLwtTopic[MQTT_TOPIC_LEN+7];
const char* mLwtOnline = "online";
const char* mLwtOffline = "offline";
char mLwtTopic[MQTT_TOPIC_LEN+5];
const char* mLwtOnline = "connected";
const char* mLwtOffline = "not connected";
const char *mDevName, *mVersion;
};

4
src/utils/sun.h

@ -11,7 +11,7 @@ namespace ah {
// Source: https://en.wikipedia.org/wiki/Sunrise_equation#Complete_calculation_on_Earth
// Julian day since 1.1.2000 12:00 + correction 69.12s
double n_JulianDay = (utcTs + offset) / 86400 - 10957.0 + 0.0008;
double n_JulianDay = (utcTs + offset) / 86400 - 10957.0;
// Mean solar time
double J = n_JulianDay - lon / 360;
// Solar mean anomaly
@ -25,7 +25,7 @@ namespace ah {
// Declination of the sun
double delta = ASIN(SIN(lambda) * SIN(23.44));
// Hour angle
double omega = ACOS(SIN(-0.83) - SIN(lat) * SIN(delta) / COS(lat) * COS(delta));
double omega = ACOS((SIN(-0.83) - SIN(lat) * SIN(delta) / COS(lat) * COS(delta)));
// Calculate sunrise and sunset
double Jrise = Jtransit - omega / 360;
double Jset = Jtransit + omega / 360;

2
src/web/html/serial.html

@ -120,7 +120,7 @@
// set time offset for serial console
var obj = new Object();
obj.cmd = "serial_utc_offset";
obj.ts = new Date().getTimezoneOffset() * -60;
obj.val = new Date().getTimezoneOffset() * -60;
getAjax("/api/setup", null, "POST", JSON.stringify(obj));
}

Loading…
Cancel
Save