flespi Channels API
[Channel](https://flespi.com/kb/channel-entry-point-to-gateway) is a protocol-specific entry point for tracking devices to the [flespi telematics hub](https://flespi.com). Configured channel starts to listen to new TCP/UDP connections from tracking devices on a **dedicated domain name:port**. In some cases, channel provides a secondary URI to connect auxiliary devices such as tachographs and cameras. One channel parses messages from devices communicating over one protocol selected during channel creation. Channel provides only data ingestion functionality. In most cases you need to register [virtual device](https://flespi.com/kb/device-virtual-instance-of-real-tracker) with device type that corresponds to channel protocol. With registered virtual device you have [remote control](https://flespi.com/kb/commands-and-settings) capabilities, long term telematics data storage, rich [reporting engine](https://flespi.com/kb/analytics-flespi-reports-engine), can perfom [data correction](https://flespi.com/kb/plugins-functionality-extensions-for-flespi-devices) and much more. Also the actual parameters in parsed messages can be different across [device types](https://flespi.com/devices) which is also defined by the registered virtual device. All channel modification operations are reported to common [logs subsystem](https://flespi.io/docs/#/platform/logs) with the following possible event codes: Event code | Description -----|------ 1|channel was created via REST API 2|channel was updated via REST API 3|channel was deleted via REST API 20|channel was blocked, see [customer](https://flespi.io/docs/#/platform/customer) for more information 21|channel was unblocked, see [customer](https://flespi.io/docs/#/platform/customer) for more information 100|channel accepted connection 101|channel connection was identified 102|channel connection was closed 103|channel data processing error 104|channel data processing warning 114|channel configuration is invalid 115|the command has been sent into the transport connection 116|channel protocol was modified Log records produced by the channel protocol parser (connection, data processing and command events) contain the "protocol_modified" parameter - modification timestamp of the channel protocol whose parser produced the record. Connection keeps the parser it was established with until it is closed, even if the protocol is modified in the meantime. If channel protocol is modified (event_code=116), you may expect the following additional parameters in the log record: Field name | Meaning ----------------------|-------- protocol_name |name of the modified channel protocol protocol_modified |new modification timestamp of the channel protocol previous_protocol_modified |previous modification timestamp of the channel protocol If you do not see anything in channel logs it means that device never attempted to establish connection to the channel and there is nothing to debug on flespi, you should check device configuration first. Whenever you need to troubleshoot device operation you can investigate raw traffic between flespi channel and hardware device. You can fetch traffic packets via API or just use flespi.io panel for this. On 'Logs & Messages' tab there is TRAFFIC button and also from each log record or message you can navigate to associated raw traffic exchange via context menu command. For traffic from unidentified connections or connectionless protocols please check the traffic under 'unidentified' ident value. ###### Channel messages Parsed data from tracking devices is stored in the message buffer associated with the given channel. Message fields depend on the channel [protocol](https://flespi.com/protocols) and type of [registered device](https://flespi.com/kb/device-virtual-instance-of-real-tracker). [Messages](https://flespi.com/kb/messages-basic-information-units) can be pulled out from the buffer via a **channels/messages** request in a **single reader** mode, meaning that stable reading process can be performed by only one worker. It is also possible to receive channel messages in realtime using MQTT API by subscribing to 'flespi/message/gw/channels/#' topic. To stay current with channel protocol updates, subscribe to 'flespi/message/gw/channel-protocols/{protocol-id}/changelog' MQTT topic delivering any changes published in the channel protocol [changelog](https://forum.flespi.com/t/changelog). And [streams](https://flespi.com/kb/stream-forward-data-from-gateway) can be used to push messages to your application in variety of protocols. Every message in the buffer is represented by a JSON object with the following fields: Field | Description --------|---------- timestamp | Actual message time provided by tracking device ident | Tracking device identification string** * ** [param name] | Any additional parameters passed by tracking device ** * ** *Unique tracking device identifier. It can be IMEI, international phone number or device serial number. Symbols '#','+','/',':' are not allowed. The way flespi gateway identifies a certain device is defined by the protocol.* ###### Channel connections Information on every active TCP connection from a tracking device to the specified channel: * connection opening time * listening channel ID * connected device IP address and identification string Connections opening, closing, and identification operations report to the common [logs subsystem](https://flespi.io/docs/#/platform/logs) with the following possible event codes: Event code | Description -----|------ 100|channel has accepted connection 101|channel connection was identified 102|channel connection was closed, see below values of "close_code" parameter If connection is accepted or identified (event_code=100 or event_code=101), you may expect the following additional parameters in the log record: Field name | Meaning ----------------------|-------- source |connected device's address transport |connected device's transport: tcp, udp, http etc. ident |connected device's identification string (optional, last value only) protocol_modified |modification timestamp of the channel protocol serving the connection If connection is closed (event_code=102), you may expect the following additional parameters in the log record: Field name | Meaning ----------------------|-------- close_code |the reason of connection close operation error_text |optional, additional error information source |connected device's address transport |connected device's transport: tcp, udp, http etc. ident |connected device's identification string (optional, last value only) protocol_modified |modification timestamp of the channel protocol serving the connection duration |connection duration in seconds msgs |quantity of messages received recv |quantity of bytes received send |quantity of bytes sent Possible "close_code" values: Code | Event -----|------ 2|connection closed by tracking device 3|connection successfully processed and closed 4|received data violates channel's protocol 5|internal error 6|data parsing error (see log details) 7|connection closed due to server restart 8|protocol implementation updated 9|channel's parameters changed 10|connection closed upon user's request 11|outgoing connection failed 12|Current connection closed because of ident collision: device has opened another connection to the channel without closing the first one. It may happen because of device firmware bug or by an unstable connectivity provider. In general, this happens to plenty of devices and usually can be ignored. 13|device is blocked 14|authentication failed 15|device associated with the connection was created, changed or deleted 16|channel rejected connection due to IP addresses match blacklist or mismatch whitelist 17|connection is closed by inactivity timeout 18|unsupported protocol part 19|protocol mismatch 20|processing was cancelled 21|channel is blocked 22|device media is blocked 23|device is disabled Here is an example of a log record reporting that **TCP** connection from **127.0.0.1** to **channel 1374** was successfully processed and closed after **11 seconds** and identified by device with ident **123456789**, **32** bytes received and **64** bytes transmitted, **10** messages total: ```json { "close_code": 3, "duration": 11, "event_code": 102, "event_origin": "gw/channels/1374", "event_text": "connections/127.0.0.1/closed", "ident": "123456789", "msgs": 10, "recv": 32, "send": 64, "source": "127.0.0.1", "timestamp": 1490347944.893743, "transport": "tcp" } ``` ###### Channel blocking When channel usage exceeds account limits the platform puts the [block reason](https://flespi.io/docs/#/platform/customer) code into the channel 'blocked' field. Codes 1, 2 and 3 pause the channel: it stops accepting new connections while established ones keep operating on TCP, MQTT and FTP transports. On traffic and messages overflow the most consuming devices are blocked before the channel itself. Other codes stop the channel and close all its connections.