第 9 節

Other operations

0瀏覽次數0訪問次數--跳出率--平均停留

How to connect the industrial computer to Wi-Fi

When our industrial computer moves from one environment to another, and we haven't connected to the Wi-Fi in the new environment, how can we get the industrial computer online without a screen?

Navigate to the hard drive directory of the industrial computer, enter /etc/netplan/, where there are many yaml files. Find the one that best matches the format below:

network: 
  version: 2 
  wifis: 
    NM-6f414fe0-2658-48ff-89ee-c7981b87bc96: 
      renderer: NetworkManager 
      match: 
        name: "wlan0" 
      dhcp4: true 
      dhcp6: true 
      access-points: 
        "EMIS_Vinci_Robocon_5G": 
          auth: 
            key-management: "psk" 
            password: "vinci666" 
          networkmanager: 
            uuid: "6f414fe0-2658-48ff-89ee-c7981b87bc96" 
            name: "EMIS_Vinci_Robocon_5G" 
            passthrough: 
              wifi-security.auth-alg: "open" 
              ipv6.addr-gen-mode: "default" 
              ipv6.ip6-privacy: "-1" 
              proxy._: "" 
      networkmanager: 
        uuid: "6f414fe0-2658-48ff-89ee-c7981b87bc96" 
        name: "EMIS_Vinci_Robocon_5G"

Change it to the new Wi-Fi name and password:

network:
  version: 2
  wifis:
    wlan0:
      dhcp4: true
      dhcp6: true
      access-points:
        "EMIS_Vinci_Robocon_5G":
          password: "vinci666"

The industrial computer connects to the internet as soon as it boots up.

SSH remote development

Environment Setup

1. Hardware Preparation

First, you need an industrial computer (X86 small computer, professional industrial computer, Raspberry Pi, etc.).

The hardware carriers of control systems are diverse, with commonly used processors based on architectures such as ARM and x86, for example: PCs, industrial PCs, Raspberry Pi, NVIDIA Jetson, and so on. Different processors have their own advantages and disadvantages. PCs and industrial PCs offer powerful processing performance but come with high power consumption, large size, and poor flexibility, while embedded systems are the opposite. For us, we can autonomously select an appropriate control system based on various factors of the robot platform, such as electrical requirements, load capacity, space, and intended use.

Regardless of which processor is chosen, as long as Robot Operating System (ROS) or ROS2 is installed for robot development, there is no fundamental difference in usage for developers. In other words, as a software engineer, in some scenarios, there is no need to focus on hardware selection.

2. Setting a Static IP

When connecting remotely, regardless of the tool used, you need to locate the target host by its IP address and then log in using an account and password. Therefore, we first need to obtain that IP address. Since the IP is required for every connection, to ensure convenience and stability, it is best to set the target host's IP address as a static IP. The specific steps are as follows.

  1. Enter the settings interface

Start the connected host machine (a monitor or HDMI capture card is required during startup; after configuring SSH remote access, the monitor or HDMI capture card is no longer needed), and enter the settings interface.

  1. Configure the connected network

  1. Set a Static IP

Check the current IP address.

Set a static IP.

At this point, the IP configuration is complete.

Environment Setup

Concept

SSH (Secure Shell) is a versatile, powerful, software-based network security solution. Every time a computer sends data over the network, SSH automatically encrypts it. When the data reaches its destination, SSH automatically decrypts the encrypted data. The entire process is transparent, and using OpenSSH tools will enhance your system's security. SSH is easy to install and simple to use.

Implementation

The SSH implementation architecture is divided into two main parts: the client and the server. The client is the sender of data, and the server is the receiver. In this scenario, we need to send data from the local host to the remote host. Therefore, the local host needs to install and start an SSH client, while the remote host needs to install and start an SSH server. The specific implementation process is as follows:

  1. Install the SSH client on the local host and the SSH server on the remote host.
  2. Start the SSH service on the remote host.
  3. Log into a remote host from a local machine.
  4. Implement data transmission.
  5. Install SSH client and server

By default, the Ubuntu system already has the SSH client installed, so you only need to install the SSH server on the remote host. The installation command is as follows:

 sudo apt install openssh-server

If the SSH client needs to be installed manually, run the following command:

sudo apt install openssh-client
  1. Start the SSH service on the remote host

The command to start the SSH service on a remote host is as follows:

sudo /etc/init.d/ssh start

After starting, you can use the following command to check whether the service is running properly:

ps -e | grep ssh

If startup is successful, it will include the sshd program.

If you need to frequently use SSH for remote login, to simplify the process, you can configure the SSH service on the remote host to start automatically at boot. The command is as follows:

sudo systemctl enable ssh
  1. Local Remote Login

To log into a remote host, you can use the following command:

ssh -X 用户名@ip地址

Then, follow the prompt to enter the login password, and you will be successfully logged in.

If you want to exit, you can call the exit command:

exit

4. Implementing Data Transmission

By using SSH on the local host, you can easily upload or download data to and from a remote host by simply calling the relevant commands. The command format is as follows:

The format for the file upload command is as follows:

scp 本地文件路径 账号@ip:路径

The command format for uploading a folder is as follows:

scp -r 本地文件夹路径 账号@ip:路径

The download file command format is as follows:

scp 账号@ip:路径 本地文件夹路径

The download folder command format is as follows:

scp -r 账号@ip:路径 本地文件夹路径

Optimization

Every time you log in remotely, you need to enter a password, which is inconvenient. You can use SSH keys to simplify the login process, enabling passwordless login and improving operational efficiency. The idea is to generate a pair of public and private keys: the private key is stored locally, and the public key is uploaded to the server. Each time you log in, the local machine sends the private key to the server. If the server has a matching public key, it recognizes you as a legitimate user and establishes an SSH connection directly. The implementation involves only two steps:

  1. Generate a local key pair.
  2. Upload the public key to the remote host.

1. Generate a key pair

Local client generates public and private keys: (just press Enter all the way to accept defaults)

ssh-keygen

The command above will create a public-private key pair in the .ssh folder under the user's home directory.

  1. id_rsa (private key);
  2. id_rsa.pub (public key).

2. Uploading the Public Key

The upload instructions are as follows:

ssh-copy-id -i ~/.ssh/id_rsa.pub 账号@ip

The instruction above is to upload the local public key to the ssh directory on the remote host. This directory contains the file authorized_keys, which stores the public key content.

From now on, you won't need to enter a password for remote logins.

Optimizing with VSCode

In the previous section, we introduced the use of SSH remote connections. However, using SSH alone has some limitations. For example, editing file content requires the vi editor, and within a single terminal, you cannot edit multiple files simultaneously. This section will introduce a more practical feature — remote development using VSCode combined with plugins. This allows us to perform remote development in a graphical way, making it more convenient and faster than using SSH alone, and can greatly improve program development efficiency.

1. Preparation

VScode remote development relies on SSH. Please first configure the SSH remote connection according to the previous section.

2. Install the Remote Development Plugin for VSCode

Launch VScode, first click the Extensions button in the sidebar, then type Remote Development into the search bar of 扩展:商店 and click the plugin with the same name, and finally click 安装 in the display area on the right.

3. Configure Remote Connection

Step 1: Use the shortcut ctrl + shift + p to open the command input window, then enter Remote-SSH:Connect to Host.... From the pop-up list, select the option with the same name.

Step 2: After Step 1 is completed, a new command window will pop up as shown below. Select Add New SSH Host from the dropdown list.

Step 3: After completing step 2, a new command window will pop up. In it, enter: ssh -X ubuntu@192.168.43.164, where ubuntu needs to be replaced with your login username, and 192.18.43.164 should be replaced with the IP address of the remote host you are connecting to.

Step 4: Select the first option in the pop-up list after completing Step 3 (or simply press Enter) to finish the configuration. A confirmation message will appear once the configuration is successful.

4. Usage

Step 1: Continue using the shortcut ctrl + shift + p to open the command input window, and enter Remote-SSH:Connect to Host.... The list will then display the IP address configured in step 3. Select it directly, and after selection, VScode will open a new window.

Alternatively, you can click 远程资源管理器 in the sidebar, select the server you want to connect to from the pop-up server list, right-click it, and choose to establish a remote connection in the current window or a new window.

Step 2: Select 打开文件夹 under the 文件 menu bar, choose the folder you want to open from the pop-up list, and click OK.

Finally, we can achieve remote development just like working with local files.

Remote Desktop

Because X11 forwarding is far too inefficient, it's necessary to use remote desktop access to view Rviz2, Gazebo, and similar tools (if needed).

We choose to use VNC to view it.

  1. Install the VNC server:

Here, TigerVNC is used as an example for installation:

sudo apt install tigervnc-standalone-server tigervnc-common
  1. Set VNC password:

To set a password for the VNC user, run the following command:

vncpasswd
  1. Configure the VNC startup script:

Create a VNC configuration file and create a startup file in the .vnc folder within the user's home directory:

mkdir -p ~/.vnc
nano ~/.vnc/xstartup

In the opened editor, enter the following content (using GNOME as an example):

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
gnome-session

Save and exit (in nano, press Ctrl + O to save, then press Ctrl + X to exit).

  1. Grant execute permission:

Set execute permission for the xstartup file:

chmod +x ~/.vnc/xstartup
  1. Start the VNC server:
vncserver -geometry 1920x1080 -localhost=0

The geometry option specifies the window size, and the localhost option is set to 0 to allow external connections. (Setting it to 1 only allows local connections.)

You will see output similar to :1, which indicates the display number of the VNC session. For example, if the output is :1, the VNC listening port is 5901 (5900 + display number).

  1. Check the enabled VNC servers:
vncserver -list

  1. Connect to the VNC server:

Use a VNC client (such as vncviewer) to connect to the VNC server by entering your server's IP address and port. For example, if the server IP is 192.168.31.10 and the display number is 1, you should connect to 192.168.31.10:1, or simply enter 192.168.31.10:5901.

  1. Stop the VNC server:

If you need to stop the VNC server, you can use the following command:

vncserver -kill :1

Replace :1 with the actual display number you are using.

USB port settings

First, configure the permissions.


# 将用户权限提高
sudo usermod -aG dialout $USER
newgrp dialout

# 查看下面命令是否输出dialout(若输出才正常)
groups

Because we plug and unplug USB devices, their port numbers may keep changing, so we need to assign a fixed alias to their tty.

Bind USB devices by port (multiple different devices)

Requirement: A radar and a smart car are now connected to the Ubuntu system. Please bind ports for both.

Implementation Principle: Port binding can be achieved through the "identifier" of the USB device itself.

The process is as follows:

(1). Find the device idVendor and idProduct

Connect two USB devices, and in the terminal run the command lsusb to view the USB device information in the system as well as the devices connected to it.

As shown in the image above, the data inside the red box represents USB devices. The values following the ID 1a86:7523 are the USB idVendor and idProduct respectively (the two parameters are separated by a colon).

Additionally: You can determine which data corresponds to the connected USB device by comparing results after re-plugging.

(2). Write mapping rules

Create a new file named xxx.rules (customize the filename) in the /etc/udev/rules.d directory.

sudo vim /etc/udev/rules.d/xxx.rules

I'd be happy to help, but it looks like you didn't include the content you want me to translate. Could you please provide the Simplified Chinese Markdown fragment you'd like me to translate into natural American English?

KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0777", SYMLINK+="mylidar"
KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777", SYMLINK+="mycar"

Code Explanation

  • KERNEL is a fixed kernel name, which here is uniformly "ttyUSB*".
  • MODE is a node permission, typically set to "0777", indicating read, write, and execute permissions.
  • A SYMLINK is a symbolic link, which is an alias for a binding.
  • ATTRS is the unique identifier for the device manufacturer, and idVendor together with idProduct form the device ID found via lsusb above.

Tip: Most USB device vendors provide similar script files. For the caller, simply copy the file to the /etc/udev/rule.d directory.

Device TypeKernel name exampleExplanation
USB serial devicettyUSB*USB to serial device, such as /dev/ttyUSB0
Serial port devicettyS*Physical serial port device, such as /dev/ttyS0
Storage devicesd*SCSI disk device, such as /dev/sda
Network deviceeth*Ethernet device, such as /dev/eth0
Input deviceevent*Input event device, such as /dev/input/event0
Bluetooth devicerfcomm*Bluetooth serial device, such as /dev/rfcomm0

(3). Apply the rules.

Enter the following command in the terminal:


# Ubuntu用下方命令
sudo service udev reload
sudo service udev restart

#Fedora用下方命令
sudo udevadm control --reload
sudo udevadm trigger

Simply re-plug the device.

(4). Test

Enter the following command in the terminal:

ll /dev | grep ttyUSB

The execution result is as follows:

You can also plug and unplug the USB device multiple times. You'll notice that the number n in the device port ttyUSBn changes, but the alias always points to the corresponding USB device. At this point, you can use the alias to associate the USB device you need.

Disadvantages:

The above implementation also has certain limitations. When Ubuntu is connected to two or more USB devices of the same model, since the device IDs are identical, this implementation will only take effect for one of them. In such cases, the second strategy is needed to achieve port binding.

Bind ports based on host hardware (multiple identical devices)

Requirement: Two identical radar units are now connected to the unmanned vehicle, one at the front and one at the rear. Please bind ports for both.

Implementation Principle: The USB interface of the host to which a USB device is connected also has its own "identifier," which can be used to implement port binding.

The process is as follows:

(1). Check the KERNELS of the USB interface on the connected host.

Run the following command to view the USB information of the first radar:

udevadm info --attribute-walk --name=/dev/ttyUSB0 | grep KERNELS
udevadm info --attribute-walk --name=/dev/ttyACM0 | grep KERNELS

Run the following command to view the USB information of the second LiDAR:

udevadm info --attribute-walk --name=/dev/ttyUSB1 | grep KERNELS

Comparing the results across different KERNELS, the first radar port address is KERNELS==1-1.3:1.0, and the second radar port address is KERNELS==1-1.4:1.0. This data can be used as a "unique identifier" for different ports.

(2). Write mapping rules

In the /etc/udev/rules.d directory, create a new file named xxx.rules (customize the filename) and enter the following content:

sudo vim /etc/udev/rules.d/xxx.rules
KERNEL=="ttyUSB*", KERNELS=="1-1.3:1.0", MODE:="0777", SYMLINK+="rplidar_front"
KERNEL=="ttyUSB*", KERNELS=="1-1.4:1.0", MODE:="0777", SYMLINK+="rplidar_back"

(3). Apply the rules.

Enter the following command in the terminal:


# Ubuntu用下方命令
sudo service udev reload
sudo service udev restart

#Fedora用下方命令
sudo udevadm control --reload
sudo udevadm trigger

Simply re-plug the device.

(4). Test

Enter the following command in the terminal, and the output will be as follows:

ll /dev | grep ttyUSB

At this point, you can use an alias to associate the USB device you need.

Drawbacks: USB devices must be connected to the host's designated ports; otherwise, port binding may fail or logic errors may occur. (Additionally, adding new devices may cause port changes.)

Bind ports based on other attributes

(1). View the information about the USB ports on the connected host.

udevadm info -a -p $(udevadm info -q path -n /dev/ttyACM0)
udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)

These data will not change, so they can be used as identifiers.

(2). Write mapping rules

In the /etc/udev/rules.d directory, create a new file named xxx.rules (customize the filename) and enter the following content:

sudo vim /etc/udev/rules.d/xxx.rules
KERNEL=="ttyACM*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55d4", ATTRS{serial}=="0001", MODE:="0777", SYMLINK+="ttyACM_Lidar"
KERNEL=="ttyACM*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55d4", ATTRS{serial}=="0002", MODE:="0777", SYMLINK+="ttyACM_MCU"
KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777", SYMLINK+="ttyUSB_IMU"

(3). Apply the rules.

Enter the following command in the terminal:


# Ubuntu用下方命令
sudo service udev reload
sudo service udev restart

#Fedora用下方命令
sudo udevadm control --reload
sudo udevadm trigger

Simply reconnect the device, or restart the system directly.

(4). Test

In the terminal, enter the following command: ll /dev|Run grep ttyUSB, the result is as follows:

At this point, you can use an alias to associate the USB device you need.

Drawbacks: Some devices may not have a serial port number, etc.

Other Precautions

Not all USB device port numbers follow the ttyUSBn format. For example, an Arduino's port number might be ttyACMn, and for a USB camera, a single device corresponds to two port numbers: videon and video(n+1). Typically, the videon port is used to enable the camera device, and that is also the interface that needs to be associated when binding.

However, regardless of which USB device is connected externally, and no matter which of the two methods mentioned above is used for port binding, the underlying principle is similar — only the implementation details differ. If an external Arduino device is connected, then in the rules file, KERNEL=="ttyUSB*" should be changed to KERNEL=="ttyACM*". If a USB camera is connected externally, then in the rules file, KERNEL=="ttyUSB*" should be changed to a format similar to KERNEL=="video[0,2,4,6]", where video[0,2,4,6] indicates that the bindable ports are video0 or video2 or video4 or video6.

Linux Partition GUI Tool

sudo apt install gparted
sudo dnf install gparted

Mount the intranet webpage

You can mount local web pages on the router, or on other devices within the same local network segment, and even mount them locally.

Below, using an Android device as an example: since Android devices cannot directly open HTML files for now, we can host the HTML on a local server and then view it through a browser.

Since the Android system is based on the Linux kernel, we can download an app called Termux to run some Linux commands:

https://github.com/termux/termux-app

First, after opening the app, update the software cache:

pkg update

Then change the source.

nano $PREFIX/etc/apt/sources.list

Replace the content of this file with the following:

deb https://mirrors.bfsu.edu.cn/termux/termux-packages-24 stable main
  • If you are using the nano editor:
    • Save the file as Ctrl+O.
    • Confirm the filename according to Enter.
    • Press Ctrl+X to exit the editor.
  • If you are using the vim editor:
    • Press Esc to exit edit mode.
    • Press :wq to save and exit.

Next, update the software sources again:

pkg update && pkg upgrade

Install Python

pkg install python3

Accessing Device Storage via Termux

If the file is on an Android device, you can use Termux's file manager to access the device's storage:

termux-setup-storage
  1. Navigate to the directory containing the HTML file:
    1. Use the cd command to enter the directory where the HTML file is located:
cd ~/your_html_folder
  1. Start Python HTTP Server
    1. Run the following command to start a simple HTTP server:
    python3 -m http.server 8000
    
    1. This will start a web server on port 8000.
  • After starting the server, Termux will display log information, for example:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
  • This indicates the server has started successfully.

Accessing an HTML file in a browser

  1. Accessing on the same device :
    1. Open the browser on your Android device (such as Chrome) and enter the following address:
    http://localhost:8000
    
    1. If the HTML file contains index.html, it will load automatically; otherwise, you need to manually click the file link.

RustDesk

RustDesk unattended remote control

Currently, RustDesk cannot perform unattended operations under Wayland, so we need to disable login passwords, screen lock, and sleep/standby entirely.

Set up KDE6 automatic login
  1. You can first check your SDDM type.
ls /usr/share/xsessions/
ls /usr/share/wayland-sessions/

Check which one outputs content; the folder that outputs content is the SDDM you have. For example, if xsessions outputs content, then it's the X11 SDDM. If wayland-sessions outputs content, then you have the Wayland SDDM.

  1. Edit the SDDM configuration:
sudo nano /etc/sddm.conf

At the very top of the file, there is a section called Autologin. Add the following content underneath it:

[Autologin]
User=你的用户名
Session=plasma.desktop   # 或 plasma.desktop(X11),方案一可用 Wayland
  1. Save and exit, then restart SDDM:
sudo systemctl restart sddm

✅ Automatically logs into the desktop after startup, no password required.

To disable the lock screen in KDE6 system settings:

Open System Settings → Screen Locking. Disable auto-lock Turn off the screen / Screen saver lock This way, RustDesk can directly control the desktop after booting, without being blocked by the lock screen.

Disable sleep system settings → Power Management

Disable "Sleep" or "Auto-Suspend" Ensure the computer stays online at all times, so RustDesk can be remotely controlled at any time. If you must use hibernation, you can disable it in the BIOS settings to ensure the device connects to the network immediately upon startup.

RustDesk self-hosted server

Install on the server side
Command line method
  1. Open the official website: https://rustdesk.com/docs/zh-cn/self-host/

alt text

  1. To access the server where you need to install RustDesk via SSH.
ssh tungchiahui@10.0.0.4

alt text

  1. Use the command from method two.

alt text

wget https://raw.githubusercontent.com/techahold/rustdeskinstall/master/install.sh
chmod +x install.sh
./install.sh

See the next section for the ./install.sh setup.

  1. Configuring and Viewing the KEY

Here, if you want to directly use a public IP, select 1)IP; if you are using DDNS or similar to bind a domain name to an IP address, select 2).

alt text

This selects 2)No.

alt text

Copy this KEY down, as you'll need it later during software configuration.

alt text

  1. Configure the firewall
    1. If you are a Debian-based system Install the firewall
    sudo apt install ufw
    

Configure the firewall ```bash sudo ufw allow 22

ufw allow 21114:21119/tcp
ufw allow 21116/udp
sudo ufw enable
```
2. If you are using a RHEL-based system

Install the firewall bash # 如果你是RHEL系 sudo dnf install firewalld sudo systemctl enable --now firewalld

Configure the firewall ```bash sudo firewall-cmd --add-port=22/tcp --permanent sudo firewall-cmd --reload

sudo firewall-cmd --add-port=21114-21119/tcp --permanent
sudo firewall-cmd --reload

sudo firewall-cmd --add-port=21116/udp --permanent
sudo firewall-cmd --reload

sudo systemctl enable --now firewalld
```
1Panel method
  1. Search for RustDesk in the panel and install it.

alt text

  1. Configure the firewall

alt text

Add a few ports. alt textalt textalt text

  1. View KEY alt text

Copy KEY

alt text

After setting up your own server, configure the RustDesk software.
  1. PC side

alt text

alt text

If "Ready" appears, the configuration is successful. alt text

  1. Mobile

alt text

alt text

Points to note

If you are using a home internal network server, you also need to configure the router to allow the corresponding ports.

Find the OpenWrt firewall settings and click Add. alt text

alt text

alt text

Only then can your server port be truly and successfully unblocked.

音乐页