Provide last read rfid-id via webinterface.

This commit is contained in:
Simon Weidacher
2021-12-26 14:00:30 +01:00
parent 20412bbd9d
commit 7398e7d604
2 changed files with 18 additions and 10 deletions

View File

@@ -3,15 +3,16 @@
#include <esp_log.h> #include <esp_log.h>
#include <esp_err.h> #include <esp_err.h>
#include <esp_http_server.h> #include <esp_http_server.h>
#include <stdio.h>
#include "WebInterface.hpp" #include "WebInterface.hpp"
static const char* TAG = "rfid"; static const char* TAG = "rfid";
void tag_handler(uint8_t* sn) { // serial number is always 5 bytes long static char* lastTagId = (char*)malloc(26 * sizeof(char));
ESP_LOGI(TAG, "Tag: %#x %#x %#x %#x %#x",
sn[0], sn[1], sn[2], sn[3], sn[4] static char* getLastTagId() {
); return lastTagId;
} }
RFIDInterface::RFIDInterface() { RFIDInterface::RFIDInterface() {
@@ -20,7 +21,15 @@ RFIDInterface::RFIDInterface() {
.mosi_io = 25, .mosi_io = 25,
.sck_io = 23, .sck_io = 23,
.sda_io = 5, .sda_io = 5,
.callback = &tag_handler .callback = [](uint8_t* sn) { // serial number is always 5 bytes long
ESP_LOGI(TAG, "Tag: %#x %#x %#x %#x %#x",
sn[0], sn[1], sn[2], sn[3], sn[4]
);
sprintf(lastTagId, "%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]);
ESP_LOGI(TAG, "sprintf tag id: %s", lastTagId);
}
}; };
} }
@@ -32,12 +41,11 @@ void RFIDInterface::registerWebResources(WebInterface* interface) {
httpd_uri_t config = { httpd_uri_t config = {
.uri = "/rfid", .uri = "/rfid",
.method = HTTP_GET, .method = HTTP_GET,
.handler = [](httpd_req_t *req) { .handler = [](httpd_req_t *req) {
httpd_resp_send(req, "it's all fine!", HTTPD_RESP_USE_STRLEN); httpd_resp_send(req, getLastTagId(), HTTPD_RESP_USE_STRLEN);
return ESP_OK; return ESP_OK;
} }
}; };
interface->registerResource(&config); interface->registerResource(&config);
} }

View File

@@ -13,4 +13,4 @@ class RFIDInterface {
void registerWebResources(WebInterface* interface); void registerWebResources(WebInterface* interface);
}; };
#endif #endif