Configuration - aleklisi/smart_house_node GitHub Wiki

This section describes how to configure project.

Init Requirements

I recommend to run those in docker containers

  1. Up and running Graphite (https://graphiteapp.org/) with known internet address (IP or routable domain)
  2. Up and running Grafana (https://grafana.com/) configured to display data from Graphite from point 1

Configuration

Graphite connection

Go to priv/sys.config and set host, port(optionallyapi_key) to Graphite you have prepared earlier. Set prefix` to whatever you want to have as first part of metric name.

Configure sensors

Go to priv/config.erl and

Active sensors

Active sensors are the sensors that trigger themselves with give period. Currently supported sensors:

  • cpu_temperature

To add an active sensor go to active_sensors tuple, and in the list of sensors add a tuple {sensor_name, #{repeat_after => 1000}}, where sensor_name is atom the same as module name of you sensor, and second argument is a map with required field repeat_after, where value is time in milliseconds.

Serial paddes data

This is how currently most of the sensors work. Since Raspberry Pi does not support analog read, Arduino is used for this purpose. Arduino program is should read data from sensors and write it to serial port in following format:

{"temp": 123,"hum": 234, ...,"whatever": 0}\n

See this https://create.arduino.cc/editor/aleklisi/46e24f74-904d-4589-aea4-ae4e932535b6/preview as an reference example. Next go to file priv/config.erl and add tuple

{ serial,
  serial_reader,
  #{ open => "/dev/ttyACM0",
     speed => 9600,
     ?PROCESS_GROUP_NAME => serial_based_sensors},
  [
    {exometer_reporter, {temp, serial_based_sensors}},
    {exometer_reporter, {hum, serial_based_sensors}},
    ...
    {exometer_reporter, {whatever, serial_based_sensors}}
  ]
}

where:

  • serial - indicates that it is serial based sensors group,
  • serial_reader - is an atom, module name that implements reading from serial, the implementation is json based, if you need you can replace the implementation for different data format and/or data source (internet, ...),
  • map - map Are params for serial_reader, serial reader requires:
    • open - that takes a string which is device name,
    • speed - is a serial speed,
    • ?PROCESS_GROUP_NAME - is a name of group of processes to which received data is send,
  • repoters - a list of consumers of data send from serial_reader, reporter is a tuple where first element is atom, module name of reporter, and second element is 2 element tuple where first element is an atom which is respective to the measurement from json as given as key, and second element is a reporter process group name.

Notice that you ma have a reporter not receiving data directly form serial reader but also form other sources.

Tested and supported sensors:

  • DHT 11
  • DSM501A
  • MQ-2
  • MQ-3
  • MQ-5
  • MQ-6
  • MQ-7
  • MQ-135