Skip to content

Commit

Permalink
Fixes on MQTT output for multiple doors
Browse files Browse the repository at this point in the history
  • Loading branch information
matjack1 committed Oct 4, 2023
1 parent 37159db commit b3888e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/mqtt.esp
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,26 @@ void mqttPublishAccess(time_t accesstime, String const &isknown, String const &t
void mqttPublishAccess(time_t accesstime, String const &isknown, int types[MAX_NUM_RELAYS], String const &user, String const &uid)
{
DynamicJsonDocument root(512);
JsonArray access = root["access"].createNestedArray();
JsonArray doorNames = root["doorName"].createNestedArray();
JsonArray access = root.createNestedArray("access");
JsonArray doorNames = root.createNestedArray("doorName");
if (config.mqttEvents)
{
root["cmd"] = "log";
}

for (int i=0; i<MAX_NUM_RELAYS; i++) {
access.add(types[i]);
for (int i=0; i<config.numRelays; i++) {
switch (types[i])
{
case 0:
access.add("Disabled");
break;
case 1:
access.add("Always");
break;
case 99:
access.add("Admin");
break;
}
doorNames.add(config.doorName[i]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/rfid.esp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,11 @@ void rfidProcess()
{
if (currentRelay == 0) {
activateRelay[currentRelay] = true;
accountTypes[currentRelay] = json["acctype"];
} else {
bool isRelayActive = accountTypes[currentRelay] == ACCESS_GRANTED;
accountTypes[currentRelay] = json["acctype" + String(currentRelay + 1)];
activateRelay[currentRelay] = isRelayActive;
accountTypes[currentRelay] = json["acctype" + String(currentRelay + 1)];
}
if (processingState == validAdmin)
{
Expand Down

0 comments on commit b3888e3

Please sign in to comment.