I've now got this script running on the router, launches after boot-up. The combination of gsmctl + grep + echo creates a /tmp/regfile which is always greater than 250 characters in size. I have my modbus request set to 125 registers (the maximum) so I need a minimum of 250 characters in /tmp/regfile otherwise I get modbus server errors. The '000...' just pad out the file.
#! /bin/ash
while true
do
gsmctl -CA 'AT+QCAINFO' -o --modemtime 2 grep pattern file | tr '\n\r,\"' ',' > /tmp/regfile
echo '0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000' >> /tmp/regfile
sleep 8
done
And after following the Teltonika documentation about Custom Modbus Registers (aka reading and broadcasting /tmp/regfile) I'm now able to log primary and secondary GSM bands, signal strength data, serving cell etc. etc. in Home Assistant.
Using the script above, my /tmp/regfile looks like the text below – comma delimited ASCII, which is easy enough for Home Assistant to parse:
72108043,+QCAINFO: ,PCC,,6300,50,,LTE BAND 20,,1,381,-84,-11,-54,0,,+QCAINFO: ,SCC,,103,100,,LTE BAND 1,,1,381,-95,-12,-73,8,0,-,-,,+QCAINFO: ,SCC,,1300,100,,LTE BAND 3,,1,381,-90,-11,-71,5,0,-,-,,+QCAINFO: ,SCC,,154570,1,,NR5G BAND 28,,381,,,vodafone P,23/04/13,22:06:17,0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000
And the Home Assistant monitoring page looks something like this. I'm trying to diagnose midnight connection blackouts, so this should help.
And finally I'm happy to share the Home Assistant yaml setup if anyone needs ... but if I paste all that into this comment I'm bumping up against the maximum word count :)