moved wifi stuff into its own file, cosmetic things wifi page
This commit is contained in:
parent
825f2e8e19
commit
827c8cd184
5 changed files with 117 additions and 75 deletions
|
@ -85,6 +85,7 @@
|
||||||
|
|
||||||
#include "include/CanGrow.h"
|
#include "include/CanGrow.h"
|
||||||
#include "include/CanGrow_Core.h"
|
#include "include/CanGrow_Core.h"
|
||||||
|
#include "include/CanGrow_Wifi.h"
|
||||||
#include "include/CanGrow_LittleFS.h"
|
#include "include/CanGrow_LittleFS.h"
|
||||||
#include "include/CanGrow_Webserver.h"
|
#include "include/CanGrow_Webserver.h"
|
||||||
|
|
||||||
|
@ -131,17 +132,9 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LFS_init();
|
LFS_Init();
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
|
Wifi_Init();
|
||||||
if(strlen(configWifi.ssid) == 0) {
|
|
||||||
Serial.println(":: [SETUP] configWifi.ssid is empty, creating access point");
|
|
||||||
WifiAP();
|
|
||||||
} else {
|
|
||||||
Serial.printf(":: [SETUP] configWifi.ssid is set, connecting to ssid: %s\n", configWifi.ssid);
|
|
||||||
WifiConnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
SetupWebserver();
|
SetupWebserver();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,43 +55,4 @@ char* IP2Char(IPAddress ipaddr){
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiConnect() {
|
|
||||||
Serial.printf(":: [WiFi] connecting to ssid: %s\n", configWifi.ssid);
|
|
||||||
WiFi.begin(configWifi.ssid, configWifi.password);
|
|
||||||
if(configWifi.dhcp == false) {
|
|
||||||
Serial.println(":: [WiFi] using static ip configuration:");
|
|
||||||
Serial.printf(":: [WiFi] IP : %s\n", IP2Char(configWifi.ip));
|
|
||||||
Serial.printf(":: [WiFi] Netmask: %s\n", IP2Char(configWifi.netmask));
|
|
||||||
Serial.printf(":: [WiFi] Gateway: %s\n", IP2Char(configWifi.gateway));
|
|
||||||
Serial.printf(":: [WiFi] DNS : %s\n", IP2Char(configWifi.dns));
|
|
||||||
|
|
||||||
WiFi.config(configWifi.ip, configWifi.dns, configWifi.gateway, configWifi.netmask);
|
|
||||||
} else {
|
|
||||||
Serial.println(":: [WiFi] using DHCP for ip configuration");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.print(":: [WiFi] ");
|
|
||||||
// wait until WiFi connection is established
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
delay(500);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
Serial.println("CONNECTED!");
|
|
||||||
|
|
||||||
if(configWifi.dhcp == true) {
|
|
||||||
Serial.println(":: [WiFi] DHCP offered ip configuration:");
|
|
||||||
Serial.printf(":: [WiFi] IP : %s\n", IP2Char(WiFi.localIP()));
|
|
||||||
Serial.printf(":: [WiFi] Netmask: %s\n", IP2Char(WiFi.subnetMask()));
|
|
||||||
Serial.printf(":: [WiFi] Gateway: %s\n", IP2Char(WiFi.gatewayIP()));
|
|
||||||
Serial.printf(":: [WiFi] DNS : %s\n", IP2Char(WiFi.dnsIP()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WifiAP() {
|
|
||||||
Serial.printf(":: [WiFi] create access point: %s\n", CANGROW_SSID);
|
|
||||||
WiFi.softAPConfig(configWifi.ip, configWifi.gateway, configWifi.netmask);
|
|
||||||
WiFi.softAP(CANGROW_SSID);
|
|
||||||
Serial.print(":: [WiFi] access point started with IP: ");
|
|
||||||
Serial.println(WiFi.softAPIP());
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
// LittleFS auto format
|
// LittleFS auto format
|
||||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||||
|
|
||||||
void LFS_init() {
|
void LFS_Init() {
|
||||||
Serial.println(":: [LittleFS] initializing");
|
Serial.println(":: [LittleFS] initializing");
|
||||||
// ESP8266 crashes with first argument set
|
// ESP8266 crashes with first argument set
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
|
|
81
Arduino/CanGrow/include/CanGrow_Wifi.h
Normal file
81
Arduino/CanGrow/include/CanGrow_Wifi.h
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* include/CanGrow_Wifi.h - Wifi stuff header file
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 DeltaLima
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void Wifi_Connect() {
|
||||||
|
Serial.printf(":: [WiFi] connecting to ssid: %s\n", configWifi.ssid);
|
||||||
|
WiFi.begin(configWifi.ssid, configWifi.password);
|
||||||
|
if(configWifi.dhcp == false) {
|
||||||
|
Serial.println(":: [WiFi] using static ip configuration:");
|
||||||
|
Serial.printf(":: [WiFi] IP : %s\n", IP2Char(configWifi.ip));
|
||||||
|
Serial.printf(":: [WiFi] Netmask: %s\n", IP2Char(configWifi.netmask));
|
||||||
|
Serial.printf(":: [WiFi] Gateway: %s\n", IP2Char(configWifi.gateway));
|
||||||
|
Serial.printf(":: [WiFi] DNS : %s\n", IP2Char(configWifi.dns));
|
||||||
|
|
||||||
|
WiFi.config(configWifi.ip, configWifi.dns, configWifi.gateway, configWifi.netmask);
|
||||||
|
} else {
|
||||||
|
Serial.println(":: [WiFi] using DHCP for ip configuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print(":: [WiFi] ");
|
||||||
|
// wait until WiFi connection is established
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("CONNECTED!");
|
||||||
|
|
||||||
|
if(configWifi.dhcp == true) {
|
||||||
|
Serial.println(":: [WiFi] DHCP offered ip configuration:");
|
||||||
|
Serial.printf(":: [WiFi] IP : %s\n", IP2Char(WiFi.localIP()));
|
||||||
|
Serial.printf(":: [WiFi] Netmask: %s\n", IP2Char(WiFi.subnetMask()));
|
||||||
|
Serial.printf(":: [WiFi] Gateway: %s\n", IP2Char(WiFi.gatewayIP()));
|
||||||
|
Serial.printf(":: [WiFi] DNS : %s\n", IP2Char(WiFi.dnsIP()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wifi_AP() {
|
||||||
|
Serial.printf(":: [WiFi] create access point: %s\n", CANGROW_SSID);
|
||||||
|
WiFi.softAPConfig(configWifi.ip, configWifi.gateway, configWifi.netmask);
|
||||||
|
WiFi.softAP(CANGROW_SSID);
|
||||||
|
Serial.print(":: [WiFi] access point started with IP: ");
|
||||||
|
Serial.println(WiFi.softAPIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wifi_Init() {
|
||||||
|
Serial.println(":: [WiFi] initializing");
|
||||||
|
if(strlen(configWifi.ssid) == 0) {
|
||||||
|
Serial.println(":: [WiFi] no value found in configWifi.ssid, creating access point");
|
||||||
|
Wifi_AP();
|
||||||
|
} else {
|
||||||
|
Serial.printf(":: [SETUP] value found in configWifi.ssid, connecting to SSID: %s\n", configWifi.ssid);
|
||||||
|
Wifi_Connect();
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,48 +36,55 @@ const char* Page_wifi_HTML PROGMEM = R"(%HEADER%
|
||||||
<p>Select your wifi network from the SSID list.
|
<p>Select your wifi network from the SSID list.
|
||||||
<br>Reload the page, if your network is not listed.</p>
|
<br>Reload the page, if your network is not listed.</p>
|
||||||
<form method='post' action='/wifiSettings/save'>
|
<form method='post' action='/wifiSettings/save'>
|
||||||
SSID: <select id='configWifi.ssid' name='configWifi.ssid' required>
|
|
||||||
|
<u>SSID</u>:<br>
|
||||||
|
<select id='configWifi.ssid' name='configWifi.ssid' required>
|
||||||
<option disabled value='' selected hidden>-Select your network-</option>
|
<option disabled value='' selected hidden>-Select your network-</option>
|
||||||
|
|
||||||
%WIFI_LIST%
|
%WIFI_LIST%
|
||||||
|
|
||||||
</select><br>
|
</select><br>
|
||||||
|
|
||||||
Password: <input type='password' name='configWifi.password'><br>
|
<u>Password</u>:<br>
|
||||||
|
<input type='password' name='configWifi.password'><br>
|
||||||
|
|
||||||
IP: <input class='inputShort' type='number' min='0' max='255' name='configWifi.ip0'> .
|
<u>DHCP</u>:<br>
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip1'> .
|
<select name='configWifi.dhcp' required>
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip2'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip3'><br>
|
|
||||||
|
|
||||||
Subnet mask: <input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask0'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask1'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask2'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask3'><br>
|
|
||||||
|
|
||||||
Gateway: <input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway0'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway1'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway2'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway3'><br>
|
|
||||||
|
|
||||||
DNS: <input class='inputShort' type='number' min='0' max='255' name='configWifi.dns0'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns1'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns2'> .
|
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns3'><br>
|
|
||||||
|
|
||||||
|
|
||||||
DHCP: <select name='configWifi.dhcp' required>
|
|
||||||
<option disabled value='' selected hidden>---</option>
|
<option disabled value='' selected hidden>---</option>
|
||||||
<option value='1'>On</option>
|
<option value='1'>On</option>
|
||||||
<option value='0'>Off</option>
|
<option value='0'>Off</option>
|
||||||
</select><br>
|
</select><br>
|
||||||
|
|
||||||
|
<u>IP</u>:<br>
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip0'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip1'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip2'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip3'><br>
|
||||||
|
|
||||||
|
<u>Netmask</u>:<br>
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask0'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask1'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask2'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask3'><br>
|
||||||
|
|
||||||
|
<u>Gateway</u>:<br>
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway0'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway1'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway2'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway3'><br>
|
||||||
|
|
||||||
|
<u>DNS</u>:<br>
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns0'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns1'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns2'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns3'><br>
|
||||||
|
|
||||||
|
|
||||||
<input type='submit' value='💾 Save settings'>
|
<input type='submit' value='💾 Save settings'>
|
||||||
</form>
|
</form>
|
||||||
%FOOTER%)";
|
%FOOTER%)";
|
||||||
|
|
||||||
const char* Page_wifi_HTML_CURRENT_SETTINGS PROGMEM = R"(<u>Current Settings:</u><br>WiFi SSID: <b>%CONFIGWIFI_SSID%</b><br>
|
const char* Page_wifi_HTML_CURRENT_SETTINGS PROGMEM = R"(<b><u>Current Settings:</u></b><br>WiFi SSID: <b>%CONFIGWIFI_SSID%</b><br>
|
||||||
Use DHCP: <b>%CONFIGWIFI_DHCP%</b><br>
|
Use DHCP: <b>%CONFIGWIFI_DHCP%</b><br>
|
||||||
IP address: <b>%CONFIGWIFI_IP%</b><br>
|
IP address: <b>%CONFIGWIFI_IP%</b><br>
|
||||||
Subnet mask: <b>%CONFIGWIFI_NETMASK%</b><br>
|
Subnet mask: <b>%CONFIGWIFI_NETMASK%</b><br>
|
||||||
|
|
Loading…
Reference in a new issue