Cloud Service

Cloud services provide application data cloud storage.

Relations with tact cloud

Cloud services using wit cloud cloud services.Tact cloud web site:http://site.gizwits.com/developer。

The definition of the data

Enter the tact cloud platform, registered account and log in.Select hardware access into and then click the "create new product", fill in the "add product" page "device name", "communication" choose "BLE", "device type" no special requirements, and then click ok.Enter the new device access wizard, click on the "manual editing data point", then click on "new data points", in name of "data points" and "data types".Tact cloud support Boolean, enums, number, string type.After click next until the click finish, finally can see the detailed information of equipment, including "APP ID" and "product ID" behind us.

Classes and interfaces:

CloudServiceManager:

Cloud management class, can use this kind of cloud, the cloud with your login account, query cloud data, insert the cloud data operation.

CloudQuery:

Cloud data query condition class.Support conditions, can be combined into a complex condition

CloudDataValues:

Cloud data classes.Store database row data, a line of data contains a number of data, each data stored in the form of the key - value.

AccountListener:

Monitor account processing related operating results

LoginListener:

To monitor the login operation execution results

DataInfoListener:

Monitored data update operations performed as a result, if the query is successful With a List < CloudDataValues > returns the query results.

DataInsertListener:

To monitor data insert operation results

DataOperationListener:

Monitoring data update delete operation results

Service access and initialization:

In order to use the cloud first need to connect to cloud services. You need to instantiate ServiceClient and pass SERVICE_CLOUD as parameters.
The code is as follows:

private ServiceClient mClient 
    = new ServiceClient(this, ServiceManagerContext.SERVICE_CLOUD, this);
...
mClient.connect()

Then get mClient obtain CloudServiceManager object after a successful connection. The code is as follows:

private CloudServiceManager mCloudService;
@Override
public void onConnected(ServiceClient serviceClient) {
   mCloudService = (CloudServiceManager) mClient.getServiceManagerContext();
}

CloudServiceManager:

Initialization:

Specified in the initialization before I can start to use, to operate the database APP_KEY and PRODUCT_KEY, namely data definition mentioned in the "APP ID" and "product ID".        The code is as follows:

public final static String APP_ID = "7a9a7b387df64979ac67518fb0b6649e";
public final static String PRODUCT_KEY = "25ee6d29f9f74743a6ee4fdcca8d4869";
mCloudService.init(APP_ID, PRODUCT_KEY);

Login:

Login into normal login, anonymous logins, the third party to login:
    public void login(String userName, String password, LoginListener listener);
    public void loginAnonymous(LoginListener listener);
    public void loginWithThirdAccount(int accountType, String uid, String token, LoginListener listener);

Common login using the user name password, login results through the com.lotus.sametime.community.loginlistener to return.
Normal login code:

mCloudService.login(userName, password,
        new LoginListener() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                IwdsLog.d(this, "login failure: " + errMsg);
            }
        });

Anonymous logins don't need the user name password, login results through the com.lotus.sametime.community.loginlistener to return.
代码如下:

mCloudService.loginAnonymous(
        new LoginListener() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                IwdsLog.d(this, "login failure: " + errMsg);
            }
        });

Third-party login

You first need to register the third-party platform application, and get the id of the application, then mail to wit cloud email open@gizwits.com, request binding third-party applications and witty cloud products and provide the id. Then download third party SDK, login to implement in the SDK, after a successful login will get uid and token, then call loginWithThirdAccount incoming uid and token to log in.

After successful login can insert and query data.

Data Representations 

CloudDataValues Used to store a row of a database.The following table, for example,

name

age

weight

jack

17

120

tom

21

150

Can be said for two CloudDataValues object, as follows:

CloudDataValues data1 = new CloudDataValues();
data1.put("name", "jack");
data1.put("age", 17);
data1.put("weight", 120);

CloudDataValues data2 = new CloudDataValues();
data2.put("name", "tom");
data2.put("age", 21);
data2.put("weight", 150);

Insert

Insert the data with the insertData, incoming data CloudDataValues List, the result by DataInsertListener returns.

Function declaration:

    void insertData(List<CloudDataValues> data, DataInsertListener listener);

Insert the data code:

List<CloudDataValues> dataList = new ArrayList<CloudDataValues>();
CloudDataValues data;

data = new CloudDataValues();
data.put("name", "jack");
data.put("age", 17);
data.put("weight", 120);
data.put("ts", System.currentTimeMillis());
dataList.add(data);

data = new CloudDataValues();
data.put("name", "tom");
data.put("age", 21);
data.put("weight", 150);
data.put("ts", System.currentTimeMillis());
dataList.add(data);

mCloudService.insertData(dataList,
    new DataInsertListener() {
        @Override
        public void onSuccess() {
            Log.v(TAG, "insertData success");
        }

        @Override
        public void onFailure(int errCode, String errMsg) {
            Log.v(TAG, "insertData failure: " + errMsg);
        }
    });
 

Note: each wit the cloud data has a timestamp attribute "ts", its value for the time of milliseconds. Don't have to create a default is a timestamp attribute. If you do not specify a timestamp when inserting data, this value defaults to the current time.

Query data

CloudQuery class is the query conditions. Support conditions, can be combined into a complex condition.

Below are two conditions:

CloudQuery query1 = new CloudQuery("ts", ">=", 1422720000295);
CloudQuery query2 = new CloudQuery("ts", "<=", 1433174399297);

Can put them as a combined into a condition:

    CloudQuery query = new CloudQuery("ts", ">=", 1422720000295).and(new CloudQuery("ts", "<", 1433174399297));

Query success through onSuccess list parameters return query results. If the query results cannot be a full return, need multiple calls queryData, every time to adjust the skip value, so as to get all the query results.

The method statement:

    void queryData(CloudQuery query, int limit, int skip, DataInfoListener listener);

Here is a query code:

CloudQuery query = new CloudQuery("ts", ">=", 1422720000295).and(new CloudQuery("ts", "<", 1433174399297));

mCloudService.queryData(query, 50, 0,
        new DataInfoListener() {
            @Override
            public void onSuccess(List<CloudDataValues> list) {

            }

            @Override
            public void onFailure(int errCode, String errMsg) {

            }
        });

Data update, and delete are not currently supported.

Account management

Account management provide user registration and password reset function.

The average user registration:
void registerUser(String userName, String password, AccountListener listener)

The mailbox user registration:
void registerUserWithEmail(String email, String password, AccountListener listener)

Mobile phone users:
void registerUserWithPhone(String phone, String password, String verifyCode, AccountListener listener)
The verifyCode for mobile phone verification code, verification code through requestPhoneVerifyCode method.
Method statement as follows:
void requestPhoneVerifyCode(String phone, AccountListener listener)

Mailbox user password reset:
void resetPasswordWithEmail(String email, AccountListener listener)

Mobile phone users password reset:
void resetPasswordWithPhone(String phone, String verifyCode, String newPassword, AccountListener listener)

Ordinary users do not provide a password reset function