mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 15:36:38 +02:00
improvment mqtt after add values
This commit is contained in:
parent
0af251bff9
commit
146a1d5eea
4 changed files with 72 additions and 37 deletions
|
@ -160,6 +160,7 @@ void app::loop(void) {
|
||||||
if((++mMqttTicker >= mMqttInterval) && (mMqttInterval != 0xffff) && mMqttActive) {
|
if((++mMqttTicker >= mMqttInterval) && (mMqttInterval != 0xffff) && mMqttActive) {
|
||||||
mMqttTicker = 0;
|
mMqttTicker = 0;
|
||||||
mMqtt.isConnected(true); // really needed? See comment from HorstG-57 #176
|
mMqtt.isConnected(true); // really needed? See comment from HorstG-57 #176
|
||||||
|
/*
|
||||||
char topic[30], val[10];
|
char topic[30], val[10];
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
|
@ -174,6 +175,8 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
char val[10];
|
||||||
snprintf(val, 10, "%ld", millis()/1000);
|
snprintf(val, 10, "%ld", millis()/1000);
|
||||||
|
|
||||||
#ifndef __MQTT_NO_DISCOVERCONFIG__
|
#ifndef __MQTT_NO_DISCOVERCONFIG__
|
||||||
|
@ -370,11 +373,32 @@ void app::processPayload(bool retransmit) {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
iv->doCalculations(); // cmd value decides which parser is used to decode payload
|
iv->doCalculations(); // cmd value decides which parser is used to decode payload
|
||||||
|
|
||||||
|
iv->setQueuedCmdFinished();
|
||||||
|
|
||||||
|
// send out
|
||||||
|
char topic[30], val[10];
|
||||||
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++)
|
||||||
|
{
|
||||||
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
|
if (NULL != iv)
|
||||||
|
{
|
||||||
|
if (iv->isAvailable(mTimestamp))
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < iv->listLen; i++)
|
||||||
|
{
|
||||||
|
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
|
||||||
|
snprintf(val, 10, "%.3f", iv->getValue(i));
|
||||||
|
mMqtt.sendMsg(topic, val);
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __MQTT_AFTER_RX__
|
#ifdef __MQTT_AFTER_RX__
|
||||||
doMQTT = true;
|
doMQTT = true;
|
||||||
#endif
|
#endif
|
||||||
iv->setQueuedCmdFinished();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield();
|
yield();
|
||||||
|
|
|
@ -144,7 +144,8 @@ class Inverter {
|
||||||
|
|
||||||
void setQueuedCmdFinished(){
|
void setQueuedCmdFinished(){
|
||||||
if (!_commandQueue.empty()){
|
if (!_commandQueue.empty()){
|
||||||
_commandQueue.pop(); // Will destroy CommandAbstract Class Object (?)
|
// Will destroy CommandAbstract Class Object (?)
|
||||||
|
_commandQueue.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +154,14 @@ class Inverter {
|
||||||
if (_commandQueue.empty()){
|
if (_commandQueue.empty()){
|
||||||
// Fill with default commands
|
// Fill with default commands
|
||||||
enqueCommand<InfoCommand>(RealTimeRunData_Debug);
|
enqueCommand<InfoCommand>(RealTimeRunData_Debug);
|
||||||
//enqueCommand<InfoCommand>(SystemConfigPara);
|
if (fwVersion == 0)
|
||||||
|
{ // info needed maybe after "one nigth" (=> DC>0 to DC=0 and to DC>0) or reboot
|
||||||
|
enqueCommand<InfoCommand>(InverterDevInform_All);
|
||||||
|
}
|
||||||
|
if (actPowerLimit == 0xffff)
|
||||||
|
{ // info needed maybe after "one nigth" (=> DC>0 to DC=0 and to DC>0) or reboot
|
||||||
|
enqueCommand<InfoCommand>(SystemConfigPara);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _commandQueue.front().get()->getCmd();
|
return _commandQueue.front().get()->getCmd();
|
||||||
}
|
}
|
||||||
|
@ -167,8 +175,6 @@ class Inverter {
|
||||||
memset(name, 0, MAX_NAME_LENGTH);
|
memset(name, 0, MAX_NAME_LENGTH);
|
||||||
memset(chName, 0, MAX_NAME_LENGTH * 4);
|
memset(chName, 0, MAX_NAME_LENGTH * 4);
|
||||||
memset(record, 0, sizeof(RECORDTYPE) * listLen);
|
memset(record, 0, sizeof(RECORDTYPE) * listLen);
|
||||||
enqueCommand<InfoCommand>(SystemConfigPara);
|
|
||||||
enqueCommand<InfoCommand>(InverterDevInform_All);
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +228,7 @@ class Inverter {
|
||||||
if (getPosByChFld(0, FLD_ALARM_MES_ID) == pos){
|
if (getPosByChFld(0, FLD_ALARM_MES_ID) == pos){
|
||||||
if (alarmMesIndex < record[pos]){
|
if (alarmMesIndex < record[pos]){
|
||||||
alarmMesIndex = record[pos];
|
alarmMesIndex = record[pos];
|
||||||
enqueCommand<InfoCommand>(AlarmUpdate);
|
//enqueCommand<InfoCommand>(AlarmUpdate); // What is the function of AlarmUpdate?
|
||||||
enqueCommand<InfoCommand>(AlarmData);
|
enqueCommand<InfoCommand>(AlarmData);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -284,41 +290,46 @@ class Inverter {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getLastTs(void) {
|
uint32_t getLastTs(void)
|
||||||
|
{
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getLastTs"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getLastTs"));
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getAssignment() {
|
void getAssignment()
|
||||||
|
{
|
||||||
DPRINTLN(DBG_DEBUG, F("hmInverter.h:getAssignment"));
|
DPRINTLN(DBG_DEBUG, F("hmInverter.h:getAssignment"));
|
||||||
|
// Default assignment;
|
||||||
|
if (INV_TYPE_1CH == type)
|
||||||
|
{
|
||||||
|
listLen = (uint8_t)(HM1CH_LIST_LEN);
|
||||||
|
assign = (byteAssign_t *)hm1chAssignment;
|
||||||
|
channels = 1;
|
||||||
|
}
|
||||||
|
else if (INV_TYPE_2CH == type)
|
||||||
|
{
|
||||||
|
listLen = (uint8_t)(HM2CH_LIST_LEN);
|
||||||
|
assign = (byteAssign_t *)hm2chAssignment;
|
||||||
|
channels = 2;
|
||||||
|
}
|
||||||
|
else if (INV_TYPE_4CH == type)
|
||||||
|
{
|
||||||
|
listLen = (uint8_t)(HM4CH_LIST_LEN);
|
||||||
|
assign = (byteAssign_t *)hm4chAssignment;
|
||||||
|
channels = 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listLen = 0;
|
||||||
|
channels = 0;
|
||||||
|
assign = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t cmd = getQueuedCmd();
|
uint8_t cmd = getQueuedCmd();
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RealTimeRunData_Debug:
|
case RealTimeRunData_Debug:
|
||||||
if (INV_TYPE_1CH == type)
|
// Do nothing will use default
|
||||||
{
|
|
||||||
listLen = (uint8_t)(HM1CH_LIST_LEN);
|
|
||||||
assign = (byteAssign_t *)hm1chAssignment;
|
|
||||||
channels = 1;
|
|
||||||
}
|
|
||||||
else if (INV_TYPE_2CH == type)
|
|
||||||
{
|
|
||||||
listLen = (uint8_t)(HM2CH_LIST_LEN);
|
|
||||||
assign = (byteAssign_t *)hm2chAssignment;
|
|
||||||
channels = 2;
|
|
||||||
}
|
|
||||||
else if (INV_TYPE_4CH == type)
|
|
||||||
{
|
|
||||||
listLen = (uint8_t)(HM4CH_LIST_LEN);
|
|
||||||
assign = (byteAssign_t *)hm4chAssignment;
|
|
||||||
channels = 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
listLen = 0;
|
|
||||||
channels = 0;
|
|
||||||
assign = NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case InverterDevInform_All:
|
case InverterDevInform_All:
|
||||||
listLen = (uint8_t)(HMINFO_LIST_LEN);
|
listLen = (uint8_t)(HMINFO_LIST_LEN);
|
||||||
|
@ -333,7 +344,7 @@ class Inverter {
|
||||||
assign = (byteAssign_t *)AlarmDataAssignment;
|
assign = (byteAssign_t *)AlarmDataAssignment;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DPRINTLN(DBG_INFO, "Parser not implemented");
|
DPRINTLN(DBG_INFO, "Parser not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String getAlarmStr(u_int16_t alarmCode)
|
String getAlarmStr(u_int16_t alarmCode)
|
||||||
|
|
|
@ -192,10 +192,9 @@ class HmRadio {
|
||||||
mTxBuf[10] = cmd; // cid
|
mTxBuf[10] = cmd; // cid
|
||||||
mTxBuf[11] = 0x00;
|
mTxBuf[11] = 0x00;
|
||||||
CP_U32_LittleEndian(&mTxBuf[12], ts);
|
CP_U32_LittleEndian(&mTxBuf[12], ts);
|
||||||
if (cmd == RealTimeRunData_Debug || cmd == AlarmData || cmd == AlarmUpdate ){
|
if (cmd == RealTimeRunData_Debug || cmd == AlarmData ){
|
||||||
mTxBuf[18] = (alarmMesId >> 8) & 0xff;
|
mTxBuf[18] = (alarmMesId >> 8) & 0xff;
|
||||||
mTxBuf[19] = (alarmMesId ) & 0xff;
|
mTxBuf[19] = (alarmMesId ) & 0xff;
|
||||||
//mTxBuf[19] = 0x05; // ToDo: Shall be the last received Alarm Index Number
|
|
||||||
} else {
|
} else {
|
||||||
mTxBuf[18] = 0x00;
|
mTxBuf[18] = 0x00;
|
||||||
mTxBuf[19] = 0x00;
|
mTxBuf[19] = 0x00;
|
||||||
|
|
|
@ -450,8 +450,9 @@ void web::showWebApi(void)
|
||||||
if (response["tx_request"] == (uint8_t)TX_REQ_INFO)
|
if (response["tx_request"] == (uint8_t)TX_REQ_INFO)
|
||||||
{
|
{
|
||||||
// if the AlarmData is requested set the Alarm Index to the requested one
|
// if the AlarmData is requested set the Alarm Index to the requested one
|
||||||
if (cmd == AlarmData){
|
if (cmd == AlarmData || cmd == AlarmUpdate){
|
||||||
iv->alarmMesIndex = response["payload"];
|
// set the AlarmMesIndex for the request from user input
|
||||||
|
iv->alarmMesIndex = response["payload"];
|
||||||
}
|
}
|
||||||
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(cmd) + F(" and payload ") + String((uint16_t) response["payload"]));
|
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(cmd) + F(" and payload ") + String((uint16_t) response["payload"]));
|
||||||
// process payload from web request corresponding to the cmd
|
// process payload from web request corresponding to the cmd
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue