We are using TRB140 to forward received SMS messages to a custom system via HTTP. Firmware is 7.04.5.
Generally everything works fine. However, if the HTTP request fails for whatever reason, the modem will not try again and/or report error. If we configure the modem to store forwarded messages, the message will be stored, but the only possible action (in the message list) is delete. If storing forwarded messages is disabled, the message simply vanishes.
This behaviour makes creating somewhat reliable service impossible.
Indeed, if the SMS forwarding to the HTTP server encounters an issue and fails, the service will log this failure, and the affected SMS message will not be resent.
To address this situation, you can implement a script to handle it to some extent. Here’s an example approach:
You can set up a script that continuously monitors the logread for instances when forwarding fails. When such an error is detected, the script can retrieve the last SMS message and attempt to resend it using curl. If the initial attempt fails (non-200 HTTP result code), the script will wait for a specified time and retry until it successfully forwards the SMS. You can then run this script as a service using the command ‘sh /etc/yourscript &’ and include it in the System → Custom scripts to ensure it runs automatically after each reboot.
Here are some useful commands:
#check logread for fails:
logread | grep fwd_to_http
#for example:
logread -f | while read -r log_line; do
if echo "$log_line" | grep -q 'fwd_to_http'; then
#get text of the last SMS message:
ubus call gsm.modem0 read_sms '{"index":-1}' | jsonfilter -e '@.messages[0].text'
# Use curl to post data:
curl_result=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "key=$yourkey&value=$sms_text" "$server_url")
# Check the HTTP response code
if [ "$curl_result" = "200" ]; then
echo "SMS message successfully posted."
else
sleep $your_interval
You can find other script examples on this forum, as well as our old (read-only) forum here.
Thank you AndzejJ for a quick reply and a proposed solution. However the system doesn’t work as expected, there will be no information of failure in the log.
If we disable the receiving http service and set Don’t save received message to off (i.e. store the message), logread will show only this:
root@Teltonika-TRB140:~# logread -f
Wed Oct 4 15:37:02 2023 kern.notice kernel: SMS received from: +358XXXXXXXX (internal modem
If we set Don’t save received message to on (i.e. do not store the message), logread will show this:
root@Teltonika-TRB140:~# logread -f
Wed Oct 4 15:45:47 2023 kern.notice kernel: SMS received from: +358XXXXXXXX (internal modem)
Wed Oct 4 15:45:47 2023 daemon.info /usr/sbin/sms_utils: Removing SMS '2' from memory
Is there a bug or should the system be somehow configured to include fwd_to_http messages to log?
The idea was to use SMS to HTTP forwarding service as usual. The script would only capture the error when the service fails, i.e. SMS was not delivered to the HTTP server. Then it will try to get the last message and try sending it again through its own means (curl in the script).
If you enable the SMS to HTTP service, execute ‘logread -f’ and try forwarding SMS to a server that you know is not available, do you see the error then?
Also, make sure you are on the latest firmware version.
This is not a full script, just some of the commands that you may use in your own solution.