How to get the push message
There are some real-time messages that need to be passed to the client through the server.We use websocket to implement this function.
There are two kinds of messages to listen: device data push and message data push.
Device data push
To get device data push need to do the following steps:
- Connect to wss://openapi.tftiot.com:8443/websocket
- Send json message like: “{“token”:”userId”,”md5-password”:”md5-password”,”event”:”signin”}”
The receive message is like:
{ event: 'snapshot', //message data type data: { //message data device_key: "191972038175241", id: 26847, imei: "1000000000112567", model: "T1", status: { ac: -1, acc: 1, acc_switch_time: 1627692684000, accumulating_fuel_consumption: 0, address: "", air_inflow_temp: 0, air_input: 0, air_pressure: 0, alert_sum: "404228143--972-2129968", alerts: 0, alerts1: 0, altitude: 42, analog1: 0.0703125, analog2: 0.0703125, analog3: 0, analog4: 0, analog5: 0, antithefted: 0, antithefted_status: 0, azimuth: 143, bat: 0, battery_voltage: 4.24, battery_voltage_percent: 100, comment: "", cooling_fluid_temp: 0, cur_event: 0, // This field represents the alarm number, and the corresponding relationship // refers to the definition of alarm number date: 1627693682000, dragThreshold: 0, drag_threshold: 0, engine_load: 0, engine_time: 13057434, event: 0, external_power_voltage: 28.09, fuel: 0, gps: true, gpsWorking: true, idle_status: 1, imei: "1000000000002567", input: "1:0|2:0|3:1|4:0|5:0|6:0|7:0|8:0", instant_fuel_consumption: 0, iop: 16384, is_external_battery_lower: 0, is_inner_battery_lower: 0, is_solar_charging: 0, is_usb_charging: 0, last_reg_date: 1627693682000, lat: 14.824593, latlng_valid: 1, link_type: "tcp", lng: 120.482598, location_date: 1627693682000, mileage: 145278016, network_signal: -999, obd_version: "", online: 1, output: "1:0|2:0|3:0|4:0|5:0|6:0|7:0|8:0", polling: 1627693682000, pwr: -1, relay: 0, relay_status: 0, remain_fuel_rate: 0, rpm: 0, rs232_device_valid: 0, satellite_count: 11, solar_voltage: 0, speed: 0, throttle_position: 0, version: "", }, }, error: 0, //error code }
Message type list
- snapshot
Device location status update data - bleTire
Bluetooth tire pressure device update information - rs232Tire
RS232 tire pressure device update information - driver
Driver update information - obdErrorInfo
OBDII error message - rs232Fuel
RS232 fuel device update information
Message data push
To get Message data push need to do the following steps:
- Connect to wss://openapi.tftiot.com
- Send json message like: “{“user_id”:”userId”,”md5-password”:”md5-password”,”type”:”registUserMessage”}”
The receive message is a json string, after decode is like:
{ type: 'messagePass', //message data type from_id: 0, //message sender's id,0 is System,1 is Alarm,others is users'id from_name: 'name', //sender's name message: 'message', //message content alarm_msg: object, //alarm message object date: 0, //message send date's timestamp }
Message type list
- messagePass
Message push - getFileShake
Can start requesting to download the file - downloadAllow
The file is ready,can start downloading the file
Tips: It is recommended to send a “ping” message to the server every minute to keep the connection from being disconnected.