Commit f25fcc79 authored by Eric Duminil's avatar Eric Duminil
Browse files

Time can be set in AP mode

parent edff02c4
Pipeline #5878 passed with stage
in 2 minutes and 23 seconds
......@@ -91,6 +91,8 @@ void setup() {
csv_writer::initialize(config::ampel_name());
ntp::initialize();
if (config::is_wifi_on) {
wifi::defineCommands();
web_server::definePages();
......@@ -166,7 +168,7 @@ void wifiConnected() {
snprintf(wifi::local_ip, sizeof(wifi::local_ip), "%d.%d.%d.%d", address[0], address[1], address[2], address[3]);
Serial.println(wifi::local_ip);
ntp::initialize();
ntp::connect();
if (config::is_mqtt_active()) {
mqtt::initialize(ampel.sensorId);
......
......@@ -12,14 +12,18 @@ namespace ntp {
bool connected_at_least_once = false;
void setLocalTime(int32_t unix_seconds);
// Should be defined, even offline
void initialize() {
timeClient.setPoolServerName(config::ntp_server);
timeClient.setTimeOffset((config::time_zone + config::daylight_saving_time) * 3600);
sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F("1618829570 (Sets time to the given UNIX time)"));
}
void connect(){
timeClient.setPoolServerName(config::ntp_server);
timeClient.setUpdateInterval(60000UL);
Serial.print("NTP - Trying to connect to : ");
Serial.println(config::ntp_server);
timeClient.begin();
sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F("1618829570 (Sets time to the given UNIX time)")); //TODO: Define even without internet
}
void update() {
......
......@@ -3,6 +3,7 @@
namespace ntp {
void initialize();
void connect();
void update();
void getLocalTime(char *timestamp);
}
......
......@@ -118,6 +118,7 @@ namespace web_server {
"<form action='/delete_csv' method='POST' onsubmit=\"return confirm('Are you really sure you want to delete all data?') && (document.body.style.cursor = 'wait');\">"
"<input type='submit' value='Delete CSV'/>"
"</form>"
"<button onclick=\"fetch('/command?send=set_time '+Math.floor(Date.now()/1000))\" %s>Set time!</button>" // Can be useful in AP mode
"</div>"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-firmware' target='_blank'>Source code</a>&nbsp;"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-documentation' target='_blank'>Documentation</a>");
......@@ -230,7 +231,7 @@ namespace web_server {
config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", config::ampel_name(),
config::ampel_name(), wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(),
esp_get_max_free_block_size(), esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board,
ampel.sensorId, ampel.version, dd, hh, mm, ss);
ampel.sensorId, ampel.version, dd, hh, mm, ss, wifi::isAccessPoint() ? "" : "hidden");
Serial.print(F(" - Body2 size : "));
Serial.print(strlen(content));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment