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_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 44 #define VERSION_PATCH 45
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

26
src/publisher/pubMqtt.h

@ -47,7 +47,7 @@ class PubMqtt {
mSunrise = sunrise; mSunrise = sunrise;
mSunset = sunset; 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) #if defined(ESP8266)
mHWifiCon = WiFi.onStationModeGotIP(std::bind(&PubMqtt::onWifiConnect, this, std::placeholders::_1)); 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(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->config->name);
snprintf(val, 40, "%s%s%s%s", 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 ", "available and ",
(status == MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "", (status == MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "",
(status == MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "" : "producing" "producing"
); );
publish(topic, val, true); publish(topic, val, true);
@ -377,9 +377,19 @@ class PubMqtt {
// data // data
if(iv->isAvailable(*mUtcTimestamp, rec)) { if(iv->isAvailable(*mUtcTimestamp, rec)) {
for (uint8_t i = 0; i < rec->length; i++) { 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(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)); snprintf(val, 40, "%.3f", iv->getValue(i, rec));
publish(topic, val); publish(topic, val, retained);
// calculate total values for RealTimeRunData_Debug // calculate total values for RealTimeRunData_Debug
if (mSendList.front() == RealTimeRunData_Debug) { if (mSendList.front() == RealTimeRunData_Debug) {
@ -428,7 +438,7 @@ class PubMqtt {
} }
snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]); snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]);
snprintf(val, 40, "%.3f", total[i]); snprintf(val, 40, "%.3f", total[i]);
publish(topic, val); publish(topic, val, true);
} }
} }
} }
@ -449,9 +459,9 @@ class PubMqtt {
subscriptionCb mSubscriptionCb; subscriptionCb mSubscriptionCb;
// last will topic and payload must be available trough lifetime of 'espMqttClient' // last will topic and payload must be available trough lifetime of 'espMqttClient'
char mLwtTopic[MQTT_TOPIC_LEN+7]; char mLwtTopic[MQTT_TOPIC_LEN+5];
const char* mLwtOnline = "online"; const char* mLwtOnline = "connected";
const char* mLwtOffline = "offline"; const char* mLwtOffline = "not connected";
const char *mDevName, *mVersion; 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 // Source: https://en.wikipedia.org/wiki/Sunrise_equation#Complete_calculation_on_Earth
// Julian day since 1.1.2000 12:00 + correction 69.12s // 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 // Mean solar time
double J = n_JulianDay - lon / 360; double J = n_JulianDay - lon / 360;
// Solar mean anomaly // Solar mean anomaly
@ -25,7 +25,7 @@ namespace ah {
// Declination of the sun // Declination of the sun
double delta = ASIN(SIN(lambda) * SIN(23.44)); double delta = ASIN(SIN(lambda) * SIN(23.44));
// Hour angle // 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 // Calculate sunrise and sunset
double Jrise = Jtransit - omega / 360; double Jrise = Jtransit - omega / 360;
double Jset = Jtransit + omega / 360; double Jset = Jtransit + omega / 360;

2
src/web/html/serial.html

@ -120,7 +120,7 @@
// set time offset for serial console // set time offset for serial console
var obj = new Object(); var obj = new Object();
obj.cmd = "serial_utc_offset"; 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)); getAjax("/api/setup", null, "POST", JSON.stringify(obj));
} }

Loading…
Cancel
Save