| 
									
										
										
										
											2020-05-24 23:44:04 +02:00
										 |  |  | #include <SystemStatus.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { | 
					
						
							|  |  |  |   server->on(SYSTEM_STATUS_SERVICE_PATH, | 
					
						
							|  |  |  |              HTTP_GET, | 
					
						
							|  |  |  |              securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1), | 
					
						
							|  |  |  |                                           AuthenticationPredicates::IS_AUTHENTICATED)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SystemStatus::systemStatus(AsyncWebServerRequest* request) { | 
					
						
							|  |  |  |   AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE); | 
					
						
							|  |  |  |   JsonObject root = response->getRoot(); | 
					
						
							|  |  |  | #ifdef ESP32
 | 
					
						
							|  |  |  |   root["esp_platform"] = "esp32"; | 
					
						
							|  |  |  |   root["max_alloc_heap"] = ESP.getMaxAllocHeap(); | 
					
						
							| 
									
										
										
										
											2020-06-21 23:02:07 +01:00
										 |  |  |   root["psram_size"] = ESP.getPsramSize(); | 
					
						
							|  |  |  |   root["free_psram"] = ESP.getFreePsram();   | 
					
						
							| 
									
										
										
										
											2020-05-24 23:44:04 +02:00
										 |  |  | #elif defined(ESP8266)
 | 
					
						
							|  |  |  |   root["esp_platform"] = "esp8266"; | 
					
						
							|  |  |  |   root["max_alloc_heap"] = ESP.getMaxFreeBlockSize(); | 
					
						
							| 
									
										
										
										
											2020-06-21 23:02:07 +01:00
										 |  |  |   root["heap_fragmentation"] = ESP.getHeapFragmentation(); | 
					
						
							| 
									
										
										
										
											2020-05-24 23:44:04 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |   root["cpu_freq_mhz"] = ESP.getCpuFreqMHz(); | 
					
						
							|  |  |  |   root["free_heap"] = ESP.getFreeHeap(); | 
					
						
							|  |  |  |   root["sketch_size"] = ESP.getSketchSize(); | 
					
						
							|  |  |  |   root["free_sketch_space"] = ESP.getFreeSketchSpace(); | 
					
						
							|  |  |  |   root["sdk_version"] = ESP.getSdkVersion(); | 
					
						
							|  |  |  |   root["flash_chip_size"] = ESP.getFlashChipSize(); | 
					
						
							|  |  |  |   root["flash_chip_speed"] = ESP.getFlashChipSpeed(); | 
					
						
							| 
									
										
										
										
											2020-05-25 11:00:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 11:35:03 +01:00
										 |  |  | // TODO - Ideally this class will take an *FS and extract the file system information from there.
 | 
					
						
							|  |  |  | // ESP8266 and ESP32 do not have feature parity in FS.h which currently makes that difficult.
 | 
					
						
							| 
									
										
										
										
											2020-05-25 11:00:42 +01:00
										 |  |  | #ifdef ESP32
 | 
					
						
							| 
									
										
										
										
											2020-07-19 19:32:08 +01:00
										 |  |  |   root["fs_total"] = ESPFS.totalBytes(); | 
					
						
							|  |  |  |   root["fs_used"] = ESPFS.usedBytes(); | 
					
						
							| 
									
										
										
										
											2020-05-25 11:00:42 +01:00
										 |  |  | #elif defined(ESP8266)
 | 
					
						
							|  |  |  |   FSInfo fs_info; | 
					
						
							| 
									
										
										
										
											2020-07-19 19:32:08 +01:00
										 |  |  |   ESPFS.info(fs_info); | 
					
						
							| 
									
										
										
										
											2020-05-25 11:04:13 +01:00
										 |  |  |   root["fs_total"] = fs_info.totalBytes; | 
					
						
							|  |  |  |   root["fs_used"] = fs_info.usedBytes; | 
					
						
							| 
									
										
										
										
											2020-05-25 11:00:42 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 23:44:04 +02:00
										 |  |  |   response->setLength(); | 
					
						
							|  |  |  |   request->send(response); | 
					
						
							|  |  |  | } |