Sesame-Device/src/main.cpp
2024-04-20 17:47:44 +02:00

78 lines
2.0 KiB
C++

/**
* Sesame-Device
* Christoph Hagen, 2022.
*
* The code for a simple door unlock mechanism where a servo pushes on an existing
* physical button.
*
* On compile error:
*
* In <Server.h>
*
* change:
* virtual void begin(uint16_t port=0) =0;
* to:
* virtual void begin() =0;
*/
#include <Arduino.h>
#include "message.h"
#include "server.h"
#include "servo.h"
#include "controller.h"
#include "config.h"
SesameController controller{};
void setup() {
Serial.begin(serialBaudRate);
Serial.setDebugOutput(true);
Serial.println("[INFO] Device started");
ServoConfiguration servoConfig {
.pwmTimer = pwmTimer,
.pwmFrequency = servoFrequency,
.pin = servoPin,
.openDuration = lockOpeningDuration,
.pressedValue = servoPressedState,
.releasedValue = servoReleasedState,
};
ServerConfiguration serverConfig {
.url = serverUrl,
.port = serverPort,
.path = serverPath,
.key = serverAccessKey,
.reconnectTime = 5000,
.socketHeartbeatIntervalMs = socketHeartbeatIntervalMs,
.socketHeartbeatTimeoutMs = socketHeartbeatTimeoutMs,
.socketHeartbeatFailureReconnectCount = socketHeartbeatFailureReconnectCount,
};
EthernetConfiguration ethernetConfig {
.macAddress = ethernetMacAddress,
.spiPinMiso = spiPinMiso,
.spiPinMosi = spiPinMosi,
.spiPinSclk = spiPinSclk,
.spiPinSS = spiPinSS,
.dhcpLeaseTimeoutMs = dhcpLeaseTimeoutMs,
.dhcpLeaseResponseTimeoutMs = dhcpLeaseResponseTimeoutMs,
.manualIp = manualIpAddress,
.manualDnsAddress = manualDnsServerAddress,
.udpPort = localUdpPort,
};
KeyConfiguration keyConfig {
.remoteKey = remoteKey,
.localKey = localKey,
.challengeExpiryMs = challengeExpiryMs,
};
controller.configure(servoConfig, serverConfig, ethernetConfig, keyConfig);
}
void loop() {
uint32_t time = millis();
controller.loop(time);
}