Remote device control with JavaScript in Web page is implemented by calling the open API and Web Socket API of Gizwits. Open API accomplishes operations such as anonymous user login, device binding, and listing bound devices. While Web Socket API accomplishes operations such as user login, device online and offline notification, data exchange between the browser and the cloud (data transparent transmission), heartbeat, and invalid message notification.
When the device is successfully connected to the cloud, you can use the following process to control the device:
Call Open API to log in as an anonymous user and bind devices.
phone_id can be the unique identifier of user’s phone. Otherwise when you already have your own user system and don’t want users to sign up for a Gizwits account again, you can use this API to create a corresponding Gizwits anonymous account for each of your users. In this case, phone_id can be the unique identifier of the user in your system. For example, when integrating with WeChat application, phone_id can be set to the openid of the WeChat user.
http://swagger.gizwits.com/doc/index/openapi_apps#/用户管理/post_app_users
POST request URL:
http://swagger.gizwits.com/doc/index/openapi_apps#/绑定管理/post_app_bind_mac
Note:
As shown below:
Its link is as follows:
https://github.com/gizwits/gizwits-wechat-js-sdk
https://gizwits.github.io/gizwits-wechat-js-sdk/v0.2.0.html
The request parameters are:
Param | Description | Value |
---|---|---|
apiHost | Gizwits Open API domain | api.gizwits.com |
commType | Standard data point format protocol | attrs_v4 |
wechatOpenId | OpenID of WeChat user (i.e. phone_id) | String |
gizwitsAppId | Gizwits application identifier | String |
Initialize as follows:
If you want to obtain the bound device list, first confirm whether the user (i.e. openid) has bound the devices to be controlled.
Select a device to control, and create a Web Socket connection.
Select the connected device and read the current state of the device.
Select the connected devices and issue control instructions.
For example, send the control instruction {“Swicth”:true} as follows:
1 | { |
Control the virtual device:
The custom format protocol V4 is also called transparent transmission without data points.
The request parameters are:
Param | Description | Value |
---|---|---|
apiHost | Gizwits Open API domain | api.gizwits.com |
commType | Custom format protocol | custom |
wechatOpenId | OpenID of WeChat user (i.e. phone_id) | String |
gizwitsAppId | Gizwits application identifier | String |
Select a device to control, and create a Web Socket connection.
Select the connected device and read the current state of the device:
Select the connected device and issue the control instruction: [0,0,0,3,9,0,0,144,1,0,1,2,3,4] (Note: The instruction payload is decimal, of which 0,0,0,3 is for header, 9 for len, 0 for flag, 0,144 for cmd, 1 for action, 0, 1, 2, 3, 4 for business instruction), as follows:
The virtual device receives the instruction as follows:
FF FF 00 0B 03 1E 00 00 01 00 01 02 03 04 37