Skip to content

Commit

Permalink
v47.0 (#123)
Browse files Browse the repository at this point in the history
* CHANGE: wait for reconfig is now default disable
* ADD: ntp client (#120)
* ADD: Timebased dimmer (#121)
* FIX: go setup mode if startup wifi connection failed
* CHANGE: move to littlefs (esp32)
  • Loading branch information
yakumo-saki authored Jan 23, 2023
1 parent 65cd2c4 commit 69e8cd6
Show file tree
Hide file tree
Showing 49 changed files with 531 additions and 358 deletions.
1 change: 1 addition & 0 deletions cloc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c:\usr\ols\bin\cloc --exclude-dir=.pio,.vscode,_release,.github . --by-file-by-lang
Empty file modified cloc.sh
100644 → 100755
Empty file.
Empty file modified create_release.sh
100644 → 100755
Empty file.
Empty file modified devel_web.sh
100644 → 100755
Empty file.
60 changes: 54 additions & 6 deletions embed/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ <h1>EnvBoyX Settings (settingID: <span replace="settingId">EBXCFG.vXX</span>)</h

<div class="setupModeOnly notice" hidden>
<p>セットアップモードです。</p>
<p>一度設定を保存して再起動すると通常モードに移行します。</p>
<p>初回設定時はWiFi設定を入力して保存することで通常モードに移行します。</p>
<p>誤ってセットアップモードに移行した場合は一度設定を保存して再起動すると通常モードに移行します。</p>
</div>

<form method='post'>
Expand Down Expand Up @@ -48,6 +49,52 @@ <h1>EnvBoyX Settings (settingID: <span replace="settingId">EBXCFG.vXX</span>)</h
MQTTモード(間欠動作・MQTT送信後ディープスリープ・非推奨)
</label><br>
</fieldset>


<fieldset>
<legend>時刻関連設定</legend>
<strong>NTPサーバー設定</strong><br>
NTPサーバーを使用しない場合、時刻関係の機能は動作しません。<br>
<label>
<input type='radio' name='ntp' value='no' id='ntp__no'>
使用しない
</label><br>
<label>
<input type='radio' name='ntp' value='yes' id='ntp__yes'>
使用する
</label><br>
<br>

<strong>NTPサーバーのIPアドレス</strong><br>
<input type='text' name='ntpAddress' placeholder='IP Address' id='ntpAddress'><br>
<br>

<strong>タイムゾーン</strong><br>
<p><a href="https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h">有効なタイムゾーン一覧</a></p>
<input type='text' name='ntpTimezone' placeholder='timezone'><br>
<br>

<strong>時刻によるディスプレイ自動消灯</strong><br>
<label>
<input type='radio' name='ntpAutoDimmer' value='no' id='ntpAutoDimmer__no'>
使用しない
</label><br>
<label>
<input type='radio' name='ntpAutoDimmer' value='yes' id='ntpAutoDimmer__yes'>
使用する
</label><br>
<br>

<strong>時刻によるディスプレイ自動消灯時刻</strong><br>
指定した時刻の間、ディスプレイを消灯します。<br>
<input type="time" name='ntpAutoDimmerStart' id='ntpAutoDimmerStart'>
&nbsp;~&nbsp;
<input type="time" name='ntpAutoDimmerEnd' id='ntpAutoDimmerEnd'>
<br>

</fieldset>


<fieldset>
<legend>表示デバイス共通設定</legend>
<strong>画面反転</strong><br>
Expand All @@ -67,18 +114,18 @@ <h1>EnvBoyX Settings (settingID: <span replace="settingId">EBXCFG.vXX</span>)</h

<strong>Wait for reconfigure画面</strong><br>
※ 起動時にセットアップモードに入るための待ち時間を追加します。<br>
v46以降、セットアップモードに意図的に入る必要はほぼありません。<br>

<label>
<input type='radio' name='displayWaitForReconfigure' value='skip' id='displayWaitForReconfigure__skip'>
表示しない(推奨)
</label><br>
<label>
<input type='radio' name='displayWaitForReconfigure' value='on' id='displayWaitForReconfigure__on'>
表示する
</label><br>


<label>
<input type='radio' name='displayWaitForReconfigure' value='skip' id='displayWaitForReconfigure__skip'>
表示しない(推奨)
</label><br>

<strong>自動消灯する明るさ(暗いと判定するしきい値)</strong><br>
<span>※ 光量センサーがない場合は自動的に無効になります。</span><br>
<span>※ 自動消灯を使用しない場合は、999999を入力してください。</span><br>
Expand Down Expand Up @@ -131,6 +178,7 @@ <h1>EnvBoyX Settings (settingID: <span replace="settingId">EBXCFG.vXX</span>)</h
縦表示モード(デカ文字)
</label><br>
</fieldset>

<fieldset>
<legend>MH-Z19B デバイス設定</legend>
<strong>MH-Z19B CO2センサー有無(金色のセンサー)</strong><br>
Expand Down
4 changes: 2 additions & 2 deletions examples/curl-example.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
curl -X POST -d "mDNS=ebx32&opMode=always&displayFlip=yes&displayBrightness=50&oledType=SSD&st7789=yes&st7789Mode=st7789_normal&mhz19b=no&mhz19bPwmPin=14&mhz19bRxPin=32&mhz19bTxPin=33&mqttBroker=&mqttName=&tempAlerts=&tempAlerts.warn1.L=-99&tempAlerts.warn1.H=10&tempAlerts.warn2.L=10&tempAlerts.warn2.H=40&tempAlerts.caut1.L=10&tempAlerts.caut1.H=15&tempAlerts.caut2.L=28&tempAlerts.caut2.H=30&humiAlerts.warn1.L=0&humiAlerts.warn1.H=20&humiAlerts.warn2.L=75&humiAlerts.warn2.H=100&humiAlerts.caut1.L=20&humiAlerts.caut1.H=35&humiAlerts.caut2.L=65&humiAlerts.caut2.H=75&luxAlerts.warn1.L=0&luxAlerts.warn1.H=1&luxAlerts.warn2.L=2000&luxAlerts.warn2.H=99999&luxAlerts.caut1.L=-1&luxAlerts.caut1.H=-1&luxAlerts.caut2.L=-1&luxAlerts.caut2.H=-1&presAlerts.warn1.L=0&presAlerts.warn1.H=995&presAlerts.warn2.L=1025&presAlerts.warn2.H=3000&presAlerts.caut1.L=995&presAlerts.caut1.H=1000&presAlerts.caut2.L=3000&presAlerts.caut2.H=3000&co2Alerts.warn1.L=0&co2Alerts.warn1.H=200&co2Alerts.warn2.L=1000&co2Alerts.warn2.H=9999&co2Alerts.caut1.L=200&co2Alerts.caut1.H=300&co2Alerts.caut2.L=800&co2Alerts.caut2.H=1000" http://ebx32.local/config
curl -X POST -d "mDNS=ebx32&opMode=always&displayFlip=yes&displayBrightness=50&oledType=SSD&st7789=yes&st7789Mode=st7789_normal&mhz19b=no&mhz19bPwmPin=14&mhz19bRxPin=32&mhz19bTxPin=33&mqttBroker=&mqttName=&tempAlerts=&tempAlerts.warn1.L=-99&tempAlerts.warn1.H=10&tempAlerts.warn2.L=10&tempAlerts.warn2.H=40&tempAlerts.caut1.L=10&tempAlerts.caut1.H=15&tempAlerts.caut2.L=28&tempAlerts.caut2.H=30&humiAlerts.warn1.L=0&humiAlerts.warn1.H=20&humiAlerts.warn2.L=75&humiAlerts.warn2.H=100&humiAlerts.caut1.L=20&humiAlerts.caut1.H=35&humiAlerts.caut2.L=65&humiAlerts.caut2.H=75&luxAlerts.warn1.L=0&luxAlerts.warn1.H=1&luxAlerts.warn2.L=2000&luxAlerts.warn2.H=99999&luxAlerts.caut1.L=-1&luxAlerts.caut1.H=-1&luxAlerts.caut2.L=-1&luxAlerts.caut2.H=-1&presAlerts.warn1.L=0&presAlerts.warn1.H=995&presAlerts.warn2.L=1025&presAlerts.warn2.H=3000&presAlerts.caut1.L=995&presAlerts.caut1.H=1000&presAlerts.caut2.L=3000&presAlerts.caut2.H=3000&co2Alerts.warn1.L=0&co2Alerts.warn1.H=200&co2Alerts.warn2.L=1000&co2Alerts.warn2.H=9999&co2Alerts.caut1.L=200&co2Alerts.caut1.H=300&co2Alerts.caut2.L=800&co2Alerts.caut2.H=1000" http://ebx32.local/api/v1/config

curl -X POST -d "tempAlerts.warn1.L=-99&tempAlerts.warn1.H=10&tempAlerts.warn2.L=10&tempAlerts.warn2.H=40&tempAlerts.caut1.L=10&tempAlerts.caut1.H=15&tempAlerts.caut2.L=28&tempAlerts.caut2.H=30&humiAlerts.warn1.L=0&humiAlerts.warn1.H=20&humiAlerts.warn2.L=75&humiAlerts.warn2.H=100&humiAlerts.caut1.L=20&humiAlerts.caut1.H=35&humiAlerts.caut2.L=65&humiAlerts.caut2.H=75&luxAlerts.warn1.L=0&luxAlerts.warn1.H=1&luxAlerts.warn2.L=2000&luxAlerts.warn2.H=99999&luxAlerts.caut1.L=-1&luxAlerts.caut1.H=-1&luxAlerts.caut2.L=-1&luxAlerts.caut2.H=-1&presAlerts.warn1.L=0&presAlerts.warn1.H=995&presAlerts.warn2.L=1025&presAlerts.warn2.H=3000&presAlerts.caut1.L=995&presAlerts.caut1.H=1000&presAlerts.caut2.L=3000&presAlerts.caut2.H=3000&co2Alerts.warn1.L=0&co2Alerts.warn1.H=200&co2Alerts.warn2.L=1000&co2Alerts.warn2.H=9999&co2Alerts.caut1.L=200&co2Alerts.caut1.H=300&co2Alerts.caut2.L=800&co2Alerts.caut2.H=1000" http://ebx32.local/config
curl -X POST -d "tempAlerts.warn1.L=-99&tempAlerts.warn1.H=10&tempAlerts.warn2.L=10&tempAlerts.warn2.H=40&tempAlerts.caut1.L=10&tempAlerts.caut1.H=15&tempAlerts.caut2.L=28&tempAlerts.caut2.H=30&humiAlerts.warn1.L=0&humiAlerts.warn1.H=20&humiAlerts.warn2.L=75&humiAlerts.warn2.H=100&humiAlerts.caut1.L=20&humiAlerts.caut1.H=35&humiAlerts.caut2.L=65&humiAlerts.caut2.H=75&luxAlerts.warn1.L=0&luxAlerts.warn1.H=1&luxAlerts.warn2.L=2000&luxAlerts.warn2.H=99999&luxAlerts.caut1.L=-1&luxAlerts.caut1.H=-1&luxAlerts.caut2.L=-1&luxAlerts.caut2.H=-1&presAlerts.warn1.L=0&presAlerts.warn1.H=995&presAlerts.warn2.L=1025&presAlerts.warn2.H=3000&presAlerts.caut1.L=995&presAlerts.caut1.H=1000&presAlerts.caut2.L=3000&presAlerts.caut2.H=3000&co2Alerts.warn1.L=0&co2Alerts.warn1.H=200&co2Alerts.warn2.L=1000&co2Alerts.warn2.H=9999&co2Alerts.caut1.L=200&co2Alerts.caut1.H=300&co2Alerts.caut2.L=800&co2Alerts.caut2.H=1000" http://ebx32.local/api/v1/config
17 changes: 7 additions & 10 deletions src/ConfigClass.h → include/ConfigClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
#include "utils.h"
#include "SimpleMap.h"

// * 項目追加時の実装項目:
// - [ ] 2. Setup HTML http_setup_web_get.cpp http_setup_get_root_content
// - [ ] 3. Setup POST後の表示 (if required) http_setup_web_post.cpp http_setup_post_root_content
// - [ ] 4. Web API http_api_backup_config
// - [ ] 5. Web API updateConfig
// - [ ] 6. Write Config _create_config_json
// - [ ] 7. Read Config read_config_file
// - [ ] 8. Print config print_config
// - [ ] 9. Config version global.cpp

enum class ConfigValueType {
String = 0, // 任意の文字列
Expand Down Expand Up @@ -130,12 +121,18 @@ class Config {
return configMetaMap.get(key);
}

// 設定値を取得する
// 設定値を取得する(String)
String get(String key) {
checkKeyExist("get", key, true);
return configMap.get(key);
}

// 設定値を取得する(bool)
bool getAsBoolean(String key) {
String val = configMap.get(key);
return parseBooleanString(val);
}

// set 普通のキー
ConfigSetResult set(String key, String value, bool haltOnNoKey = true) {
// debuglog("[Config] key=" + key + " value=" + value);
Expand Down
27 changes: 18 additions & 9 deletions include/config.h → include/config/config.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#pragma once

#include <ArduinoJson.h>
#include "FS.h"
#include <LittleFS.h>

#include "config_names.h"
#include "config_values.h"
#include "ConfigClass.h"

// --------------------------------------------------------------------
// ボード依存あり
// --------------------------------------------------------------------
enum struct CFG_VALIDATE_RESULT {
// 存在していて、バージョンも一致している
VALID,
// 存在しているが、バージョンが一致していない
NEED_UPGRADE,
// 存在していない
NOT_FOUND,
// 不明
ERROR
};

/**
* CONFIGをファイルから読み取る。
Expand All @@ -25,8 +32,11 @@ void create_configure_flag_file();

/** config ok フラグファイルを削除する */
void remove_configure_flag_file();
bool has_valid_config_file();
bool has_valid_config();

/** configファイルの存在とバージョンをチェックする */
CFG_VALIDATE_RESULT has_valid_config_file();

bool has_configured_file();

void config_setup();

Expand All @@ -37,21 +47,20 @@ void config_factory_reset();
// ボード依存なし
// --------------------------------------------------------------------

void print_config();

void trim_config();

/** config値をファイルに書き出す。closeはしない */
void write_config_file(File f);

/** ファイルを読んでconfig値にセット。closeはしない */
bool read_config_file(File f);
bool read_config_file(File f, bool readForUpdate);

/** ファイルを読んでSETTING_IDを返す。
* 取得できない場合はINVALIDが返る。closeはしない
*/
String read_config_setting_id(File f);


// APIコール用 Config->JSON
DynamicJsonDocument create_config_json(std::vector<String>& keys);

Expand Down
15 changes: 15 additions & 0 deletions include/config_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

#include <Arduino.h>

// memo
// Add new config
// config_names.h (variable names only)
// config_names.cpp (name attribute of config.html)
// config_values.h (variable names only)
// config_values.cpp (value of choice candicate)
// ConfigClass_metadata.cpp
// ConfigClass_defaultValue.cpp
/**
* Configで使用される、名称の定数クラス。
* 実際の値は ConfigValue クラスにある
Expand All @@ -21,6 +29,13 @@ class ConfigNames {
static const String DISPLAY_AUTODIM_LUX; // v45
static const String DISPLAY_AUTODIM_WAIT_SEC; // v45

static const String NTP; // v47
static const String NTP_ADDRESS; // v47
static const String NTP_TIMEZONE; // v47
static const String NTP_AUTO_DIMMER; // v47
static const String NTP_AUTO_DIMMER_START; // v47
static const String NTP_AUTO_DIMMER_END; // v47

static const String OLED_TYPE;

static const String ST7789;
Expand Down
6 changes: 6 additions & 0 deletions include/config_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class ConfigValues {
static const String OPMODE_MQTT;
static const String OPMODE_DISPLAY;

static const String NTP_ON; // v47
static const String NTP_OFF; // v47

static const String NTP_AUTO_DIMMER_ON; // v47
static const String NTP_AUTO_DIMMER_OFF; // v47

static const String ST7789_USE;
static const String ST7789_NOUSE;

Expand Down
10 changes: 10 additions & 0 deletions include/network/time_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <Arduino.h>

void ntp_setup();
String getFormattedTime();

String getDate();
String getTime();

/** time is not set due to NTP failed or NTP disabled */
const String TIME_NOT_READY = "0000/00/00 00:00:00";
1 change: 1 addition & 0 deletions include/sensors/timebased_dimmer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void timebased_dimmer();
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
[platformio]
description = "EnvBoyX"
default_envs = esp32dev
#default_envs = esp12e

[env]
extra_scripts =
pre:build_script/create_embed.py

[env:esp32dev]
platform = https://github.com/platformio/platform-espressif32.git
platform = espressif32
board = esp32dev
framework = arduino
board_build.mcu = esp32
Expand Down
12 changes: 10 additions & 2 deletions src/ConfigClass_defaultValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@

/**
* 初期値をセットする
* ここでセットしていない項目は存在しないものとして扱われる
*/
void Config::loadDefaultValue() {
this->addConfig(ConfigNames::SETTING_ID, "");
this->addConfig(ConfigNames::SSID, "");
this->addConfig(ConfigNames::PASSWORD, "");

this->addConfig(ConfigNames::MDNS, "ebx");

this->addConfig(ConfigNames::OPMODE, ConfigValues::OPMODE_DISPLAY);

this->addConfig(ConfigNames::NTP, ConfigValues::NTP_OFF);
this->addConfig(ConfigNames::NTP_ADDRESS, "");
this->addConfig(ConfigNames::NTP_TIMEZONE, "JST-9");

this->addConfig(ConfigNames::NTP_AUTO_DIMMER, ConfigValues::NTP_AUTO_DIMMER_OFF);
this->addConfig(ConfigNames::NTP_AUTO_DIMMER_START, "");
this->addConfig(ConfigNames::NTP_AUTO_DIMMER_END, "");

this->addConfig(ConfigNames::DISPLAY_FLIP, ConfigValues::DISPLAY_FLIP_OFF);
this->addConfig(ConfigNames::DISPLAY_BRIGHTNESS, "255");
this->addConfig(ConfigNames::DISPLAY_RECONFIG, ConfigValues::DISPLAY_RECONFIG_ON); // v44;
this->addConfig(ConfigNames::DISPLAY_RECONFIG, ConfigValues::DISPLAY_RECONFIG_SKIP); // v44: 追加(ON) v47: デフォルトOFF
this->addConfig(ConfigNames::DISPLAY_AUTODIM_LUX, "5"); // v45: この明るさ以下がDuration秒続けば消灯
this->addConfig(ConfigNames::DISPLAY_AUTODIM_WAIT_SEC, "10"); // v45: 消灯までの時間 second

Expand Down
Loading

0 comments on commit 69e8cd6

Please sign in to comment.