From 9d0d50f9131cd024e1d090399fe2f144b5b9f436 Mon Sep 17 00:00:00 2001 From: adfx Date: Thu, 19 Dec 2019 15:27:03 +0100 Subject: [PATCH 1/3] my maploader version --- README.md | 9 +++++++++ maploader.js | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 22ebc9c..bd34ee6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # MapLoader Map Backup/Restore for Xiaomi Vacuum and Roborock +## +Modifications of my side: +- added check wether file exists. If not --> skip + create error msg +- added all necessary files for transfer; Reason: reloading map worked fine but several times docking station was rotated. Made already defined zones useless +- added logging via mqtt + + + + ## Description MapLoader is a NodeJS based service, running on the robot that listens to MQTT commands.\ Available topics: diff --git a/maploader.js b/maploader.js index b08f5cc..b5601df 100644 --- a/maploader.js +++ b/maploader.js @@ -1,10 +1,11 @@ const fs = require('fs'); const mqtt = require('mqtt'); -const client = mqtt.connect('mqtt://172.17.2.86'); +const client = mqtt.connect('mqtt://user:passwd@xxx.xxx.xxx.xxx',{clientId:"rockrobo"});//enter your mqtt-server credentials here // Subscribe Topics client.on('connect', () => { console.log("Connected"); + client.publish("rockrobo/map/log", "Connected");//added log via mqtt client.subscribe('rockrobo/map/load'); client.subscribe('rockrobo/map/save'); }); @@ -16,6 +17,8 @@ client.on('message', (topic, message) => { var destination = '/mnt/data/rockrobo/'; console.log("Received Load Request: " + message); + + client.publish("rockrobo/map/log", "Received Load Request: " + message);//added log via mqtt copyFiles(source, destination); } @@ -24,21 +27,31 @@ client.on('message', (topic, message) => { var destination = '/mnt/data/maploader/maps/' + message + '/'; console.log("Received Save Request: " + message); + client.publish("rockrobo/map/log", "Received Save Request: " + message);//added log via mqtt copyFiles(source, destination); } }); // Backup or restore map files function copyFiles(source, destination) { - const files = ['user_map0', 'last_map', 'PersistData_1.data', 'PersistData_2.data']; + const files = ['user_map0', 'last_map', 'PersistData_1.data', 'PersistData_2.data', 'ChargerPos.data', 'Rotater.cfg', 'StartPos.data'];//added all necessary files for complete transfer, otherwise docking station could be rotated to map which makes created zones useless if (!fs.existsSync(destination)){ fs.mkdirSync(destination); console.log('Created directory: ' + destination); + client.publish("rockrobo/map/log", 'Created directory: ' + destination);//added log via mqtt } for (i = 0; i < files.length; i++) { - fs.copyFileSync(source + files[i], destination + files[i]); - console.log('Copied ' + files[i] + ' from ' + source + ' to ' + destination); + if (!fs.existsSync(source + files[i])){//check if files not existing and create error msg + console.log('Error: ' + source + files[i] + ' not found'); + var options = {retain:true, qos:1}; + client.publish('Error: ' + "rockrobo/map/log", files[i] + ' not found', options);//added log via mqtt + } + else{//if file present, copy and create msg + fs.copyFileSync(source + files[i], destination + files[i]); + console.log('Copied ' + files[i] + ' from ' + source + ' to ' + destination); + client.publish("rockrobo/map/log", 'Copied ' + files[i] + ' from ' + source + ' to ' + destination);//added log via mqtt + } } } From 6cba2e125889a16bff7613b37a9510e6ff79822e Mon Sep 17 00:00:00 2001 From: adfx Date: Thu, 19 Dec 2019 15:31:04 +0100 Subject: [PATCH 2/3] my maploader version --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd34ee6..3298fe6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ Map Backup/Restore for Xiaomi Vacuum and Roborock ## -Modifications of my side: + +## +This is a fork of Thyraz maploader! Thanks for his great work. + +## +Modifications made by me: - added check wether file exists. If not --> skip + create error msg - added all necessary files for transfer; Reason: reloading map worked fine but several times docking station was rotated. Made already defined zones useless - added logging via mqtt From 07949a37b78f2f04f2a8318761ca26ac1a93a2af Mon Sep 17 00:00:00 2001 From: adfx Date: Thu, 19 Dec 2019 21:18:15 +0100 Subject: [PATCH 3/3] updated log --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3298fe6..ff24c70 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is a fork of Thyraz maploader! Thanks for his great work. Modifications made by me: - added check wether file exists. If not --> skip + create error msg - added all necessary files for transfer; Reason: reloading map worked fine but several times docking station was rotated. Made already defined zones useless -- added logging via mqtt +- added logging via mqtt. Subscribe to: rockrobo/map/log