Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

CAT-M/NB-IoT Cellular connection and GNSS can not work simultaneously (WWAN and GNSS Rx chains in the BG77 module share certain hardware blocks, meaning the module does not support concurrent operation of WWAN and GNSS.). That is why the at+qgpscfg="priority",(0-1) command was introduced. With the help of the command, you can manually change the priority for one or the other.

...

In real-life applications, it is not very convenient to change the priority by hand and this is why, to automate automatically change the processpriority, we advise using scripts (like those mentioned below).

Set GNSS priority on the schedule

The script below should be configured with a scheduler. The scheduler will make sure that the script is initiated each X hours/minutes (whenever you need it).

the methods shown below.

note: Starting with the 7.1rc3 firmware release, it is possible to check when is the last time that the device got NMEA data (GPS data). This information can be used for troubleshooting purposes. You can check this parameter in CLI with the command "system gps monitor once". "data-age" parameter is the one that demonstrates when was the last time that the device received an NMEA message.

Automatic switch to GNSS when no outgoing traffic is detected

Automation can be achieved using ppp profile "on-down"script, "idle-timeout" features and PPP interface "dial on demand" setting.

When implemented, BG77 modem will use cellular data when there is internet traffic present (during this time GNSS coordinates are not received), and will automatically enable GPS reception when there is no internet traffic detected.

Idle-timeout parameter specifies the amount of time after which the link will be terminated if there is no activity present. 

On-down script field allows you to configure a script that will be run every time the PPP interface goes down (including after idle-timeout inactivity). The script will set modem's priority to GNSS reception.

Dial-on-demand will make sure that PPP interface tries to establish the connection only when there is outgoing traffic present (additionally, the modem will automatically set WWAN/cellular connection priority). This will make sure that after idle-timeout occurs, the connection is not automatically reestablished unless outgoing packets are detected.

By combining the three features, you can achieve the scenario, where:

  • If you have outgoing traffic, PPP interface is going to be up (because of the "dial on demand") and the priority will be set to the cellular connection. PPP interface's modem initialization AT command (that is configured under PPP interface's modem-init="AT+QGPSCFG="priority",1" setting) for WWAN priority is sent. During this time, GPS coordinates will not be received.
  • If no traffic is detected after "idle-timeout" inactivity window, the PPP interface will go down and, because of the "dial on demand" setting, it will not establish the connection until outgoing packets are detected. This is where "on-down" script is run that switches WWAN priority to GNSS priority.

In order to implement it, simply add a new PPP profile:

Code Block
languageros
/ppp profile add idle-timeout=30s name=BG77 on-down="/interface ppp-client at-chat [find where modem-init=\"AT+QGPSCFG=\\\"priority\\\",1\"] input=\"AT+QGPSCFG=\\\"priority\\\",0\""

The example above, creates a new profile with the name "BG77", sets idle-timeout to 30 seconds, and enables the on-down script that will send GNSS priority AT command.

After that, make sure to apply this newly created profile onto the PPP interface:

Code Block
languageros
/interface ppp-client set profile=BG77 0

And confirm that it was applied (profile=BG77):

Code Block
languageros
/interface ppp-client print
Flags: X - disabled; R - running 
0 R name="ppp-out1" max-mtu=1500 max-mru=1500 mrru=disabled port=modem data-channel=2 info-channel=2 
apn="internet" pin="" user="" password="" profile=BG77 phone="" dial-command="ATDT" 
modem-init="AT+QGPSCFG="priority",1" null-modem=no dial-on-demand=yes add-default-route=yes 
default-route-distance=1 use-peer-dns=yes keepalive-timeout=30 allow=pap,chap,mschap1,mschap2 

Switch to GNSS using scripts and scheduler

The script below should be configured with a scheduler. The scheduler will make sure that the script is initiated each x hours/minutes (whenever you need it).

:global lat

:global lon

:global spd

:global alt

/interface ppp-client set ppp-out1 disabled=yes
log info ("disabling WWAN to get GPS coordinates")

/interface ppp-client at-chat ppp-out1 input="AT+QGPSCFG=\"priority\",0"
log info ("enabling priority for GPS")

###the time in the delay below is the time that the device will wait for to get the coordinate fix
delay 32000ms
log info ("reading GPS coordinates")
/system gps monitor once do={

:set $lat $("latitude")

:set $lon $("longitude")

:set $spd $("speed")

:set $alt $("altitude")

}

:set $spd [:pick $spd 0 [find $spd " km"]]

:set $alt [:pick $alt 0 [find $alt "m"]]

if ($lat != "none") do={\
log info ("enabling priority back to WWAN")
/interface ppp-client at-chat ppp-out1 input="AT+QGPSCFG=\"priority\",1"
log info ("enabling WWAN")
/interface ppp-client set ppp-out1 disabled=no
delay 1000ms
###if dial on demand is enabled
###/ping 1.1.1.1 count=1

#the delay below waits for 5 seconds for the ppp connection to get established - this time can differ based on the signal strength
delay 5000ms
log info ("posting coordinates via fetch")
/tool fetch http-method=post output=user http-header-field="content-type:application/json" http-data="[\

{\

                \"payload\":{\

                             \"lat\":$lat,\

                              \"lng\":$lon,\

                               \"speed\":$spd,\

                                \"altitude\":$alt\

                                    }\


    }\

]" url="https://change-this-URL-accordingly"}\
else={
log info ("could not read GPS coordinates...enabling back WWAN")

/interface ppp-client at-chat ppp-out1 input="AT+QGPSCFG=\"priority\",1"
/interface ppp-client set ppp-out1 disabled=no
delay 1000ms
###if dial on demand is enabled
###/ping 1.1.1.1 count=1
}

If "dial on demand" is enabled, uncomment (remove "###" for) ping lines "/ping 1.1.1.1 count=1" in the script because without outgoing traffic →  ppp interface will not establish the connection.

What this script is going to do is it going to disable ppp interface, send the GNSS priority command and wait for 32 seconds until the device gets the coordinates (it is the time/period that is suggested for the Quectel modem to get the coordinate fix). You can alter this time based on your preference and signal strength. Each individual case might be unique. After a 32-second delay, if the coordinates were successfully received (if latitude does not equal "none" but equals any other value), the script will send a WWAN priority command, enable back the ppp interface, and use "/tool fetch" to post the coordinates to the configured HTTP server. If the coordinates were not received after a 32-second delay (if latitude is going to be "none"), the script is going to send WWAN priority command and enable back the ppp interface without posting any results.

Do not forget to alter the "/tool fetch" part of the script accordingly to your HTTP server configuration/requirement.

You can also use MQTT instead of HTTP post. In order to do that, change the "/tool fetch" part of the configuration from:

/tool fetch http-method=post output=user http-header-field="content-type:application/json" http-data="[\

{\

                \"payload\":{\

                             \"lat\":$lat,\

                              \"lng\":$lon,\

                               \"speed\":$spd,\

                                \"altitude\":$alt\

                                    }\


    }\

]" url="https://change-this-URL-accordingly"}\

To MQTT:

/iot mqtt publish broker="AWS" topic="my/test/topic" message="

:global lat

:global lon

:global spd

:global alt

/interface ppp-client set ppp-out1 disabled=yes
log info ("disabling WWAN to get GPS coordinates")

/interface ppp-client at-chat ppp-out1 input="AT+QGPSCFG=\"priority\",0"
log info ("enabling priority for GPS")
delay 10000ms
log info ("reading GPS coordinates")
/system gps monitor once do={

:set $lat $("latitude")

:set $lon $("longitude")

:set $spd $("speed")

:set $alt $("altitude")

}

:set $spd [:pick $spd 0 [find $spd " km"]]

:set $alt [:pick $alt 0 [find $alt "m"]]

if ($lat != "none") do={\
log info ("enabling priority back to WWAN")
/interface ppp-client at-chat ppp-out1 input="AT+QGPSCFG=\"priority\",1"
log info ("enabling WWAN")
/interface ppp-client set ppp-out1 disabled=no
delay 1000ms
###if dial on demand is enabled
###/ping 1.1.1.1 count=1
delay 5000ms
log info ("posting coordinates via fetch")
/tool fetch http-method=post output=user http-header-field="content-type:application/json" http-data="[\

{\

                \"payload\":{\                             \"lat\":$lat,\

                                  \"lng\":$lon,\

                                   \"speed\":$spd,\

                                    \"altitude\":$alt \
                                    }\  
    }\

]" url="https://change-this-URL-accordingly"}\
else={
log info ("could not read GPS coordinates...enabling back WWAN")
/interface ppp-client set ppp-out1 disabled=no
delay 1000ms
####if dial on demand is enabled
####/ping 1.1.1.1 count=1
}

...

"}\

Alter the broker, topic, and message as you see fit. You can find more information on how to configure MQTT following the link.

For example, if the MQTT server/broker is AWS, the posted result would look like this:

Image Added

Switch to GNSS when no outgoing traffic is detected using scripts and scheduler

The 1st script is used to check whether there is any traffic and to switch the priority back and forth based on that.

The 2nd script can be used to enable WWAN priority and to publish the GPS coordinates to the server of your choice. You can use any supported protocol, like HTTPS post (fetch) or MQTT to post the coordinates.

1st script

This script below will automatically create a scheduler:

...

Once all 3 conditions are met and the scheduler is ready, reboot the device for the script to take action.

2nd script

The second script is used to collect GPS coordinates and send them further to the server.

...

The script is going to "read" GPS coordinates, and if latitude could be "read" successfully (if latitude does not equal "none" but equals any other value), ping "1.1.1.1" once (to generate outgoing traffic), wait for 3 seconds for the ppp connection to get established and initiate "/tool fetch" (HTTP post). Otherwise, if latitude could not be determined (when the script was initiated), nothing will happen (you will see a log message that the device could not read GPS coordinates).

You can change the "delay" line in the script to the actual time that it takes your device to successfully establish a ppp (CAT-M/NB-IoT) connection with the ISP.

You can set up a scheduler to run the script whenever you like.

...