mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
Fix telegram response using UrlEncode
Fix telegram response using UrlEncode (#10486)
This commit is contained in:
parent
574701b2ab
commit
256f9fc285
@ -58,8 +58,8 @@ void OsWatchTicker(void)
|
|||||||
|
|
||||||
// ESP.restart(); // normal reboot
|
// ESP.restart(); // normal reboot
|
||||||
// ESP.reset(); // hard reset
|
// ESP.reset(); // hard reset
|
||||||
|
|
||||||
// Force an exception to get a stackdump
|
// Force an exception to get a stackdump
|
||||||
|
// ESP32: Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
|
||||||
volatile uint32_t dummy;
|
volatile uint32_t dummy;
|
||||||
dummy = *((uint32_t*) 0x00000000);
|
dummy = *((uint32_t*) 0x00000000);
|
||||||
(void)dummy; // avoid compiler warning
|
(void)dummy; // avoid compiler warning
|
||||||
@ -549,6 +549,38 @@ char* Trim(char* p)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String UrlEncode(const String& text) {
|
||||||
|
const char hex[] = "0123456789ABCDEF";
|
||||||
|
|
||||||
|
String encoded = "";
|
||||||
|
int len = text.length();
|
||||||
|
int i = 0;
|
||||||
|
while (i < len) {
|
||||||
|
char decodedChar = text.charAt(i++);
|
||||||
|
/*
|
||||||
|
if (('a' <= decodedChar && decodedChar <= 'z') ||
|
||||||
|
('A' <= decodedChar && decodedChar <= 'Z') ||
|
||||||
|
('0' <= decodedChar && decodedChar <= '9') ||
|
||||||
|
('=' == decodedChar)) {
|
||||||
|
encoded += decodedChar;
|
||||||
|
} else {
|
||||||
|
encoded += '%';
|
||||||
|
encoded += hex[decodedChar >> 4];
|
||||||
|
encoded += hex[decodedChar & 0xF];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if ((' ' == decodedChar) || ('+' == decodedChar)) {
|
||||||
|
encoded += '%';
|
||||||
|
encoded += hex[decodedChar >> 4];
|
||||||
|
encoded += hex[decodedChar & 0xF];
|
||||||
|
} else {
|
||||||
|
encoded += decodedChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return encoded;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char* RemoveAllSpaces(char* p)
|
char* RemoveAllSpaces(char* p)
|
||||||
{
|
{
|
||||||
|
@ -2798,40 +2798,6 @@ bool CaptivePortal(void)
|
|||||||
|
|
||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
String UrlEncode(const String& text)
|
|
||||||
{
|
|
||||||
const char hex[] = "0123456789ABCDEF";
|
|
||||||
|
|
||||||
String encoded = "";
|
|
||||||
int len = text.length();
|
|
||||||
int i = 0;
|
|
||||||
while (i < len) {
|
|
||||||
char decodedChar = text.charAt(i++);
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (('a' <= decodedChar && decodedChar <= 'z') ||
|
|
||||||
('A' <= decodedChar && decodedChar <= 'Z') ||
|
|
||||||
('0' <= decodedChar && decodedChar <= '9') ||
|
|
||||||
('=' == decodedChar)) {
|
|
||||||
encoded += decodedChar;
|
|
||||||
} else {
|
|
||||||
encoded += '%';
|
|
||||||
encoded += hex[decodedChar >> 4];
|
|
||||||
encoded += hex[decodedChar & 0xF];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if ((' ' == decodedChar) || ('+' == decodedChar)) {
|
|
||||||
encoded += '%';
|
|
||||||
encoded += hex[decodedChar >> 4];
|
|
||||||
encoded += hex[decodedChar & 0xF];
|
|
||||||
} else {
|
|
||||||
encoded += decodedChar;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return encoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSend(char *buffer)
|
int WebSend(char *buffer)
|
||||||
{
|
{
|
||||||
// [tasmota] POWER1 ON --> Sends http://tasmota/cm?cmnd=POWER1 ON
|
// [tasmota] POWER1 ON --> Sends http://tasmota/cm?cmnd=POWER1 ON
|
||||||
|
@ -256,7 +256,7 @@ bool TelegramSendMessage(int32_t chat_id, String text) {
|
|||||||
bool sent = false;
|
bool sent = false;
|
||||||
if (text != "") {
|
if (text != "") {
|
||||||
String _token = SettingsText(SET_TELEGRAM_TOKEN);
|
String _token = SettingsText(SET_TELEGRAM_TOKEN);
|
||||||
String command = "bot" + _token + "/sendMessage?chat_id=" + String(chat_id) + "&text=" + text;
|
String command = "bot" + _token + "/sendMessage?chat_id=" + String(chat_id) + "&text=" + UrlEncode(text);
|
||||||
String response = TelegramConnectToTelegram(command);
|
String response = TelegramConnectToTelegram(command);
|
||||||
|
|
||||||
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Response %s"), response.c_str());
|
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Response %s"), response.c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user