Synchronization flow
Synchronization flow consists of two parts – Cloud sync and Robot sync.
Cloud sync
- Triggered by a “Synchronize” button on the offline app UI (sidebar).
- Synchronizes offline and online databases, images, and RFs.
- Requires internet connection.
- Initial HTTPS requests are sent from the offline backend to the SM. SM accepts offline data and responds with robots ideal state data and online data. HTTPS requests contain Authentication header with private JWT (from the local environment, inputted during installation) for authenticating the requests. See Center Authentication for details on authentication.
- Following the initial request, the offline backend processes the robots ideal state data and gets a list of missing RFs. Afterwards, the offline backend downloads all missing RFs to the computer.
- Offline app also downloads any missing static image files for Action and Category models.
- Offline backend sends children and sessions collections (synchronized upstream).
- Online backend responds with latest actions, categories, skills, etc. (synchronized downstream).
- Online backend also responds with “perfect state”, which describes, for each robot, what RFs should be present, where on the robot, and where to download them from (URLs)
- No data comes from one offline app to another, as all data are sent only in one direction – upstream or downstream.
Robot sync
- Triggered by a “Update Robots” button on the offline app UI (sidebar).
- Synchronizes RFs between the offline app and all connected robots.
- Requires the offline app to be connected to robots via the UI.
- Skips updating robots that are not connected.
- The offline app uses SSH to connect to each robot. SSH passwords (saved in environment variables during installation) are used for authentication. Once connected, the app uploads all missing RFs (downloaded during Cloud sync) to the robots.
- In addition to uploading RFs, Robot sync also runs scripts to find RFs currently present on the robots. This list is used during Cloud sync to determine which RFs are missing.
- Important: Robot sync must be run at least once before the first Cloud sync on a newly installed offline app. This ensures that the offline app can download missing RFs during the Cloud sync.
Supporting script files description:
- traverse_remote_dir.py
- This script connects via SSH to a remote using provided hostname, ip and password, and traverses the provided remote dir. Then it collects all found file paths and saves them in a CSV file under column “remote_path”.
- It is used to track the list of present RFs on a robot, to gather the list of missing RFs to download with cloud sync.
- traverse_local_dir.py
- This script traverses a provided dir, collects all found file paths and saves in a CSV file under column a “local_path”.
- It is used to track RFs that were previously downloaded, to gather the list of missing RFs to download next.
- get_missing_paths.py
- This script reads which file paths should be located and which have been actually located on a remote (robot) from 2 CSV files. It then compares the file paths and outputs another CSV file with all file names missing from the remote, local download paths and URLs to download the files from. URLs to download are converted from short versions to full versions.
- It is used to get the list of missing RFs to download afterwards.
- download_files_to_local.py
- This script downloads files from remote URLs to local paths. It reads a CSV file to get URLs and corresponding local paths. It downloads from a remote host using bearer authentication JWT. Downloads files to CONFIG.UPLOAD_DIR_PATH unless base_dir is provided. Local paths can be relative paths or file names only.
- It is used to download missing RFs to a local computer to be uploaded to a robot next.
- upload_files_to_remote.py
- This script uploads files from local paths to remote paths. It connects to the remote via SSH using the provided hostname, ip and password. It reads a CSV file to get local paths and corresponding remote paths. Local paths can be relative paths or file names only.
- It is used to upload RFs (previously downloaded with cloud sync) to a robot during robot sync.
Full sync sequence diagram
sequenceDiagram
actor S as Specialist
participant B as Offline App
participant OA as Online App
participant R as Robot(s)
participant M as Online MongoDB
opt First iteration
opt Robot Sync on LAN
S->>+B: Press "Update the Robot", which initiates robot sync
B->>B: upload_files_to_remote.py
B->>R: Nothing is uploaded on the first run
B->>R: Run traverse_remote_dir.py
R->>B: Returns found RFs
B->>-S: Displays robot sync result to user
end
end
loop Loop forever
opt Cloud Sync with internet connection
S->>+B: Press "Synchronize", which initiates cloud sync
B->>+OA: POST /sync (app version, JWT, sessions, children)
M->>OA: Loads version_maps
OA->>OA: Checks if offline version is compatible
alt Compatible versions
OA->>M: Upsert sessions/children
OA->>B: Responds with is_compatible=True, actions, <br> categories, skills, etc.
else Not compatible
OA->>OA: Runs sync migrations
OA->>M: Upsert sessions/children
OA->>-B: Responds with is_compatible=False and empty data
end
B->>B: Checks if is_compatible is True
alt True
B->>B: Updates local DB with actions, categories, skills, etc.
B->>OA: Request missing static images <br> (_download_static_images)
OA->>B:
B->>B: Run get_missing_paths.py
B->>OA: Request missing RFs (download_files_to_local.py)
OA->>B:
B->>S: Displays sync result to user
else False
B->>-S: Display "outdated app" message <br> and request updating the app.
end
end
opt Robot Sync on LAN
S->>+B: Press "Update the Robot", which initiates robot sync
B->>B: upload_files_to_remote.py
B->>R: Send downloaded RFs
B->>R: Run traverse_remote_dir.py
R->>B: Gets found RF paths
B->>-S: Displays robot sync result to user
end
end