diff --git a/MKS_WIFI_source.ino b/MKS_WIFI_source.ino index 914c5af..3fb7e17 100644 --- a/MKS_WIFI_source.ino +++ b/MKS_WIFI_source.ino @@ -38,11 +38,11 @@ #include #endif -// #define ENABLE_CORS +#define ENABLE_CORS // #define EXTENDED_API -// #define MKSWIFI_DEBUG +#define MKSWIFI_DEBUG // Define where debug output will be printed. #define DEBUG_PRINTER Serial1 @@ -71,12 +71,12 @@ extern "C" { } -char* firmwareVersion = "MISCHIANTI_v1.1"; +char* firmwareVersion = "MISCHIANTI_v1.2"; char M3_TYPE = TFT28; -#define CONFIG_FILE_HEAP 512 +#define CONFIG_FILE_HEAP 1024 boolean GET_VERSION_OK = false; @@ -120,7 +120,7 @@ uint32_t ip_static, subnet_static, gateway_staic, dns_static; #define LIST_MIN_LEN_SAVE_FILE 100 #define LIST_MAX_LEN_SAVE_FILE (1024 * 100) -char ssid[32], pass[64], webhostname[64]; +char ssid[32], pass[64], webhostname[64] = {"beeprint"}; //IPAddress sessions[MAX_LOGGED_IN_CLIENTS]; uint8_t loggedInClientsNum = 0; //MDNSResponder mdns; @@ -518,6 +518,11 @@ void postConfigFile() { uint8_t readBuf[postLength]; DynamicJsonDocument doc(postLength); + DEBUG_PRINT(F("POST LENGHT: ")); + DEBUG_PRINTLN((long)postLength); + DEBUG_PRINT(F("FREE: ")); + DEBUG_PRINTLN(ESP.getMaxFreeBlockSize()); + if((postLength > sizeof(readBuf)) || (postLength <= 0)) { server.send(400, FPSTR(STR_MIME_TEXT_PLAIN), FPSTR("Bad Request")); @@ -639,6 +644,142 @@ void net_env_prepare() server.onNotFound(fsHandler); } +// DEBUG_PRINT(F("Read file: ")); +// if (SPIFFS.exists(F("/mc/config.txt"))){ +// +// +// File configFile = SPIFFS.open(F("/mc/config.txt"), "r"); +// if (configFile){ +// // while (configFile.available()) +// // { +// // Serial1.write(configFile.read()); +// // } +// // +// DEBUG_PRINTLN(F("done.")); +// DynamicJsonDocument doc(CONFIG_FILE_HEAP); +// ArduinoJson::DeserializationError error = deserializeJson(doc, configFile); +// // close the file: +// configFile.close(); +// +// if (error){ +// // if the file didn't open, print an error: +// DEBUG_PRINT(F("Error parsing JSON ")); +// DEBUG_PRINTLN(error.c_str()); +// +// }else{ +// JsonObject rootObj = doc.as(); +//// JsonObject preferences = rootObj[F("preferences")]; +//// bool isGTM = preferences.containsKey(F("GTM")); +//// if (isGTM){ +//// JsonObject GTM = preferences[F("GTM")]; +//// bool isValue = GTM.containsKey(F("value")); +//// if (isValue){ +//// int value = GTM[F("value")]; +//// +//// DEBUG_PRINT(F("Impostazione GTM+")) +//// DEBUG_PRINTLN(value) +//// +//// // timeClient.setTimeOffset(value*60*60); +//// timeOffset = value*60*60; +//// } +//// } +//// +//// bool isDST = preferences.containsKey(F("DST")); +//// if (isDST){ +//// JsonObject DST = preferences[F("DST")]; +//// bool isCode = DST.containsKey(F("code")); +//// if (isCode){ +//// const String code = DST[F("code")]; +//// // const String desc = DST[F("description")]; +//// +//// codeDST = code; +//// DEBUG_PRINT(F("Impostazione DST ")) +//// DEBUG_PRINTLN(code) +//// // DEBUG_PRINT(F("Description DST ")) +//// // DEBUG_PRINTLN(desc) +//// +//// // timeClient.setTimeOffset(value*60*60); +//// // timeOffset = value*60*60; +//// } +//// }else{ +//// codeDST = "GTM"; +//// } +// +// JsonObject serverConfig = rootObj[F("server")]; +// bool isStatic = serverConfig[F("isStatic")]; +// if (isStatic==true){ +// const char* address = serverConfig[F("address")]; +// const char* gatway = serverConfig[F("gatway")]; +// const char* netMask = serverConfig[F("netMask")]; +// +// const char* dns1 = serverConfig[F("dns1")]; +// const char* dns2 = serverConfig[F("dns2")]; +// +// const char* _hostname = serverConfig[F("hostname")]; +// //start-block2 +// IPAddress _ip; +// bool parseSuccess; +// parseSuccess = _ip.fromString(address); +// if (parseSuccess) { +// DEBUG_PRINTLN(F("Address correctly parsed!")); +// } +// +// IPAddress _gw; +// parseSuccess = _gw.fromString(gatway); +// if (parseSuccess) { +// DEBUG_PRINTLN(F("Gatway correctly parsed!")); +// } +// +// IPAddress _sn; +// parseSuccess = _sn.fromString(netMask); +// if (parseSuccess) { +// DEBUG_PRINTLN(F("Subnet correctly parsed!")); +// } +// +// IPAddress _dns1; +// IPAddress _dns2; +// bool isDNS = false; +// if (dns1 && sizeof(_dns1) > 7 && dns2 && sizeof(_dns2) > 7 ){ +// parseSuccess = _dns1.fromString(dns1); +// if (parseSuccess) { +// DEBUG_PRINTLN(F("DNS 1 correctly parsed!")); +// isDNS = true; +// } +// +// parseSuccess = _dns2.fromString(dns2); +// if (parseSuccess) { +// DEBUG_PRINTLN(F("DNS 2 correctly parsed!")); +// } +// //end-block2 +// } +// +// DEBUG_PRINT(F("Set static data...")); +// if (isDNS){ +// WiFi.config(_ip, _gw, _sn, _dns1, _dns2); +// }else{ +// WiFi.config(_ip, _gw, _sn); +// } +//// +// if (_hostname && sizeof(_hostname)>1){ +//// strcpy(hostname, _hostname); +// if (!MDNS.begin(_hostname)) { // Start the mDNS responder for esp8266.local +// DEBUG_PRINTLN(F("Error setting up MDNS responder!")); +// } +// DEBUG_PRINTLN(F("mDNS responder started")); +// +// } +// // IPAddress(85, 37, 17, 12), IPAddress(8, 8, 8, 8) +// // +// // emailSend.setEMailLogin("smtp.mischianti@gmail.com"); +// DEBUG_PRINTLN(F("done.")); +// } +// } +// } +// }else{ +// DEBUG_PRINTLN(F("File not found!")); +// } + + server.servePrinter(true); @@ -695,7 +836,7 @@ void net_env_prepare() webSocket.begin(); webSocket.onEvent(webSocketEvent); - node_monitor.begin(UDP_PORT); + node_monitor.begin(UDP_PORT); } @@ -3265,7 +3406,9 @@ bool TryToConnect() { EEPROM.get(BAK_ADDRESS_WIFI_MODE, wifi_mode); EEPROM.get(BAK_ADDRESS_WEB_HOST, webhostname); - //wifi_station_set_hostname(webhostname); // must do thia before calling WiFi.begin() + wifi_station_set_hostname(webhostname); // must do thia before calling WiFi.begin() + + } else @@ -3338,7 +3481,16 @@ bool TryToConnect() WiFi.begin(ssid, pass); + if(eeprom_valid[0] == 0x0a && webhostname && sizeof(webhostname)>1 && sizeof(webhostname)<50) + { + DEBUG_PRINT(F("mDNS hostname:")); + DEBUG_PRINTLN(webhostname); + if (!MDNS.begin(webhostname)) { // Start the mDNS responder for esp8266.local + DEBUG_PRINTLN(F("Error setting up MDNS responder!")); + } + DEBUG_PRINTLN(F("mDNS responder started")); + } while (WiFi.status() != WL_CONNECTED) { @@ -3439,7 +3591,9 @@ uint8_t refreshApWeb() wifiConfigHtml += F("

");wifiConfigHtml += F("
"); #endif wifiConfigHtml = F("MKS WIFI"); - wifiConfigHtml += F("

www.mischianti.org

MKS WIFI MISCHIANTI v0.1


Update

"); + wifiConfigHtml += F("

www.mischianti.org

MKS WIFI MISCHIANTI"); + wifiConfigHtml += firmwareVersion; + wifiConfigHtml += F("


Update

"); wifiConfigHtml += F("
wifi firmware:
"); wifiConfigHtml += F("
To upload Web part restore the original firmware, upload MksWifi_WebView than upload new firmware.
"); // wifiConfigHtml += F("
web view:
"); @@ -3466,6 +3620,103 @@ void onWifiConfig() server.send(200, FPSTR(STR_MIME_TEXT_HTML), wifiConfigHtml); }); + server.on("/get_cfg_ip", HTTP_GET, []() { + DEBUG_PRINTLN(F("get_cfg_ip")); + + setCrossOrigin(); + + uint8_t isStatic = 0; + if (manual_valid == 0xa) { + isStatic = 1; + } + return server.send(200, FPSTR("application/json"), ("{\"ip\":\""+(IPAddress(ip_static).isSet()?IPAddress(ip_static).toString():"")+"\",\"sm\":\""+(IPAddress(subnet_static).isSet()?IPAddress(subnet_static).toString():"")+"\",\"gw\":\""+(IPAddress(gateway_staic).isSet()?IPAddress(gateway_staic).toString():"")+"\",\"dns1\":\""+(IPAddress(dns_static).isSet()?IPAddress(dns_static).toString():"")+"\",\"isStatic\":"+String(isStatic)+",\"webhostname\":\""+webhostname+"\"}")); + }); + + + server.on("/update_cfg_ip", HTTP_GET, []() { + //Serial.printf("on http post\n"); + + DEBUG_PRINTLN(F("update_cfg_ip")); + + setCrossOrigin(); + + if (server.args() <= 0) + { + server.send(500, FPSTR(STR_MIME_TEXT_PLAIN), F("Got no data, go back and retry")); + return; + } + + IPAddress ip; + IPAddress sm; + IPAddress gw; + IPAddress dns1; + + uint8_t isStatic = 255; + for (uint8_t e = 0; e < server.args(); e++) { + String argument = server.arg(e); + urldecode(argument); + if (server.argName(e) == "ip") ip.fromString(argument); + else if (server.argName(e) == "sm") sm.fromString(argument); + else if (server.argName(e) == "gw") gw.fromString(argument); + else if (server.argName(e) == "dns1") dns1.fromString(argument); + else if (server.argName(e) == "isStatic") isStatic = argument.toInt(); // 0xff disabled 0xa enabled + else if (server.argName(e) == "webhostname") argument.toCharArray(webhostname, 64); + } + + + ip_static = ip.v4(); + subnet_static = sm.v4(); + gateway_staic = gw.v4(); + dns_static = dns1.v4(); + + if (isStatic==0) { + manual_valid = 0xff; + } else if (isStatic==1) { + manual_valid = 0xa; + if (!(ip.isSet() && sm.isSet() && gw.isSet() && dns1.isSet())) { + return server.send(400, FPSTR(STR_MIME_APPLICATION_JSON), F("{\"msg\":\"Configure unsuccessfully! Wrong address value.\",\"error\":true,\"status\":\"KO\"}")); + + } + } + + DEBUG_PRINT(F("ip"));DEBUG_PRINTLN(ip_static); + DEBUG_PRINT(F("sm"));DEBUG_PRINTLN(subnet_static); + DEBUG_PRINT(F("gw"));DEBUG_PRINTLN(gateway_staic); + DEBUG_PRINT(F("dns"));DEBUG_PRINTLN(dns_static); + + DEBUG_PRINT(F("manual_valid"));DEBUG_PRINTLN(manual_valid); + + if (manual_valid == 0xff || manual_valid == 0xa) { + //Serial.printf("on http post:ready eeprom\n"); + + // char valid[1] = {0x0a}; + + EEPROM.put(BAK_ADDRESS_MANUAL_IP, ip_static); + EEPROM.put(BAK_ADDRESS_MANUAL_MASK, subnet_static); + EEPROM.put(BAK_ADDRESS_MANUAL_GATEWAY, gateway_staic); + EEPROM.put(BAK_ADDRESS_MANUAL_DNS, dns_static); + EEPROM.put(BAK_ADDRESS_MANUAL_IP_FLAG, manual_valid); + EEPROM.put(BAK_ADDRESS_WEB_HOST, webhostname); + + EEPROM.commit(); + + // EEPROM.put(BAK_ADDRESS_MANUAL_IP_FLAG, 0xff); + // manual_valid = 0xff; + // + // EEPROM.commit(); + + + //Serial.printf("on http post:ready send to client\n"); + server.send(200, FPSTR(STR_MIME_APPLICATION_JSON), F("{\"msg\":\"Configure successfully! Use new IP to connect.\",\"error\":false,\"status\":\"OK\"}")); + + + //Serial.printf("on http post:after commit\n"); + delay(300); + ESP.restart(); + } else { + server.send(400, FPSTR(STR_MIME_APPLICATION_JSON), F("{\"msg\":\"Configure unsuccessfully! Wrong Manual Flag.\",\"error\":true,\"status\":\"KO\"}")); + } + }); server.on("/update_cfg", HTTP_GET, []() { //Serial.printf("on http post\n"); @@ -3482,7 +3733,7 @@ void onWifiConfig() else if (server.argName(e) == "ssid") argument.toCharArray(ssid, 32);//ssid = server.arg(e); else if (server.argName(e) == "hidden_ssid") argument.toCharArray(hidden_ssid, 32);//ssid = server.arg(e); else if (server.argName(e) == "wifi_mode") argument.toCharArray(wifi_mode, 15);//ssid = server.arg(e); - //else if (server.argName(e) == "webhostname") argument.toCharArray(webhostname, 64); +// else if (server.argName(e) == "webhostname") argument.toCharArray(webhostname, 64); } /*if(hidden_ssid[0] != 0) diff --git a/MKS_WIFI_source.ino.nodemcu.bin b/MKS_WIFI_source.ino.nodemcu.bin new file mode 100644 index 0000000..dcdc4bf Binary files /dev/null and b/MKS_WIFI_source.ino.nodemcu.bin differ diff --git a/PooledStrings.cpp b/PooledStrings.cpp index 7234b91..d3ee3a3 100644 --- a/PooledStrings.cpp +++ b/PooledStrings.cpp @@ -1,3 +1,7 @@ +#ifndef POOLED_STRINGS_H +#define POOLED_STRINGS_H + + #include const char STR_EEPROM_DUMMY[] PROGMEM = "AAA"; const char STR_EEPROM_DEFAULT_WEBPASSWORD[] PROGMEM = "reprap"; @@ -26,4 +30,5 @@ const char STR_JSON_ERR_500_IS_UPLOADING_ALREADY[] PROGMEM = "{\"err\":\"ERROR 5 const char STR_JSON_ERR_500_IS_BUSY[] PROGMEM = "{\"err\":\"ERROR 500: IS BUSY\"}"; // End +#endif //POOLED_STRINGS_H diff --git a/README.md b/README.md index b2c94d8..c5112ce 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,13 @@ ![](data/launcher-icon-3x.png?raw=true) -Version 1.1 +Version 1.4 Thanks to Aleksandr Shell for the russian language translation. +Thanks to [reprapy](https://reprapy.pl/) for the polish language translation. ##### Changelog + - 2022-01-08 BeePrint 1.4 MKS WiFi 1.2 Static IP configuration, mDNS, polish translation and minor fix + - 2022-01-02 BeePrint 1.3 Polish language - 2021-12-30 BeePrint 1.2 Add GCode sender widget - 2021-12-14 BeePrint 1.1 Add Camera rotation features - 2021-12-03 BeePrint 1.0 Fix the mobile menu on WebView diff --git a/data/bundle.min.js.gz b/data/bundle.min.js.gz index b81d635..f76f3e6 100644 Binary files a/data/bundle.min.js.gz and b/data/bundle.min.js.gz differ diff --git a/data/settings.js b/data/settings.js index 631b931..444d789 100644 --- a/data/settings.js +++ b/data/settings.js @@ -1 +1 @@ -var settings = {"localDevIP":"192.168.1.161", "localRestPort":80, "localWSPort":8081}; +var settings = {"localDevIP":"192.168.1.171", "localRestPort":80, "localWSPort":8081}; diff --git a/firmware_release/MksWifi.bin b/firmware_release/MksWifi.bin index 2864a96..c48588f 100644 Binary files a/firmware_release/MksWifi.bin and b/firmware_release/MksWifi.bin differ diff --git a/firmware_release/MksWifi_WebView.bin b/firmware_release/MksWifi_WebView.bin index fa1bc13..7ddea3c 100644 Binary files a/firmware_release/MksWifi_WebView.bin and b/firmware_release/MksWifi_WebView.bin differ diff --git a/firmware_release/debug_cors/MksWifi.bin b/firmware_release/debug_cors/MksWifi.bin index f73af23..dcdc4bf 100644 Binary files a/firmware_release/debug_cors/MksWifi.bin and b/firmware_release/debug_cors/MksWifi.bin differ diff --git a/firmware_release/wv/MksWifi_1.1.bin b/firmware_release/wv/MksWifi_1.1.bin new file mode 100644 index 0000000..2864a96 Binary files /dev/null and b/firmware_release/wv/MksWifi_1.1.bin differ diff --git a/firmware_release/wv/MksWifi_WebView_1.2.bin b/firmware_release/wv/MksWifi_WebView_1.2.bin new file mode 100644 index 0000000..fa1bc13 Binary files /dev/null and b/firmware_release/wv/MksWifi_WebView_1.2.bin differ