Skip to content

Commit

Permalink
feat: Introduce Typescript (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
mman authored Oct 15, 2024
1 parent e277d3f commit 44ce7ec
Show file tree
Hide file tree
Showing 14 changed files with 526 additions and 321 deletions.
103 changes: 58 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,15 @@ Venus Influx Loader is distributed as:
- NPM module: https://www.npmjs.com/package/venus-influx-loader
- Docker Image: https://hub.docker.com/r/victronenergy/venus-influx-loader

## Development

To start experimenting, please install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and use the following steps to spin up a quick dev environment:

### Build Venus Influx Loader docker image locally

```
$ export OWNER="martin"
$ (cd docker && ./build-dev-image.sh)
```

### Run InfluxDB docker image instance locally

```
$ (cd docker && ./run-influxdb.sh)
```

### Run Venus Influx Loader docker image locally

```
$ export OWNER="martin"
$ (cd docker && ./run-dev-image.sh)
```

Navigate to http://localhost:8088 to access Venus Influx Loader Admin UI, use `admin`, `admin` to sign in, and configure what Venus devices to watch.

Install Venus Grafana by following the instructions here: https://github.com/victronenergy/venus-grafana.


## Source Code Details

The repository is spit into the following components:

## Server

The directory `src/server` contains node.js based server watching Venus devices using MQTT and storing real time measurements into InfluxDB. It vends two binaries: `bin/venus-influx-loader`, and `bin/venus-upnp-browser`.
## Advanced Configuration

### Venus Influx Loader

Venus Influx Loader allows MQTT connection to the Venus devices running on the same network and discovered via UPNP, configured manually using their IP address, or by accessing them via VRM.

Configuration details and necessary usernames and passwords are stored in `config.json`, and `secrets.json` that are looked up under `--config-path` (`/config` by default). Config Path needs to be writable.

> TODO: should not be needed to config path to be writable in production deployments.
> TODO: should not be needed for config path to be writable in production deployments.
Configuration files can either be created manually, or by starting the Venus Influx Loader, and accessing the Admin UI by browsing to `http://localhost:8088`. The default usernname and password is `admin`, `admin`.

Expand All @@ -94,15 +59,25 @@ Options:
-h, --help display help for command
```

#### Tip: Run Influx Loader headless

For production use, once the system is configured `--disable-admin-api` can be used to run the `venus-influx-loader` headless.

#### Tip: Run Influx Loader behind Load Balancer with your own authentication

Use `--disable-admin-api-auth` to skip basic authentication mechanism protecting access to Admin Web User Interface. That way you can implement your own authentication mechanism.

#### Tip: Customize Admin UI

Use `--hide-settings-*` options to tweak the Admin UI and hide parts of the settings that you do not want to accidentally change. For example InfluxDB settings do not need to be overriden once configured.

### Venus UPNP Browser

Venus Influx Loader contains built in mechanism to discover Venus devices running on the same network via UPNP, that is enabled by default.

In cases where `venus-influx-loader` may not have access to local network UPNP, such as when it runs in isolated docker network, or in docker bridge mode, `venus-upnp-browser` can be used to discover Venus devices over UPNP.

The reason behind spliting these two functionalities among two binaries is:
The reason behind spliting the UPNP discovery into separate binary is:

- ~~Docker container running in host networking mode can not expose ports under Docker Desktop for Mac and Windows (https://github.com/docker/for-mac/issues/6185). So `venus-influx-loader` running in `host` networking mode can access UPNP, but will not get access to port `8088` to enable Admin UI.~~
- Docker Desktop since version 4.29 (https://docs.docker.com/network/drivers/host/#docker-desktop) allows to experimentally enable host networking mode in which a container running in host network mode can actually expose UDP/TCP ports and gain access to the host network.
Expand All @@ -111,7 +86,7 @@ The reason behind spliting these two functionalities among two binaries is:

To workaround the limitations, `venus-upnp-browser` actually runs in docker host mode network - having access to both local area UPNP, as well as `venus-influx-loader` admin port exposed via docker, `venus-upnp-browser` communicates discovered Venus devices and diagnostic information to `venus-influx-loader` via `--discovery-api`.

Note: `host` and `bridge` network mode work properly only on Linux. UPNP does not work in Docker Desktop for Mac at all.
Note: `host` and `bridge` network mode work properly only on Linux, support is being added to Docker Desktop for Windows and Mac incrementally. UPNP does not work in Docker Desktop for Mac at all.

```
€ npx venus-upnp-browser --help
Expand All @@ -125,28 +100,66 @@ Options:
-h, --help display help for command
```

## Development

To start experimenting, please install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and use the following steps to spin up a quick dev environment:

### Build Venus Influx Loader docker image locally

```
$ export OWNER="martin"
$ (cd docker && ./build-dev-image.sh)
```

### Run InfluxDB docker image instance locally

```
$ (cd docker && ./run-influxdb.sh)
```

### Run Venus Influx Loader docker image locally

```
$ export OWNER="martin"
$ (cd docker && ./run-dev-image.sh)
```

Navigate to http://localhost:8088 to access Venus Influx Loader Admin UI, use `admin`, `admin` to sign in, and configure what Venus devices to watch.

Install Venus Grafana by following the instructions here: https://github.com/victronenergy/venus-grafana.


## Source Code Details

The repository is spit into the following components:

## Server

The directory `src/bin`, and `src/server` contains node.js based server watching Venus devices using MQTT and storing real time measurements into InfluxDB. It vends two binaries: `venus-influx-loader`, and `venus-upnp-browser`.

Server is written in TypeScript/JavaScript and compiled using `tsc`.

### Venus Influx Loader Admin UI

The directory `src/client` contains react.js based web admin interface to manage configuration of `src/server`. Client Admin UI app uses `webpack` to compile the browser JavaScript, HTML, and CSS code.
The directory `src/client` contains react.js based web admin interface to manage configuration of `src/server`. Influx Loader Admin UI app uses `webpack` to compile the browser JavaScript, HTML, and CSS code.

## Development

### Start venus-influx-loader, and client in hot reloading mode

First install all required dependencies:

```
$ npm install
$ npm run dev
```

This command will use [`concurrently`](https://www.npmjs.com/package/concurrently) command to start hot reloading development instances of both the `src/server`, and `src/client`, so whenever you change source code in `src/` everything should get restarted/reloaded automatically.

Alternatively you can spin up only hot reloading server, or only hot reloading client via:
Then spin up hot reloading Influx Loader:

```
$ npm run watch-influx-loader
```

and
and Influx Loader Admin UI:

```
$ npm run watch-client
Expand Down
6 changes: 4 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"presets": [
["@babel/preset-react", { "runtime": "automatic" }], ["@babel/preset-env"]
],
["@babel/preset-react", { "runtime": "automatic" }],
["@babel/preset-env"],
["@babel/preset-typescript"]
]
}
101 changes: 0 additions & 101 deletions bin/venus-influx-loader.js

This file was deleted.

101 changes: 0 additions & 101 deletions bin/venus-upnp-browser.js

This file was deleted.

6 changes: 2 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ RUN apt-get update && apt-get install -y curl

WORKDIR /venus-influx-loader

COPY --from=build /venus-influx-loader/bin ./bin
COPY --from=build /venus-influx-loader/dist ./dist
COPY --from=build /venus-influx-loader/src/server ./src/server
COPY --from=build /venus-influx-loader/package*.json ./
COPY --from=build /venus-influx-loader/dist/* ./

RUN npm install --omit=dev
RUN npm install --omit=dev --ignore-scripts

USER root
RUN mkdir -p /config && chown -R node /config
Expand Down
Loading

0 comments on commit 44ce7ec

Please sign in to comment.