Skip to content

Commit 408406c

Browse files
committed
starting diskinfo api
1 parent bca7d6e commit 408406c

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,46 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
828828
_send_chunk(socket, "");
829829
}
830830

831+
static void _reply_with_diskinfo_json(socketpool_socket_obj_t *socket, _request *request) {
832+
_send_str(socket, OK_JSON);
833+
_cors_header(socket, request);
834+
_send_str(socket, "\r\n");
835+
mp_print_t _socket_print = {socket, _print_chunk};
836+
837+
const char *hostname = "";
838+
#if CIRCUITPY_MDNS
839+
if (!common_hal_mdns_server_deinited(&mdns)) {
840+
hostname = common_hal_mdns_server_get_hostname(&mdns);
841+
}
842+
#endif
843+
_update_encoded_ip();
844+
// Note: this leverages the fact that C concats consecutive string literals together.
845+
mp_printf(&_socket_print,
846+
"{\"web_api_version\": 1, "
847+
"\"version\": \"" MICROPY_GIT_TAG "\", "
848+
"\"build_date\": \"" MICROPY_BUILD_DATE "\", "
849+
"\"board_name\": \"" MICROPY_HW_BOARD_NAME "\", "
850+
"\"mcu_name\": \"" MICROPY_HW_MCU_NAME "\", "
851+
"\"board_id\": \"" CIRCUITPY_BOARD_ID "\", "
852+
"\"creator_id\": %u, "
853+
"\"creation_id\": %u, "
854+
"\"hostname\": \"%s\", "
855+
"\"port\": %d, ", CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded);
856+
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
857+
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
858+
common_hal_mcu_processor_get_uid(raw_id);
859+
mp_printf(&_socket_print, "\"UID\": \"");
860+
for (uint8_t i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
861+
mp_printf(&_socket_print, "%02X", raw_id[i]);
862+
}
863+
mp_printf(&_socket_print, "\", ");
864+
#endif
865+
mp_printf(&_socket_print, "\"ip\": \"%s\"}", _our_ip_encoded);
866+
// Empty chunk signals the end of the response.
867+
_send_chunk(socket, "");
868+
}
869+
870+
831871
// FATFS has a two second timestamp resolution but the BLE API allows for nanosecond resolution.
832872
// This function truncates the time the time to a resolution storable by FATFS and fills in the
833873
// FATFS encoded version into fattime.
@@ -1228,6 +1268,8 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
12281268
_reply_with_devices_json(socket, request);
12291269
} else if (strcmp(path, "/version.json") == 0) {
12301270
_reply_with_version_json(socket, request);
1271+
} else if (strcmp(path, "/diskinfo.json") == 0) {
1272+
_reply_with_diskinfo_json(socket, request);
12311273
} else if (strcmp(path, "/serial/") == 0) {
12321274
if (!request->authenticated) {
12331275
if (_api_password[0] != '\0') {

0 commit comments

Comments
 (0)