Code: Select all
#define STATUS_LED_GPIO 2
#define BUTTON_CFG_RELAY_GPIO 0
#include <Wire.h>
#include <SHT31.h> // https://github.com/RobTillaart/SHT31
#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/button.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/events.h>
#include <supla/sensor/therm_hygro_meter.h>
SHT31 sht[4] = {
SHT31(0x44, &Wire),
SHT31(0x45, &Wire),
SHT31(0x44, &Wire1),
SHT31(0x45, &Wire1)
};
#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom;
Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
Supla::EspWebServer suplaServer;
class Czujnik_SHT : public Supla::Sensor::ThermHygroMeter {
public:
explicit Czujnik_SHT(uint8_t czujnik_sht) : czujnik_sht(czujnik_sht){
}
double getTemp() override {
odczytaj_czujniki();
return temperature;
}
double getHumi() override {
return humidity;
}
void onInit() override {
sht[czujnik_sht].begin();
channel.setNewValue(getTemp(), getHumi());
}
private:
void odczytaj_czujniki(){
sht[czujnik_sht].read();
temperature = sht[czujnik_sht].getTemperature();
humidity = sht[czujnik_sht].getHumidity();
}
protected:
int8_t czujnik_sht;
double temperature = TEMPERATURE_NOT_AVAILABLE;
double humidity = HUMIDITY_NOT_AVAILABLE;
}; Czujnik_SHT *czujniki[4];
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Html::StatusLedParameters htmlStatusLed;
void setup() {
Serial.begin(115200);
Wire.begin();
Wire1.begin(33,32);
auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
for (int i = 0; i < 4; ++i){
czujniki[i] = new Czujnik_SHT(i);
}
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
SuplaDevice.begin();
}
void loop() {
SuplaDevice.iterate();
}