* STA interfaces operating in an "always off" mode, to make sure that the AP is always accessible
* easy setup within normal OpenWrt/LEDE environment
* fast uplink connections
-* "active mode" support, where travelmate will be restarted every n seconds (default 60) and checks the existing uplink connection regardless of ifdown event trigger
+* manual / automatic mode support, the latter one checks the existing uplink connection regardless of ifdown event trigger every n seconds
* support of devices with multiple radios
-* procd init system support
-* procd based hotplug support, the travelmate start will be triggered by interface triggers
+* procd init and hotplug support
+* runtime information accessible via ubus service call
* status & debug logging to syslog
## Prerequisites
* the application is located in LuCI under 'Services' menu
* _Thanks to Hannu Nyman for this great LuCI frontend!_
-## Chaos Calmer installation notes
-* 'travelmate' and 'luci-app-travelmate' are _not_ available as ipk packages in the Chaos Calmer download repository
-* download the packages from a development snapshot directory (see download links above)
-* manually transfer the packages to your routers temp directory (with tools like _sshfs_ or _winscp_)
-* install the packages as described above
-
## Travelmate config options
* travelmate config options:
* trm\_enabled => main switch to enable/disable the travelmate service (default: '0', disabled)
* trm\_debug => enable/disable debug logging (default: '0', disabled)
- * trm\_active => keep travelmate in an active state (default: '0', disabled)
- * trm\_maxwait => how long (in seconds) should travelmate wait for wlan interface reload action (default: '20')
+ * trm\_automatic => keep travelmate in an active state (default: '1', enabled)
+ * trm\_maxwait => how long (in seconds) should travelmate wait for a successful wlan interface reload action (default: '30')
* trm\_maxretry => how many times should travelmate try to find an uplink after a trigger event (default: '3')
- * trm\_timeout => timeout in seconds for "active mode" (default: '60')
+ * trm\_timeout => timeout in seconds for "automatic mode" (default: '60')
* trm\_iw => set this option to '0' to use iwinfo for wlan scanning (default: '1', use iw)
* trm\_radio => limit travelmate to a dedicated radio, e.g. 'radio0' (default: not set, use all radios)
- * trm\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: not set, disabled)
+ * trm\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: wan wwan)
+
+
+## Runtime information
+
+**receive travelmate information via ubus:**
+<pre><code>
+ubus call service get_data '{"name":"travelmate"}'
+This will output the current connection status, e.g.:
+{
+ "travelmate": {
+ "travelmate": {
+ "last_rundate": "02.04.2017 07:22:03",
+ "online_status": "true",
+ "station_interface": "wwan",
+ "station_radio": "radio1",
+ "station_ssid": "blackhole",
+ "system": "LEDE Reboot SNAPSHOT r3888-8fb39f1682",
+ "travelmate_version": "0.6.0"
+ }
+ }
+}
+</code></pre>
## Setup
**1. configure a wwan interface in /etc/config/network:**
#
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-trm_ver="0.5.0"
+trm_ver="0.6.0"
trm_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
-trm_enabled=1
+trm_enabled=0
trm_debug=0
-trm_active=0
+trm_automatic=0
trm_maxwait=30
trm_maxretry=3
trm_timeout=60
trm_iw=1
+# source required system library
+#
+if [ -r "/lib/functions.sh" ]
+then
+ . "/lib/functions.sh"
+else
+ f_log "error" "required system library not found"
+fi
+
# f_envload: load travelmate environment
#
f_envload()
{
- # source required system libraries
+ # initialize lists
#
- if [ -r "/lib/functions.sh" ]
- then
- . "/lib/functions.sh"
- else
- f_log "error" "required system library not found"
- fi
+ trm_aplist=""
+ trm_stalist=""
+ trm_radiolist=""
# load uci config and check 'enabled' option
#
cnt=$((cnt+1))
sleep 1
done
- f_log "debug" "mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}"
+ f_log "debug" "mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}, automatic: ${trm_automatic}"
}
-# f_active: keep travelmate in an active state
+# f_ubus: update ubus service
#
-f_active()
+f_ubus()
{
- if [ ${trm_active} -eq 1 ]
- then
- (sleep ${trm_timeout}; /etc/init.d/travelmate start >/dev/null 2>&1) &
- fi
+ local active_triggers iface="${1}" radio="${2}" ssid="${3}"
+
+ for name in ${trm_iface}
+ do
+ active_triggers="${active_triggers}[\"interface.*.down\",[\"if\",[\"eq\",\"interface\",\"${name}\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]],"
+ done
+ active_triggers="${active_triggers}[\"config.change\",[\"if\",[\"eq\",\"package\",\"travelmate\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]]"
+
+ ubus call service add "{\"name\":\"travelmate\",
+ \"instances\":{\"travelmate\":{\"command\":[\"/usr/bin/travelmate.sh\"],
+ \"data\":{\"travelmate_version\":\"${trm_ver}\",
+ \"station_interface\":\"${iface}\",
+ \"station_radio\":\"${radio}\",
+ \"station_ssid\":\"${ssid}\",
+ \"last_rundate\":\"$(/bin/date "+%d.%m.%Y %H:%M:%S")\",
+ \"online_status\":\"${trm_ifstatus}\",
+ \"system\":\"${trm_sysver}\"}}},
+ \"triggers\":[${active_triggers}]}"
}
-# f_log: function to write to syslog
+# f_log: write to syslog, exit on error
#
f_log()
{
if [ "${class}" = "error" ]
then
logger -t "travelmate-[${trm_ver}] ${class}" "Please check 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md' (${trm_sysver})"
- f_active
exit 255
fi
fi
#
f_main()
{
- local ssid_list config ap_radio sta_radio ssid cnt=1
+ local config ssid_list ap ap_radio sta_ssid sta_radio sta_iface cnt=1
f_check "initial"
if [ "${trm_ifstatus}" != "true" ]
then
uci -q commit wireless
ubus call network reload
+ sleep 5
fi
f_check "ap"
f_log "debug" "ap-list: ${trm_aplist}, sta-list: ${trm_stalist}"
do
config="${sta%%_*}"
sta_radio="${sta##*_}"
- ssid="\"$(uci -q get wireless."${config}".ssid)\""
- if [ -n "$(printf "${ssid_list}" | grep -Fo "${ssid}")" ] && [ "${ap_radio}" = "${sta_radio}" ]
+ sta_ssid="$(uci -q get wireless."${config}".ssid)"
+ sta_iface="$(uci -q get wireless."${config}".network)"
+ if [ -n "$(printf "${ssid_list}" | grep -Fo "\"${sta_ssid}\"")" ] && [ "${ap_radio}" = "${sta_radio}" ]
then
uci -q set wireless."${config}".disabled=0
ubus call network reload
if [ "${trm_ifstatus}" = "true" ]
then
uci -q commit wireless
- f_log "info " "wwan interface connected to uplink ${ssid} (${trm_sysver})"
+ f_log "info " "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_ssid}' (${trm_sysver})"
sleep 5
+ f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}"
return 0
else
uci -q revert wireless
ubus call network reload
- f_log "info " "wwan interface can't connect to uplink ${ssid} (${trm_sysver})"
+ f_log "info " "interface '${sta_iface}' on '${sta_radio}' can't connect to uplink '${sta_ssid}' (${trm_sysver})"
+ f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}"
fi
fi
done
}
f_envload
-if [ ${trm_active} -eq 0 ] || ([ ${trm_active} -eq 1 ] && [ $(pgrep -f "/usr/bin/travelmate.sh" | wc -l) -eq 3 ])
-then
+f_main
+while [ ${trm_automatic} -eq 1 ]
+do
+ sleep ${trm_timeout}
+ f_envload
f_main
- f_active
-fi
+done
exit 0