Modyfikacja przykładu WebInterface Arduino

petione
Posts: 121
Joined: Sat Jul 21, 2018 4:26 pm

Post

klew wrote: Sat Jan 25, 2025 8:43 am
petione wrote: Sat Jan 25, 2025 8:28 am Dzięki.
Pojawil mi sie natomiast jeszcze jeden niespodziewany poroblem. A mianowicie zapis do pamieci wlasnych zmiennych.
Do zapisu stosuje Preferences. Teoretycznie nie powinny kolidowac z metodą zapisu Supli a jednak cos sie gryzie. Opinie opieram na podstawie;

https://forum.supla.org/viewtopic.php?t=12427

Wszystko dziala poprawnie do momentu przeladowania WWW lub naciśnięciu Save. Gdy strona sie przeladuje lub nacisne Save zapis juz jest nieprawidlowy.. Masz koze pomysl co moze kolidować?
Jeśli mowa o tym samym preferences co w tamtym wątku to powinno być ok. Pokaż kod i logi
Chyba to nie to samo Preferences, bo to jest dla ESP8266 z https://github.com/vshymanskyy/Preferences
aczkolwiek normalnie działające.

Poniżej czysty kod Webinterface

Code: Select all

#include <Arduino.h>
/*
  Copyright (C) AC SOFTWARE SP. Z O.O.

  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.
*/

/* This example shows ESP82xx/ESP32 based device with simple WebInterface
 * used to configure Wi-Fi parameters and Supla server connection.
 * There is one RollerShutter, one Relay and 3 buttons configured.
 * Two buttons are for roller shutter with Action Trigger.
 * Third button is for controlling the relay and for switching module to
 * config mode.
 * After fresh installation, device will be in config mode. It will have its
 * own Wi-Fi AP configured. You should connect to it with your mobile phone
 * and open http://192.168.4.1 where you can configure the device.
 * Status LED is also configured. Please adjust GPIOs to your HW.
 */

#define STATUS_LED_GPIO 2
#define ROLLER_SHUTTER_UP_RELAY_GPIO 4
#define ROLLER_SHUTTER_DOWN_RELAY_GPIO 5
#define RELAY_GPIO 12
#define BUTTON_UP_GPIO 13
#define BUTTON_DOWN_GPIO 14
#define BUTTON_CFG_RELAY_GPIO 0

#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/roller_shutter.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
#include <supla/control/action_trigger.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 <Preferences.h>
Preferences prefs; // https://github.com/vshymanskyy/Preferences
#include <Timers.h>
Timer Timer1;

// Choose where Supla should store roller shutter data in persistent memory
// We recommend to use external FRAM memory
#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom;
// #include <supla/storage/fram_spi.h>
// Supla::FramSpi fram(STORAGE_OFFSET);

Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;

Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
Supla::EspWebServer suplaServer;

// HTML www component (they appear in sections according to creation
// sequence)
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Html::StatusLedParameters htmlStatusLed;

uint16_t rawData[71] = {8998, 4552, 504, 620, 504, 620, 504, 1744, 504, 620, 504, 620, 504, 620, 504, 620, 504, 620, 502, 1718, 530, 1744, 504, 620, 504, 1744, 504, 1744, 504, 1718, 528, 1744, 504, 1744, 504, 592, 530, 620, 504, 592, 530, 1718, 532, 594, 530, 596, 528, 622, 502, 620, 504, 1744, 504, 1746, 502, 1716, 532, 594, 530, 1746, 502, 1744, 504, 1744, 504, 1718, 530, 40338, 8970, 2300, 333};

void setup()
{

  Serial.begin(115200);
  Timer1.begin(2000);

  // Channels configuration
  // CH 0 - Roller shutter
  auto rs = new Supla::Control::RollerShutter(
      ROLLER_SHUTTER_UP_RELAY_GPIO, ROLLER_SHUTTER_DOWN_RELAY_GPIO, true);
  // CH 1 - Relay
  auto r1 = new Supla::Control::Relay(RELAY_GPIO);
  // CH 2 - Action trigger
  auto at1 = new Supla::Control::ActionTrigger();
  // CH 3 - Action trigger
  auto at2 = new Supla::Control::ActionTrigger();
  // CH 4 - Action trigger
  auto at3 = new Supla::Control::ActionTrigger();

  // Buttons configuration
  auto buttonOpen = new Supla::Control::Button(BUTTON_UP_GPIO, true, true);
  auto buttonClose = new Supla::Control::Button(BUTTON_DOWN_GPIO, true, true);
  auto buttonCfgRelay =
      new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);

  buttonOpen->addAction(Supla::OPEN_OR_STOP, *rs, Supla::ON_PRESS);
  buttonOpen->setHoldTime(1000);
  buttonOpen->setMulticlickTime(300);

  buttonClose->addAction(Supla::CLOSE_OR_STOP, *rs, Supla::ON_PRESS);
  buttonClose->setHoldTime(1000);
  buttonClose->setMulticlickTime(300);

  buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
  buttonCfgRelay->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1);

  // Action trigger configuration
  at1->setRelatedChannel(rs);
  at1->attach(buttonOpen);

  at2->setRelatedChannel(rs);
  at2->attach(buttonClose);

  at3->setRelatedChannel(r1);
  at3->attach(buttonCfgRelay);

  // configure defualt Supla CA certificate
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);

  SuplaDevice.begin();
  prefs.begin("key");
}

void loop()
{
  //TODO - .iterate();
  if (Timer1.available()) // wejście w if-a co 2 sekundy
  {
    Timer1.restart();
    Serial.print("Liczba zapisanych bajtow:");
    Serial.println(prefs.getBytes("key", rawData, (prefs.getBytesLength("key"))));//zapisuje i zwraca liczbe zapisanych b
                                                                                //powinno byc 142
  }
  else
  {
    SuplaDevice.iterate();
  }
}
oraz logi, myśle że wystarczy tylko kluczowy fragment

Code: Select all

Liczba zapisanych bajtow:142
LittleFsConfig: writing to file "/supla-dev.cfg"
LittleFsConfig: writing to file "/supla-dev.cfg.bak"
Liczba zapisanych bajtow:4294967295
Jak widać po

LittleFsConfig: writing to file "/supla-dev.cfg"
LittleFsConfig: writing to file "/supla-dev.cfg.bak"

zaczyna się chrzanić zapis.

Według opisu biblioteki Preferences:
Preferences are stored in the internal flash filesystem in a bunch of /nvs/{namespace}/{property} files.
Filesystem should handle flash wearing, bad sectors and atomic rename file operation.

LittleFS handles all that, so this is the default FS driver for ESP8266. SPIFFS use is possible, but it is discouraged.
Wiec tak jak by się własnie z LittleFS gryzło
User avatar
klew
Posts: 13906
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Sd używa LittleFs, więc to nie powinno się gryźć. Chyba że preferences u Ciebie działa na spifs, to wtedy się wysypie.
Najlepsze suple dla Twojego domu :mrgreen:
petione
Posts: 121
Joined: Sat Jul 21, 2018 4:26 pm

Post

klew wrote: Sat Jan 25, 2025 5:50 pm Sd używa LittleFs, więc to nie powinno się gryźć. Chyba że preferences u Ciebie działa na spifs, to wtedy się wysypie.
Niestety nie udało mi się rozwiązać problemu choć Preferences działa również na LittleFs, odpuszczam na razie ten temat...

Inne pytańko, czy można jakoś ukryć na stronie WWW pola odnośnie ustawiania protokołu Supli oraz MQTT?
User avatar
klew
Posts: 13906
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Można nie dodawać klasy, która te pola dodaje.
Czemu chcesz to schować?
Najlepsze suple dla Twojego domu :mrgreen:
petione
Posts: 121
Joined: Sat Jul 21, 2018 4:26 pm

Post

klew wrote: Wed Jan 29, 2025 7:47 am Można nie dodawać klasy, która te pola dodaje.
Czemu chcesz to schować?
Bo nawet nie miałem jeszcze potrzeby zmiany w tych polach czegokolwiek wiec w moim przypadku pola te niepotrzebnie zajmują miejsce na ekranie. Podpowiesz gdzie i które linie zakomentować?
User avatar
klew
Posts: 13906
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

petione wrote: Wed Jan 29, 2025 8:44 am
klew wrote: Wed Jan 29, 2025 7:47 am Można nie dodawać klasy, która te pola dodaje.
Czemu chcesz to schować?
Bo nawet nie miałem jeszcze potrzeby zmiany w tych polach czegokolwiek wiec w moim przypadku pola te niepotrzebnie zajmują miejsce na ekranie. Podpowiesz gdzie i które linie zakomentować?
Ale wtedy nie będzie się dało ustawić serwera, maila itp.

Samo MQTT można ukryć, aby była tylko "Supla".

To jest ta linia:

Code: Select all

Supla::Html::ProtocolParameters htmlProto;
Jak wyrzucisz, to nie będzie wcale tych ustawień.

Tak można samo mqtt wyłączyć:

Code: Select all

Supla::Html::ProtocolParameters htmlProto(false);
Najlepsze suple dla Twojego domu :mrgreen:
petione
Posts: 121
Joined: Sat Jul 21, 2018 4:26 pm

Post

petione wrote: Wed Jan 29, 2025 8:44 am
klew wrote: Wed Jan 29, 2025 7:47 am Można nie dodawać klasy, która te pola dodaje.
Czemu chcesz to schować?
Bo nawet nie miałem jeszcze potrzeby zmiany w tych polach czegokolwiek wiec w moim przypadku pola te niepotrzebnie zajmują miejsce na ekranie. Podpowiesz gdzie i które linie zakomentować?
No i właśnie jak komentowałem te linie to dane serwera, maila tez nikły. Spróbuję w domu przynajmiej MQTT ukryć bo z parametrem "false" nie próbowałem :)

Code: Select all

Supla::Html::ProtocolParameters htmlProto(false);


Reszta rozumiem że jest zaszyta gdzieś głębiej i nie da się tak jednym machnięciem ukryć wybranych pól.
User avatar
klew
Posts: 13906
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

petione wrote: Wed Jan 29, 2025 9:18 am Reszta rozumiem że jest zaszyta gdzieś głębiej i nie da się tak jednym machnięciem ukryć wybranych pól.
Zależy o co pytasz.
Zerknij sobie tutaj: https://github.com/SUPLA/supla-device/t ... twork/html
Tu są źródła wszystkich tych "htmlowych komponentów". W pliku źródłowym można zobaczyć jakie pole jest wysyłane w danej klasie.
Jak potrzebujesz coś custome'owego, to zawsze możesz sobie skopiować, zmienić nazwę, wyciąć jakieś pole i tego używać zamiast tego co jest w libce.
Możesz też dodać jakieś parametry do konstruktora, aby to "customizować" i możesz też takie zmiany proponować przy pomocy PR do sd.
Najlepsze suple dla Twojego domu :mrgreen:
petione
Posts: 121
Joined: Sat Jul 21, 2018 4:26 pm

Post

OK. Dzięki jak zwykle za Twoją pomoc i poświęcenie :)
petione
Posts: 121
Joined: Sat Jul 21, 2018 4:26 pm

Post

A czy można jakoś w sekcji Additional Settings ukrywać pole tekstowe w zależności od stanu zmiennej np. gdy dana opcja jest wyłączona to brak widocznego pola. Mam na myśli tutaj kod realizowany w Loop-pie

Return to “Pomoc”