![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
MQTT version for enno SDK
Dependencies: EthernetInterface MQTT mbed-rtos mbed serialzation_lib
Fork of HelloMQTT by
Diff: protocol/enno_api.h
- Revision:
- 20:3858e42b0cd3
- Child:
- 21:c5f6350a292d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/protocol/enno_api.h Wed Nov 25 07:07:31 2015 +0000 @@ -0,0 +1,160 @@ +/* + * enno_api.h + * + * Created on: 2015年11月20日 + * Author: wzy + */ + +#ifndef PROTOCOL_ENNO_API_H_ +#define PROTOCOL_ENNO_API_H_ + +// +// Created by root on 11/10/15. +// +#if definded(__cplusplus) +extern "C" { +#endif + +#include "stddef.h" +#include "stdbool.h" +#include "stdint.h" +#include "enno_error.h" +#include "enno_config.h" + + + +typedef struct { + char *pHardwareId; + char *pSpecificationToken; + char *pOriginator; +} Register_enno; + +typedef struct { + char *pHardwareId; + char *pMessage; + char *pOriginator; +} Acknowledge_enno; + +typedef struct { + char *pHardwareId; + char *pName; + char *pOriginator; + float value; + int64_t eventDate; +} Measurement_enno; + +typedef struct { + char *pHardwareId; + char *pOriginator; + float lat; + float lon; + float ele; + int64_t eventDate; +} Location_enno; + +typedef struct { + char *pHardwareId; + char *pAlertType; + char *pAlertMessage; + char *pOriginator; + int64_t eventDate; +} Alert_enno; + +typedef struct { + char messageType; + Register_enno Register; + Acknowledge_enno Acknowledge; + Measurement_enno Measurement; + Location_enno Location; + Alert_enno Alert; +} EnnoMessages; +//extern EnnoMessages EnnoMessagesDefault; +EnnoMessages EnnoMessagesDefault = { + .messageType = 'R', + .Register = {.pHardwareId = "enno-default-test-id-11", .pSpecificationToken = "417b36a8-21ef-4196-a8fe-cc756f994d0b", .pOriginator = NULL}, //7dfd6d63-5e8d-4380-be04-fc5c73801dfb + .Acknowledge = {.pMessage = NULL, .pOriginator = NULL}, + .Measurement = {.pName = "Temperature", .pOriginator = NULL, .value = 16, .eventDate = 0}, + .Location = {.pOriginator = NULL, .lat = 27.59, .lon = 86.5, .ele = 8844.43, .eventDate = 0}, + .Alert = {.pAlertType = "enno.info", .pAlertMessage = "I am alive", .pOriginator = NULL, .eventDate = 0} +}; + +/** + * @brief Handles the system callback message + * + * params: topic the topic subscribed by client + * payload the received payload + * length the length of payload + * + */ +void ennoSystemMessageHandler(char* topic, char* payload, int length); + +/** + * @brief Connection Function + * + * Called to establish an connection with the Enno IoT Service + * + * @param: HostURL the website address to connect + * port listening port + * appKey a key for authentication + * @return An IoT Error Type defining successful/failed connection + */ + +Error_t enno_connect(char *HostURL, uint16_t port, char *appKey); + +/** + * @brief Subscribe to a topic. + * + * Called to send a subscribe message to the broker + * + * @param: Topic Pointer to a Topic + * callback Pointer to a callback function + * @return An IoT Error Type defining successful/failed subscription + */ +Error_t enno_subscribe(char *topic, void *callback); +/** + * @brief Publish a message to a path + * + * Called to publish a message to a path. + * + * @param: path the destination of message sent to + * messages_enno Pointer to the published message + * @return An IoT Error Type defining successful/failed publish + */ + +//Error_t enno_publish(char path, EnnoParams *Params_enno, PublishParams *pParams); +Error_t enno_publish(char *path, EnnoMessages *messages_enno); +/** + * @brief Unsubscribe to an topic. + * + * Called to send an usubscribe message to the broker requesting removal of a subscription + * to a topic. + * + * @param: pTopic Pointer to the requested topic string. Ensure the string is null terminated + * @return An IoT Error Type defining successful/failed unsubscription + */ +Error_t enno_unsubscribe(char *pTopic); + +/** + * @brief Disconnect a Connection + * + * Called to send a disconnect message to the broker. + * + * @return An IoT Error Type defining successful/failed send of the disconnect control packet. + */ +Error_t enno_disconnect(); + +/** + * @brief Yield to the client + * + * Called to yield the current thread to the underlying client. + * + * @param timeout Maximum number of milliseconds to pass thread execution to the client. + * @return An IoT Error Type defining successful/failed client processing. + */ + +Error_t enno_loop(int timeout); +#ifdef __cplusplus +} +#endif + +#endif /* PROTOCOL_ENNO_API_H_ */