[GH-ISSUE #121] 3ginfo.sh returning malformed JSON on 1.0.75 #95

Open
opened 2026-03-04 11:58:35 +03:00 by kerem · 2 comments
Owner

Originally created by @raenye on GitHub (May 11, 2025).
Original GitHub issue: https://github.com/4IceG/luci-app-3ginfo-lite/issues/121

Please note the SINR parameter, it became unterminated and the JSON is invalid.
(modem is Sierra Wireless MC7430).

Please advise, thanks.

1.0.74

root@OpenWrt:~# /usr/share/3ginfo-lite/3ginfo.sh | tail
"s3pci":"",
"s3earfcn":"",
"s4band":"",
"s4pci":"",
"s4earfcn":"",
"rsrp":"-134/-91",
"rsrq":"-14.0",
"rssi":"-98/-63",
"sinr":"-1.2"
}

1.0.75

root@OpenWrt:~# /usr/share/3ginfo-lite/3ginfo.sh | tail
"s3pci":"0",
"s3earfcn":"0",
"s4band":"-",
"s4pci":"0",
"s4earfcn":"0",
"rsrp":"-135/-96",
"rsrq":"-11.8",
"rssi":"-93/-67",
"sinr":"6.4
}
Originally created by @raenye on GitHub (May 11, 2025). Original GitHub issue: https://github.com/4IceG/luci-app-3ginfo-lite/issues/121 Please note the SINR parameter, it became unterminated and the JSON is invalid. (modem is Sierra Wireless MC7430). Please advise, thanks. 1.0.74 ``` root@OpenWrt:~# /usr/share/3ginfo-lite/3ginfo.sh | tail "s3pci":"", "s3earfcn":"", "s4band":"", "s4pci":"", "s4earfcn":"", "rsrp":"-134/-91", "rsrq":"-14.0", "rssi":"-98/-63", "sinr":"-1.2" } ``` 1.0.75 ``` root@OpenWrt:~# /usr/share/3ginfo-lite/3ginfo.sh | tail "s3pci":"0", "s3earfcn":"0", "s4band":"-", "s4pci":"0", "s4earfcn":"0", "rsrp":"-135/-96", "rsrq":"-11.8", "rssi":"-93/-67", "sinr":"6.4 } ```
Author
Owner

@4IceG commented on GitHub (May 12, 2025):

Hi,
Show me debugging result, I don't know what the script shows. Writing that there is an error doesn't help, I don't have a crystal ball.

<!-- gh-comment-id:2872962229 --> @4IceG commented on GitHub (May 12, 2025): Hi, Show me debugging result, I don't know what the script shows. Writing that there is an error doesn't help, I don't have a crystal ball.
Author
Owner

@raenye commented on GitHub (Jun 5, 2025):

OK, I found the problem.

TL;DR

Suggestion for fix:

--- /usr/share/3ginfo-lite/modem/usb/11999071.old
+++ /usr/share/3ginfo-lite/modem/usb/11999071
@@ -21,7 +21,7 @@
        T=$(echo "$O" | awk '/^RSRQ/ {print $3}')
        [ -n "$T" ] && RSRQ="$T"
        T=$(echo "$O" | awk '/^SINR/ {print $3}')
-       [ -n "$T" ] && SINR="$T"
+       [ -n "$T" ] && SINR="${T%$'\r'}"
 
        T=$(echo "$O" | awk '/^LTE band:/ {print $3}')
        if [ -n "$T" ]; then

Long version

In version 1.0.74 the last few lines of /usr/share/3ginfo-lite/3ginfo.sh are:

"rsrq":"$RSRQ",
"rssi":"$RSSI",
"sinr":"$(echo $SINR | tr -d '\r')"
}
EOF
exit 0

while version 1.0.75 adds sanitization:

"rsrq":"$(sanitize_number "$RSRQ")",
"rssi":"$(sanitize_number "$RSSI")",
"sinr":"$(sanitize_number "$SINR")"
}
EOF
exit 0

But there is something missing for sinr: the removal of '\r'.
Indeed, see the CR (0x0d) between "-4.4 and the closing ":

root@OpenWrt:~# /usr/share/3ginfo-lite/3ginfo.sh | tail | hexdump -C
00000000  22 73 33 70 63 69 22 3a  22 30 22 2c 0a 22 73 33  |"s3pci":"0",."s3|
00000010  65 61 72 66 63 6e 22 3a  22 30 22 2c 0a 22 73 34  |earfcn":"0",."s4|
00000020  62 61 6e 64 22 3a 22 2d  22 2c 0a 22 73 34 70 63  |band":"-",."s4pc|
00000030  69 22 3a 22 30 22 2c 0a  22 73 34 65 61 72 66 63  |i":"0",."s4earfc|
00000040  6e 22 3a 22 30 22 2c 0a  22 72 73 72 70 22 3a 22  |n":"0",."rsrp":"|
00000050  2d 31 30 39 2f 2d 31 30  37 22 2c 0a 22 72 73 72  |-109/-107",."rsr|
00000060  71 22 3a 22 2d 31 35 2e  31 22 2c 0a 22 72 73 73  |q":"-15.1",."rss|
00000070  69 22 3a 22 2d 37 34 2f  2d 37 31 22 2c 0a 22 73  |i":"-74/-71",."s|
00000080  69 6e 72 22 3a 22 2d 34  2e 34 0d 22 0a 7d 0a     |inr":"-4.4.".}.|
0000008f

Maybe the correct approach is to make sure the script in /usr/share/3ginfo-lite/modem/usb/ does not output a malformed number, and in particular have /usr/share/3ginfo-lite/modem/usb/11999071 strip correctly the carriage return.
This is what the TL;DR code above implements.

<!-- gh-comment-id:2944333992 --> @raenye commented on GitHub (Jun 5, 2025): OK, I found the problem. ### TL;DR Suggestion for fix: ``` --- /usr/share/3ginfo-lite/modem/usb/11999071.old +++ /usr/share/3ginfo-lite/modem/usb/11999071 @@ -21,7 +21,7 @@ T=$(echo "$O" | awk '/^RSRQ/ {print $3}') [ -n "$T" ] && RSRQ="$T" T=$(echo "$O" | awk '/^SINR/ {print $3}') - [ -n "$T" ] && SINR="$T" + [ -n "$T" ] && SINR="${T%$'\r'}" T=$(echo "$O" | awk '/^LTE band:/ {print $3}') if [ -n "$T" ]; then ``` ### Long version In version 1.0.74 the last few lines of `/usr/share/3ginfo-lite/3ginfo.sh` are: ``` "rsrq":"$RSRQ", "rssi":"$RSSI", "sinr":"$(echo $SINR | tr -d '\r')" } EOF exit 0 ``` while version 1.0.75 adds sanitization: ``` "rsrq":"$(sanitize_number "$RSRQ")", "rssi":"$(sanitize_number "$RSSI")", "sinr":"$(sanitize_number "$SINR")" } EOF exit 0 ``` But there is something missing for `sinr`: the removal of `'\r'`. Indeed, see the CR (`0x0d`) between `"-4.4` and the closing `"`: ``` root@OpenWrt:~# /usr/share/3ginfo-lite/3ginfo.sh | tail | hexdump -C 00000000 22 73 33 70 63 69 22 3a 22 30 22 2c 0a 22 73 33 |"s3pci":"0",."s3| 00000010 65 61 72 66 63 6e 22 3a 22 30 22 2c 0a 22 73 34 |earfcn":"0",."s4| 00000020 62 61 6e 64 22 3a 22 2d 22 2c 0a 22 73 34 70 63 |band":"-",."s4pc| 00000030 69 22 3a 22 30 22 2c 0a 22 73 34 65 61 72 66 63 |i":"0",."s4earfc| 00000040 6e 22 3a 22 30 22 2c 0a 22 72 73 72 70 22 3a 22 |n":"0",."rsrp":"| 00000050 2d 31 30 39 2f 2d 31 30 37 22 2c 0a 22 72 73 72 |-109/-107",."rsr| 00000060 71 22 3a 22 2d 31 35 2e 31 22 2c 0a 22 72 73 73 |q":"-15.1",."rss| 00000070 69 22 3a 22 2d 37 34 2f 2d 37 31 22 2c 0a 22 73 |i":"-74/-71",."s| 00000080 69 6e 72 22 3a 22 2d 34 2e 34 0d 22 0a 7d 0a |inr":"-4.4.".}.| 0000008f ``` Maybe the correct approach is to make sure the script in `/usr/share/3ginfo-lite/modem/usb/` does not output a malformed number, and in particular have `/usr/share/3ginfo-lite/modem/usb/11999071` strip correctly the carriage return. This is what the TL;DR code above implements.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/luci-app-3ginfo-lite#95
No description provided.