The web UI is built in react and is currently being used to drive the motors via a microcontroller, set the motor speed and show IMU data with an IMU visualizer to show the robot moving in a pipe (currently a cube but a robot model can be added)
esp_web_server_pio is for an esp32 S3 Dev and uses wifi to connect to the server. It is quite slow on some wifi networks.
webserver_teensy_eth is to run the same code as the esp32 but instead for a teensy via ethernet. This should allow for much greater throughput. Code is to be tested (TBT).
Make sure npm is installed globally. Once the repo is cloned cd into S100_Interface/s100_webui/s100_webui/
and do npm install
. This should install vite and all packages that the web UI uses. also install React version 18.3.1
When you clone the repository the npm packages may not clone. Verify the following packages (npm list
)are installed on your device (applies to all OS you are running this code in). If they are not there just do npm install <PACKAGE_NAME>
, the version number doesnt directly matter
- npm
v10.9.0
- vite
v5.4.11
- roslib
v1.4.1
- aedes
v0.51.3
- concurrent
v9.1.2
- eslint
v9.15.0
- globals
v15.12.0
- mqtt
v5.10.3
- three-csg-ts
v3.2.0
- three
v0.171.0
- vite
v5.4.14
- ws
v8.18.0
There are two ways to run the GUI. Running in dev mode and running application tests if you've built a desktop app using concurrently. The instructions below go over both.
Ensure your package.json
includes the necessary scripts for concurrently running multiple processes. It should currently look like this based off my last push:
{
"name": "s100_webui",
"private": true,
"proxy": "http://192.168.2.177",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview",
"start": "concurrently \"node src/mqttBroker.cjs\" \"vite\""
},
"dependencies": {
"aedes": "^0.51.3",
"mqtt": "^5.10.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-switch": "^7.0.0",
"roslib": "^1.4.1",
"three": "^0.171.0",
"three-csg-ts": "^3.2.0",
"ws": "^8.18.0"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"concurrently": "^9.1.2",
"eslint": "^9.13.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"vite": "^5.4.11"
}
}
Note: Adjust the server path as needed based on your project structure.
To run both the React frontend and backend server concurrently:
npm start
This uses Concurrently to run node src/mqttBroker.cjs
and vite
simultaneously.
Alternatively, if you only want to run the Vite development server without the MQTT broker:
npm run dev
Using npm run dev
is only useful if you want to see the layout of the GUI, it will not allow you to connect to the robot properly
Once run, the application will open in your default browser at http://localhost:3000
To create a production build:
-
Build the React application:
npm run build
-
The optimized production files will be created in the
build
folder. -
To serve the production build:
npx serve -s build
Run tests with:
npm test
This will launch the test runner in interactive watch mode. See the testing documentation for more information.
For specific test files:
npm test -- [filename]
-
Using Chrome DevTools:
- Open Chrome DevTools by pressing F12 or right-clicking and selecting "Inspect"
- Navigate to the "Sources" tab
- Find your source files under the "webpack://" section
- Set breakpoints by clicking on line numbers
- Use the Console panel for logging
-
React Developer Tools:
- Install the React Developer Tools extension
- Inspect component hierarchy and state
-
Using VS Code:
- Create a
.vscode/launch.json
file with the following configuration:
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Server", "program": "${workspaceFolder}/../server/server.js", "skipFiles": ["<node_internals>/**"] } ] }
- Set breakpoints in your server code
- Start debugging with F5
- Create a
-
Using nodemon for automatic restarts:
- Install nodemon:
npm install nodemon --save-dev
- Add to your package.json:
"scripts": { "server-dev": "nodemon ../server/server.js" }
Add structured console logs to help with debugging:
// For grouping related logs
console.group('Data Fetching');
console.log('Request URL:', url);
console.log('Request Options:', options);
console.log('Response:', data);
console.groupEnd();
// For timing operations
console.time('Operation');
// ... your code here
console.timeEnd('Operation');
-
Port already in use:
- Change the port in your React application:
Create a
.env
file in the root directory with:PORT=3001
- Change the port in your server:
const PORT = process.env.PORT || 5001;
- Change the port in your React application:
Create a
-
CORS issues:
- Ensure your server has CORS properly configured:
const cors = require('cors'); app.use(cors());
- Ensure your server has CORS properly configured:
-
Node module resolution:
- If you encounter module resolution issues, check your import paths and ensure all dependencies are installed correctly.
The application includes an MQTT broker using aedes
that runs alongside the Vite development server when using the npm start
command. The MQTT broker is defined in src/mqttBroker.cjs
.
To debug MQTT communication:
- Use MQTT Explorer or similar tools to monitor messages
- Add console logging in your MQTT subscription handlers
- Check browser console for connection errors
If you need to modify Vite's configuration:
- Edit the
vite.config.js
file at the root of your project - Restart your development server to apply changes
-
MQTT Connectivity Issues:
- Ensure the MQTT broker is running
- Check that client IDs are unique
- Verify connection parameters in your code
-
CORS issues:
- Remember that the application is proxied to
http://192.168.2.177
as specified in your package.json - For additional CORS settings, modify your Vite configuration
- Remember that the application is proxied to
-
ROS Connection Issues:
- Ensure your ROS environment is properly set up and running
- Check network connectivity between the browser and ROS nodes
- Verify websocket connections are not being blocked
Currently runs on ROS Noetic via ROSBridge. Theretically can run on ROS2 because the topics don't generate unless the bridge is running and all data comes from the react UI.
To run it in ROS do the following
- Create a new workspace which contains this repo
- In that workspace also create a ROSBRIDGE configuration (you may already have a general configuration for this) more on ROSBRIDE here: https://wiki.ros.org/rosbridge_suite
- Start ROS and the ROSBRIDGE
- As long as the GUI is successfully running andf connected to the robot the bridge should also be running, you can do a
rostopic list
to confirm the topics generated from the UI have appeared - Once successful, you now have to option to integrate ROS with the robot such as integrating simulations or creating a rosboard