Turning MQTT library into a buildable project...?

16 Jan 2017

Hello all! I am very new to mbed. I have successfully gotten several example programs running on my Nucleo-F746ZG (uses STM32). My goal now is to learn about MQTT using ethernet. I have found this library here: https://developer.mbed.org/teams/ST/code/MQTT/

...but there are no example projects...and no "main.cpp" file. The library does have a subfolder called "samples", which contains a file called "publish-subscribe.txt". I copied the contents of this into my own "main.cpp", but it wont compile. There are all kinds of "incompatible redefinition", etc.

Any pointers or resources would be helpful. I will continue learning/searching. Thx! -frenchy (Steve French) www.voltvision.com

02 Feb 2017

Here is the MQTT team's page:

https://developer.mbed.org/teams/mqtt/

They have some great examples.

I have been working with mbed and MQTT for my current project. MQTT needs a network socket to work correctly. Info on sockets:

https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/

Looking at the MQTTSocket class we see what functions the network socket will need to have:

MQTT Socket class

class MQTTSocket
{
public:    
    int connect(char* hostname, int port, int timeout=1000)
    {
        mysock.set_blocking(false, timeout);    // 1 second Timeout 
        return mysock.connect(hostname, port);
    }

    int read(unsigned char* buffer, int len, int timeout)
    {
        mysock.set_blocking(false, timeout);  
        return mysock.receive((char*)buffer, len);
    }
    
    int write(unsigned char* buffer, int len, int timeout)
    {
        mysock.set_blocking(false, timeout);  
        return mysock.send((char*)buffer, len);
    }
    
    int disconnect()
    {
        return mysock.close();
    }
    
private:

    TCPSocketConnection mysock; 
    
};

Here you can check out various projects that use MQTT:

https://developer.mbed.org/teams/mqtt/code/MQTT/dependents?page=1