mirror of https://github.com/arendst/Tasmota.git
parent
15d475c3e6
commit
5e1cbcf94f
|
@ -874,8 +874,15 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
|
|||
}
|
||||
else if (CMND_MODULE == command_code) {
|
||||
if ((payload >= 0) && (payload <= MAXMODULE)) {
|
||||
if (0 == payload) { payload = 256; }
|
||||
bool present = false;
|
||||
if (0 == payload) {
|
||||
payload = 255;
|
||||
present = true;
|
||||
} else {
|
||||
payload--;
|
||||
present = ValidModule(payload);
|
||||
}
|
||||
if (present) {
|
||||
Settings.last_module = Settings.module;
|
||||
Settings.module = payload;
|
||||
SetModuleType();
|
||||
|
@ -886,23 +893,21 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
|
|||
}
|
||||
restart_flag = 2;
|
||||
}
|
||||
}
|
||||
Response_P(S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str());
|
||||
}
|
||||
else if (CMND_MODULES == command_code) {
|
||||
for (uint8_t i = 0; i <= MAXMODULE; i++) {
|
||||
uint8_t midx = USER_MODULE;
|
||||
for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) {
|
||||
if (i > 0) { midx = pgm_read_byte(kModuleNiceList + i -1); }
|
||||
if (!jsflg) {
|
||||
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
|
||||
} else {
|
||||
ResponseAppend_P(PSTR(","));
|
||||
}
|
||||
jsflg = true;
|
||||
uint8_t j = i;
|
||||
if (0 == i) { j = USER_MODULE; } else { j--; }
|
||||
|
||||
// ResponseAppend_P(PSTR("\"%d (%s)\""), i, AnyModuleName(j).c_str());
|
||||
// if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == MAXMODULE)) {
|
||||
|
||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), i, AnyModuleName(j).c_str()) > (LOGSZ - TOPSZ)) || (i == MAXMODULE)) {
|
||||
uint8_t j = i ? midx +1 : 0;
|
||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), j, AnyModuleName(midx).c_str()) > (LOGSZ - TOPSZ)) || (i == sizeof(kModuleNiceList))) {
|
||||
ResponseAppend_P(PSTR("]}"));
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
|
||||
jsflg = false;
|
||||
|
@ -957,10 +962,6 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
|
|||
ResponseAppend_P(PSTR(","));
|
||||
}
|
||||
jsflg = true;
|
||||
|
||||
// ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames));
|
||||
// if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
||||
|
||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
||||
ResponseAppend_P(PSTR("]}"));
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
|
||||
|
@ -2324,9 +2325,11 @@ void GpioInit(void)
|
|||
{
|
||||
uint8_t mpin;
|
||||
|
||||
if ((Settings.module >= MAXMODULE) && (Settings.module < USER_MODULE)) {
|
||||
Settings.module = MODULE;
|
||||
Settings.last_module = MODULE;
|
||||
if (!ValidModule(Settings.module)) {
|
||||
uint8_t module = MODULE;
|
||||
if (!ValidModule(MODULE)) { module = SONOFF_BASIC; }
|
||||
Settings.module = module;
|
||||
Settings.last_module = module;
|
||||
}
|
||||
SetModuleType();
|
||||
|
||||
|
|
|
@ -596,7 +596,7 @@ const uint8_t kGpioNiceList[] PROGMEM = {
|
|||
#endif
|
||||
};
|
||||
|
||||
const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = {
|
||||
const uint8_t kModuleNiceList[] PROGMEM = {
|
||||
SONOFF_BASIC, // Sonoff Relay Devices
|
||||
SONOFF_RF,
|
||||
SONOFF_TH,
|
||||
|
|
|
@ -846,6 +846,16 @@ uint8_t ModuleNr()
|
|||
return (USER_MODULE == Settings.module) ? 0 : Settings.module +1;
|
||||
}
|
||||
|
||||
bool ValidModule(uint8_t index)
|
||||
{
|
||||
for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) {
|
||||
if (index == pgm_read_byte(kModuleNiceList + i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String AnyModuleName(uint8_t index)
|
||||
{
|
||||
if (USER_MODULE == index) {
|
||||
|
|
|
@ -1038,7 +1038,7 @@ void HandleTemplateConfiguration(void)
|
|||
|
||||
if (WebServer->hasArg("m")) {
|
||||
WSContentBegin(200, CT_PLAIN);
|
||||
for (uint8_t i = 0; i < MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||
for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||
uint8_t midx = pgm_read_byte(kModuleNiceList + i);
|
||||
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
|
||||
}
|
||||
|
@ -1159,7 +1159,7 @@ void HandleModuleConfiguration(void)
|
|||
if (WebServer->hasArg("m")) {
|
||||
WSContentBegin(200, CT_PLAIN);
|
||||
uint8_t vidx = 0;
|
||||
for (uint8_t i = 0; i <= MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||
for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||
if (0 == i) {
|
||||
midx = USER_MODULE;
|
||||
vidx = 0;
|
||||
|
|
Loading…
Reference in New Issue