Closed berna1995 closed 6 months ago
This is great but can you make it work for the Uno R4 Minima too.
When I try to compile it, I get the following errors, are there changes to the Header file that need to be included.
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:176:1: error: prototype for 'MQTTClient::MQTTClient(int, int)' does not match any in class 'MQTTClient'
MQTTClient::MQTTClient(int readBufSize, int writeBufSize) {
^~~~~~
In file included from C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:1:0:
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.h:66:7: error: candidates are: MQTTClient::MQTTClient(const MQTTClient&)
class MQTTClient {
^~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.h:95:12: error: MQTTClient::MQTTClient(int)
explicit MQTTClient(int bufSize = 128);
^~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: In member function 'void MQTTClient::begin(arduino::Client&)':
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:203:52: error: 'class MQTTClient' has no member named 'writeBufSize'; did you mean 'writeBuf'?
lwmqtt_init(&this->client, this->writeBuf, this->writeBufSize, this->readBuf,
^~~~
writeBuf
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:204:21: error: 'class MQTTClient' has no member named 'readBufSize'; did you mean 'readBuf'?
this->readBufSize);
^~~
readBuf
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: In member function 'void MQTTClient::setHost(const char, int)':
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:279:20: error: 'strdup' was not declared in this scope
this->hostname = strdup(_hostname);
^~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:279:20: note: suggested alternative: 'strcmp'
this->hostname = strdup(_hostname);
^~
strcmp
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: In member function 'void MQTTClient::setWill(const char, const char, bool, int)':
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:298:37: error: 'strdup' was not declared in this scope
this->will->topic = lwmqtt_string(strdup(topic));
^~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:298:37: note: suggested alternative: 'strcmp'
this->will->topic = lwmqtt_string(strdup(topic));
^~
strcmp
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: At global scope:
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:339:43: error: no 'void MQTTClient::dropOverflow(bool)' member function declared in class 'MQTTClient'
void MQTTClient::dropOverflow(bool enabled) {
^
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: In member function 'bool MQTTClient::connect(const char, const char, const char, bool)':
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:369:3: error: 'lwmqtt_connect_options_t' was not declared in this scope
lwmqtt_connect_options_t options = lwmqtt_default_connect_options;
^~~~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:369:3: note: suggested alternative: 'lwmqtt_options_t'
lwmqtt_connect_options_t options = lwmqtt_default_connect_options;
^~~~~~~~
lwmqtt_options_t
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:370:3: error: 'options' was not declared in this scope
options.keep_alive = this->keepAlive;
^~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:370:3: note: suggested alternative: 'setOptions'
options.keep_alive = this->keepAlive;
^~~
setOptions
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:398:9: error: 'class MQTTClient' has no member named '_sessionPresent'
this->_sessionPresent = options.session_present;
^~~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: In member function 'bool MQTTClient::publish(const char, const char, int, bool, int)':
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:421:3: error: 'lwmqtt_publish_options_t' was not declared in this scope
lwmqtt_publish_options_t options = lwmqtt_default_publish_options;
^~~~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:421:3: note: suggested alternative: 'lwmqtt_options_t'
lwmqtt_publish_options_t options = lwmqtt_default_publish_options;
^~~~~~~~
lwmqtt_options_t
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:424:13: error: 'class MQTTClient' has no member named 'nextDupPacketID'
if (this->nextDupPacketID > 0) {
^~~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:425:5: error: 'options' was not declared in this scope
options.dup_id = &this->nextDupPacketID;
^~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:425:5: note: suggested alternative: 'setOptions'
options.dup_id = &this->nextDupPacketID;
^~~
setOptions
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:425:29: error: 'class MQTTClient' has no member named 'nextDupPacketID'
options.dup_id = &this->nextDupPacketID;
^~~~~~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:430:23: error: 'options' was not declared in this scope
&this->client, &options, lwmqtt_string(topic), message, this->timeout);
^~~
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:430:23: note: suggested alternative: 'setOptions'
&this->client, &options, lwmqtt_string(topic), message, this->timeout);
^~~
setOptions
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp: At global scope:
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:441:35: error: no 'uint16_t MQTTClient::lastPacketID()' member function declared in class 'MQTTClient'
uint16_t MQTTClient::lastPacketID() {
^
C:\Users\grant\OneDrive\Documents\Arduino\libraries\MQTT\src\MQTTClient.cpp:446:52: error: no 'void MQTTClient::prepareDuplicate(uint16_t)' member function declared in class 'MQTTClient'
void MQTTClient::prepareDuplicate(uint16_t packetID) {
^
exit status 1
Compilation error: exit status 1
Done! I don't have a R4 Uno Minima but i tried compiling some code using arduino-cli and looks like it works.
Thanks for the quick response, that is great. I also got rid of all the compile errors by copying your code
inline char strdup(const char dup) { size_t len = strlen(dup) + 1; char copy = (char )malloc(sizeof(char) * len); strcpy(copy, dup); return copy; }
directly into the MQTTClient.cpp file
For sure this is not the most elegant solution, but given that those arduinos are missing those POSIX functions i guess it's okay until they fix it otherwise.
I'd like to wait for https://github.com/arduino/ArduinoCore-renesas/pull/87, as it will solve problem at the source.
I'm closing this as it seems that issue has been resolved in the Arduino core.
Implements missing "strdup" function in case of Arduino Uno R4 WiFi. Possible solution for https://github.com/256dpi/arduino-mqtt/issues/307.