安信可科技

AiCloud iOS SDK Development Guide



AiCloud iOS SDK Development Guide

v1.4.0

revise history

Version Revision Content Revision by Reviewer Revision Date
1.0.0 Create Document Zhao Ying Cody 2016.8.23
1.0.1 Add smart connection, two interface callbacks for successful network access Zhao Ying Cody 2016.8.30
1.1.0 New batch deployment method (9.2) Zhao Ying Cody 2016.9.05
1.1.1 The uuid generation rules have been changed, users need to generate them themselves (see Note 4), the initialization method of the control device has been changed, and the user name, password, and uuid parameters have been added (10.1) Zhao Ying Cody 2016.9. 07
1.1.2 iOS and Android unified interface parameter names Zhao Ying Cody 2016/9/07
1.2.0 Add TCP LAN control device function, add light configuration description in SDK configuration description Zhao Ying Cody 2016/9/21
1.2.1 Update bulb light data points Zhao Ying 2016/10/9
1.2.2 Modify SDK CommConfig: Communication configuration type, user configures before SDK use, and adds and closes MQTT service interface Zhao Ying 2016/10/13
1.3.0 Unified interface with Android (method name and parameter changes are large), encapsulated mqtt can establish multiple connection functions Zhao Ying 2016/10/19
2016/10/28
1.3.2 Added mqtt return to the original data interface, and added the NSData type parameter interface for publishing devices Zhao Ying 2016/11/2
1.4.0 1. The underscore of the parameter naming convention is changed to camel case 2. There are many new interfaces, see the .h header file for details Zhao Ying 2016/11/22

1. AiCloud iOS SDK environment description

Precautions

1. The user login return value is only retained for 15 minutes, and you need to make a good judgment during the app development process to avoid unnecessary bugs

2. Configure before using SDK: Add “-all_load” to “Other Linker Flags” option in “Build Settings”;

3. The third-party frameworks referenced by this SDK include MQTTClient, MKNetwork, and AsyncSocket. Developers should avoid repeated references

4. uuid: uuid should be guaranteed to remain unchanged after the application is installed, and to be as unique as possible for tracking back. It is recommended to convert the unix timestamp*1000+ms value into a hexadecimal string when the app is started for the first time, and then intercept the first 12 bytes. If it is less than 12 bytes, fill it with a random string. (The addition of the millisecond value takes into account that the same user may open more than one APP at the same time in one second. If you use milliseconds, it is difficult to open multiple APPs at the same time in one millisecond, which is difficult for the same user It’s not unique anymore) Save it after the generation is complete, and ensure that it remains unchanged before uninstalling the APP.

Socket configuration description:

1. Press and hold the button, the small green light flashes slowly for intelligent network distribution mode, medium flashing for AP network distribution mode, fast flashing for OTA production inspection, and long light for successful initialization. 2. If the smart connection fails, press and hold the button, enter the AP network distribution mode after 6 seconds (green light flashes), and return to the field setting after 15 seconds

Light configuration instructions:

Generally, the light does not need to be initialized, unless you want to reconnect to other WIFI, switch once every two seconds (keep on for 1 second), enter the smart connection mode three times, enter the AP mode four times, and initialize it ten times.

CommConfig.m: Communication configuration class, user configuration before SDK use

/**
* Server path configuration [[http://api.vcd.io:4567/v1/|http://api.vcd.io:4567/v1/]]
* Note: "http://" cannot be added to this address
*/
NSString* NETWORK_URL=@" 123.56.46.239:4568/v1";
 
/**
* Key and secret of cooperative vendors; Provided by AiCloud to cooperative vendors
 */
NSString* ACCESS_KEY = @"2b250d04d459ec46bed1a57dad028915";
NSString * ACCESS_SECRET = @" 0e8d106602f4125a16e11445645bcc18";

Release Notes:

This update mainly adds the SMS verification interface. The SMS verification interface has only one parameter of the mobile phone number (phone). The registration interface has been slightly changed, and two parameters have been added: 1. SMS verification code (messageCode, userCode), and the manufacturer is added to the configuration information id (VENDOR_ID), added the mqtt callback original data interface, and added the NSData type interface for publishing parameters

2. Work flow

3. API instructions for use

3.1 Turn on UDP service

Note: Only enable UDP service to discover devices, enable UDP service to allow devices to connect to the network

3.1.1 Get DeviceManager singleton

[UserManager SharedInstance];

3.1.2 Open UDP service

[userManager OpenUDPServer];

3.1.3 Close UDP service

[userManager OpenUDPServer];

3.2 User login

3.2.1 Get UserManager singleton

+ (UserManager *)sharedInstance;

3.2.2 Get SMS verification code

Request parameter

Parameters Type Required Default Description
phone NSString Yes None Mobile Number
templateId int yes no 1 or 2 (register 1, change password 2)

Return parameter

Parameters Type Description
userCode NSString suerCode, used when registering/modifying password

Method call example

-(Void)getMessage:(NSString*)phone templateId:(int)templateId completionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Return example

{
"Success": true,
"Data": {
        "userCode": "sa4nUnfQisGTZH3EmE8JEE"
    }
}

3.2.3 User Registration

Request parameter

Parameters Type Required Default Description
mobile NSString Yes None Mobile number
password NSString yes none user password
messageCode NSString Yes None Verification code received by mobile phone
userCode NSString Yes None userCode (obtained when obtaining SMS verification code)

Return parameter

Parameters Type Description
userId NSString User ID

Call method

-(Void)registerWithPassword:(NSString*)passworduserCode:(NSString*)userCodemessageCode:(NSString*)messageCode mobile:(NSString*)mobilecompletionHandler:(void(^)(id responseJSON,NSError*error))completionHandler;

Correct return example

{
"Success": 1,
"Data": {
        "userId": "sa4nUnfQisGTZH3EmE8JEE"
}}
}

Error return example

{
"Success": 0,
"ErrorCode": 500,
"Message": "internal error"
}

3.2.4 Retrieve password

Request parameter

Parameters Type Required Default Description
mobile NSString Yes None Mobile number
password NSString yes none user password
messageCode NSString Yes None Verification code received by mobile phone
userCode NSString Yes None userCode (obtained when obtaining SMS verification code)

Return parameter

Parameters Type Description
None None None

Call method

//Retrieve password interface implementation
-(Void)resetPasswordWithPassword:(NSString*)passworduserCode:(NSString*)userCodemessageCode:(NSString*)messageCode mobile:(NSString*)mobilecompletionHandler:(void(^)(id responseJSON,NSError*error))completionHandler;

Correct return example

{
"Success": 1,
"Data": {
"success": "1"
}
}

Error return example

{
"Success": 0,
"ErrorCode": 500,
"Message": "internal error"
}

3.2.5 User login

Request parameter

Parameters Type Required Default Description
username NSString Yes None Username/Mobile phone number (Username length cannot exceed 32 bytes)
password NSString yes none account password

Return parameter

Parameters Type Description
userToken NSString User token (expires in 15 minutes)
userId NSString User ID

The user login return value is only retained for 15 minutes, and you need to make a judgment during the app development process to avoid unnecessary bugs

Call method

-(Void)loginUserName:(NSString*)username
password:(NSString *)password
completionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Correct return example

{
"success": 1,
"data": {
"userToken": "350cfc21-cc96-4a59-8570-d4d1e40b1ebe",
"userId": "sa4nUnfQisGTZH3EmE8JEE"
}
}

Error return example

{
"success": 0,
"errorCode": 500,
"message": "Internal error"
}

3.2.6 Modify user name

Request parameter

Parameters Type Required Default Description
userId NSString Yes None User ID (return value when logging in)
username NSString Yes None The new user name to be set (the length of the user name cannot exceed 32 bytes)

Return parameter

Parameters Type Description
responseJSON id Modify device name return value

Call method

//Change user name UserManager call
-(Void)updateUserInfoWithUserId:(NSString*)userId username:(NSString*)usernamecompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Correct return example

{
data = {
success = 1;
};
success = 1;
}

Error return example

{
"errorCode":400,
"message":"user already binding",
"success":0
}

To

3.2.7 Query user information

Request parameter

Parameters Type Required Default Description
userId NSString Yes None User id (return value when logging in)

Return parameter

Parameters Type Description
responseJSON id Query user information return value

Call method

//Query user information UserManager call
-(void)getUserInfoWithUserId:(NSString*)userIdcompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Correct return example

{
data = {
userMobile = 18500272824;
username = hh;
};
success = 1;
}

Error return example

{
"errorCode":400,
"message":"user already binding",
"success":0
}

3.3 Branch One

3.3.1 Get the bound device

Request parameter

Parameters Type Required Default Description
userToken NSString Yes None User token

Return parameters: The return value is a json string, and the following parameters can be obtained after parsing

Parameters Type Description
deviceId NSString Device ID
devicePassword NSString Device Password
status BOOL Equipment status
productId NSString Product ID
productName NSString Product Name
server NSString The address of the server where the device establishes an MQTT connection (Note: If the server is empty, first unbind and then rebind)

Calling method: call using UserManager object

-(Void)getDeviceListForUser:(NSString*)userToken
CompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Correct return example

{
"success": 1,
"data":[
{
"productId": "pnTSD3ZsRNVgvNn6YRC2Z5",
"deviceId": "sa4nUnfQisGTZH3EmE8JEE",
"devicePassword": "0a1704dee5ed7200fcea5f627f6d1fd1",
"server": "mqtt://s1.vcd.io:1883",
"status": 1,
"productName": "bulb light"
}
]
}

Error return example

{
"Success": 0,
"ErrorCode": 500,
"Message": "Internal error"
}

3.3.2 Unbind equipment

Request parameter

Parameters Type Required Default Description
userToken NSString Yes None User token
deviceId NSString Yes None Device id (obtained from the bound device list)
devicePassword NSString Yes None Device password (obtained from the list of bound devices)

Return parameter

Parameters Type Description
responseJSON id Binding device feedback information

Call method

-(Void)unbindDeviceForUser:(NSString*)userToken
deviceId:(NSString*)deviceIddevicePassword:(NSString*)devicePassword
completionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Return information correctly

responseJSON---> {
"Data":{
"result":"SUCCESS"
},
"success":1
}

Error return information

no

3.3.3 Control equipment

3.3.3.1 Generalized Network Control Equipment

3.3.3.1.1 Generalized Network Control Equipment (It can be used to read the status of the device, or it can be used to control the device)

Request parameter

Parameters Type Required Default Description
deviceId String Yes None The device's deviceId can be obtained when querying the bound list
params NSDictionary Yes None Json string that needs to publish parameters
serverUrl NSString Yes None Get the list of bound devices (also available for bound devices)

Return parameter

Parameters Type Description
None None None

Call method

-(Void)publishMessage:(NSString*)deviceId serverUrl:(NSString*)serverUrl params:(NSDictionary*)params;

Example of reading device status params

{
"i": sequence id, (who sent, who generated)
"d":{["key1","key2",,"keyn"]} is empty, the device does not need to report data
"t": Timestamp
}

Example of control device params

{
"i": serial id, (who sent, who generated)
"d":{
"key1":"value1",
"key2":"value2","keyn":"valuen"
}
"t": unix timestamp
}

Return example

no

3.3.3.1.2 Generalized Network Control Equipment (Interface 2 The parameters are the same as above, but the params parameter type is converted to NSData)

Calling method:

-(Void)publishMessage:(NSString*)deviceId serverUrl:(NSString*)serverUrl data:(NSData*)data;

3.3.3.2 LAN control equipment

Note: The priority of TCP control is higher than MQTT control. First, determine whether the device can be controlled by TCP. If it is possible to execute TCP control, use MQTT control if it is not.

Open TCP service

Request parameter

Parameters Type Required Default Description
delegate id yes none TCPHelperd proxy object
deviceId NSString Yes None Device ID (obtained from the method of obtaining device list)
deviceIp NSString Yes None Device IP (obtained from the method of obtaining device list)
devicePassword NSString Yes None Device password (obtained from the method of obtaining device list)

Return parameter

Parameters Type Description
None None None

Call method

-(Id)openTCPServerWithDelegate:(id)delegate deviceIp:(NSString*)deviceIp devicePassword:(NSString*)devicePassword deviceId:(NSString*)deviceId;

tcp control equipment

Request parameter

Parameters Type Required Default Description
commandDict NSDictionary Yes None Device information controlled by TCP

Note: This method can be used to read the device and release the device. The CGFloat type parameter retains 2 decimal places, and the value transfer example is as follows

Return parameter

Parameters Type Description
None None None

Call method

(void)tcpSendData:(NSDictionary*)params;

Example of writing bulb light json (you do not need to send all data points when sending, you can send corresponding data points according to your needs)

{
"I": 4,
"D": {
"S":0,
"M":1,
"Hue": 0.5,
"Lit": 0.5,
"Sat": 0.5,
"Lum": 0.5,
"Tem": 0.5
},
"T":1464714257
"DeviceId": "PGiHMkrgyxrUCuLgEfubUU"
}

Example of reading bulb lamp (you do not need to send all data points when sending, you can send corresponding data points according to your needs)

{
"i":4,
"d":{
[
"s":0,
"m":1,
"hue":0.5,
"lit":0.5,
"sat":0.5,
"lum":0.5,
"tem":0.5
]
},
"T":1464714257
"DeviceId": "PGiHMkrgyxrUCuLgEfubUU"
}

Determine whether TCP is connected

Calling method: Determine whether to connect through the proxy method parameter isTCPConnected

(void)isTCPConnected:(BOOL)isTCPConnected;

TCP service feedback information

Request parameter

Parameters Type Required Default Description
None None None None None

Return parameter

Parameters Type Description
receiveDict NSDictionary TCP connection return information

Calling method: proxy method, the return value is returned by receiveDict

-(Void)tcpReceiveData:(NSDictionary*)receiveDict;

Return json example (write, return data points are returned according to sent data points, which data points are sent back which ones, and those not sent will not be returned)

{
"d":{
"s":0,
"m":1,
"hue":0.5,
"lit":0.5,
"sat":0.5,
"lum":0.5,
"tem":0.5
},
"t":1464714257,
"i":234
}

Return json example (read, return data points are returned according to sent data points, which data points are sent back which ones, and those not sent will not be returned)

{
"d":{
"s":0,
"m":1,
"hue":0.5,
"lit":0.5,
"sat":0.5,
"lum":0.5,
"tem":0.5
},
"t":1464714257,
"i": 234
}

Disconnect TCP connection

Note: Disconnect the TCP service when the controller is destroyed

Call method

-(Void)closeTCPServer;

3.4 Branch Two

3.4.1 Equipment deployment

Request parameter

Parameters Type Required Default Description
userToken NSString Yes None User token with expiration time

Return parameter

Parameters Type Description
responseJSON NSDictionary Interface callback returns string, see return example for details

Call method

-(Void)deployForUser:(NSString*)userTokencompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler

Correct return example

{
"success": 1,
"data": {
"serverList": [
{
"server": "mqtt://s1.vcd.io:1883",
"username": "tNb3ZgG9HLNiCEfNnushp6",
"password": "dmUxHriiFrsAxJNTNd9Pz3",
"pubkey":"",
"pkVersion":""
},],
"signature": "8e0bb23839955bde1346b6e9395347ff"
}
}

Note: When the request return value serverList count>=1, all MQTT links must be established (if there are several servers, several MQTT connections are established)

Error return example

{
    "success": 0,
    "errorCode":500,
    "message": "Internal error"
}

3.4.2 Establish MQTT connection

3.4.2.1 Obtain the DeviceManager singleton (before establishing a connection, you must first ensure that the DeviceManager singleton is obtained)

3.4.2.2 Establish MQTT connection

Note: When MQTT is connected, when the Apple device enters the foreground from the lock screen or background state, it will automatically reconnect. Only when the network is switched, you need to manually call the reconnection port

Request parameter

Parameters Type Required Default Description
userId NSString Yes None User ID
serverHost NSString Yes None MQTT server IP address
serverPort int32_t yes none MQTT port
username NSString Yes None The user name when logging in to MQTT, obtained from the information returned after deploying the device
password NSString Yes None The password when logging in to MQTT, obtained from the information returned after deploying the device
uuid NSString Yes None Generated when the user logs in to the device for the first time, generated by referring to uuid rules

Return parameter

Parameters Type Description
devInfo NSDictionary The returned json string is not the return value of successful connection establishment, but the feedback data of the device after the message is successfully published
deviceId NSString Device ID

Call method

-(Void)openMQTTServerWithUserId:(NSString*)userId
ServerUrl:(NSString*)serverUrl
UserName:(NSString*)username
Password: (NSString *)password
Uuid:(NSString*)uuid
CompletionHandler:(void(^)(NSString*deviceId,NSDictionary*devInfo,NSError*error))completionHandler;

Note: After the device receives the control command, get the device return information in this callback

Correct return example

Socket read device status return example

devInfo = {
"I": 3,
"D":{
        "s": 1
    },
"DeviceId":"ssxggsjsfks",
    "t":"1464714257"
}
deviceId="sdgjshghklgjsgdshgjsdhk"

Socket control return example

devInfo={
"I": 3,
"D":{
        "s":1
    },
"T": "1464714257"
}
deviceId = "ssxggsjsfks"

Example of returning the status of the light bulb reading the device (the number of parameters returned by the json string when reading the device status is determined by the parameters passed in when publishing. Which parameter is passed in will return which parameter, and if there is no incoming parameter, it will not be returned.

s: switch, integer, 0 is off, 1 is on

m: Mode, integer, 1 is color light mode, 2 is white light mode, 0 is RAW mode (RGB raw data point mode)

hue: the angle of the color circle, 0 to 360 degrees, floating point (reserve 2 decimal places)

lit: brightness, used to adjust the brightness of the color mode, 0 to 1, the default value is 0.5, floating point (reserve 2 decimal places)

sat: Contrast, used to adjust the color mode, 0 to 1, the default value is changed to 0.6, floating point (reserve 2 decimal places)

lum: brightness, used to adjust the brightness of white light mode, 0 to 1, the default value is changed to 0.5, floating point (reserve 2 decimal places)

tem: Color temperature, used to adjust the heating and cooling of white light mode, 0 to 1, the default value is changed to 0.6, floating point (reserve 2 decimal places)

devInfo = {
   "i":4,
"D": {
        "s":0,
        "m":1,
        "hue":0.5,
        "lit":0.5,
        "sat":0.5,
        "lum":0.5,
        "tem":0.5
    },
    "t":1464714257
}
deviceId="PGiHMkrgyxrUCuLgEfubUU"

Lamp control (switch) Return to example

devInfo={
    "i":4,
    "d":{
        "s":0
    },
    "t":1464714257
}
deviceId="ssxggsjsfks"

Lamp control (color light) Return to example

devInfo={
    "i":4,
    "d":{
        "m":1,
        "hum":0.5
    },
    "t":1464714257
}
deviceId = "sssjhkjhs"

3.4.2.3 MQTT feedback information transparent transmission interface

Note: mqtt feedback NSData type data interface, there is one more NSData type data callback than the previous interface

Calling method:

-(Void)openMQTTServerWithUserId:(NSString*)userId
ServerUrl:(NSString*)serverUrl
UserName:(NSString*)username
Password: (NSString *)password
Uuid:(NSString*)uuid
CompletionHandler:(void(^)(NSString*deviceId,NSDictionary*devInfo,NSError*error))completionHandler
RawDataCompletionHandler: (void (^)(NSString *deviceId, NSData *data, NSError *error))rawDataCompletionHandler;

3.4.2.4 MQTT reconnect

Parameters Type Required Default Description
serverUrl NSString Yes None Obtained from the return value of the bound device (the bound device also returns serverUrl)

Return parameter

Parameters Type Description
None None None

Call method

-(Void)reconnetMQTTserver:(NSString*)serverUrl;

3.5 branch three

3.5.1 Add device

3.5.1.1 Smart Connection

Create WiFiTouch class singleton object

+ (WiFiTouch *)sharedTouch;

Smart connection

Smart access to the Internet, provide the device with a WIFI account and password for Internet access, and ensure that this method is used in a WIFI environment

Request parameter

Parameters Type Required Default Description
ssid NSString Yes None WIFI account name
password NSString Yes None WIFI account password
timeout int yes none connection timeout

Return parameter

Parameters Type Description
None None None

Call method

-(Void)smartLink:(NSString*)ssid password:(NSString*) password timeout:(int)timeout;

Stop smart connection

Method call example: Use WiFiTouch singleton call

-(Void)stop;

Determine whether the smart connection is in progress

Request parameter

Parameters Type Required Default Description
None None None None None

Return parameter

Parameters Type Description
YES (NO) BOOL YES is returned when the smart connection is connecting, or NO if not

Method call example: Use WiFiTouch singleton call

-(BOOL)isRunning;

Return example

Return YES;

Smart link feedback

Request parameter

Parameters Type Required Default Description
None None None None None

Return parameter

Parameters Type Description
devInfo NSDictionary Device Information

Call method

-(Void)receiveSmartLinkCompletionHandler:(void(^)(NSDictionary*devInfo,NSError*error))completionHandler;

Correct return example

{
    "deviceId":"PGiHMkrgyxrUCuLgEfubUU";
    "deviceIp":"192.168.1.116";
    "devicePort":12476;
    "mac":"5ccf7f026cea";
    "productId":"pnTSD3ZsRNVgvNn6YRC2Z5";
}

3.5.1.2 AP connection

Create DeviceManager class singleton

+ (DeviceManager *)sharedInstance;

AP mode connection

AP mode connection: The user connects to the Wi-Fi released by the device, and sends the configuration information directly to the device

Request parameter

Parameters Type Required Default Description
ssid NSString Yes None WIFI account name
password NSString Yes None WIFI account password

Return parameter

Parameters Type Description
devInfo NSDictionary Device Information

Call method

-(Void)APLink:(NSString*)ssid
Password:(NSString*)passwd
CompletionHandler:(void(^)(NSDictionary*devInfo,NSError*error))completionHandler;

Correct return example

{
    "productId":"pnTSD3ZsRNVgvNn6YRC2Z5",
    "deviceId":"PGiHMkrgyxrUCuLgEfubUU",
    "mac":"5ccf7f026cea",
    "deviceHost":"10.10.3.24",
    "devicePort": 12476
}

Error return example

no

Feedback on successful device access

Request parameter

Parameters Type Required Default Description
None None None None None

Return parameter

Parameters Type Description
devInfo NSDictionary Device Information

Call interface

-(Void)networkSuccessCompletionHandler:(void(^)(NSDictionary*devInfo,NSError*error))completionHandler;

Correct return example

{
"DeviceId": "PGiHMkrgyxrUCuLgEfubUU";
"DeviceIp": "192.168.1.116";
"DevicePort": 12476;
"Mac": "5ccf7f026cea";
"ProductId": "pnTSD3ZsRNVgvNn6YRC2Z5";
}

3.5.2 Discovery equipment

3.5.2.1 Device discovery

Request parameter

Parameters Type Required Default Description
None None None None None

Return parameter

Parameters Type Description
deviceIp NSString Device IP
devicePort UInt16 Device Port
deviceId NSString Device ID
mac NSString Device MAC address
productId NSString Product ID

Note: Call the discovery device interface to return all device information at one time, but each time only one device information is returned, it will automatically return multiple times

Note: The discovery device needs to be deduplicated (remove the device in the bound device list requested from the server)

Call interface

-(Void)discoverDeviceCompletionHandler:(void(^)(NSArray*deviceList,NSError*error))completionHandler;

Correct return example

deviceList---> (
{
"DeviceId": "BuZR4ohMzRqUokEKYwMrqZ";
"DeviceIp": "192.168.1.141";
"DevicePort": 12476;
"Mac": "5ccf7f035332";
"ProductId": "pnTSD3ZsRNVgvNn6YRC2Z5";
}
)

Error return example

no

3.5.2.2 Query product information interface

Request parameter

Parameters Type Required Default Description
None None None None None

Return parameter

Parameters Type Description
responseJSON NSDictionary Binding device feedback information

Calling method:

-(Void)getVendorInfoCompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Correct return example

{
data={
productVoList=(
{
productId = 3G8pAXs2kppdLwHZHqTeWH;
productName = AiBox;
},
{
productId = kc9dRAXr35PEA7PCZcR4z9;
productName = "ESP\U7cfb\U5217\U6a21\U7ec4";
},
{
productId = R6of6RqqYzKphvEqZApfNV;
productName = "\U667a\U80fd\U63d2\U5ea7";
},
{
productId = TDo7PY6XPjv3Fwru6zSnoK;
productName = "\U667a\U80fd\U706f";
}
);
};
success = 1;
}

Error return example

responseJSON---> {
"errorCode":400,
"Message":"user already binding",
"Success":0}

3.5.2.3 Get productName

Request parameter

Parameters Type Required Default Description
productId NSString Yes None Product ID

Return parameter

Parameters Type Description
productName NSString Product Name

Note: If the return value is empty, it is not the device of the manufacturer, and the device may not be found

Calling method:

//Add the interface to get the device productName, nil means it is not the manufacturer's productId, and the device can be ignored
-(NSString *)getProductNameJudgeVendorDeviceWithProductId:(NSString *)productId;

Correct return example

"Ball Bulb" or nil

3.5.2.3 Binding device

-(Void)bindingDeviceForUser:(NSString*)userTokenHost:(NSString*)deviceHostdevicePort:(UInt16)devicePortcompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler

Request parameter

Parameters Type Required Default Description
useToken NSString Yes None User token
deviceHost NSString Yes None Device IP address
devicePort UInt16 yes none device port number

Return parameter

Parameters Type Description
responseJSON id Binding device feedback information

Call method

-(Void)bindingDeviceForUser:(NSString*)userTokenHost:(NSString*)deviceHostdevicePort:(UInt16)devicePortcompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler

Note: Every time a new device is bound, it is necessary to determine whether the server has established an MQTT connection according to the returned information server, and MQTT control can be performed only if the connection has been established, and the connection needs to be re-established

Correct return example

{
"success": true,
"data":{
"server": "mqtt://s1.vcd.io:1883",
"username": "tNb3ZgG9HLNiCEfNnushp6",
"password": "dmUxHriiFrsAxJNTNd9Pz3",
"pubkey":"",
"pkVersion":""
}
}

Error return example

responseJSON---> {
"errorCode": 400,
"message":"user already binding",
"success":0
}

3.5.2.3 Determine whether MQTT is connected

Calling method: (using DeviceManager singleton call)

-(BOOL)isMQTTConnected:(NSString*)serverUrl

Note: Returning YES means MQTT is connected, NO means MQTT connection is disconnected or this serverUrl has not established MQTT service

3.5.2.4 If the connection has not been established, the MQTT connection is established, and the connection is disconnected and reconnected

Calling method: (same as 2.4.2)

3.5.2.5 Modify the device name

Request parameter

Parameters Type Required Default Description
deviceName NSString yes none new device name to be used
deviceId NSString yes none device id

Return parameter

Parameters Type Description
responseJSON id Modify device name return value

Call method

//Add user to change the device name UserManager call
-(Void)updateDeviceInfoWithDviceName:(NSString*)deviceNamedeviceId:(NSString*)deviceIdcompletionHandler:(void(^)(idresponseJSON,NSError*error))completionHandler;

Correct return example

{
data={
success = 1;
};
success = 1;
}

Error return example

{
"errorCode":400,
"Message":"user already binding",
"success":0
}

Disclaimer and Copyright Notice

The information in this article, including the URL address for reference, is subject to change without notice.

The document is provided “as is” and does not bear any guarantee responsibility, including any guarantee for marketability, suitability for a specific purpose, or non-infringement, and any guarantee mentioned elsewhere in any proposal, specification or sample. This document does not take any responsibility, including the responsibility for infringement of any patent rights caused by using the information in this document. This document does not grant any license for the use of intellectual property rights in estoppel or other ways, whether express or implied.

The Wi-Fi Alliance member logo is owned by the Wi-Fi Alliance. All brand names, trademarks and registered trademarks mentioned in this article are the property of their respective owners, and it is hereby declared.