Compare commits
2 Commits
6c1187d677
...
a265e4c138
| Author | SHA1 | Date |
|---|---|---|
|
|
a265e4c138 | |
|
|
82368fc829 |
|
|
@ -1,3 +1,3 @@
|
||||||
[submodule "PicoW_UDP"]
|
[submodule "PicoW_WiFi_Operator"]
|
||||||
path = PicoW_UDP
|
path = lib/PicoW_WiFi_Operator
|
||||||
url = https://gitea.skadubpc.net/ulysse/PicoW_UDP_Lib.git
|
url = https://gitea.skadubpc.net/ulysse/PicoW_WiFi_Operator_Lib.git
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
"${env:PICO_SDK_PATH}/lib/**/include/",
|
"${env:PICO_SDK_PATH}/lib/**/include/",
|
||||||
"${env:PICO_SDK_PATH}/lib/**/src/",
|
"${env:PICO_SDK_PATH}/lib/**/src/",
|
||||||
"${workspaceFolder}/build/generated/pico_base/",
|
"${workspaceFolder}/build/generated/pico_base/",
|
||||||
"${workspaceFolder}/src/"
|
"${workspaceFolder}/src/",
|
||||||
|
"${workspaceFolder}/lib/**/"
|
||||||
],
|
],
|
||||||
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
|
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
|
||||||
"cStandard": "c17",
|
"cStandard": "c17",
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,61 @@
|
||||||
{
|
{
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Configure",
|
||||||
|
"detail": "configure project",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cmake",
|
||||||
|
"args": [
|
||||||
|
"-H.",
|
||||||
|
"-Bbuild"
|
||||||
|
],
|
||||||
|
"group": "build",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "shared",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Build",
|
"label": "Build",
|
||||||
"detail": "Build project",
|
"detail": "Build project",
|
||||||
|
"dependsOn": [
|
||||||
|
"Configure"
|
||||||
|
],
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cmake -H. -Bbuild && make -j$(nproc) -C build",
|
"command": "make",
|
||||||
"args": [
|
"args": [
|
||||||
|
"-C",
|
||||||
|
"build",
|
||||||
|
"-j$(nproc)"
|
||||||
|
],
|
||||||
|
"group": "build",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "shared",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Flash",
|
||||||
|
"detail": "Build and flash executable",
|
||||||
|
"type": "shell",
|
||||||
|
"dependsOn": [
|
||||||
|
"Configure"
|
||||||
|
],
|
||||||
|
"command": "make",
|
||||||
|
"args": [
|
||||||
|
"-C",
|
||||||
|
"build",
|
||||||
|
"-j$(nproc)",
|
||||||
|
"Flash"
|
||||||
],
|
],
|
||||||
"group": "build",
|
"group": "build",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
|
|
@ -22,8 +71,10 @@
|
||||||
"label": "Clean",
|
"label": "Clean",
|
||||||
"detail": "Clean build directory and executable",
|
"detail": "Clean build directory and executable",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "rm -rf build",
|
"command": "rm",
|
||||||
"args": [
|
"args": [
|
||||||
|
"-rf",
|
||||||
|
"build"
|
||||||
],
|
],
|
||||||
"group": "build",
|
"group": "build",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
|
|
@ -34,24 +85,6 @@
|
||||||
"showReuseMessage": false,
|
"showReuseMessage": false,
|
||||||
"clear": true
|
"clear": true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Flash",
|
|
||||||
"detail": "Flash executable",
|
|
||||||
"type": "shell",
|
|
||||||
"dependsOn": "Build",
|
|
||||||
"command": "make Flash -C build",
|
|
||||||
"args": [
|
|
||||||
],
|
|
||||||
"group": "build",
|
|
||||||
"presentation": {
|
|
||||||
"echo": true,
|
|
||||||
"reveal": "always",
|
|
||||||
"focus": true,
|
|
||||||
"panel": "shared",
|
|
||||||
"showReuseMessage": true,
|
|
||||||
"clear": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -21,9 +21,11 @@ add_executable(PicoW_UDP_Tests
|
||||||
)
|
)
|
||||||
|
|
||||||
# Libs
|
# Libs
|
||||||
add_subdirectory(PicoW_UDP)
|
add_subdirectory(lib/PicoW_WiFi_Operator)
|
||||||
|
add_subdirectory(lib/PicoW_UDP)
|
||||||
target_link_libraries(PicoW_UDP_Tests
|
target_link_libraries(PicoW_UDP_Tests
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
|
PicoW_WiFi_Operator
|
||||||
PicoW_UDP
|
PicoW_UDP
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 0000000000000000000000000000000000000000
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 6b3d7503bd4da346740a835e464a9bc8399efcd6
|
||||||
172
src/main.c
172
src/main.c
|
|
@ -1,171 +1,13 @@
|
||||||
|
#include <pico/stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pico/stdio.h>
|
#include "PicoW_WiFi_Operator.h"
|
||||||
#include <pico/cyw43_arch.h>
|
#include "PicoW_UDP.h"
|
||||||
#include <lwip/udp.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define CLIENT
|
int main(void)
|
||||||
//#define SERVER
|
|
||||||
#define STA_MODE
|
|
||||||
//#define AP_MODE
|
|
||||||
|
|
||||||
#ifdef STA_MODE
|
|
||||||
|
|
||||||
#define SSID "thinkpad-T440p"
|
|
||||||
#define PASSWORD "CDuKaka2000!"
|
|
||||||
|
|
||||||
#endif // STA_MODE
|
|
||||||
|
|
||||||
#ifdef AP_MODE
|
|
||||||
|
|
||||||
#define AP_SSID "PicoAP"
|
|
||||||
#define AP_PASSWORD "PicoPassword!"
|
|
||||||
#define AP_CHANNEL 3
|
|
||||||
|
|
||||||
#endif // AP_MODE
|
|
||||||
|
|
||||||
#ifdef CLIENT
|
|
||||||
|
|
||||||
#define CLIENT_PORT 4243
|
|
||||||
|
|
||||||
static void udp_recv_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
|
||||||
{
|
|
||||||
puts("Callback");
|
|
||||||
|
|
||||||
if(p->len == 1)
|
|
||||||
{
|
|
||||||
printf("a:%d\n", ((uint8_t *)p->payload)[0]);
|
|
||||||
}
|
|
||||||
pbuf_free(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // CLIENT
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
{
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
sleep_ms(2000);
|
puts("Hello, World !");
|
||||||
|
|
||||||
puts("Pi Starting...");
|
return 0;
|
||||||
|
}
|
||||||
if(cyw43_arch_init_with_country(CYW43_COUNTRY_FRANCE))
|
|
||||||
{
|
|
||||||
puts("CYW43 arch init failed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cyw43_wifi_pm(&cyw43_state, CYW43_NO_POWERSAVE_MODE))
|
|
||||||
{
|
|
||||||
puts("CYW43 no powersave mode failed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
puts("CYW43 arch initialized");
|
|
||||||
|
|
||||||
#ifdef STA_MODE
|
|
||||||
|
|
||||||
cyw43_arch_enable_sta_mode();
|
|
||||||
|
|
||||||
for(int error_code = 1; error_code; )
|
|
||||||
{
|
|
||||||
printf("WiFi connection attempt to \"%s\"\n", SSID);
|
|
||||||
|
|
||||||
error_code = cyw43_arch_wifi_connect_timeout_ms(SSID, PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 10000);
|
|
||||||
|
|
||||||
if(error_code)
|
|
||||||
{
|
|
||||||
const char *error_message;
|
|
||||||
|
|
||||||
switch(error_code)
|
|
||||||
{
|
|
||||||
case PICO_ERROR_TIMEOUT:
|
|
||||||
error_message = "Timeout reached";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PICO_ERROR_BADAUTH:
|
|
||||||
error_message = "Bad password";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PICO_ERROR_CONNECT_FAILED:
|
|
||||||
error_message = "Some reason";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Connection failed : %s\n", error_message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
puts("WiFi connected");
|
|
||||||
|
|
||||||
#endif // STA_MODE
|
|
||||||
|
|
||||||
#ifdef AP_MODE
|
|
||||||
|
|
||||||
cyw43_arch_enable_ap_mode(AP_SSID, AP_PASSWORD, CYW43_AUTH_WPA2_AES_PSK);
|
|
||||||
|
|
||||||
cyw43_wifi_ap_set_channel(&cyw43_state, AP_CHANNEL);
|
|
||||||
|
|
||||||
puts("AP mode enabled");
|
|
||||||
|
|
||||||
#endif //AP_MODE
|
|
||||||
|
|
||||||
#ifdef CLIENT
|
|
||||||
|
|
||||||
struct udp_pcb *pcb = udp_new();
|
|
||||||
|
|
||||||
if(!pcb)
|
|
||||||
{
|
|
||||||
puts("UDP pcb init failed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
udp_recv(pcb, udp_recv_callback, NULL);
|
|
||||||
|
|
||||||
if(udp_bind(pcb, IP4_ADDR_ANY, CLIENT_PORT))
|
|
||||||
{
|
|
||||||
puts("UDP pcb bind failed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // CLIENT
|
|
||||||
|
|
||||||
// ========================== Main loop ==========================
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
cyw43_arch_poll();
|
|
||||||
|
|
||||||
#ifdef STA_MODE
|
|
||||||
int ret = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA);
|
|
||||||
if(ret != CYW43_LINK_JOIN)
|
|
||||||
{
|
|
||||||
const char *status_message;
|
|
||||||
switch(ret)
|
|
||||||
{
|
|
||||||
case CYW43_LINK_DOWN:
|
|
||||||
status_message = "WiFi down";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CYW43_LINK_JOIN:
|
|
||||||
status_message = "WiFi up";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CYW43_LINK_FAIL:
|
|
||||||
status_message = "WiFi connection failed";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CYW43_LINK_NONET:
|
|
||||||
status_message = "Network not found";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CYW43_LINK_BADAUTH:
|
|
||||||
status_message = "Bad auth";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
puts(status_message);
|
|
||||||
}
|
|
||||||
#endif // STA_MODE
|
|
||||||
|
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue