机械臂所使用的下位机驱动板在掉电后会损失数据,如果想保存一些数据使其不会随着掉电丢失,可将这些数据写入文件储存于Flash文件系统中,只需在掉电前将文件写入Flash,这样掉电后文件不会丢失,上电后读取文件即可。
本章的JSON指令用于操作存储在 ESP32 FLASH 中的文件,包括扫描文件、新建文件、编辑文件内容、读取文件内容等。掉电后文件不会丢失,若您重新给RoArm-M2-S上传程序,也可在Arduino IDE中选择保留Flash文件。
{"T":200}
返回的数据如下:
>>>---=== File Name and First line ===---<<<
[file]: [boot.mission]
[first line]:
{"name":"boot","intro":"these cmds run automatically at boot."}
>>>---=== File Name and First line ===---<<<
[file]: [mission_a.mission]
[first line]:
{"name":"mission_a","intro":"test mission created in flash."}
>>>---=== File Name and First line ===---<<<
[file]: [wifiConfig.json]
[first line]:
{"wifi_mode_on_boot":3,"sta_ssid":"JSBZY-2.4G","sta_password":"waveshare0755","ap_ssid":"RoArm-M2","ap_password":"12345678"}
返回值包括每个文件的文件名和文件内的第一行内容,此处的文件名会显示出完整的文件名,若您创建新的文件是带有后缀的,则也会显示。后缀为 .mission 的文件即为任务文件,可以储存一些指令用于机械臂批量操作。
{"T":201,"name":"file.txt","content":"inputContentHere."}
{"T":202,"name":"mission_a.mission"}
返回内容如下,返回内容会标注出来行号(以下是案例,并不代表您的RoArm-M2中会有mission_a.mission这个文件):
{"T":202,"name":"mission_a.mission"}
---=== File Content ===---
reading file: [mission_a.mission] starts:
[lineNum: 1 ] - {"name":"mission_a","intro":"test mission created in flash."}
[lineNum: 2 ] - {"T":104,"x":235,"y":0,"z":234,"t":3.14,"spd":0.25}
[lineNum: 3 ] - {"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":2.448233337,"spd":0.25}
[lineNum: 4 ] - {"T":114,"led":155}
[lineNum: 5 ] - {"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":2.466641107,"spd":0.5}
[lineNum: 6 ] - {"T":114,"led":0}
[lineNum: 7 ] - {"T":114,"led":255}
[lineNum: 8 ] - {"T":104,"x":156.428798,"y":40.20501586,"z":76.68339473,"t":3.052621768,"spd":0.25}
[lineNum: 9 ] - {"T":111,"cmd":3000}
[lineNum: 10 ] - {"T":114,"led":0}
[lineNum: 11 ] - {"T":1,"mode":1}
^^^ ^^^ ^^^ reading file: mission_a.mission ends. ^^^ ^^^ ^^^
案例mission_a.mission 文件中实际的文件内容如下:
{"name":"mission_a","intro":"test mission created in flash."}
{"T":104,"x":235,"y":0,"z":234,"t":3.14,"spd":0.25}
{"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":2.448233337,"spd":0.25}
{"T":114,"led":155}
{"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":2.466641107,"spd":0.5}
{"T":114,"led":0}
{"T":114,"led":255}
{"T":104,"x":156.428798,"y":40.20501586,"z":76.68339473,"t":3.052621768,"spd":0.25}
{"T":111,"cmd":3000}
{"T":114,"led":0}
{"T":1,"mode":1}
{"T":203,"name":"file.txt"}
{"T":204,"name":"file.txt","content":"inputContentHere."}
{"T":205,"name":"file.txt","lineNum":3,"content":"content"}
{"T":206,"name":"file.txt","lineNum":3,"content":"Content"}
{"T":207,"name":"file.txt","lineNum":3}
{"T":208,"name":"file.txt","lineNum":3}