Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation help #20

Open
tgdavies opened this issue May 28, 2018 · 5 comments
Open

Installation help #20

tgdavies opened this issue May 28, 2018 · 5 comments

Comments

@tgdavies
Copy link

I'm not that familiar with platformio, so I would like more explicit installation instructions -- should I be adding the contents of this repo to ~/.platformio/packages/framework-espidf/components/esp-mqtt?

@julianobst
Copy link

julianobst commented May 30, 2018

My favorite way would be to add the library as submodule into the src/ or lib/ folder under project root. But I haven't figured out how to correctly include the relevant paths to platformio with the configuration options in the platformio.ini file. If anyone has a working solution, please let me know.

For a quick and dirty but working solution, I created a folder esp-mqtt under src/ and copied the following files and subfolders from the esp-mqtt library into the folder src/esp-mqtt:

esp_lwmqtt.c
esp_lwmqtt.h
esp_mqtt.c
esp_mqtt.h
lwmqtt/include/lwmqtt.h
lwmqtt/src/client.c
lwmqtt/src/helpers.c
lwmqtt/src/helpers.h
lwmqtt/src/packet.c
lwmqtt/src/packet.h
lwmqtt/src/string.c

I didn't copy the tests and examples because platformio always compile all files... the result were just a lot of errors...

For the usage you must include the library within the __cplusplus preprocessor directive for C++ Code

#ifdef __cplusplus
extern "C" {
#endif

#include "esp-mqtt/esp_mqtt.h"

#ifdef __cplusplus
}
#endif

And don't forget to enable the LWIP_SO_RCVBUF by adding
#define CONFIG_LWIP_SO_RCVBUF 1 to sdkconfig.h

//edit
I forget the worst part of the quick and dirty solution. I have changed the includes of some library files to relative paths. I'm so ashamed of this hack...

Change #include <lwmqtt.h> to #include "../include/lwmqtt.h" in the files:

  • esp-mqtt/lwmqtt/src/helpers.h
  • esp-mqtt/lwmqtt/src/string.c

and Change #include <lwmqtt.h> to #include "lwmqtt/include/lwmqtt.h" in

  • esp-mqtt/esp_lwmqtt.h

I know this is so bad and I'm looking forward for any other solution.

@Netskeh
Copy link

Netskeh commented Jun 20, 2018

Unfortunately I couldn't get the dirty hack going, but I got some partial success by adding this to platformio.ini file:
lib_deps = https://github.com/256dpi/esp-mqtt.git
It starts downloading, and it is added the the piolibdeps folder. Unfortunately I haven't had the time to have a close look at the compile errors.

@PProvost
Copy link

I found that adding esp-mqtt via github link, like @Netskeh did, PLUS adding lwmqtt as well, makes it so you don't have to edit the include lines.

   lib_deps =
     https://github.com/256dpi/esp-mqtt.git
     LWMQTT

@PProvost
Copy link

For anyone else trying to use this with platformio... Since it doesn't have the make menuconfig stuff integrated yet, you will need to add the following to your sdkconfig.h:

#define CONFIG_ESP_MQTT_ENABLED 1
#define CONFIG_ESP_MQTT_EVENT_QUEUE_SIZE 64
#define CONFIG_ESP_MQTT_TASK_STACK_SIZE 4096
#define CONFIG_ESP_MQTT_TASK_STACK_PRIORITY 5

@PProvost
Copy link

A few more things I found for making it work cleanly with platformio:

  1. In unix.c replace #include <memory.h> with #include <string.h>. As far as I can tell, memory.h is not included in ESP-IDF, and I think include is only included to use memset() which is defined in string.h.

  2. I deleted the submodule linkage to lwmqtt

  3. I added the following library.json to the root of esp-mqtt:

{
    "name": "esp-mqtt",
    "description": "MQTT library for ESP-IDF",
    "keywords": "esp32 mqtt2",
    "repository": {
        "type": "git",
        "url": "https://github.com/256dpi/esp-mqtt.git"
    },
    "export": {
        "include": [ "*.h", "*.c" ],
        "exclude": [ "lwmqtt/tests/*" ]
    },
    "dependencies": {
        "LWMQTT": "~0.6.2"
    }
}

Now it at least will build without errors. Next up is trying to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants