Skip to content

Commit ae7fc90

Browse files
committed
applied suggested improvement to cgi handler
1 parent a55ed5d commit ae7fc90

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pico_w/wifi/access_point/picow_access_point.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@
2424
static absolute_time_t wifi_connected_time;
2525
bool led_state;
2626
bool complete;
27-
bool desired_state;
2827

2928
static const char *switch_cgi_handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) {
30-
printf("Switch cgi handler called\n");
31-
3229
// Get desired LED state from GET request and set LED
33-
desired_state = !strcmp("ON", pcValue[0]);
34-
status_led_set_state(desired_state);
35-
36-
// Update led state
37-
led_state = status_led_get_state();
30+
for (int iParam = 0; iParam < iNumParams; iParam++) {
31+
if (strcmp("switch", pcParam[iParam]) == 0) {
32+
if (strcmp("ON", pcValue[iParam]) == 0) {
33+
status_led_set_state(true);
34+
led_state = true;
35+
} else if (strcmp("OFF", pcValue[iParam]) == 0) {
36+
status_led_set_state(false);
37+
led_state = false;
38+
}
39+
break;
40+
}
41+
}
3842

3943
return "/index.shtml";
4044
}

0 commit comments

Comments
 (0)