1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _IOT_EXPORT_LINKKIT_H_ 6 #define _IOT_EXPORT_LINKKIT_H_ 7 8 #if defined(__cplusplus) 9 extern "C" { 10 #endif 11 12 #include "linkkit/wrappers/wrappers.h" 13 14 typedef enum { 15 IOTX_LINKKIT_DEV_TYPE_MASTER, 16 IOTX_LINKKIT_DEV_TYPE_SLAVE, 17 IOTX_LINKKIT_DEV_TYPE_MAX 18 } iotx_linkkit_dev_type_t; 19 20 typedef struct { 21 char product_key[IOTX_PRODUCT_KEY_LEN + 1]; 22 char product_secret[IOTX_PRODUCT_SECRET_LEN + 1]; 23 char device_name[IOTX_DEVICE_NAME_LEN + 1]; 24 char device_secret[IOTX_DEVICE_SECRET_LEN + 1]; 25 } iotx_linkkit_dev_meta_info_t; 26 27 typedef enum { 28 /* post property value to cloud */ 29 ITM_MSG_POST_PROPERTY, 30 31 /* post device info update message to cloud */ 32 ITM_MSG_DEVICEINFO_UPDATE, 33 34 /* post device info delete message to cloud */ 35 ITM_MSG_DEVICEINFO_DELETE, 36 37 /* post raw data to cloud */ 38 ITM_MSG_POST_RAW_DATA, 39 40 /* only for slave device, send login request to cloud */ 41 ITM_MSG_LOGIN, 42 43 /* only for slave device, send logout request to cloud */ 44 ITM_MSG_LOGOUT, 45 46 /* only for slave device, send delete topo request to cloud */ 47 ITM_MSG_DELETE_TOPO, 48 49 /* query ntp time from cloud */ 50 ITM_MSG_QUERY_TIMESTAMP, 51 52 /* only for master device, query topo list */ 53 ITM_MSG_QUERY_TOPOLIST, 54 55 /* only for master device, qurey firmware ota data */ 56 ITM_MSG_QUERY_FOTA_DATA, 57 58 /* only for master device, qurey config ota data */ 59 ITM_MSG_QUERY_COTA_DATA, 60 61 /* only for master device, request config ota data from cloud */ 62 ITM_MSG_REQUEST_COTA, 63 64 /* only for master device, request fota image from cloud */ 65 ITM_MSG_REQUEST_FOTA_IMAGE, 66 67 /* report subdev's firmware version */ 68 ITM_MSG_REPORT_SUBDEV_FIRMWARE_VERSION, 69 70 /* get a device's desired property */ 71 ITM_MSG_PROPERTY_DESIRED_GET, 72 73 /* delete a device's desired property */ 74 ITM_MSG_PROPERTY_DESIRED_DELETE, 75 76 IOTX_LINKKIT_MSG_MAX 77 } iotx_linkkit_msg_type_t; 78 79 /** 80 * @brief create a new device 81 * 82 * @param dev_type. type of device which will be created. see 83 * iotx_linkkit_dev_type_t 84 * @param meta_info. The product key, product secret, device name and device 85 * secret of new device. 86 * 87 * @return success: device id (>=0), fail: -1. 88 * 89 */ 90 int IOT_Linkkit_Open(iotx_linkkit_dev_type_t dev_type, 91 iotx_linkkit_dev_meta_info_t *meta_info); 92 93 /** 94 * @brief start device network connection. 95 * for master device, start to connect aliyun server. 96 * for slave device, send message to cloud for register new device and 97 * add topo with master device 98 * 99 * @param devid. device identifier. 100 * 101 * @return success: device id (>=0), fail: -1. 102 * 103 */ 104 int IOT_Linkkit_Connect(int devid); 105 106 /** 107 * @brief try to receive message from cloud and dispatch these message to user 108 * event callback 109 * 110 * @param timeout_ms. timeout for waiting new message arrived 111 * 112 * @return void. 113 * 114 */ 115 void IOT_Linkkit_Yield(int timeout_ms); 116 117 /** 118 * @brief close device network connection and release resources. 119 * for master device, disconnect with aliyun server and release all local 120 * resources. for slave device, send message to cloud for delete topo with 121 * master device and unregister itself, then release device's resources. 122 * 123 * @param devid. device identifier. 124 * 125 * @return success: 0, fail: -1. 126 * 127 */ 128 int IOT_Linkkit_Close(int devid); 129 130 /** 131 * @brief Report message to cloud 132 * 133 * @param devid. device identifier. 134 * @param msg_type. message type. see iotx_linkkit_msg_type_t, as follows: 135 * ITM_MSG_POST_PROPERTY 136 * ITM_MSG_DEVICEINFO_UPDATE 137 * ITM_MSG_DEVICEINFO_DELETE 138 * ITM_MSG_POST_RAW_DATA 139 * ITM_MSG_LOGIN 140 * ITM_MSG_LOGOUT 141 * 142 * @param payload. message payload. 143 * @param payload_len. message payload length. 144 * 145 * @return success: 0 or message id (>=1), fail: -1. 146 * 147 */ 148 int IOT_Linkkit_Report(int devid, iotx_linkkit_msg_type_t msg_type, 149 unsigned char *payload, int payload_len); 150 151 /** 152 * @brief post message to cloud 153 * 154 * @param devid. device identifier. 155 * @param msg_type. message type. see iotx_linkkit_msg_type_t, as follows: 156 * ITM_MSG_QUERY_TIMESTAMP 157 * ITM_MSG_QUERY_TOPOLIST 158 * ITM_MSG_QUERY_FOTA_DATA 159 * ITM_MSG_QUERY_COTA_DATA 160 * ITM_MSG_REQUEST_COTA 161 * ITM_MSG_REQUEST_FOTA_IMAGE 162 * 163 * @param payload. message payload. 164 * @param payload_len. message payload length. 165 * 166 * @return success: 0 or message id (>=1), fail: -1. 167 * 168 */ 169 int IOT_Linkkit_Query(int devid, iotx_linkkit_msg_type_t msg_type, 170 unsigned char *payload, int payload_len); 171 172 /** 173 * @brief post event to cloud 174 * 175 * @param devid. device identifier. 176 * @param eventid. tsl event id. 177 * @param eventid_len. length of tsl event id. 178 * @param payload. event payload. 179 * @param payload_len. event payload length. 180 * 181 * @return success: message id (>=1), fail: -1. 182 * 183 */ 184 int IOT_Linkkit_TriggerEvent(int devid, char *eventid, int eventid_len, 185 char *payload, int payload_len); 186 187 #if defined(__cplusplus) 188 } 189 #endif 190 #endif 191