diff --git a/app/src/App.vue b/app/src/App.vue
index eba3e4b..185b81b 100644
--- a/app/src/App.vue
+++ b/app/src/App.vue
@@ -1,5 +1,5 @@
-
+
@@ -7,12 +7,13 @@
+
-
+
@@ -34,6 +35,7 @@
+
+
+
+
+
+
+ $device
+
+
+ paperdash.io
+
+
+
+
+
+
+
+
+
+
+
@@ -60,23 +94,30 @@
diff --git a/app/src/api/device.js b/app/src/api/device.js
index 60dcf56..30ca9a5 100644
--- a/app/src/api/device.js
+++ b/app/src/api/device.js
@@ -67,7 +67,7 @@ export default {
wifiConnect(ssid, password, cb) {
return axios
- .put('/api/wifi/connect', {
+ .post('/api/wifi/connect', {
ssid: ssid,
password: password
}, {
diff --git a/app/src/assets/logo.svg b/app/src/assets/logo.svg
deleted file mode 100644
index 145b6d1..0000000
--- a/app/src/assets/logo.svg
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/app/src/views/Dashboard.vue b/app/src/views/Dashboard.vue
index b887505..87c0067 100644
--- a/app/src/views/Dashboard.vue
+++ b/app/src/views/Dashboard.vue
@@ -4,7 +4,14 @@
grid-list-md
pa-2
>
- dashboard...
+
+
+
+
diff --git a/app/src/views/Settings.vue b/app/src/views/Settings.vue
index 99e8210..d557d99 100644
--- a/app/src/views/Settings.vue
+++ b/app/src/views/Settings.vue
@@ -35,6 +35,18 @@
placeholder="i8n:https://"
>
+
+
+
+
i8n:save
diff --git a/app/src/views/Wifi.vue b/app/src/views/Wifi.vue
index 0680108..61d403c 100644
--- a/app/src/views/Wifi.vue
+++ b/app/src/views/Wifi.vue
@@ -17,6 +17,118 @@
i8n:saved
+
+
+
+
+ $signalWifi0
+ not connected
+
+
+ i8n:scan
+
+
+
+
+
+
+ $signalWifi3Lock
+ xd-design.info
+
+
+
+
+
+
+
+ mdi-dots-vertical
+
+
+
+
+ i8n:scan
+
+
+
+
+
+
+
+
+
+ {{ key }}
+
+
+ {{ value }}
+
+
+
+
+
+
+
+
+
+
+ $signalWifi3Lock
+
+ xd-design.info
+
+
+
+
+ connected to
+
+ xd-design.info
+
+
+
+
+
+
+ $signalWifi3Lock
+
+
+ xd-design.info
+ connected to
+
+
+
+
+
+
+
+ {{ key }}
+
+
+ {{ value }}
+
+
+
+
+
+
+
+
+
@@ -25,7 +137,7 @@
i8n:Cancel
- i8n:Connect
+
+ i8n:Connect
+
@@ -86,10 +205,21 @@
data: () => ({
isLoading: true,
isSnackbar: false,
+ isConnecting: false,
+
+ wifiStats: {
+ connected: true,
+ ip: 'xxx.xxx.xxx.xxx',
+ mac: 'xxxx-xxxx-xxxx-xxxx',
+ channel: 11,
+ dns: 'xxx.xxx.xxx.xxx',
+ gateway: 'xxx.xxx.xxx.xxx',
+ },
wifiAvailable: [],
- wifiConnectSSID: null,
wifiConnectModal: false,
+ wifiConnectSSID: null,
+ wifiConnectPassword: null,
show1: false,
}),
created () {
@@ -141,11 +271,9 @@
},
onWifiConnect() {
- // TODO
- //this.isLoading = true
- //alert("onWifiConnect")
+ this.isConnecting = true
- //apiDevice.wifiConnect()
+ apiDevice.wifiConnect(this.wifiConnectSSID, this.wifiConnectPassword)
}
}
}
diff --git a/app/vue.config.js b/app/vue.config.js
index 475a541..7638a8a 100644
--- a/app/vue.config.js
+++ b/app/vue.config.js
@@ -7,8 +7,8 @@ module.exports = {
],
devServer: {
proxy: {
- '^/api': {
- target: 'http://192.168.178.65:80',
+ '^/': {
+ target: 'http://192.168.178.62:80',
ws: true,
changeOrigin: true
},
diff --git a/include/device.h b/include/device.h
index 04af7ef..f3b4aca 100644
--- a/include/device.h
+++ b/include/device.h
@@ -10,6 +10,7 @@ void loopDevice();
void deviceSetSleepInterval(long interval);
long deviceGetSleepInterval();
+unsigned int deviceGetBootCount();
#endif
\ No newline at end of file
diff --git a/src/app.cpp b/src/app.cpp
index ab72c1a..5612919 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -31,7 +31,8 @@ void setupApp()
server
.serveStatic("/", SPIFFS, "/dist/")
.setDefaultFile("index.html")
- .setCacheControl("max-age=600");
+ //.setCacheControl("max-age=600")
+ ;
setupSettingsGet();
setupSettingsPost();
@@ -42,13 +43,28 @@ void setupApp()
// TODO response
server.on("/stats", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("application/json");
- DynamicJsonDocument root(1024);
+ DynamicJsonDocument doc(1024); // TODO
- root["heap"] = ESP.getFreeHeap();
- root["wifi"] = WiFi.SSID();
- root["sleep"] = 97;
+ doc["wifi"]["ssid"] = WiFi.SSID();
+ doc["wifi"]["connected"] = WiFi.isConnected();
+ doc["wifi"]["ip"] = WiFi.localIP();
+ doc["wifi"]["mac"] = WiFi.macAddress();
+ doc["wifi"]["channel"] = WiFi.channel();
+ doc["wifi"]["dns"] = WiFi.dnsIP();
+ doc["wifi"]["gateway"] = WiFi.gatewayIP();
- serializeJson(root, *response);
+ doc["device"]["heap"] = ESP.getFreeHeap();
+ doc["device"]["bootCycle"] = deviceGetBootCount();
+ doc["device"]["screen"]["width"] = 640;
+ doc["device"]["height"]["screen"] = 384;
+
+ JsonArray capability = doc.createNestedArray("capability");
+ capability.add("png");
+ capability.add("wbmp");
+
+ doc["cloud"]["sleep"] = deviceGetSleepInterval();
+
+ serializeJson(doc, *response);
request->send(response);
});
@@ -65,10 +81,11 @@ void setupSettingsGet()
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
- //root["wifi_ssid"] = NVS.getString("wifi_ssid");
root["device_mode"] = NVS.getString("device_mode");
root["device_rotation"] = 0;
root["cloud_server"] = NVS.getString("cloud_server");
+ root["cloud_uuid"] = NVS.getString("cloud_uuid");
+ root["cloud_user"] = NVS.getString("cloud_user");
serializeJson(root, *response);
request->send(response);
@@ -96,6 +113,12 @@ void setupSettingsPost()
NVS.setString("cloud_server", doc["cloud_server"]);
//Serial.println(doc["cloud_server"].as());
}
+ if (doc.containsKey("cloud_uuid")) {
+ NVS.setString("cloud_uuid", doc["cloud_uuid"]);
+ }
+ if (doc.containsKey("cloud_user")) {
+ NVS.setString("cloud_user", doc["cloud_user"]);
+ }
request->send(200, "application/ld+json; charset=utf-8", "{}");
} });
@@ -104,15 +127,15 @@ void setupSettingsPost()
/**
* @todo
*/
-
void setupCurrentImage()
{
server.on("/current-image", HTTP_GET, [](AsyncWebServerRequest *request) {
Serial.println("/current-image");
- request->send(SPIFFS, "/currentImage.bin", "image/x-bmp");
+ //request->send(SPIFFS, "/currentImage.bin", "image/x-bmp");
+ request->send(SPIFFS, "/blackPNG.png");
});
-/*
+ /*
server.on("/current-image2", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/currentImage.bin", "image/x-bmp"); // image/x-bmp | image/vnd.wap.wbmp
//response->addHeader("Content-Encoding", "gzip");
@@ -173,9 +196,8 @@ void setupWifiScan()
*/
void setupWifiConnect()
{
- server.on("/api/wifi/connect", HTTP_PUT, [](AsyncWebServerRequest *request) { /* nothing and dont remove it */ }, NULL, [](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
+ server.on("/api/wifi/connect", HTTP_POST, [](AsyncWebServerRequest *request) { /* nothing and dont remove it */ }, NULL, [](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
DynamicJsonDocument doc(1024);
- Serial.println("/api/wifi/connect");
DeserializationError error = deserializeJson(doc, data);
if (error) {
@@ -186,14 +208,17 @@ void setupWifiConnect()
}
else
{
- if (doc.containsKey("user")) {
- //NVS.setString("device_mode", doc["device_mode"]);
+ if (doc.containsKey("ssid")) {
+ NVS.setString("wifi_ssid", doc["ssid"]);
+ Serial.println(doc["ssid"].as());
}
if (doc.containsKey("password")) {
- //NVS.setString("cloud_server", doc["cloud_server"]);
- //Serial.println(doc["cloud_server"].as());
+ NVS.setString("wifi_password", doc["password"]);
+ Serial.println(doc["password"].as());
}
request->send(200, "application/ld+json; charset=utf-8", "{}");
+
+ ESP.restart();
} });
}
\ No newline at end of file
diff --git a/src/device.cpp b/src/device.cpp
index a35a8dd..7d48d92 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -2,7 +2,7 @@
#include "settings.h"
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
-RTC_DATA_ATTR int bootCount = 0;
+RTC_DATA_ATTR unsigned int bootCount = 0;
RTC_DATA_ATTR long config_DeepSleepInterval = 10; // sec
unsigned long bootTime = 0;
@@ -53,6 +53,12 @@ long deviceGetSleepInterval()
return config_DeepSleepInterval;
}
+unsigned int deviceGetBootCount()
+{
+ return bootCount;
+}
+
+
bool isBootTimeOver()
{
return millis() - bootTime >= 60000;
diff --git a/src/imageWBMP.cpp b/src/imageWBMP.cpp
index 8b4a258..589780b 100644
--- a/src/imageWBMP.cpp
+++ b/src/imageWBMP.cpp
@@ -23,7 +23,6 @@ void wbmpOpenFramebuffer()
// TODO do it better :-)
void wbmpWriteFramebuffer(int offset, uint8_t bitmap[], int c)
{
- Serial.println("wbmpWriteFramebuffer");
for (int i = 0; i < c; i++)
{
_buffer[offset + i] = bitmap[i];
diff --git a/src/main.cpp b/src/main.cpp
index e25425c..8c9870d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,9 @@
#include "cloud.h"
#include "app.h"
+#include "imagePNG.h"
+#include "imageWBMP.h"
+
void gotoDeepSleep();
String getWakeupReason();
@@ -23,8 +26,13 @@ void setup()
Serial.println();
setupDisplay();
+
+ //setupImagePNG();
+ //setupImageWBMP();
+
setupSettings();
setupDevice();
+
setupWlan();
if (wlan_isConnected())
diff --git a/src/wlan.cpp b/src/wlan.cpp
index a598c9f..3dc0213 100644
--- a/src/wlan.cpp
+++ b/src/wlan.cpp
@@ -7,19 +7,14 @@ RTC_DATA_ATTR int wifiFailedCount = 0;
void initClientMode(const char *ssid, const char *password);
void initAPMode();
-
void setupWlan()
{
Serial.println("setup Wlan");
WiFi.setHostname(deviceName);
- //NVS.setString("wifi_ssid", "xd-design.info");
- //NVS.setString("wifi_password", "SonicHome");
-
// load wifi settings
- String ssid = NVS.getString("wifi_ssid");
- String password = NVS.getString("wifi_password");
-
+ String ssid = NVS.getString("wifi_ssid");
+ String password = NVS.getString("wifi_password");
// TODO count failed connecting wifiFailedCount <=3
if (!ssid.isEmpty() && !password.isEmpty()) // && wifiFailedCount <=3
@@ -36,13 +31,35 @@ void setupWlan()
Serial.println("setup Wlan - done");
}
+void ___connectToNetwork()
+{
+ uint8_t veces = 10;
+ WiFi.begin("ssid", "password");
+ Serial.println("Establishing connection to WiFi..");
+ while (WiFi.status() != WL_CONNECTED)
+ {
+ delay(1000);
+ Serial.println(veces);
+ if (!veces--)
+ {
+ veces = 10;
+ WiFi.disconnect();
+ Serial.println("Wifi reset...");
+ delay(1000);
+ WiFi.begin("ssid", "password");
+ Serial.println("Establishing connection to WiFi..");
+ }
+ }
+ Serial.println("Connected to network");
+}
void initClientMode(const char *ssid, const char *password)
{
+ uint8_t veces = 10;
long startMills = millis();
Serial.print(" Connecting to: ");
- Serial.print(ssid);
+ Serial.print(ssid);
// print try count
Serial.print(" (");
@@ -51,7 +68,25 @@ void initClientMode(const char *ssid, const char *password)
// connecting
WiFi.mode(WIFI_STA);
+
+
WiFi.begin(ssid, password);
+ while (WiFi.status() != WL_CONNECTED)
+ {
+ delay(500);
+ Serial.println(veces);
+ if (!veces--)
+ {
+ veces = 10;
+ WiFi.disconnect();
+ Serial.println("Wifi reset...");
+ delay(500);
+ WiFi.begin(ssid, password);
+ Serial.println("Establishing connection to WiFi..");
+ }
+ }
+
+ /*
while (WiFi.waitForConnectResult() != WL_CONNECTED)
{
wifiFailedCount++;
@@ -59,28 +94,27 @@ void initClientMode(const char *ssid, const char *password)
delay(100);
ESP.restart();
}
+ */
- Serial.println(" ...connected");
- Serial.print(" IP address: ");
- Serial.println(WiFi.localIP());
+ Serial.println(" ...connected");
+ Serial.print(" IP address: ");
+ Serial.println(WiFi.localIP());
Serial.print(" connected in: ");
Serial.println(millis() - startMills);
}
-
void initAPMode()
{
Serial.println(" init AP (Access Point)");
- WiFi.softAP(deviceName);
+ WiFi.softAP("paperdash.io");
IPAddress IP = WiFi.softAPIP();
- Serial.print(" AP IP address: ");
- Serial.println(IP);
+ Serial.print(" AP IP address: ");
+ Serial.println(IP);
}
-
bool wlan_isConnected()
{
return WiFi.isConnected();