Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPU-6050 incorrect json output (via mqtt) #4412

Closed
6 tasks done
paspo opened this issue Nov 22, 2018 · 2 comments
Closed
6 tasks done

MPU-6050 incorrect json output (via mqtt) #4412

paspo opened this issue Nov 22, 2018 · 2 comments
Labels
bug Type - Confirmated Bug fixed Result - The work on the issue has ended

Comments

@paspo
Copy link

paspo commented Nov 22, 2018

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

  • Searched the problem in issues and in the wiki
  • Hardware used : Sonoff SV + MPU-6050 (sda/scl on gpio 4&5)
  • Development/Compiler/Upload tools used : atom + PlatformIO
  • If a pre-compiled release or development binary was used, which one? : none
  • You have tried latest release or development binaries? : commit #5b5b0b928fbd4292c745938c507a9dcf3badff93
  • Provide the output of commandstatus 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.

@ascillato2 ascillato2 added the bug Type - Confirmated Bug label Nov 22, 2018
@andrethomas
Copy link
Contributor

Looks correct, please make a PR.

@arendst
Copy link
Owner

arendst commented Nov 23, 2018

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

arendst added a commit that referenced this issue Nov 23, 2018
Fix MPU6050 JSON message (#4412)
@arendst arendst added the fixed Result - The work on the issue has ended label Nov 23, 2018
gemu2015 pushed a commit to gemu2015/Sonoff-Tasmota that referenced this issue Jan 27, 2019
Fix MPU6050 JSON message (arendst#4412)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type - Confirmated Bug fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

4 participants