mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-07 13:11:38 +02:00
parent
4093be7e70
commit
56cfffbcd8
3 changed files with 16 additions and 17 deletions
|
@ -43,7 +43,7 @@ void app::setup(uint32_t timeout) {
|
||||||
#ifndef AP_ONLY
|
#ifndef AP_ONLY
|
||||||
setupMqtt();
|
setupMqtt();
|
||||||
if(mMqttActive)
|
if(mMqttActive)
|
||||||
mPayload.addListener(std::bind(&MqttType::payloadEventListener, mMqtt, std::placeholders::_1));
|
mPayload.addListener(std::bind(&MqttType::payloadEventListener, &mMqtt, std::placeholders::_1));
|
||||||
#endif
|
#endif
|
||||||
setupLed();
|
setupLed();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 5
|
#define VERSION_MINOR 5
|
||||||
#define VERSION_PATCH 34
|
#define VERSION_PATCH 35
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -65,7 +65,6 @@ class mqtt {
|
||||||
reconnect();
|
reconnect();
|
||||||
mClient->loop();
|
mClient->loop();
|
||||||
|
|
||||||
if(!mSendList.empty())
|
|
||||||
sendIvData();
|
sendIvData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,19 +215,19 @@ class mqtt {
|
||||||
return (pos >= DEVICE_CLS_ASSIGN_LIST_LEN) ? NULL : stateClasses[deviceFieldAssignment[pos].stateClsId];
|
return (pos >= DEVICE_CLS_ASSIGN_LIST_LEN) ? NULL : stateClasses[deviceFieldAssignment[pos].stateClsId];
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendIvData() {
|
void sendIvData(void) {
|
||||||
|
if(mSendList.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
isConnected(true); // really needed? See comment from HorstG-57 #176
|
isConnected(true); // really needed? See comment from HorstG-57 #176
|
||||||
char topic[32 + MAX_NAME_LENGTH], val[32];
|
char topic[32 + MAX_NAME_LENGTH], val[32];
|
||||||
float total[4];
|
float total[4];
|
||||||
bool sendTotal = false;
|
bool sendTotal = false;
|
||||||
bool totalIncomplete = false;
|
bool totalIncomplete = false;
|
||||||
snprintf(val, 32, "%ld", millis() / 1000);
|
snprintf(val, 40, "%ld", millis() / 1000);
|
||||||
|
|
||||||
sendMsg("uptime", val);
|
sendMsg("uptime", val);
|
||||||
|
|
||||||
if(mSendList.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
while(!mSendList.empty()) {
|
while(!mSendList.empty()) {
|
||||||
memset(total, 0, sizeof(float) * 4);
|
memset(total, 0, sizeof(float) * 4);
|
||||||
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
|
@ -250,20 +249,20 @@ class mqtt {
|
||||||
status = MQTT_STATUS_AVAIL_NOT_PROD;
|
status = MQTT_STATUS_AVAIL_NOT_PROD;
|
||||||
}
|
}
|
||||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name);
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name);
|
||||||
snprintf(val, 32, "%s%s%s%s",
|
snprintf(val, 40, "%s%s%s%s",
|
||||||
(MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not yet " : "",
|
(status == MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not yet " : "",
|
||||||
"available and ",
|
"available and ",
|
||||||
(MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "",
|
(status == MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "",
|
||||||
(MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "" : "producing"
|
(status == MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "" : "producing"
|
||||||
);
|
);
|
||||||
sendMsg(topic, val);
|
sendMsg(topic, val);
|
||||||
|
|
||||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available", iv->name);
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available", iv->name);
|
||||||
snprintf(val, 32, "%d", status);
|
snprintf(val, 40, "%d", status);
|
||||||
sendMsg(topic, val);
|
sendMsg(topic, val);
|
||||||
|
|
||||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/last_success", iv->name);
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/last_success", iv->name);
|
||||||
snprintf(val, 48, "%i", iv->getLastTs(rec) * 1000);
|
snprintf(val, 40, "%i", iv->getLastTs(rec) * 1000);
|
||||||
sendMsg(topic, val);
|
sendMsg(topic, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +270,7 @@ class mqtt {
|
||||||
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++) {
|
||||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]);
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]);
|
||||||
snprintf(val, 10, "%.3f", iv->getValue(i, rec));
|
snprintf(val, 40, "%.3f", iv->getValue(i, rec));
|
||||||
sendMsg(topic, val);
|
sendMsg(topic, val);
|
||||||
|
|
||||||
// calculate total values for RealTimeRunData_Debug
|
// calculate total values for RealTimeRunData_Debug
|
||||||
|
@ -320,7 +319,7 @@ class mqtt {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]);
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]);
|
||||||
snprintf(val, 10, "%.3f", total[i]);
|
snprintf(val, 40, "%.3f", total[i]);
|
||||||
sendMsg(topic, val);
|
sendMsg(topic, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue