1
0
mirror of https://github.com/daniviga/bite.git synced 2024-11-22 21:16:12 +01:00
Go to file
Daniele Viganò b318c32485
Implement MQTT over WebSocket support (#19)
* Update README.md

* Change default port in EEPROM

* Add more docs

* Implement MQTT over WS

* Update diagrams

* Update README.md and fix travis

* Fix simulator.py

* Fix a warning in .travis.yml

* Sync travis with simulator.py

* Fix serial in EDGE composer
2020-06-21 15:21:00 +02:00
arduino Implement MQTT over WebSocket support (#19) 2020-06-21 15:21:00 +02:00
bite Add testing suite (#18) 2020-06-20 14:41:50 +02:00
docker Implement MQTT over WebSocket support (#19) 2020-06-21 15:21:00 +02:00
docs Implement MQTT over WebSocket support (#19) 2020-06-21 15:21:00 +02:00
.gitignore Implement MQTT ingestion and improve dockerization (#13) 2020-06-15 22:47:55 +02:00
.gitmodules Implement the MQTT protocol (#11) 2020-06-08 23:17:16 +02:00
.travis.yml Implement MQTT over WebSocket support (#19) 2020-06-21 15:21:00 +02:00
LICENSE Initial commit 2020-05-29 14:20:21 +02:00
README.md Implement MQTT over WebSocket support (#19) 2020-06-21 15:21:00 +02:00
requirements-dev.txt Bootstrap Django project 2020-05-29 14:27:38 +02:00
requirements.txt Add static support and health-check (#17) 2020-06-18 19:09:46 +02:00

BITE - Basic/IoT/Example

Playing with IoT

This project is for educational purposes only. It does not implement any authentication and/or encryption protocol, so it is not suitable for real production.

Application Schema

Future implementations

Installation

Requirements

  • docker-ce or moby
  • docker-compose

The project is compatible with Docker for Windows (using Linux executors), but it is advised to directly use a minimal Linux VM instead (via the preferred hypervisor).

The application stack is composed by the following components:

  • Django with Django REST framework web application (running via gunicorn in production mode)
    • mqtt-to-db custom daemon to dump telemetry into the timeseries database
    • telemetry payload is stored as json object (via PostgreSQL JSON data type)
  • Timescale DB, a PostgreSQL database with a timeseries extension
  • Mosquitto MQTT broker (see alternatives below)
  • Nginx as ingress for HTTP (see alternative below)
  • Chrony as NTP server (with optional MD5 encryption)

Deployment

Development

docker-compose -f docker/docker-compose.yml up -d [--scale {bite,mqtt-to-db)=N]

It exposes:

  • http://localhost:80 (HTTP and MQTT over Websockets)
  • tcp://localhost:1883 (MQTT)
  • udp://localhost:123 (NTP)

Django runs with DEBUG = True and SKIP_WHITELIST = True

Development with direct access to services

docker-compose -f docker/docker-compose.yml -f docker-compose.dev.yml up -d [--scale {bite,mqtt-to-db)=N]

It exposes:

  • http://localhost:80 (HTTP and MQTT over Websockets)
  • http://localhost:8080 (Django's runserver)
  • tcp://localhost:1883 (MQTT)
  • tcp://localhost:9001 (MQTT over Websockets)
  • udp://localhost:123 (NTP)
  • tcp://localhost:5432 (PostgreSQL/Timescale)

Django runs with DEBUG = True and SKIP_WHITELIST = True

Production (kind of)

docker-compose -f docker/docker-compose.yml -f docker-compose.prod.yml up -d [--scale {bite,mqtt-to-db)=N]

It exposes:

  • http://localhost:80 (HTTP and MQTT over Websockets)
  • tcp://localhost:1883 (MQTT)
  • udp://localhost:123 (NTP)

Django runs with DEBUG = False and SKIP_WHITELIST = False

Extra features

The project provides multiple modules that can be combined with the fore-mentioned configurations.

Traefik

To use Traefik instead of Nginx use:

docker-compose -f docker/docker-compose.yml up -f docker/ingress/docker-compose.traefik.yml -d

VerneMQ

A ~8x memory usage can be expected compared to Mosquitto.

To use VerneMQ instead of Mosquitto run:

docker-compose -f docker/docker-compose.yml up -f docker/mqtt/docker-compose.vernemq.yml -d

RabbitMQ

RabbitMQ does provide AMQP protocol too, but ingestion on the application side is not implemented yet. A ~10x memory usage can be expected compared to Mosquitto.

To use RabbitMQ (with the MQTT plugin enabled) instead of Mosquitto run:

docker-compose -f docker/docker-compose.yml up -f docker/mqtt/docker-compose.rabbitmq.yml -d

EDGE gateway simulation (via dind)

An EDGE gateway, with containers as modules, may be simulated via dind (docker-in-docker).

Start the EDGE

docker-compose -f docker/docker-compose.yml up -f docker/edge/docker-compose.edge.yml -d

Run the modules inside the EDGE

DOCKER_HOST='127.0.0.1:22375' docker-compose -f docker-compose.modules.yml up -d [--scale {device-http,device-ws,device-mqtt}=N]

Arduino

A simple Arduino UNO sketch is provided in the arduino/tempLightSensor folder. The sketch reads temperature and light from sensors.

Read more ...

Testing

Application tests are part of the Django suite:

python manage.py test

End-to-End tests are performed via Travis-CI. See .travis.yml for further explanations.