Skip to content

Implement serial plotter webapp using chart.js #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
134f8ce
Initialize project using Create React App
fstasi Oct 11, 2021
a8ba0aa
first implementation
fstasi Oct 11, 2021
2a9cfec
Apply suggestions from code review
fstasi Oct 19, 2021
ed8527d
css & fonts
fstasi Oct 20, 2021
15ce569
ws connection improvements
fstasi Oct 21, 2021
b79806c
improved communication between components
fstasi Oct 22, 2021
2aac56e
Update public/index.html
fstasi Oct 22, 2021
ae6b859
added bourbon
fstasi Oct 22, 2021
b45a96b
removed prepare script
fstasi Oct 22, 2021
c0c1afa
fixed parsing issue 1
fstasi Oct 22, 2021
256c37c
move dependencies to dev-dependecies
fstasi Oct 25, 2021
11c3975
added action caching to speedup releases
fstasi Oct 25, 2021
8400a7a
remove private flag
fstasi Oct 25, 2021
7550e4a
fixed parsing issues
fstasi Oct 25, 2021
1d572a0
update local EoL and baudrate
fstasi Nov 4, 2021
12051e4
adding switch button
fstasi Nov 8, 2021
7b994a0
improved dataset cleanup & data drop
fstasi Nov 10, 2021
fd56d57
offload message parsing to webworker
fstasi Nov 11, 2021
25ac4ab
add serial port name and connection status
fstasi Nov 11, 2021
b2b5812
scrolling variable names
fstasi Nov 11, 2021
e977fd3
updated to version 0.0.7
fstasi Nov 11, 2021
657741c
title bar status fixes
fstasi Nov 11, 2021
11c7efb
remove old dataset from chart
fstasi Nov 11, 2021
33ed7a5
update to 0.0.8
fstasi Nov 11, 2021
6a9122b
fix license
fstasi Nov 12, 2021
e9c7479
various graphical fixes
fstasi Nov 12, 2021
ec6a368
fix legend ui issues
Nov 15, 2021
db39462
disable UI elements when disconnected + UI fixes to bottom panel
Nov 15, 2021
2b89872
bump version to 0.0.10
Nov 15, 2021
3bc294a
fix message UI when window is small
Nov 16, 2021
ce78707
fix labelling issue
Nov 16, 2021
0922b0c
Bump app version
Nov 16, 2021
59d5f5d
show legend when no data has yet arrived
Nov 17, 2021
a6d7d50
show cursor pointer when hovering a button
Nov 17, 2021
68c0832
bump version to 0.0.12
Nov 17, 2021
5b01199
fix reconnection issues
fstasi Nov 22, 2021
fd1ca36
prevent baudrate from being reset
Nov 23, 2021
6386c13
bump version to 0.0.14
Nov 23, 2021
26b1e3d
clean code
Nov 23, 2021
2456425
bump version to 0.0.15
Nov 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on: push

# push:
# branches:
# - main

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 10
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- run: npm install
# TODO: enable test as soon as they are implemented
# - run: npm test
- run: npm run build
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
File renamed without changes.
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Serial Plotter WebApp

This is a SPA that receives data points over WebSocket and prints graphs. The purpose is to provide a visual and live representation of data printed to the Serial Port.

The application is designed to be as agnostic as possible regarding how and where it runs. For this reason, it accepts different settings when it's launched in order to configure the look&feel and the connection parameters.


## Main Tech/framework used

- React: as the backbone of the application
- Chart.js: to display data
- WebSockets: to provide a fast communication mechanism between a middle layer and the Serial Plotter (see section [How it works](#how-it-works))
- Npm: as the registry

## How it works

- As soon as the application is bootstrapped it reads the [URL parameters](#config-parameters) and uses them to set the initial state and create the WebSocket connection
- When the WebSocket connection is created, data points are collected, parsed, and printed to the chart
- The app can also send messages back to the boards via WebSocket

### Config Parameters

The Serial Plotter Web App is initialized by passing a number of parameters in the URL, in the form of a QueryString (eg: http://localhost:3000?currentBaudrate=2400&baudrates=300,1200,2400,4800,9600,19200,38400,57600,74880,115200,230400,250000,500000,1000000,2000000&darkTheme=true&wsPort=5000&connected=true&interpolate=true&generate=true).

| Name | Description | Type (default) |
|-|-|-|
| `currentBaudrate` | currently selected baudrate | Number(9600)|
| `currentLineEnding` | currently selected line ending | String("\r\n")|
| `baudrates` | populate the baudrates menu | String[]/Comma separated strings ([])|
| `darkTheme` | whether to use the dark version of the plotter | Boolean(false) |
| `wsPort` | websocket port used for communication | Number(3030) |
| `interpolate` | whether to smooth the graph or not | Boolean(false) |
| `serialPort` | name of the serial port the data is coming from | String("") |
| `connected` | whether if the serial port is connected or not| Boolean(false) |
| `generate` | generate fake datapoints to print random charts (dev purposes only)| Boolean(false) |

It is possible to update the state of the serial plotter by sending the above parameters via WebSocket in the form of a JSON-stringified object, using the `MIDDLEWARE_CONFIG_CHANGED` [Command](#websocket-communication-protocol).

### Websocket Communication Protocol

Besides the initial configuration, which is passed in via URL parameters, the communication between the app and the middleware is implemented over WebSocket.

It's possible to send a JSON-stringified message from and to the Serial Plotter App, as long as it adheres to the following format:

```
{
"command": <a valid command, see below>,
"data": <the value for the command>
}
```

The command/data fields follow the specification:

| Command Field | Data field format | Initiator | Description |
|-|-|-|-|
| "PLOTTER_SET_BAUDRATE" | number | Serial Plotter | request the middleware to change the baudrate |
| "PLOTTER_SET_LINE_ENDING" | string | Serial Plotter| request the middleware to change the lineending for the messages sent from the middleware to the board |
| "PLOTTER_SEND_MESSAGE" | text | Serial Plotter | send a message to the middleware. The message will be sent over to the board |
| "PLOTTER_SET_INTERPOLATE" | boolean | Serial Plotter | send the interpolation flag to the Middleware |
| "MIDDLEWARE_CONFIG_CHANGED" | Object (see [config parameters](#config-parameters) ) | Middleware | Send an updated configuration from the middleware to the Serial Plotter. Used to update the state, eg: changing the color theme at runtime |

Example of a message ready to be sent from the Serial Plotter App to the Middleware

```typescript
const websocketMessage = JSON.stringify({command: "PLOTTER_SET_BAUDRATE", data: 9600})
```

**NOTE: For performance sake, the raw data coming from the serial port that is sent by the middleware to the serial plotter has to be a stringified array of values, rather than the Command/Data object**


## Development

- `npm i` to install dependencies
- `npm start` to run the application in development mode @ [http://localhost:3000](http://localhost:3000)

## Deployment

Usually, there is no need to build the app manually: as soon as a new version of the `package.json` is merged into `main` branch, the CI runs and deploys the package to npm.

## Security

If you think you found a vulnerability or other security-related bug in this project, please read our [security policy](https://github.com/arduino/arduino-serial-plotter-webapp/security/policy) and report the bug to our Security Team 🛡️ Thank you!

e-mail contact: security@arduino.cc
Loading