diff --git a/_how-to-develop.md b/_how-to-develop.md index 4763683..140bd98 100644 --- a/_how-to-develop.md +++ b/_how-to-develop.md @@ -1,28 +1,32 @@ -# how to develop web ui +# how to develop -## copy files except config.html to static/ +## arduino code -``` -cd embed -rsync -v --exclude=config.html ./* static -``` +1. git clone +2. open directory in VSCode +3. Fix includePath -## run python http.server or some simple web server on embed +### include path + +Edit `.vscode/c_cpp_properties.json` file. ``` -cd embed -python -m http.server +"includePath": [ + "${workspaceFolder}/**", + "/Users/username/.platformio/packages/**" <-- Add this. path vary on your OS. +], ``` -## Access web via web browser +## Web UI code -Use firefox or chrome newer version. +1. git clone +2. edit `src/global.cpp` `DEBUG_BUILD = true`. by change this, envboy returns CORS header. +3. Upload to board +4. exec `python -m http.server` In `embed` directory +5. access `localhost:8000` using web browser -# after development +### NOTE -Dont forget to write back all files in static/ to embed. +1. you cant use external JS libraries. because host has no internet access while in setup mode. -``` -cd embed/static -cp -v ./* ../ -``` \ No newline at end of file +NOTE: modernize JS/Web development is a task in near future. \ No newline at end of file diff --git a/include/config/config.h b/include/config/config.h index 9583208..ae964c0 100644 --- a/include/config/config.h +++ b/include/config/config.h @@ -7,6 +7,8 @@ #include "config_values.h" #include "ConfigClass.h" +extern const String CFG_VERSION_INVALID; + enum struct CFG_VALIDATE_RESULT { // 存在していて、バージョンも一致している VALID, diff --git a/src/config/config.cpp b/src/config/config.cpp index 8592823..5032f0e 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -12,6 +12,8 @@ #include "config_names.h" const unsigned int CONF_JSON_SIZE = 4000; +extern const String CFG_VERSION_INVALID = "INVALID"; + DynamicJsonDocument _create_config_json(bool save, const std::vector &keyArray) { @@ -119,12 +121,12 @@ String read_config_setting_id(File f) { DeserializationError error = deserializeJson(doc, f); if (error) { - return "INVALID"; + return CFG_VERSION_INVALID; } JsonVariant value = doc[ConfigNames::SETTING_ID]; if (value.isNull()) { - return "INVALID"; // JSON not contains SETTING_ID + return CFG_VERSION_INVALID; // JSON not contains SETTING_ID } return value.as(); diff --git a/src/config/config_file.cpp b/src/config/config_file.cpp index 75735f9..90b159f 100644 --- a/src/config/config_file.cpp +++ b/src/config/config_file.cpp @@ -71,7 +71,10 @@ CFG_VALIDATE_RESULT has_valid_config_file() { settingId = read_config_setting_id(f); f.close(); - if (String(SETTING_ID).equals(settingId)) { + if (settingId.equals(CFG_VERSION_INVALID)) { + cfglog("SETTING_ID not found. INVALID config."); + return CFG_VALIDATE_RESULT::ERROR; + } else if (String(SETTING_ID).equals(settingId)) { cfglog("SETTING_ID verified. " + settingId); return CFG_VALIDATE_RESULT::VALID; } else { @@ -80,7 +83,7 @@ CFG_VALIDATE_RESULT has_valid_config_file() { } } - cfglog("Unknown state. Assuming config not found"); + cfglog("Unknown state. Assuming config not found. " + settingId); return CFG_VALIDATE_RESULT::ERROR; } @@ -102,6 +105,7 @@ bool has_configured_file() { return true; } +/** ファイルシステムのマウント */ void config_setup() { if (!LittleFS.begin()) { diff --git a/src/i2c_scan.cpp b/src/i2c_scan.cpp index 466fc5f..500d76d 100644 --- a/src/i2c_scan.cpp +++ b/src/i2c_scan.cpp @@ -5,54 +5,43 @@ String get_device_name_by_address(byte address) { // ("0x39=TSL2561/0x3c=LCD/0x5c=AM2320/0x5d=LPS22HB/0x76=BME280")); + if (address == 0x23) return "BH1750 Lux sensor"; if (address == 0x39) return "TSL2561 Lux sensor"; if (address == 0x3c) return "SSD1306/SH1106 OLED display"; if (address == 0x5c) return "AM2320 Temperature and Humidity sensor"; if (address == 0x5d) return "LPS22HB High precision air pressure sensor"; - if (address == 0x76) return "BME280 Temperature and Humidity and air pressure sensor"; - + if (address == 0x76) + return "BME280 Temperature and Humidity and air pressure sensor"; return "unknown device"; } -void i2c_scan() -{ - +void i2c_scan() { unsigned long start = millis(); byte error, address; int nDevices = 0; - for(address = 1; address < 127; address++ ) - { - + for (address = 1; address < 127; address++) { Wire.beginTransmission(address); error = Wire.endTransmission(); - - if (error == 0) - { + + if (error == 0) { String msg = "Found at 0x"; - if (address<16) - msg += "0"; - msg += String(address,HEX); + if (address < 16) msg += "0"; + msg += String(address, HEX); msg += " " + String(address); i2clog(msg + " " + get_device_name_by_address(address)); nDevices++; - } - else if (error==4) - { + } else if (error == 4) { String msg = "Unknown error at address 0x"; - if (address<16) - msg += "0"; - msg += String(address,HEX); + if (address < 16) msg += "0"; + msg += String(address, HEX); i2clog(msg); } } if (nDevices == 0) { i2clog(F("No I2C devices found")); - } else { - i2clog(F("0x39=TSL2561/0x3c=LCD/0x5c=AM2320/0x5d=LPS22HB/0x76=BME280")); } i2clog("I2C scan done. time = " + String(millis() - start) + " ms"); - } diff --git a/src/main.cpp b/src/main.cpp index fd77b68..ba9bcb5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,7 +41,10 @@ void setup() if (validateResult == CFG_VALIDATE_RESULT::VALID) { mainlog(F("Config file is valid.")); } else if (validateResult == CFG_VALIDATE_RESULT::NEED_UPGRADE) { - mainlog(F("Config file needs upgrade.")); + sectionlog(F("Config file needs upgrade. upgrading...")); + read_config(); + save_config(); // upgrade means json + default, so only saving is needed. + sectionlog(F("Config file upgrade done!")); } else { mainlog(F("Config file validation error. dropping to setup mode.")); isNormal = false; diff --git a/src/main_normal.cpp b/src/main_normal.cpp index aaa7dfa..8c62400 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -143,7 +143,7 @@ void setup_normal() { sectionlog(F("Start watchdog")); setup_watchdog(); - // setupモードに入りやすくするための処理 + // setupモードに入りやすくするための処理(deprecated) if (config->get(ConfigNames::DISPLAY_RECONFIG) == ConfigValues::DISPLAY_RECONFIG_ON) { sectionlog(F("Reset to reconfig start.")); remove_configure_flag_file(); diff --git a/src/sensors/bh1750.cpp b/src/sensors/bh1750.cpp index 00fbe34..4f8349d 100644 --- a/src/sensors/bh1750.cpp +++ b/src/sensors/bh1750.cpp @@ -24,16 +24,16 @@ bool bh_setup(void) { byte error = Wire.endTransmission(); if (!(error == 0)) { - amlog(F("BH1750 disabled. ")); + bhlog(F("BH1750 disabled. ")); return false; } if (!bh1750.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) { - amlog(F("BH1750 disabled: Device found but initialize error. ")); + bhlog(F("BH1750 disabled: Device found but initialize error. ")); return false; } - amlog(F("BH1750 Enabled")); + bhlog(F("BH1750 Enabled")); use_bh1750 = true; return true; }