add config switch

This commit is contained in:
2022-12-23 14:48:47 +01:00
parent 015309f20f
commit 0923c59280
4 changed files with 27 additions and 3 deletions

View File

@ -10,7 +10,7 @@
#define LED_RED 3
#define LED_GREEN 2
#define LED_BLUE 45
#define CONFIG_SWITCH 46

View File

@ -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 },

View File

@ -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 {

View File

@ -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", "");
}