ソースを参照

Rolling - fixed IP

jomjol 5 年 前
コミット
793f928e6e

+ 9 - 2
README.md

@@ -25,18 +25,26 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 **General remark:** Beside the `firmware.bin`, typically also the content of `/html` needs to be updated!
 
+##### Rolling - (2020-12-06)
+
+* Option for fixed IP settings in `wlan.ini` - description see inside file
+
+* based on v5.0.05 (2020-12-06)
+
+  
+
 ##### 5.0.0 Setup Modus - (2020-12-06)
 
 * Implementation of intial setup modus for fresh installation
 
 * Code restructuring (full compatibility between pure ESP-IDF and Platformio w/ espressif)
   
+  
 
 ##### 4.1.1 Configuration editor - (2020-12-02)
 
 * Bug fixing: internal improvement of file handling (reduce not responding)
 
-  
 
 ##### 4.1.0 Configuration editor - (2020-11-30)
 
@@ -52,7 +60,6 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 * Bug fixing: truncation error,  CheckDigitConsistency & PreValue implementation
 
-  
 
 
 ##### 4.0.0 Tflite Core - (2020-11-15)

+ 65 - 0
code/components/connect_wlan/connect_wlan.cpp

@@ -319,6 +319,71 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
     }
 }
 
+void LoadNetConfigFromFile(std::string fn, std::string &_ip, std::string &_gw, std::string &_netmask, std::string &_dns)
+{
+    string line = "";
+    std::vector<string> zerlegt;
+
+    FILE* pFile;
+    fn = FormatFileName(fn);
+    pFile = fopen(fn.c_str(), "r");
+
+    printf("file loaded\n");
+
+    if (pFile == NULL)
+        return;
+
+    char zw[1024];
+    fgets(zw, 1024, pFile);
+    line = std::string(zw);
+
+    while ((line.size() > 0) || !(feof(pFile)))
+    {
+        printf("%s", line.c_str());
+        zerlegt = ZerlegeZeile(line, "=");
+        zerlegt[0] = trim(zerlegt[0], " ");
+
+        if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "IP")){
+            _ip = zerlegt[1];
+            if ((_ip[0] == '"') && (_ip[_ip.length()-1] == '"')){
+                _ip = _ip.substr(1, _ip.length()-2);
+            }
+        }
+
+        if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "GATEWAY")){
+            _gw = zerlegt[1];
+            if ((_gw[0] == '"') && (_gw[_gw.length()-1] == '"')){
+                _gw = _gw.substr(1, _gw.length()-2);
+            }
+        }
+
+        if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "NETMASK")){
+            _netmask = zerlegt[1];
+            if ((_netmask[0] == '"') && (_netmask[_netmask.length()-1] == '"')){
+                _netmask = _netmask.substr(1, _netmask.length()-2);
+            }
+        }
+
+        if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "DNS")){
+            _dns = zerlegt[1];
+            if ((_dns[0] == '"') && (_dns[_dns.length()-1] == '"')){
+                _dns = _dns.substr(1, _dns.length()-2);
+            }
+        }
+
+        if (fgets(zw, 1024, pFile) == NULL)
+        {
+            line = "";
+        }
+        else
+        {
+            line = std::string(zw);
+        }
+    }
+
+    fclose(pFile);
+}
+
 
 std::string getHostname(){
     return hostname;

+ 1 - 1
code/components/connect_wlan/connect_wlan.h

@@ -11,7 +11,7 @@ void initialise_wifi_fixed_ip(std::string _ip, std::string _gw, std::string _net
 
 
 void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname);
-void LoadNetConfigFromFile(std::string &_ip, std::string &_gw, std::string &_netmask, std::string &_dns);
+void LoadNetConfigFromFile(std::string fn, std::string &_ip, std::string &_gw, std::string &_netmask, std::string &_dns);
 
 std::string getHostname();
 std::string getIPAddress();

+ 2 - 1
code/main/main.cpp

@@ -88,11 +88,12 @@ extern "C" void app_main(void)
 
 //    LoadWlanFromFile("/sdcard/wlan.ini", ssid, password, hostname, ip, gw, netmask, dns); 
     LoadWlanFromFile("/sdcard/wlan.ini", ssid, password, hostname); 
+    LoadNetConfigFromFile("/sdcard/wlan.ini", ip, gw, netmask, dns);
 
 //    LogFile.WriteToFile("Startsequence 04");    
     printf("To use WLan: %s, %s\n", ssid.c_str(), password.c_str());
     printf("To set Hostename: %s\n", hostname.c_str());
-    printf("Fixed IP: %s, Gateway %s, Netmask %s\n", ip.c_str(), gw.c_str(), netmask.c_str());
+    printf("Fixed IP: %s, Gateway %s, Netmask %s, DNS %s\n", ip.c_str(), gw.c_str(), netmask.c_str(), dns.c_str());
    
     if (ip.length() == 0 || gw.length() == 0 || netmask.length() == 0)
     {

+ 3 - 3
code/main/version.cpp

@@ -1,4 +1,4 @@
-const char* GIT_REV="bcdd0c6";
+const char* GIT_REV="a8fb2e3";
 const char* GIT_TAG="";
-const char* GIT_BRANCH="master";
-const char* BUILD_TIME="2020-12-06 19:32";
+const char* GIT_BRANCH="rolling";
+const char* BUILD_TIME="2020-12-06 21:10";

+ 3 - 3
code/version.cpp

@@ -1,4 +1,4 @@
-const char* GIT_REV="bcdd0c6";
+const char* GIT_REV="a8fb2e3";
 const char* GIT_TAG="";
-const char* GIT_BRANCH="master";
-const char* BUILD_TIME="2020-12-06 19:32";
+const char* GIT_BRANCH="rolling";
+const char* BUILD_TIME="2020-12-06 21:10";

BIN
firmware/bootloader.bin


BIN
firmware/firmware.bin


+ 9 - 1
sd-card/wlan.ini

@@ -1,4 +1,12 @@
 ssid = "SSID"
 password = "PASSWORD"
 hostname = "watermeter"
-;hostname is optional
+;hostname is optional
+
+;if you want to use a fixed IP you need to specify the following 3 parameters (ip, gateway, netmask) with IP4-Addresses "123.456.789.012"
+ip = "IP4-ADDRESS"
+gateway = "IP4-ADDRESS"
+netmask = "255.255.255.0"
+
+;in some cases you want to specify the DNS server as well (especially, if it is not identical to the gateway - this is optional for a fixed IP
+dns = "IP4-ADDRESS"