Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

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

NotificationsYou must be signed in to change notification settings

khoih-prog/AsyncTCP_RP2040W

Repository files navigation

arduino-library-badgeGitHub releasecontributions welcomeGitHub issues

Donate to my libraries using BuyMeACoffee



Table of contents



Why do we need thisAsyncTCP_RP2040W library

Features

This library is based on, modified from:

  1. Hristo Gochkov's ESPAsyncTCP

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

Why Async is better

  • 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

Currently supported Boards

  1. RASPBERRY_PI_PICO_W with CYW43439 WiFi usingarduino-pico core


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino.GitHub release
  2. Earle Philhower's arduino-pico core v2.7.1+ forRASPBERRY_PI_PICO_W with CYW43439 WiFi, etc.GitHub release


Installation

Use Arduino Library Manager

The best and easiest way is to useArduino Library Manager. Search forAsyncTCP_RP2040W, then select / install the latest version.You can also use this linkarduino-library-badge for more detailed instructions.

Manual Install

Another way to install is to:

  1. Navigate toAsyncTCP_RP2040W page.
  2. Download the latest releaseAsyncTCP_RP2040W-main.zip.
  3. Extract the zip file toAsyncTCP_RP2040W-main directory
  4. Copy wholeAsyncTCP_RP2040W-main folder to Arduino libraries' directory such as~/Arduino/libraries/.

VS Code & PlatformIO

  1. InstallVS Code
  2. InstallPlatformIO
  3. InstallAsyncTCP_RP2040W library by usingLibrary Manager. Search forAsyncTCP_RP2040W inPlatform.io Author's Libraries
  4. 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


Original documentation

CheckAsyncTCP Library

AsyncClient and AsyncServer

The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use.

AsyncPrinter

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.

AsyncTCPbuffer

This class is really similar to theAsyncPrinter, but it can buffer some of the incoming data.

SyncClient

It is exactly what it sounds like. This is a standard, synchronous blocking TCP Client you're used to.



Examples

  1. AsyncTCP_Client
  2. AsyncTCP_Server

Please take a look at other examples, as well.

#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();
}
}



Debug Terminal Output Samples

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


Libraries currently depend on this library

  1. AsyncWebServer_RP2040WGitHub release
  2. AsyncHTTPRequest_RP2040WGitHub release


Debug

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

Troubleshooting

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.



Issues

Submit issues to:AsyncTCP_RP2040W issues


TO DO

  1. Search for bug and improvement.

DONE

  1. RASPBERRY_PI_PICO_W with CYW43439 WiFi
  2. Add astyle usingallman style. Restyle the library
  3. Add complex auto-reconnectAsyncTCPClient andAsyncTCP_Server examples
  4. ImproveREADME.md so that links can be used in other sites, such asPIO


Contributions and Thanks

Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.


Contributions and Thanks

  1. Based on and modified fromHristo Gochkov's ESPAsyncTCP. Many thanks toHristo Gochkov for greatESPAsyncTCP Library
me-no-dev
⭐️⭐️ Hristo Gochkov


Contributing

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


License

  • The library is licensed underGPLv3

Copyright

  • 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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp