mirror of
https://github.com/revspace/operame
synced 2024-10-31 21:47:30 +00:00
Merge 5bd075e078
into b84a6d8b19
This commit is contained in:
commit
ece4847ffb
BIN
Control CO2 Logo V1 240_135.png
Normal file
BIN
Control CO2 Logo V1 240_135.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
BIN
Control CO2 Logo V2 240_135.png
Normal file
BIN
Control CO2 Logo V2 240_135.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.1 KiB |
34
README.md
34
README.md
@ -1,6 +1,6 @@
|
|||||||
# Operame
|
# Operame
|
||||||
|
|
||||||
Dit is de broncode van de firmware voor de [Operame CO2-meter](https://operame.nl/).
|
Dit is de broncode van de firmware voor de [ControlCO2-meter](https://controlco2.space), operame project origineel gestart door RevSpace.
|
||||||
|
|
||||||
## Language
|
## Language
|
||||||
|
|
||||||
@ -16,4 +16,34 @@ Deze repository gebruikt [PlatformIO](https://platformio.org/) voor installatie.
|
|||||||
|
|
||||||
1. Installeer PlatformIO.
|
1. Installeer PlatformIO.
|
||||||
2. Kloon deze repository lokaal.
|
2. Kloon deze repository lokaal.
|
||||||
3. Ga naar de map van deze repository en voer `pio run` uit.
|
3. Ga in de commandline of terminal naar de map van deze repository en voer `pio run` uit.
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
Indien het bord niet gevonden wordt, controleer of je de cp210x USB TO UART drivers van silicon labs hebt geinstalleerd.
|
||||||
|
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
|
||||||
|
|
||||||
|
## Ervaring van een windows 10 gebruiker
|
||||||
|
-windows 10 systeem
|
||||||
|
|
||||||
|
-visual studio code installeren
|
||||||
|
|
||||||
|
-platformio 2.3.2 extensie geinstalleerd (issue met 2.3.3) in VS code.
|
||||||
|
|
||||||
|
-python 3.9 geinstalleerd, zorg dat add to path aangevinkt is
|
||||||
|
|
||||||
|
-git installeren om repository te clonen
|
||||||
|
|
||||||
|
-bordje connecteren en in devices checken of driver er is anders cp210x driver van silicon lans installeren.
|
||||||
|
|
||||||
|
-dan in platformio.ini upload_port en flags commenten. zoek port dan automatisch
|
||||||
|
|
||||||
|
## 4MB or 16MB
|
||||||
|
|
||||||
|
board = esp32thing
|
||||||
|
board_build.partitions = default.csv
|
||||||
|
|
||||||
|
If you have a 16MB TTGO T-Display board, you can change the env settings in the platformio.ini file.
|
||||||
|
board = esp32thing_plus
|
||||||
|
board_build.partitions = default_16MB.csv
|
||||||
|
|
||||||
|
249
operame.ino
249
operame.ino
@ -1,25 +1,44 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
#include <MQTT.h>
|
#include <MQTT.h>
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#include <WiFiSettings.h>
|
#include <WiFiSettings.h>
|
||||||
#include <MHZ19.h>
|
#include <MHZ19.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <TFT_eSPI.h>
|
#include <TFT_eSPI.h>
|
||||||
#include <logo.h>
|
#include <logo.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <operame_strings.h>
|
#include <operame_strings.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
//#include <DHT_U.h>
|
||||||
|
#include "Stream.h"
|
||||||
|
|
||||||
|
|
||||||
#define LANGUAGE "nl"
|
#define LANGUAGE "nl"
|
||||||
|
|
||||||
|
#define DHTPIN 15 // Digital pin connected to the DHT sensor
|
||||||
|
// Uncomment the type of sensor in use:
|
||||||
|
//#define DHTTYPE DHT11 // DHT 11
|
||||||
|
#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
||||||
|
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
|
||||||
|
|
||||||
OperameLanguage::Texts T;
|
OperameLanguage::Texts T;
|
||||||
|
|
||||||
enum Driver { AQC, MHZ };
|
enum Driver { AQC, MHZ };
|
||||||
|
|
||||||
Driver driver;
|
Driver driver;
|
||||||
MQTTClient mqtt;
|
MQTTClient mqtt;
|
||||||
HardwareSerial hwserial1(1);
|
HardwareSerial hwserial1(1);
|
||||||
TFT_eSPI display;
|
TFT_eSPI display;
|
||||||
TFT_eSprite sprite(&display);
|
TFT_eSprite sprite(&display);
|
||||||
MHZ19 mhz;
|
MHZ19 mhz;
|
||||||
|
WiFiClient wificlient;
|
||||||
|
WiFiClientSecure wificlientsecure;
|
||||||
|
DHT dht(DHTPIN, DHTTYPE);
|
||||||
|
|
||||||
const int pin_portalbutton = 35;
|
const int pin_portalbutton = 35;
|
||||||
const int pin_demobutton = 0;
|
const int pin_demobutton = 0;
|
||||||
@ -36,12 +55,31 @@ int co2_warning;
|
|||||||
int co2_critical;
|
int co2_critical;
|
||||||
int co2_blink;
|
int co2_blink;
|
||||||
String mqtt_topic;
|
String mqtt_topic;
|
||||||
|
bool mqtt_template_enabled;
|
||||||
String mqtt_template;
|
String mqtt_template;
|
||||||
|
bool mqtt_user_pass_enabled;
|
||||||
|
String mqtt_username;
|
||||||
|
String mqtt_password;
|
||||||
|
bool mqtt_temp_hum_enabled;
|
||||||
|
String mqtt_topic_temperature;
|
||||||
|
bool mqtt_template_temp_hum_enabled;
|
||||||
|
String mqtt_template_temp;
|
||||||
|
String mqtt_topic_humidity;
|
||||||
|
String mqtt_template_hum;
|
||||||
bool add_units;
|
bool add_units;
|
||||||
bool wifi_enabled;
|
bool wifi_enabled;
|
||||||
bool mqtt_enabled;
|
bool mqtt_enabled;
|
||||||
int max_failures;
|
int max_failures;
|
||||||
|
|
||||||
|
// REST configuration via WiFiSettings
|
||||||
|
unsigned long rest_interval;
|
||||||
|
int rest_port;
|
||||||
|
String rest_domain;
|
||||||
|
String rest_uri;
|
||||||
|
String rest_resource_id;
|
||||||
|
String rest_cert;
|
||||||
|
bool rest_enabled;
|
||||||
|
|
||||||
void retain(const String& topic, const String& message) {
|
void retain(const String& topic, const String& message) {
|
||||||
Serial.printf("%s %s\n", topic.c_str(), message.c_str());
|
Serial.printf("%s %s\n", topic.c_str(), message.c_str());
|
||||||
mqtt.publish(topic, message, true, 0);
|
mqtt.publish(topic, message, true, 0);
|
||||||
@ -70,6 +108,21 @@ void display_big(const String& text, int fg = TFT_WHITE, int bg = TFT_BLACK) {
|
|||||||
|
|
||||||
sprite.pushSprite(0, 0);
|
sprite.pushSprite(0, 0);
|
||||||
}
|
}
|
||||||
|
void display_3(const String& co2, const String& temp, const String& hum, int fg = TFT_WHITE, int bg = TFT_BLACK) {
|
||||||
|
clear_sprite(bg);
|
||||||
|
sprite.setTextSize(1);
|
||||||
|
sprite.setTextFont(8);
|
||||||
|
sprite.setTextDatum(MC_DATUM);
|
||||||
|
sprite.setTextColor(fg, bg);
|
||||||
|
sprite.drawString(co2, display.width()/2, display.height()/2 - 25);
|
||||||
|
sprite.setTextFont(4);
|
||||||
|
sprite.setTextDatum(ML_DATUM);
|
||||||
|
sprite.drawString(temp, 10, display.height() - 15);
|
||||||
|
sprite.setTextDatum(MR_DATUM);
|
||||||
|
sprite.drawString(hum, display.width() - 10, display.height() - 15);
|
||||||
|
|
||||||
|
sprite.pushSprite(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void display_lines(const std::list<String>& lines, int fg = TFT_WHITE, int bg = TFT_BLACK) {
|
void display_lines(const std::list<String>& lines, int fg = TFT_WHITE, int bg = TFT_BLACK) {
|
||||||
clear_sprite(bg);
|
clear_sprite(bg);
|
||||||
@ -90,10 +143,17 @@ void display_lines(const std::list<String>& lines, int fg = TFT_WHITE, int bg =
|
|||||||
void display_logo() {
|
void display_logo() {
|
||||||
clear_sprite();
|
clear_sprite();
|
||||||
sprite.setSwapBytes(true);
|
sprite.setSwapBytes(true);
|
||||||
sprite.pushImage(12, 30, 215, 76, OPERAME_LOGO);
|
sprite.pushImage(0, 0, 240, 135, CONTROL_CO2_V2_240_135_LOGO);
|
||||||
sprite.pushSprite(0, 0);
|
sprite.pushSprite(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_cal() {
|
||||||
|
int fg, bg;
|
||||||
|
fg = TFT_WHITE;
|
||||||
|
bg = TFT_BLACK;
|
||||||
|
display_big(String("E 01"), fg, bg);
|
||||||
|
}
|
||||||
|
|
||||||
void display_ppm(int ppm) {
|
void display_ppm(int ppm) {
|
||||||
int fg, bg;
|
int fg, bg;
|
||||||
if (ppm >= co2_critical) {
|
if (ppm >= co2_critical) {
|
||||||
@ -113,6 +173,26 @@ void display_ppm(int ppm) {
|
|||||||
display_big(String(ppm), fg, bg);
|
display_big(String(ppm), fg, bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_ppm_t_h(int ppm, float t, float h) {
|
||||||
|
int fg, bg;
|
||||||
|
if (ppm >= co2_critical) {
|
||||||
|
fg = TFT_WHITE;
|
||||||
|
bg = TFT_RED;
|
||||||
|
} else if (ppm >= co2_warning) {
|
||||||
|
fg = TFT_BLACK;
|
||||||
|
bg = TFT_YELLOW;
|
||||||
|
} else {
|
||||||
|
fg = TFT_GREEN;
|
||||||
|
bg = TFT_BLACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ppm >= co2_blink && millis() % 2000 < 1000) {
|
||||||
|
std::swap(fg, bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
display_3(String(ppm), String(int(t)) + String("`C"), String(int(h)) + String("%"), fg, bg);
|
||||||
|
}
|
||||||
|
|
||||||
void calibrate() {
|
void calibrate() {
|
||||||
auto lines = T.calibration;
|
auto lines = T.calibration;
|
||||||
for (int count = 60; count >= 0; count--) {
|
for (int count = 60; count >= 0; count--) {
|
||||||
@ -208,12 +288,23 @@ void connect_mqtt() {
|
|||||||
if (mqtt.connected()) return; // already/still connected
|
if (mqtt.connected()) return; // already/still connected
|
||||||
|
|
||||||
static int failures = 0;
|
static int failures = 0;
|
||||||
|
if( mqtt_user_pass_enabled ) {
|
||||||
|
if (mqtt.connect(WiFiSettings.hostname.c_str(), mqtt_username.c_str(), mqtt_password.c_str())) {
|
||||||
|
failures = 0;
|
||||||
|
display_big("MQTT connect");
|
||||||
|
} else {
|
||||||
|
failures++;
|
||||||
|
if (failures >= max_failures) panic(T.error_mqtt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (mqtt.connect(WiFiSettings.hostname.c_str())) {
|
if (mqtt.connect(WiFiSettings.hostname.c_str())) {
|
||||||
failures = 0;
|
failures = 0;
|
||||||
} else {
|
} else {
|
||||||
failures++;
|
failures++;
|
||||||
if (failures >= max_failures) panic(T.error_mqtt);
|
if (failures >= max_failures) panic(T.error_mqtt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush(Stream& s, int limit = 20) {
|
void flush(Stream& s, int limit = 20) {
|
||||||
@ -321,7 +412,7 @@ void set_zero() {
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Operame start");
|
Serial.println("Operame / www.controlCO2.space start");
|
||||||
|
|
||||||
digitalWrite(pin_backlight, HIGH);
|
digitalWrite(pin_backlight, HIGH);
|
||||||
display.init();
|
display.init();
|
||||||
@ -369,6 +460,8 @@ void setup() {
|
|||||||
Serial.println("Using MHZ driver.");
|
Serial.println("Using MHZ driver.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize DHT device.
|
||||||
|
dht.begin();
|
||||||
|
|
||||||
for (auto& str : T.portal_instructions[0]) {
|
for (auto& str : T.portal_instructions[0]) {
|
||||||
str.replace("{ssid}", WiFiSettings.hostname);
|
str.replace("{ssid}", WiFiSettings.hostname);
|
||||||
@ -389,8 +482,29 @@ void setup() {
|
|||||||
max_failures = WiFiSettings.integer("operame_max_failures", 0, 1000, 10, T.config_max_failures);
|
max_failures = WiFiSettings.integer("operame_max_failures", 0, 1000, 10, T.config_max_failures);
|
||||||
mqtt_topic = WiFiSettings.string("operame_mqtt_topic", WiFiSettings.hostname, T.config_mqtt_topic);
|
mqtt_topic = WiFiSettings.string("operame_mqtt_topic", WiFiSettings.hostname, T.config_mqtt_topic);
|
||||||
mqtt_interval = 1000UL * WiFiSettings.integer("operame_mqtt_interval", 10, 3600, 60, T.config_mqtt_interval);
|
mqtt_interval = 1000UL * WiFiSettings.integer("operame_mqtt_interval", 10, 3600, 60, T.config_mqtt_interval);
|
||||||
mqtt_template = WiFiSettings.string("operame_mqtt_template", "{} PPM", T.config_mqtt_template);
|
// mqtt_template_enabled = WiFiSettings.checkbox("operame_mqtt_template_enabled", false, T.config_mqtt_template_enabled);
|
||||||
WiFiSettings.info(T.config_template_info);
|
// mqtt_template = WiFiSettings.string("operame_mqtt_template", "{} PPM", T.config_mqtt_template);
|
||||||
|
// WiFiSettings.info(T.config_template_info);
|
||||||
|
mqtt_temp_hum_enabled = WiFiSettings.checkbox("operame_mqtt_temp_hum", false, T.config_mqtt_temp_hum);
|
||||||
|
mqtt_topic_temperature = WiFiSettings.string("operame_mqtt_topic_temperature", WiFiSettings.hostname + "/t", T.config_mqtt_topic_temperature);
|
||||||
|
mqtt_topic_humidity = WiFiSettings.string("operame_mqtt_topic_humidity", WiFiSettings.hostname + "/h", T.config_mqtt_topic_humidity);
|
||||||
|
// mqtt_template_temp_hum_enabled = WiFiSettings.checkbox("operame_mqtt_template_temp_hum_enabled", false, T.config_mqtt_template_temp_hum_enabled);
|
||||||
|
// mqtt_template_temp = WiFiSettings.string("operame_mqtt_template_temp", "{} C", T.config_mqtt_template_temp);
|
||||||
|
// mqtt_template_hum = WiFiSettings.string("operame_mqtt_template_hum", "{} %R.H.", T.config_mqtt_template_hum);
|
||||||
|
mqtt_user_pass_enabled = WiFiSettings.checkbox("operame_mqtt_user_pass", false, T.config_mqtt_user_pass);
|
||||||
|
mqtt_username = WiFiSettings.string("operame_mqtt_username", 64, "", T.config_mqtt_username);
|
||||||
|
mqtt_password = WiFiSettings.string("operame_mqtt_password", 64, "", T.config_mqtt_password);
|
||||||
|
|
||||||
|
WiFiSettings.heading("REST");
|
||||||
|
rest_enabled = WiFiSettings.checkbox("operame_rest", false, T.config_rest) && wifi_enabled;
|
||||||
|
rest_domain = WiFiSettings.string("rest_domain", 150, "", T.config_rest_domain);
|
||||||
|
rest_uri = WiFiSettings.string("rest_uri", 600, "", T.config_rest_uri);
|
||||||
|
rest_port = WiFiSettings.integer("rest_port", 0, 65535, 443, T.config_rest_port);
|
||||||
|
rest_interval = 1000UL * WiFiSettings.integer("operame_rest_interval", 10, 3600, 60 * 5, T.config_rest_interval);
|
||||||
|
rest_resource_id = WiFiSettings.string("rest_resource_id", 64, "", T.config_rest_resource_id);
|
||||||
|
bool rest_cert_enabled = WiFiSettings.checkbox("operame_rest_cert", false, T.config_rest_cert_enabled);
|
||||||
|
rest_cert = WiFiSettings.string("rest_cert", 6000, "", T.config_rest_cert);
|
||||||
|
rest_cert.replace("\\n", "\n");
|
||||||
|
|
||||||
WiFiSettings.onConnect = [] {
|
WiFiSettings.onConnect = [] {
|
||||||
display_big(T.connecting, TFT_BLUE);
|
display_big(T.connecting, TFT_BLUE);
|
||||||
@ -429,20 +543,53 @@ void setup() {
|
|||||||
|
|
||||||
if (wifi_enabled) WiFiSettings.connect(false, 15);
|
if (wifi_enabled) WiFiSettings.connect(false, 15);
|
||||||
|
|
||||||
static WiFiClient wificlient;
|
|
||||||
if (mqtt_enabled) mqtt.begin(server.c_str(), port, wificlient);
|
if (mqtt_enabled) mqtt.begin(server.c_str(), port, wificlient);
|
||||||
|
|
||||||
|
if (rest_cert_enabled) wificlientsecure.setCACert(rest_cert.c_str());
|
||||||
|
|
||||||
if (ota_enabled) setup_ota();
|
if (ota_enabled) setup_ota();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void post_rest_message(DynamicJsonDocument message, Stream& stream) {
|
||||||
|
stream.println("POST " + rest_uri + " HTTP/1.1");
|
||||||
|
stream.println("Host: " + rest_domain);
|
||||||
|
stream.println("Content-Type: application/json");
|
||||||
|
stream.println("Connection: keep-alive");
|
||||||
|
stream.print("Content-Length: ");
|
||||||
|
stream.println(measureJson(message));
|
||||||
|
stream.println();
|
||||||
|
serializeJson(message, stream);
|
||||||
|
stream.println();
|
||||||
|
}
|
||||||
|
|
||||||
#define every(t) for (static unsigned long _lasttime; (unsigned long)((unsigned long)millis() - _lasttime) >= (t); _lasttime = millis())
|
#define every(t) for (static unsigned long _lasttime; (unsigned long)((unsigned long)millis() - _lasttime) >= (t); _lasttime = millis())
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
static int co2;
|
static int co2;
|
||||||
|
static float h;
|
||||||
|
static float t;
|
||||||
|
static bool first_boot = true;
|
||||||
|
|
||||||
every(5000) {
|
if(first_boot)
|
||||||
|
{
|
||||||
co2 = get_co2();
|
co2 = get_co2();
|
||||||
Serial.println(co2);
|
h = dht.readHumidity();
|
||||||
|
t = dht.readTemperature();
|
||||||
|
first_boot = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
every(60000) {
|
||||||
|
// Read CO2, humidity and temperature
|
||||||
|
co2 = get_co2();
|
||||||
|
h = dht.readHumidity();
|
||||||
|
t = dht.readTemperature();
|
||||||
|
// Print data to serial port
|
||||||
|
Serial.print(co2);
|
||||||
|
Serial.print(",");
|
||||||
|
Serial.print(t);
|
||||||
|
Serial.print(",");
|
||||||
|
Serial.print(h);
|
||||||
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
every(50) {
|
every(50) {
|
||||||
@ -451,9 +598,39 @@ void loop() {
|
|||||||
} else if (co2 == 0) {
|
} else if (co2 == 0) {
|
||||||
display_big(T.wait);
|
display_big(T.wait);
|
||||||
} else {
|
} else {
|
||||||
|
// Check if there is a humidity sensor
|
||||||
|
if (isnan(h) || isnan(t)) {
|
||||||
|
// Only display CO2 value (the old way)
|
||||||
// some MH-Z19's go to 10000 but the display has space for 4 digits
|
// some MH-Z19's go to 10000 but the display has space for 4 digits
|
||||||
|
if(co2 < 330 )
|
||||||
|
{
|
||||||
|
display_cal();
|
||||||
|
}
|
||||||
|
else if(co2 < 400)
|
||||||
|
{
|
||||||
|
display_ppm(co2 < 399 ? 399 : co2);
|
||||||
|
}
|
||||||
|
else if(co2 >= 400)
|
||||||
|
{
|
||||||
display_ppm(co2 > 9999 ? 9999 : co2);
|
display_ppm(co2 > 9999 ? 9999 : co2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if(co2 < 330)
|
||||||
|
{
|
||||||
|
display_cal();
|
||||||
|
}
|
||||||
|
else if(co2 < 400)
|
||||||
|
{
|
||||||
|
display_ppm_t_h(co2 < 399 ? 399 : co2, t, h);
|
||||||
|
}
|
||||||
|
// Display also humidity and temperature
|
||||||
|
else if(co2 >= 400)
|
||||||
|
{
|
||||||
|
display_ppm_t_h(co2 > 9999 ? 9999 : co2, t, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mqtt_enabled) {
|
if (mqtt_enabled) {
|
||||||
@ -461,9 +638,63 @@ void loop() {
|
|||||||
every(mqtt_interval) {
|
every(mqtt_interval) {
|
||||||
if (co2 <= 0) break;
|
if (co2 <= 0) break;
|
||||||
connect_mqtt();
|
connect_mqtt();
|
||||||
String message = mqtt_template;
|
//CO2
|
||||||
message.replace("{}", String(co2));
|
String message;
|
||||||
|
const size_t capacity = JSON_OBJECT_SIZE(3);
|
||||||
|
DynamicJsonDocument doc(capacity);
|
||||||
|
doc["variable"] = "CO2";
|
||||||
|
doc["value"] = co2;
|
||||||
|
doc["unit"] = "ppm";
|
||||||
|
serializeJson(doc, message);
|
||||||
retain(mqtt_topic, message);
|
retain(mqtt_topic, message);
|
||||||
|
|
||||||
|
if(mqtt_temp_hum_enabled) {
|
||||||
|
//temperature
|
||||||
|
if(!isnan(t)) {
|
||||||
|
String message;
|
||||||
|
const size_t capacity = JSON_OBJECT_SIZE(3);
|
||||||
|
DynamicJsonDocument doc(capacity);
|
||||||
|
doc["variable"] = "temperature";
|
||||||
|
doc["value"] = t;
|
||||||
|
doc["unit"] = "C";
|
||||||
|
serializeJson(doc, message);
|
||||||
|
retain(mqtt_topic_temperature, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//humidity
|
||||||
|
if(!isnan(h)) {
|
||||||
|
String message;
|
||||||
|
const size_t capacity = JSON_OBJECT_SIZE(3);
|
||||||
|
DynamicJsonDocument doc(capacity);
|
||||||
|
doc["variable"] = "humidity";
|
||||||
|
doc["value"] = h;
|
||||||
|
doc["unit"] = "%R.H.";
|
||||||
|
serializeJson(doc, message);
|
||||||
|
retain(mqtt_topic_humidity, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rest_enabled) {
|
||||||
|
while(wificlientsecure.available()){
|
||||||
|
String line = wificlientsecure.readStringUntil('\r');
|
||||||
|
Serial.print(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
every(rest_interval) {
|
||||||
|
if (co2 <= 0) break;
|
||||||
|
|
||||||
|
const size_t capacity = JSON_OBJECT_SIZE(4);
|
||||||
|
DynamicJsonDocument message(capacity);
|
||||||
|
message["co2"] = co2;
|
||||||
|
message["temperature"] = t;
|
||||||
|
message["humidity"] = h;
|
||||||
|
message["id"] = rest_resource_id.c_str();
|
||||||
|
|
||||||
|
if (wificlientsecure.connected() || wificlientsecure.connect(&rest_domain[0], rest_port)) {
|
||||||
|
post_rest_message(message, wificlientsecure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,27 @@ struct Texts {
|
|||||||
*config_mqtt_port,
|
*config_mqtt_port,
|
||||||
*config_max_failures,
|
*config_max_failures,
|
||||||
*config_mqtt_topic,
|
*config_mqtt_topic,
|
||||||
|
*config_mqtt_topic_temperature,
|
||||||
|
*config_mqtt_topic_humidity,
|
||||||
*config_mqtt_interval,
|
*config_mqtt_interval,
|
||||||
|
*config_mqtt_template_enabled,
|
||||||
*config_mqtt_template,
|
*config_mqtt_template,
|
||||||
*config_template_info,
|
*config_template_info,
|
||||||
|
*config_mqtt_temp_hum,
|
||||||
|
*config_mqtt_template_temp_hum_enabled,
|
||||||
|
*config_mqtt_template_temp,
|
||||||
|
*config_mqtt_template_hum,
|
||||||
|
*config_mqtt_user_pass,
|
||||||
|
*config_mqtt_username,
|
||||||
|
*config_mqtt_password,
|
||||||
|
*config_rest,
|
||||||
|
*config_rest_domain,
|
||||||
|
*config_rest_uri,
|
||||||
|
*config_rest_port,
|
||||||
|
*config_rest_interval,
|
||||||
|
*config_rest_resource_id,
|
||||||
|
*config_rest_cert_enabled,
|
||||||
|
*config_rest_cert,
|
||||||
*connecting,
|
*connecting,
|
||||||
*wait
|
*wait
|
||||||
;
|
;
|
||||||
@ -69,9 +87,27 @@ bool select(Texts& T, String language) {
|
|||||||
T.config_mqtt_server = "Broker"; // probably should not be translated
|
T.config_mqtt_server = "Broker"; // probably should not be translated
|
||||||
T.config_mqtt_port = "Broker TCP port";
|
T.config_mqtt_port = "Broker TCP port";
|
||||||
T.config_max_failures = "Number of failed connections before automatic restart";
|
T.config_max_failures = "Number of failed connections before automatic restart";
|
||||||
T.config_mqtt_topic = "Topic"; // probably should not be translated
|
T.config_mqtt_topic = "Topic for CO2"; // probably should not be translated
|
||||||
|
T.config_mqtt_topic_temperature = "Topic for temperature (if available)"; // probably should not be translated
|
||||||
|
T.config_mqtt_topic_humidity = "Topic for humidity (if available)"; // probably should not be translated
|
||||||
T.config_mqtt_interval = "Publication interval [s]";
|
T.config_mqtt_interval = "Publication interval [s]";
|
||||||
T.config_mqtt_template = "Message template";
|
T.config_mqtt_template_enabled = "Enable this if you want to use your own MQTT message template for CO2";
|
||||||
|
T.config_mqtt_template = "Message template for CO2";
|
||||||
|
T.config_mqtt_user_pass = "Enable username and password for MQTT";
|
||||||
|
T.config_mqtt_username = "Username MQTT";
|
||||||
|
T.config_mqtt_password = "Password MQTT";
|
||||||
|
T.config_mqtt_temp_hum = "Enable MQTT publish of temperature and humidity (if available)";
|
||||||
|
T.config_mqtt_template_temp_hum_enabled = "Enable this if you want to use your own MQTT message template for temperature/humidity";
|
||||||
|
T.config_mqtt_template_temp = "Message template for temperature";
|
||||||
|
T.config_mqtt_template_hum = "Message template for humidity";
|
||||||
|
T.config_rest = "Publish measurements via the HTTPS protocol";
|
||||||
|
T.config_rest_domain = "Domain";
|
||||||
|
T.config_rest_uri = "URI";
|
||||||
|
T.config_rest_port = "TCP Port";
|
||||||
|
T.config_rest_interval = "Publication interval [s]";
|
||||||
|
T.config_rest_resource_id = "ID of this device";
|
||||||
|
T.config_rest_cert_enabled = "Use CA root certificate";
|
||||||
|
T.config_rest_cert = "CA root certificat";
|
||||||
T.config_template_info = "The {} in the template is replaced by the measurement value.";
|
T.config_template_info = "The {} in the template is replaced by the measurement value.";
|
||||||
T.connecting = "Connecting to WiFi...";
|
T.connecting = "Connecting to WiFi...";
|
||||||
T.portal_instructions = {
|
T.portal_instructions = {
|
||||||
@ -135,9 +171,27 @@ bool select(Texts& T, String language) {
|
|||||||
T.config_mqtt_server = "Broker"; // zo heet dat in MQTT
|
T.config_mqtt_server = "Broker"; // zo heet dat in MQTT
|
||||||
T.config_mqtt_port = "Broker TCP-poort";
|
T.config_mqtt_port = "Broker TCP-poort";
|
||||||
T.config_max_failures = "Aantal verbindingsfouten voor automatische herstart";
|
T.config_max_failures = "Aantal verbindingsfouten voor automatische herstart";
|
||||||
T.config_mqtt_topic = "Topic"; // zo heet dat in MQTT
|
T.config_mqtt_topic = "Topic voor CO2"; // zo heet dat in MQTT
|
||||||
|
T.config_mqtt_topic_temperature = "Topic voor temperatuur (indien beschikbaar)"; // probably should not be translated
|
||||||
|
T.config_mqtt_topic_humidity = "Topic voor rel. luchtvochtigheid (indien beschikbaar)"; // probably should not be translated
|
||||||
T.config_mqtt_interval = "Publicatie-interval [s]";
|
T.config_mqtt_interval = "Publicatie-interval [s]";
|
||||||
T.config_mqtt_template = "Berichtsjabloon";
|
T.config_mqtt_template_enabled = "Activeer dit indien je jouw eigen MQTT berichtsjabloon voor CO2 wil gebruiken";
|
||||||
|
T.config_mqtt_template = "Berichtsjabloon voor CO2";
|
||||||
|
T.config_mqtt_user_pass = "Activeer gebruikersnaam en paswoord voor MQTT";
|
||||||
|
T.config_mqtt_username = "Gebruikersnaam MQTT";
|
||||||
|
T.config_mqtt_password = "Paswoord MQTT";
|
||||||
|
T.config_mqtt_temp_hum = "Activeer MQTT publicatie van temperatuur en rel. luchtvochtigheid (indien beschikbaar)";
|
||||||
|
T.config_mqtt_template_temp_hum_enabled = "Activeer dit indien je jouw eigen MQTT berichtsjabloon voor temperatuur/rel. luchtvochtigheid wil gebruiken";
|
||||||
|
T.config_mqtt_template_temp = "Berichtsjabloon voor temperatuur";
|
||||||
|
T.config_mqtt_template_hum = "Berichtsjabloon voor rel. luchtvochtigheid";
|
||||||
|
T.config_rest = "Metingen via het HTTPS-protocol versturen";
|
||||||
|
T.config_rest_domain = "Domein";
|
||||||
|
T.config_rest_uri = "URI";
|
||||||
|
T.config_rest_port = "TCP-Poort";
|
||||||
|
T.config_rest_interval = "Publicatie-interval [s]";
|
||||||
|
T.config_rest_resource_id = "ID van dit apparaat";
|
||||||
|
T.config_rest_cert_enabled = "Gebruik een CA root certificaat";
|
||||||
|
T.config_rest_cert = "CA root certificaat";
|
||||||
T.config_template_info = "De {} in het sjabloon wordt vervangen door de gemeten waarde.";
|
T.config_template_info = "De {} in het sjabloon wordt vervangen door de gemeten waarde.";
|
||||||
T.connecting = "Verbinden met WiFi...";
|
T.connecting = "Verbinden met WiFi...";
|
||||||
T.portal_instructions = {
|
T.portal_instructions = {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
; Advanced options: extra scripting
|
; Advanced options: extra scripting
|
||||||
;
|
;
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; http://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
src_dir = .
|
src_dir = .
|
||||||
@ -20,11 +20,14 @@ board_build.partitions = default.csv
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
targets = upload
|
targets = upload
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ESP-WiFiSettings@^3.7.2
|
ESP-WiFiSettings@^3.7.2
|
||||||
MH-Z19
|
MH-Z19
|
||||||
TFT_eSPI
|
TFT_eSPI
|
||||||
MQTT
|
MQTT
|
||||||
|
ArduinoJson
|
||||||
|
adafruit/DHT sensor library@^1.4.2
|
||||||
|
|
||||||
build_flags =
|
build_flags =
|
||||||
# ESP-WiFiSettings languages:
|
# ESP-WiFiSettings languages:
|
||||||
@ -54,6 +57,7 @@ build_flags =
|
|||||||
-DLOAD_GFXFF=1
|
-DLOAD_GFXFF=1
|
||||||
-DSPI_FREQUENCY=40000000
|
-DSPI_FREQUENCY=40000000
|
||||||
|
|
||||||
|
|
||||||
[env:serial]
|
[env:serial]
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
|
|
||||||
@ -63,9 +67,3 @@ upload_port = operame-HEX_HERE.local
|
|||||||
upload_flags =
|
upload_flags =
|
||||||
--port=3232
|
--port=3232
|
||||||
--auth=PASSWORD_HERE
|
--auth=PASSWORD_HERE
|
||||||
; Alternatively, instead of editing this file (which is annoying because it
|
|
||||||
; might end up being committed in git), you can create extra an extra config
|
|
||||||
; file.
|
|
||||||
; Just copy the [env:ota] section to a new file called platformio-NAME.ini
|
|
||||||
; and change [env:ota] to [env:NAME]. You can use this to OTA-update multiple
|
|
||||||
; Operames with a single command: pio run -t upload -e NAME -e NAME -e NAME
|
|
||||||
|
Loading…
Reference in New Issue
Block a user