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

Adding NTP param

parent 7109e2ab
...@@ -75,6 +75,7 @@ void setup() { ...@@ -75,6 +75,7 @@ void setup() {
Serial.print(F("WiFi - Connected! IP address: ")); Serial.print(F("WiFi - Connected! IP address: "));
IPAddress address = WiFi.localIP(); IPAddress address = WiFi.localIP();
snprintf(wifi::local_ip, sizeof(wifi::local_ip), "%d.%d.%d.%d", address[0], address[1], address[2], address[3]); 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::initialize();
...@@ -82,7 +83,6 @@ void setup() { ...@@ -82,7 +83,6 @@ void setup() {
mqtt::initialize(ampel.sensorId); mqtt::initialize(ampel.sensorId);
# endif # endif
Serial.println(wifi::local_ip);
Serial.print(F("You can access this sensor via http://")); Serial.print(F("You can access this sensor via http://"));
Serial.print(ampel.sensorId); Serial.print(ampel.sensorId);
Serial.print(F(".local (might be unstable) or http://")); Serial.print(F(".local (might be unstable) or http://"));
......
...@@ -30,7 +30,7 @@ const int NEOPIXELS_PIN = 5; ...@@ -30,7 +30,7 @@ const int NEOPIXELS_PIN = 5;
const int NEOPIXELS_PIN = 23; const int NEOPIXELS_PIN = 23;
#endif #endif
// config::led_count is not yet known // config::led_count is not yet known, will be set later.
Adafruit_NeoPixel pixels(0, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel pixels(0, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800);
namespace led_effects { namespace led_effects {
......
#include "ntp.h" #include "ntp.h"
#include "sensor_console.h" #include "sensor_console.h"
#include "config.h" #include "config.h"
#include "web_config.h"
#include <WiFiUdp.h> // required for NTP #include <WiFiUdp.h> // required for NTP
#include "src/lib/NTPClient/NTPClient.h" // NTP #include "src/lib/NTPClient/NTPClient.h" // NTP
namespace config { namespace config {
const char *ntp_server = NTP_SERVER;
const long utc_offset_in_seconds = UTC_OFFSET_IN_SECONDS; // UTC+1 const long utc_offset_in_seconds = UTC_OFFSET_IN_SECONDS; // UTC+1
} }
...@@ -18,6 +18,8 @@ namespace ntp { ...@@ -18,6 +18,8 @@ namespace ntp {
void setLocalTime(int32_t unix_seconds); void setLocalTime(int32_t unix_seconds);
void initialize() { void initialize() {
Serial.print("NTP - Trying to connect to : ");
Serial.println(config::ntp_server);
timeClient.begin(); timeClient.begin();
sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F("1618829570 (Sets time to the given UNIX time)")); sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F("1618829570 (Sets time to the given UNIX time)"));
} }
......
...@@ -118,7 +118,7 @@ namespace web_config { ...@@ -118,7 +118,7 @@ namespace web_config {
Builder<TextTParameter<STRING_LEN>>("mqtt_user").label("MQTT User").defaultValue(MQTT_USER).build(); Builder<TextTParameter<STRING_LEN>>("mqtt_user").label("MQTT User").defaultValue(MQTT_USER).build();
//TODO: Show the number of * for password? //TODO: Show the number of * for password?
PasswordTParameter<STRING_LEN> mqttPasswordParam = Builder<PasswordTParameter< STRING_LEN>>("mqtt_password").label( PasswordTParameter<STRING_LEN> mqttPasswordParam = Builder<PasswordTParameter<STRING_LEN>>("mqtt_password").label(
"MQTT password").defaultValue(MQTT_PASSWORD).build(); "MQTT password").defaultValue(MQTT_PASSWORD).build();
/** /**
...@@ -127,7 +127,7 @@ namespace web_config { ...@@ -127,7 +127,7 @@ namespace web_config {
ParameterGroup timeParams = ParameterGroup("NTP", "Time server"); ParameterGroup timeParams = ParameterGroup("NTP", "Time server");
TextTParameter<STRING_LEN> ntpParam = TextTParameter<STRING_LEN> ntpParam =
Builder<TextTParameter< STRING_LEN>>("ntp_server").label("NTP Server").defaultValue(NTP_SERVER).build(); Builder<TextTParameter<STRING_LEN>>("ntp_server").label("NTP Server").defaultValue(NTP_SERVER).build();
IntTParameter<int16_t> timeOffsetParam = Builder<IntTParameter<int16_t>>("timezone").label("Timezone").defaultValue( IntTParameter<int16_t> timeOffsetParam = Builder<IntTParameter<int16_t>>("timezone").label("Timezone").defaultValue(
(UTC_OFFSET_IN_SECONDS) / 3600).min(-23).max(23).step(1).placeholder("[h]").build(); (UTC_OFFSET_IN_SECONDS) / 3600).min(-23).max(23).step(1).placeholder("[h]").build();
CheckboxTParameter dstParam = CheckboxTParameter dstParam =
...@@ -280,7 +280,11 @@ namespace config { ...@@ -280,7 +280,11 @@ namespace config {
bool &auto_calibrate_sensor = web_config::autoCalibrateParam.value(); // [true / false] bool &auto_calibrate_sensor = web_config::autoCalibrateParam.value(); // [true / false]
float &temperature_offset = web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant. float &temperature_offset = web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant.
// LEDs
uint8_t &max_brightness = web_config::maxBrightnessParam.value(); uint8_t &max_brightness = web_config::maxBrightnessParam.value();
uint8_t &min_brightness = web_config::minBrightnessParam.value(); uint8_t &min_brightness = web_config::minBrightnessParam.value();
uint16_t &led_count = web_config::ledCountParam.value(); uint16_t &led_count = web_config::ledCountParam.value();
char *ntp_server = web_config::ntpParam.value();
int16_t &time_zone = web_config::timeOffsetParam.value();
} }
...@@ -23,6 +23,9 @@ namespace config { ...@@ -23,6 +23,9 @@ namespace config {
extern uint8_t &max_brightness; extern uint8_t &max_brightness;
extern uint8_t &min_brightness; extern uint8_t &min_brightness;
extern uint16_t &led_count; extern uint16_t &led_count;
extern char *ntp_server;
extern int16_t &time_zone;
} }
namespace web_config { namespace web_config {
......
Markdown is supported
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