Skip to content

Commit

Permalink
Merge pull request #4 from blalop/features/3
Browse files Browse the repository at this point in the history
#3 nan checking
  • Loading branch information
blalop authored Oct 22, 2021
2 parents 46e7128 + a3c1016 commit a5b55cf
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 245 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PlatformIO CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v2
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v2
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: WIFI_SSID='\"ssid\"' WIFI_PASS='\"pass\"' ROOM='\"livingroom\"' pio run
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,3 @@ fp-info-cache
# Platform.io
.pio
tmp_*

# Project related
include/config.hpp
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,24 @@ Classic ESP8266-DHT22 schematic with pull-up resistor of 4,7k-10k omhs.
## Schematics

Schematics uses [kicad-ESP8266](https://github.com/jdunmire/kicad-ESP8266) library.


## Deployment

```bash
WIFI_SSID='\"ssid\"' WIFI_PASS='\"pass\"' ROOM='\"livingroom\"' PLATFORMIO_UPLOAD_PORT=192.168.1.2 pio run -t upload -e ota
```

The output metrics look like this:

```
ambiance_build_info{version="1.0.0",gccversion="10.3.0", room="bedroom"} 1
ambiance_temperature{room="bedroom"} 22.00
ambiance_humidity{room="bedroom"} 59.50
```

## Testing

```bash
WIFI_SSID='\"ssid\"' WIFI_PASS='\"pass\"' ROOM='\"livingroom\"' pio run test
```
202 changes: 0 additions & 202 deletions grafana/grafana_dashboard.json

This file was deleted.

15 changes: 15 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

// GCC info
#ifdef __VERSION__
#define GCC_VERSION __VERSION__
#else
#define GCC_VERSION "unknown"
#endif

// Http Server config
#define PORT 80

// DHT config
#define DHTPIN D2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
16 changes: 0 additions & 16 deletions include/config.hpp.sample

This file was deleted.

27 changes: 17 additions & 10 deletions lib/prometheus/prometheus.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "prometheus.hpp"

#include <cmath>
#include <cstdio>

PrometheusExporter::PrometheusExporter(const char *version, const char *prefix)
: version(version), prefix(prefix) {}
PrometheusExporter::PrometheusExporter(const char *version, const char *gcc, const char *prefix,
const char *room)
: version(version), gcc(gcc), prefix(prefix), room(room) {}

const char *PrometheusExporter::buildRoot() {
return "<html>"
Expand All @@ -16,13 +18,18 @@ const char *PrometheusExporter::buildRoot() {
}

const char *PrometheusExporter::buildMetrics(char *buffer, float temperature, float humidity) {
#ifdef __VERSION__
int len = sprintf(buffer, "%s_%s{version=\"%s\",gccversion=\"%s\"} 1\n", prefix,
"build_info", version, __VERSION__);
#else
int len = sprintf(buffer, "%s_%s{version=\"%s\"} 1\n", prefix, "build_info", version);
#endif
len += sprintf(buffer + len, "%s_%s %.2f\n", prefix, "temperature", temperature);
len += sprintf(buffer + len, "%s_%s %.2f\n", prefix, "humidity", humidity);
int len = sprintf(buffer, "%s_%s{version=\"%s\",gccversion=\"%s\",room=\"%s\"} 1\n",
prefix, "build_info", version, gcc, room);

if (!std::isnan(temperature)) {
len += sprintf(buffer + len, "%s_%s{room=\"%s\"} %.2f\n", prefix, "temperature",
room, temperature);
}

if (!std::isnan(humidity)) {
len += sprintf(buffer + len, "%s_%s{room=\"%s\"} %.2f\n", prefix, "humidity", room,
humidity);
}

return buffer;
}
4 changes: 3 additions & 1 deletion lib/prometheus/prometheus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

class PrometheusExporter {
public:
PrometheusExporter(const char *version, const char *prefix);
PrometheusExporter(const char *version, const char *gcc, const char *prefix, const char *room);
const char *buildRoot();
const char *buildMetrics(char *buffer, float temperature, float humidity);

private:
const char *version;
const char *gcc;
const char *prefix;
const char *room;
};
15 changes: 8 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[platformio]
description = Prometheus Exporter for DHT22 sensor
default_envs = debug
default_envs = wire

[env]
platform = espressif8266
Expand All @@ -16,13 +16,14 @@ monitor_filters = default, esp8266_exception_decoder
test_speed = 115200
build_flags =
-Wall
-D RELEASE
-DVERSION=\"1.0.0\"
-DMETRICS_PREFIX=\"ambiance\"
-DWIFI_SSID=${sysenv.WIFI_SSID}
-DWIFI_PASS=${sysenv.WIFI_PASS}
-DROOM=${sysenv.ROOM}

[env:debug]
build_type = debug
build_flags =
-Wall
-D DEBUG
[env:wire]
upload_protocol = esptool

[env:ota]
upload_protocol = espota
Expand Down
Loading

0 comments on commit a5b55cf

Please sign in to comment.