lukfud podstawiłem jak zaleciłeś ale niestety nie odczytuje. Pewnie tu jest problem nie wiem jak tu podstawić bo czyta te teksty.lukfud pisze: ↑pt gru 16, 2022 11:09 pmNie potrzebujesz tych definicji.nebraska pisze: ↑pt gru 16, 2022 10:58 pm Tak tylko chodzi mi o to jak podstawic klucze do tych define żeby czytał z konfigu? Bo teraz tylko mi czyta jak są wpisane obok co mam obecnie zakomentiwane bo chce żeby czytał je z konfigu.
Jak tego param1 gdzie obok jest klucz na logu wrzucić go do define BOT TOKEN?
Poprzez #define nadajesz w kodzie nazwę stałej wartości.
Ty nie będziesz posługiwał się w tym programie stałą wartością, tylko zmienną, więc tam gdzie telegram potrzebuje BOT_TOKEN wstaw zmienną TelegramBOT, tak samo z chatID.
Powiedz proszę jak to rozwiązać drugi dzień męcze to i nie potrafię
const char TelegramBOT[] = "tele_bot";
const char TelegramCHATID[] = "tele_chat_id";
Kod: Zaznacz cały
connecting to ..api.telegram.org
requesting URL: /bottele_bot/sendMessage?chat_id=tele_chat_id&text=Przekaźnik Włączony!!!
Kod: Zaznacz cały
// 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[] = "tele_bot";
const char TelegramCHATID[] = "tele_chat_id";
const char PARAM2[] = "param2";
const char PARAM_CMD1[] = "cmd1";
const char PARAM_CMD2[] = "cmd2";
byte stan = 0;
auto r1 = new Supla::Control::Relay(18, false);
#define TELEGRAM_HOST "api.telegram.org"
#define TELEGRAM_SSL_PORT 443
//#define BOT_TOKEN "5081602654:AAEaeI_7aOc2yxgJVV1nVObH4Ol6RlrC_KI"
//#define BOT_CHAT_ID "-632947517"
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, "Telegram BOT_Token", 100);
new Supla::Html::CustomTextParameter(TelegramCHATID, "Telegram 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();
if ((digitalRead(18) == LOW) && (stan == 0)) {
stan = 1;
direct_telegram(TelegramCHATID, "Przekaźnik Włączony!!! ");
} else if (digitalRead(13) == HIGH) {
stan = 0;
}
}