Receive the last error description.
void mco_iot_conn_get_error(iot_connection_h iotc,
mco_iot_stop_reason_t *reason,
MCO_RET *last_error,
int *last_errno,
char *message,
int message_len);
iotc
iot_connection_h).reason
One of the following enumerated values:
typedef enum mco_iot_stop_reason_t_
{
MCO_IOT_STOP_REASON_NONE = 0,
MCO_IOT_STOP_REASON_NETWORK_ERROR,
MCO_IOT_STOP_REASON_CALLBACK_FAILED,
MCO_IOT_STOP_REASON_IOT_STOPPED,
MCO_IOT_STOP_REASON_USER_REQUEST
} mco_iot_stop_reason_t;
last_error
last_errno
message
message_len
This function receives the error description for the last error in the
onDisconnect() and onDestroy() callbacks to find out
why the connection was dropped.
void
// onDisconnect callback
int iot_on_disconnect(mco_iot_connection_h iotc, void *context)
{
char errmsg[128];
mco_iot_stop_reason_t stop_reason;
MCO_RET last_error;
int last_errno;
mco_iot_conn_get_error(iotc, &stop_reason, &last_error, &last_errno, errmsg, sizeof(errmsg));
printf("IoT device %llu disconnected. Reason %d, errcode %d. errno %d : <%s>",
mco_iot_conn_get_agent_id(iotc), stop_reason, last_error, last_errno, errmsg);
return IOT_CALLBACK_OK;
}