v1.1.3
This release refactors the initial parts of the MQTT code into an external class, CloudIoTCoreMqtt:
class CloudIoTCoreMqtt {
// ...
MQTTClient *mqttClient;
Client *netClient;
CloudIoTCoreDevice *device;
public:
CloudIoTCoreMqtt(MQTTClient *&mqttClient, Client *&netClient, CloudIoTCoreDevice *&device);
void startMQTT();
void publishTelemetry(String data);
void publishTelemetry(String subtopic, String data);
void publishState(String data);
void onConnect();
void setLogConnect(boolean enabled);
void logError();
void logReturnCode();
void mqttConnect();
As a result, this refactor greatly reduces the amount of code that is copied between device examples and is progress towards having an example that works on multiple devices.
The caller is required for allocating the objects used with the wrapper to simplify the object management and allow the caller to manage / control what has context.
There are still some device-specific parts like connectivity / JWT generation that are defined globally within the examples.
Additional changes include:
- Minor documentation updates
- Enhanced reconnect logic
- Subtopic support for sending telemetry, ex:
mqttDevice->publishTelemetry("/subfolder", "data")
In future releases, we'll be looking to further unify the examples and further reduce the code made visible to the developer. For now, some of this is left visible in the example code to be tweaked.