🧼 Removes ntp
This commit is contained in:
@@ -25,12 +25,6 @@ build_flags =
|
||||
-D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\"
|
||||
-D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\"
|
||||
|
||||
; NTP settings
|
||||
-D FACTORY_NTP_ENABLED=true
|
||||
-D FACTORY_NTP_TIME_ZONE_LABEL=\"Europe/London\"
|
||||
-D FACTORY_NTP_TIME_ZONE_FORMAT=\"GMT0BST,M3.5.0/1,M10.5.0\"
|
||||
-D FACTORY_NTP_SERVER=\"time.google.com\"
|
||||
|
||||
; OTA settings
|
||||
-D FACTORY_OTA_PORT=8266
|
||||
-D FACTORY_OTA_PASSWORD=\"spot-leika\"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
[features]
|
||||
build_flags =
|
||||
-D USE_NTP=1
|
||||
-D USE_SLEEP=0
|
||||
-D USE_UPLOAD_FIRMWARE=1
|
||||
-D USE_DOWNLOAD_FIRMWARE=0
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <event_socket.h>
|
||||
#include <features.h>
|
||||
#include <MotionService.h>
|
||||
#include <ntp_service.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <task_manager.h>
|
||||
#include <WiFi.h>
|
||||
@@ -77,9 +76,6 @@ class Spot {
|
||||
WiFiService _wifiService;
|
||||
APService _apService;
|
||||
EventSocket _socket;
|
||||
#if FT_ENABLED(USE_NTP)
|
||||
NTPService _ntpService;
|
||||
#endif
|
||||
#if FT_ENABLED(USE_UPLOAD_FIRMWARE)
|
||||
FirmwareUploadService _uploadFirmwareService;
|
||||
#endif
|
||||
|
||||
+25299
-26936
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@ static const char *TAG = "APService";
|
||||
|
||||
APService::APService()
|
||||
: endpoint(APSettings::read, APSettings::update, this),
|
||||
_persistence(APSettings::read, APSettings::update, this, NTP_SETTINGS_FILE) {
|
||||
_persistence(APSettings::read, APSettings::update, this, AP_SETTINGS_FILE) {
|
||||
addUpdateHandler([&](const String &originId) { reconfigureAP(); }, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace feature_service {
|
||||
|
||||
void features(JsonObject &root) {
|
||||
root["ntp"] = USE_NTP;
|
||||
root["upload_firmware"] = USE_UPLOAD_FIRMWARE;
|
||||
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
|
||||
root["sleep"] = USE_SLEEP;
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
|
||||
#define FT_ENABLED(feature) feature
|
||||
|
||||
// ntp feature on by default
|
||||
#ifndef USE_NTP
|
||||
#define USE_NTP 1
|
||||
#endif
|
||||
|
||||
// upload firmware feature off by default
|
||||
#ifndef USE_UPLOAD_FIRMWARE
|
||||
#define USE_UPLOAD_FIRMWARE 0
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#define AP_SETTINGS_FILE "/config/apSettings.json"
|
||||
#define CAMERA_SETTINGS_FILE "/config/cameraSettings.json"
|
||||
#define FS_CONFIG_DIRECTORY "/config"
|
||||
#define NTP_SETTINGS_FILE "/config/ntpSettings.json"
|
||||
#define DEVICE_CONFIG_FILE "/config/peripheral.json"
|
||||
#define WIFI_SETTINGS_FILE "/config/wifiSettings.json"
|
||||
#define SERVO_SETTINGS_FILE "/config/servoSettings.json"
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
#include <ntp_service.h>
|
||||
|
||||
static const char *TAG = "NPT Service";
|
||||
|
||||
NTPService::NTPService()
|
||||
: endpoint(NTPSettings::read, NTPSettings::update, this),
|
||||
_persistence(NTPSettings::read, NTPSettings::update, this, NTP_SETTINGS_FILE) {
|
||||
addUpdateHandler([&](const String &originId) { configureNTP(); }, false);
|
||||
}
|
||||
|
||||
void NTPService::begin() {
|
||||
WiFi.onEvent(std::bind(&NTPService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
||||
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
|
||||
WiFi.onEvent(std::bind(&NTPService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
|
||||
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
|
||||
_persistence.readFromFS();
|
||||
configureNTP();
|
||||
}
|
||||
|
||||
/*
|
||||
* Formats the time using the format provided.
|
||||
*
|
||||
* Uses a 25 byte buffer, large enough to fit an ISO time string with offset.
|
||||
*/
|
||||
const char *formatTime(const tm *time, const char *format) {
|
||||
static char time_string[25];
|
||||
strftime(time_string, sizeof(time_string), format, time);
|
||||
return time_string;
|
||||
}
|
||||
|
||||
const char *toUTCTimeString(const tm *time) { return formatTime(time, "%FT%TZ"); }
|
||||
|
||||
const char *toLocalTimeString(const tm *time) { return formatTime(time, "%FT%T"); }
|
||||
|
||||
esp_err_t NTPService::getStatus(PsychicRequest *request) {
|
||||
PsychicJsonResponse response = PsychicJsonResponse(request, false);
|
||||
JsonObject root = response.getRoot();
|
||||
|
||||
// grab the current instant in unix seconds
|
||||
time_t now = time(nullptr);
|
||||
|
||||
// only provide enabled/disabled status for now
|
||||
root["status"] = sntp_enabled() ? 1 : 0;
|
||||
|
||||
// the current time in UTC
|
||||
root["utc_time"] = toUTCTimeString(gmtime(&now));
|
||||
|
||||
// local time with offset
|
||||
root["local_time"] = toLocalTimeString(localtime(&now));
|
||||
|
||||
// the sntp server name
|
||||
root["server"] = sntp_getservername(0);
|
||||
|
||||
// device uptime in seconds
|
||||
root["uptime"] = millis() / 1000;
|
||||
|
||||
return response.send();
|
||||
}
|
||||
|
||||
void NTPService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
ESP_LOGI(TAG, "Got IP address, starting NTP Synchronization");
|
||||
configureNTP();
|
||||
}
|
||||
|
||||
void NTPService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
ESP_LOGD(TAG, "WiFi connection dropped, stopping NTP.");
|
||||
configureNTP();
|
||||
}
|
||||
|
||||
void NTPService::configureNTP() {
|
||||
if (WiFi.isConnected() && _state.enabled) {
|
||||
ESP_LOGI(TAG, "Starting NTP...");
|
||||
configTzTime(_state.tzFormat.c_str(), _state.server.c_str());
|
||||
} else {
|
||||
setenv("TZ", _state.tzFormat.c_str(), 1);
|
||||
tzset();
|
||||
sntp_stop();
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t NTPService::handleTime(PsychicRequest *request, JsonVariant &json) {
|
||||
if (!sntp_enabled() && json.is<JsonObject>()) {
|
||||
struct tm tm = {0};
|
||||
String timeLocal = json["local_time"];
|
||||
char *s = strptime(timeLocal.c_str(), "%Y-%m-%dT%H:%M:%S", &tm);
|
||||
if (s != nullptr) {
|
||||
time_t time = mktime(&tm);
|
||||
struct timeval now = {.tv_sec = time};
|
||||
settimeofday(&now, nullptr);
|
||||
return request->reply(200);
|
||||
}
|
||||
}
|
||||
return request->reply(400);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef NTPService_h
|
||||
#define NTPService_h
|
||||
|
||||
#include <filesystem.h>
|
||||
#include <template/stateful_persistence.h>
|
||||
#include <WiFi.h>
|
||||
#include <template/stateful_endpoint.h>
|
||||
#include <settings/ntp_settings.h>
|
||||
|
||||
#include <lwip/apps/sntp.h>
|
||||
#include <time.h>
|
||||
|
||||
class NTPService : public StatefulService<NTPSettings> {
|
||||
public:
|
||||
NTPService();
|
||||
|
||||
void begin();
|
||||
static esp_err_t getStatus(PsychicRequest *request);
|
||||
static esp_err_t handleTime(PsychicRequest *request, JsonVariant &json);
|
||||
|
||||
StatefulHttpEndpoint<NTPSettings> endpoint;
|
||||
|
||||
private:
|
||||
FSPersistence<NTPSettings> _persistence;
|
||||
|
||||
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
void configureNTP();
|
||||
};
|
||||
|
||||
#endif // end NTPService_h
|
||||
@@ -55,18 +55,6 @@ void Spot::setupServer() {
|
||||
return _apService.endpoint.handleStateUpdate(request, json);
|
||||
});
|
||||
|
||||
// NTP
|
||||
#if FT_ENABLED(USE_NTP)
|
||||
_server->on("/api/ntp/status", HTTP_GET, [this](PsychicRequest *r) { return _ntpService.getStatus(r); });
|
||||
_server->on("/api/ntp/time", HTTP_POST,
|
||||
[this](PsychicRequest *r, JsonVariant &json) { return _ntpService.handleTime(r, json); });
|
||||
_server->on("/api/ntp/settings", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _ntpService.endpoint.getState(request); });
|
||||
_server->on("/api/ntp/settings", HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) {
|
||||
return _ntpService.endpoint.handleStateUpdate(request, json);
|
||||
});
|
||||
#endif
|
||||
|
||||
// CAMERA
|
||||
_server->on("/api/camera/still", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _cameraService.cameraStill(request); });
|
||||
@@ -180,9 +168,6 @@ void Spot::startServices() {
|
||||
_apService.begin();
|
||||
#if FT_ENABLED(USE_UPLOAD_FIRMWARE)
|
||||
_uploadFirmwareService.begin();
|
||||
#endif
|
||||
#if FT_ENABLED(USE_NTP)
|
||||
_ntpService.begin();
|
||||
#endif
|
||||
_peripherals.begin();
|
||||
_servoController.begin();
|
||||
|
||||
Reference in New Issue
Block a user