RoArm-M3-S FLASH File System Operation

From Waveshare Wiki
Jump to: navigation, search

FLASH File System Operation

The slave driver board used by the robotic arm loses data after power-off. To save certain data and prevent it from being lost during power off, you can write this data into a file and store it in the Flash file system. Simply write the file to Flash before power-off, ensuring the file remains intact after power is restored, and then read the file upon powering up.

The JSON commands in this chapter are designed for manipulating files stored in the ESP32 FLASH, including scanning files, creating new files, editing file content, and reading file content. The files are retained even after power-off. If you re-upload the demo for RoArm-M3-S, you can also choose to save Flash files in the Arduino IDE.


Scan FLASH Files

{"T":200}
  • 200: Indicates this command is CMD_SCAN_FILES for scanning all files of the current Flash file system.

The returned data is shown below:

>>>---=== 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-M3","ap_password":"12345678"}

The returned values include the file name of each file and the first line of content. This file name will display the full file name. If you create a new file with a suffix, it will be displayed too. The files with the suffix .mission are mission files, which can store some commands for batch operation of the robotic arm.

  • boot.mission: The mission file that can automatically run after booting the robotic arm. If this file is not found during the startup process, it will be automatically created. All the rest of the JSON commands can be added to this file to configure the steps that need to be executed automatically after powering up;
  • mission_a.mission is the example of testing the generated mission file, which does not represent there will be a file named mission_a.mission in your RoArm-M3.
  • wifiConfig.json is for storing WiFi-related configuration files. If the file is not detected upon startup, it will be automatically created and set a hotspot in the default AP mode. For more details, you can refer to RoArm-M3-S_WIFI Configuration.

Create File

{"T":201,"name":"file.txt","content":"inputContentHere."}
  • 201: indicates this command is CMD_CREATE_FILE for creating a file.
  • name: The file name to be created, which must be input the full file name. If you want to create a .txt file, the file name must include the .txt suffix, as shown above.
  • content: the content of the first line in the file.


Read File Content

{"T":202,"name":"mission_a.mission"}
  • 202: indicates this command is CMD_READ_FILE for reading a file content.
  • name: the file name to be read. The full filename must be entered, if you created the file with a suffix, the filename you enter must include the suffix.

The content returned is as follows, with line numbers marked (the following is an example, it does not mean that you will have the file mission_a.mission in your RoArm-M3):

{"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":0,"r":0,"g":3.14,"spd":0.25}
[lineNum: 3 ] - {"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":0,"r":0,"g":3.14,"spd":0.25}
[lineNum: 4 ] - {"T":114,"led":155}
[lineNum: 5 ] - {"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":0,"r":0,"g":3.14,"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":0,"r":0,"g":3.14,"spd":0.25}
[lineNum: 9 ] - {"T":111,"cmd":3000}
[lineNum: 10 ] - {"T":114,"led":0}
^^^ ^^^ ^^^ reading file: mission_a.mission ends. ^^^ ^^^ ^^^

The actual file content in the mission_a.mission file is as follows:

{"name":"mission_a","intro":"test mission created in flash."}
{"T":104,"x":235,"y":0,"z":234,"t":0,"r":0,"g":3.14,"spd":0.25}
{"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":0,"r":0,"g":3.14,"spd":0.25}
{"T":114,"led":155}
{"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":0,"r":0,"g":3.14,"spd":0.5}
{"T":114,"led":0}
{"T":114,"led":255}
{"T":104,"x":156.428798,"y":40.20501586,"z":76.68339473,"t":0,"r":0,"g":3.14,"spd":0.25}
{"T":111,"cmd":3000}
{"T":114,"led":0}


Delete File

{"T":203,"name":"file.txt"}
  • 203: This command is CMD_DELETE_FILE for deleting the specified file.
  • name: the file name to be deleted, and you need to input the full file name here.


Edit FLASH File

Add New Line At End of File

{"T":204,"name":"file.txt","content":"inputContentHere."}
  • 204: This command is CMD_APPEND_LINE for adding a line to the end of the specified file.
  • name: The file name to be edited, and you need to input the full file name here.
  • content: The content to be added.


Insert Content at Specified Line in File

{"T":205,"name":"file.txt","lineNum":3,"content":"content"}
  • 205: This command is CMD_INSERT_LINE for adding a line at specified line in the specified file.
  • name: The file name to be edited, and you need to input the full file name here.
  • lineNum: Specifies the row number where the new content is inserted. The line number of the first line in the file is 1; for example, if the value of lineNum is 3, the original third line will become the fourth line, and the new content will be inserted as the third line.
  • content: The content to be inserted.


Replace Content at Specified Line in File

{"T":206,"name":"file.txt","lineNum":3,"content":"Content"}
  • 206: This command is CMD_REPLACE_LINE for replacing the content of specified line in the specified file.
  • name: The file name to be edited, and you need to input the full file name with a suffix.
  • lineNum: Specify the line number of the content to be replaced. For example, the lineNum value here is 3, it represents the content of the third line that will be replaced.
  • content: The content to be replaced.


Read Content at Specified Line in File

{"T":207,"name":"file.txt","lineNum":3}
  • 207: This command is CMD_READ_LINE for reading the content of specified line in the specified file.
  • name: The file name to be read, and you need to input the full file name here.
  • lineNum: the specified line to be read.


Delete Content at Specified Line in File

{"T":208,"name":"file.txt","lineNum":3}
  • 208: This command is CMD_DELETE_LINE for deleting the content of specified line in the specified file.
  • name: The file name to be edited, and you need to input the full file name here.
  • lineNum: Specify the line number to be deleted. For example, the lineNum value here is 3, it means the original third line will be deleted and the content of the subsequent lines will shift up by one line.

RoArm-M3-S Tutorial