Remote File Management¶
The TEG gateway supports remote file management via ThingsBoard shared attributes. This mechanism allows configuration and system files on the gateway device to be created, updated, monitored, and synchronized in a controlled and traceable way. The approach is designed to be robust against intermittent connectivity and to support both read-only mirroring and file writing.
The remote file management mechanism follows a server-authoritative model. ThingsBoard shared attributes define the desired state of all managed files. The TEG gateway never propagates local file changes upstream, except for mirroring file content and reporting synchronization status.
Client Attributes¶
Client attributes are used to report file content back to ThingsBoard and preserve synchronization status.
For each file defined in the FILES attribute:
A client attribute
FILE_READ_<file_key>mirrors the latest local file content.A global client attribute
FILE_HASHESis updated after file creation or modification.
File Hashes and Synchronization¶
The FILE_HASHES attribute is used to ensure consistency between ThingsBoard and the TEG gateway.
The TEG gateway periodically computes a hash for each managed local file and compares it against the corresponding entry in FILE_HASHES. Each entry includes both the hash and the associated write_version.
If a mismatch is detected:
The TEG gateway requests the latest content from
FILE_CONTENT_<file_key>.If the shared attribute is missing or empty, no action is taken.
If a managed file was modified locally, the detected hash mismatch causes the TEG gateway to re-apply the remote file content, restoring the desired state defined in ThingsBoard.
If a file update fails, for example due to invalid encoding, insufficient permissions, or temporary I/O errors, the TEG gateway logs the error locally and does not update the corresponding hash entry. This allows the issue to be diagnosed and retried without leaving the system in an inconsistent state.
Example: FILE_HASHES client attribute
{
"crontab": {
"hash": "5eaad668b8e694ec58f0873830110d5f",
"write_version": 2
},
"controller_config": {
"hash": "9368caefc2b90f334671fb96e41ecbe1",
"write_version": 3
}
}