Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ logic.html
# JSON
topics.JSON
values.JSON
logic.JSON
logic.JSON

.vscode
.DS_Store
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.21-alpine3.18 as builder
WORKDIR /app
ADD . /app
ADD ./config-docker ./config.go
RUN go mod download
RUN go build -o controller .

FROM alpine:3.18
WORKDIR /app
COPY --from=builder /app/controller /app/
CMD ["/app/controller"]

110 changes: 88 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,112 @@
# OS-EDGEC

## Description

Open Steering edge controller is written in Go Lang, and can be run or built for many operating systems.

A Publish/Subscribe system, where sensors publish data on unique topics to the subscribing edge controller, which in turn publishes control commands to relays, motors, actuators and more.

# System Setup
## System Setup

Edge controller relies on MQTT for telemetry. You may use your MQTT server of choice. We suggest EMQX with username/password, jailed users, and ssl/tls. EMQX is open source and free for on premise installation. Edge controller will also work with many MQTT free to use services online. We do however suggest you run your services on premise.
Edge controller relies on MQTT for telemetry. You may use your MQTT server of choice. We suggest [EMQX](https://www.emqx.io/) with username/password, jailed users, and ssl/tls. [EMQX](https://www.emqx.io/) is open source and free for on premise installation. Edge controller will also work with many MQTT free to use services online. We do however suggest you run your services on premise.

Edge controller also relies on InfluxDB for time based data store.
Edge controller also relies on InfluxDB for time based data store.

Edit config.go to match your mqtt and influxdb server details.
Edit `config.go` to match your mqtt and influxdb server details.

Setup and deploy sensors or control. You can find SDI-12, RS485, and power control examples in our repository. You should configure each sensor mcu with a unique mqtt/device id, and a unique topic or "zone name" for orginizational purposes.
Setup and deploy sensors or control. You can find SDI-12, RS485, and power control examples in our repository. You should configure each sensor mcu with a unique mqtt/device id, and a unique topic or "zone name" for organizational purposes.

Create a ca.pem file in the same directory as your edgec_server.go (or binary)

run or build the edge controller

```bash
go run .
```

```bash
go build
```

## Using Docker

Prerequisites

- Docker [installed](https://docs.docker.com/engine/install/)

### Building

```bash

docker build -t os-edgec:latest .

```

### Running

Please make sure that MQTT and Influxdb variables are set properly in ./config-docker if you running both servers locally.

[Build](#building) service in docker, then run it.

```bash

docker run -p 8081:8081 os-edgec:latest

```

### Running using docker compose

`docker-compose.yml` contains InfluxDB, EMQX and edge controller.

```bash
docker compose build
```

```bash
docker compose up -d
```

### Check logs

```bash

docker compose logs -f controller

```

### Cleaning up

```bash
docker compose down
```

To free up docker rubbish (optional).

```bash
docker system prune
```

```bash
docker image prune -a -f
```

Example of ca.pem:
Example of `ca.pem`:

-----BEGIN CERTIFICATE-----
MIIM9DCCC9wCAQAwXDEVMBMGA1UEAwwMKi5nb29nbGUuY29tMQswCQYDVQQGEwJD
QTEiMCAGA1UECAwZTmV3Zm91bmRsYW5kIGFuZCBMYWJyYWRvcjESMBAGA1UEBwwJ
U3QuIEpvaG5zMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvKILbKB+
9qUzK3Vr98hnG4T4UVZGKh1Q9jkrBOU9M2vDeWTMwQt+Eu9HMUe4E2vj+iBxSDes
6pi6LwlUDWqHBckj/SOzMQblUD3r+cyaP30hONfGxdynJwp25PGTuYUgk9fHm5GA
I9BHhM6f+Uh+tTsQESJgAmGCUJj9FEToM2/CRTRG6SDb8SR3bdOWzlun3S9y35CW
ndZ7R3wY0jgOzYkMnsRp0q+p+FaVmMpPSCUKirZ0GgUi53HtX+dhFNFMSwTJ0OEE
AzvHzRh7hQLf9to7v+fCa5KeNq4QP5GtGH8vTx5RHsoIA82kwDFSVOY01L8xJ99H
b03A/qlcG6diWQIDAQABoIIKUTCCCk0GCSqGSIb3DQEJDjGCCj4wggo6MA4GA1Ud
DwEB/wQEAwIHgDATBgNVHSUEDDAKBggrB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vdWQu
Z29vZ2xlLmNvbYIYKi5jcm93ZHNvdXJjZS5nb29nbGUuY29tghgqLmRhdGFjb21w
zAlloJswHfU=
-----END CERTIFICATE-----
```
21 changes: 21 additions & 0 deletions config-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

/** MQTT Info */

var MQTT_BROKER = "mqtt"
var MQTT_ID = "EdgeC"
var MQTT_USER = ""
var MQTT_PASSWORD = ""
var MQTT_CONFIG = MQTT_USER + "/" + MQTT_ID + "/config"
var MQTT_STATUS = MQTT_USER + "/" + MQTT_ID + "/status"
var MQTT_PORT = 8883

/** InfluxDB Info */
var INFLUX_URL = "http://influxdb:8086"
var INFLUX_TOKEN = "my-super-secret-auth-token"
var INFLUX_ORG = "oss-org"
var INFLUX_BUCKET = "oss-bucket"
var INFLUX_MEASUREMENT = ""

/** Debug Messages */
var DEBUG = true
54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3'
services:
controller:
build: .
ports:
- "8081:8081"
depends_on:
mqtt:
condition: service_started
influxdb:
condition: service_healthy

mqtt:
image: emqx/emqx:5.5.0
ports:
- "1883:1883"
- "8083:8083"
- "8084:8084"
- "8883:8883"
- "18083:18083"
environment:
foo: bar
volumes:
- emqx-data:/opt/emqx/data

influxdb:
image: influxdb:2.0
privileged: true
ports:
- "8086:8086"
environment:
- DOCKER_INFLUXDB_INIT_MODE=setup
- DOCKER_INFLUXDB_INIT_USERNAME=oss-user
- DOCKER_INFLUXDB_INIT_PASSWORD=oss-password
- DOCKER_INFLUXDB_INIT_ORG=oss-org
- DOCKER_INFLUXDB_INIT_BUCKET=oss-bucket
- DOCKER_INFLUXDB_INIT_RETENTION=1w
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-auth-token
volumes:
- influxdb-data:/var/lib/influxdb2
- influxdb-config:/etc/influxdb2
healthcheck:
test: "curl -f http://localhost:8086/ping"
interval: 5s
timeout: 10s
retries: 5

volumes:
emqx-data:
influxdb-data:
influxdb-config: