v1.4.0
revise history
Version | Revision Content | Revision by | Reviewer | Revision Date |
1.0.0 | Create Document | Bai Xueru | 2016.8.23 | |
1.0.1 | Add SDK required permissions | Bai Xueru | 2016.8.24 | |
1.0.2 | Modify usage rights | Bai Xueru | 2016.8.25 | |
1.0.3 | Add smart connection, two interface callbacks for successful network access, modify error information | Bai Xueru | 2016.8.30 | |
1.0.4 | Combined user binding method | Bai Xueru | 2016.8.31 | |
1.1.0 | Add batch deployment interface | Bai Xueru | 2016.9.5 | |
1.1.1 | Modified the initial control information interface, added two parameters of user name and password | Bai Xueru | 2016.9.6 | |
1.1.2 | Modify the returned information of MQTT subscription, modify the returned topic to device_id | Bai Xueru | 2016.9.7 | |
1.2.0 | Add LAN control | Bai Xueru | 2016.9.18 | |
1.2.1 | Modify bulb light data points | Bai Xueru | 2016.10.9 | |
1.3.0 | Unify the method name with ios, modify the deployment method, cancel a single deployment, modify the binding method, modify the MQTT service, now get the device list and deploy at the same time | Bai Xueru | 2016.10.28 | |
1.3.2 | Modify openMQTTServer() interface | Bai Xueru | 2016.11.2 | |
1.4.0 | Updated naming method and countless APIs | Bai Xueru | 2016.11.22 |
compile files('libs/javastruct-0.1.jar') compile'com.google.code.gson:gson:2.2.4' compile'com.koushikdutta.async:androidasync:2.1.8' compile'com.koushikdutta.ion:ion:2.1.8' compile'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
static{ //TODO: Processing configuration information, configuration information will change according to different manufacturers CommConfig.NETWORK_URL="http://api.vcd.io:4568/v1/"; CommConfig.ACCESS_SECRET="cafdeb099d45eee7e2faddea091fd609"; CommConfig.ACCESS_KEY="8e0bb23839955bde1346b6e9395347ff"; Commconfig.VENDOR_ID="2D8UbrFaRDDvWbhCaqQc8"; Commconfig.APPNAME="SmartDevice" }
The configuration information is recommended to be written in the Application class
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> <!--Network Status--> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!-- Access network --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Network communication --> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!-- Get device information --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <!-- Read and write sdcard, storage, etc. --> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.CALL_PHONE"/> <!-- Used for network positioning --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Used to access GPS location --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- This permission is used to obtain wifi access permissions, wifi information will be used for network positioning --> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <!-- Write extended storage, write data to the expansion card, used to write cache location data?--> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="com.android.providers.media.MediaProvider"/> <uses-permission android:name="android.permission.WRITE_CONTACTS"/> <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/> <!-- Network status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!-- Access network --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Network communication --> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!-- Get device information --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <!-- Read and write sdcard, storage, etc. --> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.CALL_PHONE"/> <!-- Used for network positioning --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Used to access GPS location --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- This permission is used to obtain wifi access permissions, wifi information will be used for network positioning --> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <!-- Write extended storage, write data to the expansion card, used to write cache location data --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="com.android.providers.media.MediaProvider"/> <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
Bulb light: turn on and off the bulb light three times in a row to enter the smart connection mode. At this time, the bulb is flashing red, and turn on and off the bulb light four times to enter the AP connection mode. At this time, the color of the bulb light changes continuously and switches on and off continuously. Ten times the bulb is initialized and enters the smart connection state.
Socket: long press the switch button, the small green light flashes slowly for the smart connection state, after five seconds, the small donkey light flashes in the AP connection state, long press for 10 seconds, the small green light flashes super fast, and the socket is initialized Status, let go and enter the smart connection mode.
This section mainly introduces the use of API in SDK
Request parameter
Parameters | Type | Required | Default | Description |
None | None | None | None | None |
Return parameter
Parameters | Type | Description |
instance | UserManger | UserManger entity object |
Method call description
UserManager.getInstance();
Return to instance
return instance;
Request example
Parameters | Type | Required | Default | Description |
phone | String | Yes | None | Phone number |
1 | int | Yes | None | Pass 2 when resetting the password to obtain the verification code, and pass 1 when registering an account to obtain the verification code |
context | Context | yes | none | context object |
callback | Callback | Yes | None | Interface callback |
Return parameter
Parameters | Type | Description |
user_code | String | User code, which will be used when registering |
Method call example
userManager.getMessage(phone, 1, this, new Callback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject){ } });
Return example
{ "success":true, "data":{ "userCode":"sa4nUnfQisGTZH3EmE8JEE" } }
Request parameter
Parameters | Type | Required | Default | Description |
mobile | String | Yes | None | Mobile number |
password | String | Yes | None | Password when logging in |
messageCode | String | Yes | None | SMS verification code |
userCode | String | Yes | None | Return in the method of obtaining SMS verification code |
context | Context | yes | none | context object |
callback | Callback | Yes | None | Interface callback |
Return parameter
Parameters | Type | Description |
userId | String | User id, the unique identification of the user |
Method call example
UserManager.register(username, password, message_code, user_code, mobile, newCallback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject){ } }, this);
Return example
{ "success":true, "data":{ "userId":"sa4nUnfQisGTZH3EmE8JEE" } }
Request parameter
Parameters | Type | Required | Default | Description |
username | String | Yes | None | Mobile phone number/user nickname |
password | String | Yes | None | Login password |
“productId”:“kc9dRAXr35PEA7PCZcR4z9”,
"status":"1", "server":"mqtt://221.122.108.89:1883", "deviceName":"device name" "logo":"http://doss.ai-thinker.com/devicexx/esp8266.png" "productName":"bulb light" }]
} </code>
Request parameter
Parameters | Type | Required | Default | Description |
user_token | String | Yes | None | User token, with expiration time, obtained when the user logs in |
device_id | string | Yes | None | The unique id of the device, which can be obtained when the user queries the bound list |
device_password | string | Yes | None | Device password, which can be obtained when the user queries the bound list |
callback | Callback | Yes | None | Interface callback for successful request |
context | Context | yes | none | context object |
Return parameter
Parameters | Type | Description |
result | String | Whether the device is successfully released |
Method call example
userManager.unbindDevice(token, device_id, device_password, newCallback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject){ } }, DeviceListActivity.this);
Return example
{ "success":true, "data":{ "result":"SUCCESS" } }
Request parameter
Parameters | Type | Required | Default | Description |
deviceId | String | Yes | None | The unique id of the device, which can be obtained when the user queries the bound list |
deviceName | string | Yes | None | User's name for the device |
callback | Callback | Yes | None | Modified successful interface callback |
Return parameter
Parameters | Type | Description |
true | boolean | Whether the device is successfully released |
Method call example
userManager.updateDeviceInfo(bean.getDevice_id(), name, new Callback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject){ } }, getContext());
Return example
{ "success":true, "data":{ "success":"true" } }
Request parameter
Parameters | Type | Required | Default | Description |
context | Context | yes | none | context object |
callback | Callback | Yes | None | Interface callback |
Return parameter
Parameters | Type | Required | Default | Description |
productId | String | Yes | None | Product Id |
productName | String | Yes | None | Product Name |
Method call example
userManager.getVendorInfo(getContext(), new Callback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject jsonObject) { Log.e(TAG, "getVendor:"+e); Log.i(TAG,"getVendorInfo:" + jsonObject); saveVendorInfo(e, jsonObject); } });
Return example
{ "success":true, "data":{ "productVList":[ { "productId":"3G8pAXs2kppdLwHZHqTeWH" "productName":"AiBo" }] } }
Request parameter
Parameters | Type | Required | Default | Description |
callback | CallBack | Yes | None | Interface callback for successful request |
Return parameter
Parameters | Type | Description |
productId | String | Product Id |
deviceId | String | Device Id |
mac | String | device mac |
deviceHost | String | Device Ip |
devicePort | String | Device Port |
Method call example
deviceManager.discoverDevice(new Callback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject){ } });
Return example
{ "productId":"kc9dRAXr35PEA7PCZcR4z9"", "deviceId":"JiEbsXMdn2W5uZtMm6fmr6", "mac":"001122334455", "deviceHost":"225.224.224.0", "devicePort":"8080" }
Parameters | Type | Required | Default | Description |
deviceManager | DeviceManager | None | DeviceManager entity class | |
deviceHost | String | Yes | None | Device IP, which can be obtained when an unbound device is found |
devicePort | string | Yes | None | Device port, which can be obtained when an unbound device is found |
user_token | String | Yes | None | User token, with expiration time, obtained when the user logs in |
callback | CallBack | Yes | None | Interface callback for successful request |
context | Contex | yes | none | context object |
Return parameter
Parameters | Type | Description |
true | boolean | Is the binding successful |
Request example
new Thread(){ @Override public void run(){ super.run(); userManager.bindingDevice(deviceManager, deviceHost, devicePort, token, new Callback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject){ } }, DeviceListActivity.this); } }.start();
Return example
{ "success":true, "data":{ "success":"true" } }
There are two conditions for controlling equipment, one is to control the equipment through the WAN, the other is to control the equipment through the local area network
The prerequisite for LAN control equipment is to enable TCP service
Request parameter
Parameters | Type | Required | Default | Description |
device_ip | String | Yes | None | Hardware TCP? IP address, which can be obtained when the device is discovered |
device_id | String | Yes | None | Device id, which can be obtained when obtaining the binding list |
device_password | String | Yes | None | Device password, which can be obtained when obtaining the binding list |
callback | Callbackt | Yes | None | TCP service start successful interface callback |
Return parameter
no
Method call example
deviceManager.openTCPServer(device_ip, deviceId, device_password,new Callback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject jsonObject){ } });
Return example
no
Request parameter
no
Return parameter
no
Example request method
deviceManager.closeTCPServer();
Return example
no
Request parameter
Parameters | Type | Required | Default | Description |
jsonObject | JsonObject | Yes | None | Parameters in the form of json string |
callback<JsonObject> | Callback | Yes | None | Interface callback for controlling data transmission success (return type is json string) |
Callback<byte[]> | Callback | Yes | None | Interface callback for successful control data transmission (return type is byte array) |
Return parameter
The control parameters returned by different control information devices are different, see the return example for details
Method call example (send json string, return json string and byte[])
deviceManager.tcpSendData(params, new Callback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject jsonObject){ } new Callback<byte[]>() { @Override public void onCompleted(Exception e, byte[] bytes){ } } });
Method call example (send byte[], return byte[])
deviceManager.tcpSendData(params.toString().getBytes(), new Callback<byte[]>() { @Override public void onCompleted(Exception e, byte[] bytes) { } });
Method call example (send json, return json)
deviceManager.tcpSendData(params, new Callback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject) { } });
Method call example (send byte[], return jsonhebyte[])
deviceManager.tcpSendData(params.toString().getBytes(), new Callback<JsonObject>(){ @Override public void onCompleted(Exception e, JsonObject jsonObject) { } },new Callback<byte[]>() { @Override public void onCompleted(Exception e, byte[] bytes) { } });
Example of sending parameter params
Write bulb light
{ "i":4, "d":{ "s":0, "m":1, "hue":0.5, "lit":0.5, "sat":0.5, "lum":0.5, "tem":0.5 }, "t":1464714257 "device_id":"PGiHMkrgyxrUCuLgEfubUU" }
Reading bulb
{ "i":4, "d":{[ "s":0, "m":1, "hue":0.5, "lit":0.5, "sat":0.5, "lum":0.5, "tem":0.5 ]}, "t":1464714257 }
Return parameter example
Read (write) bulb light
{ "i":4, "d":{ "s":0, "m":1, "hue":0.5, "lit":0.5, "sat":0.5, "lum":0.5, "tem":0.5 }, "t":1464714257 "device_id":"PGiHMkrgyxrUCuLgEfubUU" }
The prerequisite for WAN control equipment is that MQTT connection must be established first
Request parameter
Parameters | Type | Required | Default | Description |
user_token | String | Yes | None | User token with expiration time |
callback | Callback | Yes | None | Deployment success interface callback |
context? | Context | yes | none | context object |
Return parameter
Parameters | Type | Description |
server | String | The address of the server connected to the device |
username | String | (user nickname) |
password | String | User password (after encryption) |
pubkey | String | ? |
pubVersion | String | Hardware firmware version |
Method call description
instance.batchDeploy(token, new Callback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject jsonObject) { } }, this);
Return description
Return value example (the interface returns a json string after returning)
{ "success":true, "data":{ "server_list":[( { "server":"mqtt://s1.vcd.io:1883", "username":"tNb3ZgG9HLNiCEfNnushp6", "password":"dmUxHriiFrsAxJNTNd9Pz3", "pubkey":"", "pk_version":"" } ], "signature":"8e0bb23839955bde1346b6e9395347ff" } }
Request parameter
Parameters | Type | Required | Default | Description |
serverUrl | String | Yes | None | MQTT request address, which is returned when the user deploys, the user deploys, binds the device, and obtains the address from the bound device. |
username | String | Yes | None | The username used to log in to MQTT, which can be obtained during deployment |
password | String | Yes | None | The password used to log in to MQTT, which can be obtained during deployment |
user_id | String | Yes | None | User ID, which is returned when the user logs in, and can be obtained when the user logs in |
uuid | String | Yes | None | Generated when the user logs in to the device for the first time, see special instructions for details, uuid instructions |
callback (JsonObject) | CallBack | Yes | None | Interface callback for successful request (return value type is JsonObject) |
callback (byte[]) | Callback | yes | none | interface callback for successful request (return value type is byte[]) |
Return parameter
The return value is the feedback information of the device when the WAN controls the device. For details, please refer to the return of LAN control information
Method call example
deviceManager.openMQTTServer(server,userName,userPassword,userId,uuid,new DataCallback<String,{ JsonObject>() @Override public void onCompleted(Exception e, String device_id, JsonObject jsonObject) {} },new DataCallback<String, byte[]>(){ @Override public void onCompleted(Exception e, String s, byte[] bytes) { } } );
Return example
See TCP control return example
Request parameter
Parameters | Type | Required | Default | Description |
serverUrl | String | Yes | None | MQTT request address, which is returned when the user deploys, the user deploys, binds the device, and obtains the address from the bound device. |
deviceId | String | Yes | None | ID of the device to be controlled |
params | String | Yes | None | Control data sent |
context | String | yes | none | context object |
Return parameter
no
Method call example (send json)
deviceManager.publishMessage(serverUrl, deviceId, params, this);
Method call example (send byte[])
deviceManager.publishMessage(serverUrl, deviceId, params.toString().getBytes(), this);
Parms example
See TCP control params example
Return example
no
Disclaimer and Copyright Notice
The information in this article, including the URL address for reference, is subject to change without notice.
The files are provided “as is” and do not bear any guarantee responsibility, including any guarantees for marketability, suitability for specific routes, or infringement, and any guarantees mentioned elsewhere in any proposal, specification or sample. This file does not bear any responsibility, including the responsibility for the infringement of any patent rights in the information property in this file. This document does not grant any intellectual property licenses, either expressly or implicitly, by prohibition or other forms.
The Wi-Fi Alliance member logo is owned by the Wi-Fi Alliance. All the brand names, trademarks and registered trademarks mentioned in are the property of their respective owners, hereby declare.