[PORADNIK] Arduino IDE

krzychunh
Posts: 53
Joined: Mon Jul 12, 2021 6:23 am

Post

Dziękuje za pomoc, zastosowałem się do powyższych wskazówek, sieć jest rozsyłana, aplikacja Supli wykrywa układ , niestety po zakończeniu konfiguracji przechodzi ponownie do parowania i nie jest widoczna na koncie serwera Supli.
Na chwile obecną kod wygląda tak:

Code: Select all

// --- GPIO dla konfiguracji / statusu ---
#define STATUS_LED_GPIO        2      // LED na ESP32 Dev Module
#define BUTTON_CFG_RELAY_GPIO  0      // BOOT

// --- SUPLA ---
#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/events.h>

#include <supla/sensor/DS18B20.h>
#include <supla/sensor/rain.h>
#include <supla/sensor/wind.h>
#include <supla/sensor/pressure.h>
#include <supla/channel_element.h>
#include <supla/clock/clock.h>

// --- pamięć trwała ---
#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom;

// --- WiFi (dla RSSI) ---
#include <WiFi.h>

// --- Czujniki I2C / inne ---
#include <Wire.h>
#include "HDC1080.h"
#include "MS5611Sensor.h"

// --- Twoje czujniki ---
#include "LightSensor.h"
#include "RainSensor.h"
#include "Anemometr.h"
#include "WindDirection.h"
#include "SPS30Sensor.h"
#include "VoltageSensor.h"

Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); 
Supla::EspWebServer suplaServer;

// --- AUTHKEY ---
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {
  0x3F,0x73,0x85,0x54,0x07,0x83,0x34,0x43,
  0x09,0x8C,0x3B,0xE6,0x41,0x5F,0x4C,0x7D
};

// --- obiekty globalne ---
Supla::Clock *suplaClock = nullptr;
Supla::Sensor::RainSensor *rainSensor = nullptr;

bool resetOncePerHour = true;
long lastRead = 0;

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println();
  Serial.println(F("Startuje stacja pogodowa SUPLA + CONFIG MODE..."));

  // --- I2C ---
  Wire.begin();
  Wire.setClock(100000);

  // --- CZUJNIKI ---

  new Supla::Sensor::LightSensor();

  Supla::Sensor::SPS30_X *sps30 = new Supla::Sensor::SPS30_X();
  new Supla::Sensor::SPS30_PM005(sps30);
  new Supla::Sensor::SPS30_PM01(sps30);
  new Supla::Sensor::SPS30_PM025(sps30);
  new Supla::Sensor::SPS30_PM04(sps30);
  new Supla::Sensor::SPS30_PM10(sps30);

  uint8_t internalTemp[8] = { 0x28, 0x52, 0x29, 0xB5, 0x63, 0x20, 0x01, 0x9B };
  uint8_t externalTemp[8] = { 0x28, 0x1C, 0x7F, 0x57, 0x04, 0xE1, 0x3C, 0x56 };

  new Supla::Sensor::DS18B20(4, internalTemp);
  new Supla::Sensor::DS18B20(4, externalTemp);

  new Supla::Sensor::HDC1080();

  new Supla::Sensor::MS5611Sensor(248);

  rainSensor = new Supla::Sensor::RainSensor(2, 2.5, 300);

  new Supla::Sensor::WindDirectionSensor(18, 15);
  new Supla::Sensor::Anemometr(15, 1, 0);

  // --- Zegar SUPLA ---
  suplaClock = new Supla::Clock();
  SuplaDevice.addClock(suplaClock);

  // --- HTML WWW + PARAMETRY SUPLI ---
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;
  new Supla::Html::StatusLedParameters;

  new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);

  // --- TRYB STARTU: CFG MODE (WIFI AP) ---
  SuplaDevice.setInitialMode(Supla::InitialMode::StartInCfgMode);

  // (opcjonalnie)
  // SuplaDevice.setAuthKey(AUTHKEY);

  // --- START SUPLI (Tylko raz!!!) ---
  SuplaDevice.begin();

  Serial.println(F("SuplaDevice.begin() => Tryb konfiguracyjny wystartował."));
}

void loop() {
  SuplaDevice.iterate();

  // reset licznika opadów raz na godzinę
  if (suplaClock) {
    int minute = suplaClock->getMin();

    if (minute == 0 && resetOncePerHour) {
      if (rainSensor) {
        rainSensor->setReset(true);
        Serial.println(F("Reset licznika opadów (początek godziny)."));
      }
      resetOncePerHour = false;
    }

    if (minute == 1) {
      resetOncePerHour = true;
    }
  }

  // RSSI co 10 s
  if (millis() - lastRead > 10000) {
    Serial.print(F("RSSI: "));
    Serial.println(WiFi.RSSI());
    lastRead = millis();
  }
}
Monitor portu szeregowego:

Code: Select all

MS5611 getting pres.
Channel(9) value changed to -123.00
Speed: 0.00
RSSI: 0
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0

Startuje stacja pogodowa SUPLA + CONFIG MODE...
Channel[0] initial caption set to 'Natężenie światła'
GPM[0]: DefaultUnitAfterValue "lx"
Channel[1] initial caption set to 'PM 0.5'
GPM[1]: DefaultUnitAfterValue "μg/m³"
GPM[1]: RefreshIntervalMs 60000 ms
LittleFS: writing file 1_gpm_common
GPM[1]: common config saved successfully
GPM[2]: DefaultUnitAfterValue "μg/m³"
Channel[2] initial caption set to 'PM 1.0'
GPM[2]: RefreshIntervalMs 60000 ms
LittleFS: writing file 2_gpm_common
GPM[2]: common config saved successfully
GPM[3]: DefaultUnitAfterValue "μg/m³"
Channel[3] initial caption set to 'PM 2.5'
GPM[3]: RefreshIntervalMs 60000 ms
LittleFS: writing file 3_gpm_common
GPM[3]: common config saved successfully
GPM[4]: DefaultUnitAfterValue "μg/m³"
Channel[4] initial caption set to 'PM 4.0'
GPM[4]: RefreshIntervalMs 60000 ms
LittleFS: writing file 4_gpm_common
GPM[4]: common config saved successfully
GPM[5]: DefaultUnitAfterValue "μg/m³"
Channel[5] initial caption set to 'PM 10.0'
GPM[5]: RefreshIntervalMs 60000 ms
LittleFS: writing file 5_gpm_common
GPM[5]: common config saved successfully
Creating OneWire bus for pin: 4
Initializing OneWire bus at pin 4
OneWire(pin 4) Parasite power is OFF
OneWire(pin 4) Found 0 devices:
Channel(9) value changed to -1.00
Channel(10) value changed to -1.00
Channel(12) value changed to -1
addClock: DEPRECATED
SD: initial mode: Start in cfg mode (legacy, deprected)
 *** Supla - starting initialization (platform 0)
SD: add flag DEVICE_CONFIG_SUPPORTED
SD: add flag CALCFG_RESTART_DEVICE
Storage initialization
readStorage: 8; Read: [53 55 50 4C 41 1 0 1 ]
Storage: Number of sections 1
Reading section: 0
readStorage: 7; Read: [3 0 0 FF FF FF FF ]
Section type: 3; size: 0
storedCRC 65535, CRC calc 65535
LittleFsConfig: init called on non empty database. Aborting
 *** Supla - Config initalization
SD: add flag CALCFG_ENTER_CFG_MODE
SD: add flag CALCFG_FACTORY_RESET_SUPPORTED
LittleFsConfig: writing to file "/supla-dev.cfg"
LittleFsConfig: writing to file "/supla-dev.cfg.bak"
Successfully generated GUID and AuthKey
New AuthKey: E485BDADB66AD5269688CE8836B734F4
Automatic firmware update is disabled
Device mode: 0
Config incomplete: missing Wi-Fi SSID
LAST STATE ADDED: Missing Wi-Fi SSID
Config incomplete: missing Wi-Fi password
LAST STATE ADDED: Missing Wi-Fi password
Config incomplete: missing server
Config incomplete: missing email
Security level: Supla CA
 *** Supla - Config load for elements
SD: add flag CALCFG_IDENTIFY_DEVICE
RemoteDeviceConfig: Registering field 0x000000001
GPM[0]: config loaded successfully
GPM[0]: RefreshIntervalMs 5000 ms
GPM[1]: config loaded successfully
GPM[1]: RefreshIntervalMs 60000 ms
Channel[1] config changed offline flag is set
GPM[2]: config loaded successfully
GPM[2]: RefreshIntervalMs 60000 ms
Channel[2] config changed offline flag is set
GPM[3]: config loaded successfully
GPM[3]: RefreshIntervalMs 60000 ms
Channel[3] config changed offline flag is set
GPM[4]: config loaded successfully
GPM[4]: RefreshIntervalMs 60000 ms
Channel[4] config changed offline flag is set
GPM[5]: config loaded successfully
GPM[5]: RefreshIntervalMs 60000 ms
Channel[5] config changed offline flag is set
Channel[6] temperature correction 0.00
Channel[6] humidity correction 0.00
Channel[7] temperature correction 0.00
Channel[7] humidity correction 0.00
Channel[8] temperature correction 0.00
Channel[8] humidity correction 0.00
RemoteDeviceConfig: Registering field 0x000000010
Clock: automaticTimeSync: 1
Button[0] enabling IN as config button
 *** Supla - Config load for elements done
 *** Supla - Load state storage
Validating storage state section with current device configuration
Storage state section validation successful
 *** Supla - Load state storage done
 *** Supla - Init elements
Turning ON SPS sensor
Channel(1) value changed to 1.96
Channel(3) value changed to 1.96
Channel(5) value changed to 2147483647.47
Channel(6) value changed to -275.00
Channel(7) value changed to -275.00
Channel(8) value changed to temp(-275.00), humi(-1.00)
MS5611 init.
MS5611 getting pres.
Channel(9) value changed to temp(-123.00), humi(-1.00)
Channel(10) value changed to 0.00
Channel(12) value changed to 0.00
Button[0]: Initialized: pin 0, pullUp 1, invertLogic 1, state 1
 *** Supla - Init elements done
Config incomplete: deviceMode = CONFIG
LAST STATE ADDED: Missing server address
Current status: [3] Missing server address
LAST STATE ADDED: Missing email address
Current status: [32] Missing email address
GUID: 462C73C59929A5910803AC0CF26BF50F
Device name: SUPLA-ESP32
Device software version: SDK 25.11-dev
 *** Supla - Initializing network layer
[Wi-Fi] Network AP/hostname: SUPLA-ESP32-BCDDC2CD9250
Using Supla protocol version 23
Current status: [5] SuplaDevice initialized
Config incomplete: deviceMode = CONFIG
Wi-Fi SSID missing
[Wi-Fi] setConfigMode
WiFi: enter config mode with SSID: "SUPLA-ESP32-BCDDC2CD9250"
Starting local web server
LAST STATE ADDED: Config mode
Current status: [40] Config mode
 *** Supla - Initialization done
 *** Self-test ***
TEST: ManufacturerID is 0
TEST failed: ProductID is empty
TEST failed: storage init result is false
TEST failed: missing public RSA key
TEST failed: automatic firmware update is disabled
TEST failed: config encryption is disabled
TEST failed: invalid certificates format
TEST failed: security log is disabled
TEST failed: initial mode is set to config mode
 *** Self-test done ***
SuplaDevice.begin() => Tryb konfiguracyjny wystartował.
Reset licznika opadów (początek godziny).

[email protected]
Posts: 1584
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

Spróbuję to zaktualizować w weekend to Ci dam znać
krzychunh
Posts: 53
Joined: Mon Jul 12, 2021 6:23 am

Post

[email protected] wrote: Fri Jan 16, 2026 12:54 pm Spróbuję to zaktualizować w weekend to Ci dam znać
Dziękuje za pomoc i za Twój projekt ;) pełen szacunek
krzychunh
Posts: 53
Joined: Mon Jul 12, 2021 6:23 am

Post

Przerobiłem troche kod ale nie wiem jak to ugryźć
Image

Code: Select all

// --- GPIO dla konfiguracji / statusu ---
#define STATUS_LED_GPIO        2      // LED na ESP32 Dev Module
#define BUTTON_CFG_RELAY_GPIO  0      // BOOT

// --- SUPLA ---
#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/events.h>

#include <supla/sensor/DS18B20.h>
#include <supla/sensor/rain.h>
#include <supla/sensor/wind.h>
#include <supla/sensor/pressure.h>
#include <supla/channel_element.h>
#include <supla/clock/clock.h>

// --- WiFi (dla RSSI) ---
#include <WiFi.h>

// --- Czujniki I2C / inne ---
#include <Wire.h>
#include "HDC1080.h"
#include "MS5611Sensor.h"

// --- Twoje czujniki ---
#include "LightSensor.h"
#include "RainSensor.h"
#include "Anemometr.h"
#include "WindDirection.h"
#include "SPS30Sensor.h"
#include "VoltageSensor.h"

Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;      // <<< TYLKO TEN STORAGE
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true);
Supla::EspWebServer suplaServer;

// --- AUTHKEY ---
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {
  0x3F,0x73,0x85,0x54,0x07,0x83,0x34,0x43,
  0x09,0x8C,0x3B,0xE6,0x41,0x5F,0x4C,0x7D
};

// --- obiekty globalne ---
Supla::Clock *suplaClock = nullptr;
Supla::Sensor::RainSensor *rainSensor = nullptr;

// --- PRZYCISK CFG ---
Supla::Control::Button *cfgButton = nullptr;

bool resetOncePerHour = true;
long lastRead = 0;

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println();
  Serial.println(F("Startuje stacja pogodowa SUPLA + CONFIG MODE..."));

  // --- I2C ---
  Wire.begin();
  Wire.setClock(100000);

  // --- CZUJNIKI ---
  new Supla::Sensor::LightSensor();

  Supla::Sensor::SPS30_X *sps30 = new Supla::Sensor::SPS30_X();
  new Supla::Sensor::SPS30_PM005(sps30);
  new Supla::Sensor::SPS30_PM01(sps30);
  new Supla::Sensor::SPS30_PM025(sps30);
  new Supla::Sensor::SPS30_PM04(sps30);
  new Supla::Sensor::SPS30_PM10(sps30);

  uint8_t internalTemp[8] = { 0x28, 0x52, 0x29, 0xB5, 0x63, 0x20, 0x01, 0x9B };
  uint8_t externalTemp[8] = { 0x28, 0x1C, 0x7F, 0x57, 0x04, 0xE1, 0x3C, 0x56 };

  new Supla::Sensor::DS18B20(4, internalTemp);
  new Supla::Sensor::DS18B20(4, externalTemp);

  new Supla::Sensor::HDC1080();
  new Supla::Sensor::MS5611Sensor(248);

  rainSensor = new Supla::Sensor::RainSensor(5, 2.5, 300);

  new Supla::Sensor::WindDirectionSensor(18, 15);
  new Supla::Sensor::Anemometr(15, 1, 0);

  // --- Zegar SUPLA ---
  suplaClock = new Supla::Clock();
  SuplaDevice.addClock(suplaClock);

  // --- HTML WWW + PARAMETRY SUPLI ---
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;
  new Supla::Html::StatusLedParameters;

  // --- PRZYCISK CFG (BOOT / GPIO0) ---
  cfgButton = new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
  cfgButton->configureAsConfigButton(&SuplaDevice);

  // --- TRYB STARTU: (opcjonalnie) zawsze w CFG ---
  // SuplaDevice.setInitialMode(Supla::InitialMode::StartInCfgMode);

  // (opcjonalnie)
  // SuplaDevice.setAuthKey(AUTHKEY);

  // --- START SUPLI (Tylko raz!!!) ---
  SuplaDevice.begin();

  Serial.println(F("SuplaDevice.begin() => uruchomione."));
}

void loop() {
  SuplaDevice.iterate();

  // reset licznika opadów raz na godzinę
  if (suplaClock) {
    int minute = suplaClock->getMin();

    if (minute == 0 && resetOncePerHour) {
      if (rainSensor) {
        rainSensor->setReset(true);
        Serial.println(F("Reset licznika opadów (początek godziny)."));
      }
      resetOncePerHour = false;
    }

    if (minute == 1) {
      resetOncePerHour = true;
    }
  }

  // RSSI co 10 s
  if (millis() - lastRead > 10000) {
    Serial.print(F("RSSI: "));
    Serial.println(WiFi.RSSI());
    lastRead = millis();
  }
}
Monitor Portu Szeregowego

Code: Select all

09:38:38.732 -> Button[0] pressed
09:38:41.653 -> MS5611 getting pres.
09:38:41.653 -> Speed: 0.00
09:38:41.653 -> RSSI: 0
09:38:43.748 -> Wi-Fi SSID missing
09:38:43.748 -> [Wi-Fi] setConfigMode
09:38:43.748 -> WiFi: enter config mode with SSID: "SUPLA-ESP32-BCDDC2CD9250"
09:38:43.841 -> Starting local web server
09:38:43.841 -> LAST STATE ADDED: Config mode (22)
09:38:43.841 -> Current status: [40] Config mode
09:38:45.545 -> Button[0] released
09:38:51.670 -> MS5611 getting pres.
09:38:51.670 -> Speed: 0.00
09:38:51.670 -> RSSI: 0
09:39:01.669 -> MS5611 getting pres.
09:39:01.669 -> Speed: 0.00
09:39:01.669 -> RSSI: 0
09:39:02.842 -> SERVER: get request
09:39:03.124 -> WebSender error - lost connection
09:39:03.124 -> LittleFsConfig:: custom ca file missing
09:39:03.309 -> SERVER: get request
09:39:04.122 -> LittleFsConfig:: custom ca file missing
09:39:04.936 -> SERVER: post request
09:39:04.936 -> SERVER: key sid, value (ukryty mój)
09:39:04.982 -> SERVER: key wpw, value (ukryty mój)
09:39:04.982 -> SERVER: key svr, value (ukryty mój)
09:39:04.982 -> SERVER: key eml, value (ukryty mój)
09:39:04.982 -> SERVER: key mqttserver, value 
09:39:04.982 -> SERVER: key mqttport, value 1883
09:39:04.982 -> SERVER: key mqttuser, value 
09:39:04.982 -> SERVER: key mqttpasswd, value 
09:39:04.982 -> SERVER: key mqttprefix, value 
09:39:04.982 -> SERVER: key mqttqos, value 0
09:39:04.982 -> SERVER: key rbt, value 0
09:39:04.982 -> rbt found 0
09:39:04.982 -> SERVER: key protocol_supla, value 1
09:39:04.982 -> SERVER: key sec, value 0
09:39:04.982 -> SERVER: key protocol_mqtt, value 0
09:39:04.982 -> SERVER: key mqtttls, value 0
09:39:04.982 -> SERVER: key mqttauth, value 1
09:39:05.029 -> SERVER: key mqttretain, value 0
09:39:05.029 -> SERVER: key led, value 0
09:39:05.029 -> LittleFsConfig: writing to file "/supla-dev.cfg"
09:39:05.029 -> LittleFsConfig: writing to file "/supla-dev.cfg.bak"
09:39:05.076 -> SERVER: get request
09:39:05.716 -> LittleFsConfig:: custom ca file missing
09:39:06.592 -> SERVER: post request
09:39:06.592 -> SERVER: key sid, value (ukryty mój)
09:39:06.592 -> SERVER: key wpw, value (ukryty mój)
09:39:06.592 -> SERVER: key svr, value (ukryty mój)
09:39:06.638 -> SERVER: key eml, value (ukryty mój)
09:39:06.638 -> SERVER: key mqttserver, value 
09:39:06.638 -> SERVER: key mqttport, value 1883
09:39:06.638 -> SERVER: key mqttuser, value 
09:39:06.638 -> SERVER: key mqttpasswd, value 
09:39:06.638 -> SERVER: key mqttprefix, value 
09:39:06.638 -> SERVER: key mqttqos, value 0
09:39:06.638 -> SERVER: key rbt, value 1
09:39:06.638 -> rbt found 1
09:39:06.638 -> Scheduling soft restart in 1000 ms
09:39:06.638 -> LAST STATE ADDED: Software reset (44)
09:39:06.638 -> Current status: [41] Software reset
09:39:06.638 -> SERVER: key protocol_supla, value 1
09:39:06.638 -> SERVER: key sec, value 0
09:39:06.638 -> SERVER: key protocol_mqtt, value 0
09:39:06.638 -> SERVER: key mqtttls, value 0
09:39:06.638 -> SERVER: key mqttauth, value 1
09:39:06.686 -> SERVER: key mqttretain, value 0
09:39:06.686 -> SERVER: key led, value 0
09:39:06.686 -> LittleFsConfig: writing to file "/supla-dev.cfg"
09:39:06.686 -> LittleFsConfig: writing to file "/supla-dev.cfg.bak"
09:39:07.671 -> Reset requested. Reset device
09:39:07.671 -> LittleFsConfig: writing to file "/supla-dev.cfg"
09:39:07.671 -> LittleFsConfig: writing to file "/supla-dev.cfg.bak"
09:39:07.764 -> Stopping local web server
09:39:07.764 -> Resetting in 0.5s...
09:39:08.295 -> See you soon!
09:39:08.295 -> ets Jun  8 2016 00:22:57
09:39:08.295 -> 
09:39:08.295 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
09:39:08.295 -> configsip: 0, SPIWP:0xee
09:39:08.295 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
09:39:08.295 -> mode:DIO, clock div:1
09:39:08.295 -> load:0x3fff0030,len:4980
09:39:08.295 -> load:0x40078000,len:16612
09:39:08.295 -> load:0x40080400,len:3500
09:39:08.295 -> entry 0x400805b4
09:39:09.686 -> 
09:39:09.686 -> Startuje stacja pogodowa SUPLA + CONFIG MODE...
09:39:09.686 -> Channel[0] initial caption set to 'Natężenie światła'
09:39:09.686 -> GPM[0]: DefaultUnitAfterValue "lx"
09:39:09.686 -> Channel[1] initial caption set to 'PM 0.5'
09:39:09.733 -> GPM[1]: DefaultUnitAfterValue "μg/m³"
09:39:09.733 -> GPM[1]: RefreshIntervalMs 60000 ms
09:39:09.733 -> LittleFS: writing file 1_gpm_common
09:39:09.733 -> GPM[1]: common config saved successfully
09:39:09.733 -> GPM[2]: DefaultUnitAfterValue "μg/m³"
09:39:09.733 -> Channel[2] initial caption set to 'PM 1.0'
09:39:09.733 -> GPM[2]: RefreshIntervalMs 60000 ms
09:39:09.733 -> LittleFS: writing file 2_gpm_common
09:39:09.733 -> GPM[2]: common config saved successfully
09:39:09.779 -> GPM[3]: DefaultUnitAfterValue "μg/m³"
09:39:09.779 -> Channel[3] initial caption set to 'PM 2.5'
09:39:09.779 -> GPM[3]: RefreshIntervalMs 60000 ms
09:39:09.779 -> LittleFS: writing file 3_gpm_common
09:39:09.779 -> GPM[3]: common config saved successfully
09:39:09.779 -> GPM[4]: DefaultUnitAfterValue "μg/m³"
09:39:09.779 -> Channel[4] initial caption set to 'PM 4.0'
09:39:09.779 -> GPM[4]: RefreshIntervalMs 60000 ms
09:39:09.779 -> LittleFS: writing file 4_gpm_common
09:39:09.826 -> GPM[4]: common config saved successfully
09:39:09.826 -> GPM[5]: DefaultUnitAfterValue "μg/m³"
09:39:09.826 -> Channel[5] initial caption set to 'PM 10.0'
09:39:09.826 -> GPM[5]: RefreshIntervalMs 60000 ms
09:39:09.826 -> LittleFS: writing file 5_gpm_common
09:39:09.826 -> GPM[5]: common config saved successfully
09:39:09.826 -> Creating OneWire bus for pin: 4
09:39:09.826 -> Initializing OneWire bus at pin 4
09:39:09.966 -> OneWire(pin 4) Parasite power is OFF
09:39:09.966 -> OneWire(pin 4) Found 0 devices:
09:39:10.717 -> Channel(9) value changed to -1.00
09:39:10.717 -> Channel(10) value changed to -1.00
09:39:10.764 -> Channel(12) value changed to -1.00
09:39:10.764 -> addClock: DEPRECATED
09:39:10.764 -> Button[0]::configureAsConfigButton
09:39:10.764 -> Button[0] setHoldTime: 5000
09:39:10.764 -> Button[0] setMulticlickTime: 300
09:39:10.764 ->  *** Supla - starting initialization (platform 0)
09:39:10.764 -> SD: add flag DEVICE_CONFIG_SUPPORTED
09:39:10.764 -> SD: add flag CALCFG_RESTART_DEVICE
09:39:10.764 -> Main storage not configured
09:39:10.764 -> LittleFsConfig: init called on non empty database. Aborting
09:39:10.764 ->  *** Supla - Config initalization
09:39:10.764 -> SD: add flag CALCFG_ENTER_CFG_MODE
09:39:10.764 -> SD: add flag CALCFG_FACTORY_RESET_SUPPORTED
09:39:10.764 -> LittleFsConfig: writing to file "/supla-dev.cfg"
09:39:10.798 -> LittleFsConfig: writing to file "/supla-dev.cfg.bak"
09:39:10.798 -> Successfully generated GUID and AuthKey
09:39:10.798 -> New AuthKey: C5254E7BE17E32A863FF4E11C4B59979
09:39:10.798 -> Automatic firmware update is disabled
09:39:10.798 -> Device mode: 0
09:39:10.798 -> Config incomplete: missing Wi-Fi SSID
09:39:10.798 -> LAST STATE ADDED: Missing Wi-Fi SSID
09:39:10.798 -> Config incomplete: missing Wi-Fi password
09:39:10.798 -> LAST STATE ADDED: Missing Wi-Fi password
09:39:10.798 -> Config incomplete: missing server
09:39:10.798 -> Config incomplete: missing email
09:39:10.847 -> Security level: Supla CA
09:39:10.847 ->  *** Supla - Config load for elements
09:39:10.847 -> SD: add flag CALCFG_IDENTIFY_DEVICE
09:39:10.847 -> RemoteDeviceConfig: Registering field 0x000000001
09:39:10.847 -> GPM[0]: config loaded successfully
09:39:10.847 -> GPM[0]: RefreshIntervalMs 5000 ms
09:39:10.888 -> GPM[1]: config loaded successfully
09:39:10.888 -> GPM[1]: RefreshIntervalMs 60000 ms
09:39:10.888 -> Channel[1] config changed offline flag is set
09:39:10.888 -> GPM[2]: config loaded successfully
09:39:10.888 -> GPM[2]: RefreshIntervalMs 60000 ms
09:39:10.888 -> Channel[2] config changed offline flag is set
09:39:10.936 -> GPM[3]: config loaded successfully
09:39:10.936 -> GPM[3]: RefreshIntervalMs 60000 ms
09:39:10.936 -> Channel[3] config changed offline flag is set
09:39:10.936 -> GPM[4]: config loaded successfully
09:39:10.936 -> GPM[4]: RefreshIntervalMs 60000 ms
09:39:10.936 -> Channel[4] config changed offline flag is set
09:39:10.936 -> GPM[5]: config loaded successfully
09:39:10.936 -> GPM[5]: RefreshIntervalMs 60000 ms
09:39:10.936 -> Channel[5] config changed offline flag is set
09:39:10.936 -> Channel[6] temperature correction 0.00
09:39:10.982 -> Channel[6] humidity correction 0.00
09:39:10.982 -> Channel[7] temperature correction 0.00
09:39:10.982 -> Channel[7] humidity correction 0.00
09:39:10.982 -> Channel[8] temperature correction 0.00
09:39:10.982 -> Channel[8] humidity correction 0.00
09:39:10.982 -> RemoteDeviceConfig: Registering field 0x000000010
09:39:10.982 -> Clock: automaticTimeSync: 1
09:39:10.982 -> Button[0] don't load config
09:39:10.982 ->  *** Supla - Config load for elements done
09:39:10.982 ->  *** Supla - Init elements
09:39:10.982 -> Turning ON SPS sensor
09:39:10.982 -> Channel(1) value changed to 1.96
09:39:10.982 -> Channel(3) value changed to 1.96
09:39:10.982 -> Channel(5) value changed to 2147483647.47
09:39:10.982 -> Channel(6) value changed to -275.00
09:39:11.028 -> Channel(7) value changed to -275.00
09:39:11.028 -> Channel(8) value changed to temp(-275.00), humi(-1.00)
09:39:11.028 -> MS5611 init.
09:39:11.028 -> MS5611 getting pres.
09:39:11.028 -> Channel(9) value changed to temp(-123.00), humi(-1.00)
09:39:11.028 -> Channel(10) value changed to 0.00
09:39:11.028 -> Channel(12) value changed to 0.00
09:39:11.028 -> Button[0]: Initialized: pin 0, pullUp 1, invertLogic 1, state 1
09:39:11.028 ->  *** Supla - Init elements done
09:39:11.028 -> Config incomplete: deviceMode = CONFIG
09:39:11.028 -> LAST STATE ADDED: Missing server address
09:39:11.028 -> Current status: [3] Missing server address
09:39:11.028 -> LAST STATE ADDED: Missing email address
09:39:11.075 -> Current status: [32] Missing email address
09:39:11.075 -> GUID: E158C7FD55631B3FD6103C85E3441963
09:39:11.075 -> Device name: SUPLA-ESP32
09:39:11.075 -> Device software version: SDK 25.11-dev
09:39:11.075 ->  *** Supla - Initializing network layer
09:39:11.075 -> [Wi-Fi] Network AP/hostname: SUPLA-ESP32-BCDDC2CD9250
09:39:11.075 -> Using Supla protocol version 23
09:39:11.075 -> Current status: [5] SuplaDevice initialized
09:39:11.075 -> Config incomplete: deviceMode = CONFIG
09:39:11.075 -> Disabling network setup, device work in not configured mode
09:39:11.075 -> LAST STATE ADDED: Not configured mode
09:39:11.075 -> Current status: [90] Not configured mode
09:39:11.075 -> [Wi-Fi] setOfflineMode
09:39:11.075 ->  *** Supla - Initialization done
09:39:11.123 ->  *** Self-test ***
09:39:11.123 -> TEST: ManufacturerID is 0
09:39:11.123 -> TEST failed: ProductID is empty
09:39:11.123 -> TEST failed: storage init result is false
09:39:11.123 -> TEST failed: missing public RSA key
09:39:11.123 -> TEST failed: automatic firmware update is disabled
09:39:11.123 -> TEST failed: config encryption is disabled
09:39:11.123 -> TEST failed: invalid certificates format
09:39:11.123 -> TEST failed: security log is disabled
09:39:11.123 ->  *** Self-test done ***
09:39:11.123 -> SuplaDevice.begin() => uruchomione.
09:39:11.123 -> Reset licznika opadów (początek godziny).
09:39:14.717 -> LittleFsConfig: writing to file "/supla-dev.cfg"
09:39:14.764 -> LittleFsConfig: writing to file "/supla-dev.cfg.bak"
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Problem widać w:
-> LittleFsConfig: init called on non empty database. Aborting

Pokaż kod tych Twoich klas, które dodałeś do Supli.

Zgaduję że w konstruktorze coś do Config dodajesz I potem się sypie.

Kilka dni temu ktoś miał podobny problem.
Wydaje mi się że dodałem zabezpieczanie na tą sytuację.
Sprawdź na źródłach z brancha main z repo
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
Bania
Posts: 107
Joined: Wed Jul 24, 2024 5:03 pm
Location: Bielsko-Biała
Has thanked: 5 times
Been thanked: 5 times

Post

Moim zdaniem pierwsze użyj przykładu:

https://github.com/SUPLA/supla-device/b ... lRelay.ino

Dzięki niemu sprawdzisz czy Twój ESP łączy się i czy nie ma jakiś błędów.
Później można dodawać kolejno: przycisk CFG, RSSI, zegar, sensory...
https://github.com/anarhbania/Supla
krzychunh
Posts: 53
Joined: Mon Jul 12, 2021 6:23 am

Post

klew wrote: Sat Jan 17, 2026 10:10 am Problem widać w:
-> LittleFsConfig: init called on non empty database. Aborting

Pokaż kod tych Twoich klas, które dodałeś do Supli.

Zgaduję że w konstruktorze coś do Config dodajesz I potem się sypie.

Kilka dni temu ktoś miał podobny problem.
Wydaje mi się że dodałem zabezpieczanie na tą sytuację.
Sprawdź na źródłach z brancha main z repo
Anemometr.cpp

Code: Select all

/*
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <Time.h>
#include "Anemometr.h"
#include <Arduino.h>
namespace Supla
{
  namespace Sensor
  {

    unsigned long lastWindTime;
    unsigned long stopSampling = 0;
    long Anemometr::_currentWindCount = 0;
    unsigned long Anemometr::_shortestWindTime = 0;

    void ICACHE_RAM_ATTR serviceInterruptAnem()
    {
      unsigned long currentTime = (unsigned long)(micros() - lastWindTime);

      lastWindTime = micros();
      if (currentTime > 1000) // debounce
      {
        Anemometr::_currentWindCount++;
        if (currentTime < Anemometr::_shortestWindTime)
        {
          Anemometr::_shortestWindTime = currentTime;
        }
      }
    }

    Anemometr::Anemometr(int pinAnem, double wind_factory, int selectedMode) : lastReadTime(0) // constructor
    {

      channel.setType(SUPLA_CHANNELTYPE_WINDSENSOR);
      channel.setDefault(SUPLA_CHANNELFNC_WINDSENSOR);
      channel.setNewValue((double)WIND_NOT_AVAILABLE);

      _pinAnem = pinAnem;
      _wind_factory = wind_factory;
      _currentWindCount = 0;
      _currentWindSpeed = 0.0;

      lastWindTime = 0;
      _shortestWindTime = 0xffffffff;

      _sampleTime = 5.0;
      _startSampleTime = micros();
    };

    double Anemometr::getValue() // in milliseconds
    {
#ifdef normalMode
      _currentWindSpeed = get_current_wind_speed_when_sampling();
      /*
      if (!_selectedMode)
      {
        _currentWindSpeed = get_current_wind_speed_when_sampling();
      }
      else
      {

        startWindSample(SAMPLETIME);
        _currentWindCount = 0;
        if(stopSampling > _sampleTime * 1000)
        {
          _currentWindSpeed = ((float)_currentWindCount / _sampleTime) * _wind_factory;
        }
        delay(_sampleTime * 1000);

      }
      */
      return _currentWindSpeed;
#else
      return 0.0;
#endif
    };

    void Anemometr::iterateAlways()
    {
      if (millis() - lastReadTime > 10000)
      {
        lastReadTime = millis();
        channel.setNewValue(getValue());
        Serial.print("Speed: ");
        Serial.println(getValue());
      }
    }

    float Anemometr::get_wind_gust()
    {
      unsigned long latestTime;
      latestTime = _shortestWindTime;
      _shortestWindTime = 0xffffffff;
      double time = latestTime / 1000000.0; // in microseconds

      return (1 / (time)) * _wind_factory / 2;
    };

    void Anemometr::reset_wind_gust()
    {
      _shortestWindTime = 0xffffffff;
    };

    void Anemometr::startWindSample(float sampleTime)
    {

      _startSampleTime = micros();

      _sampleTime = sampleTime;
    };

    float Anemometr::get_current_wind_speed_when_sampling()
    {

      unsigned long compareValue;
      compareValue = _sampleTime * 1000000;

      if (micros() - _startSampleTime >= compareValue)
      {
        // sample time exceeded, calculate currentWindSpeed
        float _timeSpan;
        //     _timeSpan = (unsigned long)(micros() - _startSampleTime);
        _timeSpan = (micros() - _startSampleTime);

        _currentWindSpeed = ((float)_currentWindCount / (_timeSpan)) * _wind_factory * 1000000;

        _currentWindCount = 0;

        _startSampleTime = micros();
      }
      else
      {
        // Serial.println("NOT Triggered");
        // Serial.print("time = ");
        // Serial.println(micros() - _startSampleTime);
        //  if not, then return last wind speed
      }
      return _currentWindSpeed;
    };

    void Anemometr::onInit()
    {

      pinMode(_pinAnem, INPUT_PULLUP);
      digitalWrite(_pinAnem, HIGH);
#ifdef normalMode
      attachInterrupt(digitalPinToInterrupt(_pinAnem), serviceInterruptAnem, FALLING);
#endif
      channel.setNewValue(getValue());
    }

  }; // namespace Sensor
}; // namespace Supla
Anemometr.h

Code: Select all

#ifndef _Anemometr_h
#define _Anemometr_h

#include "supla/channel.h"
#include "supla/element.h"

#define WIND_NOT_AVAILABLE -1
#define SAMPLETIME 5.0

namespace Supla
{
	namespace Sensor
	{
		class Anemometr : public Element
		{
		public:
			Anemometr(int pinAnem, double wind_factory, int selectedMode);

			float get_wind_gust();
			void reset_wind_gust();
			static unsigned long _shortestWindTime;
			static long _currentWindCount;
			friend void serviceInterruptAnem();
			virtual double getValue();
			void iterateAlways();
			void onInit();

		protected:
			Channel *getChannel()
			{
				return &channel;
			}
			Channel channel;

			unsigned long lastReadTime;
			double _wind_factory;
			int _pinAnem;
			int _selectedMode;
			unsigned long _startSampleTime;
			float _currentWindSpeed;
			void startWindSample(float sampleTime);
			float get_current_wind_speed_when_sampling();
			float _sampleTime;
		};

	}; // namespace Sensor
};	   // namespace Supla

#endif
HDC1080.h

Code: Select all

/*
Copyright (C) krycha88

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef _hdc1080_h
#define _hdc1080_h

// Dependency: Adafruid HDC1080 library - use library manager to install it
// https://github.com/closedcube/ClosedCube_HDC1080_Arduino

#include <ClosedCube_HDC1080.h>
#include <Wire.h>
#include <supla/sensor/therm_hygro_meter.h>

namespace Supla
{
  namespace Sensor
  {
    class HDC1080 : public ThermHygroMeter
    {
    public:
      HDC1080()
      {
      }

      double getTemp()
      {
        float value = TEMPERATURE_NOT_AVAILABLE;
#ifdef normalMode
        value = hdc1080.readTemperature();

        if (isnan(value))
        {
          value = TEMPERATURE_NOT_AVAILABLE;
        }
#endif

        return value;
      }

      double getHumi()
      {
        float value = HUMIDITY_NOT_AVAILABLE;
#ifdef normalMode
        value = hdc1080.readHumidity();

        if (isnan(value))
        {
          value = HUMIDITY_NOT_AVAILABLE;
        }
#endif
        return value;
      }

      void onInit() override
      {
#ifdef normalMode
        hdc1080.begin(0x40);

        Serial.print("Manufacturer ID=0x");
        Serial.println(hdc1080.readManufacturerId(),
                       HEX); // 0x5449 ID of Texas Instruments
        Serial.print("Device ID=0x");
        Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device

        Serial.print("Device Serial Number=");
        HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
        char format[15];
        sprintf(format,
                "%02X-%04X-%04X",
                sernum.serialFirst,
                sernum.serialMid,
                sernum.serialLast);
        Serial.println(format);
#endif
        channel.setNewValue(getTemp(), getHumi());
      }

    protected:
      ::ClosedCube_HDC1080 hdc1080; // I2C
    };

  }; // namespace Sensor
}; // namespace Supla

#endif
LightSensor.h

Code: Select all

#include <supla/channel_element.h>
#include "Adafruit_LTR390.h"
#include <supla/sensor/general_purpose_measurement.h>
namespace Supla
{
    namespace Sensor
    {

        class LightSensor : public GeneralPurposeMeasurement
        {
        public:
            LightSensor()
            {
                this->setInitialCaption("Natężenie światła");
                this->setDefaultUnitAfterValue("lx");
            };

            void onInit()
            {
#ifdef normalMode
                ltr = Adafruit_LTR390();
                ltr.begin();
                ltr.setGain(LTR390_GAIN_3);
                ltr.setResolution(LTR390_RESOLUTION_16BIT);
                ltr.setThresholds(100, 1000);
                ltr.configInterrupt(true, LTR390_MODE_ALS);
                ltr.setMode(LTR390_MODE_ALS);
#endif
            }

            double getValue()
            {
                /*
                if (ltr.newDataAvailable())
                {
                  ltr.setMode(LTR390_MODE_UVS);
                  Serial.print("UV data: ");
                  Serial.println(ltr.readUVS());
                }
                */
               #ifdef normalMode
                return ltr.readALS();
                #else
                return 0.0;
                #endif
            
            }

        protected:
            Adafruit_LTR390 ltr;
        };
    };
};
MS5611Sensor.h

Code: Select all

/*
Copyright (C) krycha88

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef _ms5611Sensor_h
#define _ms5611Sensor_h

// Dependency: MS5611 library - use library manager to install it
// https://github.com/RobTillaart/MS5611

#include <MS5611.h>
#include <Wire.h>
#include <supla/sensor/pressure.h>

namespace Supla
{
  namespace Sensor
  {
    class MS5611Sensor : public Supla::Sensor::Pressure
    {
    public:
      MS5611Sensor(int altitude)
      {
        this->altitude = altitude;
      }

      double getValue()
      {
        Serial.println(F("MS5611 getting pres."));

        float value = -123;
#ifdef normalMode
        int result = ms5611.read();
        if (result != MS5611_READ_OK)
        {
          Serial.print("Error in read: ");
          Serial.println(result);
        }
        else
        {
          value = ms5611.getPressure();
          float temp = ms5611.getTemperature();
          float multiplier = 0.0065;
          value = pow(((multiplier * altitude) / (temp + 273.15) + 1), 5.255) * value;
        }
#endif
        return value;
      }

      void onInit() override
      {
        Serial.println(F("MS5611 init."));
#ifdef normalMode
        ms5611 = MS5611(0x77);
        if (ms5611.begin() == true)
        {
          Serial.println("MS5611 found.");
        }
        else
        {
          Serial.println("MS5611 not found.");
        }
#endif
        channel.setNewValue(getValue(), -1.0);
      }

    protected:
      ::MS5611 ms5611; // I2C
      float altitude = 248;
    };

  }; // namespace Sensor
}; // namespace Supla

#endif
RainSensor.h

Code: Select all

#include <supla/sensor/rain.h>
namespace Supla
{
    namespace Sensor
    {

        unsigned long _lastRainTime;
        unsigned long _currentRainMin;
        double _bucketSize;
        double _currentRainCount;
        int debounceTimeGlobal = 0;
        void ICACHE_RAM_ATTR rain_detect()
        {
            unsigned long currentTime = (unsigned long)(micros() - _lastRainTime);

            _lastRainTime = micros();
            if (currentTime > debounceTimeGlobal) // debounce
            {
                _currentRainCount += 1;

                if (currentTime < _currentRainMin)
                {
                    _currentRainMin = currentTime;
                }
            }
        }

        class RainSensor : public Supla::Sensor::Rain
        {
        public:
            RainSensor(int pinRain, double bucketSize, int debounceTime)
            {
                channel.setType(SUPLA_CHANNELTYPE_RAINSENSOR);
                channel.setDefault(SUPLA_CHANNELFNC_RAINSENSOR);
                channel.setNewValue(RAIN_NOT_AVAILABLE);
                _bucketSize = bucketSize;
                _pinRain = pinRain;
                debounceTimeGlobal = debounceTime;
            };

            void onInit() override
            {
                // pinMode(_pinRain, INPUT_PULLUP);
                #ifdef normalMode
                attachInterrupt(digitalPinToInterrupt(_pinRain), rain_detect, FALLING);
                #endif
                channel.setNewValue(getValue());
            }
            double getValue()
            {
                return _currentRainCount * _bucketSize;
            }

            void iterateAlways()
            {
                if (millis() -lastReadTime > 10000)
                {
                    lastReadTime = millis();
                    channel.setNewValue(getValue());
                }
            }

            void setReset(bool value)
            {
                if (value)
                    _currentRainCount = 0;
            }

        protected:
            int _pinRain;
            bool _reset;

            unsigned long _lastReadTime;
        };
    };
};
SPS30Sensor.h

Code: Select all

/*
  Copyright (C) krycha88

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef _sps30_h
#define _sps30_h

#include <Arduino.h>
#include <supla/sensor/general_purpose_measurement.h>
#include <supla/element.h>
#include <sps30.h>

namespace Supla
{
  namespace Sensor
  {
    // 1, 2.5, 4. , 10
    class SPS30_X : public Element
    {
    public:
      explicit SPS30_X()
      {
      }

      void iterateAlways()
      {

        if (millis() - lastReadTime > 60000)
        { // 1min
          lastReadTime = millis();
#ifdef normalMode

          {
            do
            {

              ret = sps30_read_data_ready(&data_ready);
              if (ret < 0)
              {
                Serial.print("error reading data-ready flag: ");
                Serial.println(ret);
              }
              else if (!data_ready)
                Serial.print("data not ready, no new measurement available\n");
              else
                break;
              delay(100);
            } while (1);

            ret = sps30_read_measurement(&m);
          }
          
#endif
        }
      }

      void onInit() override
      {

        lastReadTime = millis();
        Serial.println(F("Turning ON SPS sensor"));
#ifdef normalMode

        sensirion_i2c_init();
        while (sps30_probe() != 0)
        {
          Serial.print("SPS sensor probing failed\n");
          delay(500);
        }

        ret = sps30_set_fan_auto_cleaning_interval_days(auto_clean_days);
        if (ret)
        {
          Serial.print("error setting the auto-clean interval: ");
          Serial.println(ret);
        }

        ret = sps30_start_measurement();
        if (ret < 0)
        {
          Serial.print("error starting measurement\n");
        }

#ifndef PLOTTER_FORMAT
        Serial.print("measurements started\n");
        
#endif

#endif
      }

      sps30_measurement getMeasurement()
      {
        return this->m;
      }

    protected:
      unsigned long lastSleepTime = 0;
      unsigned long lastReadTime = 0;
      bool sleepSensor = false;
      int16_t ret;
      uint8_t auto_clean_days = 4;
      uint32_t auto_clean;
      uint16_t data_ready;
      struct sps30_measurement m;
    };

    class SPS30_PM005 : public GeneralPurposeMeasurement
    {
    public:
      SPS30_PM005(SPS30_X *sensor)
      {
        sps30 = sensor;
        this->setInitialCaption("PM 0.5");
        this->setDefaultUnitAfterValue("μg/m³");
        this->setRefreshIntervalMs(60000);
      }

      double getValue()
      {
        double value = 0.0;
        auto measurement = sps30->getMeasurement();
        if (measurement.nc_0p5 > 0.0)
        {
          value = measurement.nc_0p5;
        }
        return value;
      }

    protected:
      SPS30_X *sps30;
    };

    class SPS30_PM01 : public GeneralPurposeMeasurement
    {
    public:
      SPS30_PM01(SPS30_X *sensor)
      {
        sps30 = sensor;

        this->setDefaultUnitAfterValue("μg/m³");
        this->setInitialCaption("PM 1.0");
        this->setRefreshIntervalMs(60000);
      }

      double getValue()
      {
        double value = 0.0;
        auto measurement = sps30->getMeasurement();
        if (measurement.nc_1p0 - measurement.nc_0p5 > 0.0)
        {
          value = measurement.nc_1p0 - measurement.nc_0p5;
        }
        return value;
      }

    protected:
      SPS30_X *sps30;
    };

    class SPS30_PM025 : public GeneralPurposeMeasurement
    {
    public:
      SPS30_PM025(SPS30_X *sensor)
      {
        sps30 = sensor;

        this->setDefaultUnitAfterValue("μg/m³");
        this->setInitialCaption("PM 2.5");
        this->setRefreshIntervalMs(60000);
      }

      double getValue()
      {
        double value = 0.0;
        auto measurement = sps30->getMeasurement();
        if (measurement.nc_2p5 - measurement.nc_1p0 > 0.0)
        {
          value = measurement.nc_2p5 - measurement.nc_1p0;
        }
        return value;
      }

    protected:
      SPS30_X *sps30;
    };

    class SPS30_PM04 : public GeneralPurposeMeasurement
    {
    public:
      SPS30_PM04(SPS30_X *sensor)
      {
        sps30 = sensor;

        this->setDefaultUnitAfterValue("μg/m³");
        this->setInitialCaption("PM 4.0");
        this->setRefreshIntervalMs(60000);
      }

      double getValue()
      {
        double value = 0.0;
        auto measurement = sps30->getMeasurement();
        if (measurement.nc_4p0 - measurement.nc_2p5 > 0.0)
        {
          value = measurement.nc_4p0 - measurement.nc_2p5;
        }
        return value;
      }

    protected:
      SPS30_X *sps30;
    };

    class SPS30_PM10 : public GeneralPurposeMeasurement
    {
    public:
      SPS30_PM10(SPS30_X *sensor)
      {
        sps30 = sensor;

        this->setDefaultUnitAfterValue("μg/m³");
        this->setInitialCaption("PM 10.0");
        this->setRefreshIntervalMs(60000);
      }

      double getValue()
      {
        double value = 0.0;
        auto measurement = sps30->getMeasurement();
        if (measurement.nc_10p0 - measurement.nc_4p0 > 0.0)
        {
          value = measurement.nc_10p0 - measurement.nc_4p0;
        }
        return value;
      }

    protected:
      SPS30_X *sps30;
    };

  } // namespace Sensor
} // namespace Supla

#endif
VoltageSensor.h

Code: Select all

#include <Arduino.h>
#include <SuplaDevice.h>

namespace Supla
{
  namespace Sensor
  {
    class VoltageMeasurement : public Element
    {
    public:
      VoltageMeasurement(int pinDirection);

      void iterateAlways();
      void onInit();

    protected:
      Channel *getChannel()
      {
        return &channel;
      }
      Channel channel;
      unsigned long lastSendTime;
      int _pinInput;
    };
    VoltageMeasurement::VoltageMeasurement(int pin) : lastSendTime(0) // constructor
    {
      _pinInput = pin;
      pinMode(_pinInput, INPUT);
      analogSetPinAttenuation(_pinInput, ADC_11db);
      channel.setType(SUPLA_CHANNELTYPE_THERMOMETER);
      channel.setDefault(SUPLA_CHANNELFNC_THERMOMETER);
      channel.setNewValue(0.0);
    };

    void VoltageMeasurement::iterateAlways()
    {

      if (lastSendTime + 10000 < millis())
      {
        lastSendTime = millis();
        int mv = analogReadMilliVolts(_pinInput);
        Serial.print("Analog read of voltage:");
        Serial.println(mv);
        // 2.686 - 8.4
        //  read - x
        channel.setNewValue(mv * 8400 / 2686 / 1000.0);
      }
    }

    void VoltageMeasurement::onInit()
    {
      channel.setNewValue(0.0);
    }

  }; // namespace Sensor
}; // namespace Supla
WindDirection.cpp

Code: Select all

/*
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <Time.h>
#include "WindDirection.h"
#include <Arduino.h>
namespace Supla
{
  namespace Sensor
  {

    WindDirectionSensor::WindDirectionSensor(int pinDirection, int angleAdjustmentToNorth) : lastReadTime(0), lastSendTime(0) // constructor
    {
      _pinDirection = pinDirection;
      _angleAdjustmentToNorth = angleAdjustmentToNorth;
      channel.setType(SUPLA_CHANNELTYPE_THERMOMETER);
      channel.setDefault(SUPLA_CHANNELFNC_THERMOMETER);
      channel.setNewValue(0.0);
    };

    void WindDirectionSensor::iterateAlways()
    {
#ifdef normalMode
      if (millis() - lastReadTime > 1000)
      {
        lastReadTime = millis();
        averageAngle.add(as5600.rawAngle() * AS5600_RAW_TO_DEGREES + _angleAdjustmentToNorth);
      }
      if (millis() - lastSendTime > 10000)
      {
        lastSendTime = millis();
        channel.setNewValue(averageAngle.getAverage());
        Serial.print("Wind direction: ");
        Serial.println(averageAngle.getAverage());
        averageAngle.reset();
      }
#endif
    }

    void WindDirectionSensor::onInit()
    {
#ifdef normalMode
      as5600.begin(_pinDirection);            //  set direction pin.
      as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
#endif
      channel.setNewValue(0.0);
      averageAngle = AverageAngle(AverageAngle::DEGREES);
      averageAngle.reset();
    }

  }; // namespace Sensor
}; // namespace Supla
WindDirection.h

Code: Select all

#ifndef _WindDirection_h
#define _WindDirection_h

#include "supla/channel.h"
#include "supla/element.h"
#include "AS5600.h"
#include "AverageAngle.h"
namespace Supla
{
    namespace Sensor
    {
        class WindDirectionSensor : public Element
        {
        public:
            WindDirectionSensor(int pinDirection, int angleAdjustmentToNorth);

            void iterateAlways();
            void onInit();

        protected:
            Channel *getChannel()
            {
                return &channel;
            }
            Channel channel;
            AS5600 as5600;
            AverageAngle averageAngle;
            unsigned long lastReadTime;
            unsigned long lastSendTime;
            int _pinDirection;
            int _angleAdjustmentToNorth;
        };

    }; // namespace Sensor
};     // namespace Supla

#endif
krzychunh
Posts: 53
Joined: Mon Jul 12, 2021 6:23 am

Post

Bania wrote: Sat Jan 17, 2026 11:03 am Moim zdaniem pierwsze użyj przykładu:

https://github.com/SUPLA/supla-device/b ... lRelay.ino

Dzięki niemu sprawdzisz czy Twój ESP łączy się i czy nie ma jakiś błędów.
Później można dodawać kolejno: przycisk CFG, RSSI, zegar, sensory...

Połączył się jest widoczny przełącznik w Supli :)
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Na pierwszy rzut oka nie widzę przyczyny.
Wyrzuć wszystko z programu, zacznij od prawie pustego przykładu i dodawaj po kolei.
Najlepsze suple dla Twojego domu :mrgreen:
krzychunh
Posts: 53
Joined: Mon Jul 12, 2021 6:23 am

Post

Wyrzuciłem wpis sps30 i oto jest efekt. Zastanawiam się w czym może być problem

Image

Return to “FAQ / Jak to zrobić”