Compare commits
2 Commits
463757fa60
...
5ae0cdfc08
| Author | SHA1 | Date | |
|---|---|---|---|
|
5ae0cdfc08
|
|||
|
03131b65f1
|
26
.clangd
Normal file
26
.clangd
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [
|
||||||
|
-DSSIZE_MAX,
|
||||||
|
-DLWIP_NO_UNISTD_H=1,
|
||||||
|
-Dssize_t=long,
|
||||||
|
-D_SSIZE_T_DECLARED,
|
||||||
|
-Wno-unknown-warning-option
|
||||||
|
]
|
||||||
|
Remove: [
|
||||||
|
-mlong-calls,
|
||||||
|
-fno-tree-switch-conversion,
|
||||||
|
-mtext-section-literals,
|
||||||
|
-mlongcalls,
|
||||||
|
-fstrict-volatile-bitfields,
|
||||||
|
-free,
|
||||||
|
-fipa-pta,
|
||||||
|
-march=*,
|
||||||
|
-mabi=*,
|
||||||
|
-mcpu=*
|
||||||
|
]
|
||||||
|
Diagnostics:
|
||||||
|
Suppress:
|
||||||
|
- pp_including_mainfile_in_preamble
|
||||||
|
- pp_expr_bad_token_start_expr
|
||||||
|
- redefinition_different_typedef
|
||||||
|
- main_returns_nonint
|
||||||
11
README.org
11
README.org
@@ -1,12 +1,6 @@
|
|||||||
* Muraqib
|
* Muraqib
|
||||||
|
|
||||||
Temperature and humidity sensor that sends its data via MQTT. The project is implemented using a Wemos D1 mini board with the following components:
|
CO2 sensor that collects and sends its data via MQTT to a server. The board of the sensor is the Wemos D1 mini and the sensor is a SCD41.
|
||||||
|
|
||||||
- DHT22 temperature and humidity sensor
|
|
||||||
- Battery shield
|
|
||||||
- 3.7V 1000mAh Lithium battery
|
|
||||||
|
|
||||||
The sensor captures the data every 5 minutes and sends it to a MQTT broker and then enters deep sleep, it is important to save power as the device runs off a battery. This sensor is part of a project to grow mushrooms in a controlled environment.
|
|
||||||
|
|
||||||
** Pinout of the board
|
** Pinout of the board
|
||||||
|
|
||||||
@@ -14,8 +8,7 @@ The sensor captures the data every 5 minutes and sends it to a MQTT broker and t
|
|||||||
[[./pinout.png]]
|
[[./pinout.png]]
|
||||||
|
|
||||||
** Dependencies
|
** Dependencies
|
||||||
- [[https://github.com/adafruit/DHT-sensor-library][Adafruit DHT sensor library]]
|
- [[https://github.com/Sensirion/arduino-i2c-scd4x][Sensirion I²C SCD4X Arduino Library]]
|
||||||
- [[https://github.com/adafruit/Adafruit_Sensor][Adafruit Unified Sensor Driver]]
|
|
||||||
- [[https://github.com/knolleary/pubsubclient][PubSubClient]]
|
- [[https://github.com/knolleary/pubsubclient][PubSubClient]]
|
||||||
- [[https://github.com/bblanchon/ArduinoJson][ArduinoJSON]]
|
- [[https://github.com/bblanchon/ArduinoJson][ArduinoJSON]]
|
||||||
** Configuration
|
** Configuration
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ platform = espressif8266
|
|||||||
board = d1_mini
|
board = d1_mini
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
monitor_filters = esp8266_exception_decoder
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/DHT sensor library@^1.4.6
|
sensirion/Sensirion I2C SCD4x@^1.1.0
|
||||||
adafruit/Adafruit Unified Sensor@^1.1.15
|
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
bblanchon/ArduinoJson@^7.4.1
|
bblanchon/ArduinoJson@^7.4.1
|
||||||
|
|
||||||
|
|||||||
64
src/main.cpp
64
src/main.cpp
@@ -1,38 +1,64 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wlan.h"
|
#include "wlan.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <DHT.h>
|
#include <SensirionI2cScd4x.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
#define DHTTYPE DHT22
|
#define DHTTYPE DHT22
|
||||||
#define DHTPIN 4
|
#define DHTPIN 4
|
||||||
DHT dht(DHTPIN, DHTTYPE);
|
SensirionI2cScd4x sensor;
|
||||||
|
|
||||||
|
int error;
|
||||||
|
static char errorMessage[64];
|
||||||
|
|
||||||
const char *config_file_path = "/config.json";
|
const char *config_file_path = "/config.json";
|
||||||
|
long inactivity_delay;
|
||||||
Config *config;
|
Config *config;
|
||||||
WiFiClient wifi_client;
|
WiFiClient wifi_client;
|
||||||
PubSubClient mqtt_client(wifi_client);
|
PubSubClient mqtt_client(wifi_client);
|
||||||
|
|
||||||
bool check_valid_value(float value) {
|
int check_error(int error) {
|
||||||
return (!isnan(value) && value >= 0 && value <= 100);
|
if (error) {
|
||||||
|
Serial.println("Error while initializing sensor");
|
||||||
|
errorToString(error, errorMessage, sizeof errorMessage);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
dht.begin();
|
Wire.begin();
|
||||||
config = (Config *)malloc(sizeof(Config));
|
sensor.begin(Wire, SCD41_I2C_ADDR_62);
|
||||||
if (!load_config_file(config_file_path, config))
|
error = sensor.wakeUp();
|
||||||
Serial.println("ERROR: The config file could not be loaded");
|
error = sensor.stopPeriodicMeasurement();
|
||||||
connect_wlan(config);
|
error = sensor.reinit();
|
||||||
|
error = sensor.startPeriodicMeasurement();
|
||||||
|
inactivity_delay = 60000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
float temperature = dht.readTemperature();
|
uint16_t co2_concentration = 0.0;
|
||||||
float humidity = dht.readHumidity();
|
float temperature = 0.0;
|
||||||
float data[2] = {temperature, humidity};
|
float humidity = 0.0;
|
||||||
if (check_valid_value(temperature) && check_valid_value(humidity)) {
|
bool data_available = false;
|
||||||
mqtt_transfer(mqtt_client, config, data);
|
|
||||||
}
|
error = sensor.getDataReadyStatus(data_available);
|
||||||
disconnect_mqtt(mqtt_client, config->topic);
|
error = sensor.readMeasurement(co2_concentration, temperature, humidity);
|
||||||
free(config);
|
|
||||||
enter_deep_sleep(false, config->sleep_time);
|
if (data_available) {
|
||||||
|
Serial.print("CO2 concentration [ppm]: ");
|
||||||
|
Serial.print(co2_concentration);
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("Temperature [°C]: ");
|
||||||
|
Serial.print(temperature);
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("Relative Humidity [RH]: ");
|
||||||
|
Serial.print(humidity);
|
||||||
|
Serial.println();
|
||||||
|
} else {
|
||||||
|
Serial.println(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(inactivity_delay);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user