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 @@
/*****************************************************************
* 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.
#include "config.h" //TODO: Replace with just web_config
#include "web_config.h"
#include "csv_writer.h"
......
......@@ -67,7 +67,7 @@ void setup() {
web_config::initialize();
#ifdef AMPEL_WIFI
#ifdef AMPEL_WIFI // TODO: What to do with those? Replace with webconf::wifi_active?
web_config::setWifiConnectionCallback([]() {
//TODO: Move somewhere else
led_effects::showKITTWheel(color::green);
......@@ -113,7 +113,7 @@ void setup() {
csv_writer::initialize(ampel.sensorId);
#ifdef AMPEL_WIFI // Structure doesn't make sense anymore
#ifdef AMPEL_WIFI
wifi::defineCommands();
# ifdef AMPEL_HTTP
web_server::definePages();
......
......@@ -2,6 +2,7 @@
#if defined(ESP32)
#include "config.h" //TODO: Replace with just web_config
#include "led_effects.h"
#include "sensor_console.h"
#include "util.h"
......
#ifndef AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_
#include "config.h"
# if defined(ESP32)
#include <stdint.h> // For uint32_t & uint16_t
......
#include "mqtt.h"
#include "web_config.h"
#include "config.h"
#include "led_effects.h"
#include "sensor_console.h"
#include "wifi_util.h"
......@@ -121,7 +120,7 @@ namespace mqtt {
Serial.print(F("User:'"));
Serial.print(config::mqtt_user);
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(F("' ..."));
......@@ -201,7 +200,7 @@ namespace mqtt {
char payload[75]; // Should be enough for info json...
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);
}
......
......@@ -3,8 +3,6 @@
#include <stdint.h> // For uint32_t & uint16_t
#include "config.h"
namespace mqtt {
extern char last_successful_publish[];
extern bool connected;
......
......@@ -26,7 +26,7 @@ class Ampel {
private:
static void showFreeSpace();
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 *sensorId;
const char *macAddress;
......
......@@ -7,6 +7,10 @@
#endif
#include "config.h"
#ifndef MEASUREMENT_TIMESTEP
# error Missing config.h file. Please copy config.public.h to config.h.
#endif
#include "util.h"
#include "sensor_console.h"
......@@ -268,6 +272,11 @@ namespace web_config {
* Define all the corresponding config values as reference, so that they can be updated.
*/
namespace config {
char* current_ssid() {
return web_config::iotWebConf->getWifiSsidParameter()->valueBuffer;
}
// 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]
......
......@@ -10,6 +10,7 @@
#endif
namespace config {
char* current_ssid();
// Sensor
extern uint16_t &measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor).
extern uint16_t &altitude_above_sea_level; // [m]
......
#include "web_server.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 "ntp.h"
#include "wifi_util.h"
......@@ -96,16 +96,16 @@ namespace web_server {
"<tr><td>Humidity</td><td>%.1f%%</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><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>Timestep</td><td>%5d s</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>Last publish</td><td>%s</td></tr>\n"
"<tr><td>Timestep</td><td>%5d s</td></tr>\n"
#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>Frequency</td><td>%s MHz</td></tr>\n"
"<tr><td>Last transmission</td><td>%s</td></tr>\n"
......
#include "wifi_util.h"
#include "config.h"
#include "web_config.h"
#include "util.h"
#include "ntp.h"
#include "led_effects.h"
......@@ -12,18 +12,6 @@
# include <WiFi.h>
#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 {
char local_ip[16]; // "255.255.255.255\0"
......@@ -53,9 +41,9 @@ namespace wifi {
Serial.print(F("WiFi - Local IP : "));
Serial.println(wifi::local_ip);
Serial.print(F("WiFi - SSID : "));
Serial.println(WIFI_SSID);
Serial.println(config::current_ssid());
}
void defineCommands() {
sensor_console::defineCommand("wifi_scan", scanNetworks, F("(Scans available WiFi networks)"));
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