pgmqtt

module
v0.0.0-...-0c72d35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: Apache-2.0

README ΒΆ

logo

Power-Generator MQTT Simulator

Power-Generator Simulator over MQTT

contributors forks stars open issues license Linkedin

Demo Β· Report Bug Β· Request Feature


πŸ“’ Table of Contents


✨ About the Project

  • Power generators are basically small power-plants. They allow their owners to generate electricity on-site, as a substitute or complement to electricity from the electric grid.

  • pgmqtt is a simulator generates power generators data and publish it over MQTT.

  • Each power generator will write to its own MQTT topic the following tags:

    • Load
    • Power
    • Temperature
    • Fuel Level
    • Base Fuel
    • Used Fuel

  • The message payload of a simulated generator :
{
  "Name": "Generator_1",
  "Lat": -65.37906,
  "Lon": -62.64473,
  "Base Fuel": 909.3602
}
  • The message payload of a generator's tag :
{
  "ItemTopic": "Site/Area/Power-Generators/Generator_8/Load",
  "ItemId": "147377909",
  "ItemName": "Load",
  "ItemValue": 69,
  "ItemOldValue": 71,
  "ItemDataType": "INT",
  "ChangedTimestamp": "2022-07-10T06:42:59+01:00",
  "PreviousTimestamp": "2022-07-10T06:42:54+01:00"
}

πŸ“· Screenshots


Power-Generator MQTT microservice :

screenshot

MQTT Client subscribing to topics published by the microservice

screenshot

πŸ“Ž Using the simulator


Check out a scenario of using the simulator :

  • Docker is the recommended way to use the simulator.

    A Docker image of the simulator is available : docker pull amineamaach/simulators-pgmqtt.

pgmqtt-example

Watch it on YouTube

  1. Clone this repository :
  git clone git@github.com:amine-amaach/simulators.git && cd examples/pgmqtt/
  1. Run πŸƒ
  docker compose up
  • You can configure the pgmqtt simulators through the config files in examples/pgmqtt/configs/ or by using the environment variables in examples/pgmqtt/docker-compose.yml.

    Note : Environment variables in docker-compose.yml will override the corresponding values in config.json if they exist.

    Default topic for all the generators : Site/Area/Power-Generators/#


πŸ’» Development


Make sure you have GO installed (1.18+)

  1. Clone this repository :
  git clone git@github.com:amine-amaach/simulators.git && cd pgmqtt
  1. Run πŸƒ
  go run cmd/pgmqtt/main.go

And Happy Coding


πŸ›£οΈ Roadmap


  • Randomize the delay between messages separately for each generator.
  • Simulate multiple generators in a single microservice.
  • Support TLS connections.

βš™οΈ Configuration


The application is configured using the following environmental variables:

SITE

  • The ISA-95 Model site name. SITE used as the parent topic in the MQTT structure. If this is unset, Site will be used.

AREA

  • The ISA-95 Model area name. AREA used as the second topic in the MQTT structure. If this is unset, Area will be used.

MQTT_SERVER_URL

  • The address of the MQTT server.

MQTT_SERVER_USER

  • The name of the MQTT user with subscribe and publish permissions.

MQTT_SERVER_PWD

  • The password for the MQTT user with subscribe and publish permissions.

MQTT_CLIENT_ID

  • The client id to use when connecting to the broker.

DELAY_BETWEEN_MESSAGES_MIN

  • The minimum delay between messages in seconds.

DELAY_BETWEEN_MESSAGES_MAX

  • The maximum delay between messages in seconds.

RANDOM_DELAY_BETWEEN_MESSAGES

  • If set to true the delay between messages will be randomly generated based on DELAY_BETWEEN_MESSAGES_MIN and DELAY_BETWEEN_MESSAGES_MIN env variables, else DELAY_BETWEEN_MESSAGES_MIN will be set as fixed delay.

GENERATORS_NUMBER

  • The number of generators to simulate.

GENERATORS_NUMBER_LIMIT

  • The maximum number of generators to simulate, if GENERATORS_NUMBER > GENERATORS_NUMBER_LIMIT the number of generators will be set to GENERATORS_NUMBER_LIMIT

🀝 Contact


Amine Amaach - LinkedIn - Email

Project Link: https://github.com/amine-amaach/simulators.git


πŸ‘‹ Contributing


Every bit helps! If you come across any bugs, please send a bug report, or if you feel inclined to fix it yourself, submit a pull request.


πŸ’Ž Acknowledgements & Inspiration


Directories ΒΆ

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL