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
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!