Skip to content

jipp/mqttSensorApp

Repository files navigation

master branch: Build Status Build status

development branch: Build Status Build status

mqttSensorApp

This app is collecting data using different sensors connected via I2C. In addition two pins are used as input switches. The data will be sent using MQTT to a broker and published on a web server running on the chip.

IDE

PlatformIO

Configurataion

Configuration parameters can be changed in the config.hpp file.

WiFi configuraion

If it is not possible to connect to an existing WiFi network during boot an access point will be started to reconfigure the credentials. After a timeout a reboot will take place to try reconnecting with already stored credentials.

MQTT

MQTT can be used either plain or over TLS. Server, port and other parameters can be configured manually using config.hpp.

topic structure

  • publish value: <macAddress w/o ":">/value
  • subscribe to togle switch: <macAddress w/o ":">/switch

eg:

  • 5ccf7f3c88a2/value
  • 5ccf7f3c88a2/switch

value structure

In case you connect different sensors and multiple values are read for the same topic, they will be listed as csv.

{"vcc":[<value in volt>],"illuminance":[<value in lux>],"temperature":[<value in degrees celsius>],"humidity":[<value in %>],"pressure":[<value in hPa>]}

eg: 5ccf7f3c830d/value {"sensorSwitch":[true,true],"illuminance":[],"temperature":[21.05],"humidity":[74.08301],"pressure":[975.1332],"version":"bv1.2.5-30-gcd37613-dirty","millis":43279,"hostname":"test-sensor","switch":true,"memory":15864,"vcc":3.017}

switch message structure

  • '0' switch 'off'
  • '1' switch 'on'
  • 'x' switch/keep for x milliseconds 'on' then 'off' (x > 1ms)

Web Server

A http server is started on a configureable port.

supported Features

  • WiFi configuration started when not connecting to WiFi (running AP running till timeout and restarting)
  • build-in LED shows WiFi status
  • secure WiFi password storage
  • data publishing: MQTT
  • MQTT with or without username/password
  • MQTT data transfer: plain
  • MQTT data transfer: TLS
  • data handling: JSON
  • OTA updates secured with password hash
  • data publishing: HTTP
  • configurable HTTP port
  • act as switch (on/off/timed off - duration in ms)
  • publish state change of switch immediately
  • two sensor connectors for on/off detection

needed additional libraries

  • ArduinoJson
  • AsyncMqttClient
  • Bounce2
  • ESPAsyncTCP
  • WiFiManager

Wemos/Lolin (d1_mini_pro) shields default

  • i2c: SCL (D1), SDA (D2)
  • switch (D5)
  • contact sensor (D6/D7)

security parameter

  • generate md5 hash for ota: echo -n "<password>" | md5sum
  • get fingerprint: echo | openssl s_client -connect localhost:8883 | openssl x509 -fingerprint -noout

mqtt validation

  • subscribe: mosquitto_sub -h localhost -u <username> -P <pssword> -v -t <id>/value
  • publish: mosquitto_pub -h localhost -u <username> -P <pssword> -t <id>/switch -m <message>

About

Sensor App using mqtt as transport protocol based on ESP processor

Resources

License

Stars

Watchers

Forks

Packages

No packages published