-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
81 lines (68 loc) · 2.05 KB
/
main.c
File metadata and controls
81 lines (68 loc) · 2.05 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "pico/stdlib.h"
#include "pico/bootrom.h"
#include "hardware/watchdog.h"
#include "hardware/structs/watchdog.h"
#include "hardware/clocks.h"
#include "hardware/structs/clocks.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
}
};
uint8_t tud_network_mac_address[6] = {0x02,0x02,0x84,0x6A,0x96,0x00};
void core1(){
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);
}
void cyw43_cb_tcpip_set_link_up(cyw43_t *self, int itf) {
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
}
void cyw43_cb_tcpip_set_link_down(cyw43_t *self, int itf) {
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
}
int main()
{
// Initialize tinyusb, lwip, dhcpd and httpd
set_sys_clock_khz(250000 , true); // Set system clock to 250 MHz
cyw43_arch_init_with_country(CYW43_COUNTRY_INDIA);
cyw43_arch_enable_sta_mode();
cyw43_wifi_pm(&cyw43_state, cyw43_pm_value(CYW43_NO_POWERSAVE_MODE, 20, 1, 1, 1));
cyw43_hal_get_mac(0, tud_network_mac_address);
multicore_launch_core1(core1);
absolute_time_t next_wifi_try = 0;
int eth_frame_send_success;
while (true)
{
tud_task();
service_traffic();
if (absolute_time_diff_us(get_absolute_time(), next_wifi_try) < 0) {
eth_frame_send_success = cyw43_arch_wifi_connect_async("aayush-iphone", "1234567890", CYW43_AUTH_WPA2_MIXED_PSK);
next_wifi_try = make_timeout_time_ms(10000);
}
}
return 0;
}