lukfud wrote: Fri Dec 16, 2022 6:07 pm
nebraska wrote: Fri Dec 16, 2022 2:13 pm
Czy ktoś podpowie jak odczytać wpisaną wartość w konfigu zeby czytał jako liczby bo nie mogę sobie z tym poradzić czyta jako tekst.
Pokaż kod
Klucz z
TelegramBOT jest pobierany z if (Supla::Storage::ConfigInstance()->getString(TelegramBOT, buf, 200)) {
SUPLA_LOG_DEBUG(" **** Param[%s]: %s", TelegramBOT, buf);
i prawidłowo odczytuje tylko nie wiem jak te pobrane klucze które wpisuje w CFG podstawić do tych define' ow, zeby czytał te klucze
Code: Select all
Enter normal mode
**** Param[param1]: 5081602654:AAEaeI_7aOc2yxgJVV1nVObH4Ol6RlrC_KI
**** Param[param2]: 0
#define BOT_TOKEN "token" //"5081602654:AAEaeI_7aOc2yxgJVV1nVObH4Ol6RlrC_KI"
#define BOT_CHAT_ID "chatid" //"-632947517"
Code: Select all
#define STATUS_LED_GPIO 2
#define RELAY_GPIO 15
#define BUTTON_CFG_RELAY_GPIO 4
#include <SuplaDevice.h>
#include <supla/network/esp_wifi.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/device/supla_ca_cert.h>
#include <supla/events.h>
// Includes for HTML elements
#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/network/html/custom_parameter.h>
#include <supla/network/html/custom_text_parameter.h>
#include <supla/network/html/text_cmd_input_parameter.h>
#include <supla/network/html/select_cmd_input_parameter.h>
#include <WiFiClientSecure.h>
// 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);
// This class provides Wi-Fi network connectivity for your device
Supla::ESPWifi wifi;
// This class provides web server to handle config mode
Supla::EspWebServer suplaServer;
// This class provides configuration storage (like SSID, password, all
// user defined parameters, etc. We use LittleFS.
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
auto r1 = new Supla::Control::Relay(13, false); // Relay Lampka
uint8_t stan=0;
// Those tags are used for HTML element names and for keys to access parameter
// values in Config storage class. Max length of those values is 15 chars.
const char TelegramBOT[] = "token";
const char TelegramChatID[] = "chatid";
const char PARAM2[] = "param2";
const char PARAM_CMD1[] = "cmd1";
const char PARAM_CMD2[] = "cmd2";
const char PARAM_CMD3[] = "cmd3";
//------------------------- TELEGRAM ---------------------------------
#define TELEGRAM_HOST "api.telegram.org"
#define TELEGRAM_SSL_PORT 443
#define BOT_TOKEN "token" //"5081602654:AAEaeI_7aOc2yxgJVV1nVObH4Ol6RlrC_KI"
#define BOT_CHAT_ID "chatid" //"-632947517"
//#define BOT_CHAT_ID2 "-729189328"
//--------------------------------------------------------------------
void setup() {
Serial.begin(115200);
// Channels configuration
// CH 0 - Relay
auto r1 = new Supla::Control::Relay(RELAY_GPIO);
// CH 1 - Action trigger
auto at1 = new Supla::Control::ActionTrigger();
// Buttons configuration
auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
buttonCfgRelay->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1);
// Action trigger configuration
at1->setRelatedChannel(r1);
at1->attach(buttonCfgRelay);
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
// HTML www component (they appear in sections according to creation
// sequence).
new Supla::Html::DeviceInfo(&SuplaDevice);
new Supla::Html::WifiParameters;
new Supla::Html::ProtocolParameters;
new Supla::Html::StatusLedParameters;
// Here user defined inputs are defined.
// Simple text input:
// PARAM1 - input name and key used for storage in Config instance
// "Please provide text value" - label for field on config page
// 100 - maximum text length accepted by your input
new Supla::Html::CustomTextParameter(TelegramBOT, "Klucz BOT Token", 100);
new Supla::Html::CustomTextParameter(TelegramChatID, "Klucz CHAT ID", 100);
// Numeric input:
// PARAM2 - input name and key used for storage in Config instance
// "Your age" - label for field on config page
// 100 - maximum text length accepted by your input
new Supla::Html::CustomParameter(PARAM2, "Your age");
// Text based command input
// PARAM_CMD1 - Html field input name
// "Relay control" - label that is displayed on config page
auto textCmd = new Supla::Html::TextCmdInputParameter(PARAM_CMD1, "Relay control");
// First we register allowed text input values and we assign which event
// should be generated:
textCmd->registerCmd("ON", Supla::ON_EVENT_1);
textCmd->registerCmd("OFF", Supla::ON_EVENT_2);
textCmd->registerCmd("TOGGLE", Supla::ON_EVENT_3);
// Then we link events with actions on a relay.
// Last "true" parameter will make sure that those actions won't be disabled
// when we enter config mode. By default actions are disabled when device
// enters config mode, but those text commands can be used only in config
// mode, so we want to have them enabled.
textCmd->addAction(Supla::TURN_ON, r1, Supla::ON_EVENT_1, true);
textCmd->addAction(Supla::TURN_OFF, r1, Supla::ON_EVENT_2, true);
textCmd->addAction(Supla::TOGGLE, r1, Supla::ON_EVENT_3, true);
// Select based command input - exactly the same configuration as for text
// field
// PARAM_CMD2 - Html field input name
// "Relay control" - label that is displayed on config page
auto selectCmd = new Supla::Html::SelectCmdInputParameter(PARAM_CMD1, "Relay control");
// First we register allowed text input values and we assign which event
// should be generated:
selectCmd->registerCmd("ON", Supla::ON_EVENT_1);
selectCmd->registerCmd("OFF", Supla::ON_EVENT_2);
selectCmd->registerCmd("TOGGLE", Supla::ON_EVENT_3);
// Then we link events with actions on a relay.
// Last "true" parameter will make sure that those actions won't be disabled
// when we enter config mode. By default actions are disabled when device
// enters config mode, but those text commands can be used only in config
// mode, so we want to have them enabled.
selectCmd->addAction(Supla::TURN_ON, r1, Supla::ON_EVENT_1, true);
selectCmd->addAction(Supla::TURN_OFF, r1, Supla::ON_EVENT_2, true);
selectCmd->addAction(Supla::TOGGLE, r1, Supla::ON_EVENT_3, true);
// Set custom device name
SuplaDevice.setName("SUPLA-INPUT-EXAMPLE");
// Start!
SuplaDevice.begin();
// Below lines show how to access values provided by user via config mode.
// It has to be used after SuplaDevice.begin() or in loop(). If you would
// like to access them before begin(), then please first call:
// Supla::Storage::Init();
char buf[200] = {};
if (Supla::Storage::ConfigInstance()->getString(TelegramBOT, buf, 200)) {
SUPLA_LOG_DEBUG(" **** Param[%s]: %s", TelegramBOT, buf);
} else {
SUPLA_LOG_DEBUG(" **** Param[%s] is not set", TelegramBOT);
}
if (Supla::Storage::ConfigInstance()->getString(TelegramChatID, buf, 200)) {
SUPLA_LOG_DEBUG(" **** Param[%s]: %s", TelegramChatID, buf);
} else {
SUPLA_LOG_DEBUG(" **** Param[%s] is not set", TelegramChatID);
}
int32_t intValue = 0;
if (Supla::Storage::ConfigInstance()->getInt32(PARAM2, &intValue)) {
SUPLA_LOG_DEBUG(" **** Param[%s]: %d", PARAM2, intValue);
} else {
SUPLA_LOG_DEBUG(" **** Param[%s] is not set", PARAM2);
}
}
void loop() {
SuplaDevice.iterate();
}