LightBlog

lundi 16 janvier 2017

Use Tasker to Notify when your Tethered Devices lose Internet Access

From the last article, you know that I spend quite a bit of my time on a train. It's an excellent time to write an article or two, provided I have access to the Internet to look up facts and ideas. Tethering can be tricky on the train, as reception-less areas are scattered across my route. I find it quite easy to tell that I'm about to go offline when I'm in a tunnel, but the situation is less apparent when the train cruises through the open meadows of North Yorkshire. Android's built-in tethering solution doesn't have any way to let you know that you are not going to be able to load that website for the next 5 minutes.

That's why, as a Tasker aficionado, I thought about how to solve my problem using the popular Android automation app. I've solved my problem by building a tethering 'no network' warning using Tasker. The aim of the project is to let you know when your phone no longer is in cellular network range. This will be done in 3 ways:

  • Using notification LED (best for when you tether for friends)
  • Using a smartphone icon (needs a smartwatch)
  • Using a Join push (best for personal devices -can be replaced with AutoRemote)

You can get more creative with notifications, however, I will use only discrete options as tethering is most likely to be used in public places. No one likes obnoxious notifications, right? Please bear in mind that the notifications will use an internet connection to show up on the connected device. You could use AutoRemote (via Bluetooth) to send out warnings when the network is not present. This will require the device in question to be paired via Bluetooth.

You will need:
Android version: 4.0+, Android 7.0 needed for the notification tile
Apps: Join
Plugins:  AutoWear (optional), AutoRemote (can replace Join), AutoNotification (optional)


Enable a tethering 'no network' warning with Tasker

Instead of checking if tethering is enabled, it's easier to replace a tile in the status bar with AutoNotification and set up a toggle behavior. If you are not on Android 7.0 you can use a shortcut or a widget instead.

If you have never enabled a tile with AutoNotification – you will see that this is a bit awkward. You will need to create a setup task which will convert a template tile into a tile of our choice. Place an empty tile, i.e. AutoNotification 02 onto the tiles area (click edit to edit the visible tiles).

Create a Tethering tile

Tethering tile

  Tile Setup          A1: AutoNotification Tiles [ Configuration:Tile: 2  Command: hotspottoggle  Label: Hotspot  Icon: android.resource://net.dinglisch.android.taskerm/hd_aaa_ext_signal  State: 1  Require Unlock: false  Hide Notifications: true Timeout (Seconds):60 ]           A2: Variable Set [ Name:%HotspotVariable To:0 Recurse Variables:Off Do Maths:Off Append:Off ]           A3: Variable Set [ Name:%HotspotDialog To:0 Recurse Variables:Off Do Maths:Off Append:Off ]  

You will only need to run this once to set up the tiles and variables. The tile will use a command hotspottoggle to change the state of tethering and will set it as inactive. It will also collapse the status bar once pressed. You can dress up the tile with a label of your choice and the icon.

Two more variables will be created and set to 0. %HotspotVariable will display the status of the tether (0 = no, 1 = yes) and %HotspotDialog will display a dialog asking us what device we want to notify (0 = do not show, 1 = show dialog).

Tethering toggle

Tethering toggle

  Hotspot Toggle           A1: Variable Add [ Name:%HotspotDialog Value:1 Wrap Around:2 ]           A2: AutoNotification Tiles [ Configuration:Tile: 2  Command: hotspottoggle  Label: Hotspot  Icon: android.resource://net.dinglisch.android.taskerm/hd_aaa_ext_signal  State: 999  Require Unlock: false  Hide Notifications: true Timeout (Seconds):60 ]           A3: WiFi Tether [ Set:Toggle ]           A4: Perform Task [ Name:Hotspot Dialog Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ] If [ %HotspotDialog ~ 1 ]          A5: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]           A6: Variable Add [ Name:%HotspotVariable Value:1 Wrap Around:2 ]           A7: Variable Clear [ Name:%HotspotDevice Pattern Matching:Off ] If [ %HotspotVariable ~ 0 ]  

I want to display a dialog only when tethering is enabled. The dialog will show some devices I own and will allow me to set the target for the notifications. In each case, I will set my tethering phone to blink the notification LED rapidly each time the reception is poor.

When the tile is pressed, it changes the status to active. %HotspotDialog changes to 1 and it triggers the HotspotDialog task. While we select our device, the Hotspot profiles are armed by setting the variable %HotspotVariable to 1. When I press on a tile again to end tethering, the HotspotDialog returns to 0 and no longer prompts the dialog to be displayed, and the %HotspotVariable is set to the neutral value 0.

A1,A6

The action Variable Add +1 will change the value of our starting variables from 0 to 1 and will wrap it around 2. This means these variables will always take values of 1 or 0. The action placement is relevant as well, as the %HotspotDialog will control when the dialog is displayed. We are running the same task to disable and enable the tethering, but we don't want the dialog to appear each time we toggle it.

A7

While we are at it, if the task is performed to disable the tether (%HotspotVariable = 0), we want to clear the variable that stores the name of the device which gets notified by the Hotspot Dialog task.

A5

The Wait action is added to prevent the information about poor range from being displayed straight away which may happen when the hotspot setting is toggled.

A3

Simply toggle the WiFi tether action. Nothing complicated about this step.

A4

A separate task is displayed to show the AutoTools Dialog and action for the choice I've made. This will run when our dialog controlling variable %HotspotDialog = 1.

A2

When the toggle is pressed, we want to make sure that the tile toggles the state active/inactive and retains the same command: hotspottoggle. Lastly, make sure it will collapse the status bar.

Hotspot Dialog

Hotspot dialog

  Hotspot Dialog           A1: AutoTools Dialog [ Configuration:Dialog Type: List  Title: Enable poor network notification?  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png  List Type: 1  Texts: Tablet,Mobile,Computer,Watch,Laptop  Text Size: 20  Images: /storage/emulated/0/Tasker/Material Icons/ic_tablet-1.png,/storage/emulated/0/Tasker/Material Icons/ic_cellphone_android-1.png,/storage/emulated/0/Tasker/Material Icons/ic_desktop_mac-1.png,/storage/emulated/0/Tasker/Material Icons/ic_watch-1.png,/storage/emulated/0/Tasker/Material Icons/ic_laptop-1.png  Image Width: 50  Dim Background: true  Number Of Columns: 3  Top Margin: 16  Bottom Margin: 16  Bottom Buttons Top Margin: 16  Bottom Buttons Bottom Margin: 16  Close On Select: true  Separator: ,  Command Variable: atcommand  Cancelable: true  Turn Screen On: true Timeout (Seconds):60 ]           A2: Variable Set [ Name:%HotspotDevice To:%attext Recurse Variables:Off Do Maths:Off Append:Off ]   

The AutoTools dialog is used to display available devices. When the device is selected, dialog will close and set the value of the %HotspotDevice to the name of that device. This variable gets cleared each time the tethering is stopped.

Poor reception/No data

Poor reception/No data profiles

I have created 2 profiles which will check the signal strength and the Internet connection. Each one is controlled by the variable %HotspotVariable and is only active when tethering is enabled. Both profiles will trigger the same task when activated and deactivated. One contains the state context – signal strength –  and the other the mobile network. Ideally, the connection will be still present when the notification is issued. This is why I'm including the signal strength set to 1 in the profile condition.

Poor Signal

Poor signal

  Profile: Poor Reception (91)          State: Variable Value [ %HotspotVariable ~ 1 ]          State: Signal Strength [ From:0 To:1 ]  Enter: PoorSignal (89)                    A1: AutoNotification [ Configuration:Use HTML: false  Title: Poor reception  Icon: android.resource://net.dinglisch.android.taskerm/hl_device_access_network_cell  Status Bar Icon: device_access_network_cell  Status Bar Text Size: 16  Id: 55  Priority: -1  Persistent: true  Is Group Summary: false  LED Color: red  LED On: 300  LED Off: 30p  Skip Picture Cache: false  Update Notification: false  Only on Phone: true Timeout (Seconds):20 ]                     A2: Join Send Push [ Configuration:Device: Chrome@Laptop  Text: Poor range  Title: Poor reception  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png Timeout (Seconds):60 ] If [ %HotspotDevice ~ Laptop ]                    A3: Join Send Push [ Configuration:Device: Chrome@Home  Text: Poor range  Title: warning  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png Timeout (Seconds):60 ]                     A4: Join Send Push [ Configuration:Device: Tablet  Text: Poor range  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png Timeout (Seconds):60 ] If [ %HotspotDevice ~ Tablet ]          A5: AutoWear App [ Configuration:Execute Now: true  Trigger Event: true  Haptic Feedback: true  Name: App  AutoWear Elements: Show  AutoWear Element Id: poorrange  Turn Screen On: true Timeout (Seconds):60 ] If [ %HotspotDevice ~ Watch ]    Exit: Cancel (90)          A1: AutoNotification Cancel [ Configuration:Id: 55  Cancel All: false Timeout (Seconds):0 ]           A2: AutoWear App [ Configuration:Execute Now: true  Trigger Event: true  Haptic Feedback: true  Name: App  AutoWear Elements: Hide  AutoWear Element Id: poorrange  Turn Screen On: true Timeout (Seconds):60 ] If [ %HotspotDevice ~ Watch ]    Profile: No Data (92)          State: Variable Value [ %HotspotVariable ~ 1 ]          State: Mobile Network [ 2G:On 3G:Off 3G - HSPA:Off 4G:Off ]  Enter: PoorSignal (89)                    A1: AutoNotification [ Configuration:Use HTML: false  Title: Poor reception  Icon: android.resource://net.dinglisch.android.taskerm/hl_device_access_network_cell  Status Bar Icon: device_access_network_cell  Status Bar Text Size: 16  Id: 55  Priority: -1  Persistent: true  Is Group Summary: false  LED Color: red  LED On: 300  LED Off: 30p  Skip Picture Cache: false  Update Notification: false  Only on Phone: true Timeout (Seconds):20 ]                     A2: Join Send Push [ Configuration:Device: Chrome@Laptop  Text: Poor range  Title: Poor reception  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png Timeout (Seconds):60 ] If [ %HotspotDevice ~ Laptop ]                    A3: Join Send Push [ Configuration:Device: Chrome@Home  Text: Poor range  Title: warning  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png Timeout (Seconds):60 ]                     A4: Join Send Push [ Configuration:Device: Tablet  Text: Poor range  Icon: /storage/emulated/0/Tasker/Material Icons/ic_wifi.png Timeout (Seconds):60 ] If [ %HotspotDevice ~ Tablet ]          A5: AutoWear App [ Configuration:Execute Now: true  Trigger Event: true  Haptic Feedback: true  Name: App  AutoWear Elements: Show  AutoWear Element Id: poorrange  Turn Screen On: true Timeout (Seconds):60 ] If [ %HotspotDevice ~ Watch ]    Exit: Cancel          A1: AutoNotification Cancel [ Configuration:Id: 55  Cancel All: false Timeout (Seconds):0 ]           A2: AutoWear App [ Configuration:Execute Now: true  Trigger Event: true  Haptic Feedback: true  Name: App  AutoWear Elements: Hide  AutoWear Element Id: poorrange  Turn Screen On: true Timeout (Seconds):60 ] If [ %HotspotDevice ~ Watch ]  

The AutoNotification notification is created on the phone, but only to make the LED blink. Choose the other values of the notification to your personal liking and set fast LED blink (mine is 300ms on/off) in your preferred color. The idea is to display discrete information rather than a fully invasive alert when the screen wake. The notification is saved as a permanent notification with ID 55.

What follows next is a Join push for each device you own. Select a Join push for each device, and use the IF condition to match the value of %HotspotDevice variable.

Configure the Join push action to send a notification of your choice. Since these notifications will be dismissed on the target device, no other actions are needed.

SmartWatch

Smartwatch profile

  Profile: Remove Watch Icon           Event: AutoWear Command [ Configuration:Command Filter: closepoorrange  Case Insensitive: false  Exact: true  Regex: false  Variable Array: false ]  Enter: Close WearIcon (55)          A1: AutoWear App [ Configuration:Execute Now: true  Trigger Event: true  Haptic Feedback: true  Name: App  AutoWear Elements: Hide  AutoWear Element Id: poorrange  Turn Screen On: true Timeout (Seconds):60 ]   

You will notice that I have changed the way the notification works for the smartwatch. None of the above will show up on my watch. The only thing I want to show on my watch is a small icon which can be dismissed on request.

Create an icon using AutoWear Manage Floating Icons *(you have to go to the AutoWear app) and test the size and placement on your watch. The icon will draw over any screen, so make sure it contain a command on tap to close it. I used closepoorrange and named the icon poorrange. The size of my icon is 30×30 pixels and it is placed 65% to the right and 20% from the top.

Once you are happy with the size and location – use the AutoWear App action to show the icon and the IF condition to link it to the %HotspotDevice variable.

Cancel

Cancel

  Cancel (90)          A1: AutoNotification Cancel [ Configuration:Id: 55  Cancel All: false Timeout (Seconds):0 ]           A2: AutoWear App [ Configuration:Execute Now: true  Trigger Event: true  Haptic Feedback: true  Name: App  AutoWear Elements: Hide  AutoWear Element Id: poorrange  Turn Screen On: true Timeout (Seconds):60 ] If [ %HotspotDevice ~ Watch ]  

To end the LED blink and remove the floating icon from the watch, I'm going to use a simple AutoNotification Cancel action with the ID of my notification (55) to perform the AutoWear App action which hides the floating icon.

The smartwatch has an additional profile that will remove the floating icon if the icon is pressed. To do this I use the AutoWear Command event 'closepoorrange' then I run a separate task that contains pretty much the same action as the Cancel task.


We hope you enjoy this little creation of ours, and let us know if you think we can make any enhancements! As always, you can download the project by clicking the link below.

Download the Tethering 'No Network' Warning Project File here!

In order to import the tethering 'no network' warnings with Tasker project file, download the above file and save it anywhere in your internal storage. Open up Tasker and check to make sure that "beginner mode" is disabled in the preferences menu. Then, long-press on the "home" icon in the bottom left hand corner and click on "import". Find the prj.xml file you saved earlier, and select it to import it. You will now see a new tab in the bottom row containing all of the profiles and tasks we referenced in this article.



from xda-developers http://ift.tt/2jsjA9l
via IFTTT

Aucun commentaire:

Enregistrer un commentaire