OpenWrt X86_64 + Mikrotik R11e-LTE6

Hi
I use a script file to initiate my Huawei ME909s-120. wwan intetace is configured with protocol DHCP client. I even have a hotplug script for network disconnects.
I use two extra gcom files.
I have tried to adapt my script file to work with the Mikrotek modem. I´m not sure about the "AT+Z.." commands.

#!/bin/sh
# 
#


# Modem AT-port
DEV='/dev/ttyUSB0'

# PINcode
PINcode='0000'

# APN settings
APN='internet'
PDPtype='IP'
username=''
password=''


creg () {
	case $1 in
		0 )
			registration=" not registered" ;;
		1 )
			registration=" registered" ;;
		2 )
			registration=" searching" ;;
		3 )
			registration=" registration denied" ;;
		4 )
			registration=" unknown" ;;
		5 )
			registration=" registered - roaming" ;;
		* )
			registration=$1
	esac
	echo "$registration"
}


cops () {
	atOut=$(COMMAND="AT+cops?" gcom -d "${DEV}" -s /etc/gcom/getrun_at.gcom | grep COPS:)
	operator=$(echo $atOut  | awk -F , '{print $3}'  | sed -e 's/"//g')
	atOut=$(echo $atOut  | awk -F , '{print $4}' | sed -e 's/[\r\n]//g')

	case $atOut in
		0|1|3 )
			rat=GSM ;;
		2|4|5|6 )
			rat=UTRAN ;;
		7 )
			rat=LTE ;;
		* )
			rat=$atOut ;;
	esac
	echo Connected to $operator on $rat
}


# Set error codes to verbose
atOut=$(COMMAND="AT+CMEE=2" gcom -d "${DEV}" -s /etc/gcom/run_at.gcom | sed -e 's/[\r\n]//g')
while [ "$atOut" != 'OK' ]
do
	logger -t LTEmodem -p 6 Modem not ready yet
	atOut=$(COMMAND="AT+CMEE=2" gcom -d "${DEV}" -s /etc/gcom/run_at.gcom | sed -e 's/[\r\n]//g')
done
	
# Check SIMcard and PIN status
atOut=$(COMMAND="AT+CPIN?" gcom -d "${DEV}" -s /etc/gcom/getrun_at.gcom | grep CPIN: | awk -F ' ' '{print $2 $3}' | sed -e 's/[\r\n]//g')
case $atOut in
	READY )
		logger -t LTEmodem -p 6 SIMcard ready
		;;
	SIMPIN )
		if [ -z ${PINcode} ]
		then
			logger -t LTEmodem -p 3 PINcode required but missing
			exit 1
		fi
		atOut=$(COMMAND="AT+CPIN=${PINcode}" gcom -d "${DEV}" -s /etc/gcom/getrun_at.gcom | grep 'CME ERROR:')
		if [ -n "$atOut" ]
		then
			logger -t LTEmodem -p 3 PINcode error: ${atOut:11}
			exit 1
		fi
		logger -t LTEmodem -p 6 PINcode verified
		;;
	* )
		logger -t LTEmodem -p 3 SIMcard error: $atOut
		exit 1
		;;
esac

# Flight mode on
logger -t LTEmodem -p 6 Flightmode on
atOut=$(COMMAND="AT+CFUN=0" gcom -d "${DEV}" -s /etc/gcom/run_at.gcom)

# Configure APN
logger -t LTEmodem -p 6 Configure APN
atOut=$(COMMAND="AT+ZGDCONT=1,\"${PDPtype}\",\"${APN}\"" gcom -d "${DEV}" -s /etc/gcom/run_at.gcom)
atOut=$(COMMAND="AT+ZGPCOAUTH=1,\"${username}\",\"${password}\"" gcom -d "${DEV}" -s /etc/gcom/run_at.gcom)

# Flight mode off
logger -t LTEmodem -p 6 Flightmode off
atOut=$(COMMAND="AT+CFUN=1" gcom -d "${DEV}" -s /etc/gcom/run_at.gcom)
sleep 1
atOut=$(COMMAND="AT+creg?" gcom -d "${DEV}" -s /etc/gcom/getrun_at.gcom | grep CREG: | awk -F , '{print $2}' | sed -e 's/[\r\n]//g')
while [ $atOut -eq 0 ] || [ $atOut -eq 2 ]
do
	logger -t LTEmodem -p 6 "$(creg $atOut)"
	sleep 2
	atOut=$(COMMAND="AT+creg?" gcom -d "${DEV}" -s /etc/gcom/getrun_at.gcom | grep CREG: | awk -F , '{print $2}' | sed -e 's/[\r\n]//g')
done
logger -t LTEmodem -p 6 "$(creg $atOut)"
if [ $atOut -eq 3 ] || [ $atOut -eq 4 ]
then
	logger -t LTEmodem -p 3 Check subscription
	exti 1
fi

# Check operator
logger -t LTEmodem -p 6 "$(cops)"

# Connect
atOut=$(COMMAND="AT+ZGACT=1,1" gcom -d "${DEV}" -s /etc/gcom/getrun_at.gcom)


gcom files:

/etc/gcom/getrun_at.gcom

# run AT-command from environment
opengt
 set com 115200n81
 set senddelay 0.02
 waitquiet 1 0.2
 flash 0.1

:start
 send $env("COMMAND")
 send "^m"
 get 1 "" $s
 print $s

:continue
 exit 0


/etc/gcom/run_at.gcom

# run AT-command from environment
opengt
 set com 115200n81
 set senddelay 0.02
 waitquiet 1 0.2
 flash 0.1

:start
# print "sending -> ",$env("COMMAND"),"\n"
 send $env("COMMAND")
 send "^m"

 waitfor 25 "OK","ERR","ERROR","COMMAND NOT SUPPORT"
 if % = 0 goto continue
 if % = 1 goto error
 if % = 2 goto error
 if % = 3 goto notsupported

 print "Timeout running AT-command; ",$env("COMMAND"),"\n"
 exit 1

:error
 print "Error running AT-command: ",$env("COMMAND"),"\n"
 exit 1

:notsupported
 print "AT-command not supported: ",$env("COMMAND"),"\n"
 exit 1

:continue
 print "OK\n"
 exit 0