Fastest Way to Connect Wi-Fi on Ai-M61/M62 (with HTTP GET/POST) #22
Yaqing-Zheng
started this conversation in
📚Tutorials(教程)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What you'll learn
This tutorial shows the fastest way to connect Wi-Fi on the Ai-M61/M62 and how to send HTTP GET/POST requests using the built-in shell command mechanism of the SDK's
wifi_httpexample — no FreeRTOS task code required to get started.Prerequisites
The Example Project
The example lives at
examples\wifi\sta\wifi_http. The key file iswifi_http_client.c, which registers custom shell commands to connect Wi-Fi and send HTTP requests.How the Shell Command Works
First, look at
main.c— it grabs the UART0 peripheral and binds the serial input to the shell command input. This means any data received on the UART is treated as a shell command and dispatched to the custom commands registered inwifi_http_client.c.Back in
wifi_http_client.c, when a command arrives it is parsed. If the command array length is less than 2, the command is considered invalid and it prints a usage hint.Sending GET / POST Requests
Once connected, you can send requests with the command:
Format:
wifi_http_test <host>. The request path is defined inside the code.Connecting to Wi-Fi
Method 1 — Serial command (same as above)
Send the connect command over UART:
For example:
Method 2 —
shell_execfrom codeYou can also call the Wi-Fi connect command from within your code using
shell_exec, essentially sending the command to yourself:This works — though I wasn't able to trace exactly where
wifi_sta_connectis registered to the command line.This is a work-in-progress share, so here are a few things I ran into and couldn't fully solve:
shell_execcan't be reused for GET/POST. If you try to call the HTTP request command viashell_exec, it misbehaves — it treats the POST/GET command as a Wi-Fi connect command. I haven't found the cause yet.wifi_test_http_client_init()is for HTTP requests only. Don't try to use it to connect Wi-Fi.Sending requests from code (not yet solved). I wanted to send GET/POST programmatically after Wi-Fi connects, but the request always fires before the connection is fully established (no IP yet), so it fails. My idea is to write a FreeRTOS task that waits for the connection before sending the request — but I haven't learned FreeRTOS scheduling well enough to implement it.
Try It Yourself
Adapt the code to your environment, or just copy
main.candwifi_http_client.cfrom the example.📦 Example project download: wifi_http.zip
Questions?
📖 Original (Chinese) tutorial: 最快办法连接 WiFi(基于小安派 M61-M62)
Contributed by WangChong · Curated by the Ai-Thinker community team
All reactions