The Cayenne MQTT mbed Library provides functions to easily connect to the Cayenne IoT project builder.

Fork of Cayenne-MQTT-mbed by myDevicesIoT

Committer:
pferland
Date:
Tue Apr 25 15:32:32 2017 +0000
Revision:
24:686d9ed1d192
Parent:
1:90dccf306268
Child:
22:0dbabcc6e7b2
Small changes for compatibility with MTSAS socket library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jburhenn 0:09ef59d2d0f7 1 /*
jburhenn 0:09ef59d2d0f7 2 The MIT License(MIT)
jburhenn 0:09ef59d2d0f7 3
jburhenn 0:09ef59d2d0f7 4 Cayenne MQTT Client Library
jburhenn 0:09ef59d2d0f7 5 Copyright (c) 2016 myDevices
jburhenn 0:09ef59d2d0f7 6
jburhenn 0:09ef59d2d0f7 7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
jburhenn 0:09ef59d2d0f7 8 documentation files(the "Software"), to deal in the Software without restriction, including without limitation
jburhenn 0:09ef59d2d0f7 9 the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software,
jburhenn 0:09ef59d2d0f7 10 and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
jburhenn 0:09ef59d2d0f7 11 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
jburhenn 0:09ef59d2d0f7 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
jburhenn 0:09ef59d2d0f7 13 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
jburhenn 0:09ef59d2d0f7 14 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
jburhenn 0:09ef59d2d0f7 15 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
jburhenn 0:09ef59d2d0f7 16
jburhenn 0:09ef59d2d0f7 17 */
jburhenn 0:09ef59d2d0f7 18
jburhenn 0:09ef59d2d0f7 19 #ifndef _CAYENNEUTILS_h
jburhenn 0:09ef59d2d0f7 20 #define _CAYENNEUTILS_h
jburhenn 0:09ef59d2d0f7 21
jburhenn 0:09ef59d2d0f7 22 #if defined(__cplusplus)
jburhenn 0:09ef59d2d0f7 23 extern "C" {
jburhenn 0:09ef59d2d0f7 24 #endif
jburhenn 0:09ef59d2d0f7 25
jburhenn 0:09ef59d2d0f7 26 #if defined(WIN32_DLL) || defined(WIN64_DLL)
jburhenn 0:09ef59d2d0f7 27 #define DLLImport __declspec(dllimport)
jburhenn 0:09ef59d2d0f7 28 #define DLLExport __declspec(dllexport)
jburhenn 0:09ef59d2d0f7 29 #elif defined(LINUX_SO)
jburhenn 0:09ef59d2d0f7 30 #define DLLImport extern
jburhenn 0:09ef59d2d0f7 31 #define DLLExport __attribute__ ((visibility ("default")))
jburhenn 0:09ef59d2d0f7 32 #else
jburhenn 0:09ef59d2d0f7 33 #define DLLImport
jburhenn 0:09ef59d2d0f7 34 #define DLLExport
jburhenn 0:09ef59d2d0f7 35 #endif
jburhenn 0:09ef59d2d0f7 36
jburhenn 0:09ef59d2d0f7 37 #include <stdio.h>
jburhenn 0:09ef59d2d0f7 38 #include "CayenneDefines.h"
jburhenn 0:09ef59d2d0f7 39
jburhenn 0:09ef59d2d0f7 40 enum CayenneReturnCode { CAYENNE_BUFFER_OVERFLOW = -2, CAYENNE_FAILURE = -1, CAYENNE_SUCCESS = 0 };
jburhenn 0:09ef59d2d0f7 41
jburhenn 1:90dccf306268 42 /**
jburhenn 1:90dccf306268 43 * A unit/value pair used in Cayenne payloads.
jburhenn 1:90dccf306268 44 */
jburhenn 0:09ef59d2d0f7 45 typedef struct CayenneValuePair
jburhenn 0:09ef59d2d0f7 46 {
jburhenn 1:90dccf306268 47 const char* unit; /**< The data unit. */
jburhenn 1:90dccf306268 48 const char* value; /**< The data value. */
jburhenn 0:09ef59d2d0f7 49 } CayenneValuePair;
jburhenn 0:09ef59d2d0f7 50
jburhenn 0:09ef59d2d0f7 51 /**
jburhenn 0:09ef59d2d0f7 52 * Build a specified topic string.
jburhenn 0:09ef59d2d0f7 53 * @param[out] topicName Returned topic string
jburhenn 0:09ef59d2d0f7 54 * @param[in] length CayenneTopic buffer length
jburhenn 0:09ef59d2d0f7 55 * @param[in] username Cayenne username
jburhenn 0:09ef59d2d0f7 56 * @param[in] clientID Cayennne client ID
jburhenn 0:09ef59d2d0f7 57 * @param[in] topic Cayenne topic
jburhenn 0:09ef59d2d0f7 58 * @param[in] channel The topic channel, use CAYENNE_NO_CHANNEL if none is required, CAYENNE_ALL_CHANNELS if a wildcard is required
jburhenn 0:09ef59d2d0f7 59 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 60 */
jburhenn 0:09ef59d2d0f7 61 DLLExport int CayenneBuildTopic(char* topicName, size_t length, const char* username, const char* clientID, CayenneTopic topic, unsigned int channel);
jburhenn 0:09ef59d2d0f7 62
jburhenn 0:09ef59d2d0f7 63 /**
jburhenn 0:09ef59d2d0f7 64 * Build a specified data payload.
jburhenn 0:09ef59d2d0f7 65 * @param[out] payload Returned payload
jburhenn 0:09ef59d2d0f7 66 * @param[in,out] length Payload buffer length
jburhenn 0:09ef59d2d0f7 67 * @param[in] type Optional type to use for type,unit=value payload, can be NULL
jburhenn 0:09ef59d2d0f7 68 * @param[in] values Unit/value array
jburhenn 0:09ef59d2d0f7 69 * @param[in] valueCount Number of values
jburhenn 0:09ef59d2d0f7 70 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 71 */
jburhenn 0:09ef59d2d0f7 72 DLLExport int CayenneBuildDataPayload(char* payload, size_t* length, const char* type, const CayenneValuePair* values, size_t valueCount);
jburhenn 0:09ef59d2d0f7 73
jburhenn 0:09ef59d2d0f7 74 /**
jburhenn 0:09ef59d2d0f7 75 * Build a specified response payload.
jburhenn 0:09ef59d2d0f7 76 * @param[out] payload Returned payload
jburhenn 0:09ef59d2d0f7 77 * @param[in,out] length Payload buffer length
jburhenn 0:09ef59d2d0f7 78 * @param[in] id ID of message the response is for
jburhenn 0:09ef59d2d0f7 79 * @param[in] error Optional error message, NULL for success
jburhenn 0:09ef59d2d0f7 80 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 81 */
jburhenn 0:09ef59d2d0f7 82 DLLExport int CayenneBuildResponsePayload(char* payload, size_t* length, const char* id, const char* error);
jburhenn 0:09ef59d2d0f7 83
jburhenn 0:09ef59d2d0f7 84 /**
jburhenn 0:09ef59d2d0f7 85 * Parse a topic string in place. This may modify the topic string.
jburhenn 0:09ef59d2d0f7 86 * @param[out] topic Returned Cayenne topic
jburhenn 0:09ef59d2d0f7 87 * @param[out] channel Returned channel, CAYENNE_NO_CHANNEL if there is none
jburhenn 0:09ef59d2d0f7 88 * @param[out] clientID Returned client ID
jburhenn 0:09ef59d2d0f7 89 * @param[in] username Cayenne username
jburhenn 0:09ef59d2d0f7 90 * @param[in] topicName Topic name string
jburhenn 0:09ef59d2d0f7 91 * @param[in] length Topic name string length
jburhenn 0:09ef59d2d0f7 92 * @return CAYENNE_SUCCESS if topic was parsed, error code otherwise
jburhenn 0:09ef59d2d0f7 93 */
jburhenn 0:09ef59d2d0f7 94 DLLExport int CayenneParseTopic(CayenneTopic* topic, unsigned int* channel, const char** clientID, const char* username, char* topicName, unsigned int length);
jburhenn 0:09ef59d2d0f7 95
jburhenn 0:09ef59d2d0f7 96 /**
jburhenn 0:09ef59d2d0f7 97 * Parse a null terminated payload in place. This may modify the payload string.
jburhenn 0:09ef59d2d0f7 98 * @param[out] values Returned payload data unit & value array
jburhenn 0:09ef59d2d0f7 99 * @param[in,out] valuesSize Size of values array, returns the count of values in the array
jburhenn 0:09ef59d2d0f7 100 * @param[out] type Returned type, NULL if there is none
jburhenn 0:09ef59d2d0f7 101 * @param[out] id Returned message id, empty string if there is none
jburhenn 0:09ef59d2d0f7 102 * @param[in] topic Cayenne topic
jburhenn 0:09ef59d2d0f7 103 * @param[in] payload Payload string, must be null terminated.
jburhenn 0:09ef59d2d0f7 104 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 105 */
jburhenn 0:09ef59d2d0f7 106 DLLExport int CayenneParsePayload(CayenneValuePair* values, size_t* valuesSize, const char** type, const char** id, CayenneTopic topic, char* payload);
jburhenn 0:09ef59d2d0f7 107
jburhenn 0:09ef59d2d0f7 108 #if defined(__cplusplus)
jburhenn 0:09ef59d2d0f7 109 }
jburhenn 0:09ef59d2d0f7 110 #endif
jburhenn 0:09ef59d2d0f7 111
jburhenn 0:09ef59d2d0f7 112 #endif