OpenWrt X86_64 + Mikrotik R11e-LTE6

logread:

The correction works. Now we got the PID value.

Wed Mar  8 10:15:25 2023 user.info LTEmodem: Waiting for ethernet adapter name
Wed Mar  8 10:15:26 2023 user.info LTEmodem: Waiting for ethernet adapter name
Wed Mar  8 10:15:27 2023 user.info LTEmodem: Waiting for ethernet adapter name
Wed Mar  8 10:15:28 2023 user.info LTEmodem: Waiting for ethernet adapter name
Wed Mar  8 10:15:29 2023 user.info LTEmodem: Waiting for ethernet adapter name
Wed Mar  8 10:15:30 2023 user.info LTEmodem: Release DHCP lease, PID: 4161

Maybe there is a better way to find out the process id, but I don´t know right now.
Of course , you can specify the ethAdapter manually, but I tried to make the script more generic.

Okay. I'll test the final config, and reply.

I think, we can mark this project succeded. There was more sucesessfully reconnect, reboot and all of these without fail. Thank you very much!

Wed Mar  8 09:36:22 2023 daemon.notice netifd: Interface 'WANN' is now up
Wed Mar  8 10:15:29 2023 daemon.notice netifd: Interface 'WANN' is now up
Thu Mar  9 10:16:07 2023 daemon.notice netifd: Interface 'WANN' is now up
Fri Mar 10 10:16:18 2023 daemon.notice netifd: Interface 'WANN' is now up
Fri Mar 10 19:08:59 2023 daemon.notice netifd: Interface 'WANN' is now up
Sat Mar 11 05:32:09 2023 daemon.notice netifd: Interface 'WANN' is now up

other thing: on these config, can You help me with GPIO?

Document the changes required?

Might want to create a new thread about the gpio.

1 Like

Later I will attach all of the files and changes what is needed for working configuration.

1 Like

Nice to hear!

I agree with @frollic, create a new thread.

Okay! Here are my working config. The packages, that I installed is this:

attr avahi-dbus-daemon bnx2-firmware chat collectd collectd-mod-cpu collectd-mod-cpufreq collectd-mod-interface collectd-mod-iwinfo collectd-mod-load collectd-mod-memory collectd-mod-network collectd-mod-rrdtool collectd-mod-sensors collectd-mod-thermal comgt comgt-directip comgt-ncm coreutils coreutils-timeout dbus ddns-scripts ddns-scripts-services fdisk glib2 hostapd-utils htop kmod-amazon-ena kmod-amd-xgbe kmod-asn1-decoder kmod-bnx2 kmod-crypto-aead kmod-crypto-arc4 kmod-crypto-ecb kmod-crypto-kpp kmod-crypto-lib-chacha20 kmod-crypto-lib-chacha20poly1305 kmod-crypto-lib-curve25519 kmod-crypto-lib-poly1305 kmod-crypto-manager kmod-crypto-null kmod-crypto-sha1 kmod-e1000 kmod-e1000e kmod-forcedeth kmod-gre kmod-hwmon-core kmod-hwmon-vid kmod-hwmon-w83627ehf kmod-i2c-algo-bit kmod-i2c-core kmod-igb kmod-igc kmod-iptunnel kmod-ixgbe kmod-lib-textsearch kmod-libphy kmod-mdio kmod-mdio-devres kmod-mii kmod-mppe kmod-nf-nathelper-extra kmod-phy-realtek kmod-pps kmod-pptp kmod-ptp kmod-r8169 kmod-scsi-core kmod-tg3 kmod-udptunnel4 kmod-udptunnel6 kmod-usb-acm kmod-usb-core kmod-usb-ehci kmod-usb-net kmod-usb-net-cdc-ether kmod-usb-net-cdc-ncm kmod-usb-net-huawei-cdc-ncm kmod-usb-net-qmi-wwan kmod-usb-net-rndis kmod-usb-net-sierrawireless kmod-usb-ohci kmod-usb-ohci-pci kmod-usb-serial kmod-usb-serial-option kmod-usb-serial-sierrawireless kmod-usb-serial-wwan kmod-usb-storage kmod-usb-wdm kmod-usb-xhci-hcd kmod-usb2 kmod-usb2-pci kmod-usb3 kmod-wireguard lcd4linux-custom libatomic1 libattr libavahi-client libavahi-dbus-support libcap libdaemon libdbus libevdev libexpat libfdisk1 libffi libgmp10 libgnutls libltdl7 libmount1 libncurses6 libnettle8 libopenssl1.1 libpam libparted libpcre libpopt0 libreadline8 librrd1 libsensors5 libsqlite3-0 libssh2-1 libsysfs2 libtasn1 libtirpc libuci-lua libudev-zero liburing libusb-1.0-0 libuv1 libwebsockets-full lm-sensors lm-sensors-detect losetup luci-app-ddns luci-app-samba4 luci-app-statistics luci-app-ttyd luci-app-wireguard luci-proto-ncm luci-proto-qmi luci-proto-wireguard luci-theme-material mc parted perl perlbase-base perlbase-bytes perlbase-class perlbase-config perlbase-cwd perlbase-errno perlbase-essential perlbase-fcntl perlbase-file perlbase-filehandle perlbase-i18n perlbase-integer perlbase-io perlbase-list perlbase-locale perlbase-params perlbase-posix perlbase-re perlbase-scalar perlbase-selectsaver perlbase-socket perlbase-symbol perlbase-tie perlbase-unicore perlbase-utf8 perlbase-xsloader picocom ppp-mod-pptp r8169-firmware resize2fs resolveip rrdtool1 samba4-libs samba4-server screen sysfsutils terminfo tio ttyd uqmi usb-modeswitch usbutils wireguard-tools wwan zlib

In this, there are some important for me. I don't know exactly what packages are needed for the Mikrotik R11e LTE6 modem, but with this package list it is working. Beside that I use wireguard, DynDNS and many more extra. The interface called 'WANN' is a DHCP client and the config files are this:

/etc/gcom/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"
 exit 0

/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

/etc/init.d/mikrotikR11

#!/bin/sh /etc/rc.common
#

START=99
STOP=01

USE_PROCD=1

start_service() {
    procd_open_instance
    procd_set_param command sh "/root/test2.sh"
    procd_close_instance
}

And the script, for service:

#!/bin/sh
#
# By mrhaav 2023-03-03
# IPv4 only
#

# Modem settings
modemDEV='/dev/ttyACM0'
interface='WANN'

#PINcode, if in use
PINcode=''

# APN settings
APN='vitamax.snet.vodafone.net'
PDPtype='IP'
username=''
password=''

# Debug mode
# If you run this as a service set to false
# If you run the script in a terminal and would like to see all messages, set to true
debug=false

[ $debug = true ] && echo Modem initialization || logger -t LTEmodem -p 6 Modem initialization

# Set error codes to verbose
atOut=$(COMMAND='AT+CMEE=2' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
while [ $atOut != 'OK' ]
do
    [ $debug = true ] && echo 'Modem not ready yet: '$atOut || logger -t LTEmodem -p 6 'Modem not ready yet'
    atOut=$(COMMAND='AT+CMEE=2' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
done

# Check SIMcard and PIN status
atOut=$(COMMAND="AT+CPIN?" gcom -d "$modemDEV" -s /etc/gcom/getrun_at.gcom | grep CPIN: | awk -F ' ' '{print $2 $3}' | sed -e 's/[\r\n]//g')
case $atOut in
    READY )
	[ $debug = true ] && echo SIMcard ready || logger -t LTEmodem -p 6 SIMcard ready
	;;
    SIMPIN )
	if [ -z $PINcode ]
	then
	    [ $debug = true ] && echo PINcode required but missing || logger -t LTEmodem -p 3 PINcode required but missing
	    exit 1
	fi
	atOut=$(COMMAND="AT+CPIN=${PINcode}" gcom -d "$modemDEV" -s /etc/gcom/getrun_at.gcom | grep 'CME ERROR:')
	if [ -n "$atOut" ]
	then
	    [ $debug = true ] && echo PINcode error: ${atOut:11} || logger -t LTEmodem -p 3 PINcode error: ${atOut:11}
	    exit 1
	fi
	[ $debug = true ] && echo PINcode verified || logger -t LTEmodem -p 6 PINcode verified
	;;
    * )
	[ $debug = true ] && echo SIMcard error: $atOut || logger -t LTEmodem -p 3 SIMcard error: $atOut
	exit 1
	;;
esac

# Enable flightmode
atOut=$(COMMAND='AT+CFUN=0' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut

# Set operator name in long format
atOut=$(COMMAND='AT+COPS=3,0' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut


# URC
# CREG, CGREG, CEREG. Set to 2 when debug=true
# 0 Disable network registration unsolicited result code
# 1 Enable network registration unsolicited result code
# 2 Enable network registration and location information unsolicited result code <stat>[,<lac>,<ci>[,<AcT>]]
atOut=$(COMMAND='AT+CREG=0' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut
atOut=$(COMMAND='AT$CREG=0' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut
atOut=$(COMMAND='AT+CGREG=0' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut
atOut=$(COMMAND='AT+CEREG=0' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut

# CGEREG, for URCcode +CGEV
atOut=$(COMMAND='AT+CGEREP=2,1' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut

# Release DHCP lease
ethAdapter=$(ubus call network.interface.${interface} status | jsonfilter -e '@["l3_device"]')
while [ -z $ethAdapter ]
do
    [ $debug = false ] && logger -t LTEmodem -p 6 'Waiting for ethernet adapter name'
    sleep 1
    ethAdapter=$(ubus call network.interface.${interface} status | jsonfilter -e '@["l3_device"]')
done
PIDudhcpc=$(cat /var/run/udhcpc-${ethAdapter}.pid)
while [ -z $PIDudhcpc ]
do
    [ $debug = false ] && logger -t LTEmodem -p 6 'Waiting for udhcpc PID value'
    sleep 1
    PIDudhcpc=$(cat /var/run/udhcpc-${ethAdapter}.pid)
done
[ $debug = false ] && logger -t LTEmodem -p 6 'Release DHCP lease, PID: '$PIDudhcpc
kill -SIGUSR2 $PIDudhcpc

# Set DHCP lease time, 216000s = 2.5days
atOut=$(COMMAND='AT+ZDHCPLEASE=216000' gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut

# Configure PDPcontext, profile 1
atOut=$(COMMAND="AT+ZGDCONT=1,\"${PDPtype}\",\"${APN}\"" gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut
atOut=$(COMMAND="AT+ZGPCOAUTH=1,\"${username}\",\"${password}\",0" gcom -d "$modemDEV" -s /etc/gcom/run_at.gcom)
[ $debug = true ] && echo $atOut


# Disable flightmode
[ $debug = true ] || logger -t LTEmodem -p 6 Activate modem
atOut=$(COMMAND='AT+CFUN=1' gcom -d "$modemDEV" -s /etc/gcom/at.gcom)


while read URCline
do
    firstASCII=$(printf "%d" \'${URCline::1})
    if [ ${firstASCII} != 13 ] && [ ${firstASCII} != 32 ]
    then
	URCcommand=$(echo $URCline | awk -F ':' '{print $1}')
	x=${#URCcommand}
	x=$(($x+2))
	URCvalue=${URCline:x}
	URCvalue=$(echo $URCvalue | sed -e 's/[\r\n]//g')
	dateTime=$(date '+%Y-%m-%d %H:%M:%S')
	case $URCcommand in

	    +CGEV )
		[ $debug = true ] && echo $dateTime $URCline
		if [ "$URCvalue" = 'NW PDN DEACT 1' ]
		then
		    [ $debug = true ] || logger -t LTEmodem -p 6 Session disconnected, release DHCP lease
		    kill -SIGUSR2 $PIDudhcpc
		elif [ "$URCvalue" = 'EPS PDN ACT 5' ] || [ "$URCvalue" = 'NW PDN ACT 5' ]
		then
		    [ $debug = true ] || logger -t LTEmodem -p 6 Activate session
		    atOut=$(COMMAND="AT+ZGACT=1,1" gcom -d "$modemDEV" -s /etc/gcom/at.gcom)
		fi
		;;

	    +ZGIPDNS )
		[ $debug = true ] && echo $dateTime $URCline || logger -t LTEmodem -p 6 Renew DHCP lease
		kill -SIGUSR1 $PIDudhcpc
		;;

	    * )
		[ $debug = true ] && echo $dateTime $URCline
		;;
	esac
    fi
done < ${modemDEV}
1 Like

Can I get signal strenght and other infos from the modem like this?

https://forum.openwrt.org/t/luci-app-luci-app-3ginfo-3ginfo-gui-info-about-3g-lte-connection/67893

1 Like

I've tested it with fresh build with firmware selector. Everything is works, no problem. I think we can close the thread.

Just one thing! After fresh install, i restored the settings, and the mikrotikR11 service is disabled default. How can I set it enabled by default?

But, isn´t that a one time thing to fix, or did I miss understood you?

I think, i found something . If i backup the /etc/rc.d/, then i can restore the service.

Edit:

I tested it and works! I need to backup /etc/rc.d/ :slight_smile:

For the record: I was able to use this modem with such a simple config.
Here is the proof:

Thu Mar 23 21:40:10 2023 daemon.notice netifd: Interface 'mikrotik' is setting up now
Thu Mar 23 21:40:11 2023 daemon.notice pppd[7831]: pppd 2.4.9 started by root, uid 0
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: abort on (BUSY)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: abort on (NO CARRIER)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: abort on (ERROR)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: report (CONNECT)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: timeout set to 10 seconds
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: send (AT&F^M)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: expect (OK)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: ^M
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: OK
Thu Mar 23 21:40:12 2023 local2.info chat[7834]:  -- got it
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: send (ATE1^M)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: expect (OK)
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: ^M
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: ^M
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: OK
Thu Mar 23 21:40:12 2023 local2.info chat[7834]:  -- got it
Thu Mar 23 21:40:12 2023 local2.info chat[7834]: send (AT+CGDCONT=1,"IP","internet"^M)
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: timeout set to 30 seconds
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: expect (OK)
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: ^M
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: AT+CGDCONT=1,"IP","internet"^MAT+CGDCONT=1,"IP","internet"^M^M
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: OK
Thu Mar 23 21:40:13 2023 local2.info chat[7834]:  -- got it
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: send (ATD*99***1#^M)
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: expect (CONNECT)
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: ^M
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: ATD*99***1#^M^M
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: CONNECT
Thu Mar 23 21:40:13 2023 local2.info chat[7834]:  -- got it
Thu Mar 23 21:40:13 2023 local2.info chat[7834]: send ( ^M)
Thu Mar 23 21:40:13 2023 daemon.info pppd[7831]: Serial connection established.
Thu Mar 23 21:40:13 2023 kern.info kernel: [  513.479138] 3g-mikrotik: renamed from ppp0
Thu Mar 23 21:40:13 2023 daemon.info pppd[7831]: Renamed interface ppp0 to 3g-mikrotik
Thu Mar 23 21:40:13 2023 daemon.info pppd[7831]: Using interface 3g-mikrotik
Thu Mar 23 21:40:13 2023 daemon.notice pppd[7831]: Connect: 3g-mikrotik <--> /dev/ttyACM0
Thu Mar 23 21:40:14 2023 daemon.warn pppd[7831]: Could not determine remote IP address: defaulting to 10.64.64.64
Thu Mar 23 21:40:14 2023 daemon.notice pppd[7831]: local  IP address 100.112.169.135
Thu Mar 23 21:40:14 2023 daemon.notice pppd[7831]: remote IP address 10.64.64.64
Thu Mar 23 21:40:14 2023 daemon.notice pppd[7831]: primary   DNS address 185.29.83.64
Thu Mar 23 21:40:14 2023 daemon.notice pppd[7831]: secondary DNS address 185.62.131.64
Thu Mar 23 21:40:14 2023 daemon.notice netifd: Network device '3g-mikrotik' link is up
Thu Mar 23 21:40:14 2023 daemon.notice netifd: Interface 'mikrotik' is now up

Sadly I have to find out the exact solution: too much irrelevant package was installed and the /etc/gcom/ncm.json file was also modified. :see_no_evil:

then post your installed packages, and the diff for ncm.json
something is still better than nothing.

I hope I could do it in the weekend! :ok_hand:

Interestingly the proto '3g' mode is far more stable than the proto 'ncm': the ncm proto needs lot of love.

I opened a pull request to use such a simple configuration.
Thanks @mrhaav for sharing your work!
Thanks @yodee13 for lending your device!

:pray:

PR landed with commit 91eca7b04ff1 and dbd6ebd6d84b! :tada:
The backport PR #12275 landed too! It will be included first in OpenWrt 22.03.4!

Using on SNAPSHOT builds and on OpenWrt 22.03.4+ releases

For option proto '3g'

# after opkg update
opkg install comgt kmod-usb-acm

Example configuration:

config interface 'mikrotik'
	option proto '3g'
	option apn 'internet'
	option device '/dev/ttyACM0'

For option proto 'ncm'

# after opkg update
opkg install comgt-ncm kmod-usb-acm kmod-usb-net-rndis

Example configuration:

config interface 'mikrotik'
	option proto 'ncm'
	option apn 'internet'
	option device '/dev/ttyACM0'
	option delay '20'

To ensure internet connecivity, ncm users may have exercise pingcheck's offline script.

Using on OpenWrt 22.03.3 and earlier 22.03.x releases

After installing the required packages one should grab the files from the PR:

For option proto '3g' one should grab the runcommand.gcom file too (and put to /etc/gcom directory).

3 Likes

Looks good to me.

FYI, I tried to force the modem the QMI mode but that is not supported on this MikroTik modified Marvell crap, so PPP or MBIM (NCM) are the two options. For speed you definitely need the MBIM interface.

1 Like

It looks fine. But the interface lease time is only 7200 s. How should we extend it?

root@OpenWRT_x86-64:~# logread | grep WANN_4 | grep now
Thu Mar 30 20:58:35 2023 daemon.notice netifd: Interface 'WANN_4' is setting up   now
Thu Mar 30 20:59:09 2023 daemon.notice netifd: Interface 'WANN_4' is now up
Thu Mar 30 22:58:56 2023 daemon.notice netifd: Interface 'WANN_4' is now up
Fri Mar 31 00:58:42 2023 daemon.notice netifd: Interface 'WANN_4' is now up
Fri Mar 31 02:58:29 2023 daemon.notice netifd: Interface 'WANN_4' is now up
Fri Mar 31 04:58:16 2023 daemon.notice netifd: Interface 'WANN_4' is now up
Fri Mar 31 06:58:02 2023 daemon.notice netifd: Interface 'WANN_4' is now up
root@OpenWRT_x86-64:~#

Set the 0 (default) value to your favourite number in the finalize block!

"finalize": "AT+ZDHCPLEASE=0",
1 Like