@ -78,11 +78,11 @@ const char post_connected_html[] PROGMEM = R"=====(
< head >
< head >
< title > 01 OS Setup < / title >
< title > 01 OS Setup < / title >
< style >
< style >
* {
* {
box - sizing : border - box ;
box - sizing : border - box ;
}
}
body {
body {
background - color : # fff ;
background - color : # fff ;
margin : 0 ;
margin : 0 ;
@ -122,15 +122,15 @@ const char post_connected_html[] PROGMEM = R"=====(
input [ type = " submit " ] : hover {
input [ type = " submit " ] : hover {
background - color : # 333 ;
background - color : # 333 ;
}
}
# error_message {
# error_message {
color : red ;
color : red ;
font - weight : bold ;
font - weight : bold ;
text - align : center ;
text - align : center ;
width : 100 % ;
width : 100 % ;
margin - top : 20 px ;
margin - top : 20 px ;
max - width : 300 px ;
max - width : 300 px ;
}
}
< / style >
< / style >
@ -144,7 +144,7 @@ const char post_connected_html[] PROGMEM = R"=====(
< input type = " text " id = " server_address " name = " server_address " > < br > < br >
< input type = " text " id = " server_address " name = " server_address " > < br > < br >
< / div >
< / div >
< input type = " submit " value = " Connect " / >
< input type = " submit " value = " Connect " / >
< p id = " error_message " > < / p >
< p id = " error_message " > < / p >
@ -270,7 +270,7 @@ bool connectTo01OS(String server_address)
portStr = server_address . substring ( colonIndex + 1 ) ;
portStr = server_address . substring ( colonIndex + 1 ) ;
} else {
} else {
domain = server_address ;
domain = server_address ;
portStr = " " ;
portStr = " " ;
}
}
WiFiClient c ;
WiFiClient c ;
@ -281,7 +281,7 @@ bool connectTo01OS(String server_address)
port = portStr . toInt ( ) ;
port = portStr . toInt ( ) ;
}
}
HttpClient http ( c , domain . c_str ( ) , port ) ;
HttpClient http ( c , domain . c_str ( ) , port ) ;
Serial . println ( " Connecting to 01OS at " + domain + " : " + port + " /ping " ) ;
Serial . println ( " Connecting to 01OS at " + domain + " : " + port + " /ping " ) ;
if ( domain . indexOf ( " ngrok " ) ! = - 1 ) {
if ( domain . indexOf ( " ngrok " ) ! = - 1 ) {
@ -363,7 +363,7 @@ bool connectTo01OS(String server_address)
Serial . print ( " Connection failed: " ) ;
Serial . print ( " Connection failed: " ) ;
Serial . println ( err ) ;
Serial . println ( err ) ;
}
}
return connectionSuccess ;
return connectionSuccess ;
}
}
@ -436,7 +436,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
{
{
String ssid ;
String ssid ;
String password ;
String password ;
// Check if SSID parameter exists and assign it
// Check if SSID parameter exists and assign it
if ( request - > hasParam ( " ssid " , true ) ) {
if ( request - > hasParam ( " ssid " , true ) ) {
ssid = request - > getParam ( " ssid " , true ) - > value ( ) ;
ssid = request - > getParam ( " ssid " , true ) - > value ( ) ;
@ -446,7 +446,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
Serial . println ( " OTHER SSID SELECTED: " + ssid ) ;
Serial . println ( " OTHER SSID SELECTED: " + ssid ) ;
}
}
}
}
// Check if Password parameter exists and assign it
// Check if Password parameter exists and assign it
if ( request - > hasParam ( " password " , true ) ) {
if ( request - > hasParam ( " password " , true ) ) {
password = request - > getParam ( " password " , true ) - > value ( ) ;
password = request - > getParam ( " password " , true ) - > value ( ) ;
@ -458,7 +458,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
if ( request - > hasParam ( " password " , true ) & & request - > hasParam ( " ssid " , true ) ) {
if ( request - > hasParam ( " password " , true ) & & request - > hasParam ( " ssid " , true ) ) {
connectToWifi ( ssid , password ) ;
connectToWifi ( ssid , password ) ;
}
}
// Redirect user or send a response back
// Redirect user or send a response back
if ( WiFi . status ( ) = = WL_CONNECTED ) {
if ( WiFi . status ( ) = = WL_CONNECTED ) {
@ -466,7 +466,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
AsyncWebServerResponse * response = request - > beginResponse ( 200 , " text/html " , htmlContent ) ;
AsyncWebServerResponse * response = request - > beginResponse ( 200 , " text/html " , htmlContent ) ;
response - > addHeader ( " Cache-Control " , " public,max-age=31536000 " ) ; // save this file to cache for 1 year (unless you refresh)
response - > addHeader ( " Cache-Control " , " public,max-age=31536000 " ) ; // save this file to cache for 1 year (unless you refresh)
request - > send ( response ) ;
request - > send ( response ) ;
Serial . println ( " Served Post connection HTML Page " ) ;
Serial . println ( " Served Post connection HTML Page " ) ;
} else {
} else {
request - > send ( 200 , " text/plain " , " Failed to connect to " + ssid ) ;
request - > send ( 200 , " text/plain " , " Failed to connect to " + ssid ) ;
} } ) ;
} } ) ;
@ -474,7 +474,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
server . on ( " /submit_01os " , HTTP_POST , [ ] ( AsyncWebServerRequest * request )
server . on ( " /submit_01os " , HTTP_POST , [ ] ( AsyncWebServerRequest * request )
{
{
String server_address ;
String server_address ;
// Check if SSID parameter exists and assign it
// Check if SSID parameter exists and assign it
if ( request - > hasParam ( " server_address " , true ) ) {
if ( request - > hasParam ( " server_address " , true ) ) {
server_address = request - > getParam ( " server_address " , true ) - > value ( ) ;
server_address = request - > getParam ( " server_address " , true ) - > value ( ) ;
@ -490,7 +490,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
{
{
AsyncWebServerResponse * response = request - > beginResponse ( 200 , " text/html " , successHtml ) ;
AsyncWebServerResponse * response = request - > beginResponse ( 200 , " text/html " , successHtml ) ;
response - > addHeader ( " Cache-Control " , " no-cache, no-store, must-revalidate " ) ; // Prevent caching of this page
response - > addHeader ( " Cache-Control " , " no-cache, no-store, must-revalidate " ) ; // Prevent caching of this page
request - > send ( response ) ;
request - > send ( response ) ;
Serial . println ( " " ) ;
Serial . println ( " " ) ;
Serial . println ( " Connected to 01 websocket! " ) ;
Serial . println ( " Connected to 01 websocket! " ) ;
Serial . println ( " " ) ;
Serial . println ( " " ) ;
@ -502,7 +502,7 @@ void setUpWebserver(AsyncWebServer &server, const IPAddress &localIP)
String htmlContent = String ( post_connected_html ) ; // Load your HTML template
String htmlContent = String ( post_connected_html ) ; // Load your HTML template
// Inject the error message
// Inject the error message
htmlContent . replace ( " <p id= \" error_message \" ></p> " , " <p id= \" error_message \" style= \" color: red; \" >Error connecting, please try again.</p> " ) ;
htmlContent . replace ( " <p id= \" error_message \" ></p> " , " <p id= \" error_message \" style= \" color: red; \" >Error connecting, please try again.</p> " ) ;
AsyncWebServerResponse * response = request - > beginResponse ( 200 , " text/html " , htmlContent ) ;
AsyncWebServerResponse * response = request - > beginResponse ( 200 , " text/html " , htmlContent ) ;
response - > addHeader ( " Cache-Control " , " no-cache, no-store, must-revalidate " ) ; // Prevent caching of this page
response - > addHeader ( " Cache-Control " , " no-cache, no-store, must-revalidate " ) ; // Prevent caching of this page
request - > send ( response ) ;
request - > send ( response ) ;
@ -622,7 +622,7 @@ void InitI2SSpeakerOrMic(int mode)
# if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0)
# if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0)
. communication_format =
. communication_format =
I2S_COMM_FORMAT_STAND_I2S , // Set the format of the communication.
I2S_COMM_FORMAT_STAND_I2S , // Set the format of the communication.
# else
# else
. communication_format = I2S_COMM_FORMAT_I2S ,
. communication_format = I2S_COMM_FORMAT_I2S ,
# endif
# endif
. intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 ,
. intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 ,
@ -779,17 +779,17 @@ void setup() {
Serial . begin ( 115200 ) ; // Initialize serial communication at 115200 baud rate.
Serial . begin ( 115200 ) ; // Initialize serial communication at 115200 baud rate.
// Attempt to reconnect to WiFi using stored credentials.
// Attempt to reconnect to WiFi using stored credentials.
// Check if WiFi is connected but the server URL isn't stored
// Check if WiFi is connected but the server URL isn't stored
Serial . setTxBufferSize ( 1024 ) ; // Set the transmit buffer size for the Serial object.
Serial . setTxBufferSize ( 1024 ) ; // Set the transmit buffer size for the Serial object.
WiFi . mode ( WIFI_AP_STA ) ; // Set WiFi mode to both AP and STA.
WiFi . mode ( WIFI_AP_STA ) ; // Set WiFi mode to both AP and STA.
// delay(100); // Short delay to ensure mode change takes effect
// delay(100); // Short delay to ensure mode change takes effect
// WiFi.softAPConfig(localIP, gatewayIP, subnetMask);
// WiFi.softAPConfig(localIP, gatewayIP, subnetMask);
// WiFi.softAP(ssid, password);
// WiFi.softAP(ssid, password);
startSoftAccessPoint ( ssid , password , localIP , gatewayIP ) ;
startSoftAccessPoint ( ssid , password , localIP , gatewayIP ) ;
setUpDNSServer ( dnsServer , localIP ) ;
setUpDNSServer ( dnsServer , localIP ) ;
setUpWebserver ( server , localIP ) ;
setUpWebserver ( server , localIP ) ;
tryReconnectWiFi ( ) ;
tryReconnectWiFi ( ) ;
// Print a welcome message to the Serial port.
// Print a welcome message to the Serial port.
@ -823,7 +823,7 @@ void loop()
if ( ( millis ( ) - last_dns_ms ) > DNS_INTERVAL ) {
if ( ( millis ( ) - last_dns_ms ) > DNS_INTERVAL ) {
last_dns_ms = millis ( ) ; // seems to help with stability, if you are doing other things in the loop this may not be needed
last_dns_ms = millis ( ) ; // seems to help with stability, if you are doing other things in the loop this may not be needed
dnsServer . processNextRequest ( ) ; // I call this atleast every 10ms in my other projects (can be higher but I haven't tested it for stability)
dnsServer . processNextRequest ( ) ; // I call this atleast every 10ms in my other projects (can be higher but I haven't tested it for stability)
}
}
// Check WiFi connection status
// Check WiFi connection status
if ( WiFi . status ( ) = = WL_CONNECTED & & ! hasSetupWebsocket )
if ( WiFi . status ( ) = = WL_CONNECTED & & ! hasSetupWebsocket )
@ -865,4 +865,4 @@ void loop()
M5 . update ( ) ;
M5 . update ( ) ;
webSocket . loop ( ) ;
webSocket . loop ( ) ;
}
}
}
}