@ -6,6 +6,8 @@ bool update_status = false;
bool opened = false ;
File root ;
String header_html_str = " <html><meta charset= \" UTF-8 \" ><title>SimpleRX</title><meta name= \" viewport \" content= \" width=device-width,initial-scale=1 \" ><body><pre> " ;
WEB : : WEB ( void ) {
}
@ -18,50 +20,69 @@ void WEB::begin(void) {
// File html_handler = LITTLEFS.open("/index.html.gz", FILE_READ);
// server.streamFile(html_handler, "text/html");
// html_handler.close();
server . send ( 200 , " text/html " , " SimpleRX 0.1 " ) ;
String index_html_str = header_html_str + " <b>SimpleRX v " + String ( VERSION_MAJOR ) + " . " + String ( VERSION_MINOR ) + String ( VERSION_BUILD ) + " \n \n [ MAIN ] \n </b><hr>CPU: " + String ( ESP . getCpuFreqMHz ( ) ) + " MHz \n " ;
index_html_str = index_html_str + " NRF Channel: " + String ( rx . getChannel ( ) ) ;
server . send ( 200 , " text/html " , index_html_str ) ;
server . sendHeader ( " Connection " , " close " ) ;
} ) ;
/*** Temporary disable update for ESP8266
// Update
server . on ( " /update " , HTTP_POST , [ ] ( ) {
server . sendHeader ( " Connection " , " close " ) ;
server . send ( 200 , " text/plain " , ( Update . hasError ( ) ) ? " FAIL " : " OK. Device is rebooting " ) ;
// Multiple configuration
server . on ( " /set " , HTTP_GET , [ ] ( ) {
bool update_channel = false ;
uint8_t channel_raw = 0 ;
String msg = " " ;
if ( Update . hasError ( ) ) {
update_status = false ;
// web.set_update_status(false);
} else {
delay ( 1000 ) ;
ESP . restart ( ) ;
// Server parameters
for ( uint8_t i = 0 ; i < server . args ( ) ; i + + ) {
String value = server . arg ( i ) ;
if ( server . argName ( i ) = = " channel " ) {
channel_raw = value . toInt ( ) ;
update_channel = true ;
}
}
} , [ ] ( ) {
HTTPUpload & upload = server . upload ( ) ;
if ( ! update_status )
update_status = true ;
if ( upload . status = = UPLOAD_FILE_START ) {
Serial . printf ( " Update: %s \n " , upload . filename . c_str ( ) ) ;
if ( update_channel ) {
// Making sure is channel 1 ~ 125.
if ( channel_raw > 0 & & channel_raw < 126 ) {
String filename = " /NRF_CHANNEL " ;
msg = " CHANNEL SET: " + String ( channel_raw ) ;
storage . writeFile ( LittleFS , filename , String ( channel_raw ) ) ;
//// File file = LittleFS.open(filename, "w+");
//// file.println(channel_raw);
//// file.close();
channel = channel_raw ;
rx . setChannel ( channel ) ; // Instant Change
} else {
msg = " ERROR UPDATE CHANNEL " ;
}
}
// Start with maximum available size
if ( ! Update . begin ( UPDATE_SIZE_UNKNOWN ) )
Update . printError ( Serial ) ;
} else if ( upload . status = = UPLOAD_FILE_WRITE ) {
// Flashing firmware to ESP
if (
Update . write ( upload . buf , upload . currentSize ) ! = upload . currentSize
)
Update . printError ( Serial ) ;
String index_html_str = header_html_str + msg ;
server . sendHeader ( " Connection " , " close " ) ;
server . send ( 200 , " text/html " , index_html_str ) ;
} ) ;
} else if ( upload . status = = UPLOAD_FILE_END ) {
if ( Update . end ( true ) )
// True to set the size to the current progress
Serial . printf ( " Update Success: %u \n Rebooting... \n " , upload . totalSize ) ;
else
Update . printError ( Serial ) ;
// Getting configuration
server . on ( " /get " , HTTP_GET , [ ] ( ) {
bool update_channel = false ;
uint8_t channel_raw = 0 ;
String msg = " " ;
// Server parameters
for ( uint8_t i = 0 ; i < server . args ( ) ; i + + ) {
String value = server . arg ( i ) ;
if ( server . argName ( i ) = = " channel " ) {
String filename = " /NRF_CHANNEL " ;
msg = storage . readFile ( LittleFS , filename ) ;
msg = " Channel (From FILE): " + msg ;
}
}
String index_html_str = header_html_str + msg ;
server . sendHeader ( " Connection " , " close " ) ;
server . send ( 200 , " text/html " , index_html_str ) ;
} ) ;
* * */
// Reset
server . on ( " /reset " , HTTP_GET , [ ] ( ) {
@ -76,7 +97,7 @@ void WEB::begin(void) {
// Reboot
server . on ( " /reboot " , HTTP_GET , [ ] ( ) {
server . sendHeader ( " Connection " , " close " ) ;
server . send ( 200 , " text/html " , " 1 " ) ;
server . send ( 200 , " text/html " , " Rebooting... " ) ;
delay ( 1000 ) ;
ESP . restart ( ) ;
} ) ;