From eba0ea8a89498c841d2e9b72d088c521249f14d9 Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Thu, 31 Aug 2023 20:12:49 +0200 Subject: [PATCH] simple http call to test the led flasher --- ESP32_AP-Flasher/include/commstructs.h | 16 ++++++++ ESP32_AP-Flasher/src/web.cpp | 53 +++++++++++++++++++++++++- tag_types.h | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/ESP32_AP-Flasher/include/commstructs.h b/ESP32_AP-Flasher/include/commstructs.h index 9aef661b..6e6f2b4f 100644 --- a/ESP32_AP-Flasher/include/commstructs.h +++ b/ESP32_AP-Flasher/include/commstructs.h @@ -126,4 +126,20 @@ struct tagsettings { uint8_t fixedChannel; // default 0; if set to a valid channel number, the tag will stick to that channel } __packed; +struct ledFlash { + uint8_t mode : 4; + uint8_t flashDuration : 4; + uint8_t color1; + uint8_t flashCount1 : 4; + uint8_t delay1 : 4; + uint8_t color2; + uint8_t flashCount2 : 4; + uint8_t delay2 : 4; + uint8_t color3; + uint8_t flashCount3 : 4; + uint8_t delay3 : 4; + uint8_t repeats; + uint8_t spare; +} __packed; + #pragma pack(pop) \ No newline at end of file diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index 612b0f07..78a95cde 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -320,9 +320,11 @@ void init_web() { if (strcmp(cmdValue, "deepsleep") == 0) { sendTagCommand(mac, CMD_DO_DEEPSLEEP, !taginfo->isExternal); } + if (strcmp(cmdValue, "ledflash") == 0) { + } request->send(200, "text/plain", "Ok, done"); } else { - request->send(200, "text/plain", "Error: mac not found"); + request->send(400, "text/plain", "Error: mac not found"); } } } else { @@ -330,6 +332,55 @@ void init_web() { } }); + server.on("/led_flash", HTTP_GET, [](AsyncWebServerRequest *request) { + // color picker: https://roger-random.github.io/RGB332_color_wheel_three.js/ + // http GET to /led_flash?mac=000000000000&pattern=3/0x1C,4,5/0xE0,3,1/0x4F,5,10/5 + // (flashDuration/color1,flashCount1,delay1/color2,flashCount2,delay2/color3,flashCount3,delay3/repeats) + if (request->hasParam("mac")) { + String dst = request->getParam("mac")->value(); + uint8_t mac[8]; + if (hex2mac(dst, mac)) { + tagRecord *taginfo = tagRecord::findByMAC(mac); + if (taginfo != nullptr) { + if (request->hasParam("pattern")) { + String pattern = request->getParam("pattern")->value(); + struct ledFlash flashData; + + int values[13]; + int numValues = sscanf( + pattern.c_str(), + "%i/%i,%i,%i/%i,%i,%i/%i,%i,%i/%i", + &values[1], &values[2], &values[3], &values[4], &values[5], + &values[6], &values[7], &values[8], &values[9], &values[10], &values[11]); + + if (numValues != 11) { + request->send(400, "text/plain", "Error: wrong number of inputs in pattern"); + return; + } else { + flashData.mode = 0; + flashData.flashDuration = values[1] & 0x0F; + flashData.color1 = values[2]; + flashData.flashCount1 = values[3] & 0x0F; + flashData.delay1 = values[4] & 0x0F; + flashData.color2 = values[5]; + flashData.flashCount2 = values[6] & 0x0F; + flashData.delay2 = values[7] & 0x0F; + flashData.color3 = values[8]; + flashData.flashCount3 = values[9] & 0x0F; + flashData.delay3 = values[10] & 0x0F; + flashData.repeats = values[11]; + flashData.spare = 0; + + const uint8_t *payload = reinterpret_cast(&flashData); + sendTagCommand(mac, CMD_DO_LEDFLASH, !taginfo->isExternal, payload); + } + } + } + } + } + request->send(400, "text/plain", "parameters are missing"); + }); + server.on("/get_ap_config", HTTP_GET, [](AsyncWebServerRequest *request) { UDPcomm udpsync; udpsync.getAPList(); diff --git a/tag_types.h b/tag_types.h index 7b79349d..69434912 100755 --- a/tag_types.h +++ b/tag_types.h @@ -56,6 +56,7 @@ #define CMD_DO_SCAN 1 #define CMD_DO_RESET_SETTINGS 2 #define CMD_DO_DEEPSLEEP 3 +#define CMD_DO_LEDFLASH 4 #define WAKEUP_REASON_TIMED 0 #define WAKEUP_REASON_GPIO 2