diff --git a/libraries/includes/defines.h b/libraries/includes/defines.h index 3610300..cb1a040 100644 --- a/libraries/includes/defines.h +++ b/libraries/includes/defines.h @@ -10,7 +10,7 @@ #define LED_RED 3 #define LED_GREEN 2 #define LED_BLUE 45 - +#define CONFIG_SWITCH 46 diff --git a/sketch/configuration.cpp b/sketch/configuration.cpp index b4a79fc..56d99cc 100644 --- a/sketch/configuration.cpp +++ b/sketch/configuration.cpp @@ -26,8 +26,8 @@ const uint32_t MAGIC = 0xaffe0001; config_t myConfig = { .magic = MAGIC, - .appEui = { 0, 0, 0, 0, 0, 0, 0, 0 }, - .appKey = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + .appEui = { 0xa0, 0x57, 0x81, 0x00, 0x01, 0x12, 0xaa, 0xf3 }, + .appKey = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, .modbus_poll_slots = { { .typ = INPUT_REGISTERS, .id = 7, .address = 0x01 }, { .typ = INPUT_REGISTERS, .id = 7, .address = 0x02 }, diff --git a/sketch/sketch.ino b/sketch/sketch.ino index e499a20..ecdde8d 100644 --- a/sketch/sketch.ino +++ b/sketch/sketch.ino @@ -18,10 +18,13 @@ void setup() { pinMode(LED_GREEN, OUTPUT); digitalWrite(LED_GREEN, LOW); + pinMode(CONFIG_SWITCH, INPUT_PULLUP); + Serial.begin(115200); configLoad(); + productionMode = (digitalRead(CONFIG_SWITCH) == HIGH); if (productionMode) { productionSetup(); } else { diff --git a/snippets/form_table_config_approach.txt b/snippets/form_table_config_approach.txt index c29b910..06ecabb 100644 --- a/snippets/form_table_config_approach.txt +++ b/snippets/form_table_config_approach.txt @@ -34,3 +34,24 @@ buffer << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (int)myConfig.appKey[i]; } buffer << "\">"; + + + + + +static void handleConfigSave() { + char *arg1 = (char*)server.arg("AppEui").c_str(); + Serial.printf("AppEui: %s\n\r", arg1); + parseField(arg1, 1, 8, myConfig.appEui); + + if (!configParsingFailed) { + char *arg2 = (char*)server.arg("AppKey").c_str(); + Serial.printf("AppKey: %s\n\r", arg2); + parseField(arg2, 2, 16, myConfig.appKey); + } + + configSaved = !configParsingFailed; + server.sendHeader("Location", String("/"), true); + server.send(302, "text/plain", ""); +} +