Well, I have already received my Huawei E3372h-320 modem that incorporates an API that allows to manage some functions of the modem.
I have tested the following script and it works correctly:
:global sendSMS do={
# Send SMS messages via Huawei LTE modem API (tested with E3372)
# global vars:
# lteIP - lte modem ip address (api)
# phone - sms destination phone number
# sms - sms text message
# usage example
# :global sendSMS
# :put [$sendSMS lteIP="192.168.8.1" phone="+35912345678" sms="test sms via lte api"]
#
:local getBetween do={
# "CuriousKiwi - mikrotik forum"
# This is a basic parser, can be used for XML
# It takes three parameters:
# inputString - The main string
# betweenStart - Text AFTER this point will be returned
# betweenEnd - Text BEFORE this point will be returned
:local posStart 0;
:if ([:len $betweenStart] > 0) do={
:set posStart [:find $inputString $betweenStart]
:if ([:len $posStart] = 0) do={
:set posStart 0
} else={
:set posStart ($posStart + [:len $betweenStart])
}
}
:local posEnd 9999;
:if ([:len $betweenEnd] > 0) do={
:set posEnd [:find $inputString $betweenEnd];
:if ([:len $posEnd] = 0) do={ :set posEnd 9999 }
}
:local result [:pick $inputString $posStart $posEnd];
:return $result;
}
:local lteIP "192.168.8.1"
# get SessionID and Token via LTE modem API
:local urlSesTokInfo "http://$lteIP/api/webserver/SesTokInfo";
:local api [/tool fetch $urlSesTokInfo output=user as-value];
:local apiData ($api->"data");
# pars SessionID and Token from API session data
:local apiSessionID [$getBetween inputString=$apiData betweenStart="<SesInfo>" betweenEnd="</SesInfo>"];
:local apiToken [$getBetween inputString=$apiData betweenStart="<TokInfo>" betweenEnd="</TokInfo>"];
# header and data config
:local apiHead "Content-Type:application/x-www-form-urlencoded,Cookie: $apiSessionID,__RequestVerificationToken:$apiToken";
:local sendData "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><Index>-1</Index><Phones><Phone>$phone</Phone></Phones><Sca></Sca><Content>$sms</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>";
# send SMS via LTE modem API with fetch
/tool fetch http-method=post output=user \
http-header-field=$apiHead \
url="http://$lteIP/api/sms/send-sms" \
http-data=$sendData;
}
To use it, I type from Terminal the following command:
:put [$sendSMS lteIP="192.168.8.1" phone="+35912345678" sms="test sms via lte api"]
All correct, it sends the SMS without errors.
Now, like my colleague @notanial I am trying to figure out how I can get the list of received SMS and be able to forward them by email or save them in a file.
Using this script:
:global recvSMS do={
:local lteIP "192.168.8.1"
:local getBetween do={
:local posStart 0;
:if ([:len $betweenStart] > 0) do={
:set posStart [:find $inputString $betweenStart]
:if ([:len $posStart] = 0) do={
:set posStart 0
} else={
:set posStart ($posStart + [:len $betweenStart])
}
}
:local posEnd 9999;
:if ([:len $betweenEnd] > 0) do={
:set posEnd [:find $inputString $betweenEnd]
:if ([:len $posEnd] = 0) do={ :set posEnd 9999 }
}
:local result [:pick $inputString $posStart $posEnd]
:return $result
}
# get SessionID and Token via LTE modem API
:local urlSesTokInfo "http://$lteIP/api/webserver/SesTokInfo"
:local api [/tool fetch $urlSesTokInfo output=user as-value]
:local apiData ($api->"data")
# pars SessionID and Token from API session data
:local apiSessionID [$getBetween inputString=$apiData betweenStart="<SesInfo>" betweenEnd="</SesInfo>"]
:local apiToken [$getBetween inputString=$apiData betweenStart="<TokInfo>" betweenEnd="</TokInfo>"]
# header and data config
:local apiHead "Content-Type:text/xml,Cookie: $apiSessionID,__RequestVerificationToken:$apiToken"
:local recvData "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><PageIndex>1</PageIndex><ReadCount>20</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>"
# recv SMS via LTE modem API with fetch
/tool fetch http-method=post output=user \
http-header-field=$apiHead \
url="http://$lteIP/api/sms/sms-list" \
http-data=$recvData;
}
:local arrData [ :toarray $recvSMS ]
:local varData ( $arrData->"data" )
:put [ $varData ]
I execute with
:put [$recvSMS]
and I get the following result:
With a message received:
status: finished
downloaded: 0KiBC-z pause]
data: <?xml version="1.0" encoding="UTF-8"?> 1 0
40001 +34XXXXXXXXX SMS test from my Mobile 2023-01-11
13:20:26 0 0 1
\
With 3 messages received:
status: finished
downloaded: 0KiBC-z pause]
data: <?xml version="1.0" encoding="UTF-8"?> 3 1
40003 +34XXXXXXXXX SMS test from my Mobile3 2023-01-11
17:02:05 0 0 1
1 40002 +34XXXXXXXXX SMS test from my
Mobile2 2023-01-11 16:59:48 0 0
1 1 40001 +34XXXXXXXXX
SMS test from my Mobile 2023-01-11 13:20:26 0
0 1
There is a function that allows you to extract certain data from XML:
:global getBetween do={
:local posStart 0;
:if ([:len $betweenStart] > 0) do={
:set posStart [:find $inputString $betweenStart]
:if ([:len $posStart] = 0) do={
:set posStart 0
} else={
:set posStart ($posStart + [:len $betweenStart])
}
}
:local posEnd 9999;
:if ([:len $betweenEnd] > 0) do={
:set posEnd [:find $inputString $betweenEnd]
:if ([:len $posEnd] = 0) do={ :set posEnd 9999 }
}
:local result [:pick $inputString $posStart $posEnd]
:return $result
}
The idea is to extract the content of and of each SMS using the previous function and save it to give those values to local variables in order to resend those messages or save them in a file. But I don’t know how to do it. 
I have tried this without success:
{
:global getBetween
:execute {$recvSMS} file=sms-list.xml
:local ExtractedXML [/file get sms-list.xml.txt contents]
:local phon [$getBetween inputString=$ExtractedXML betweenStart="<Phone>" betweenEnd="</Phone>"]
:local mens [$getBetween inputString=$ExtractedXML betweenStart="<Content>" betweenEnd="</Content>"]
:put "$phon\t$mens"
}
Any help please??
BR.