Jak przesłać dane z apk do urządzenia?

User avatar
klew
Posts: 13911
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 136 times
Been thanked: 137 times

Post

SOYER wrote: Sun Mar 12, 2023 12:22 pm Teraz jeszcze sprawdziłem w serial monitorze, wprawdzie nie wiem co tam się powinno drukować przy zapisie, ale po zmianie wartości prze virtual relay i wyświetleniu jej na termometrze, nie widzę żadnych zapisów o storage na serialu.
A masz dodaną instancję klasy storage, np Supla::eeprom?
Prawie w każdym przykładzie w bibliotece ją znajdziesz
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

Dzięki, znalazłem na forum,

Code: Select all

#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom(0);
dopisałem do szkicu i zaczęło zapisywać w pamięci, ale:
po każdym resecie wartość jest mniejsza o 1 step od tej zostawionej przed resetem. Niezależnie czy przed resetem podnosiłem wartość, obniżałem, czy nic nie robiłem. Po resecie jest mniejsza o 1(bo step ustawiłem na 1).

Code: Select all

class RelayAsInput : public Supla::Control::VirtualRelay {
 public:
  explicit RelayAsInput(int step = 1) : step(step) {
  }
  virtual ~RelayAsInput() {}

  void turnOn(_supla_int_t duration = 0) override {
    (void)(duration);
    int newTemp = temp.getValue() + step;
    if (newTemp > 90) {
      newTemp = 90;
    }
    temp.setValue(newTemp);
    tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;
    Supla::Storage::ScheduleSave(2000);
  }

  void turnOff(_supla_int_t duration = 0) override {
    (void)(duration);
    int newTemp = temp.getValue() - step;
    if (newTemp < 5) {
      newTemp = 5;
    }
    temp.setValue(newTemp);
    tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;
    Supla::Storage::ScheduleSave(2000);
  }

  int getValue() {
    return temp.getValue();
  }

  void setValue(int value) {
    temp.setValue(value);
    Supla::Storage::ScheduleSave(2000);
  }

  void onLoadState() override {
    int temperature = 0;
    Supla::Storage::ReadState(reinterpret_cast<unsigned char *>(&temperature),
                              sizeof(int));
    temp.setValue(temperature);
    tempON = temperature;
  }

  void onSaveState() override {
    int temperature = temp.getValue();
    Supla::Storage::WriteState(reinterpret_cast<unsigned char *>(&temperature),
                               sizeof(int));
  }

 protected:
  Supla::Sensor::VirtualThermometer temp;
  int step = 1;
};
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
klew
Posts: 13911
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 136 times
Been thanked: 137 times

Post

Może za szybko resetujesz? Zapis jest robiony 2s po użyciu Relay.

Nie jest też dobrym pomysłem modyfikacja tej klasy i wstawianie tam odwołań do zmiennych globalnych.
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

Resetuję po dłuższym czasie niż 2s. Zresztą napisałem, że niezależnie czy przed resetem zwiększałem, zmniejszałem czy nic nie robiłem to i tak po resecie wartość jest mniejsza o 1.
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

Zakomentowałem te moje dodatkowe linijki i program zachowuje się tak samo. Po resecie wartość mniejsza o 1. :shock:
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

Code: Select all

class RelayAsInput : public Supla::Control::VirtualRelay {
 public:
  explicit RelayAsInput(int step = 1) : step(step) {
  }
  virtual ~RelayAsInput() {}

  void turnOn(_supla_int_t duration = 0) override {
    (void)(duration);
    int newTemp = temp.getValue() + step;
    if (newTemp > 90) {
      newTemp = 90;
    }
    temp.setValue(newTemp);
    /*tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;*/
    Supla::Storage::ScheduleSave(2000);
  }

  void turnOff(_supla_int_t duration = 0) override {
    (void)(duration);
    int newTemp = temp.getValue() - step;
    if (newTemp < 5) {
      newTemp = 5;
    }
    temp.setValue(newTemp);
   /* tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;*/
    Supla::Storage::ScheduleSave(2000);
  }

  int getValue() {
    return temp.getValue();
  }

  void setValue(int value) {
    temp.setValue(value);
    Supla::Storage::ScheduleSave(2000);
  }

  void onLoadState() override {
    int temperature = 0;
    Supla::Storage::ReadState(reinterpret_cast<unsigned char *>(&temperature),
                              sizeof(int));
    temp.setValue(temperature);
    //tempON = temperature;
  }

  void onSaveState() override {
    int temperature = temp.getValue();
    Supla::Storage::WriteState(reinterpret_cast<unsigned char *>(&temperature),
                               sizeof(int));
  }

 protected:
  Supla::Sensor::VirtualThermometer temp;
  int step = 1;
};

class RelayAsInput1 : public Supla::Control::VirtualRelay {//////////HISTEREZA
 public:
  explicit RelayAsInput1(int step = 1) : step(step) {
  }
  virtual ~RelayAsInput1() {}

  void turnOn(_supla_int_t duration = 0) override {
    (void)(duration);
    int newTemp = temp.getValue() + step;
    if (newTemp > 20) {
      newTemp = 20;
    }
    temp.setValue(newTemp);
   /* histereza = newTemp;
    sekund5.restart();
     if(menu != SZESC){
      lcd.clear();
     }
    menu = SZESC;*/
    Supla::Storage::ScheduleSave(2000);
  }

  void turnOff(_supla_int_t duration = 0) override {
    (void)(duration);
    int newTemp = temp.getValue() - step;
    if (newTemp < 1) {
      newTemp = 1;
    }
    temp.setValue(newTemp);
   /* histereza = newTemp;
    sekund5.restart();
     if(menu != SZESC){
      lcd.clear();
     }
    menu = SZESC;*/
    Supla::Storage::ScheduleSave(2000);
  }

  int getValue() {
    return temp.getValue();
  }

  void setValue(int value) {
    temp.setValue(value);
    Supla::Storage::ScheduleSave(2000);
  }

  void onLoadState() override {
    int temperature = 0;
    Supla::Storage::ReadState(reinterpret_cast<unsigned char *>(&temperature),
                              sizeof(int));
    temp.setValue(temperature);
    //histereza = temperature;
  }

  void onSaveState() override {
    int temperature = temp.getValue();
    Supla::Storage::WriteState(reinterpret_cast<unsigned char *>(&temperature),
                               sizeof(int));
  }

 protected:
  Supla::Sensor::VirtualThermometer temp;
  int step = 1;
};
Może to ma coś z tym wspólnego, bo dołożyłem jeszcze kod do obsługi histerezy. Zachowuje się tak samo, tzn po resecie wartość mniejsza o 1, ale może jakoś to się gryzie? Nie wiem, nie znam się.
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

Po serialu widać, że program dekrementuje te zmienne po uruchomieniu, jeśli to dobrze interpretuję, to odczyt następuje prawidłowo, tylko potem następuje obniżenie o 1, tylko dlaczego?
To są kanały 2 i 4.

16:31:44.933 -> ⸮⸮Creating OneWire bus for pin: 13
16:31:45.418 -> Initializing OneWire bus at pin 13
16:31:45.418 -> OneWire(pin 13) Parasite power is OFF
16:31:45.418 -> OneWire(pin 13) Found 1 devices:
16:31:45.418 -> Index 0 - address {0x28, 0xF2, 0xDF, 0x57, 0x04, 0xE1, 0x3C, 0x5F}
16:31:46.339 -> Supla - starting initialization
16:31:46.339 -> Storage initialization
16:31:46.339 -> readStorage: 8; Read: [53 55 50 4C 41 1 0 1 ]
16:31:46.339 -> Storage: Number of sections 1
16:31:46.339 -> Reading section: 0
16:31:46.339 -> readStorage: 7; Read: [3 12 0 14 8 14 8 ]
16:31:46.339 -> Section type: 3; size: 18
16:31:46.339 -> CRC1 2068, CRC2 2068, CRC calc 2068
16:31:46.339 -> Config storage not configured
16:31:46.339 -> Validating storage state section with current device configuration
16:31:46.839 -> Storage state section validation completed. Loading elements state...
16:31:46.839 -> readStorage: 4; Read: [1E 0 0 0 ]
16:31:46.839 -> readStorage: 4; Read: [2 0 0 0 ]
16:31:46.839 -> readStorage: 4; Read: [0 0 0 0 ]
16:31:46.839 -> readStorage: 1; Read: [0 ]
16:31:46.839 -> readStorage: 4; Read: [0 0 0 0 ]
16:31:46.839 -> readStorage: 1; Read: [0 ]
16:31:46.839 -> Channel(0) value changed to 25.6
16:31:46.839 -> Channel(2) value changed to 29.0
16:31:46.839 -> Channel(4) value changed to 1.0
16:31:46.839 -> Relay[5] turn OFF (duration 0 ms)
16:31:46.839 -> **** Digital write[5], gpio: 14; value 1
16:31:47.339 -> Relay[5] turn OFF (duration 0 ms)
16:31:47.339 -> **** Digital write[5], gpio: 14; value 1
16:31:47.339 -> Relay[6] turn OFF (duration 0 ms)
16:31:47.339 -> **** Digital write[6], gpio: 12; value 1
16:31:47.339 -> Relay[6] turn OFF (duration 0 ms)
16:31:47.339 -> **** Digital write[6], gpio: 12; value 1
16:31:47.339 -> Initializing network layer
16:31:47.339 -> Network AP/hostname: SUPLA-ESP8266-C45BBEE3C8DC
16:31:47.339 -> Using Supla protocol version 16
16:31:47.339 -> Current status: [5] SuplaDevice initialized
16:31:47.339 -> Enter normal mode
16:31:48.355 -> Wrote 4 bytes to storage at 15
16:31:48.839 -> Wrote 4 bytes to storage at 19
16:31:48.839 -> Wrote 7 bytes to storage at 8
16:31:48.839 -> Commit
16:31:49.339 -> WiFi: establishing connection with SSID: "WWW.MULTI-TELEKOM.PL_23g"
16:31:49.339 -> Relay[6] turn OFF (duration 0 ms)
16:31:49.339 -> **** Digital write[6], gpio: 12; value 1
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

Code: Select all

class RelayAsInput : public Supla::Control::VirtualRelay {
 public:
  explicit RelayAsInput(int step = 1) : step(step) {
  }
  virtual ~RelayAsInput() {}

  void turnOn(_supla_int_t duration = 0) override {
      Serial.print("!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////  4  ");
  Serial.println(tempON);
    (void)(duration);
    int newTemp = temp.getValue() + step;
    if (newTemp > 90) {
      newTemp = 90;
    }
    temp.setValue(newTemp);
    tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;
      Serial.print("!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////  5  ");
  Serial.println(tempON);
    Supla::Storage::ScheduleSave(2000);
  }

  void turnOff(_supla_int_t duration = 0) override {
      Serial.print("!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////   6 ");
  Serial.println(tempON);
    (void)(duration);
    int newTemp = temp.getValue() - step;
    if (newTemp < 5) {
      newTemp = 5;
    }
    temp.setValue(newTemp);
    tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;
      Serial.print("!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////  7  ");
  Serial.println(tempON);
    Supla::Storage::ScheduleSave(2000);
  }

  int getValue() {
    return temp.getValue();
  }

  void setValue(int value) {
    temp.setValue(value);
    Supla::Storage::ScheduleSave(2000);
  }

  void onLoadState() override {
    int temperature = 0;
    Supla::Storage::ReadState(reinterpret_cast<unsigned char *>(&temperature),
                              sizeof(int));
    temp.setValue(temperature);
    tempON = temperature;
  }

  void onSaveState() override {
    int temperature = temp.getValue();
    Supla::Storage::WriteState(reinterpret_cast<unsigned char *>(&temperature),
                               sizeof(int));
  }

 protected:
  Supla::Sensor::VirtualThermometer temp;
  int step = 1;
};
16:54:14.103 -> Creating OneWire bus for pin: 13
16:54:14.103 -> Initializing OneWire bus at pin 13
16:54:14.150 -> OneWire(pin 13) Parasite power is OFF
16:54:14.244 -> OneWire(pin 13) Found 1 devices:
16:54:14.244 -> Index 0 - address {0x28, 0xF2, 0xDF, 0x57, 0x04, 0xE1, 0x3C, 0x5F}
16:54:14.713 -> Supla - starting initialization
16:54:14.713 -> Storage initialization
16:54:14.713 -> readStorage: 8; Read: [53 55 50 4C 41 1 0 1 ]
16:54:14.807 -> Storage: Number of sections 1
16:54:14.807 -> Reading section: 0
16:54:14.807 -> readStorage: 7; Read: [3 12 0 E2 4A E2 4A ]
16:54:14.900 -> Section type: 3; size: 18
16:54:14.947 -> CRC1 19170, CRC2 19170, CRC calc 19170
16:54:14.947 -> Config storage not configured
16:54:14.994 -> Validating storage state section with current device configuration
16:54:15.041 -> Storage state section validation completed. Loading elements state...
16:54:15.135 -> readStorage: 4; Read: [1D 0 0 0 ]
16:54:15.182 -> readStorage: 4; Read: [4 0 0 0 ]
16:54:15.182 -> readStorage: 4; Read: [0 0 0 0 ]
16:54:15.228 -> readStorage: 1; Read: [0 ]
16:54:15.275 -> readStorage: 4; Read: [0 0 0 0 ]
16:54:15.275 -> readStorage: 1; Read: [0 ]
16:54:15.322 -> Channel(0) value changed to 25.68
16:54:15.369 -> !!!!!!!!!!!!!!!!!!!!!!!!!/////////////////// 6 29
16:54:15.416 -> !!!!!!!!!!!!!!!!!!!!!!!!!/////////////////// 7 28
16:54:15.510 -> Channel(2) value changed to 28.0
16:54:15.510 -> Channel(4) value changed to 3.0
16:54:15.557 -> Relay[5] turn OFF (duration 0 ms)
16:54:15.603 -> **** Digital write[5], gpio: 14; value 1
16:54:15.650 -> Relay[5] turn OFF (duration 0 ms)
16:54:15.650 -> **** Digital write[5], gpio: 14; value 1
16:54:15.744 -> Relay[6] turn OFF (duration 0 ms)
16:54:15.744 -> **** Digital write[6], gpio: 12; value 1
16:54:15.791 -> Relay[6] turn OFF (duration 0 ms)
16:54:15.838 -> **** Digital write[6], gpio: 12; value 1
16:54:15.838 -> Initializing network layer

Ewidentnie przy odpalaniu widzi kliknięcie na OFF i dekrementuje zmienną, ale dlaczego?
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
SOYER
Posts: 1623
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry
Been thanked: 2 times

Post

i jeszcze na oryginalnych wartościach:

Code: Select all

class RelayAsInput : public Supla::Control::VirtualRelay {
 public:
  explicit RelayAsInput(int step = 1) : step(step) {
  }
  virtual ~RelayAsInput() {}

  void turnOn(_supla_int_t duration = 0) override {

    (void)(duration);
    int newTemp = temp.getValue() + step;
    if (newTemp > 90) {
      newTemp = 90;
    }
    temp.setValue(newTemp);
    tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;
    Supla::Storage::ScheduleSave(2000);
  }

  void turnOff(_supla_int_t duration = 0) override {
      Serial.print("!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////   1 ");
  Serial.println(temp.getValue());
    (void)(duration);
    int newTemp = temp.getValue() - step;
    if (newTemp < 5) {
      newTemp = 5;
    }
    temp.setValue(newTemp);
    tempON = newTemp;
    sekund5.restart();
     if(menu != PIEC){
      lcd.clear();
     }
    menu = PIEC;
      Serial.print("!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////  2  ");
  Serial.println(temp.getValue());
    Supla::Storage::ScheduleSave(2000);
  }

  int getValue() {
    return temp.getValue();
  }

  void setValue(int value) {
    temp.setValue(value);
    Supla::Storage::ScheduleSave(2000);
  }

  void onLoadState() override {
    int temperature = 0;
    Supla::Storage::ReadState(reinterpret_cast<unsigned char *>(&temperature),
                              sizeof(int));
    temp.setValue(temperature);
    tempON = temperature;
  }

  void onSaveState() override {
    int temperature = temp.getValue();
    Supla::Storage::WriteState(reinterpret_cast<unsigned char *>(&temperature),
                               sizeof(int));
  }

 protected:
  Supla::Sensor::VirtualThermometer temp;
  int step = 1;
};
17:05:53.157 -> ⸮bn⸮n⸮⸮⸮Creating OneWire bus for pin: 13
17:05:53.298 -> Initializing OneWire bus at pin 13
17:05:53.345 -> OneWire(pin 13) Parasite power is OFF
17:05:53.392 -> OneWire(pin 13) Found 1 devices:
17:05:53.438 -> Index 0 - address {0x28, 0xF2, 0xDF, 0x57, 0x04, 0xE1, 0x3C, 0x5F}
17:05:53.857 -> Supla - starting initialization
17:05:53.904 -> Storage initialization
17:05:53.904 -> readStorage: 8; Read: [53 55 50 4C 41 1 0 1 ]
17:05:53.951 -> Storage: Number of sections 1
17:05:53.997 -> Reading section: 0
17:05:53.997 -> readStorage: 7; Read: [3 12 0 B5 71 B5 71 ]
17:05:54.044 -> Section type: 3; size: 18
17:05:54.091 -> CRC1 29109, CRC2 29109, CRC calc 29109
17:05:54.138 -> Config storage not configured
17:05:54.185 -> Validating storage state section with current device configuration
17:05:54.232 -> Storage state section validation completed. Loading elements state...
17:05:54.279 -> readStorage: 4; Read: [1C 0 0 0 ]
17:05:54.326 -> readStorage: 4; Read: [3 0 0 0 ]
17:05:54.372 -> readStorage: 4; Read: [0 0 0 0 ]
17:05:54.419 -> readStorage: 1; Read: [0 ]
17:05:54.419 -> readStorage: 4; Read: [0 0 0 0 ]
17:05:54.466 -> readStorage: 1; Read: [0 ]
17:05:54.513 -> Channel(0) value changed to 25.75
17:05:54.513 -> !!!!!!!!!!!!!!!!!!!!!!!!!/////////////////// 1 28.00
17:05:54.607 -> !!!!!!!!!!!!!!!!!!!!!!!!!/////////////////// 2 27.00
17:05:54.654 -> Channel(2) value changed to 27.0
17:05:54.701 -> Channel(4) value changed to 2.0
17:05:54.747 -> Relay[5] turn OFF (duration 0 ms)
17:05:54.747 -> **** Digital write[5], gpio: 14; value 1
17:05:54.794 -> Relay[5] turn OFF (duration 0 ms)
17:05:54.841 -> **** Digital write[5], gpio: 14; value 1
17:05:54.888 -> Relay[6] turn OFF (duration 0 ms)
17:05:54.935 -> **** Digital write[6], gpio: 12; value 1
17:05:54.982 -> Relay[6] turn OFF (duration 0 ms)
17:05:54.982 -> **** Digital write[6], gpio: 12; value 1
17:05:55.076 -> Initializing network layer
https://youtube.com/@tomaszhamer8134?si=_J1cT_QWsXxgt1Fm
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603
https://github.com/Soyer79
User avatar
klew
Posts: 13911
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 136 times
Been thanked: 137 times

Post

Turn off jest uruchamiane przy starcie urządzenia ;)
Poprawię to
Najlepsze suple dla Twojego domu :mrgreen:

Return to “Pomoc”