diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino index 4b209123e..743fc1f62 100755 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino @@ -4750,7 +4750,10 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value); lp++; } } - bool isint = is_int_var(lp); + bool isint = false; + if (*lp != '(') { + isint = is_int_var(lp); + } lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); char str[SCRIPT_MAXSSIZE]; if (isint) { @@ -7696,6 +7699,24 @@ getnext: #ifdef USE_SCRIPT_ONEWIRE +bool script_OneWireCrc8(uint8_t *addr) { + uint8_t crc = 0; + uint8_t len = 8; + + while (len--) { + uint8_t inbyte = *addr++; // from 0 to 7 + for (uint32_t i = 8; i; i--) { + uint8_t mix = (crc ^ inbyte) & 0x01; + crc >>= 1; + if (mix) { + crc ^= 0x8C; + } + inbyte >>= 1; + } + } + return (crc == *addr); // addr 8 +} + uint32_t script_ow(uint8_t sel, uint32_t val) { uint32_t res = 0; uint8_t bits; @@ -7843,27 +7864,41 @@ ScriptOneWire *ow = &glob_script_mem.ow; } if (ow->ds) { + uint8_t data[9]; ow->ds->reset(); ow->ds->select(ow->ds_address[val - 1]); if (!bits) { ow->ds->write(0x44, 1); } else { ow->ds->write(0xbe, 1); - delay(10); - res = ow->ds->read(); - res |= ow->ds->read() << 8; + for (uint32_t cnt = 0; cnt < 9; cnt++) { + data[cnt] = ow->ds->read(); + } + if (script_OneWireCrc8(data)) { + res = data[0]; + res |= data[1] << 8; + } else { + res = 0; + } ow->ds->reset(); } } else { + uint8_t data[9]; ow->dsh->reset(); ow->dsh->select(ow->ds_address[val - 1]); if (!bits) { ow->dsh->write(0x44, 1); } else { ow->dsh->write(0xbe, 1); - delay(10); - res = ow->dsh->read(); - res |= ow->dsh->read() << 8; + for (uint32_t cnt = 0; cnt < 9; cnt++) { + data[cnt] = ow->dsh->read(); + } + if (script_OneWireCrc8(data)) { + res = data[0]; + res |= data[1] << 8; + } else { + res = 0; + } ow->dsh->reset(); } } @@ -8894,7 +8929,7 @@ void Script_Check_Hue(String *response) { } #ifdef SCRIPT_HUE_DEBUG if (response) { - AddLog(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs); + AddLog(LOG_LEVEL_INFO, PSTR("Hue: %d"), hue_devs); toLog(">>>>"); toLog(response->c_str()); toLog(response->c_str()+700); // Was MAX_LOGSZ @@ -8926,20 +8961,33 @@ void Script_Handle_Hue(String path) { uint8_t device = DecodeLightId(atoi(path.c_str())); uint8_t index = device - TasmotaGlobal.devices_present - 1; + uint16_t args = Webserver->args(); + +#ifdef ESP82666 + char *json = (char*)Webserver->arg(args - 1).c_str(); +#else + String request_arg = Webserver->arg(args - 1); + char *json = (char*)request_arg.c_str(); +#endif + +#ifdef SCRIPT_HUE_DEBUG + AddLog(LOG_LEVEL_INFO, PSTR("Hue 0: %s - %d "),path.c_str(), device); + AddLog(LOG_LEVEL_INFO, PSTR("Hue 1: %d, %s"), args, json); +#endif if (Webserver->args()) { response = "["; - JsonParser parser((char*) Webserver->arg((Webserver->args())-1).c_str()); + JsonParser parser(json); JsonParserObject root = parser.getRootObject(); JsonParserToken hue_on = root[PSTR("on")]; - if (hue_on) { + if (hue_on) { response += FPSTR(sHUE_LIGHT_RESPONSE_JSON); response.replace("{id", String(EncodeLightId(device))); response.replace("{cm", "on"); bool on = hue_on.getBool(); - if (on==false) { + if (on == false) { glob_script_mem.fvars[hue_script[index].index[0] - 1] = 0; response.replace("{re", "false"); } else { @@ -10158,6 +10206,16 @@ const char SCRIPT_MSG_PULLDOWNb[] PROGMEM = const char SCRIPT_MSG_PULLDOWNc[] PROGMEM = ""; +const char SCRIPT_MSG_RADIOa[] PROGMEM = + "%s