kompost.ino 1.32 KB
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <Wire.h>

#include "PCF8591.h"
#include "pcf.h"
#include "wifi.h"
#include "sonar.h"
#include "mqtt.h"
#include "queue.h"
#include "device.h"


/* #include "control.h" */
/* #include "control.h" */

unsigned int counter = 0;


void setup(void) {
  /* Serial.begin(115200); */
  delay(100);
  setup_wifi();
  /* pinMode(LED_BUILTIN, OUTPUT); */

  /* delay(5000); */
  setup_pcf();
  setup_sonar();
  delay(100);
  setup_mqtt();
  /* setup_queue(); */
}

void loop(void) {
  MDNS.update();
  delay(500);
  counter++;

  /* sensors_event_t temp_event, pressure_event; */
  /* bmp_temp->getEvent(&temp_event); */
  /* bmp_pressure->getEvent(&pressure_event); */


  loop_sonar(counter);

  /* pcf8574.digitalWrite(0,counter % 2); */

  /* float ana0V = pcf8591.voltageRead(AIN0); // Read voltage from analog 0 */
  /* int ana = pcf8591.analogRead(AIN0); */
  String moistureLevelStr(pcf8591.analogRead(0));
  mqttClient.publish(PREAMBLE T_MOIST, moistureLevelStr );

  String temp(bmp.readTemperature());
  mqttClient.publish(PREAMBLE T_TEMP, temp );

  String liquidLevelAvgStr(liquid_level_avg());
  mqttClient.publish(PREAMBLE T_SDIST, liquidLevelAvgStr );

  /* String temp(temp_event.temperature); */

  /* loop_pcf(); */
  loop_queue();
  loop_device();
  /* loop_control(counter); */
}