Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the function to set the IP address #459

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pico_w/wifi/access_point/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ target_link_libraries(picow_access_point_background
pico_cyw43_arch_lwip_threadsafe_background
pico_stdlib
)

# You can change the address below to change the address of the access point
pico_configure_ip4_address(picow_access_point_background PRIVATE
CYW43_DEFAULT_IP_AP_ADDRESS 192.168.4.1
)
pico_add_extra_outputs(picow_access_point_background)

add_executable(picow_access_point_poll
Expand All @@ -33,4 +36,8 @@ target_link_libraries(picow_access_point_poll
pico_cyw43_arch_lwip_poll
pico_stdlib
)
# You can change the address below to change the address of the access point
pico_configure_ip4_address(picow_access_point_poll PRIVATE
CYW43_DEFAULT_IP_AP_ADDRESS 192.168.4.1
)
pico_add_extra_outputs(picow_access_point_poll)
24 changes: 6 additions & 18 deletions pico_w/wifi/access_point/picow_access_point.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ typedef struct TCP_SERVER_T_ {
struct tcp_pcb *server_pcb;
bool complete;
ip_addr_t gw;
async_context_t *context;
} TCP_SERVER_T;

typedef struct TCP_CONNECT_STATE_T_ {
Expand Down Expand Up @@ -269,24 +268,15 @@ static bool tcp_server_open(void *arg, const char *ap_name) {
return true;
}

// This "worker" function is called to safely perform work when instructed by key_pressed_func
void key_pressed_worker_func(async_context_t *context, async_when_pending_worker_t *worker) {
assert(worker->user_data);
printf("Disabling wifi\n");
cyw43_arch_disable_ap_mode();
((TCP_SERVER_T*)(worker->user_data))->complete = true;
}

static async_when_pending_worker_t key_pressed_worker = {
.do_work = key_pressed_worker_func
};

void key_pressed_func(void *param) {
assert(param);
TCP_SERVER_T *state = (TCP_SERVER_T*)param;
int key = getchar_timeout_us(0); // get any pending key press but don't wait
if (key == 'd' || key == 'D') {
// We are probably in irq context so call wifi in a "worker"
async_context_set_work_pending(((TCP_SERVER_T*)param)->context, &key_pressed_worker);
cyw43_arch_lwip_begin();
cyw43_arch_disable_ap_mode();
cyw43_arch_lwip_end();
state->complete = true;
}
}

Expand All @@ -305,9 +295,6 @@ int main() {
}

// Get notified if the user presses a key
state->context = cyw43_arch_async_context();
key_pressed_worker.user_data = state;
async_context_add_when_pending_worker(cyw43_arch_async_context(), &key_pressed_worker);
stdio_set_chars_available_callback(key_pressed_func, state);

const char *ap_name = "picow_test";
Expand Down Expand Up @@ -358,5 +345,6 @@ int main() {
dns_server_deinit(&dns_server);
dhcp_server_deinit(&dhcp_server);
cyw43_arch_deinit();
printf("Test complete\n");
return 0;
}
Loading