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

Dependents:   Cayenne-ESP8266Interface Cayenne-WIZnet_Library Cayenne-WIZnetInterface Cayenne-X-NUCLEO-IDW01M1 ... more

Committer:
jburhenn
Date:
Wed Jan 25 11:10:39 2017 -0700
Branch:
feature/multivalue
Revision:
23:1a9aed5e77c9
Parent:
22:0dbabcc6e7b2
CayenneDataArray updates for multivalue support.

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 0:09ef59d2d0f7 43 * Build a specified topic string.
jburhenn 0:09ef59d2d0f7 44 * @param[out] topicName Returned topic string
jburhenn 0:09ef59d2d0f7 45 * @param[in] length CayenneTopic buffer length
jburhenn 0:09ef59d2d0f7 46 * @param[in] username Cayenne username
jburhenn 0:09ef59d2d0f7 47 * @param[in] clientID Cayennne client ID
jburhenn 0:09ef59d2d0f7 48 * @param[in] topic Cayenne topic
jburhenn 0:09ef59d2d0f7 49 * @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 50 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 51 */
jburhenn 0:09ef59d2d0f7 52 DLLExport int CayenneBuildTopic(char* topicName, size_t length, const char* username, const char* clientID, CayenneTopic topic, unsigned int channel);
jburhenn 0:09ef59d2d0f7 53
jburhenn 0:09ef59d2d0f7 54 /**
jburhenn 0:09ef59d2d0f7 55 * Build a specified data payload.
jburhenn 0:09ef59d2d0f7 56 * @param[out] payload Returned payload
jburhenn 0:09ef59d2d0f7 57 * @param[in,out] length Payload buffer length
jburhenn 0:09ef59d2d0f7 58 * @param[in] type Optional type to use for type,unit=value payload, can be NULL
jburhenn 22:0dbabcc6e7b2 59 * @param[in] unit Payload unit
jburhenn 22:0dbabcc6e7b2 60 * @param[in] value Payload value
jburhenn 0:09ef59d2d0f7 61 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 62 */
jburhenn 22:0dbabcc6e7b2 63 DLLExport int CayenneBuildDataPayload(char* payload, size_t* length, const char* type, const char* unit, const char* value);
jburhenn 0:09ef59d2d0f7 64
jburhenn 0:09ef59d2d0f7 65 /**
jburhenn 0:09ef59d2d0f7 66 * Build a specified response payload.
jburhenn 0:09ef59d2d0f7 67 * @param[out] payload Returned payload
jburhenn 0:09ef59d2d0f7 68 * @param[in,out] length Payload buffer length
jburhenn 0:09ef59d2d0f7 69 * @param[in] id ID of message the response is for
jburhenn 0:09ef59d2d0f7 70 * @param[in] error Optional error message, NULL for success
jburhenn 0:09ef59d2d0f7 71 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 72 */
jburhenn 0:09ef59d2d0f7 73 DLLExport int CayenneBuildResponsePayload(char* payload, size_t* length, const char* id, const char* error);
jburhenn 0:09ef59d2d0f7 74
jburhenn 0:09ef59d2d0f7 75 /**
jburhenn 0:09ef59d2d0f7 76 * Parse a topic string in place. This may modify the topic string.
jburhenn 0:09ef59d2d0f7 77 * @param[out] topic Returned Cayenne topic
jburhenn 0:09ef59d2d0f7 78 * @param[out] channel Returned channel, CAYENNE_NO_CHANNEL if there is none
jburhenn 0:09ef59d2d0f7 79 * @param[out] clientID Returned client ID
jburhenn 0:09ef59d2d0f7 80 * @param[in] username Cayenne username
jburhenn 0:09ef59d2d0f7 81 * @param[in] topicName Topic name string
jburhenn 0:09ef59d2d0f7 82 * @param[in] length Topic name string length
jburhenn 0:09ef59d2d0f7 83 * @return CAYENNE_SUCCESS if topic was parsed, error code otherwise
jburhenn 0:09ef59d2d0f7 84 */
jburhenn 22:0dbabcc6e7b2 85 DLLExport int CayenneParseTopic(CayenneTopic* topic, unsigned int* channel, const char** clientID, const char* username, char* topicName, size_t length);
jburhenn 0:09ef59d2d0f7 86
jburhenn 0:09ef59d2d0f7 87 /**
jburhenn 0:09ef59d2d0f7 88 * Parse a null terminated payload in place. This may modify the payload string.
jburhenn 0:09ef59d2d0f7 89 * @param[out] type Returned type, NULL if there is none
jburhenn 22:0dbabcc6e7b2 90 * @param[out] unit Returned unit, NULL if there is none
jburhenn 22:0dbabcc6e7b2 91 * @param[out] value Returned value, NULL if there is none
jburhenn 0:09ef59d2d0f7 92 * @param[out] id Returned message id, empty string if there is none
jburhenn 0:09ef59d2d0f7 93 * @param[in] topic Cayenne topic
jburhenn 0:09ef59d2d0f7 94 * @param[in] payload Payload string, must be null terminated.
jburhenn 0:09ef59d2d0f7 95 * @return CAYENNE_SUCCESS if topic string was created, error code otherwise
jburhenn 0:09ef59d2d0f7 96 */
jburhenn 22:0dbabcc6e7b2 97 DLLExport int CayenneParsePayload(const char** type, const char** unit, const char** value, const char** id, CayenneTopic topic, char* payload);
jburhenn 0:09ef59d2d0f7 98
jburhenn 0:09ef59d2d0f7 99 #if defined(__cplusplus)
jburhenn 0:09ef59d2d0f7 100 }
jburhenn 0:09ef59d2d0f7 101 #endif
jburhenn 0:09ef59d2d0f7 102
jburhenn 0:09ef59d2d0f7 103 #endif