Skip to content

Commit 07e2828

Browse files
committed
Bump version to v1.4.1
* Clear modbus retained
1 parent 1318de6 commit 07e2828

File tree

8 files changed

+69
-7
lines changed

8 files changed

+69
-7
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ERa",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "E-Ra by EoH. An IoT Market Enabler! It supports WiFi, Ethernet, Zigbee, Modbus, Serial. Works with boards like Arduino, ESP8266, ESP32, STM32, Raspberry Pi...",
55
"keywords": "ERa, E-Ra, esp8266, esp32, stm32, raspberry-pi, http, mqtt, zigbee, modbus, sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, wifi, ethernet, serial",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ERa
2-
version=1.4.0
2+
version=1.4.1
33
author=EoH Ltd
44
license=MIT
55
maintainer=EoH Ltd <[email protected]>

linux/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
ERA_MAJOR = 1
2121
ERA_MINOR = 4
22-
ERA_PATCH = 0
23-
ERA_VERSION = "1.4.0"
24-
ERA_FIRMWARE_VERSION = "1.4.0"
22+
ERA_PATCH = 1
23+
ERA_VERSION = "1.4.1"
24+
ERA_FIRMWARE_VERSION = "1.4.1"
2525

2626
BUTTON_GPIO = 16
2727

src/ERa/ERaApi.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ class ERaApi
454454
#endif
455455
}
456456

457+
void configIdRemove(ERaInt_t configId) {
458+
this->thisProto().removeRetainedConfigIdData(configId);
459+
}
460+
457461
#if defined(ERA_MODBUS)
458462
void modbusDataWrite(ERaDataBuff* value) {
459463
#if ERA_MAX_EVENTS
@@ -468,6 +472,10 @@ class ERaApi
468472
this->thisProto().sendCommand(rsp, value);
469473
#endif
470474
}
475+
476+
void modbusDataRemove() {
477+
this->thisProto().removeRetainedModbusData();
478+
}
471479
#endif
472480

473481
#if defined(ERA_ZIGBEE)

src/ERa/ERaProtocol.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class ERaProto
271271
bool sendChangeResultWiFi(const char* payload);
272272
bool publishData(const char* prefixTopic, const char* payload,
273273
bool retained, bool extended = false);
274+
bool removeRetainedData(const char* prefixTopic);
274275
bool isConfigMode();
275276
void onConnected();
276277
void onDisconnected();
@@ -322,7 +323,9 @@ class ERaProto
322323
void sendCommandVirtual(ERaRsp_t& rsp, ERaDataJson* data);
323324
#if defined(ERA_MODBUS)
324325
void sendCommandModbus(ERaRsp_t& rsp, ERaDataBuff* data);
326+
void removeRetainedModbusData();
325327
#endif
328+
void removeRetainedConfigIdData(ERaInt_t configId);
326329

327330
void processRequest(const char* topic, const char* payload);
328331
#if !defined(ERA_HAS_FUNCTIONAL_H)
@@ -1020,6 +1023,11 @@ bool ERaProto<Transp, Flash>::publishData(const char* prefixTopic, const char* p
10201023
return this->transp.publishData(topic, payload, retained);
10211024
}
10221025

1026+
template <class Transp, class Flash>
1027+
bool ERaProto<Transp, Flash>::removeRetainedData(const char* prefixTopic) {
1028+
return this->publishData(prefixTopic, "", true);
1029+
}
1030+
10231031
template <class Transp, class Flash>
10241032
bool ERaProto<Transp, Flash>::sendListWiFi(const char* payload) {
10251033
return this->publishData(ERA_PUB_PREFIX_LIST_WIFI_TOPIC,
@@ -1640,8 +1648,21 @@ void ERaProto<Transp, Flash>::sendCommandVirtual(ERaRsp_t& rsp, ERaDataJson* dat
16401648
cJSON_Delete(root);
16411649
root = nullptr;
16421650
}
1651+
1652+
template <class Transp, class Flash>
1653+
void ERaProto<Transp, Flash>::removeRetainedModbusData() {
1654+
this->removeRetainedData(ERA_PUB_PREFIX_MODBUS_DATA_TOPIC);
1655+
}
16431656
#endif
16441657

1658+
template <class Transp, class Flash>
1659+
void ERaProto<Transp, Flash>::removeRetainedConfigIdData(ERaInt_t configId) {
1660+
char topicName[MAX_TOPIC_LENGTH] {0};
1661+
FormatString(topicName, this->ERA_TOPIC);
1662+
FormatString(topicName, ERA_PUB_PREFIX_CONFIG_DATA_TOPIC, configId);
1663+
this->transp.publishData(topicName, "", true);
1664+
}
1665+
16451666
template <class Transp, class Flash>
16461667
size_t ERaProto<Transp, Flash>::splitString(char* strInput, const char* delims) {
16471668
if ((strInput == nullptr) ||

src/ERa/ERaVersion.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define ERA_MAJOR 1
55
#define ERA_MINOR 4
6-
#define ERA_PATCH 0
6+
#define ERA_PATCH 1
77

88
#define ERA_VERSION_TO_STR_2(val) # val
99
#define ERA_VERSION_TO_STR(val) ERA_VERSION_TO_STR_2(val)
@@ -17,7 +17,7 @@
1717
#define ERA_VERSION ERA_VERSION_TO_STR(ERA_MAJOR) "." \
1818
ERA_VERSION_TO_STR(ERA_MINOR) "." \
1919
ERA_VERSION_TO_STR(ERA_PATCH)
20-
#define ERA_VERSION_1_4_0
20+
#define ERA_VERSION_1_4_1
2121

2222
#if !defined(ERA_FIRMWARE_VERSION)
2323
#define ERA_FIRMWARE_VERSION ERA_VERSION

src/Modbus/ERaModbus.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ class ERaModbus
290290
this->thisApi().configIdWrite(configId, value);
291291
}
292292

293+
void configIdModbusRemove(ERaInt_t configId) override {
294+
this->thisApi().configIdRemove(configId);
295+
}
296+
293297
void clearDataBuff() {
294298
this->dataBuff.clearBuffer();
295299
}
@@ -413,6 +417,13 @@ class ERaModbus
413417
this->modbusConfig->resize();
414418
this->modbusControl->resize();
415419
this->initModbus(true);
420+
ERaDelay(500);
421+
if (ModbusTransp::isNewReport()) {
422+
this->thisApi().modbusDataRemove();
423+
}
424+
else {
425+
ModbusTransp::removeConfigId();
426+
}
416427
}
417428
ModbusState::set(ModbusStateT::STATE_MB_RUNNING);
418429
}

src/Modbus/ERaModbusData.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ class ERaModbusData
273273
return this->enableReport;
274274
}
275275

276+
void removeConfigId();
276277
void updateRegister();
277278
void parseConfig(const void* ptr, bool json);
278279
void processParseParamConvertAi(const cJSON* const root, iterator& it);
@@ -288,6 +289,11 @@ class ERaModbusData
288289
ERA_LOG_WARNING(TAG, ERA_PSTR("configIdModbusWrite default."));
289290
}
290291

292+
virtual void configIdModbusRemove(ERaInt_t configId) {
293+
ERA_FORCE_UNUSED(configId);
294+
ERA_LOG_WARNING(TAG, ERA_PSTR("configIdModbusRemove default."));
295+
}
296+
291297
private:
292298
iterator addInternalRegister(ERaInt_t configId, uint8_t addr, uint8_t func, uint16_t reg) {
293299
return this->addInternalRegister(configId, addr, func, HI_WORD(reg), LO_WORD(reg));
@@ -328,6 +334,7 @@ class ERaModbusData
328334
}
329335

330336
ERaList<Register_t*> ERaReg;
337+
ERaList<ERaInt_t> ERaRegId;
331338
ERaReport ERaRegRp;
332339
unsigned int numRegister;
333340

@@ -387,6 +394,7 @@ ERaModbusData::Register_t* ERaModbusData::setupRegister(WrapperBase* value, uint
387394

388395
inline
389396
void ERaModbusData::updateRegister() {
397+
this->ERaRegId.clear();
390398
Register_t* pReg = nullptr;
391399
ModbusDataIterator* next = nullptr;
392400
const ModbusDataIterator* e = this->ERaReg.end();
@@ -399,6 +407,7 @@ void ERaModbusData::updateRegister() {
399407
if (!pReg->configId) {
400408
continue;
401409
}
410+
this->ERaRegId.put(pReg->configId);
402411
if (pReg->value != nullptr) {
403412
delete pReg->value;
404413
pReg->value = nullptr;
@@ -616,6 +625,19 @@ bool ERaModbusData::handler(ERaModbusRequest* request, ERaModbusResponse* respon
616625
return found;
617626
}
618627

628+
inline
629+
void ERaModbusData::removeConfigId() {
630+
const ERaList<ERaInt_t>::iterator* e = this->ERaRegId.end();
631+
for (ERaList<ERaInt_t>::iterator* it = this->ERaRegId.begin(); it != e; it = it->getNext()) {
632+
ERaInt_t configId = it->get();
633+
if (!configId) {
634+
continue;
635+
}
636+
this->configIdModbusRemove(configId);
637+
}
638+
this->ERaRegId.clear();
639+
}
640+
619641
inline
620642
bool ERaModbusData::handlerBits(ERaModbusRequest* request, ERaModbusResponse* response, bool success) {
621643
bool found {false};

0 commit comments

Comments
 (0)