1

how to get driver groups using wialon.js

(09/02/2019 14:33:51 отредактировано Fadi Ramzi)

Тема: how to get driver groups using wialon.js

Hello,
the docs of wialon.js sdk is not enough clear to understand how to deal with wialon data
it is  complex api, the structure of the api is so complicated
so can you provide me with the best way to read and use it?
i also tried to read the docs with the examples in playground but there are many things are missed

now i have problem in loading drivers group, how to do that?
there is an example on how to load resources,reports and units but how about drivers groups?
i checked the most provided examples but i couldn't understand how to deal perfectly with js sdk
for example:i searched about res.getReports() function but i didn't find this function in all js sdk,how can i know details of the api(classes and functions name)?

please can you guide me?


best regards,
thanks

2

how to get driver groups using wialon.js

Re: how to get driver groups using wialon.js

Drivers and driver groups are part of resource.

To fetch them you need to get resources via updateDataFlags/searchItems with corresponding data flags. It is 0x100 for drivers and 0x8000 for driver groups.

All classes are presented in docs. But, suddenly, not all their methods.

There is Session->loadLibrary method, that adds different methods:

+ открыть спойлер
  • userNotifications - personal notifications plugin, applied to users, require wialon.item.User.dataFlag.notifications data flags
  • itemCustomFields - custom fields plugin, applied to all items, require wialon.item.Item.dataFlag.customFields data flags, custom field sample: {id: X, n: "name", v: "value"}
  • itemAdminFields - admin fields plugin, applied to all items, require wialon.item.Item.dataFlag.adminFields data flags, admin field sample: {id: X, n: "name", v: "value"}
  • itemProfileFields - profile fields plugin, applied to all items, require wialon.item.Item.dataFlag.profileFields data flags, profile field sample: {id: X, n: "name", v: "value"}
  • itemIcon - add functionality from MIcon to units and unit groups, require wialon.item.Item.dataFlag.image data flags
  • unitCommandDefinitions - unit command definitions plugin, applied to units, require wialon.item.Unit.dataFlag.commandAliases data flags, command definition sample: {id: X, n: "my command", c: "query_pos", l: "gsm", p: "", a: 0x1}
  • unitSensors - unit sensors plugin, applied to units, require wialon.item.Unit.dataFlag.sensors data flags, sensors sample: {id: X, n: "my sensor", t: "unk", d: "", m: "km/h", p: "param", f: 0, c: "", vt: 0, vs: 0, tbl: [[0, 1, 2]]}
  • unitServiceIntervals- unit service intervals plugin, applied to units, require wialon.item.Unit.dataFlag.maintenance data flags
  • unitTripDetector - unit trip detector functionality
  • unitMessagesFilter - unit messages filter functionality
  • unitReportSettings - unit report settings
  • unitFuelSettings - unit fuel settings
  • resourceNotifications - unit notifications, applied to resources, require wialon.item.Resource.dataFlag.notifications data flags
  • resourceJobs - jobs, applied to resources, require wialon.item.Resource.dataFlag.jobs data flags
  • resourcePois - POIs, applied to resources, require wialon.item.Resource.dataFlag.poi data flags
  • resourceZones - zones, applied to resources, require wialon.item.Resource.dataFlag.zones data flags, zone sample
  • resourceZoneGroups - zone groups, applied to resources, require wialon.item.Resource.dataFlag.zoneGroups data flag
  • resourceDrivers - drivers, applied to resources, require wialon.item.Resource.dataFlag.drivers data flags
  • resourceDriverGroups - driver groups, applied to resources, require wialon.item.Resource.dataFlag.driverGroups data flags
  • resourceTrailers - trailers, applied to resources, require wialon.item.Resource.dataFlag.trailers data flags
  • resourceTrailerGroups - trailer groups, applied to resources, require wialon.item.Resource.dataFlag.trailerGroups data flags
  • resourceAccounts - billing account, applied to resources
  • resourceReports - reports, applied to resources
  • unitEvents - unit events history
  • mobileApps - registered user mobile applications

To get getReport/getReports method, you need to loadLibrary('resourceReports'), then those methods will be available on Resource objects.

They didn't documented, because they are added dynamically:

+ открыть спойлер

In SDK such code exists:

bindPropItem(wialon.item.Item, "flds", "customField", "item/update_custom_field");
bindPropItem(wialon.item.Item, "ftp", "FtpProp", "item/update_ftp_property");
bindPropItem(wialon.item.Item, "aflds", "adminField", "item/update_admin_field");
bindPropItem(wialon.item.Item, "pflds", "profileField", "item/update_profile_field");
bindPropItem(wialon.item.User, "usnf", "userNotification", "user/update_user_notification");
bindPropItem(wialon.item.User, "mapps", "mobileApp", "user/update_mobile_app");
bindPropItem(wialon.item.Unit, "cml", "commandDefinition", "unit/update_command_definition");
bindPropItem(wialon.item.Unit, "sens", "sensor", "unit/update_sensor");
bindPropItem(wialon.item.Unit, "si", "serviceInterval", "unit/update_service_interval");
bindPropItem(wialon.item.Resource, "unf", "notification", "resource/update_notification", "resource/get_notification_data");
bindPropItem(wialon.item.Resource, "ujb", "job", "resource/update_job", "resource/get_job_data");
bindPropItem(wialon.item.Resource, "zl", "zone", "resource/update_zone", "resource/get_zone_data");
bindPropItem(wialon.item.Resource, "zg", "zonesGroup", "resource/update_zones_group");
bindPropItem(wialon.item.Resource, "poi", "poi", "resource/update_poi", "resource/get_poi_data");
bindPropItem(wialon.item.Resource, "drvrs", "driver", "resource/update_driver");
bindPropItem(wialon.item.Resource, "drvrsgr", "driversGroup", "resource/update_drivers_group");
bindPropItem(wialon.item.Resource, "trlrs", "trailer", "resource/update_trailer");
bindPropItem(wialon.item.Resource, "trlrsgr", "trailersGroup", "resource/update_trailers_group");
bindPropItem(wialon.item.Resource, "rep", "report", "report/update_report", "report/get_report_data");
bindPropItem(wialon.item.Resource, "orders", "order", "order/update");
bindPropItem(wialon.item.Resource, "order_routes", "orderRoute", "order/route_update");
bindPropItem(wialon.item.Resource, "tags", "tag", "resource/update_tag");
bindPropItem(wialon.item.Resource, "tagsgr", "tagsGroup", "resource/update_tags_group");
bindPropItem(wialon.item.Route, "rr", "round", "route/update_round", "route/get_round_data");
bindPropItem(wialon.item.Route, "rs", "schedule", "route/update_schedule");

For example, that line adds custom fields functionality:

bindPropItem(wialon.item.Item, "flds", "customField", "item/update_custom_field");

Then instances of wialon.item.Item obtaining following methods:

  • getСustomField(id) — returns single custom field by id
  • getСustomFields() — returns object with all custom fields
  • createCustomField(json, callback) — creates custom field (does a request)
  • updateCustomField(json, callback) — modifies custom field (does a request)
  • deleteCustomField(id, callback) — deletes custom field (does a request)

Also, if bindPropItem has fifth argument (like resource/get_zone_data), then another method will be added:

  • getZonesData(ids, flags, callback)