Controlling a Device with more than two states

Allendrome_
Posts: 14
Joined: Tue Jan 12, 2021 1:22 pm

Post

klew wrote: Wed Jun 19, 2024 8:38 am Please quote me when you reply (even empty quote) - this way I'll get notification about your post and I'll reply quicker :)
Thanks, will do. I actually managed to make this change last night after brushing up on C++ a little and looking through the libraries referenced in the error. I'm glad to see your solution was the same, it gives me hope!

I'm still getting an error on compile though - from this line:

Code: Select all

Supla::Control::DimmerBase(red, green, blue, colorBrightness, brightness, toggle);
The error reads:

Code: Select all

C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino: In member function 'virtual void MyDimmer::setRGBW(int, int, int, int, int, bool, bool)':
DEFCON_new_library_latest:91:96: error: invalid cast to abstract class type 'Supla::Control::DimmerBase'
   91 |                Supla::Control::DimmerBase(red, green, blue, colorBrightness, brightness, toggle);
      |                                                                                                ^
In file included from C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino:38:
C:\Users\Alexa\Documents\Arduino\libraries\SuplaDevice\src/supla/control/dimmer_base.h:26:7: note:   because the following virtual functions are pure within 'Supla::Control::DimmerBase':
   26 | class DimmerBase : public RGBWBase {
      |       ^~~~~~~~~~
In file included from C:\Users\Alexa\Documents\Arduino\libraries\SuplaDevice\src/supla/control/dimmer_base.h:22,
                 from C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino:38:
C:\Users\Alexa\Documents\Arduino\libraries\SuplaDevice\src/supla/control/rgbw_base.h:76:16: note:     'virtual void Supla::Control::RGBWBase::setRGBWValueOnDevice(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)'
   76 |   virtual void setRGBWValueOnDevice(uint32_t red,
      |                ^~~~~~~~~~~~~~~~~~~~
exit status 1
invalid cast to abstract class type 'Supla::Control::DimmerBase'
Again, I've tried to trace the way that Classes in the library reference each other, and eventually I tried changing the line to:

Code: Select all

Supla::Control::RGBWBase::setRGBW(red, green, blue, colorBrightness, brightness, toggle);
Which does compile, and kind of works, but it's buggy. I think from looking at the console I think I've managed to call the SetRGBW() function twice - at least it's reporting the new values twice each time the dimmer value is changed in the app.

Any ideas?
User avatar
klew
Posts: 9728
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

Allendrome_ wrote: Wed Jun 19, 2024 10:32 am Any ideas?
Please share your current code, and logs from serial.
Kiedy będzie Supla Offline Party / SOP#2025 ?
Allendrome_
Posts: 14
Joined: Tue Jan 12, 2021 1:22 pm

Post

klew wrote: Wed Jun 19, 2024 10:38 am
Allendrome_ wrote: Wed Jun 19, 2024 10:32 am Any ideas?
Please share your current code, and logs from serial.
Of course, I've added comments to the line that was causing an error:

Code: Select all

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




#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/dimmer_base.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>

//define variables to assign Correct IO Pins to The correct defcon level
int Def0 = 0;
int Def1 = 12;
int Def2 = 13;
int Def3 = 14;
int Def4 = 5;
int Def5 = 4;


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;

//Class to customise Dimmer control

class MyDimmer : public Supla::Control::DimmerBase {
 public:
  void setRGBWValueOnDevice(uint32_t red,
                                    uint32_t green,
                                    uint32_t blue,
                                    uint32_t colorBrightness,
                                    uint32_t brightness) override { }  // empty method

   
   
   void setRGBW(int red,
               int green,
               int blue,
               int colorBrightness,
               int brightness,
               bool toggle = false,
               bool instant = false) override {
               //Supla::Control::DimmerBase(red, green, blue, colorBrightness, brightness, toggle, instant); // Original line which causes error 
               Supla::Control::RGBWBase::setRGBW(red, green, blue, colorBrightness, brightness, toggle); // Line I tried instead which compiles but is buggy as I mentioned
          int _brightness = getChannel()->getValueBrightness();
          
      // put here your code with "switch (_brightness)" etc
          //Serial.println(_brightness);

                    switch (_brightness) {
            case 0:  //Turn off Main Relay
            Serial.println("Turning off...");
            digitalWrite(Def5, LOW);
            digitalWrite(Def4, HIGH);
            digitalWrite(Def3, LOW); 
            digitalWrite(Def2, LOW); 
            digitalWrite(Def1, LOW);
            digitalWrite(Def0, LOW);
            break;
            case 1 ... 20:
            Serial.println("Going to DEFCON 1");
            digitalWrite(Def5, LOW);
            digitalWrite(Def4, HIGH);
            digitalWrite(Def3, LOW); 
            digitalWrite(Def2, LOW); 
            digitalWrite(Def1, HIGH);
            digitalWrite(Def0, HIGH);
            break;
            case 21 ... 40:
            Serial.println("Going to DEFCON 2");
            digitalWrite(Def5, LOW);
            digitalWrite(Def4, HIGH);
            digitalWrite(Def3, LOW); 
            digitalWrite(Def2, HIGH); 
            digitalWrite(Def1, LOW);
            digitalWrite(Def0, HIGH);
            break;
            case 41 ... 60:
            Serial.println("Going to DEFCON 3");
            digitalWrite(Def5, LOW);
            digitalWrite(Def4, HIGH);
            digitalWrite(Def3, HIGH); 
            digitalWrite(Def2, LOW); 
            digitalWrite(Def1, LOW);
            digitalWrite(Def0, HIGH);
            break;
            case 61 ... 80:
            Serial.println("Going to DEFCON 4");
            digitalWrite(Def5, LOW);
            digitalWrite(Def4, LOW);
            digitalWrite(Def3, LOW); 
            digitalWrite(Def2, LOW); 
            digitalWrite(Def1, LOW);
            digitalWrite(Def0, HIGH);
            break;
            case 81 ... 100:
            Serial.println("Going to DEFCON 5");
            digitalWrite(Def5, HIGH);
            digitalWrite(Def4, HIGH);
            digitalWrite(Def3, LOW); 
            digitalWrite(Def2, LOW); 
            digitalWrite(Def1, LOW);
            digitalWrite(Def0, HIGH);
            break;
          }
      
      }

 };



void setup() {
  Serial.begin(115200);
  // Buttons configuration
//  auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG__GPIO, true, true);
//  buttonCfgRelay->configureAsConfigButton(&SuplaDevice);

  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(0, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  
  auto dimmer = new MyDimmer();
  
  // configure defualt Supla CA certificate
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);

  SuplaDevice.begin();
}



void loop() {
  SuplaDevice.iterate();
}
And here's the output to the serial monitor:

Code: Select all

0燆⸮!,⸮⸮⸮Send: [53 55 50 4C 41 17 05 00 00 00 28 00 00 00 10 00 00 00 21 00 00 00 00 00 00 00 C5 95 09 00 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 04 00 00 00 32 00 00 00 10 00 00 00 DC B7 72 66 00 00 00 00 02 94 02 00 00 00 00 00 53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 05 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 01 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=1, command=0, toggleOnOff=0
RGBW: 0,255,0,0,1
Turning off...
Recv: [53 55 50 4C 41 17 06 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 17 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=23, command=0, toggleOnOff=0
RGBW: 0,255,0,0,23
Turning off...
Recv: [53 55 50 4C 41 17 07 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 17 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=23, command=0, toggleOnOff=0
RGBW: 0,255,0,0,23
Turning off...
Recv: [53 55 50 4C 41 17 08 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 17 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=23, command=0, toggleOnOff=0
RGBW: 0,255,0,0,23
Turning off...
Recv: [53 55 50 4C 41 17 09 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 16 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=22, command=0, toggleOnOff=0
RGBW: 0,255,0,0,22
Turning off...
Channel(0) value changed to RGB(0, 255, 0), colBr(0), bright(22)
Send: [53 55 50 4C 41 17 06 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 16 00 00 FF 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 0A 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 29 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=41, command=0, toggleOnOff=0
RGBW: 0,255,0,0,41
Going to DEFCON 2
Channel(0) value changed to RGB(0, 255, 0), colBr(0), bright(41)
Send: [53 55 50 4C 41 17 07 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 29 00 00 FF 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 0B 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 44 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=68, command=0, toggleOnOff=0
RGBW: 0,255,0,0,68
Going to DEFCON 3
Channel(0) value changed to RGB(0, 255, 0), colBr(0), bright(68)
Send: [53 55 50 4C 41 17 08 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 44 00 00 FF 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 0C 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 47 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=71, command=0, toggleOnOff=0
RGBW: 0,255,0,0,71
Going to DEFCON 4
Recv: [53 55 50 4C 41 17 0D 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 37 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=55, command=0, toggleOnOff=0
RGBW: 0,255,0,0,55
Going to DEFCON 4
Recv: [53 55 50 4C 41 17 0E 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 24 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=36, command=0, toggleOnOff=0
RGBW: 0,255,0,0,36
Going to DEFCON 4
Recv: [53 55 50 4C 41 17 0F 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 1A 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=26, command=0, toggleOnOff=0
RGBW: 0,255,0,0,26
Going to DEFCON 4
Recv: [53 55 50 4C 41 17 10 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 17 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=23, command=0, toggleOnOff=0
RGBW: 0,255,0,0,23
Going to DEFCON 4
Recv: [53 55 50 4C 41 17 11 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 16 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=22, command=0, toggleOnOff=0
RGBW: 0,255,0,0,22
Going to DEFCON 4
Recv: [53 55 50 4C 41 17 12 00 00 00 6E 00 00 00 11 00 00 00 1C 15 00 00 00 00 00 00 00 16 00 00 FF 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=22, command=0, toggleOnOff=0
RGBW: 0,255,0,0,22
Going to DEFCON 4
Channel(0) value changed to RGB(0, 255, 0), colBr(0), bright(22)
Send: [53 55 50 4C 41 17 09 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 16 00 00 FF 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Send: [53 55 50 4C 41 17 0A 00 00 00 28 00 00 00 10 00 00 00 61 00 00 00 00 00 00 00 6F BE 0A 00 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 13 00 00 00 32 00 00 00 10 00 00 00 1C B8 72 66 00 00 00 00 08 98 03 00 00 00 00 00 53 55 50 4C 41 ]
If I comment out the line

Code: Select all

Supla::Control::RGBWBase::setRGBW(red, green, blue, colorBrightness, brightness, toggle);
it still compiles, and I only get the

Code: Select all

RGBW: red=0, green=255, blue=0, colorBrightness=0, brightness=22, command=0, toggleOnOff=0
style lines in the monitor, and not the

Code: Select all

RGBW: 0,255,0,0,22
lines.
The problem then, though, is that the line

Code: Select all

int _brightness = getChannel()->getValueBrightness();
always gets the value '0'.

sorry about the formatting, the anti-spam system kicked in when I tried to but the few lines of code above in outside of code markers!
User avatar
klew
Posts: 9728
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

Allendrome_ wrote: Wed Jun 19, 2024 11:02 am The problem then, though, is that the line

Code: Select all

int _brightness = getChannel()->getValueBrightness();
always gets the value '0'.
Without setRGBW it won't update channel value, that's why this getValueBrightness on channel returns 0.

I don't see all messages doubled. Only sometimes there is the same brightness send do the device. Maybe it is just send from app, when you move finger on brightness adjuster?

Maybe you can test it by setting brightness via cloud.supla.org? There you can put number in form and send it. This way device should get only single message.
Kiedy będzie Supla Offline Party / SOP#2025 ?
Allendrome_
Posts: 14
Joined: Tue Jan 12, 2021 1:22 pm

Post

klew wrote: Wed Jun 19, 2024 11:18 am
Allendrome_ wrote: Wed Jun 19, 2024 11:02 am The problem then, though, is that the line

Code: Select all

int _brightness = getChannel()->getValueBrightness();
always gets the value '0'.
Without setRGBW it won't update channel value, that's why this getValueBrightness on channel returns 0.

I don't see all messages doubled. Only sometimes there is the same brightness send do the device. Maybe it is just send from app, when you move finger on brightness adjuster?

Maybe you can test it by setting brightness via cloud.supla.org? There you can put number in form and send it. This way device should get only single message.
I've tried setting the brightness from cloud.supla.org as you suggested. I've added the line:

Code: Select all

Serial.println("_brightness: " + String(_brightness));
to the SetRGBW() method to make it clearer. Here is the serial output:

Code: Select all

Recv: [53 55 50 4C 41 17 06 00 00 00 6E 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=0, blue=0, colorBrightness=0, brightness=21, command=0, toggleOnOff=0
RGBW: 0,0,0,0,21
_brightness: 0
Turning off...
Channel(0) value changed to RGB(0, 0, 0), colBr(0), bright(21)
Send: [53 55 50 4C 41 17 07 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 07 00 00 00 6E 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 29 00 00 00 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=0, blue=0, colorBrightness=0, brightness=41, command=0, toggleOnOff=0
RGBW: 0,0,0,0,41
_brightness: 21
Going to DEFCON 2
Channel(0) value changed to RGB(0, 0, 0), colBr(0), bright(41)
Send: [53 55 50 4C 41 17 08 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 29 00 00 00 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
Recv: [53 55 50 4C 41 17 08 00 00 00 6E 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 3D 00 00 00 00 00 00 00 53 55 50 4C 41 ]
RGBW: red=0, green=0, blue=0, colorBrightness=0, brightness=61, command=0, toggleOnOff=0
RGBW: 0,0,0,0,61
_brightness: 41
Going to DEFCON 3
Channel(0) value changed to RGB(0, 0, 0), colBr(0), bright(61)
Send: [53 55 50 4C 41 17 09 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 3D 00 00 00 00 00 00 00 ]
Send: [53 55 50 4C 41 ]
It seems to be 'lagging' one step behind - so that when a new level is set, the _brightness variable receives the previous brightness, rather than the new one.

Incidentally, when I was talking about it looking like the messages were doubled, I was talking about lines like these:

Code: Select all

RGBW: red=0, green=0, blue=0, colorBrightness=0, brightness=61, command=0, toggleOnOff=0
RGBW: 0,0,0,0,61
Would we expect it to show the same information in two different formats like that?
User avatar
klew
Posts: 9728
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

Allendrome_ wrote: Wed Jun 19, 2024 11:41 am It seems to be 'lagging' one step behind - so that when a new level is set, the _brightness variable receives the previous brightness, rather than the new one.
Right, I checked the code and setRGB first update interanal state in class. Channel value is updated later in "iterateAlways" method with some 0,4 s delay in order to avoid sending too many messages to server.

So, use "_brightness = curBrightness;" instead. It should work properly.
Allendrome_ wrote: Wed Jun 19, 2024 11:41 am Incidentally, when I was talking about it looking like the messages were doubled, I was talking about lines like these:

Code: Select all

RGBW: red=0, green=0, blue=0, colorBrightness=0, brightness=61, command=0, toggleOnOff=0
RGBW: 0,0,0,0,61
Would we expect it to show the same information in two different formats like that?
First print is used only for method which is parsing messages from server.
Second print is from setRGBW method, which can be called also from different source (i.e. as a result of local button press).
Those logs doesn't look elegant, but you can ignore them.
Kiedy będzie Supla Offline Party / SOP#2025 ?
Allendrome_
Posts: 14
Joined: Tue Jan 12, 2021 1:22 pm

Post

klew wrote: Wed Jun 19, 2024 11:52 am
Right, I checked the code and setRGB first update interanal state in class. Channel value is updated later in "iterateAlways" method with some 0,4 s delay in order to avoid sending too many messages to server.

So, use "_brightness = curBrightness;" instead. It should work properly.
That's got it, looks like it's working perfectly, thanks!

klew wrote: Wed Jun 19, 2024 11:52 am First print is used only for method which is parsing messages from server.
Second print is from setRGBW method, which can be called also from different source (i.e. as a result of local button press).
Those logs doesn't look elegant, but you can ignore them.
That's great, as long as it doesn't indicate something wrong in the code, I'm happy!

I'm really surprised that using "Supla::Control::RGBWBase::setRGBW" ended up being a correct solution to the error I was getting from "Supla::Control::DimmerBase", as it was much more luck than judgement that I tried it!

I do have one more question, and it's regarding the WebInterface functionality (Which worked great and made it very easy to set up the device using the app!) I know you advised me in an earlier post that it's recommended to include a button to switch the device to cfg mode, but it's a bit awkward to add a button to my hardware. Is it possible to set up the device such that it automatically switches to cfg mode if it cannot connect to WIFI after a certain period of time after boot?
User avatar
klew
Posts: 9728
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

Allendrome_ wrote: Wed Jun 19, 2024 12:11 pm I'm really surprised that using "Supla::Control::RGBWBase::setRGBW" ended up being a correct solution to the error I was getting from "Supla::Control::DimmerBase", as it was much more luck than judgement that I tried it!
I'm not sure what that error was about, but call to RGBWBase instead is also valid, so I didn't dig into it.
Allendrome_ wrote: Wed Jun 19, 2024 12:11 pm I do have one more question, and it's regarding the WebInterface functionality (Which worked great and made it very easy to set up the device using the app!) I know you advised me in an earlier post that it's recommended to include a button to switch the device to cfg mode, but it's a bit awkward to add a button to my hardware. Is it possible to set up the device such that it automatically switches to cfg mode if it cannot connect to WIFI after a certain period of time after boot?
It's possible, but there is no such implemnetation ready, so you'd have to implement it by yourself.

There is only this class:
https://github.com/SUPLA/supla-device/b ... er_cycle.h
It will enable cfg mode, when you power cycle the device more than 3x (it can be set to different value).
However this class checks one parameter in configuration, which by default is not set, and, as a result, it is in "disabled mode".

Code: Select all

    cfg->getUInt8(Supla::Html::DisableUserInterfaceCfgTag, &disableUI);
    enabled = (disableUI == 1);
You can add:

Code: Select all

     cfg->setUInt8(Supla::Html::DisableUserInterfaceCfgTag, 1);
     cfg->saveWithDelay(1000);
 
in your code. "cfg" is a pointer to Supla::Config class. You can call it only after Config is initialized (i.e. right after SuplaDevice.begin() ).

On first device startup it will configure this parameter and it will start working.
Kiedy będzie Supla Offline Party / SOP#2025 ?
Allendrome_
Posts: 14
Joined: Tue Jan 12, 2021 1:22 pm

Post

klew wrote: Wed Jun 19, 2024 12:44 pm There is only this class:
https://github.com/SUPLA/supla-device/b ... er_cycle.h
It will enable cfg mode, when you power cycle the device more than 3x (it can be set to different value).
That sounds like it would work for me. I've tried adding:

Code: Select all

  cfg->setUInt8(Supla::Html::DisableUserInterfaceCfgTag, 1);
  cfg->saveWithDelay(1000); 
Directly after "SuplaDevice.begin();", but on compile I get the error:

Code: Select all

C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino: In function 'void setup()':
DEFCON_new_library_latest:181:3: error: 'cfg' was not declared in this scope
  181 |   cfg->setUInt8(Supla::Html::DisableUserInterfaceCfgTag, 1);
      |   ^~~
DEFCON_new_library_latest:181:30: error: 'DisableUserInterfaceCfgTag' is not a member of 'Supla::Html'
  181 |   cfg->setUInt8(Supla::Html::DisableUserInterfaceCfgTag, 1);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
exit status 1
'cfg' was not declared in this scope
I tried replacing the pointer with "Supla::Config::" for both lines and got:

Code: Select all

C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino: In function 'void setup()':
DEFCON_new_library_latest:186:69: error: cannot call member function 'virtual bool Supla::Config::setUInt8(const char*, uint8_t)' without object
  186 |   Supla::Config::setUInt8(Supla::Html::DisableUserInterfaceCfgTag, 1);
      |                                                                     ^
DEFCON_new_library_latest:187:36: error: cannot call member function 'virtual void Supla::Config::saveWithDelay(uint32_t)' without object
  187 |   Supla::Config::saveWithDelay(1000);
      |                                    ^
exit status 1
cannot call member function 'virtual bool Supla::Config::setUInt8(const char*, uint8_t)' without object
User avatar
klew
Posts: 9728
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

Missing symbol is Supla::Html::DisableUserInterfaceCfgTag
It should be in some header file in src/supła/network/html.
Try to look for it there and add include
Kiedy będzie Supla Offline Party / SOP#2025 ?

Return to “General discussion”