AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.)....
Transcript of AT&T Smart Cities With M2X & Flow Designer...type of node (such as a websocket node, etc.)....
![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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/1.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/2.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/7.jpg)
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"> <buttonid="set-tags-btn"onclick="setTags()"style="display:inline-block">settags</button><br><inputtype="text"id="add-tags-text"style="display:inline-block"> <buttonid="add-tags-btn"onclick="addTags()"style="display:inline-block">addtags</button><br><inputtype="text"id="remove-tags-text"style="display:inline-block"> <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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/13.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050103/5f41b6baf5d1a75d97422eec/html5/thumbnails/15.jpg)
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