It would be nice to have unique callback paths for each topic you subscribe to:
fnptrA = subscribe("topicA", callbackFnA(buffer,buffer_length))
fnptrB = subscribe("topicB", callbackFnB(buffer,buffer_length))
Also, I think that the callback function should be capable of using a supplied buffer (for storing the payload) that is given via its registration (above).
It would be cool to have the ability to register multiple callbacks with a given topic:
fnptrA1 = subscribe("topicA", callbackFnA1(buffer,buffer_length))
fnptrA2 =subscribe("topicA", callbackFnA2(buffer,buffer_length))
...
Adding and removing registered callback pointers would also be nice:
deregisterCallback(fnptrA);
...
Additionally, the current MQTT library has issues when trying to send more than the 128byte default payload limit (and I believe there are issues with the code if you try to change that default define... to accept larger limits...). It would be great to support the full payload length that MQTT (as a specification) supports (or at least make it configurable and expandable if needed).
The current MQTT library does not support wildcards in the topic name - this is a really cool feature in MQTT in that you can address whole sets of endpoints with wildcards. Wildcard support typically comes into play during the subscription:
fnptrA = subscribe("topic/tree/#", callbackFnA(buffer,buffer_length));
Lastly, it would be great to have the library support MQTT wills.
Up to now, we have had two major styles of MQTT APIs, which are exemplified by the Paho C and Java client libraries. The first style was designed to make MQTT programming a little easier. To that end, all of the calls block to some extent:
This, synchronous, style, as we call it, is described for the C client here: http://www.eclipse.org/paho/files/mqttdoc/Cclient/index.html, and for the Java client: http://www.eclipse.org/paho/files/javadoc/org/eclipse/paho/client/mqttv3/MqttClient.html.
In this style, there are 3 callbacks:
The second style, asynchronous, was intended to be used in environments where the application does not have the main thread of control, and blocking calls are not acceptable. Thus every API call indicates its success or failure by means of a callback, and never blocks.
This style of API is somewhat harder to use, providing more ability to shoot yourself in the foot, but is more flexible than the synchronous API - more operations can be executed in parallel. This style of API is described for the C client here: http://www.eclipse.org/paho/files/mqttdoc/Casync/index.html and for the Java client: http://www.eclipse.org/paho/files/javadoc/org/eclipse/paho/client/mqttv3/MqttAsyncClient.html. The Javascript API is in this style because it is intended to be used in a web browser using websockets.
The style of programs using the asynchronous API becomes quite different, and is one I have come to like. The whole program can become a series of callbacks. Connect, then wait for the connect callback, and in that callback, subscribe, and so on.
An mbed API could look like one of these APIs but with extra callbacks for the networking calls, to allow various networking APIs to be substituted.