Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT delete topic doesn't work #10

Open
bad-gargoyle opened this issue Jul 14, 2022 · 9 comments
Open

MQTT delete topic doesn't work #10

bad-gargoyle opened this issue Jul 14, 2022 · 9 comments

Comments

@bad-gargoyle
Copy link

"status" topic and "learn" topic are working fine, but when I try to use "delete" topic, nothing happens (fingerprintId is still in sensor database).

Topic is: /fingerprint/espfingscan1/delete
Payload sended:
{
"fingerprintId":10
}

Please help.

@vinz486
Copy link
Owner

vinz486 commented Jul 14, 2022

Are you sure about the id? Maybe you recorded multiple times with same id?

@bad-gargoyle
Copy link
Author

Yes, I've checked via "TestDemo_V3.012" (app for testing R503) - application is showing that recorded id's are 10 and 11.
What do you mean by saying "Maybe you recorded multiple times with same id". That is possible, but as I see it, new finger record should overwrite the previous one.

@vinz486
Copy link
Owner

vinz486 commented Jul 14, 2022

So, deleting 10 and 11 is not working?

@bad-gargoyle
Copy link
Author

Unfortunately yes, but have in mind that those are only one recorded for now. So you may say that it doesn't work for any recorded ID's. You think that I should try to make records for other ID's and check, let's say, range of the problem?

@bad-gargoyle
Copy link
Author

And one more thing. I can ofcourse with success delete those ID's using "TestDemo_V3.012" (app for testing R503). ;-)

@vinz486
Copy link
Owner

vinz486 commented Jul 14, 2022

Never had this issue with my sensors.

@bad-gargoyle
Copy link
Author

bad-gargoyle commented Jul 14, 2022

It's not an sesnsors issue. In "setup.cpp" I think there is an error in this part of code (some prints added from my side to visualize problem):

void mqttConnect()
{
    if (!client.connected() && loopDelay(DELAY_CONNECT, 5000))
    {
        String topic;

        topic = "/fingerprint/";
        topic.concat(deviceGateId);
        topic.concat("/delete");
        deleteTopic[topic.length() + 1];
        topic.toCharArray(deleteTopic, topic.length() + 1);
        Serial.print("Delete topic: ");
        Serial.println(deleteTopic);

        topic = "/fingerprint/";
        topic.concat(deviceGateId);
        topic.concat("/learn");
Serial.printf("Test... deleteTopic %s\n", deleteTopic);
        learnTopic[topic.length() + 1];
        // char learnTopic[topic.length() + 1];
Serial.printf("Test... deleteTopic %s\n", deleteTopic);
        topic.toCharArray(learnTopic, topic.length() + 1);
Serial.printf("Test... deleteTopic %s\n", deleteTopic);
        Serial.print("Learn topic: ");
        Serial.println(learnTopic);

        topic = "/fingerprint/";
        topic.concat(deviceGateId);
        topic.concat("/available");
        char availableTopic[topic.length() + 1];
        topic.toCharArray(availableTopic, topic.length() + 1);
        Serial.print("Availability topic: ");
        Serial.println(availableTopic);

        Serial.print("Connecting to MQTT ");
        Serial.print(mqttHost);
        Serial.print("...");

        if (client.connect(HOSTNAME, mqttUsername, mqttPassword, availableTopic, 1, true, "offline"))
        {
            Serial.println("connected");

Serial.printf("deleteTopic... %s\n", deleteTopic);
Serial.printf("learnTopic... %s\n", learnTopic);
Serial.printf("availableTopic... %s\n", availableTopic);

            client.publish(availableTopic, "online");
            client.subscribe(learnTopic);
            client.subscribe(deleteTopic);

            led(LED_READY);
        }
        else
        {
            Serial.print("failed, rc: ");
            Serial.print(client.state());
            Serial.println(" waiting for retry.");
        }
    }
}

Output from serial console:

00:04:19.606 -> No need to save config
00:04:19.711 -> Message: Waiting...
00:04:19.711 -> {"message":"Waiting...","state":"wait","mode":"reading","match":false,"fingerprintId":0,"userId":0,"confidence":0,"gate":"espfingscan1"}
00:04:19.849 -> Delete topic: /fingerprint/espfingscan1/delete
00:04:19.919 -> Test... deleteTopic /fingerprint/espfingscan1/delete
00:04:19.989 -> Test... deleteTopic /fingerprint/espfingscan1/delete
00:04:20.024 -> Test... deleteTopic /fingerprint/espfingscan1/delete/fingerprint/espfingscan1/learn
00:04:20.125 -> Learn topic: /fingerprint/espfingscan1/learn
00:04:20.160 -> Availability topic: /fingerprint/espfingscan1/available
00:04:20.229 -> Connecting to MQTT 192.168.1.1...connected
00:04:20.297 -> deleteTopic... /fingerprint/espfingscan1/delete/fingerprint/espfingscan1/learn
00:04:20.366 -> learnTopic... /fingerprint/espfingscan1/learn
00:04:20.401 -> availableTopic... /fingerprint/espfingscan1/available

That results with registering wrong "delete" topic ("deleteTopic = /fingerprint/espfingscan1/delete/fingerprint/espfingscan1/learn") on MQTT and propper topic "/fingerprint/espfingscan1/delete" just won't work.

@vinz486
Copy link
Owner

vinz486 commented Jul 18, 2022

Thank you. I will check (in my spare time).

@bad-gargoyle
Copy link
Author

Great project, by the way. That is what my OpenHAB system was missing. ;-) Thanks!

And by the way... For now, when that issue still persist, if someone still want to make "delete" topic work, you should use as "delete" topic this whole fraze ("/fingerprint/espfingscan1/delete/fingerprint/espfingscan1/learn"), and that's it. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants