Top Banner
AT&T Smart Cities With M2X & Flow Designer Introduction ............................................................................................................................................................................................. 2 FASTEST Way to Get Started............................................................................................................................................................. 5 Getting Started – use Socket.io ......................................................................................................................................................... 6 Getting Started – Get Data / Polling ............................................................................................................................................... 9 Add a New M2X Device and Create your own Flow ............................................................................................................. 10 Add your own M2X Device into our Smart City Ecosystem.............................................................................................. 14 Testing a Device Trigger to an AT&T Smart City team device......................................................................................... 15 Example Test Application................................................................................................................................................................ 15 For Available Devices please see Devices Page...................................................................................................................... 15 AT&T Developer Forum Thread ................................................................................................................................................... 15 For Assistance Contact...................................................................................................................................................................... 15
15

AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

Jul 13, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

AT&TSmartCitiesWithM2X&FlowDesigner

Introduction.............................................................................................................................................................................................2FASTESTWaytoGetStarted.............................................................................................................................................................5GettingStarted–useSocket.io.........................................................................................................................................................6GettingStarted–GetData/Polling...............................................................................................................................................9AddaNewM2XDeviceandCreateyourownFlow.............................................................................................................10AddyourownM2XDeviceintoourSmartCityEcosystem..............................................................................................14TestingaDeviceTriggertoanAT&TSmartCityteamdevice.........................................................................................15ExampleTestApplication................................................................................................................................................................15ForAvailableDevicespleaseseeDevicesPage......................................................................................................................15AT&TDeveloperForumThread...................................................................................................................................................15ForAssistanceContact......................................................................................................................................................................15

Page 2: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

IntroductionWe have seeded our Smart City with various connected devices (people counters, fire hydrants, etc.). You can either use the sensor data from these devices or add your own devices. Traditionally in M2X, you add devices, connect the data streams, set up triggers, and deal mostly with devices using their individual unique device keys. For Smart City, we’ve expanded that model by allowing you to subscribe to data streams based on tags that might encompass multiple devices, even if you don’t know the specific device ids. You can get device data from multiple devices in our Smart City based on tags. Tags can be location based or subject based. If you choose to add your own devices then you decide.

Publish/SubscribeTo make life easier, we built a basic pub/sub architecture using Socket.io and Flow Designer. There is a Smart City node that contains a Socket.io server. You simply connect to this server, emit tags that you wish to subscribe to, and listen for events that come down the pipe. All of the devices we have set up in the model smart city funnel data through a Smart City node which you can connect to using Socket.io: http://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events If you would like more info about Socket.io, check out http://socket.io. If you don’t want to use Socket.io, that’s ok too. We’ve created a Smart City client node that you can drop into Flow Designer and hook up to any other type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by connecting directly to the M2X APIs. We’re flexible.

MoreaboutTagsTagsareemittedbacktothesmartcitynodeinanarray.Forexample,ifyouwantedtosubscribetoeventsfordeviceswithtagsofeither“temperature”or“midtown”,youwouldemit[“temperature”,”midtown”].Thiscomma-delimitedarray(,)wouldsubscribeyoutoanydevicethathasatagthatmatcheseither“temperature”or“midtown”.Thisis‘or’matching.Ifyouwanttosubscribetodevicesthathavetagsthatmatchboth“temperature”and“midtown”,youwouldemit[“temperature+midtown”].Addingaplussign(+)wouldsubscribeyoutoeventsfromdevicesthathavebothtags.Thisis‘and’matching.Noticetheplussignispartofastringinsideanarrayofn-length.Wildcards:Currentlywesupportanasterisk(*)asawildcardcharacter.Youcanuseanasteriskatthebeginning(“*town”),end(“temp*”),orbothbeginningandend(“*emp*”).Inaddition,emittingjustanasterisk[“*”]willsubscribetoalleventsregardlessofdevicetag.Inthefuturewemightsupportregexmatchingbutdon’tcurrently.ForavailabletagsinourSmartCityinstance,goto:http://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/tags

Page 3: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

Howoursmartcitynodeworks:

1. Emittagsfromyourapp

2. Listen for events

Page 4: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

Howoursmartcityclientworks:

The smart city client manages the Socket.io connection for you. Configure it to point to the URL of a smart city node, and enter tags you wish to subscribe to.

Page 5: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

FASTESTWaytoGetStarted

1. CreateaFlowDesigneraccountathttps://flow.att.com/

2. Adda“smartcityclient”nodeDrag a smart city client node from the palette to your flow.

3. Specifyurl&tags

(usehttp://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events)(use“*”inTagsifyouwanttosubscribetoallevents)

4. ReceiveSmartCitydeviceeventsYou’llreceiveeventsfromthesmartcitynodelocatedattheurlyouspecifiedabove

Page 6: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

GettingStarted–useSocket.io <scriptsrc=" http://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events/socket.io.js"></script>

1. UsingSocket.io,connecttohttp://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/eventsvarsocket=io("http://run-east.att.io",{path:/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events";});

2. Emitarrayoftagsbacktoserversocket.emit('tags',["midtown","atlanta","puppies"]);

3. Listenfor4typesofmessages“message”

- humanreadablestring- usuallycorrespondstotagsbeingemittedoreventsbeingreceived

“event”- jsonobjectthatrepresentsonchangeeventfromM2X

“tags”- tagsyouarecurrentlysubscribedto

“availableTags” - allavailabletagsforthisSmartCityInstance

//listenformessagessocket.on("message",function(message){console.log("receivedsocket.iomessage:",message);});//listenforeventssocket.on("event",function(message){console.log("event:",message);});//listenforsubscriptiontagssocket.on("tags",function(message){console.log("tags",message);});//listenforavailabletagssocket.on("availableTags",function(message){console.log("availableTags",message);});

4. Youcangetalistofallavailabletagsbyemitting“availableTags”socket.emit('availableTags');

Page 7: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

JavaScript Example: <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=no"><scriptsrc="http://code.jquery.com/jquery-2.1.4.min.js"></script><scriptsrc="http://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events/socket.io.js"></script><title>ExampleApp</title></head><body><h2id="title">ExampleApp</h2><divid="event-list"style="color:#000000"></div><br/><divid="controls"><inputtype="text"id="set-tags-text"style="display:inline-block">&nbsp;&nbsp;<buttonid="set-tags-btn"onclick="setTags()"style="display:inline-block">settags</button><br><inputtype="text"id="add-tags-text"style="display:inline-block">&nbsp;&nbsp;<buttonid="add-tags-btn"onclick="addTags()"style="display:inline-block">addtags</button><br><inputtype="text"id="remove-tags-text"style="display:inline-block">&nbsp;&nbsp;<buttonid="remove-tags-btn"onclick="removeTags()"style="display:inline-block">removetags</button><br><br><buttonid="remove-all-tags-btn"onclick="removeAllTags()">removealltags</button><buttonid="get-tags-btn"onclick="getTags()">gettags</button><buttonid="available-tags-btn"onclick="availableTags()">availabletags</button><br/></div></body><script>//pathtosocket.ioservervarpath="/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events";//socket.ioconnectionvarsocket=io("http://run-east.att.io",{path:path});//onconnectsocket.on("connect",function(){console.log("socketconnected");//subscribetotags(use['*']forall)socket.emit('tags',["midtown","atlanta","puppies"]);//socket.emit("tags",["*"]);//listenformessagessocket.on("message",function(message){console.log("receivedsocket.iomessage:",message);$("#event-list").append(message+"<br/>");});//listenforeventssocket.on("event",function(message){console.log("event:",message);});//listenforsubscriptiontagssocket.on("tags",function(message){console.log("tags",message);});//listenforavailabletagssocket.on("availableTags",function(message){console.log("availableTags",message);});});//socketerror

Page 8: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

socket.on("error",function(message){console.log("error",message);});//socketconnecterrorsocket.on("connect_error",function(message){console.log("connect_error",message);});//socketreconnecterrorsocket.on('reconnect_failed',function(message){console.log("reconnect_error",message);});//emitsettagsmessagefunctionsetTags(){vartags=$("#set-tags-text").val().split(",");socket.emit('tags',tags);$("#set-tags-text").val("");}//emitaddtagsmessagefunctionaddTags(){vartags=$("#add-tags-text").val().split(",");socket.emit('addTags',tags);$("#add-tags-text").val("");}//emitremovetagsmessagefunctionremoveTags(){vartags=$("#remove-tags-text").val().split(",");socket.emit('removeTags',tags);$("#remove-tags-text").val("");}//emitemptytagsfunctionremoveAllTags(){socket.emit('tags',[]);}//getcurrentsubscriptionsfunctiongetTags(){socket.emit('tags');}//emitrequestforavailabletagsfunctionavailableTags(){socket.emit('availableTags');}</script></html>

Page 9: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

GettingStarted–GetData/Polling

1. CreateFlowDesigneraccountathttps://flow.att.com/

2. AddM2XNode

3. Addanewfeed

4. Giveitanameandleaveapikeyblanksincewe’reusingpublicdevices

5. GototheM2Xpubliccataloghttps://m2x.att.com/catalog?page=1

6. Type“SC-“intheresearchbox.Searchfordevicesthatbeginwith“SC-“.Clickonadevicestarting

with“SC-“toseeaccessdetails.

Page 10: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

AddaNewM2XDeviceandCreateyourownFlow

1. CreateFlowDesigneraccountathttps://flow.att.com/

2. CreateNewProject

3. Addhttpinputnode

4. Addhttpresponsenode

5. ConnectNodes

6. Deploytosandbox

Page 11: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

7. EnterOnlineMode

8. SelectendpointsTab(notetheURL)

9. Createacctinm2xathttps://m2x.att.com

10. Createdevice

11. AddDevicename&Tags

12. Addstream

13. AddtriggerforEVERYstream

Page 12: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

o Nameo Selectstreamo Condition–OnChangeo Callbackurl(useCallbackURLfromStep7)o “continuous”frequency

14. Testtrigger

- ClickingtheTestTriggerbutton,underactions ,- ThiswilltriggerthecallinFlowDesigner

Page 13: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

15. Addasmartcitynode,wireittotheHTTPPOSTnodefromstep3

16. Connectyourapptothesmartcitynode.Emittags,listenforevents

17. Forfun,trytowireasmartcityclientintoyoursmartcitynode,effectivelychaining2smartcityFlowinstancestogether.Towireineventsfromoursmartcityflow,usethefollowingURL

http://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events

Note:msg.payloadisfordebugpurposes

Page 14: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

AddyourownM2XDeviceintoourSmartCityEcosystem

1. InM2X,edityourdevice

2. Addatagtoyourdevicethatbeginswith“sc-“(or“SC-“).Thisishowweflagsmartcitydevices.Yourdevicemusthaveatleastonetagthatbeginswith“sc-“.Itcanhaveasmanytagsasneeded,andtheydon’tallhavetostartwith“sc-“aslongasatleastonedoes.

3. SetVisibilityto“PublicDevice”

4. AddatriggerforEVERYdataStreamintoM2X.

5. Setconditionto“OnChange”6. SetcallbackURLto“http://run-

east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/callback”7. SetNotificationFrequencyto“Continuous”

That’sit,thesedeviceswillnowsendonchangeeventstoourSmartCityFlowDesignerinstance,andeventscanbesubscribedtousingSocket.ioathttp://run-east.att.io/f3d5e7227fb53/6ec7d0945763/32567042d798e81/in/flow/events

Page 15: AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.). Alternatively, you can connect directly to M2X using via a Flow Designer M2X node, or by

TestingaDeviceTriggertoanAT&TSmartCityteamdevice http://run-west.att.io/daa244d6cabbb/f812823805c2/36016024ad8ff4e/in/flow/wwwroot/postValue.html

ExampleTestApplication Here’sanexampletestapplication.

• Clonehttp://github.com/attm2x/smartcities-sample.git• Startupindex.htmlfromthePublicfolder.(Runningonyourlocalwebinstanceisfine).• Enter*inthe“addtags”field• Click“addtags• Youarenowsubscribedtoafeedofallthesmartcitydevicesthathasatagthatbeginswith“sc-“.

Throughthis,youareessentiallysubscribingtoallthedevicesthatarepublic,hasthetagbeginningwith“sc-“,andanyotherparametersyouadd.Hint:Withindex.htmlrunninginChrome,“inspectelement”,andselect“console”tab.

ForAvailableDevicespleaseseeDevicesPagehttp://developer.att.com/smart-cities/available-datasets-devices

AT&TDeveloperForumThreadWe will be monitoring the Smart City thread under M2X.

http://developerboards.att.lithium.com/t5/M2X-Data-Service/bd-p/M2X_Data_Service

ForAssistanceContact

Jonathan Davis [email protected] 404.545.8267

Virginia Ng [email protected] 404.375.9148

Joanie Twersky [email protected] 404.213.2284