Tasmota: MPU-6050 incorrect json output (via mqtt)

Created on 22 Nov 2018  路  2Comments  路  Source: arendst/Tasmota

When data for this sensor is reported via MQTT, the json format is incorrect.

  • [x] _Searched the problem in issues and in the wiki_
  • [x] _Hardware used_ : Sonoff SV + MPU-6050 (sda/scl on gpio 4&5)
  • [x] _Development/Compiler/Upload tools used_ : atom + PlatformIO
  • [x] _If a pre-compiled release or development binary was used, which one?_ : none
  • [x] _You have tried latest release or development binaries?_ : commit #5b5b0b928fbd4292c745938c507a9dcf3badff93
  • [x] _Provide the output of command_status 0 :
17:44:36 MQT: stat/sonoff6/STATUS = {"Status":{"Module":3,"FriendlyName":["Sonoff"],"Topic":"sonoff6","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
17:44:36 MQT: stat/sonoff6/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"sonoffs","OtaUrl":"http://REDACTED/release/sonoff.bin","RestartReason":"Power on","Uptime":"0T00:11:20","StartupUTC":"2018-11-22T16:33:16","Sleep":0,"BootCount":9,"SaveCount":45,"SaveAddress":"F7000"}}
17:44:36 MQT: stat/sonoff6/STATUS2 = {"StatusFWR":{"Version":"6.3.0.7(sonoff)","BuildDateTime":"2018-11-22T17:25:57","Boot":7,"Core":"2_3_0","SDK":"1.5.3(aec24ac9)"}}
17:44:36 MQT: stat/sonoff6/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"SysLog":2,"LogHost":"REDACTED","LogPort":514,"SSId":["REDACTED",""],"TelePeriod":300,"SetOption":["00008009","5581C000","00000000"]}}
17:44:36 MQT: stat/sonoff6/STATUS4 = {"StatusMEM":{"ProgramSize":488,"Free":512,"Heap":18,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"146085","FlashMode":3,"Features":["00000809","0FCAE794","24018001","23B617CE","00003BC8"]}}
17:44:36 MQT: stat/sonoff6/STATUS5 = {"StatusNET":{"Hostname":"sonoff6-7764","IPAddress":"REDACTED","Gateway":"REDACTED","Subnetmask":"255.255.255.0","DNSServer":"REDACTED","Mac":"CC:50:E3:REDACTED","Webserver":2,"WifiConfig":2}}
17:44:36 MQT: stat/sonoff6/STATUS6 = {"StatusMQT":{"MqttHost":"REDACTED","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_029E54","MqttUser":"DVES_USER","MqttType":1,"MAX_PACKET_SIZE":1000,"KEEPALIVE":15}}
17:44:36 MQT: stat/sonoff6/STATUS7 = {"StatusTIM":{"UTC":"Thu Nov 22 16:44:36 2018","Local":"Thu Nov 22 17:44:36 2018","StartDST":"Sun Mar 25 02:00:00 2018","EndDST":"Sun Oct 28 03:00:00 2018","Timezone":"+01:00","Sunrise":"08:09","Sunset":"17:02"}}
17:44:36 MQT: stat/sonoff6/STATUS10 = {"StatusSNS":{"Time":"2018-11-22T17:44:36","MPU6050":{"Temperature":74.7,"AccelXAxis":13312.00,"AccelYAxis":0.00,"AccelZAxis":0.00,"GyroXAxis":0.00,"GyroYAxis":0.00,"GyroZAxis":0.00},"TempUnit":"C"}}
17:44:36 MQT: stat/sonoff6/STATUS11 = {"StatusSTS":{"Time":"2018-11-22T17:44:36","Uptime":"0T00:11:20","Vcc":2.994,"POWER":"OFF","Wifi":{"AP":1,"SSId":"REDACTED","BSSId":"REDACTED","Channel":10,"RSSI":42}}}

the "status 0" above reports the correct output because I corrected the sources.

To Reproduce
_Steps to reproduce the behavior:_ Compile with MPU-6050 support, connect the wifi and configure mqtt. Then take a look at the mqtt messages.

Behavior
Data received:

{"Time":"2018-11-22T17:19:14","MPU6050":{"Temperature":74.7,"AccelXAxis":13328.00,"AccelYAxis":-652.00,"AccelZAxis":18208.00,"GyroXAxis":-488.00,"GyroYAxis":-452.00,"GyroZAxis":-230.00,"},"TempUnit":"C"}

Please note the extra ," just after the value of GyroZAxis.

Expected behavior
The correct json should be:

{"Time":"2018-11-22T17:19:14","MPU6050":{"Temperature":74.7,"AccelXAxis":13328.00,"AccelYAxis":-652.00,"AccelZAxis":18208.00,"GyroXAxis":-488.00,"GyroYAxis":-452.00,"GyroZAxis":-230.00},"TempUnit":"C"}

Proposed resolution
Change this line: https://github.com/arendst/Sonoff-Tasmota/blob/9ec57e0203129719553935f52cbd23a22f0bdbec/sonoff/xsns_32_mpu6050.ino#L155
to:

snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s%s%s%s%s%s}"),

This solution is actually working for me. If it's OK, I can open a PR to fix this.

bug fixed

Most helpful comment

No need for PR. I'll fix it now.

All 2 comments

Looks correct, please make a PR.

No need for PR. I'll fix it now.

Was this page helpful?
0 / 5 - 0 ratings