Mercurial > code > home > repos > homeauto
changeset 1742:1c1b38b145f8
rm custom cpp fingerprint driver that's under the wrong name 'desk'
author | drewp@bigasterisk.com |
---|---|
date | Fri, 01 Sep 2023 17:15:25 -0700 |
parents | 097bfd91187d |
children | daf9deee42ca |
files | espNode/desk/platformio.ini espNode/desk/src/display.cpp espNode/desk/src/display.h espNode/desk/src/fingerprint.cpp espNode/desk/src/fingerprint.h espNode/desk/src/main.cpp espNode/desk/src/mqtt.cpp espNode/desk/src/mqtt.h espNode/desk/src/wifi.cpp espNode/desk/src/wifi.h |
diffstat | 10 files changed, 0 insertions(+), 865 deletions(-) [+] |
line wrap: on
line diff
--- a/espNode/desk/platformio.ini Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:ttgo-t1] -platform = espressif32 -; board = ttgo-t1 -board = esp32dev -framework = arduino -upload_port = /dev/ttyUSB0 -upload_protocol = esptool -upload_speed = 921600 -monitor_port = /dev/ttyUSB0 -monitor_speed = 115200 - -build_flags = - -Os - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG - -DUSER_SETUP_LOADED=1 - -DST7789_DRIVER=1 - -DTFT_WIDTH=135 - -DTFT_HEIGHT=240 - -DCGRAM_OFFSET=1 - -DTFT_MISO=-1 - -DTFT_MOSI=19 - -DTFT_SCLK=18 - -DTFT_CS=5 - -DTFT_DC=16 - -DTFT_RST=23 - -DTFT_BL=4 - -DTFT_BACKLIGHT_ON=1 - -DLOAD_GLCD=1 - -DLOAD_FONT2=1 - -DLOAD_FONT4=1 - -DLOAD_FONT6=1 - -DLOAD_FONT7=1 - -DLOAD_FONT8=1 - -DLOAD_GFXFF=1 - -DSMOOTH_FONT=1 - -DSPI_FREQUENCY=40000000 - -DSPI_READ_FREQUENCY=6000000 - -lib_deps = - TFT_eSPI@1.4.21 - Button2@1.0.0 - https://github.com/brianrho/FPM - AsyncMqttClient@0.8.2
--- a/espNode/desk/src/display.cpp Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#include "display.h" - -#include <TFT_eSPI.h> -#include <Wire.h> - -// see https://github.com/JakubAndrysek/TTGO_T_Display - -namespace display { - -TFT_eSPI tft(135, 240); - -void Setup() { - tft.init(); - tft.fontHeight(2); - tft.setRotation(1); - tft.fillScreen(TFT_BLACK); -} - -void Message(std::string msg) { - tft.drawString(msg.c_str(), tft.width() / 4, tft.height() / 2, - 4); // string,start x,start y, font weight {1;2;4;6;7;8} -} - -} \ No newline at end of file
--- a/espNode/desk/src/display.h Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#ifndef INCLUDED_DISPLAY -#define INCLUDED_DISPLAY -#include <string> - -#ifndef TFT_DISPOFF -#define TFT_DISPOFF 0x28 -#endif - -#ifndef TFT_SLPIN -#define TFT_SLPIN 0x10 -#endif - -namespace display { -void Setup(); -void Message(std::string msg); -} // namespace display -#endif \ No newline at end of file
--- a/espNode/desk/src/fingerprint.cpp Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,455 +0,0 @@ -#include "fingerprint.h" - -#include <string> -#include <vector> - -#include "mqtt.h" - -namespace fingerprint { - -HardwareSerial fserial(1); -FPM finger(&fserial); - -constexpr uint8_t led_red = 0x01, led_blue = 0x02, led_purple = 0x03; -constexpr uint8_t led_breathe = 0x01, led_flash = 0x02, led_on = 0x03, - led_off = 0x04, led_gradual_on = 0x05, led_gradual_off = 0x06; -constexpr uint8_t led_fast = 0x30, led_medium = 0x60, led_slow = 0x80; -constexpr uint8_t led_forever = 0; - -FPM_System_Params params; - -void BlinkNotConnected() { - finger.led_control(led_flash, led_fast, led_red, led_forever); -} -void BlinkConnected() { - finger.led_control(led_flash, led_fast, led_red, /*times=*/1); -} -void BlinkProgress() { - finger.led_control(led_flash, led_fast, led_blue, /*times=*/1); -} -void BlinkSuccess() { - finger.led_control(led_breathe, led_medium, led_purple, led_forever); -} -void BlinkClearSuccess() { - finger.led_control(led_breathe, led_medium, led_purple, /*times=*/1); -} -void BlinkError() { - finger.led_control(led_flash, led_medium, led_red, /*times=*/3); - delay(500); -} -void BlinkStartEnroll() { - finger.led_control(led_flash, led_slow, led_blue, led_forever); -} -void BlinkStartEnrollRepeat() { - finger.led_control(led_flash, led_medium, led_blue, led_forever); -} -void BlinkClearEnroll() { - finger.led_control(led_flash, led_slow, led_blue, /*times=*/1); -} - -void (*queued)() = nullptr; -void QueueBlinkConnected() { queued = BlinkConnected; } -void ExecuteAnyQueued() { - if (queued) { - queued(); - queued = nullptr; - } -} -namespace { -bool NeedToGetBackToMainLoopSoon() { - return mqtt::HasPendingMessage() || queued; -} - -void LogStatus(const std::string& log_mode, const std::string& msg) { - mqtt::Publish(log_mode + "/status", msg); -} -void LogError(const std::string& log_mode, const std::string& caller, - const std::string& err) { - mqtt::Publish(log_mode + "/error/" + caller, err); -} -void LogStore(const std::string& msg) { mqtt::Publish("store", msg); } -void LogDetect(const std::string& msg) { mqtt::Publish("detected", msg); } - -void PublishModel(uint16_t fid, char* model, size_t model_len) { - std::string msg(model, model_len); - char subtopic[50]; - snprintf(subtopic, sizeof(subtopic), "model/%d", fid); - mqtt::Publish(subtopic, msg); -} - -void PublishImage(char* image_data, size_t image_len) { - std::string msg(image_data, image_len); - char subtopic[50]; - snprintf(subtopic, sizeof(subtopic), "image/%d", -1); - mqtt::Publish(subtopic, msg); -} - -void LogFpmError(const std::string& log_mode, const std::string& caller, - int16_t p) { - std::string errStr; - switch (p) { - case FPM_FEATUREFAIL: - errStr = "Could not find fingerprint features"; - break; - case FPM_IMAGEFAIL: - errStr = "Imaging error"; - break; - case FPM_IMAGEMESS: - errStr = "Image too messy"; - break; - case FPM_INVALIDIMAGE: - errStr = "Could not find fingerprint features"; - break; - case FPM_NOTFOUND: - errStr = "Did not find a match"; - break; - case FPM_PACKETRECIEVEERR: - errStr = "Communication error"; - break; - case FPM_READ_ERROR: - errStr = "Got wrong PID or length"; - break; - case FPM_BADLOCATION: - errStr = "Could not store/delete in that location"; - break; - case FPM_FLASHERR: - errStr = "Error writing to flash"; - break; - case FPM_TIMEOUT: - errStr = "Timeout"; - break; - case FPM_ENROLLMISMATCH: - errStr = "Fingerprints did not match"; - break; - case FPM_UPLOADFAIL: - errStr = "Cannot transfer the image"; - break; - case FPM_DBREADFAIL: - errStr = "Invalid model"; - break; - case FPM_DBCLEARFAIL: - errStr = "Could not clear database"; - break; - default: - char buf[100]; - snprintf(buf, sizeof(buf), "Unknown error (%d)", p); - errStr = buf; - break; - } - LogError(log_mode, caller, errStr); -} - -bool GetImage(const std::string& log_mode) { - int16_t p = -1; - LogStatus(log_mode, "Waiting for valid finger"); - - while (p != FPM_OK) { - p = finger.getImage(); - - if (p == FPM_OK) { - LogStatus(log_mode, "Image taken"); - } else if (p == FPM_NOFINGER) { - if (NeedToGetBackToMainLoopSoon()) { - return false; - } - } else { - LogFpmError(log_mode, "getImage", p); - return false; - } - yield(); - } - LogStatus(log_mode, "Got image"); - - BlinkProgress(); - return true; -} - -bool ConvertImage(const std::string& log_mode, uint8_t slot = 1) { - int16_t p = -1; - p = finger.image2Tz(slot); - if (p == FPM_OK) { - LogStatus(log_mode, "Image converted"); - } else { - LogFpmError(log_mode, "image2Tz", p); - return false; - } - return true; -} - -bool SearchDatabase(const std::string& log_mode, uint16_t* fid, - uint16_t* score) { - int16_t p = -1; - p = finger.searchDatabase(fid, score); - - /* now wait to remove the finger, though not necessary; - this was moved here after the search because of the R503 sensor, - which seems to wipe its buffers after each scan */ - LogStatus(log_mode, "Waiting for finger removal"); - while (finger.getImage() != FPM_NOFINGER) { - delay(500); - } - - if (p != FPM_OK) { - LogFpmError(log_mode, "searchDatabase", p); - - if (p == FPM_NOTFOUND) { - BlinkError(); - } - return false; - } - return true; -} - -void ReportFoundMatch(uint16_t fid, uint16_t score) { - char msg[100]; - snprintf(msg, sizeof(msg), "Found id %d confidence %d", fid, score); - LogDetect(msg); -} -} // namespace -void ScanLoop() { - const std::string& log_mode = "scan"; - if (!GetImage(log_mode)) { - return; - } - - if (!ConvertImage(log_mode)) { - return; - } - - uint16_t fid, score; - if (!SearchDatabase(log_mode, &fid, &score)) { - return; - } - - ReportFoundMatch(fid, score); -} -namespace { -bool get_free_id(const std::string& log_mode, int16_t* fid) { - int16_t p = -1; - for (int page = 0; page < (params.capacity / FPM_TEMPLATES_PER_PAGE) + 1; - page++) { - p = finger.getFreeIndex(page, fid); - if (p != FPM_OK) { - LogFpmError(log_mode, "getFreeIndex", p); - return false; - } - if (*fid != FPM_NOFREEINDEX) { - char buf[100]; - snprintf(buf, sizeof(buf), "Free slot at id %d", *fid); - LogStatus(log_mode, buf); - return true; - } - yield(); - } - LogStatus(log_mode, "getFreeIndex: No free slots"); - return false; -} - -void WaitForRemove(const std::string& log_mode) { - int16_t p = -1; - LogStatus(log_mode, "Remove finger"); - delay(2000); - p = 0; - while (p != FPM_NOFINGER) { - p = finger.getImage(); - yield(); - } -} - -void EnrollFailed(const std::string& log_mode) { - LogStatus(log_mode, "Exiting enroll"); - BlinkError(); - WaitForRemove(log_mode); -} - -void enroll_finger(const std::string& log_mode, int16_t fid) { - int16_t p = -1; - LogStatus(log_mode, "Waiting for valid finger to enroll"); - BlinkStartEnroll(); - if (!GetImage(log_mode)) { - return EnrollFailed(log_mode); - } - - if (!ConvertImage(log_mode, 1)) { - return EnrollFailed(log_mode); - } - - WaitForRemove(log_mode); - - BlinkStartEnrollRepeat(); - LogStatus(log_mode, "Place same finger again"); - if (!GetImage(log_mode)) { - return EnrollFailed(log_mode); - } - if (!ConvertImage(log_mode, 2)) { - return EnrollFailed(log_mode); - } - - p = finger.createModel(); - if (p == FPM_OK) { - LogStatus(log_mode, "Prints matched"); - } else { - LogFpmError(log_mode, "createModel", p); - return EnrollFailed(log_mode); - } - - p = finger.storeModel(fid); - if (p == FPM_OK) { - char buf[100]; - snprintf(buf, sizeof(buf), "Stored as id %d", fid); - LogStore(buf); - BlinkSuccess(); - WaitForRemove(log_mode); - BlinkClearSuccess(); - return; - } else { - LogFpmError(log_mode, "storeModel", p); - return EnrollFailed(log_mode); - } -} -} // namespace -void Enroll() { - const std::string log_mode = "enroll"; - BlinkStartEnroll(); - LogStatus(log_mode, "Searching for a free slot to store the template..."); - int16_t fid; - if (!get_free_id(log_mode, &fid)) { - BlinkError(); - return; - } - enroll_finger(log_mode, fid); -} - -// a GetImage image must be in the buffer to get the real bitmap image -void DownloadLastImage(const std::string& log_mode) { - LogStatus(log_mode, "Starting image stream"); - finger.downImage(); - std::vector<char> image(256 * 288 / 2); - size_t image_pos = 0; - bool read_complete = false; - uint16_t read_len; - - while (true) { - read_len = image.size() - image_pos; - if (!finger.readRaw(FPM_OUTPUT_TO_BUFFER, image.data() + image_pos, - &read_complete, &read_len)) { - LogFpmError(log_mode, "readRaw", -1); - return; - } - image_pos += read_len; - if (read_complete) { - break; - } - } - size_t image_len = image_pos; - - char buf[100]; - snprintf(buf, sizeof(buf), "Got %d bytes to download", image_len); - LogStatus(log_mode, buf); - - PublishImage(image.data(), image_len); -} - -void DownloadModel(uint16_t fid) { - const std::string log_mode = "download"; - int p = -1; - LogStatus(log_mode, "Retrieve model for download"); - p = finger.loadModel(fid); - if (p != FPM_OK) { - LogFpmError(log_mode, "loadModel", p); - return; - } - p = finger.downloadModel(fid); - if (p != FPM_OK) { - LogFpmError(log_mode, "downloadModel", p); - return; - } - char model[2048]; // expect 1536 bytes - size_t model_pos = 0; - bool read_complete = false; - uint16_t read_len; - while (true) { - read_len = sizeof(model) - model_pos; - if (!finger.readRaw(FPM_OUTPUT_TO_BUFFER, model + model_pos, &read_complete, - &read_len)) { - LogFpmError(log_mode, "readRaw", -1); - return; - } - model_pos += read_len; - if (read_complete) { - break; - } - } - size_t model_len = model_pos; - char buf[100]; - - snprintf(buf, sizeof(buf), "Got %d bytes to download", model_len); - LogStatus(log_mode, buf); - - PublishModel(fid, model, model_len); -} - -void SetModel(uint16_t fid, const std::vector<uint8_t>& payload) { - const std::string log_mode = "setModel"; - int16_t p = -1; - LogStatus(log_mode, "Upload buffer to slot 1"); - - p = finger.uploadModel(); - if (p != FPM_OK) { - LogFpmError(log_mode, "uploadModel", p); - return; - } - yield(); - finger.writeRaw(const_cast<uint8_t*>(payload.data()), payload.size()); - delay( - 100); // load-bearing sleep. Without this, the storeModel doesn't answer. - - LogStatus(log_mode, "Store model from slot 1 to fid"); - p = finger.storeModel(fid); - if (p != FPM_OK) { - LogFpmError(log_mode, "storeModel", p); - return; - } - char buf[100]; - snprintf(buf, sizeof(buf), "SetModel successful for id %d", fid); - LogStore(buf); -} - -void DeleteModel(uint16_t fid) { - const std::string log_mode = "deleteModel"; - int16_t p = finger.deleteModel(fid); - if (p == FPM_OK) { - char msg[100]; - snprintf(msg, sizeof(msg), "Deleted id %d", fid); - LogStore(msg); - } else { - LogFpmError(log_mode, "deleteModel", p); - } -} - -void DeleteAll() { - int16_t p = finger.emptyDatabase(); - if (p == FPM_OK) { - LogStore("Database cleared"); - } else { - LogFpmError("deleteAll", "emptyDatabase", p); - } -} - -void Setup() { - fserial.begin(57600, SERIAL_8N1, 26 /*rx*/, 27 /*tx*/); - - if (finger.begin()) { - finger.readParams(¶ms); - Serial.println("Found fingerprint sensor!"); - Serial.print("Capacity: "); - Serial.println(params.capacity); - Serial.print("Packet length: "); - Serial.println(FPM::packet_lengths[params.packet_len]); - } else { - Serial.println("Did not find fingerprint sensor :("); - while (1) yield(); - } - BlinkNotConnected(); -} -} // namespace fingerprint \ No newline at end of file
--- a/espNode/desk/src/fingerprint.h Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#ifndef INCLUDED_FINGERPRINT -#define INCLUDED_FINGERPRINT -#include <FPM.h> -#include <HardwareSerial.h> - -#include <vector> - -namespace fingerprint { -void Setup(); -void ExecuteAnyQueued(); -void BlinkProgress(); -void BlinkNotConnected(); -void BlinkConnected(); -void QueueBlinkConnected(); // for inside an ISR -void BlinkSuccess(); -void BlinkClearSuccess(); -void ScanLoop(); -void Enroll(); -void DownloadLastImage(); -void DownloadModel(uint16_t fid); -void DeleteAll(); -void DeleteModel(uint16_t fid); -void SetModel(uint16_t fid, const std::vector<uint8_t>& payload); - -} // namespace fingerprint -#endif \ No newline at end of file
--- a/espNode/desk/src/main.cpp Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -#include <Arduino.h> - -#include <string> - -#include "display.h" -#include "fingerprint.h" -#include "mqtt.h" -#include "wifi.h" - -#define ADC_EN 14 -#define ADC_PIN 34 - -// #include <Button2.h> -// #define BUTTON_1 35 -// #define BUTTON_2 0 - -void setup() { - Serial.begin(115200); - Serial.println("Serial.begin"); - - fingerprint::Setup(); // go early since the others display status on our LED - display::Setup(); - display::Message("Hello world"); - wifi::Setup(); - mqtt::Setup(); -} - -namespace { -uint16_t LastComponentNumber(const std::string &s) { - return atoi(s.substr(s.rfind("/") + 1).c_str()); -} -} // namespace - -void HandleCommand(const std::string &payload_string) { - if (payload_string == "enroll") { - fingerprint::Enroll(); - } else if (payload_string == "show_success") { - fingerprint::BlinkSuccess(); - while (!mqtt::HasPendingMessage()) yield(); - mqtt::PopPendingMessage(); - // hope it's "clear_success", but who cares - fingerprint::BlinkClearSuccess(); - } else if (payload_string == "delete_all") { - fingerprint::DeleteAll(); - } else if (payload_string.rfind("delete/model/", 0) == 0) { - uint16_t fid = LastComponentNumber(payload_string); - fingerprint::DeleteModel(fid); - } else if (payload_string.rfind("get/model/", 0) == 0) { - uint16_t fid = LastComponentNumber(payload_string); - fingerprint::DownloadModel(fid); - } -} - -void loop() { - Serial.println("--loop--"); - - fingerprint::ExecuteAnyQueued(); - - fingerprint::ScanLoop(); - - if (mqtt::HasPendingMessage()) { - std::pair<std::string, std::vector<byte>> msg = mqtt::PopPendingMessage(); - const std::string &topic = msg.first; - const std::vector<byte> &payload = msg.second; - - if (topic == "fingerprint/command") { - const std::string payload_string(payload.begin(), payload.end()); - HandleCommand(payload_string); - } else if (topic.rfind("fingerprint/set/model/", 0) == 0) { - uint16_t fid = LastComponentNumber(topic); - - fingerprint::SetModel(fid, payload); - } - } -}
--- a/espNode/desk/src/mqtt.cpp Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -#include "mqtt.h" - -#include "config.h" -#include "fingerprint.h" -#include "wifi.h" - -namespace mqtt { -AsyncMqttClient mqttClient; -TimerHandle_t mqttReconnectTimer; - -#define MAX_INCOMING_PAYLOAD 1536 -class IncomingMessage { - public: - bool complete; - std::string topic; - std::vector<byte> payload; -}; -IncomingMessage incomingMessage; - -void StopTimer() { - xTimerStop(mqttReconnectTimer, - 0); // ensure we don't reconnect to MQTT while reconnecting - // to Wi-Fi -} -/* - -Subscribed by MCU: - -fingerprint/command = - 'enroll' - | 'show_success' - | 'clear_success' - | 'delete_all' - | 'delete/model/<fid>' - | 'get/model/<fid>' -fingerprint/set/model/<fid> = binary model data - -Published from MCU: - -mode in {scan, enroll, download, setModel, deleteModel} - -fingerprint/<mode>/status = junk -fingerprint/<mode>/error/<caller> = FPM error message -fingerprint/store = some change to fingerprint storage -fingerprint/detect = input finger -fingerprint/model/<fid> = binary model data -fingerprint/image/<fid> = binary image data -fingerprint/temperature = "%.3fC" -*/ -void Publish(const std::string& subtopic, const std::string& msg) { - std::string topic = "fingerprint/" + subtopic; - mqttClient.publish(topic.c_str(), 1, /*retain=*/false, msg.data(), - msg.size()); -} - -void ConnectToMqtt() { - Serial.println("Connecting to MQTT..."); - mqttClient.connect(); -} - -void SendTemperature() { - float temp_c = temperatureRead(); - char buf[20]; - snprintf(buf, sizeof(buf), "%.3fC", temp_c); - mqttClient.publish("fingerprint/temperature", 1, /*retain=*/true, buf); -} - -void onMqttConnect(bool sessionPresent) { - Serial.println("Connected to MQTT."); - Serial.print("Session present: "); - Serial.println(sessionPresent); - - mqttClient.subscribe("fingerprint/command", 1); - mqttClient.subscribe("fingerprint/set/#", 1); - - SendTemperature(); - - mqttClient.setWill("fingerprint/status", 1, /*retain=*/true, "offline"); - mqttClient.publish("fingerprint/status", 1, /*retain=*/true, "online"); - - Serial.println("queuing a blink change"); - fingerprint::QueueBlinkConnected(); -} - -void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) { - Serial.println("Disconnected from MQTT."); - fingerprint::BlinkNotConnected(); - - if (wifi::IsConnected()) { - xTimerStart(mqttReconnectTimer, 0); - } -} - -void onMqttMessage(char* topic, char* payload, - AsyncMqttClientMessageProperties properties, size_t len, - size_t index, size_t total) { - if (index == 0) { - incomingMessage.complete = false; - incomingMessage.topic = std::string(topic); - incomingMessage.payload.clear(); - } - - for (int i = 0; i < len; i++) { - incomingMessage.payload.push_back(payload[i]); - } - - if (index + len == total) { - incomingMessage.complete = true; - } -} - -// Don't do command right away; wait for main loop to ask for it. -bool HasPendingMessage() { return incomingMessage.complete; } -std::pair<std::string, std::vector<byte>> PopPendingMessage() { - std::pair<std::string, std::vector<byte>> ret{incomingMessage.topic, - incomingMessage.payload}; - incomingMessage.complete = false; - return ret; -} - -void Setup() { - mqttReconnectTimer = - xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, - reinterpret_cast<TimerCallbackFunction_t>(ConnectToMqtt)); - - mqttClient.onConnect(onMqttConnect); - mqttClient.onDisconnect(onMqttDisconnect); - mqttClient.onMessage(onMqttMessage); - mqttClient.setServer(MQTT_HOST, MQTT_PORT); -} - -} // namespace mqtt
--- a/espNode/desk/src/mqtt.h Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#ifndef INCLUDED_MQTT -#define INCLUDED_MQTT -#include <AsyncMqttClient.h> - -#include <string> - -// #include "esp_adc_cal.h" - -extern "C" { -#include "freertos/FreeRTOS.h" -#include "freertos/timers.h" -} - -namespace mqtt { - -void Setup(); -void Publish(const std::string& subtopic, const std::string& msg); -void StopTimer(); -void ConnectToMqtt(); -bool HasPendingMessage(); -std::pair<std::string /*topic*/, std::vector<byte> /*payload*/> PopPendingMessage(); - -} // namespace mqtt -#endif \ No newline at end of file
--- a/espNode/desk/src/wifi.cpp Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -#include "wifi.h" - -#include "config.h" -#include "mqtt.h" -#include "fingerprint.h" - -namespace wifi { - -TimerHandle_t wifiReconnectTimer; -namespace { -void connectToWifi() { - Serial.println("Connecting to Wi-Fi..."); - fingerprint::BlinkNotConnected(); - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); -} -void WiFiEvent(WiFiEvent_t event) { - Serial.printf("[WiFi-event] event: %d\n", event); - switch (event) { - case SYSTEM_EVENT_STA_GOT_IP: - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - mqtt::ConnectToMqtt(); - break; - case SYSTEM_EVENT_STA_DISCONNECTED: - Serial.println("WiFi lost connection"); - mqtt::StopTimer(); - xTimerStart(wifiReconnectTimer, 0); - break; - default: - // ?? - break; - } -} -} // namespace -void Setup() { - wifiReconnectTimer = - xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, - reinterpret_cast<TimerCallbackFunction_t>(connectToWifi)); - - WiFi.onEvent(WiFiEvent); - connectToWifi(); -} -bool IsConnected() { return WiFi.isConnected(); } -} // namespace wifi \ No newline at end of file
--- a/espNode/desk/src/wifi.h Fri Sep 01 17:14:25 2023 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#ifndef INCLUDED_WIFI -#define INCLUDED_WIFI - -#include "WiFi.h" -extern "C" { -#include "freertos/FreeRTOS.h" -#include "freertos/timers.h" -} - -namespace wifi { -void Setup(); -bool IsConnected(); -} // namespace wifi -#endif \ No newline at end of file