Skip to content

Commit 3ffe7d9

Browse files
committed
WiFi network information & cleanup
1 parent 87df520 commit 3ffe7d9

17 files changed

Lines changed: 284 additions & 42 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Check out repository
2020
uses: actions/checkout@v4
2121
- run: make prepare
22-
- run: make build DEVICE=${{ matrix.device }}
22+
- run: make build DEVICE=${{ matrix.device }} FAT=1
2323
- run: mv build/${{ matrix.device }}/bootloader/*.bin build/${{ matrix.device }}/
2424
- run: mv build/${{ matrix.device }}/bootloader/*.elf build/${{ matrix.device }}/
2525
- run: mv build/${{ matrix.device }}/partition_table/*.bin build/${{ matrix.device }}/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SHELL := /usr/bin/env bash
1212

1313
DEVICE ?= tanmatsu # Default target device
1414
BUILD ?= build/$(DEVICE)
15-
FAT ?= 1
15+
FAT ?= 0 # Don't build and/or flash FAT partition by default
1616

1717
export IDF_TOOLS_PATH
1818
export IDF_GITHUB_ASSETS

main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ idf_component_register(
3535
"menu/rftest.c"
3636
"menu/menu_repository_client.c"
3737
"menu/menu_repository_client_project.c"
38+
"menu/menu_wifi_info.c"
3839

3940
# Fonts
4041
"chakrapetchmedium.c"

main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
badgeteam/custom-certificates:
1515
version: ">=1.1.0"
1616
nicolaielectronics/wifi-manager:
17-
version: ">=0.1.1"
17+
version: ">=0.2.0"
1818
espressif/esp_tinyusb:
1919
version: ^1.1
2020
rules:

main/menu/apps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void execute_app(pax_buf_t* buffer, gui_theme_t* theme, pax_vec2_t position, app
6969
{get_icon(ICON_F2), "Details"}, \
7070
{get_icon(ICON_F5), "Remove"}}), \
7171
4
72-
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "↑ / ↓ Navigate ⏎ Start app"}}), 1
72+
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "↑ / ↓ | ⏎ Start app"}}), 1
7373
#elif defined(CONFIG_BSP_TARGET_MCH2022)
7474
#define FOOTER_LEFT NULL, 0
7575
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "🅰 Start app"}}), 1

main/menu/home.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void execute_action(pax_buf_t* fb, menu_home_action_t action, gui_theme_t
6161
#if defined(CONFIG_BSP_TARGET_TANMATSU) || defined(CONFIG_BSP_TARGET_KONSOOL) || \
6262
defined(CONFIG_BSP_TARGET_HACKERHOTEL_2026)
6363
#define FOOTER_LEFT ((gui_element_icontext_t[]){{get_icon(ICON_F5), "Settings"}, {get_icon(ICON_F6), "USB mode"}}), 2
64-
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "↑ / ↓ / ← / → Navigate ⏎ Select"}}), 1
64+
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "↑ / ↓ / ← / → | ⏎ Select"}}), 1
6565
#elif defined(CONFIG_BSP_TARGET_MCH2022)
6666
#define FOOTER_LEFT NULL, 0
6767
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "🅰 Select"}}), 1

main/menu/menu_repository_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void render(pax_buf_t* buffer, gui_theme_t* theme, menu_t* menu, bool par
8080
buffer, theme, !partial, !partial || icons, !partial,
8181
((gui_element_icontext_t[]){{get_icon(ICON_REPOSITORY), "Repository"}}), 1,
8282
((gui_element_icontext_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "Back"}}), 2,
83-
((gui_element_icontext_t[]){{NULL, "↑ / ↓ Navigate ⏎ Select"}}), 1);
83+
((gui_element_icontext_t[]){{NULL, "↑ / ↓ | ⏎ Select"}}), 1);
8484
}
8585
menu_render(buffer, menu, position, theme, partial);
8686
display_blit_buffer(buffer);

main/menu/menu_repository_client_project.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void render(pax_buf_t* buffer, gui_theme_t* theme, menu_t* menu, bool par
5959
buffer, theme, !partial, !partial || icons, !partial,
6060
((gui_element_icontext_t[]){{get_icon(ICON_REPOSITORY), "Repository"}}), 1,
6161
((gui_element_icontext_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "Back"}}), 2,
62-
((gui_element_icontext_t[]){{NULL, "← / → Navigate ⏎ Select"}}), 1);
62+
((gui_element_icontext_t[]){{NULL, "← / → | ⏎ Select"}}), 1);
6363
}
6464

6565
// Description

main/menu/menu_wifi_info.c

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#include "about.h"
2+
#include "bsp/input.h"
3+
#include "common/display.h"
4+
#include "common/theme.h"
5+
#include "esp_netif_types.h"
6+
#include "esp_wifi.h"
7+
#include "esp_wifi_types_generic.h"
8+
#include "freertos/idf_additions.h"
9+
#include "gui_style.h"
10+
#include "icons.h"
11+
#include "lwipopts.h"
12+
#include "menu/message_dialog.h"
13+
#include "pax_fonts.h"
14+
#include "pax_gfx.h"
15+
#include "pax_matrix.h"
16+
#include "pax_text.h"
17+
#include "pax_types.h"
18+
#include "wifi_connection.h"
19+
20+
#if defined(CONFIG_BSP_TARGET_TANMATSU) || defined(CONFIG_BSP_TARGET_KONSOOL) || \
21+
defined(CONFIG_BSP_TARGET_HACKERHOTEL_2026)
22+
#define FOOTER_LEFT ((gui_element_icontext_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "Back"}}), 2
23+
#define FOOTER_RIGHT NULL, 0
24+
#elif defined(CONFIG_BSP_TARGET_MCH2022)
25+
#define FOOTER_LEFT NULL, 0
26+
#define FOOTER_RIGHT NULL, 0
27+
#else
28+
#define FOOTER_LEFT NULL, 0
29+
#define FOOTER_RIGHT NULL, 0
30+
#endif
31+
32+
extern bool wifi_stack_get_initialized(void);
33+
34+
static wifi_ap_record_t connected_ap = {0};
35+
36+
static bool get_connection_info(void) {
37+
bool radio_initialized = wifi_stack_get_initialized();
38+
wifi_mode_t mode = WIFI_MODE_NULL;
39+
if (radio_initialized && esp_wifi_get_mode(&mode) == ESP_OK) {
40+
if (mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) {
41+
if (wifi_connection_is_connected() && esp_wifi_sta_get_ap_info(&connected_ap) == ESP_OK) {
42+
return true;
43+
}
44+
}
45+
}
46+
return false;
47+
}
48+
49+
static const char* ip6_addr_type_to_string(esp_ip6_addr_type_t type) {
50+
switch (type) {
51+
case ESP_IP6_ADDR_IS_UNKNOWN:
52+
return "Unknown";
53+
case ESP_IP6_ADDR_IS_GLOBAL:
54+
return "Global";
55+
case ESP_IP6_ADDR_IS_LINK_LOCAL:
56+
return "Link Local";
57+
case ESP_IP6_ADDR_IS_SITE_LOCAL:
58+
return "Site Local";
59+
case ESP_IP6_ADDR_IS_UNIQUE_LOCAL:
60+
return "Unique Local";
61+
case ESP_IP6_ADDR_IS_IPV4_MAPPED_IPV6:
62+
return "IPv4 Mapped IPv6";
63+
default:
64+
return "Invalid Type";
65+
}
66+
}
67+
68+
static void render(bool partial, bool icons) {
69+
gui_theme_t* theme = get_theme();
70+
pax_buf_t* buffer = display_get_buffer();
71+
72+
char message_buffer[128] = {0};
73+
74+
int header_height = theme->header.height + (theme->header.vertical_margin * 2);
75+
int footer_height = theme->footer.height + (theme->footer.vertical_margin * 2);
76+
77+
pax_vec2_t position = {
78+
.x0 = theme->menu.horizontal_margin + theme->menu.horizontal_padding,
79+
.y0 = header_height + theme->menu.vertical_margin + theme->menu.vertical_padding,
80+
.x1 = pax_buf_get_width(buffer) - theme->menu.horizontal_margin - theme->menu.horizontal_padding,
81+
.y1 = pax_buf_get_height(buffer) - footer_height - theme->menu.vertical_margin - theme->menu.vertical_padding,
82+
};
83+
84+
if (!partial || icons) {
85+
render_base_screen_statusbar(buffer, theme, !partial, !partial || icons, !partial,
86+
((gui_element_icontext_t[]){{get_icon(ICON_INFO), "WiFi information"}}), 1,
87+
FOOTER_LEFT, FOOTER_RIGHT);
88+
}
89+
if (!partial) {
90+
bool connected = get_connection_info();
91+
if (!connected) {
92+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
93+
position.y0 + 18 * 0, "Not connected to a network");
94+
} else {
95+
esp_netif_ip_info_t ip_info;
96+
esp_netif_get_ip_info(wifi_get_netif(), &ip_info);
97+
98+
esp_ip6_addr_t ip6[LWIP_IPV6_NUM_ADDRESSES];
99+
int ip6_addrs = esp_netif_get_all_ip6(wifi_get_netif(), ip6);
100+
101+
snprintf(message_buffer, sizeof(message_buffer), "SSID: %s", connected_ap.ssid);
102+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
103+
position.y0 + 18 * 0, message_buffer);
104+
snprintf(message_buffer, sizeof(message_buffer), "BSSID: %02x:%02x:%02x:%02x:%02x:%02x",
105+
connected_ap.bssid[0], connected_ap.bssid[1], connected_ap.bssid[2], connected_ap.bssid[3],
106+
connected_ap.bssid[4], connected_ap.bssid[5]);
107+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
108+
position.y0 + 18 * 1, message_buffer);
109+
snprintf(message_buffer, sizeof(message_buffer), "Channel: %d", connected_ap.primary);
110+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
111+
position.y0 + 18 * 2, message_buffer);
112+
snprintf(message_buffer, sizeof(message_buffer), "RSSI: %d dBm", connected_ap.rssi);
113+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
114+
position.y0 + 18 * 3, message_buffer);
115+
116+
snprintf(message_buffer, sizeof(message_buffer), "IP address: " IPSTR, IP2STR(&ip_info.ip));
117+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
118+
position.y0 + 18 * 5, message_buffer);
119+
snprintf(message_buffer, sizeof(message_buffer), "Gateway: " IPSTR, IP2STR(&ip_info.gw));
120+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
121+
position.y0 + 18 * 6, message_buffer);
122+
snprintf(message_buffer, sizeof(message_buffer), "Netmask: " IPSTR, IP2STR(&ip_info.netmask));
123+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
124+
position.y0 + 18 * 7, message_buffer);
125+
126+
if (ip6_addrs > 0) {
127+
snprintf(message_buffer, sizeof(message_buffer), "IPv6 addresses:");
128+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
129+
position.y0 + 18 * 8, message_buffer);
130+
131+
for (int j = 0; j < ip6_addrs; ++j) {
132+
esp_ip6_addr_type_t ipv6_type = esp_netif_ip6_get_addr_type(&(ip6[j]));
133+
snprintf(message_buffer, sizeof(message_buffer), "- %s: " IPV6STR,
134+
ip6_addr_type_to_string(ipv6_type), IPV62STR(ip6[j]));
135+
pax_draw_text(buffer, theme->palette.color_foreground, theme->menu.text_font, 16, position.x0,
136+
position.y0 + 18 * (9 + j), message_buffer);
137+
}
138+
}
139+
}
140+
}
141+
display_blit_buffer(buffer);
142+
}
143+
144+
void menu_wifi_info(void) {
145+
QueueHandle_t input_event_queue = NULL;
146+
ESP_ERROR_CHECK(bsp_input_get_queue(&input_event_queue));
147+
148+
render(false, true);
149+
while (1) {
150+
bsp_input_event_t event;
151+
if (xQueueReceive(input_event_queue, &event, pdMS_TO_TICKS(1000)) == pdTRUE) {
152+
switch (event.type) {
153+
case INPUT_EVENT_TYPE_NAVIGATION: {
154+
if (event.args_navigation.state) {
155+
switch (event.args_navigation.key) {
156+
case BSP_INPUT_NAVIGATION_KEY_ESC:
157+
case BSP_INPUT_NAVIGATION_KEY_F1:
158+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
159+
return;
160+
default:
161+
break;
162+
}
163+
}
164+
break;
165+
}
166+
default:
167+
break;
168+
}
169+
} else {
170+
render(true, true);
171+
}
172+
}
173+
}

main/menu/menu_wifi_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void menu_wifi_info(void);

0 commit comments

Comments
 (0)