iot_cloud.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef __IOT_CLOUD_H__
  16. #define __IOT_CLOUD_H__
  17. #include <stdbool.h>
  18. #include <iot_demo_def.h>
  19. /**
  20. * @brief Initialize the cloud sdk
  21. * @return 0 success while others failed
  22. */
  23. int CLOUD_Init(void);
  24. /**
  25. * @brief Do deinitialize the cloud sdk
  26. * @return 0 success while others failed
  27. */
  28. int CLOUD_Deinit(void);
  29. /**
  30. * @brief Send collected data to Cloud Platform
  31. * @param jsonString, which means this has been formated as the profile defines
  32. * @return Returns 0 success while others failed
  33. */
  34. int CLOUD_ReportMsg(const char *jsonString);
  35. /**
  36. * @brief Connect to the Cloud Platform
  37. * @param deviceID Indicats the deviceID create in the iot platform
  38. * @param devicePwd Indicates the corresponding to the deviceID
  39. * @param serverIP Indicates the ip of the iot platform
  40. * @param serverPort Indicates the port correspond to the ip
  41. * @param cmdCallBack Indicates command callback and will be called if any message comes
  42. * @return Returns 0 success while others failed
  43. */
  44. int CLOUD_Connect(const char *deviceID, const char *devicePwd, \
  45. const char *serverIP, const char *serverPort);
  46. /**
  47. * @brief Disconnect from the Cloud Platform
  48. * @return 0 success while others failed
  49. */
  50. int CLOUD_Disconnect(void);
  51. /**
  52. * @brief use this is a call back function implemented by the demo
  53. * @param jsonString indicated the jsonString received from the iot_cloud
  54. * @return Returns 0 success while -1 failed
  55. */
  56. int CLOUD_CommandCallBack(const char *jsonString);
  57. /**
  58. * @brief functions and data for the syntax format
  59. *
  60. */
  61. // enum all the data type for the oc profile
  62. typedef enum {
  63. IOT_PROFILE_KEY_DATATYPE_INT = 0,
  64. IOT_PROFILE_KEY_DATATYPE_LONG,
  65. IOT_PROFILE_KEY_DATATYPE_FLOAT,
  66. IOT_PROFILE_KEY_DATATYPE_DOUBLE,
  67. IOT_PROFILE_KEY_DATATYPE_STRING,
  68. IOT_PROFILE_KEY_DATATYPE_LAST,
  69. }IotProfileDataType;
  70. typedef struct {
  71. void *nxt; ///< ponit to the next key
  72. char *key;
  73. IotProfileDataType type;
  74. void *value;
  75. }IotProfileKV;
  76. typedef struct {
  77. void *nxt;
  78. char *serviceID; ///< the service id in the profile, which could not be NULL
  79. char *eventTime; ///< eventtime, which could be NULL means use the platform time
  80. IotProfileKV *propertyLst; ///< the property in the profile, which could not be NULL
  81. } IotProfileService;
  82. /**
  83. * @brief Package the profile to json string mode, and you should free it manually
  84. * @param serviceLst, profile services
  85. * @return Returns the formates json string or NULL if failed
  86. *
  87. */
  88. char *IoTProfilePackage(IotProfileService *serviceLst);
  89. char *IotNotificationPackage(int type, const char *enString, const char *chString);
  90. typedef enum {
  91. NOTIFY_TYPE_NORMAL = 0,
  92. NOTIFY_TYPE_SECONDARY,
  93. NOTIFY_TYPE_URGENT,
  94. NOTIFY_TYPE_LAST
  95. } NOTIFY_TYPE;
  96. int CLOUD_ReportNotification(int type, const char *enString, const char *chString);
  97. int CLOUD_GetCloudConnectedStatus(void);
  98. #endif /* __IOT_CLOUD_H__ */