Advanced Action Flows – Part 4. Tweeting lat-long info

lat long action flows
Let’s see how to use action flows and tweet the latitude and longitude positions to Twitter whenever an event occurs in a defined geofence from the action flow editor.

Pre-requisite:

  • Creation of Places, Floors , Departments and Geofences.
  • This is a simple example which can be achieved by triggering an enter event to the geofences created.

How to trigger an Enter event?

Once you have created the places, floors, department and geofences, download Proximi.io Management App for Android or iOS.

  1. Login to the app with the same credentials as the one that you have used in the Web Portal to create the action flow.
  2. Go to the Map demo. This, in turn, will show your current position in blue and the geofences created as red circle. In our case, we have two geofences. The geofences will show up in the map only when you enable ‘Show Input and Geofences’ option from the bottom of the page.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       AFgeoofenceevent

3.With Proximi.io management app running in your mobile device, move in and out of the Geofence area to get the ENTER and EXIT events triggered. That’s when your latitude and longitude positions will be posted to Twitter.

Note:

You need to have beacons installed  or have IndoorAtlas mapped in your location or GPS enabled to track your Movement.  In order to use  GPS, you actually need to go outside to trigger events.

Step 1 : Import the following piece of code into the action flow clipboard from top right corner.

[{"id":"1cc386bf.46a9b9","type":"function","z":"b39b501d.be416","name":"Corner Geofence Notification","func":"msg.payload = \"You are now in Corner Geofence with Lat \"+ msg.data.location.lat + \" and Longitude \"+ msg.data.location.lng;\nreturn msg;","outputs":1,"noerr":0,"x":593,"y":213,"wires":[["e2a0f3a5.c6d57"]]},{"id":"3f4b1769.d8a8c8","type":"function","z":"b39b501d.be416","name":"Elevator Notification","func":"msg.payload = \"You are now Near Elevator with Lat \"+ msg.data.location.lat + \" and Longitude \"+ msg.data.location.lng;\nreturn msg;","outputs":1,"noerr":0,"x":574,"y":480,"wires":[["e2a0f3a5.c6d57"]]},{"id":"82e02960.718f08","type":"switch","z":"b39b501d.be416","name":"Check Event Type","property":"event","propertyType":"msg","rules":[{"t":"eq","v":"enter","vt":"str"},{"t":"eq","v":"exit","vt":"str"}],"checkall":"false","outputs":2,"x":199,"y":219,"wires":[["29cb7799.c1d948"],[]]},{"id":"29cb7799.c1d948","type":"switch","z":"b39b501d.be416","name":"Check Geofence ","property":"data.geofence","propertyType":"msg","rules":[{"t":"eq","v":"CornerOffice Geofence","vt":"str"},{"t":"eq","v":"Elevator Geofence","vt":"str"}],"checkall":"true","outputs":2,"x":292,"y":372,"wires":[["1cc386bf.46a9b9"],["3f4b1769.d8a8c8"]]},{"id":"76ee3452.c4a3ec","type":"proximiio-event-receiver","z":"b39b501d.be416","delete_event":true,"x":159,"y":119,"wires":[["82e02960.718f08"],[]]},{"id":"e2a0f3a5.c6d57","type":"twitter out","z":"b39b501d.be416","twitter":"","name":"Sending Lat and Lng Tweet","x":914,"y":314,"wires":[]}]

actions_5

Step 2 : Once the above code is imported the action flow would look like this.

TwitterWhole

Here’s the full walk-through of each of the steps and what’s happening in the action flows:

Proximi.io Event Receiver
This node listens for visitors entering or exiting any of the defined geofences. When a proximity event occurs, the node get’s triggered and it will pass all the event data as an output payload.

Switch node
A Switch node can be used to segment the action flow based on the event type, department and a lot of other properties as well. You can check out all the properties from our REST API documentation. In this case we’re reacting only to Enter events.

Switch node #2

Another Switch node will be used to determine, which Geofence was entered. Change the name of the Geofences to match with the ones created by you. Double click on “Check Geofence” switch node and change the two entries as to match with your geofence names.

Function node

A Function node allows you to use JavaScript to add custom logic which might not be possible with other nodes. In this case, based on the Enter event in the corresponding geofences, the appropriate latitude and longitude will be posted to Twitter. So we have two Function nodes: ‘Corner Geofence Notification’ and ‘Elevator Notification’.

Sending Lat-and-Long Tweets

Twitter Out node 

Twitter Out node will tweet the msg.payload that’s passed. The most important step here is to authenticate the twitter account to which the tweets will be send. Double-click on the Twitter Out node and the below screen pops up.

AFTwitter2

 

Click on the pencil option that you see on the top right corner to authenticate the Twitter account.

AFTwitter3

 

Press ‘Click here to authenticate with Twitter’ the next page opens up in which you can give your Twitter credentials and complete the step by clicking “Authorise app”.

AFTwitter4

 

Once you authorize the app, another confirmation page would open up. You can close it and proceed to deploy the action flow.

Step 3: Deploying the action flow : You can deploy the action flow from the top right corner of the editor. Usually it’s good idea to select the first option “Full”.

Deploying the action flow

 

Once you have deployed your action flow and have ensured there were no errors, you need to follow the above steps mentioned in ‘How to trigger an Enter events’ to get an Enter event triggered. After that you can see the tweets posted to your Twitter account.

TwitterPic

About Annina Koskiola

CEO and Co-founder of Proximi.io. Loves exploring new ways for technology to intertwine with our everyday lives. Passion for history, traveling, eating and the Valais Blacknose sheep.