- Notifications
You must be signed in to change notification settings - Fork7
Asynchronous TCP Library for RASPBERRY_PI_PICO_W using CYW43439 WiFi with arduino-pico core. This library is the base for future and more advanced Async libraries, such as AsyncWebServer_RP2040W, AsyncHTTPRequest_RP2040W, AsyncHTTPSRequest_RP2040W
License
khoih-prog/AsyncTCP_RP2040W
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- Table of contents
- Why do we need this AsyncTCP_RP2040W library
- Changelog
- Prerequisites
- Installation
- Original documentation
- Examples
- Example AsyncTCP_Client
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need thisAsyncTCP_RP2040W library
This library is based on, modified from:
to apply the better and fasterasynchronous feature of thepowerfulESPAsyncTCP Library intoRASPBERRY_PI_PICO_W with CYW43439 WiFi, and will be the base for future and more advanced Async libraries, such asAsyncWebServer_RP2040W,AsyncHTTPRequest_RP2040W,AsyncHTTPSRequest_RP2040W
- Using asynchronous network means that you can handlemore than one connection at the same time
- You are called once the request is ready and parsed
- When you send the response, you areimmediately ready to handle other connections while the server is taking care of sending the response in the background
- Speed is OMG
- Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse
- Easily extensible to handleany type of content
- Supports Continue 100
- Async WebSocket plugin offering different locations without extra servers or ports
- Async EventSource (Server-Sent Events) plugin to send events to the browser
- URL Rewrite plugin for conditional and permanent url rewrites
- ServeStatic plugin that supports cache, Last-Modified, default index and more
- Simple template processing engine to handle templates
- RASPBERRY_PI_PICO_W with CYW43439 WiFi usingarduino-pico core
Arduino IDE 1.8.19+for Arduino.Earle Philhower's arduino-pico core v2.7.1+forRASPBERRY_PI_PICO_W with CYW43439 WiFi, etc.
The best and easiest way is to useArduino Library Manager. Search forAsyncTCP_RP2040W, then select / install the latest version.You can also use this link for more detailed instructions.
Another way to install is to:
- Navigate toAsyncTCP_RP2040W page.
- Download the latest release
AsyncTCP_RP2040W-main.zip. - Extract the zip file to
AsyncTCP_RP2040W-maindirectory - Copy whole
AsyncTCP_RP2040W-mainfolder to Arduino libraries' directory such as~/Arduino/libraries/.
- InstallVS Code
- InstallPlatformIO
- InstallAsyncTCP_RP2040W library by usingLibrary Manager. Search forAsyncTCP_RP2040W inPlatform.io Author's Libraries
- Use includedplatformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples atProject Configuration File
CheckAsyncTCP Library
The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use.
This class can be used to send data like any otherPrint interface (Serial for example).
The object then can be used outside of the Async callbacks (the loop) and receive asynchronously data usingonData. The object can be checked if the underlyingAsyncClientis connected, or hook to theonDisconnect callback.
This class is really similar to theAsyncPrinter, but it can buffer some of the incoming data.
It is exactly what it sounds like. This is a standard, synchronous blocking TCP Client you're used to.
ExampleAsyncTCP_Client
Please take a look at other examples, as well.
AsyncTCP_RP2040W/examples/ClientServer/AsyncTCP_Client/AsyncTCP_Client.ino
Lines 13 to 200 inf6ed4d3
| #include<AsyncTCP_RP2040W.h> | |
| char ssid[] ="your_ssid";// your network SSID (name) | |
| char pass[] ="12345678";// your network password (use for WPA, or use as key for WEP), length must be 8+ | |
| int status = WL_IDLE_STATUS; | |
| // Change the Server IPAddress accordingly | |
| IPAddressserverIP(192,168,2,128); | |
| #defineTCP_PORT5698 | |
| #defineCHECK_INTERVAL_MS1000L// Check connection | |
| #defineSEND_INTERVAL_MS10000L// delay between updates, in milliseconds | |
| unsignedlong lastCheck = SEND_INTERVAL_MS;// last time you connected to the server, in milliseconds | |
| AsyncClient* client =nullptr; | |
| bool clientConnected =false; | |
| bool dataReceived =false; | |
| #defineREPLY_SIZE64 | |
| staticvoidreplyToServer(void* arg) | |
| { | |
| (void) arg; | |
| Serial.println("\n********************"); | |
| Serial.println("New replyToServer"); | |
| AsyncClient* client =reinterpret_cast<AsyncClient*>(arg); | |
| // send reply | |
| if (client->space() > REPLY_SIZE && client->canSend()) | |
| { | |
| char message[REPLY_SIZE]; | |
| sprintf(message,"This is from AsyncTCPClient @ %s", WiFi.localIP().toString().c_str()); | |
| client->add(message,strlen(message)); | |
| client->send(); | |
| dataReceived =false; | |
| } | |
| } | |
| /* event callbacks*/ | |
| staticvoidhandleData(void* arg, AsyncClient* client,void *data,size_t len) | |
| { | |
| (void) arg; | |
| Serial.printf("\nData received from %s\n", client->remoteIP().toString().c_str()); | |
| Serial.write((uint8_t*)data, len); | |
| lastCheck =millis(); | |
| dataReceived =true; | |
| } | |
| voidonConnect(void* arg, AsyncClient* client) | |
| { | |
| (void) arg; | |
| clientConnected =true; | |
| Serial.printf("\nAsyncTCPClient has been connected to Server %s, port %d\n", serverIP.toString().c_str(), TCP_PORT); | |
| replyToServer(client); | |
| } | |
| voidonDisconnect(void* arg, AsyncClient* client) | |
| { | |
| (void) arg; | |
| (void) client; | |
| Serial.printf("\nAsyncTCPClient has been disconnected from Server %s, port %d\n", serverIP.toString().c_str(), TCP_PORT); | |
| clientConnected =false; | |
| } | |
| voidprintWifiStatus() | |
| { | |
| // print the SSID of the network you're attached to: | |
| Serial.print("SSID:"); | |
| Serial.println(WiFi.SSID()); | |
| // print your board's IP address: | |
| IPAddress ip = WiFi.localIP(); | |
| Serial.print("Local IP Address:"); | |
| Serial.println(ip); | |
| } | |
| boolconnectServer() | |
| { | |
| if (client) | |
| delete(client); | |
| client =new AsyncClient; | |
| if (client) | |
| { | |
| client->onData(&handleData, client); | |
| client->onConnect(&onConnect, client); | |
| client->onDisconnect(&onDisconnect, client); | |
| client->connect(serverIP, TCP_PORT); | |
| returntrue; | |
| } | |
| else | |
| { | |
| Serial.println("\nError, NULL client"); | |
| returnfalse; | |
| } | |
| } | |
| voidsetup() | |
| { | |
| Serial.begin(115200); | |
| while (!Serial &&millis() <5000); | |
| delay(200); | |
| Serial.print("\nStart AsyncTCP_Client on"); | |
| Serial.print(BOARD_NAME); | |
| Serial.print(" with"); | |
| Serial.println(SHIELD_TYPE); | |
| Serial.println(ASYNCTCP_RP2040W_VERSION); | |
| /////////////////////////////////// | |
| // check for the WiFi module: | |
| if (WiFi.status() == WL_NO_MODULE) | |
| { | |
| Serial.println("Communication with WiFi module failed!"); | |
| // don't continue | |
| while (true); | |
| } | |
| Serial.print(F("Connecting to SSID:")); | |
| Serial.println(ssid); | |
| status = WiFi.begin(ssid, pass); | |
| delay(1000); | |
| // attempt to connect to WiFi network | |
| while ( status != WL_CONNECTED) | |
| { | |
| delay(500); | |
| // Connect to WPA/WPA2 network | |
| status = WiFi.status(); | |
| } | |
| printWifiStatus(); | |
| /////////////////////////////////// | |
| connectServer(); | |
| lastCheck =millis(); | |
| } | |
| voidloop() | |
| { | |
| staticunsignedlong lastConnectCheck = CHECK_INTERVAL_MS; | |
| if (millis() - lastCheck > SEND_INTERVAL_MS) | |
| { | |
| if (clientConnected && dataReceived) | |
| { | |
| replyToServer(client); | |
| } | |
| elseif ( !clientConnected || !dataReceived ) | |
| { | |
| Serial.printf("\nReconnecting to Server %s, port %d\n", serverIP.toString().c_str(), TCP_PORT); | |
| connectServer(); | |
| } | |
| lastCheck =millis(); | |
| } | |
| } |
1.AsyncTCP_Server on RASPBERRY_PI_PICO_W with CYW43439 WiFi
Start AsyncTCP_Server on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFiAsyncTCP_RP2040W v1.2.0Connecting to SSID: HueNetSSID: HueNetLocal IP Address:192.168.2.128AsyncTCPServer is @ IP:192.168.2.128, port:5698New client has been connected to server, IP:192.168.2.118Data received from client192.168.2.118 This is from AsyncTCPClient @192.168.2.118
2.AsyncTCP_Client on RASPBERRY_PI_PICO_W with CYW43439 WiFi
Following is debug terminal output when running exampleAsyncTCP_Client onRASPBERRY_PI_PICO_W using CYW43439 WiFi, to demo theAsyncTCP_Client auto-reconnects toAsyncTCP_Server if connection is lost (network, power-recycle, etc.)
Start AsyncTCP_Client on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFiAsyncTCP_RP2040W v1.2.0Connecting to SSID: HueNetSSID: HueNetLocal IP Address:192.168.2.118AsyncTCPClient has been connected to Server192.168.2.128, port5698 ********************New replyToServerData received from192.168.2.128 You've connected to AsyncTCPServer @ 192.168.2.128********************New replyToServerData received from 192.168.2.128You've connected to AsyncTCPServer @192.168.2.128********************New replyToServerData received from192.168.2.128 You've connected to AsyncTCPServer @ 192.168.2.128********************New replyToServerReconnecting to Server 192.168.2.128, port 5698AsyncTCPClient has been disconnected from Server 192.168.2.128, port 5698Reconnecting to Server 192.168.2.128, port 5698Reconnecting to Server 192.168.2.128, port 5698Reconnecting to Server 192.168.2.128, port 5698AsyncTCPClient has been connected to Server 192.168.2.128, port 5698********************New replyToServerData received from 192.168.2.128You've connected to AsyncTCPServer @192.168.2.128********************New replyToServerData received from192.168.2.128 You've connected to AsyncTCPServer @ 192.168.2.128
Debug is enabled by default on Serial.
You can also change the debugging level_ASYNCTCP_RP2040W_LOGLEVEL_ from 0 to 4 in the librarycpp files
#define_ASYNCTCP_RP2040W_LOGLEVEL_1
If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
Submit issues to:AsyncTCP_RP2040W issues
- Search for bug and improvement.
- RASPBERRY_PI_PICO_W with CYW43439 WiFi
- Add astyle using
allmanstyle. Restyle the library - Add complex auto-reconnect
AsyncTCPClientandAsyncTCP_Serverexamples - Improve
README.mdso that links can be used in other sites, such asPIO
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
- Based on and modified fromHristo Gochkov's ESPAsyncTCP. Many thanks toHristo Gochkov for greatESPAsyncTCP Library
![]() ⭐️⭐️ Hristo Gochkov |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed underGPLv3
- Copyright (c) 2016- Hristo Gochkov
- Copyright (c) 2022- Khoi Hoang
About
Asynchronous TCP Library for RASPBERRY_PI_PICO_W using CYW43439 WiFi with arduino-pico core. This library is the base for future and more advanced Async libraries, such as AsyncWebServer_RP2040W, AsyncHTTPRequest_RP2040W, AsyncHTTPSRequest_RP2040W
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.

