Self-sustaining WiFi Flow - need help please

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
kssxs
Posts: 9
Joined: 25 Feb 2014 04:31

Self-sustaining WiFi Flow - need help please

Post by kssxs » 25 Feb 2014 05:08

Hi there!

I'm a heavy Tasker user, and thought I would try out AM, so am in trial mode while giving it a spin on my work phone. I'm trying to build a task I already have working in Tasker, on my personal phone. I've setup 2 flows to try and make an automated WiFi enabler/disabler based on GSM Cell ID.

The way it's setup is as per below.

Flow 1:

Trigger:

WiFi Connected to Any SSID

Condition:

Phone Cell GSM: Connected to CIDs *

Actions (as per below):

1) When WiFi connects to an access point (this could be at home, work, friends house, etc, but basically, I go somewhere where I want to always connect to WiFi, ask for the password, and then connect to it), a flow fires off that checks the current GSM Cell ID, and then saves it into a text file, and also into a global variable if it's not already saved.

2) This flow will always fire when the phone connects to WiFi; the first couple of times I will have to turn on WiFi manually, as it hasn't yet saved all of the GSM Cell ID's in the area, but after having done that a few times, it becomes self-sustaining, and automatically turns it on when in that area in the future due to a second flow (below) that turns on WiFi for matching Cell ID's.

3) one of the things that the flow does is check to make sure it doesn't already have the GSM Cell ID saved in the global variable (which contains all of the Cell ID's of valid WiFi access points); if the Cell ID already exists, the flow stops (based on a comparison condition).

Number 3 is where my problem is. I can't seem to figure out how to compare the list of Cell ID's saved in 'global_cid' with the currently identified 'cid'. I've tried various expressions and permutations:

global_cid=cid
global_cid=='*cid*'
contains (global_cid, 'cid')
contains (global_cid, '*cid*')

Since this is contained in a condition, when I execute just the one step (or even the entire flow), I never get the response I'm expecting. I want it to be able to identify when one of the Cell ID's is already contained within the 'global_cid' variable, and if it's there, then DO NOT save the current Cell ID into the existing list, nor add it to the list of Cell ID's in the text file I'm writing to. I know for a fact that it's not working, because every time I go and check the value of the 'global_cid' variable, it has the same Cell ID listed multiple times. I want it to contains ONLY UNIQUE values. That way, the list is short and efficient, and keeps the task quick. I realize the size of the variable may not matter, but for efficiencies sake, I'd like to keep it clean.

The second flow, just to show you the whole picture, looks like this:

Trigger:

WiFi Disconnected
Phone Connected to {global_cid}
Display State: On

Action:

Set WiFi State: On

This flow will turn on WiFi if it's currently off, when the screen comes on, and the phone is connected to a known GSM Cell ID.

If WiFi connects to an access point, Flow 1 will fire and check to see if the Cell ID is already known (although redundant at this point), but for the sake of not knowing a Cell ID in that area while being connected to a known WiFi access point, it will then save it for future. If, however, the Cell ID is known, the flow will stop, based on the comparison condition in item number 3.

Can anyone help with the variable comparison that I'm looking for above in item number 3?

Also, side question:

In Tasker, a profile has contexts that control the triggering of tasks. When the profile goes active, it fires the enter task, and when it goes inactive, it can fire the exit task (to turn WiFi off, for example, using the above ideas).

In AM, do I need to manually setup a 3rd flow (for the WiFi state above) to turn OFF WiFi if I'm not connected to a known network, and am in an area where I don't have the Cell ID's saved? Basically, I'm asking if I have to create another flow to turn WiFi off, or is it automatic? Do the settings changed by flows reset to their original settings when the triggers are no longer valid?

I love AM's interface, and flow charting in general, so am really enjoying this so far.

Thanks for any help you all can provide!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Self-sustaining WiFi Flow - need help please

Post by Martin » 25 Feb 2014 17:56

Hi,

In step 3 I would probably use a list of known cell IDs and then check if the list already contains the value.

To create a new empty list, you can use following script (in an action Script):

Code: Select all

global_cid_list = newList();
Script to add a new cell ID to the list:

Code: Select all

addElement(global_cid_list, cid);
Checking if the list contains an element:

Code: Select all

result = containsElement(global_cid_list, cid);
You could use the last script in a condition Expression: containsElement(global_cid_list, cid); and continue the flow on the true- or false-branch.

There's a flow available in the flow sharing area that uses the methods above to create a simple multiclipboard: http://automagic4android.com/forum/view ... f=3&t=1897
The flow also uses a script to keep a maximum of 5 entries in the list to ensure that the clipboard doe not grow endlessly.

Automagic has no concept of an exit-task since flows are always executed by an event that's very short lived so you have to create a separate flow to build something like an exit-task.

Regards,
Martin

User avatar
kssxs
Posts: 9
Joined: 25 Feb 2014 04:31

Re: Self-sustaining WiFi Flow - need help please

Post by kssxs » 26 Feb 2014 00:28

Thank you Martin! No answer could be better than from the dev himself ;) .

I'm almost complete with the new flow with your suggestions included. The last thing I needed was the name of the variable that contains the name of the currently connected WiFi access point. I use this to write the details to my Cell ID file. In that file, I write the following details:

{cid};{getdate(),dateformat,MM-dd-yy - HH:mm};{name of SSID}

The last part is the only one not working now (the name of the SSID).

The file keeps track of what cell ID's are connected on that date and time, and which WiFi networks were connected at the time. This way, I always have a historical view of the networks I've been on, and when they were connected, but also in the case of having been connected to a network I no longer need, I can delete (manually or through a flow) the ones I no longer want to connect to in the future.

If you can shed some light on the magic variable, or a means of acquiring that WiFi name, that would be greatly appreciated.

Also, another side question:

Do you have a list of built-in variables that get updated by AM as conditions change? So, for example, the way {cid} contains the current Cell ID.

I think a page on your website with those variables and an explanation of what each variable is for and how it can be used in flows, how it's updated, if it is global, etc, would help a lot of users, if it doesn't already exist.

Thanks again!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Self-sustaining WiFi Flow - need help please

Post by Martin » 26 Feb 2014 18:35

The variables provided by triggers, conditions and actions are listed on the help page of each type of object. You can access the help page on the upper right side when editing a trigger/condition/action using the [?]-icon. Scroll down to the variables section.
The help pages are also available on the website: http://automagic4android.com/en/help/co ... _connected

You can also use menu->Select Variable to show a list of the variables that will be likely available when the flow reaches the action you are currently editing. There's also a special condition Debug Dialog that can be added in the middle of a flow that will show all available variables and the corresponding values.

In your case you can probably access the name of the WiFi network like this:
{cid};{getdate(),dateformat,MM-dd-yy - HH:mm};{ssid}

User avatar
kssxs
Posts: 9
Joined: 25 Feb 2014 04:31

Re: Self-sustaining WiFi Flow - need help please

Post by kssxs » 26 Feb 2014 20:13

Edited:

Fantastic, it works! Looks like my trailing ';' was causing the issue (had one on the {SSID} variable, not shown above). Is the proper use of semi-colons also documented?

Just as a feature request, it would be nice if there was a global variable that was updated by AM when an SSID is connected, and then blanked out when the device is no longer connected. Basically a state that is monitored by AM all the time so that the value of the variable is accurate and can be used globally at any time. Would that be possible to get?

I'll post my 2 working flows for this once I've tested them out thoroughly over the next couple of days.

Thanks so much for your help Martin! I look forward to becoming a paying owner of Automagic! :)

User avatar
kssxs
Posts: 9
Joined: 25 Feb 2014 04:31

Re: Self-sustaining WiFi Flow - need help please

Post by kssxs » 26 Feb 2014 23:42

I've run into an issue where the following expression errors out in my 3 trial flows:

expression: containsElement(global_CellIDList, cid);
error: <other error text> Could not execute expression 'containsElement(global_CellIDList, cid);'<other error text>
Caused by: <other error text> Can not find element xxxxxxxx since [xxxxxxxx] is not a list.<other error text>

It happens after the initial list has been built, but now when the list is trying to update with other GSM cell ID's, AM doesn't evaluate the expression properly and errors out with the above error.

Any idea why?

Thanks!

Update:

If I delete the 'global_CellIDList' from the 'Global Variables' section of the app, and then execute the list builder manually, it doesn't error out. Also, if I then turn off WiFi to manually test it, it also doesn't error out, and works as expected (turns on WiFi, confirms that the cell ID exists in the initial list and doesn't add a new cell ID).

Not sure what is going on with that error, and why it occurs and then only works or doesn't work intermittently.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Self-sustaining WiFi Flow - need help please

Post by Martin » 27 Feb 2014 16:29

Maybe you have assigned a number to the list so it was not a list anymore, for example like this:
global_CellIDList = cid;
Maybe you have edited the list manually and converted the list to a string at this point.

User avatar
kssxs
Posts: 9
Joined: 25 Feb 2014 04:31

Re: Self-sustaining WiFi Flow - need help please

Post by kssxs » 27 Feb 2014 23:47

Yep, that's exactly what happened. I had modified the list manually (to delete bad/duplicate Cell ID's), and I guess that converted it to a string (or corrupted it for the purposes for which I was using it).

So a question from that issue:

Is there a way to modify a list manually without it being converted to a string? I realize there is another 'Element' script I can use to remove an element, but I'm going to assume the answer to this question is no, which means just delete the list/variable and then reload it (which I've already managed to figure out how to do from the fact that I've been saving the Cell ID's to a text file as part of this flow). So the question is, rather than a list, would it be possible to match a value (such as the Cell ID) from within a bunch of values from a string variable (the way I was attempting before) rather than having to use a list?

Thanks!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Self-sustaining WiFi Flow - need help please

Post by Martin » 28 Feb 2014 10:16

You could also keep the list in a string variable and convert the string to a list when required.
Assume you have a string like this: global_cell_ids="1,2,3,4"

You could use following script to create a real list temporarily:

Code: Select all

list = split(global_cell_ids, ",");
..then use the regular list functions like containsElement, addElement etc. and finally convert the list back to a string:

Code: Select all

global_cell_ids = "{list,listformat,comma}";
Another way would be to use strings only. First create a global variable of type string with a comma only:
global_cell_ids = ",";

..then use string operations to check if the string contains the cell:

Code: Select all

if(!contains(global_cell_ids, "," + cid + ",") //could also be written as: if(!contains(global_cell_ids, ",{cid},")
{
   global_cell_ids = global_cell_ids + cid + ",";
}

There's an item on my todo-list to add to support for manually editing lists and maps that will greatly simplify such operations.

User avatar
kssxs
Posts: 9
Joined: 25 Feb 2014 04:31

Re: Self-sustaining WiFi Flow - need help please

Post by kssxs » 01 Mar 2014 00:07

Awesome Martin!

Thank you for taking the time to answer. I'll try out your suggestions (after I backup my currently *seems to be working* set of flows) and see where it takes me.

Post Reply