I would like to use AsyncWebServer_RP2040W for a RP pico W web server application. The code works well in the below example. However, I need to include the <HTTPClient.h> library in my code. Unfortunately, just adding the #include command produces error messages.
Is there a way to resolve the incompatibility?
Any thoughts would be appreciated.
/****************************************************************************************************************************
Async_HelloServer.h
For RP2040W with CYW43439 WiFi
AsyncWebServer_RP2040W is a library for the RP2040W with CYW43439 WiFi
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_RP2040W
Licensed under GPLv3 license
*****************************************************************************************************************************/
#include <Arduino.h>
#include <WiFi.h>
#include "pico/cyw43_arch.h"
#include <AsyncWebServer_RP2040W.h>
//#include <HTTPClient.h>
///////////////////////////////////////////////////////////////////
char ssid[] = "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;
AsyncWebServer server(80);
#define LED_OFF LOW
#define LED_ON HIGH
#define BUFFER_SIZE 64
char temp[BUFFER_SIZE];
void handleRoot(AsyncWebServerRequest *request)
{
digitalWrite(LED_BUILTIN, LED_ON);
snprintf(temp, BUFFER_SIZE - 1, "Hello from Async_HelloServer --- on %s\n", BOARD_NAME);
request->send(200, "text/plain", temp);
digitalWrite(LED_BUILTIN, LED_OFF);
}
void handleNotFound(AsyncWebServerRequest *request)
{
digitalWrite(LED_BUILTIN, LED_ON);
String message = "File Not Found\n\n";
message += "URI: ";
//message += server.uri();
message += request->url();
message += "\nMethod: ";
message += (request->method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += request->args();
message += "\n";
for (uint8_t i = 0; i < request->args(); i++)
{
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
}
request->send(404, "text/plain", message);
digitalWrite(LED_BUILTIN, LED_OFF);
}
void printWifiStatus()
{
// 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);
// print your board's country code
// #define CYW43_COUNTRY(A, B, REV) ((unsigned char)(A) | ((unsigned char)(B) << 8) | ((REV) << 16))
uint32_t myCountryCode = cyw43_arch_get_country_code();
char countryCode[3] = { 0, 0, 0 };
countryCode[0] = myCountryCode & 0xFF;
countryCode[1] = (myCountryCode >> 8) & 0xFF;
Serial.print("Country code: ");
Serial.println(countryCode);
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);
Serial.begin(115200);
while (!Serial && millis() < 5000);
delay(200);
Serial.print("\nStart Async_HelloServer on ");
Serial.print(BOARD_NAME);
Serial.print(" with ");
Serial.println(SHIELD_TYPE);
Serial.println(ASYNCTCP_RP2040W_VERSION);
Serial.println(ASYNC_WEBSERVER_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);
WiFi.mode(WIFI_STA);
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();
///////////////////////////////////
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
{
handleRoot(request);
});
server.on("/inline", [](AsyncWebServerRequest * request)
{
request->send(200, "text/plain", "This works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(WiFi.localIP());
}
void heartBeatPrint()
{
static int num = 1;
Serial.print(F("."));
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 10000L
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
heartBeatPrint();
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
void loop()
{
check_status();
}
Here is my platformio.ini file:
[env]
platform = raspberrypi
framework = arduino
board_build.core = earlephilhower
monitor_speed = 115200
[env:rpipicow]
board = rpipicow
lib_deps =
khoih-prog/AsyncTCP_RP2040W@>=1.1.0
khoih-prog/AsyncMQTT_Generic@>=1.8.1
stm32duino/STM32duino LwIP@>=2.1.2
when I un-comment the line "#include <HTMLClient.h>, I get this error message:
Processing rpipicow (board: rpipicow; platform: raspberrypi; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/rpipicow.html
PLATFORM: Raspberry Pi RP2040 (1.14.0+sha.196d31b) > Pico W
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, pico-debug, picoprobe, raspberrypi-swd)
PACKAGES:
- framework-arduinopico @ 1.30903.0+sha.96a2e92
- tool-rp2040tools @ 1.0.2
- toolchain-rp2040-earlephilhower @ 5.120300.240127 (12.3.0)
Flash size: 2.00MB
Sketch size: 2.00MB
Filesystem size: 0.00MB
Maximium Sketch size: 2093056 EEPROM start: 0x101ff000 Filesystem start: 0x101ff000 Filesystem end: 0x101ff000
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 66 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AsyncTCP_RP2040W @ 1.2.0
|-- AsyncMQTT_Generic @ 1.8.1
|-- STM32duino LwIP @ 2.1.3
|-- AsyncWebServer_RP2040W @ 1.5.0
|-- HTTPClient @ 1.2
|-- WiFi @ 1.0.0
Building in release mode
Compiling .pio/build/rpipicow/src/main.cpp.o
In file included from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/arch.h:48,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/debug.h:40,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/opt.h:52,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/init.h:40,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/../../../ArduinoCore-API/api/IPAddress.h:26,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/../../../ArduinoCore-API/api/ArduinoAPI.h:30,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/ArduinoAPI.h:2,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/Arduino.h:28,
from src/main.cpp:15:
.pio/libdeps/rpipicow/STM32duino LwIP/src/arch/cc.h:86: warning: "LWIP_RAND" redefined
86 | #define LWIP_RAND() ((u32_t)rand())
|
In file included from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/opt.h:51:
/Users/ludwin/.platformio/packages/framework-arduinopico/include/lwipopts.h:15: note: this is the location of the previous definition
15 | #define LWIP_RAND() __lwip_rand()
|
Compiling .pio/build/rpipicow/lib582/HTTPClient/HTTPClient.cpp.o
Compiling .pio/build/rpipicow/lib582/HTTPClient/base64.cpp.o
In file included from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/arch.h:48,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/debug.h:40,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/opt.h:52,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/init.h:40,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/../../../ArduinoCore-API/api/IPAddress.h:26,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/../../../ArduinoCore-API/api/ArduinoAPI.h:30,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/ArduinoAPI.h:2,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/Arduino.h:28,
from /Users/ludwin/.platformio/packages/framework-arduinopico/libraries/HTTPClient/src/HTTPClient.cpp:26:
.pio/libdeps/rpipicow/STM32duino LwIP/src/arch/cc.h:86: warning: "LWIP_RAND" redefined
86 | #define LWIP_RAND() ((u32_t)rand())
|
In file included from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/opt.h:51:
/Users/ludwin/.platformio/packages/framework-arduinopico/include/lwipopts.h:15: note: this is the location of the previous definition
15 | #define LWIP_RAND() __lwip_rand()
|
In file included from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/arch.h:48,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/debug.h:40,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/opt.h:52,
from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/init.h:40,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/../../../ArduinoCore-API/api/IPAddress.h:26,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/../../../ArduinoCore-API/api/ArduinoAPI.h:30,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/api/ArduinoAPI.h:2,
from /Users/ludwin/.platformio/packages/framework-arduinopico/cores/rp2040/Arduino.h:28,
from /Users/ludwin/.platformio/packages/framework-arduinopico/libraries/HTTPClient/src/base64.cpp:25:
.pio/libdeps/rpipicow/STM32duino LwIP/src/arch/cc.h:86: warning: "LWIP_RAND" redefined
86 | #define LWIP_RAND() ((u32_t)rand())
|
In file included from .pio/libdeps/rpipicow/STM32duino LwIP/src/lwip/opt.h:51:
/Users/ludwin/.platformio/packages/framework-arduinopico/include/lwipopts.h:15: note: this is the location of the previous definition
15 | #define LWIP_RAND() __lwip_rand()
|
/Users/ludwin/.platformio/packages/framework-arduinopico/libraries/HTTPClient/src/base64.cpp: In static member function 'static arduino::String base64::encode(const uint8_t*, size_t, bool)':
/Users/ludwin/.platformio/packages/framework-arduinopico/libraries/HTTPClient/src/base64.cpp:42:23: error: 'base64_encode_expected_len_nonewlines' was not declared in this scope; did you mean 'base64_encode_expected_len'?
42 | : base64_encode_expected_len_nonewlines(length)) + 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| base64_encode_expected_len
/Users/ludwin/.platformio/packages/framework-arduinopico/libraries/HTTPClient/src/base64.cpp:50:13: error: 'base64_init_encodestate_nonewlines' was not declared in this scope; did you mean 'base64_init_encodestate'?
50 | base64_init_encodestate_nonewlines(&_state);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| base64_init_encodestate
*** [.pio/build/rpipicow/lib582/HTTPClient/base64.cpp.o] Error 1
======================================================== [FAILED] Took 2.78 seconds ========================================================