Added password/ssid dotenv management in plateform io.

This commit is contained in:
Yohan Boujon 2023-11-26 14:50:41 +01:00
parent c9ad92c031
commit 0b63d99510
5 changed files with 31 additions and 2 deletions

1
embedded/.gitignore vendored
View file

@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json .vscode/c_cpp_properties.json
.vscode/launch.json .vscode/launch.json
.vscode/ipch .vscode/ipch
.env

View file

@ -17,3 +17,5 @@ lib_deps =
bbx10/DNSServer@^1.1.0 bbx10/DNSServer@^1.1.0
ArduinoJson ArduinoJson
olikraus/U8g2@^2.35.7 olikraus/U8g2@^2.35.7
extra_scripts =
pre:scripts/dotenv-var.py

4
embedded/readme.MD Normal file
View file

@ -0,0 +1,4 @@
# .env file
SSID_CLOVER='"SSID"'
PSWD_CLOVER='"PASSWORD"'

View file

@ -0,0 +1,14 @@
from os.path import isfile
Import("env")
assert isfile(".env")
try:
f = open(".env", "r")
lines = f.readlines()
envs = []
for line in lines:
envs.append("-D{}".format(line.strip()))
env.Append(BUILD_FLAGS=envs)
except IOError:
print("File .env not accessible",)
finally:
f.close()

View file

@ -7,6 +7,13 @@
#include "Component.hpp" #include "Component.hpp"
#include "Display.hpp" #include "Display.hpp"
#ifdef SSID_CLOVER
const char* ssid = SSID_CLOVER;
#endif
#ifdef PSWD_CLOVER
const char* pswd = PSWD_CLOVER;
#endif
DataHandler dataHandler; DataHandler dataHandler;
ServerHandler serverHandler(&dataHandler); // Référence à dataHandler ServerHandler serverHandler(&dataHandler); // Référence à dataHandler
Component humidity(ComponentType::Analog, PIN_A0); Component humidity(ComponentType::Analog, PIN_A0);
@ -15,16 +22,17 @@ Display screen;
void setup() void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
serverHandler.setup("Iphone de Nicole", "cesthonteux"); serverHandler.setup(ssid, pswd);
} }
void loop() void loop()
{ {
screen.loop(); screen.loop();
dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); dataHandler.updateTemperatureData(random(1800, 2200) / 100.0);
// 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940)
dataHandler.updateHumidityData(static_cast<float>(std::any_cast<int>(humidity.getValue()))); dataHandler.updateHumidityData(static_cast<float>(std::any_cast<int>(humidity.getValue())));
Serial.println(dataHandler.getJsonData()); Serial.println(dataHandler.getJsonData());
delay(1000); delay(1000);
serverHandler.loop(); serverHandler.loop();
} }