thingsboard / thingsboard-edge

Apache License 2.0
98 stars 74 forks source link

[Bug] JSON shared attributes are synced as String to the edge #17

Closed thirstyfish closed 2 years ago

thirstyfish commented 2 years ago

Describe the bug JSON type shared attributes are synced to the edge as String rather than JSON.

Your Server Environment Own cloud instance running in k8s, v3.3.4.1 for both the TB cloud and the edge

Your Client Environment Mac & Chrome

To Reproduce Steps to reproduce the behavior:

  1. Setup device in TB cloud with a JSON shared attribute and assign to a customer
  2. Assign device to edge instance
  3. Sync edge instance
  4. Shared attribute is synced as String instead of JSON

Expected behavior The type of the shared attribute should match the type of the attribute on the cloud

volodymyr-babak commented 2 years ago

Hello @thirstyfish,

I just tried it with the latest 3.4 release version and it works as expected. Cloud: image Edge: image

ThingsBoard 3.4 platform was released last week. Edge 3.4 is going to be released tomorrow. Please do upgrade to 3.4 once you'll have the possibility - the issue should be fixed.

thirstyfish commented 2 years ago

No worries, thanks @volodymyr-babak , we'll be testing with 3.4 in the near future.

qiangwanfu commented 2 years ago

边缘和云部署在一台服务器可以收到rpc 控制 部署在两台服务器上收不到rpc命令 什么原因呢3.4版本边和云都是

qiangwanfu commented 2 years ago

防火墙处于关闭状态 遥测数据可以同步

thirstyfish commented 2 years ago

Tested with 3.4 TB Edge and server versions and can confirm that the issue is resolved. Closing bug, thanks.

AndreMaz commented 1 year ago

@volodymyr-babak not sure why but this issue seems to be back in v3.5.1

Whenever I press "Sync Edge" the shared attributes @ TB-Cloud, that are specified as JSON, are synced to TB-Edge as String.

image

Temporary fix: After every "Sync Edge" I manually change type from String to JSON

volodymyr-babak commented 1 year ago

@AndreMaz

The bug you mentioned is a separate issue but has been recently addressed in the following pull request: GitHub PR #9091.

This fix will be included in our upcoming release. Currently, we've frozen the addition of new features and are only accepting bug fixes. The new version is expected to be released in a couple of weeks.

AndreMaz commented 1 year ago

@volodymyr-babak thank you for quick response. Waiting for new release

Totally unrelated to this issue but is there any chance that https://github.com/thingsboard/thingsboard-edge/issues/57#issuecomment-1704950106 issue is also addressed in the new release?

volodymyr-babak commented 1 year ago

@AndreMaz

Thank you for providing additional information. Over the next few days, I'll attempt to reproduce the issue and will update you on whether a fix will be included in the upcoming release.

At the moment, unfortunately, I don't have a consistent set of steps to reproduce the issue for a definitive fix. Additionally, a deep code analysis hasn't yet shed light on why this is occurring.

aistisdev commented 3 months ago

@volodymyr-babak

Hello, I have encountered a similar problem with creating a String attribute, that gets converted to long after syncing between edge and tb:

image image

This happens both ways (edge to tb, tb to edge) and only happens if I create String attribute that has only '0' symbols as shown in the screenshots.

I'm currently using thingsboard/tb-edge-pe:3.6.2EDGEPE and thingsboard/tb-pe-node:3.6.2PE. Has this been fixed in future newer versions?

EDIT:

Actually it seems to remove leading zero symbols from string and converts it to integer: 0011 will be 11 0000000001 will be 1 1000000000 will be 1000000000

So the problem seems to be when the string has all digits and has leading zero digits.

volodymyr-babak commented 3 months ago

@aistisdev

to fix this behavior please add next parameter to conf files of thingsboard and edge services: export JSON_TYPE_CAST_ENABLED=false

In this way converters will not try to convert string values to integer if possible.

aistisdev commented 2 months ago

@aistisdev

to fix this behavior please add next parameter to conf files of thingsboard and edge services: export JSON_TYPE_CAST_ENABLED=false

In this way converters will not try to convert string values to integer if possible.

Thanks, seems to be working. Is there a specific reason (that I should be aware of) why this option is set to true by default?

volodymyr-babak commented 2 months ago

@aistisdev

I would say that historically this option was set to true by default. We can't change default value for this parameter to false to avoid backward compatibility issues. Considering number of issues related to this auto casting from String to Long, we probably considered to disable it at the start of the product, but for now we can't do this as a lot of deployment already working with this feature in place and disable it would broke a lot of production setups.