Add local server option
This commit is contained in:
30
include/base64.h
Normal file
30
include/base64.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef UTILITY_BASE64_H_
|
||||
#define UTILITY_BASE64_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief Base64 encode function.
|
||||
*
|
||||
* @param[in] *data Pointer to data that will be encoded.
|
||||
* @param[in] data_length Data length.
|
||||
* @param[out] *result Pointer to result, encoded data.
|
||||
* @param[in] max_result_length Maximum result length.
|
||||
*
|
||||
* @return 0 = success, in case of fail value different than 0 is returned.
|
||||
*/
|
||||
int32_t Base64_encode(const char* data, size_t data_length, char* result, size_t max_result_length);
|
||||
|
||||
/**
|
||||
* @brief Base64 decode function.
|
||||
*
|
||||
* @param[in] *in Pointer to data that will be decoded.
|
||||
* @param[in] in_len Input data length.
|
||||
* @param[out] *out Pointer to result data, decoded data.
|
||||
* @param[in] max_out_len Maximum output length.
|
||||
*
|
||||
* @return 0 = success, in case of fail value different than 0 is returned.
|
||||
*/
|
||||
int32_t Base64_decode(const char* in, size_t in_len, uint8_t* out, size_t max_out_len);
|
||||
|
||||
#endif /* UTILITY_BASE64_H_ */
|
@ -40,9 +40,20 @@ constexpr const char* wifiSSID = "MyWiFi";
|
||||
// The WiFi password to connect to the above network
|
||||
constexpr const char* wifiPassword = "00000000";
|
||||
|
||||
// The name of the device on the network
|
||||
constexpr const char* networkName = "Sesame-Device";
|
||||
|
||||
// The interval to reconnect to WiFi if the connection is broken
|
||||
constexpr uint32_t wifiReconnectInterval = 10000;
|
||||
|
||||
/* Local server */
|
||||
|
||||
// The port for the local server to directly receive messages over WiFi
|
||||
constexpr uint16_t localPort = 80;
|
||||
|
||||
// The url parameter to send the message to the local server
|
||||
constexpr char messageUrlParameter[] = "m";
|
||||
|
||||
|
||||
/* Server */
|
||||
|
||||
|
@ -84,4 +84,26 @@ typedef struct {
|
||||
|
||||
#define MESSAGE_CONTENT_SIZE sizeof(Message)
|
||||
|
||||
#define AUTHENTICATED_MESSAGE_SIZE sizeof(AuthenticatedMessage)
|
||||
#define AUTHENTICATED_MESSAGE_SIZE sizeof(AuthenticatedMessage)
|
||||
|
||||
/**
|
||||
* An event signaled from the device
|
||||
*/
|
||||
enum class SesameEvent {
|
||||
TextReceived = 1,
|
||||
UnexpectedSocketEvent = 2,
|
||||
InvalidMessageData = 3,
|
||||
MessageAuthenticationFailed = 4,
|
||||
MessageTimeMismatch = 5,
|
||||
MessageCounterInvalid = 6,
|
||||
MessageAccepted = 7,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A callback for messages received over the socket
|
||||
*
|
||||
* The first parameter is the received message.
|
||||
* The second parameter is the response to the remote.
|
||||
* The return value is the type of event to respond with.
|
||||
*/
|
||||
typedef SesameEvent (*MessageCallback)(AuthenticatedMessage*, AuthenticatedMessage*);
|
@ -6,28 +6,6 @@
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <WebSocketsClient.h>
|
||||
|
||||
/**
|
||||
* An event signaled from the device
|
||||
*/
|
||||
enum class SesameEvent {
|
||||
TextReceived = 1,
|
||||
UnexpectedSocketEvent = 2,
|
||||
InvalidMessageData = 3,
|
||||
MessageAuthenticationFailed = 4,
|
||||
MessageTimeMismatch = 5,
|
||||
MessageCounterInvalid = 6,
|
||||
MessageAccepted = 7,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A callback for messages received over the socket
|
||||
*
|
||||
* The first parameter is the received message.
|
||||
* The second parameter is the response to the remote.
|
||||
* The return value is the type of event to respond with.
|
||||
*/
|
||||
typedef SesameEvent (*MessageCallback)(AuthenticatedMessage*, AuthenticatedMessage*);
|
||||
|
||||
class ServerConnection {
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user