-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathwebserver.c
55 lines (45 loc) · 1.06 KB
/
webserver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "pico/stdlib.h"
#include "pico/bootrom.h"
#include "hardware/watchdog.h"
#include "hardware/structs/watchdog.h"
#include "tusb_lwip_glue.h"
#define LED_PIN 25
// let our webserver do some dynamic handling
static const char *cgi_toggle_led(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
{
gpio_put(LED_PIN, !gpio_get(LED_PIN));
return "/index.html";
}
static const char *cgi_reset_usb_boot(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
{
reset_usb_boot(0, 0);
return "/index.html";
}
static const tCGI cgi_handlers[] = {
{
"/toggle_led",
cgi_toggle_led
},
{
"/reset_usb_boot",
cgi_reset_usb_boot
}
};
int main()
{
// Initialize tinyusb, lwip, dhcpd and httpd
init_lwip();
wait_for_netif_is_up();
dhcpd_init();
httpd_init();
http_set_cgi_handlers(cgi_handlers, LWIP_ARRAYSIZE(cgi_handlers));
// For toggle_led
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true)
{
tud_task();
service_traffic();
}
return 0;
}