Features of Travel SDK

Last Updated on : 2024-07-01 08:14:29download

Travel SDK serves your development as an extension of Smart Life App SDK. Before you integrate the Travel SDK, implement the device control feature on top of the Smart Life App SDK.

Required classes

Class name Description
IODDeviceInfo(ODDeviceInfo) Get smart travel device information, such as HD images and firmware details.
IODDeviceDPManager(ODDeviceDPManager) Process device data points (DPs). For example, send DP data (advanced programming languages supported) and check whether device DPs are supported.
IODStore(ODStore) Implement features related to offline stores. For example, get a list of offline stores and search for target ones.
IODTrack(ODTrack) Implement features related to cycling navigation. For example, get a list of cycling routes and upload cycling routes.

Get device details

Get HD device image

Smart Life App SDK supports device thumbnails by default. You can make the following API request to get the HD device image with dimensions of 800 x 800 pixels. This image is configured on the Tuya IoT Development Platform. Device firmware information is also returned in this call.

API description

void getDeviceIcon(String deviceId, IThingResultCallback<ProductMap> callback)

Request parameters

Parameter Type Required Example Description
deviceId String Yes - The device ID.
callback IThingResultCallback Yes - The callback.

Data model of ProductMap

  • Fields of ProductMap

    Field Type Description
    productIconVOMap Map<String, ProductIcon> The list of image information.
  • Fields of ProductIcon

    Field Type Description
    icon String The HD image of the device. Dimensions: 800 x 800 pixels.
    smallIcon String The thumbnail of the device.

Example

ThingODSDK.getIODDeviceInfoInstance().getDeviceIcon(deviceId, new IThingResultCallback<ProductMap>() {
                @Override
                public void onSuccess(ProductMap result) {

                }

                @Override
                public void onError(String errorCode, String errorMessage) {

                }
            });

Get device firmware details

API description

void getDeviceHardwareInfo(String deviceId, IThingResultCallback<DeviceHardwareInfo> listener);

Request parameters

Parameter Type Required Example Description
deviceId String Yes - The device ID.
listener IThingResultCallback Yes - The callback.

Data model of DeviceHardwareInfo

  • Fields of DeviceHardwareInfo

    Field Type Description
    deviceId String The device ID.
    deviceInfo Map<String, Object> The list of device information.
  • Fields of deviceInfo

    Field Type Description
    chassisNo String The vehicle identification number.
    activeTime String The time when a device is activated.
    productModel String The device model.

Example

ThingODSDK.getIODDeviceInfoInstance().getDeviceHardwareInfo(devId, new IThingResultCallback<DeviceHardwareInfo>() {
                @Override
                public void onSuccess(DeviceHardwareInfo result) {

                }

                @Override
                public void onError(String errorCode, String errorMessage) {

                }
            });

Process device DPs

Send DP data to control a device

API description

void publishDP(String deviceId, String dpCode, Object value, IThingDevice thingDevice, IResultCallback callback);

Request parameters

Parameter Type Required Example Description
deviceId String Yes - The device ID.
dpCode String Yes “blelock_switch” The value of dpCode that identifies a device DP.
value Object Yes true The DP value.
thingDevice IThingDevice Yes ThingHomeSdk.newDeviceInstance(deviceBean.getDevId()) -
callback IResultCallback Yes - The callback.

Return parameters

None.

Example

IThingDevice mDevice = ThingHomeSdk.newDeviceInstance(deviceBean.getDevId());
ThingODSDK.getIODDeviceManagerInstance().publishDP(deviceBean.getDevId(), "blelock_switch", true, mDevice, new IResultCallback() {
                    @Override
                    public void onError(String code, String error) {

                    }

                    @Override
                    public void onSuccess() {

                    }
                });

Get DP value based on dpCode

API description

<T> T getValueByDPCode(String deviceId, String dpCode, Class<T> valueType);

Request parameters

Parameter Type Required Example Description
deviceId String Yes - The device ID.
dpCode String Yes “blelock_switch” The value of dpCode that identifies a device DP.
valueType Object Yes true The DP value.

Return parameters

Type Example Description
Boolean true The DP value.

Example

boolean switchValue = ThingODSDK.getIODDeviceManagerInstance().getValueByDPCode(devId, "blelock_switch", Boolean.class);

Get device mode configurations

API description

SchemaBean getSchemaByDPCode(String deviceId, String dpCode);

Request parameters

Parameter Type Required Example Description
deviceId String Yes - The device ID.
dpCode String Yes “blelock_switch” The value of dpCode that identifies a device DP.

Return parameters

SchemaBean

For more information about SchemaBean, see Device Control.

Example

ThingODSDK.getIODDeviceManagerInstance().getSchemaByDPCode(devId, "blelock_switch");

Check support for dpCode-specific feature

API description

boolean isDPCodeSupport(String deviceId, String dpCode);

Request parameters

Parameter Type Required Example Description
deviceId String Yes - The device ID.
dpCode String Yes “blelock_switch” The value of dpCode that identifies a device DP.

Return parameters

Type Example Description
Boolean true true: supported. false: not supported.

Example

ThingODSDK.getIODDeviceManagerInstance().isDPCodeSupport(devId, "blelock_switch");

Offline stores

Get a list of stores within geographical scope

API description

void getStoreList(StoreGetReq storeGetReq, IThingResultCallback<List<StoreInfo>> callback);

Request parameters

Parameter Type Required Example Description
storeGetReq StoreGetReq Yes - -
callback IThingResultCallback<List> Yes - The callback.

Data model of StoreInfo

Field Type Description
id String The ID of a specified store.
name String The name of a specified store.
address String The address of the store.
lon Double The longitude of a specified store.
lat Double The latitude of a specified store.
source String The source of the store information. Valid values:
  • tuya: Tuya
  • baidu: Baidu
type String The type of points of interest (POI). Example: store_electrocar means an electric vehicle store.
coordType String The type of coordinate system. Valid values:
  • WGS84: Google Maps
  • GCJ02: AutoNavi
  • BD09LL: Baidu Maps
distance Double The distance from the store to the current location. Unit: meters.
favorite Boolean Specifies whether the store is favorited.
info ExtraInfo The additional information about the store.

Data model of ExtraInfo

Field Type Description
phone String The contact phone of the store.
picture String The image of the store.

Data model of StoreGetReq

Field Type Description
radius Int The radius of the geographical scope within which stores are returned. Unit: meters.
max Int The maximum number of stores to be returned in this call.
lon Double The longitude of the current location.
lat Double The latitude of the current location.
coordType String The type of coordinate system. Valid values:
  • WGS84: Google Maps
  • GCJ02: AutoNavi
  • BD09LL: Baidu Maps
source String The source of the store information. Valid values:
  • tuya: Tuya
  • baidu: Baidu
type String The type of point of interest (POI). Example: store_electrocar means an electric vehicle store.

Example

double longitude = 121.355359;
double latitude = 31.217979;
StoreGetReq storeGetReq = new StoreGetReq storeGetReq = new StoreGetReq().setLon(longitude).setLat(latitude).setRadius(5).setSource(StoreInfoConstants.Source.THING.value).setType(StoreInfoConstants.STORE_TYPE.ELECTRONIC.value);
ThingODSDK.getIODStoreInstance().getStoreList(storeGetReq, new IThingResultCallback<List<StoreInfo>>() {
            @Override
            public void onSuccess(List<StoreInfo> result) {
                showToast("success");
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                showToast(errorMessage);
            }
        });

Query stores within specified geographical scope

API description

void searchStoreList(StoreSearchReq storeSearchReq, IThingResultCallback<List<StoreInfo>> callback);

Request parameters

Parameter Type Required Example Description
storeSearchReq StoreSearchReq Yes - -
callback IThingResultCallback<List> Yes - The callback.

Data model of StoreSearchReq

Field Type Description
radius Int The radius of the geographical scope within which stores are returned. Unit: meters.
lon Double The longitude of the current location.
lat Double The latitude of the current location.
coordType String The type of coordinate system. Valid values:
  • WGS84: Google Maps
  • GCJ02: AutoNavi
  • BD09LL: Baidu Maps
source String The source of the store information. Valid values:
  • tuya: Tuya
  • baidu: Baidu
type String The type of point of interest (POI). Example: store_electrocar means an electric vehicle store.
keyword String The search keyword.
pageIndex Int The requested page number.
pageSize Int The maximum number of entries to be returned per page.

Example

double longitude = 121.355359;
double latitude = 31.217979;
StoreSearchReq storeSearchReq = new StoreSearchReq().setLon(longitude).setLat(latitude).setRadius(5).setSource(StoreInfoConstants.Source.THING.value).setType(StoreInfoConstants.STORE_TYPE.ELECTRONIC.value).setKeyword("car");
ThingODSDK.getIODStoreInstance().searchStoreList(storeSearchReq, new IThingResultCallback<List<StoreInfo>>() {
            @Override
            public void onSuccess(List<StoreInfo> result) {
                showToast("success");
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                showToast(errorMessage);
            }
        });

Cycling navigation

Implement features related to cycling navigation. For example, get a list of cycling routes and upload cycling routes.

Get device route statistics in a period

API description

void getTrackStatistic(TrackStatisticReq trackStatisticReq, IThingResultCallback<TrackStatisticInfo> callback);

Request parameters

Parameter Type Required Example Description
trackStatisticReq TrackStatisticReq Yes - -
callback IThingResultCallback Yes - The callback.

Data model of TrackStatisticReq

Field Type Description
deviceId String The device ID.
startTime Long The start time of the cycling period.
endTime Long The end time of the cycling period.

Data model of TrackStatisticInfo

  • Fields of TrackStatisticInfo

    Field Type Description
    deviceId String The device ID.
    list List The list of segmented routes.
  • Fields of TrackStatistic

    Field Type Description
    totalTime Long The total duration of a segmented route.
    startTime Long The start time of a segmented route.
    averageSpeed Double The average speed of a segmented route.
    maxSpeed Double The maximum speed of a segmented route.
    totalMileage Double The total distance of a segmented route.
    battery Int The battery information.

Example

TrackStatisticReq trackStatisticReq = new TrackStatisticReq().setDeviceId(deviceId).setStartTime(startTime).setEndTime(endTime);
ThingODSDK.getIODTrackInstance().getTrackStatistic(trackStatisticReq, new IThingResultCallback<TrackStatisticInfo>() {
            @Override
            public void onSuccess(TrackStatisticInfo result) {
                showToast("success");
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                showToast(errorMessage);
            }
        });

Get segmented routes of a device

API description

void getTrackSegment(TrackSegmentReq trackSegmentReq, IThingResultCallback<TrackSegmentInfo> callback);

Request parameters

Parameter Type Required Example Description
trackSegmentReq TrackSegmentReq Yes - -
callback IThingResultCallback Yes - The callback.

Data model of TrackSegmentReq

Field Type Description
deviceId String The device ID.
lastId Long The route ID used to query the next array of data.
lessMileage Double The minimum distance, used to filter data.
pageSize Int The maximum number of entries to be returned per page.

Data model of TrackSegmentInfo

  • Fields of TrackSegmentInfo

    Field Type Description
    deviceId String The device ID.
    lastIdStr Long The route ID used to query the next array of data.
    areLastPage Boolean Indicate whether the last page is returned.
    segmentList List The array of route data.
  • Fields of TrackSegment

    Field Type Description
    duration Long The cycling duration of the route. Unit: seconds.
    startTime Long The start time of the route. Unit: seconds.
    endTime Long The end time of the route. Unit: seconds.
    speed Double The cycling speed. Unit: km/h.
    mileage Double The distance. Unit: km.
    battery Int The battery Level.
    bufferFlag Int The flag of the route. Valid values:
    • 0: an online route segment
    • 1: an offline route segment

Example

TrackSegmentReq trackSegmentReq = new TrackSegmentReq().setDeviceId(deviceId).setLastId(-1).setLessMileage(1).setPageSize(10);
ThingODSDK.getIODTrackInstance().getTrackSegment(trackSegmentReq, new IThingResultCallback<TrackSegmentInfo>() {
            @Override
            public void onSuccess(TrackSegmentInfo result) {
                showToast("success");
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                showToast(errorMessage);
            }
        });

Report location to cloud

API description

void reportLocation(ReportLocationReq reportLocationReq, IThingResultCallback<Boolean> callback);

Request parameters

Parameter Type Required Example Description
reportLocationReq ReportLocationReq Yes - -
callback IThingResultCallback Yes - The callback.

Data model of ReportLocationReq

  • Fields of ReportLocationReq

    Field Type Description
    deviceId String The device ID.
    productId String The product ID (PID).
    payLoad PayLoad The location information.
  • Fields of PayLoad

    Field Type Description
    accuracy Float The precision of the location information. Unit: meters.
    battery Int The battery Level.
    lat Double The latitude of the current location.
    lon Double The longitude of the current location.
    speed Int The current value of dpCode for speed.
    mileage Int The current value of dpCode for mileage_once.
    start Boolean Indicates whether the current location is the start or end of the route. Valid values:
    • true: the start of the route
    • false: the end of the route

Example

double longitude = 121.355359;
double latitude = 31.217979;
ReportLocationReq.PayLoad payLoad = new ReportLocationReq.PayLoad().setLon(longitude).setLat(latitude).setBattery(50).setMileage(10).setSpeed(20).setStart(true);
ReportLocationReq reportLocationReq = new ReportLocationReq().setDeviceId(deviceId).setProductId(productId).setPayLoad(payLoad);
ThingODSDK.getIODTrackInstance().reportLocation(reportLocationReq, new IThingResultCallback<Boolean>() {
              @Override
              public void onSuccess(Boolean result) {
                  showToast("success");
              }

              @Override
              public void onError(String errorCode, String errorMessage) {
                  showToast(errorMessage);
              }
          });