Hello,
I want to include the library StompClient
from github using lib_deps
. Because StompClient has a dependency to Websockets
my platformio.ini
looks the following:
lib_deps =
links2004/WebSockets@^2.3.6
https://github.com/ukmaker/StompClient
The Problem is now that StompClient
doesn’t define any dependencies to WebSockets
using it’s library.properties
file and but includes it. When building I know obviosly get
.pio/libdeps/d1_mini/StompClient/src/StompClient.h:20:10: fatal error: WebsocketsClient.h: No such file or directory
Is there a way to fix that ?
Thanks
Have you tried all available lib_ldf_mode
?
Yes, I did try all options. But I think platformio
doesn’t recognize the dependency correctly since it’s not defined in the library.properties
file
Well if you’re on Linux one reason for the
is because the library authors misspelled the header here, as you can see in arduinoWebSockets/src at 2.0.3 · Links2004/arduinoWebSockets · GitHub it is WebSocketsClient.h
. So if I correct the librariy in regards to that (.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h
), the dependency graph immediately gets fixed, but errors out later in compilation. I don’t think this 5 year old library is compatible with todays cores…
max@PC-LT-23-VM:~/temp/stomp$ pio run
Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 (3.2.0) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
- framework-arduinoespressif8266 3.30002.0 (3.0.2)
- tool-esptool 1.413.0 (4.13)
- tool-esptoolpy 1.30000.201119 (3.0.0)
- toolchain-xtensa 2.100300.210717 (10.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 37 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <WebSockets> 2.3.6
| |-- <ESP8266WiFi> 1.0
| |-- <Ethernet> 2.0.0
| | |-- <SPI> 1.0
| |-- <SPI> 1.0
| |-- <Hash> 1.0
|-- <StompClient> 1.0.0+sha.81318ac
| |-- <WebSockets> 2.3.6
| | |-- <ESP8266WiFi> 1.0
| | |-- <Ethernet> 2.0.0
| | | |-- <SPI> 1.0
| | |-- <SPI> 1.0
| | |-- <Hash> 1.0
|-- <ESP8266WiFi> 1.0
Building in release mode
Compiling .pio/build/nodemcuv2/src/main.cpp.o
Compiling .pio/build/nodemcuv2/lib61a/ESP8266WiFi/WiFiUdp.cpp.o
Compiling .pio/build/nodemcuv2/lib61a/ESP8266WiFi/enable_wifi_at_boot_time.cpp.o
Compiling .pio/build/nodemcuv2/libd7c/SPI/SPI.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/Dhcp.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/Dns.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/Ethernet.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/EthernetClient.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/EthernetServer.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/EthernetUdp.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/socket.cpp.o
Compiling .pio/build/nodemcuv2/libef8/Ethernet/utility/w5100.cpp.o
Compiling .pio/build/nodemcuv2/lib32b/Hash/Hash.cpp.o
Compiling .pio/build/nodemcuv2/lib76c/WebSockets/SocketIOclient.cpp.o
Compiling .pio/build/nodemcuv2/lib76c/WebSockets/WebSockets.cpp.o
Compiling .pio/build/nodemcuv2/lib76c/WebSockets/WebSocketsClient.cpp.o
In file included from .pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:19,
from src/main.cpp:5:
.pio/libdeps/nodemcuv2/StompClient/src/StompCommandParser.h: In static member function 'static Stomp::StompCommand Stomp::StompCommandParser::parse(String)':
.pio/libdeps/nodemcuv2/StompClient/src/StompCommandParser.h:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
56 | while (start < headers.length()) {
| ~~~~~~^~~~~~~~~~~~~~~~~~
In file included from src/main.cpp:5:
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h: In constructor 'Stomp::StompClient::StompClient(WebSocketsClient&, const char*, int, const char*, bool)':
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:193:14: warning: 'Stomp::StompClient::_heartbeats' will be initialized after [-Wreorder]
193 | uint32_t _heartbeats;
| ^~~~~~~~~~~
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:188:23: warning: 'void (* Stomp::StompClient::_connectHandler)(Stomp::StompCommand)' [-Wreorder]
188 | StompStateHandler _connectHandler;
| ^~~~~~~~~~~~~~~
In file included from src/main.cpp:5:
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:36:5: warning: when initialized here [-Wreorder]
36 | StompClient(
| ^~~~~~~~~~~
In file included from src/main.cpp:5:
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h: In member function 'void Stomp::StompClient::beginSSL()':
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:69:50: error: cannot convert 'String' to 'const char*'
69 | _wsClient.beginSSL(_host, _port, _socketUrl());
| ~~~~~~~~~~^~
| |
| String
In file included from src/main.cpp:4:
.pio/libdeps/nodemcuv2/WebSockets/src/WebSocketsClient.h:50:66: note: initializing argument 3 of 'void WebSocketsClient::beginSSL(const char*, uint16_t, const char*, const uint8_t*, const char*)'
50 | void beginSSL(const char * host, uint16_t port, const char * url = "/", const uint8_t * fingerprint = NULL, const char * protocol = "arduino");
| ~~~~~~~~~~~~~^~~~~~~~~
In file included from src/main.cpp:5:
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h: In member function 'void Stomp::StompClient::_handleWebSocketEvent(WStype_t, uint8_t*, size_t)':
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_ERROR' not handled in switch [-Wswitch]
211 | switch (type) {
| ^
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_FRAGMENT_TEXT_START' not handled in switch [-Wswitch]
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_FRAGMENT_BIN_START' not handled in switch [-Wswitch]
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_FRAGMENT' not handled in switch [-Wswitch]
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_FRAGMENT_FIN' not handled in switch [-Wswitch]
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_PING' not handled in switch [-Wswitch]
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:211:14: warning: enumeration value 'WStype_PONG' not handled in switch [-Wswitch]
src/main.cpp: In function 'void setup()':
src/main.cpp:64:21: error: 'subscribe' was not declared in this scope
64 | stomper.onConnect(subscribe);
| ^~~~~~~~~
src/main.cpp:65:19: error: 'error' was not declared in this scope; did you mean 'perror'?
65 | stomper.onError(error);
| ^~~~~
| perror
Archiving .pio/build/nodemcuv2/libd7c/libSPI.a
Indexing .pio/build/nodemcuv2/libd7c/libSPI.a
Compiling .pio/build/nodemcuv2/lib76c/WebSockets/WebSocketsServer.cpp.o
*** [.pio/build/nodemcuv2/src/main.cpp.o] Error 1
===================================================== [FAILED] Took 2.48 seconds =====================================================
2 Likes
Okay, partly that is because I copied a .ino
file into .cpp
without doing the proper conversion, but it still leaves one compile failure in the library open…
.pio/libdeps/nodemcuv2/StompClient/src/StompClient.h:69:50: error: cannot convert 'String' to 'const char*'
69 | _wsClient.beginSSL(_host, _port, _socketUrl());
| ~~~~~~~~~~^~
| |
| String
Ah yes, big thank you 
Really didn’t see that. But you’re right, now there are different errors, I don’t want to fix. So I guess I won’t use that library…
If you use
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
links2004/WebSockets@^2.3.6
https://github.com/maxgerhardt/StompClient.git
with a src/main.cpp
of
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
#include "StompClient.h"
void setup(){}
void loop(){}
Does it compile?
Yes it does. There are still some warnings, but I guess that’s fine. Thanks!
For reference, the converted variant of SpringStompButtons.ino
as a src/main.cpp
would be
#include <Arduino.h>
#include "StompClient.h"
#include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
/**
* WiFi settings
**/
const char *wlan_ssid = "--- Your wifi SSID ---";
const char *wlan_password = "--- Your wifi password";
/**
* Stomp server settings
**/
bool useWSS = true;
const char *ws_host = "--- Your Stomp server hostname ---";
const int ws_port = 4443;
const char *ws_baseurl = "/esp-websocket/"; // don't forget leading and trailing "/" !!!
// Confusingly, on a NodeMCU board these correspond to D1 and D2
#define BUTTON1 4
#define BUTTON2 5
// VARIABLES
WebSocketsClient webSocket;
Stomp::StompClient stomper(webSocket, ws_host, ws_port, ws_baseurl, true);
bool b1 = false;
bool b1_l = false;
bool b2 = false;
bool b2_l = false;
long b1_t = 0;
long b2_t = 0;
// Once the Stomp connection has been made, subscribe to a topic
void subscribe(Stomp::StompCommand cmd) {
Serial.println("Connected to STOMP broker");
}
void error(const Stomp::StompCommand cmd) {
Serial.println("ERROR: " + cmd.body);
}
void clickB1() { stomper.sendMessage("/esp/buttons", "{\\\"button\\\": 0}"); }
void clickB2() { stomper.sendMessage("/esp/buttons", "{\\\"button\\\": 1}"); }
/**
* Read and debounce the buttons
*/
void buttons() {
bool b = digitalRead(BUTTON1);
if (b != b1_l) {
b1_t = millis();
b1_l = b;
} else if ((millis() - b1_t) > 200) {
if (b1_l && !b1)
clickB1();
b1 = b1_l;
}
b = digitalRead(BUTTON2);
if (b != b2_l) {
b2_t = millis();
b2_l = b;
} else if ((millis() - b2_t) > 200) {
if (b2_l && !b2)
clickB2();
b2 = b2_l;
}
}
void setup() {
// Enable pullups on the GPIO pins the buttons are attached to
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
// setup serial
Serial.begin(115200);
// flush it - ESP Serial seems to start with rubbish
Serial.println();
// connect to WiFi
Serial.println("Logging into WLAN: " + String(wlan_ssid));
Serial.print(" ...");
WiFi.begin(wlan_ssid, wlan_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" success.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
stomper.onConnect(subscribe);
stomper.onError(error);
// Start the StompClient
if (useWSS) {
stomper.beginSSL();
} else {
stomper.begin();
}
}
void loop() {
webSocket.loop();
buttons();
}
which also compiles for me. But I can’t make any statement on working during runtime.
1 Like