mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
JSMN phase 2
This commit is contained in:
parent
7605ec388c
commit
2fc7626025
@ -104,18 +104,15 @@ void CmndRfSend(void)
|
||||
int repeat = 10;
|
||||
int pulse = 350;
|
||||
|
||||
char dataBufUc[XdrvMailbox.data_len + 1];
|
||||
UpperCase(dataBufUc, XdrvMailbox.data);
|
||||
StaticJsonBuffer<150> jsonBuf; // ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(5) + 40 = 134
|
||||
JsonObject &root = jsonBuf.parseObject(dataBufUc);
|
||||
if (root.success()) {
|
||||
JsonParserObject root = JsonParser(XdrvMailbox.data).getRootObject();
|
||||
if (root) {
|
||||
// RFsend {"data":0x501014,"bits":24,"protocol":1,"repeat":10,"pulse":350}
|
||||
char parm_uc[10];
|
||||
data = strtoul(root[UpperCase_P(parm_uc, PSTR(D_JSON_RF_DATA))], nullptr, 0); // Allow decimal (5246996) and hexadecimal (0x501014) input
|
||||
bits = root[UpperCase_P(parm_uc, PSTR(D_JSON_RF_BITS))];
|
||||
protocol = root[UpperCase_P(parm_uc, PSTR(D_JSON_RF_PROTOCOL))];
|
||||
repeat = root[UpperCase_P(parm_uc, PSTR(D_JSON_RF_REPEAT))];
|
||||
pulse = root[UpperCase_P(parm_uc, PSTR(D_JSON_RF_PULSE))];
|
||||
data = root.getUInt(PSTR(D_JSON_RF_DATA), data);
|
||||
bits = root.getUInt(PSTR(D_JSON_RF_BITS), bits);
|
||||
protocol = root.getInt(PSTR(D_JSON_RF_PROTOCOL), protocol);
|
||||
repeat = root.getInt(PSTR(D_JSON_RF_REPEAT), repeat);
|
||||
pulse = root.getInt(PSTR(D_JSON_RF_PULSE), pulse);
|
||||
} else {
|
||||
// RFsend data, bits, protocol, repeat, pulse
|
||||
char *p;
|
||||
|
@ -1328,17 +1328,13 @@ void ThermostatDebug(uint8_t ctr_output)
|
||||
#endif // DEBUG_THERMOSTAT
|
||||
|
||||
void ThermostatGetLocalSensor(uint8_t ctr_output) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject((const char*)mqtt_data);
|
||||
if (root.success()) {
|
||||
const char* value_c = root[THERMOSTAT_SENSOR_NAME]["Temperature"];
|
||||
if (value_c != NULL && strlen(value_c) > 0 && (isdigit(value_c[0]) || (value_c[0] == '-' && isdigit(value_c[1])) ) ) {
|
||||
int16_t value;
|
||||
JsonParserObject root = JsonParser(mqtt_data).getRootObject();
|
||||
if (root) {
|
||||
JsonParserToken value_token = root[PSTR(THERMOSTAT_SENSOR_NAME)].getObject()[PSTR("Temperature")];
|
||||
if (value_token.isNum()) {
|
||||
int16_t value = value_token.getFloat() * 10;
|
||||
if (Thermostat[ctr_output].status.temp_format == TEMP_FAHRENHEIT) {
|
||||
value = (int16_t)ThermostatFahrenheitToCelsius((int32_t)(CharToFloat(value_c) * 10), TEMP_CONV_ABSOLUTE);
|
||||
}
|
||||
else {
|
||||
value = (int16_t)(CharToFloat(value_c) * 10);
|
||||
value = ThermostatFahrenheitToCelsius(value, TEMP_CONV_ABSOLUTE);
|
||||
}
|
||||
if ( (value >= -1000)
|
||||
&& (value <= 1000)
|
||||
|
@ -76,7 +76,7 @@ bool TelegramInit(void) {
|
||||
if (!telegramClient) {
|
||||
telegramClient = new BearSSL::WiFiClientSecure_light(tls_rx_size, tls_tx_size);
|
||||
#ifdef USE_MQTT_TLS_CA_CERT
|
||||
telegramClient->setTrustAnchor(&GoDaddyCAG2_TA);
|
||||
telegramClient->setTrustAnchor(&GoDaddyCAG2_TA, 1);
|
||||
#else
|
||||
telegramClient->setPubKeyFingerprint(Telegram_Fingerprint, Telegram_Fingerprint, false); // check server fingerprint
|
||||
#endif
|
||||
@ -225,15 +225,21 @@ void TelegramAnalizeMessage(void) {
|
||||
for (uint32_t i = 1; i < Telegram.message[0][0].toInt() +1; i++) {
|
||||
Telegram.message[i][5] = "";
|
||||
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject &root = jsonBuffer.parseObject(Telegram.message[i][0]);
|
||||
if (root.success()) {
|
||||
Telegram.message[i][0] = root["update_id"].as<String>();
|
||||
Telegram.message[i][1] = root["message"]["from"]["id"].as<String>();
|
||||
Telegram.message[i][2] = root["message"]["from"]["first_name"].as<String>();
|
||||
Telegram.message[i][3] = root["message"]["from"]["last_name"].as<String>();
|
||||
Telegram.message[i][4] = root["message"]["chat"]["id"].as<String>();
|
||||
Telegram.message[i][5] = root["message"]["text"].as<String>();
|
||||
String buf = Telegram.message[i][0]; // we need to keep a copy of the buffer
|
||||
JsonParserObject root = JsonParser((char*)buf.c_str()).getRootObject();
|
||||
if (root) {
|
||||
Telegram.message[i][0] = root["update_id"].getStr();
|
||||
Telegram.message[i][1] = root["message"].getObject()["from"].getObject()["id"].getStr();
|
||||
Telegram.message[i][2] = root["message"].getObject()["from"].getObject()["first_name"].getStr();
|
||||
Telegram.message[i][3] = root["message"].getObject()["from"].getObject()["last_name"].getStr();
|
||||
Telegram.message[i][4] = root["message"].getObject()["chat"].getObject()["id"].getStr();
|
||||
Telegram.message[i][5] = root["message"].getObject()["text"].getStr();
|
||||
// Telegram.message[i][0] = root["update_id"].as<String>();
|
||||
// Telegram.message[i][1] = root["message"]["from"]["id"].as<String>();
|
||||
// Telegram.message[i][2] = root["message"]["from"]["first_name"].as<String>();
|
||||
// Telegram.message[i][3] = root["message"]["from"]["last_name"].as<String>();
|
||||
// Telegram.message[i][4] = root["message"]["chat"]["id"].as<String>();
|
||||
// Telegram.message[i][5] = root["message"]["text"].as<String>();
|
||||
}
|
||||
|
||||
int id = Telegram.message[Telegram.message[0][0].toInt()][0].toInt() +1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user