diff --git a/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte b/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte index 2f9863fd..fd686f83 100644 --- a/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte +++ b/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte @@ -1,212 +1,367 @@ -
-
- General -
- Timezone
- -
-
- Hostname
- -
-
- Security
- -
-
- Username
- -
-
- Password
- -
-
-
- Meter -
- Serial configuration -
- - - +
- +
+ Hostname
+ +
+
+ Security
+ +
+
+ Username
+ +
+
+ Password
+ +
+
+ Meter +
+ Serial configuration +
+ + + +
+ +
-
-
- Distribution
- +
+
+ Distribution
+ +
+
+ Main fuse
+ +
+
+ Production
+ +
-
- Main fuse
+ +
+ Encryption key
+ +
+
+ Authentication key
+ +
+
+
+ WiFi +
+ SSID
+ +
+
+ PSK
+ +
+
+ Power
-
-
- Production
-
- -
- Encryption key
- +
+ Network +
+ IP
+
+ + + +
+
+
+ Gateway
+ +
+
+ DNS
+
+ + +
+ +
+
+ NTP
+
+ + +
+ +
-
- Authentication key
- -
-
-
- WiFi -
- SSID
- -
-
- PSK
- -
-
- Power
- -
-
-
- Network -
- IP
-
- - - + +
+
+
+ Username
+ +
+
+ Password
+ +
+
+ Client ID
+ +
+
+ Publish topic
+ +
+
+ Payload
+
-
-
- Gateway
- -
-
- DNS
-
- - -
- -
-
- NTP
-
- - -
- -
-
-
- MQTT -
- Server
-
- - +
+ SSL
-
- Username
- +
+ Prices
-
- Password
- +
+ Webhook
-
- Client ID
- +
+ Backup and restore
-
- Publish topic
-
- - -
+
+ Debugging
-
- SSL +
+ Vendor menu + Board type
+ GPIO
+ Vcc
+ Favico
-
- Prices -
-
- Webhook -
-
- Backup and restore -
-
- Debugging -
-
- Vendor menu - Board type
- GPIO
- Vcc
- Favico
-
-
+ + \ No newline at end of file diff --git a/lib/SvelteUi/app/src/lib/ConfigurationStore.js b/lib/SvelteUi/app/src/lib/ConfigurationStore.js new file mode 100644 index 00000000..4e3aabe8 --- /dev/null +++ b/lib/SvelteUi/app/src/lib/ConfigurationStore.js @@ -0,0 +1,12 @@ +import { readable } from 'svelte/store'; + +let configuration = {}; +export const configurationStore = readable(configuration, (set) => { + async function getConfiguration(){ + const response = await fetch("/configuration.json"); + configuration = (await response.json()) + set(configuration); + } + getConfiguration(); + return function stop() {} +}); diff --git a/lib/SvelteUi/app/src/lib/DataStores.js b/lib/SvelteUi/app/src/lib/DataStores.js index 06b6600e..f91d81e3 100644 --- a/lib/SvelteUi/app/src/lib/DataStores.js +++ b/lib/SvelteUi/app/src/lib/DataStores.js @@ -24,7 +24,9 @@ export const pricesStore = readable(prices, (set) => { const date = new Date(); const timeout = setTimeout(getPrices, (61-date.getMinutes())*60000) getPrices(); - return function stop() {} + return function stop() { + clearTimeout(timeout); + } }); let dayPlot = {}; diff --git a/lib/SvelteUi/app/vite.config.js b/lib/SvelteUi/app/vite.config.js index 33c59e1d..ae73491f 100644 --- a/lib/SvelteUi/app/vite.config.js +++ b/lib/SvelteUi/app/vite.config.js @@ -17,12 +17,12 @@ export default defineConfig({ plugins: [svelte()], server: { proxy: { - "/data.json": "http://192.168.233.235", - "/energyprice.json": "http://192.168.233.235", - "/dayplot.json": "http://192.168.233.235", - "/monthplot.json": "http://192.168.233.235", - "/temperature.json": "http://192.168.233.235", - "/configuration.json": "http://192.168.233.244" + "/data.json": "http://192.168.233.207", + "/energyprice.json": "http://192.168.233.207", + "/dayplot.json": "http://192.168.233.207", + "/monthplot.json": "http://192.168.233.207", + "/temperature.json": "http://192.168.233.207", + "/configuration.json": "http://192.168.233.207" } } }) diff --git a/lib/SvelteUi/src/AmsWebServer.cpp b/lib/SvelteUi/src/AmsWebServer.cpp index 2f0b36d5..5086fc15 100644 --- a/lib/SvelteUi/src/AmsWebServer.cpp +++ b/lib/SvelteUi/src/AmsWebServer.cpp @@ -547,7 +547,7 @@ void AmsWebServer::indexJs() { } void AmsWebServer::configurationJson() { - if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("Serving /config.json over http...\n"); + if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("Serving /configuration.json over http...\n"); server.sendHeader(HEADER_CACHE_CONTROL, CACHE_CONTROL_NO_CACHE); server.sendHeader(HEADER_PRAGMA, PRAGMA_NO_CACHE); @@ -556,35 +556,70 @@ void AmsWebServer::configurationJson() { if(!checkSecurity(1)) return; - DynamicJsonDocument doc(512); + DynamicJsonDocument doc(1024); doc["version"] = VERSION; + #if defined(CONFIG_IDF_TARGET_ESP32S2) + doc["chip"] = "esp32s2"; + #elif defined(CONFIG_IDF_TARGET_ESP32C3) + doc["chip"] = "esp32c3"; + #elif defined(ESP32) + doc["chip"] = "esp32"; + #elif defined(ESP8266) + doc["chip"] = "esp8266"; + #endif - doc["general"]["t"] = ""; - doc["general"]["h"] = ""; - doc["general"]["s"] = ""; - doc["general"]["u"] = ""; - doc["general"]["p"] = ""; + WiFiConfig wifiConfig; + config->getWiFiConfig(wifiConfig); + WebConfig webConfig; + config->getWebConfig(webConfig); + doc["general"]["zone"] = "Europe/Oslo"; + doc["general"]["host"] = wifiConfig.hostname; + doc["general"]["sec"] = webConfig.security; + doc["general"]["user"] = webConfig.username; + doc["general"]["pass"] = webConfig.password; -/* - uint16_t wattageMultiplier; - uint16_t voltageMultiplier; - uint16_t amperageMultiplier; - uint16_t accumulatedMultiplier; - uint8_t source; - uint8_t parser -*/ config->getGpioConfig(*gpioConfig); config->getMeterConfig(*meterConfig); - doc["meter"]["s"] = gpioConfig->hanPin; - doc["meter"]["b"] = meterConfig->baud; - doc["meter"]["p"] = meterConfig->parity; - doc["meter"]["i"] = meterConfig->invert; - doc["meter"]["d"] = meterConfig->distributionSystem; - doc["meter"]["f"] = meterConfig->mainFuse; - doc["meter"]["o"] = meterConfig->productionCapacity; - doc["meter"]["e"] = toHex(meterConfig->encryptionKey, 16); - doc["meter"]["a"] = toHex(meterConfig->authenticationKey, 16); + doc["meter"]["pin"] = gpioConfig->hanPin; + doc["meter"]["baud"] = meterConfig->baud; + doc["meter"]["par"] = meterConfig->parity; + doc["meter"]["inv"] = meterConfig->invert; + doc["meter"]["dist"] = meterConfig->distributionSystem; + doc["meter"]["fuse"] = meterConfig->mainFuse; + doc["meter"]["prod"] = meterConfig->productionCapacity; + doc["meter"]["enc"] = toHex(meterConfig->encryptionKey, 16); + doc["meter"]["auth"] = toHex(meterConfig->authenticationKey, 16); + + // TODO: Tariff thresholds + // TODO: Multipliers + + doc["wifi"]["ssid"] = wifiConfig.ssid; + doc["wifi"]["psk"] = wifiConfig.psk; + doc["wifi"]["pwr"] = wifiConfig.power / 10.0; + + NtpConfig ntpConfig; + config->getNtpConfig(ntpConfig); + doc["net"]["mode"] = strlen(wifiConfig.ip) > 0 ? "s" : "d"; + doc["net"]["ip"] = wifiConfig.ip; + doc["net"]["mask"] = wifiConfig.subnet; + doc["net"]["gw"] = wifiConfig.gateway; + doc["net"]["dns1"] = wifiConfig.dns1; + doc["net"]["dns2"] = wifiConfig.dns2; + doc["net"]["mdns"] = wifiConfig.mdns; + doc["net"]["ntp1"] = ntpConfig.server; + doc["net"]["ntpdhcp"] = ntpConfig.dhcp; + + MqttConfig mqttConfig; + config->getMqttConfig(mqttConfig); + doc["mqtt"]["host"] = mqttConfig.host; + doc["mqtt"]["port"] = mqttConfig.port; + doc["mqtt"]["user"] = mqttConfig.username; + doc["mqtt"]["pass"] = mqttConfig.password; + doc["mqtt"]["clid"] = mqttConfig.clientId; + doc["mqtt"]["pub"] = mqttConfig.publishTopic; + doc["mqtt"]["mode"] = mqttConfig.payloadFormat; + doc["mqtt"]["ssl"] = mqttConfig.ssl; serializeJson(doc, buf, BufferSize); server.send(200, MIME_JSON, buf);