Use local UDP messages instead of web server

This commit is contained in:
Christoph Hagen
2024-04-20 17:47:44 +02:00
parent 4a88d1a380
commit 1504ce6b0c
5 changed files with 70 additions and 40 deletions

View File

@ -28,4 +28,6 @@ struct EthernetConfiguration {
// The IP address of the DNS server, if DHCP fails
uint8_t manualDnsAddress[4];
// The port for the incoming UDP connection
uint16_t udpPort;
};

View File

@ -3,14 +3,13 @@
#include "server.h"
#include "servo.h"
#include "message.h"
#include <ESPAsyncWebServer.h>
#include "configurations/EthernetConfiguration.h"
#include "configurations/KeyConfiguration.h"
class SesameController: public ServerConnectionCallbacks {
public:
SesameController(uint16_t localWebServerPort);
SesameController();
void configure(ServoConfiguration servoConfig, ServerConfiguration serverConfig, EthernetConfiguration ethernetConfig, KeyConfiguration keyConfig);
@ -22,7 +21,16 @@ private:
ServerConnection server;
ServoController servo;
AsyncWebServer localWebServer;
// UDP
// buffers for receiving and sending data
char udpReceiveBuffer[SIGNED_MESSAGE_SIZE]; // buffer to hold incoming packet
// An EthernetUDP instance to send and receive packets over UDP
EthernetUDP Udp;
EthernetConfiguration ethernetConfig;
bool ethernetIsConfigured = false;
@ -52,7 +60,7 @@ private:
// MARK: Local client callbacks
void handleLocalMessage(AsyncWebServerRequest *request);
void checkLocalMessage();
// MARK: Socket Callbacks
@ -76,7 +84,7 @@ private:
*
* Note: Prepares the response in the outgoing message buffer.
*/
void processMessage(SignedMessage* message);
void processMessage(SignedMessage* message, bool shouldPerformUnlock);
/**
* @brief Checks that the message is valid and prepares a challenge.
@ -105,7 +113,7 @@ private:
*
* Note: Prepares the response in the outgoing message buffer.
*/
void completeUnlockRequest(Message* message);
void completeUnlockRequest(Message* message, bool shouldPerformUnlock);
// MARK: Responses
@ -117,12 +125,18 @@ private:
*/
void prepareResponseBuffer(MessageResult event, Message* message = NULL);
/**
* @brief Read a message from the UDP port
*
*/
bool readLocalMessage();
/**
* @brief Send the prepared outgoing message to a locally connected client
*
* @param request The original request of the client
*/
void sendPreparedLocalResponse(AsyncWebServerRequest *request);
void sendPreparedLocalResponse();
/**
* @brief Send the prepared outgoing message to the server
@ -131,5 +145,5 @@ private:
// MARK: Helper
bool convertHexMessageToBinary(const char* str);
bool convertHexMessageToBinary(const char* str);
};