Files
muraqib/src/main.cpp
2025-11-27 13:23:04 +01:00

37 lines
803 B
C++

#include "config.h"
#include "sensor.h"
#include "wlan.h"
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <stdlib.h>
WiFiClient wifi_client;
PubSubClient mqtt_client(wifi_client);
SensirionI2cScd4x sensor;
int error_code;
char error_msg[64];
const char *config_file_path = "/config.json";
Config *config;
void setup() {
Serial.begin(9600);
config = (Config *)malloc(sizeof(Config));
if (!load_config_file(config_file_path, config))
Serial.println("ERROR: The config file could not be loaded");
connect_wlan(config);
initialize_sensor(sensor, error_code, error_msg);
}
void loop() {
float data[3];
read_values(sensor, data, error_code, error_msg);
mqtt_transfer(mqtt_client, config, data);
delay(config->sleep_time);
}