From aa4d6deafd085fcdbea5cfca0ab9c86cde5943b6 Mon Sep 17 00:00:00 2001 From: bogdan Date: Sun, 20 Aug 2023 12:36:42 +0200 Subject: [PATCH] added source files --- CardActions.vue | 11 ++++++ EssentialLink.vue | 48 +++++++++++++++++++++++++ SelectWiFiDialog.vue | 67 +++++++++++++++++++++++++++++++++++ cards/EthSetCard.vue | 45 ++++++++++++++++++++++++ cards/FirmwareCard.vue | 41 ++++++++++++++++++++++ cards/HomeCard.vue | 44 +++++++++++++++++++++++ cards/MQTT1Card.vue | 46 ++++++++++++++++++++++++ cards/MQTT2Card.vue | 51 +++++++++++++++++++++++++++ cards/SNTPCard.vue | 39 ++++++++++++++++++++ cards/StatCard.vue | 65 ++++++++++++++++++++++++++++++++++ cards/SystemCard.vue | 43 +++++++++++++++++++++++ cards/WifiSetCard.vue | 80 ++++++++++++++++++++++++++++++++++++++++++ network.js | 64 +++++++++++++++++++++++++++++++++ 13 files changed, 644 insertions(+) create mode 100644 CardActions.vue create mode 100644 EssentialLink.vue create mode 100644 SelectWiFiDialog.vue create mode 100644 cards/EthSetCard.vue create mode 100644 cards/FirmwareCard.vue create mode 100644 cards/HomeCard.vue create mode 100644 cards/MQTT1Card.vue create mode 100644 cards/MQTT2Card.vue create mode 100644 cards/SNTPCard.vue create mode 100644 cards/StatCard.vue create mode 100644 cards/SystemCard.vue create mode 100644 cards/WifiSetCard.vue create mode 100644 network.js diff --git a/CardActions.vue b/CardActions.vue new file mode 100644 index 0000000..49a65d2 --- /dev/null +++ b/CardActions.vue @@ -0,0 +1,11 @@ + + + diff --git a/EssentialLink.vue b/EssentialLink.vue new file mode 100644 index 0000000..1a32006 --- /dev/null +++ b/EssentialLink.vue @@ -0,0 +1,48 @@ + + + + + diff --git a/SelectWiFiDialog.vue b/SelectWiFiDialog.vue new file mode 100644 index 0000000..7b56675 --- /dev/null +++ b/SelectWiFiDialog.vue @@ -0,0 +1,67 @@ + + + diff --git a/cards/EthSetCard.vue b/cards/EthSetCard.vue new file mode 100644 index 0000000..d668947 --- /dev/null +++ b/cards/EthSetCard.vue @@ -0,0 +1,45 @@ + + diff --git a/cards/FirmwareCard.vue b/cards/FirmwareCard.vue new file mode 100644 index 0000000..75d37e3 --- /dev/null +++ b/cards/FirmwareCard.vue @@ -0,0 +1,41 @@ + + + diff --git a/cards/HomeCard.vue b/cards/HomeCard.vue new file mode 100644 index 0000000..8ae266f --- /dev/null +++ b/cards/HomeCard.vue @@ -0,0 +1,44 @@ + + + diff --git a/cards/MQTT1Card.vue b/cards/MQTT1Card.vue new file mode 100644 index 0000000..c709556 --- /dev/null +++ b/cards/MQTT1Card.vue @@ -0,0 +1,46 @@ + + + diff --git a/cards/MQTT2Card.vue b/cards/MQTT2Card.vue new file mode 100644 index 0000000..b694b9a --- /dev/null +++ b/cards/MQTT2Card.vue @@ -0,0 +1,51 @@ + + + + + diff --git a/cards/SNTPCard.vue b/cards/SNTPCard.vue new file mode 100644 index 0000000..b1048ec --- /dev/null +++ b/cards/SNTPCard.vue @@ -0,0 +1,39 @@ + + + diff --git a/cards/StatCard.vue b/cards/StatCard.vue new file mode 100644 index 0000000..601ddcf --- /dev/null +++ b/cards/StatCard.vue @@ -0,0 +1,65 @@ + + + diff --git a/cards/SystemCard.vue b/cards/SystemCard.vue new file mode 100644 index 0000000..d4c2165 --- /dev/null +++ b/cards/SystemCard.vue @@ -0,0 +1,43 @@ + + + diff --git a/cards/WifiSetCard.vue b/cards/WifiSetCard.vue new file mode 100644 index 0000000..0624e7e --- /dev/null +++ b/cards/WifiSetCard.vue @@ -0,0 +1,80 @@ + + + diff --git a/network.js b/network.js new file mode 100644 index 0000000..50ed1bb --- /dev/null +++ b/network.js @@ -0,0 +1,64 @@ +import { api } from "boot/axios"; +import { sha256 } from "js-sha256"; +import { Notify, Dialog } from "quasar"; + +const API_URL = "/api"; +const SHA256_HMAC_KEY = "mykey"; + +function ShowSaveDialog(apltype) { + const opername = ['Data applying...', 'Data saving...', 'Data saving and reboot...']; + let step = (apltype == 2) ? 1 : 10; + let percentage = 0; + const dialog = Dialog.create({ message: opername[apltype], progress: true, persistent: true, ok: false }) + const interval = setInterval(() => { + percentage = Math.min(100, percentage + step); + dialog.update({ + message: `${opername[apltype]} ${percentage}%` + }) + if (percentage === 100) { + clearInterval(interval); + setTimeout(() => { dialog.hide() }, 350) + } + }, 100) +} + + + +function PostData(varlist, messtype, applytype, onfinished) { + var pld = {}; + var data = {}; + data.msgid = Math.floor(Date.now() / 1000); + data.time = new Date().toISOString(); + data.msgtype = messtype; + data.payloadtype = 1; + data.payload = {}; + data.payload.applytype = applytype; + data.payload.variables = varlist; + pld.data = data; + pld.signature = sha256.hmac(SHA256_HMAC_KEY, JSON.stringify(data)); + + api + .post(API_URL, JSON.stringify(pld), { + headers: { "Content-Type": "application/json" }, + }) + .then((response) => { + var resp = response.data.data.payload.variables; + for (var k in resp) varlist[k] = resp[k]; + if (onfinished) onfinished(); + }) + .catch((err) => { + Notify.create({ color: "negative", position: "top", message: err.message, icon: "report_problem", }); + }); + +} + +function SendAndRequest(varlist, mstp, apltp, shakey, okreport) { + var onfinish = (okreport) ? () => { ShowSaveDialog(apltp) } : null; + PostData(varlist, mstp, apltp, onfinish); +} + +export { SendAndRequest, PostData }; + + + +