-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
SHT3X sensor driver: invalid JSON identifier syntax when converted to a JSON object in node-red #4313
Comments
Thanks for your report. Very complete 👍 Made the PR #4314 for solving this. |
To be noted: Refering RFC 7159 a JSON token is a String which needs only escaping a few characters - where a dash is not part of it. This solution here is a workaroung for the wrong implemtation in node-re template. The correct way would be node-red using the suggestion of #1949 Frogmore42. edit: |
Not sure if it is mentioned earlier but to get the temperature and/or humidity of the sensor received from mqtt in node-red one can do the following: mqtt node -> json node -> function node where the function node has the following code:
In other words, using the bracket-quote style notation one can access the key - value pair. |
@curzon01 is right. There is no need for this fix. Thanks for pointing this. This is the good thing of posting a PR for revision. Thanks to all. |
Describe the bug
Closed issues #1949 and #3758 refer - the issue raised in each bug report (with reference to a Home Assistant use case) has been closed but is not resolved. I have further input to make on the issue in a node-red use case.
Also, make sure these boxes are checked [x] before submitting your issue - Thank you!
status 0
:To Reproduce
Using node-red, connect an MQTT input node to a JSON string to object converter node to a function node. In the (Javascript) function node, reference to the JSON object identifier "SHT3X-0x44" throws a syntax error.
The error is that the dash between the sensor type and the i2c address is not a valid JSON object identifier within Javascript. This is discussed in more detail in the referenced closed issues but within a Home Assistant use case.
Refer: https://developer.mozilla.org/en-US/docs/Glossary/Identifier Quote: "In JavaScript, identifiers can contain only alphanumeric characters (or "$" or "_"), and may not start with a digit."
Thus, an underscore is correct but a dash is not.
I have proved the bug fix by editing the sensor driver xsns_14_sht3x.ino and modifying the PSTR in line 109 from PSTR("%s-0x%02X") to PSTR("%s_0x%02X"). This creates a correctly parsable JSON object identifier.
I don't have the knowledge to propose a change within github.
Expected behavior
The node-red function node should output correctly parsed JSON values for temperature and humidity for further processing in the flow.
Screenshots
n/a
Additional context
Closed issues #1949 and #3758 refer - the issue raised in each bug report (with reference to a Home Assistant use case) has been closed but not resolved.
(Please, remember to close the issue when the problem has been addressed)
The text was updated successfully, but these errors were encountered: