arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.71k stars 4.72k forks source link

Crash on Domotics scene/group message on MQTT #3963

Closed mycroes closed 5 years ago

mycroes commented 5 years ago

I'm using sonoff.bin version 6.2.1 (manual download from releases page). I have 3 devices that are working fine individually, but since I created a screne (type group) to group them in Domoticz one of the devices seems to have issues. I subscribed to domoticz/out with MQTT.fx to see what messages are being send and noticed Domoticz also sends a message for the scene/group itself. The body of the message is as follows:

{
   "LastUpdate" : "2018-10-02 20:39:45",
   "Name" : "Sfeerverlichting",
   "Status" : "Off",
   "Timers" : "true",
   "Type" : "Group",
   "idx" : "2"
}

Sending this message manually (using MQTT.fx) causes an identical restart of the Sonoff.

I'm not sure if it's normal (this is my first Domoticz install, I'm running a Docker container and had no issues at all setting it up), but idx 2 is used both by the scene/group and the Sonoff. I added my Sonoffs first, so they have idx 1, 2, 3 and 4 (of which one is having issues since I started using it, but that's out of the scope of this issue). I added a scene first and then the group, so probably the scene had idx 1 before I deleted it, and the group has idx 2.

Is it absolutely wrong that the scene/group has the same idx as the Sonoff (and do you perhaps have any clue how that could have happened), or is there something more I should have configured to prevent the exception?

arendst commented 5 years ago

Nice problem. Will investigate tomorrow. I probably have to do better message analyzing.

mycroes commented 5 years ago

@arendst Is that by any chance something I could fix as newbie to ESP8266? I'm a C# developer (professionally) but I have a fondness for programming in general (and have done more than just C# in the past as well). I must admit though that I haven't even installed PlatformIO, never programmed my Arduino Uno, but this doesn't sound like a hard issue to handle...

mycroes commented 5 years ago

@arendst I'm guessing the problem arises from xdrv_07_domoticz.ino:177: nvalue = domoticz["nvalue"];, which is definitely not there in the JSON. (Yes, installed PlatformIO now :smile:)

arendst commented 5 years ago

Me too. Didn't find the time yet.

mycroes commented 5 years ago

Please correct me if I'm wrong, but I think the following could fix it: Line 182 original:

if ((idx > 0) && (nvalue >= 0) && (nvalue <= 15)) {

proposed:

if ((idx > 0) && nvalue.success() && (nvalue >= 0) && (nvalue <= 15)) {

I have no clue how to build or anything, but this seems to make sense after checking the ArduinoJson source.

mycroes commented 5 years ago

Err that won't work, nvalue is int16_t. However JsonObject[<string>] should return a JsonObjectSubscript which has .success() and templated conversion (is that what it's called in C++?).

arendst commented 5 years ago

Thx for your suggestions.

Just released the fix. Pls test and if OK just close this issue.

ascillato2 commented 5 years ago

@mycroes

Hi

Have you managed to test it?

mycroes commented 5 years ago

No sorry, didn't get to it yesterday... I'll test it soon and I'll close the issue then (from the code change it seems fixed).

mycroes commented 5 years ago

Can't confirm it works yet. Downloaded sonoff.bin from 4208bad from thehackbox.org/tasmota/, but now the sonoff is unreachable over network most of the time. Sometimes the web UI works for something like half a minute, but it's kinda unusable now.

I guess I have to solder header pins to update it using esptool, it didn't work the previous time when I attempted to wire it up using a breadboard and loose connections.

ascillato2 commented 5 years ago

Hi,

When you have time, please tell us if this have work for you. If not, remember that you can find us in the Tasmota Discord Chat.

Support Information

See Wiki for more information. See Community for forum. See Chat for more user experience.

mycroes commented 5 years ago

So I soldered the header, flashed 6.2.1 back in, everything seemed to be fine (didn't test extensively, but web interface was working). Then flashed the above mentioned sonoff.bin, same issue. Web interface works sometimes, but most of the times a single request is all it'll handle. Went back to 6.2.1 again, everything fine so far.

It's a Sonoff Basic, I'm not sure if it ought to be able to just use the sonoff.bin or if that could be too much for it's limited resources already, but for now that's all I could try. I can try to do a custom build with some features disabled, but honestly I would be kinda disappointed if that's what it takes to run newer Tasmota versions on my Sonoffs.