diff --git a/include/config.h b/include/config.h index 1ae480c..dbb78fb 100644 --- a/include/config.h +++ b/include/config.h @@ -60,9 +60,9 @@ static const ConfigDef configdefs[] = { {"key5long", ConfigType::BYTE, uint8_t(15)}, {"key6", ConfigType::BYTE, uint8_t(6)}, {"key6long", ConfigType::BYTE, uint8_t(16)}, - {"n2kDestA", ConfigType::STRING, String("")}, - {"n2kDestB", ConfigType::STRING, String("")}, - {"n2kDestC", ConfigType::STRING, String("")}, + {"n2kDestA", ConfigType::STRING, String("none")}, + {"n2kDestB", ConfigType::STRING, String("none")}, + {"n2kDestC", ConfigType::STRING, String("none")}, {"envInterval", ConfigType::SHORT, int16_t(5)}, // no user access diff --git a/src/webserver.cpp b/src/webserver.cpp index a639e1f..9fafef5 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -99,7 +99,7 @@ void webserver_init() { }); server.on("/api/config", HTTP_GET, [](AsyncWebServerRequest *request) { - StaticJsonDocument<512> doc; + StaticJsonDocument<1024> doc; doc["systemName"] = config.getString("systemName"); doc["systemMode"] = String(config.getChar("systemMode")); doc["logLevel"] = loglevel; @@ -130,6 +130,9 @@ void webserver_init() { doc["key4long"] = longcode[BUTTON_4]; doc["key5long"] = longcode[BUTTON_5]; doc["key6long"] = longcode[BUTTON_6]; + doc["n2kDestA"] = config.getString("n2kDestA"); + doc["n2kDestB"] = config.getString("n2kDestB"); + doc["n2kDestC"] = config.getString("n2kDestC"); doc["envInterval"] = config.getShort("envInterval"); String out; serializeJson(doc, out); @@ -230,7 +233,7 @@ void webserver_init() { AsyncResponseStream *response = request->beginResponseStream("application/json"); response->print("["); bool first = true; - for (int i = 0; i <= 252; i++) { + for (uint8_t i = 0; i <= 252; i++) { const tNMEA2000::tDevice *d = pN2kDeviceList->FindDeviceBySource(i); if (d == nullptr) { continue; @@ -244,8 +247,36 @@ void webserver_init() { first = false; } // TODO last seen? - response->printf("{\"source\":%d,\"name\":\"%s\",\"manuf\":\"%d\",\"model\":\"%s\"}", - i, hex_name, d->GetManufacturerCode(), d->GetModelID()); + uint16_t mfcode = d->GetManufacturerCode(); + // TODO RAW-String! + response->printf("{\"source\":%d,\"name\":\"%s\",\"manufcode\":\"%d\",\"model\":\"%s\",\"manufname\":\"%s\"}", + i, hex_name, mfcode, d->GetModelID(), NMEA2000.GetManufacturerName(mfcode)); + } + response->print("]"); + request->send(response); + }); + + server.on("/api/dyndevlist", HTTP_GET, [](AsyncWebServerRequest *request) { + // NMEA2000 dynmic config list: devices + AsyncResponseStream *response = request->beginResponseStream("application/json"); + response->print("["); + bool first = true; + for (uint8_t i = 0; i <= 252; i++) { + const tNMEA2000::tDevice *d = pN2kDeviceList->FindDeviceBySource(i); + if (d == nullptr) { + continue; + } + uint64_t NAME = d->GetName(); + char hex_name[17]; + snprintf(hex_name, sizeof(hex_name), "%08X%08X", (uint32_t)(NAME >> 32), (uint32_t)(NAME & 0xFFFFFFFF)); + if (!first) { + response->print(","); + } else { + first = false; + } + uint16_t mfcode = d->GetManufacturerCode(); + response->printf(R"DELIM({"v":"%s","l":"%s - %s (%d)"})DELIM", + hex_name, d->GetModelID(), NMEA2000.GetManufacturerName(mfcode), mfcode); } response->print("]"); request->send(response); diff --git a/web/config.json b/web/config.json index 953c4ad..8d4dd48 100644 --- a/web/config.json +++ b/web/config.json @@ -54,6 +54,20 @@ "description": "A password for configuration modifications is required.", "category": "System" }, +{ + "name": "instDesc1", + "label": "Description 1", + "type": "string", + "description": "NMEA2000 installation description 1", + "category": "System" +}, +{ + "name": "instDesc2", + "label": "Description 2", + "type": "string", + "description": "NMEA2000 installation description 2", + "category": "System" +}, { "name": "apEnable", "label": "Enable AP", @@ -120,8 +134,8 @@ "type": "number", "default": 64, "min": 0, - "max": 255, - "description": "The brightness of the destination leds (0..255).", + "max": 4095, + "description": "The brightness of the destination leds (0..4095).", "category": "Hardware" }, { @@ -130,8 +144,8 @@ "type": "number", "default": 64, "min": 0, - "max": 255, - "description": "The brightness of the rgb status led (0..255).", + "max": 4095, + "description": "The brightness of the rgb status led (0..4095).", "category": "Hardware" }, { @@ -281,8 +295,8 @@ "name": "n2kDestA", "label": "Destination A", "type": "dynlist", - "source": "devicelist", - "interval": "5000", + "source": "dyndevlist", + "interval": "30000", "description": "Destination device A", "category": "NMEA2000" }, @@ -290,8 +304,8 @@ "name": "n2kDestB", "label": "Destination B", "type": "dynlist", - "source": "devicelist", - "interval": "5000", + "source": "dyndevlist", + "interval": "30000", "description": "Destination device B", "category": "NMEA2000" }, @@ -299,8 +313,8 @@ "name": "n2kDestC", "label": "Destination C", "type": "dynlist", - "source": "devicelist", - "interval": "5000", + "source": "dyndevlist", + "interval": "30000", "description": "Destination device C", "category": "NMEA2000" }, @@ -312,7 +326,7 @@ "check": "checkMinMax", "min": 1, "max": 300, - "description": "interval seconds to send environment data [1..300]", + "description": "interval in seconds to send environment data [1..300]", "category": "NMEA2000" } ] diff --git a/web/index.html b/web/index.html index 8b75af6..6b595c9 100644 --- a/web/index.html +++ b/web/index.html @@ -104,11 +104,11 @@ if (!window.isSecureContext) { -