Commit 1a2aa6ff authored by Eric Duminil's avatar Eric Duminil
Browse files

Some refactor

parent 1575b514
Pipeline #5779 passed with stage
in 2 minutes and 7 seconds
...@@ -3,12 +3,10 @@ ...@@ -3,12 +3,10 @@
/***************************************************************** /*****************************************************************
* Libraries * * Libraries *
*****************************************************************/ *****************************************************************/
#include "config.h"
#ifndef MEASUREMENT_TIMESTEP
# error Missing config.h file. Please copy config.public.h to config.h.
#endif
//NOTE: Too many headers. Move them to include/ folder?
// Needed for offline config too. // Needed for offline config too.
#include "config.h" //TODO: Replace with just web_config
#include "web_config.h" #include "web_config.h"
#include "csv_writer.h" #include "csv_writer.h"
......
...@@ -67,7 +67,7 @@ void setup() { ...@@ -67,7 +67,7 @@ void setup() {
web_config::initialize(); web_config::initialize();
#ifdef AMPEL_WIFI #ifdef AMPEL_WIFI // TODO: What to do with those? Replace with webconf::wifi_active?
web_config::setWifiConnectionCallback([]() { web_config::setWifiConnectionCallback([]() {
//TODO: Move somewhere else //TODO: Move somewhere else
led_effects::showKITTWheel(color::green); led_effects::showKITTWheel(color::green);
...@@ -113,7 +113,7 @@ void setup() { ...@@ -113,7 +113,7 @@ void setup() {
csv_writer::initialize(ampel.sensorId); csv_writer::initialize(ampel.sensorId);
#ifdef AMPEL_WIFI // Structure doesn't make sense anymore #ifdef AMPEL_WIFI
wifi::defineCommands(); wifi::defineCommands();
# ifdef AMPEL_HTTP # ifdef AMPEL_HTTP
web_server::definePages(); web_server::definePages();
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#if defined(ESP32) #if defined(ESP32)
#include "config.h" //TODO: Replace with just web_config
#include "led_effects.h" #include "led_effects.h"
#include "sensor_console.h" #include "sensor_console.h"
#include "util.h" #include "util.h"
......
#ifndef AMPEL_LORAWAN_H_ #ifndef AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_ #define AMPEL_LORAWAN_H_
#include "config.h"
# if defined(ESP32) # if defined(ESP32)
#include <stdint.h> // For uint32_t & uint16_t #include <stdint.h> // For uint32_t & uint16_t
......
#include "mqtt.h" #include "mqtt.h"
#include "web_config.h" #include "web_config.h"
#include "config.h"
#include "led_effects.h" #include "led_effects.h"
#include "sensor_console.h" #include "sensor_console.h"
#include "wifi_util.h" #include "wifi_util.h"
...@@ -121,7 +120,7 @@ namespace mqtt { ...@@ -121,7 +120,7 @@ namespace mqtt {
Serial.print(F("User:'")); Serial.print(F("User:'"));
Serial.print(config::mqtt_user); Serial.print(config::mqtt_user);
Serial.print(F("' Password:'")); Serial.print(F("' Password:'"));
for (int i = 0; i < strlen(config::mqtt_password); ++i) { for (size_t i = 0; i < strlen(config::mqtt_password); ++i) {
Serial.print("*"); Serial.print("*");
} }
Serial.print(F("' ...")); Serial.print(F("' ..."));
...@@ -201,7 +200,7 @@ namespace mqtt { ...@@ -201,7 +200,7 @@ namespace mqtt {
char payload[75]; // Should be enough for info json... char payload[75]; // Should be enough for info json...
const char *json_info_format = PSTR("{\"local_ip\":\"%s\", \"ssid\":\"%s\"}"); const char *json_info_format = PSTR("{\"local_ip\":\"%s\", \"ssid\":\"%s\"}");
snprintf(payload, sizeof(payload), json_info_format, wifi::local_ip, WIFI_SSID); snprintf(payload, sizeof(payload), json_info_format, wifi::local_ip, config::current_ssid());
mqttClient.publish(info_topic, payload); mqttClient.publish(info_topic, payload);
} }
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
#include <stdint.h> // For uint32_t & uint16_t #include <stdint.h> // For uint32_t & uint16_t
#include "config.h"
namespace mqtt { namespace mqtt {
extern char last_successful_publish[]; extern char last_successful_publish[];
extern bool connected; extern bool connected;
......
...@@ -26,7 +26,7 @@ class Ampel { ...@@ -26,7 +26,7 @@ class Ampel {
private: private:
static void showFreeSpace(); static void showFreeSpace();
public: public:
const char *version = "v0.2.3-DEV"; // Update manually after significant changes. const char *version = "webconf-DEV"; // Update manually after significant changes.
const char *board; const char *board;
const char *sensorId; const char *sensorId;
const char *macAddress; const char *macAddress;
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#endif #endif
#include "config.h" #include "config.h"
#ifndef MEASUREMENT_TIMESTEP
# error Missing config.h file. Please copy config.public.h to config.h.
#endif
#include "util.h" #include "util.h"
#include "sensor_console.h" #include "sensor_console.h"
...@@ -268,6 +272,11 @@ namespace web_config { ...@@ -268,6 +272,11 @@ namespace web_config {
* Define all the corresponding config values as reference, so that they can be updated. * Define all the corresponding config values as reference, so that they can be updated.
*/ */
namespace config { namespace config {
char* current_ssid() {
return web_config::iotWebConf->getWifiSsidParameter()->valueBuffer;
}
// Sensor // Sensor
uint16_t &measurement_timestep = web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor). uint16_t &measurement_timestep = web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor).
uint16_t &altitude_above_sea_level = web_config::altitudeParam.value(); // [m] uint16_t &altitude_above_sea_level = web_config::altitudeParam.value(); // [m]
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#endif #endif
namespace config { namespace config {
char* current_ssid();
// Sensor // Sensor
extern uint16_t &measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor). extern uint16_t &measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor).
extern uint16_t &altitude_above_sea_level; // [m] extern uint16_t &altitude_above_sea_level; // [m]
......
#include "web_server.h" #include "web_server.h"
#include "web_config.h" #include "web_config.h"
#include "config.h" #include "config.h" // TODO: Remove once HTTP_USER and HTTP_PASSWORD are in web_config
#include "util.h" #include "util.h"
#include "ntp.h" #include "ntp.h"
#include "wifi_util.h" #include "wifi_util.h"
...@@ -96,16 +96,16 @@ namespace web_server { ...@@ -96,16 +96,16 @@ namespace web_server {
"<tr><td>Humidity</td><td>%.1f%%</td></tr>\n" "<tr><td>Humidity</td><td>%.1f%%</td></tr>\n"
"<tr><td>Last measurement</td><td>%s</td></tr>\n" "<tr><td>Last measurement</td><td>%s</td></tr>\n"
"<tr><td>Measurement timestep</td><td>%5d s</td></tr>\n" "<tr><td>Measurement timestep</td><td>%5d s</td></tr>\n"
"<tr><th colspan='2'>CSV</th></tr>\n" "<tr><th colspan='2'>CSV</th></tr>\n" //TODO: Gray out if !config::csv_active
"<tr><td>Last write</td><td>%s</td></tr>\n" "<tr><td>Last write</td><td>%s</td></tr>\n"
"<tr><td>Timestep</td><td>%5d s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n"
"<tr><td>Available drive space</td><td>%d kB</td></tr>\n" "<tr><td>Available drive space</td><td>%d kB</td></tr>\n"
"<tr><th colspan='2'>MQTT</th></tr>\n" "<tr><th colspan='2'>MQTT</th></tr>\n"//TODO: Gray out if !config::mqtt_active
"<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Connected?</td><td>%s</td></tr>\n"
"<tr><td>Last publish</td><td>%s</td></tr>\n" "<tr><td>Last publish</td><td>%s</td></tr>\n"
"<tr><td>Timestep</td><td>%5d s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n"
#if defined(ESP32) #if defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>\n" "<tr><th colspan='2'>LoRaWAN</th></tr>\n" //TODO: Gray out if !config::lora_active
"<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Connected?</td><td>%s</td></tr>\n"
"<tr><td>Frequency</td><td>%s MHz</td></tr>\n" "<tr><td>Frequency</td><td>%s MHz</td></tr>\n"
"<tr><td>Last transmission</td><td>%s</td></tr>\n" "<tr><td>Last transmission</td><td>%s</td></tr>\n"
......
#include "wifi_util.h" #include "wifi_util.h"
#include "config.h" #include "web_config.h"
#include "util.h" #include "util.h"
#include "ntp.h" #include "ntp.h"
#include "led_effects.h" #include "led_effects.h"
...@@ -12,18 +12,6 @@ ...@@ -12,18 +12,6 @@
# include <WiFi.h> # include <WiFi.h>
#endif #endif
namespace config {
// WiFi config. See 'config.h' if you want to modify those values.
const char *wifi_ssid = WIFI_SSID;
const char *wifi_password = WIFI_PASSWORD;
#ifdef WIFI_TIMEOUT
const uint8_t wifi_timeout = WIFI_TIMEOUT; // [s] Will try to connect during wifi_timeout seconds before failing.
#else
const uint8_t wifi_timeout = 60; // [s] Will try to connect during wifi_timeout seconds before failing.
#endif
}
namespace wifi { namespace wifi {
char local_ip[16]; // "255.255.255.255\0" char local_ip[16]; // "255.255.255.255\0"
...@@ -53,9 +41,9 @@ namespace wifi { ...@@ -53,9 +41,9 @@ namespace wifi {
Serial.print(F("WiFi - Local IP : ")); Serial.print(F("WiFi - Local IP : "));
Serial.println(wifi::local_ip); Serial.println(wifi::local_ip);
Serial.print(F("WiFi - SSID : ")); Serial.print(F("WiFi - SSID : "));
Serial.println(WIFI_SSID); Serial.println(config::current_ssid());
} }
void defineCommands() { void defineCommands() {
sensor_console::defineCommand("wifi_scan", scanNetworks, F("(Scans available WiFi networks)")); sensor_console::defineCommand("wifi_scan", scanNetworks, F("(Scans available WiFi networks)"));
sensor_console::defineCommand("local_ip", showLocalIp, F("(Displays local IP and current SSID)")); sensor_console::defineCommand("local_ip", showLocalIp, F("(Displays local IP and current SSID)"));
......
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