Fibocom G510 Dashboard and Localization with OpenCellID and Google APIs

General

This Flow allows users to retrive informations from their G510 GSM/GPRS Module like: signal strength, Operator name, MCC MNC CellID and LAC (for localization purposes), IMEI code aND other manifacturer specific codes.

node-red-node-serialport is used to send AT comands to the ttyAMA0 interface and read the output response from the module. More info about AT commands input/output formats can be found in AT COMMANDS function node.

Location info codes are stored in a flow variabile named locationInfo. You can find a trigger node that can be used to send the current location object in the debug console.

Usage

var location = flow.get('locationInfo');

In a function node to retrive the current location everywhere in this flow

Screenshots

0_1507124912843_upload-f44d0f00-3612-47f8-aa08-91819d6ff5fe

0_1507124782319_upload-8a2171eb-31ce-403a-8b88-428e8162c1b4

License

MIT License

Copyright (c) 2017 Daniel Lando

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[{"id":"cb334c13.148f2","type":"tab","label":"Fibocom G510","disabled":false,"info":"## General\n\nThis Flow allows users to retrive informations from their\n**G510 GSM/GPRS** Module like: signal strength, Operator name, \nMCC MNC CellID and LAC (for **localization** purposes), IMEI code\naND other manifacturer specific codes.\n\n`node-red-node-serialport` is used to send *AT comands* to the\n`ttyAMA0` interface and read the output response from the module.\nMore info about AT commands input/output formats can be found\nin *AT COMMANDS* function node.\n\nLocation info codes are stored in a flow variabile named\n`locationInfo`. You can find a trigger node that can be used\nto send the current location object in the debug console.\n\n## Usage\n\n```\nvar location = flow.get('locationInfo');\n```\n\nIn a function node to retrive the current location everywhere in this flow\n\n## License\n\nMIT License\n\nCopyright (c) 2017 Daniel Lando\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."},{"id":"731cbd5c.ee0b54","type":"inject","z":"cb334c13.148f2","name":"","topic":"","payload":"init","payloadType":"str","repeat":"","crontab":"","once":true,"x":101,"y":105,"wires":[["ed285df2.64a44"]]},{"id":"dde8589c.07b868","type":"serial out","z":"cb334c13.148f2","name":"write","serial":"741b4068.5a76a","x":471,"y":178,"wires":[]},{"id":"c2932b4e.8c0338","type":"serial in","z":"cb334c13.148f2","name":"read","serial":"741b4068.5a76a","x":76,"y":237,"wires":[["6973b680.b52518"]]},{"id":"ed285df2.64a44","type":"function","z":"cb334c13.148f2","name":"AT COMMANDS","func":"\nvar commands = {getSignal:'AT+CSQ', //<rssi>,<ber> -- rssi:0-31 ber:Channel bit error rate (in percent) 0-7 RXQUAL values in the GSM 05.08 table \n                enableGPRS:'AT+CGREG=2', //<n> = 2 (Enables the network registration and location information)\n                getGPRS:'AT+CGREG?',  //<n>,<stat>[,<lac>,<cellID>] \n                enableNetwork:'AT+CREG=2', //<n> = 2 (Enables the network registration and location information)\n                getNetwork:'AT+CREG?', /*\n                response: <n>,<stat>[,<lac>, <cellID>] \n                <n> \n                    0 Disables the network registration unsolicited result code. \n                    1 Enables the network registration unsolicited result code +CREG: <stat>. \n                    2 Enables the network registration and location information in unsolicited reports and Read command +CREG: <stat>[,<lac>,<ci>]. \n                    The default value is 0.  \n                <stat> \n                    0 Not registered, and the ME is not currently searching for a new operator to which to register. \n                    1 Registered, home network. \n                    2 Not registered, but the ME is currently searching for a new operator to which to register. \n                    3 Registration denied. \n                    4 Unknown. \n                    5 Registered, roaming. \n                <lac> Two-byte location area code in hexadecimal format. \n                <ci> Two-byte cell ID in hexadecimal format. \n                */\n                getOperator:'AT+COPS?', \n                /*\n                response: <mode>[,<format>,<oper>] \n                <format>:  (0 Long alphanumeric 1 Short alphanumeric 2 Numeric) \n                <mode>: Determines whether what is displayed is defined by <oper>, or is done automatically by the G5xx. \n                    0 Automatic (<oper> field is ignored) \n                    1 Manual (<oper> field is present) \n                    2 De-register from network \n                    3 Set only <format> (<oper> field is ignored); used for Read command only, do not attempt registration/deregistration \n                    4 Manual/automatic (<oper> field is present; if manual selection fails, use automatic mode) The default value is 0.  \n                <stat>: \n                    0 Unknown \n                    1 Available \n                    2 Current \n                    3 Forbidden \n                */\n                setStringOperator: 'AT+COPS=3,0',\n                setNumericOperator: 'AT+COPS=3,2', //will be a 5 digit code MCC(3)+MNC(2)\n                getOperatorsList:'AT+COPS=?', \n                /*\n                response: [list of supported network (<stat>,<oper>,short alphanumeric<oper>, numeric<oper>)] [,list of supported <mode>s,(list of supported<format>s)] \n                OK indicating the availability of the operator <stat>, \n                long and short alphanumeric format of the name of the operator,\n                and numeric format representation of the operator. \n                If any of the formats are unavailable, there is an empty field. \n                The list of operators is in the following order: home network, \n                networks referenced in SIM or active application in the UICC (GSM or USIM) \n                in the following order: \n                    HPLMN selector \n                    User controlled PLMN selector\n                    Operator controlled PLMN selector and PLMN selector (in the SIM or GSM application)\n                    and other networks. \n                After the operator list, the G30 returns lists of the supported <mode>s and <format>s. \n                These lists are separated from the operator list by two commas. \n \n                */\n                getManifacturerID:'AT+CGMI',  //<manifacturerID> eg. \"Fibocom\"\n                getModelID:'AT+CGMM',  //<list of supported technologies>,<model> eg.  \"GSM850/900/1800/1900”,”G510\" \n                getRevision:'AT+CGMR',  //<revision> eg.  \"G510_V0D.00.16\" \n                getIMEI:'AT+CGSN', //<imei> 15 digits imei\n                };\n\nflow.set('at_commands', commands);","outputs":"0","noerr":0,"x":284,"y":105,"wires":[]},{"id":"6973b680.b52518","type":"join","z":"cb334c13.148f2","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","x":207,"y":237,"wires":[["93378fd6.5a6c2"]]},{"id":"d4e3f070.4374b","type":"function","z":"cb334c13.148f2","name":"getOutput","func":"var ok = msg.payload.indexOf('OK') >= 0;\nvar commands = flow.get(\"at_commands\");\n\nmsg.ok = ok;\nmsg.command = Object.keys(commands).find(key => commands[key] === msg.payload[0]);\n\nif(ok)\n    msg.output = msg.payload[2];\n\nif(!ok && msg.payload.indexOf('ERROR') < 0) //no error detected, something else went wrong\n msg = null;\n\nif(msg.payload.indexOf('ERROR') >= 0 && msg.payload[2].indexOf('SIM DROP') >= 0) //sim removed\n msg.payload = 'SIM REMOVED';\n\nreturn msg;","outputs":1,"noerr":0,"x":478,"y":237,"wires":[["a9b577dd.6e25f8"]]},{"id":"93378fd6.5a6c2","type":"function","z":"cb334c13.148f2","name":"trim","func":"for(var i=0;i<msg.payload.length;i++)\n msg.payload[i] = msg.payload[i].trim();\nreturn msg;","outputs":1,"noerr":0,"x":335,"y":237,"wires":[["d4e3f070.4374b"]]},{"id":"c20b4215.70588","type":"switch","z":"cb334c13.148f2","name":"","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"getSignal","vt":"str"},{"t":"eq","v":"getGPRS","vt":"str"},{"t":"eq","v":"getNetwork","vt":"str"},{"t":"eq","v":"getOperator","vt":"str"},{"t":"eq","v":"getManifacturerID","vt":"str"},{"t":"eq","v":"getModelID","vt":"str"},{"t":"eq","v":"getRevision","vt":"str"},{"t":"eq","v":"getIMEI","vt":"str"}],"checkall":"false","outputs":8,"x":765,"y":235,"wires":[["77fa9e83.bf455"],["ba6b1bf1.de5618"],["a00cbc12.518d4"],["8d69f322.be7d8"],["e632c8fc.b2f838"],["3bc57482.a6c35c"],["67b6c4.eb65593c"],["61d411eb.934b"]]},{"id":"3004ad23.99e3e2","type":"link in","z":"cb334c13.148f2","name":"writeSerial","links":["2ace9119.b3bd7e","504221df.67e87","d145548.df406a8","582134b6.f4be8c","32d0b1cd.55407e","e955bcc2.70fef","23a8a4f7.733c7c","88db1de6.bdc21","b1f84744.05fdd8","e8d279bf.4986c8","bfc9aa67.eedd68","7e0dcdb2.dede54","4788ed8f.8ab664","4ebeda6b.f835a4"],"x":44,"y":178,"wires":[["bbe54f9a.162bf"]]},{"id":"32b31b6c.667d54","type":"inject","z":"cb334c13.148f2","name":"everyMinute","topic":"","payload":"at_commands","payloadType":"flow","repeat":"60","crontab":"","once":true,"x":263,"y":576,"wires":[["ba569226.796e9"]]},{"id":"ef2723d9.c445a","type":"function","z":"cb334c13.148f2","name":"getSignal","func":"msg.payload = msg.payload.getSignal;\n\nreturn msg;","outputs":1,"noerr":0,"x":636,"y":418,"wires":[["582134b6.f4be8c"]]},{"id":"77fa9e83.bf455","type":"function","z":"cb334c13.148f2","name":"parseSignal","func":"var index = msg.output.indexOf(' ');\nvar signal = msg.output.substring(index,msg.output.length);\nsignal = signal.split(',')[0];\nsignal = parseInt(signal);\nmsg.payload = signal;\n\nreturn msg;","outputs":1,"noerr":0,"x":976,"y":31,"wires":[["7161aea7.1ed05"]]},{"id":"bbe54f9a.162bf","type":"function","z":"cb334c13.148f2","name":"addEnter","func":"msg.payload += '\\r\\n';\nreturn msg;","outputs":1,"noerr":0,"x":144,"y":178,"wires":[["3ef9b632.ebe8ca"]]},{"id":"7161aea7.1ed05","type":"range","z":"cb334c13.148f2","minin":"0","maxin":"31","minout":"0","maxout":"100","action":"scale","round":true,"name":"","x":1139,"y":31,"wires":[["5c94d4ce.ae7f8c"]]},{"id":"5c94d4ce.ae7f8c","type":"ui_gauge","z":"cb334c13.148f2","name":"signal strength","group":"dee76989.5e3358","order":1,"width":0,"height":0,"gtype":"gage","title":"Signal strength","label":"","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1321,"y":31,"wires":[]},{"id":"5c4b90e4.399b2","type":"function","z":"cb334c13.148f2","name":"getOperator","func":"msg.payload = msg.payload.getOperator;\n\nreturn msg;","outputs":1,"noerr":0,"x":646,"y":461,"wires":[["582134b6.f4be8c"]]},{"id":"8d69f322.be7d8","type":"function","z":"cb334c13.148f2","name":"parseOperator","func":"var msg2 = null;\n\nvar index = msg.output.indexOf(' ');\nvar operator = msg.output.substring(index,msg.output.length);\noperator = operator.split(',')[2].trim().slice(1 , -1);\n\nif(!isNaN(operator)){ //numeric operator\n    msg2 = {};\n    var locationInfo = flow.get('locationInfo') || {};\n    flow.set(\"numericOperator\", true);\n    var mcc = parseInt(operator.substr(0,3));\n    var mnc = parseInt(operator.substr(3,2));\n    \n    if(mcc)\n        locationInfo.mcc = mcc;\n    if(mnc)\n        locationInfo.mnc = mnc;\n        \n    flow.set('locationInfo', locationInfo);\n    msg = null;\n}\nelse{ //string operator\n    flow.set(\"numericOperator\", false);\n    msg.payload = operator;\n}\n\n//sends a message to switchoperatorformat function to change the format of\n//the operator, in next read the operator will be readed in the other format\n//and the format will keep change in this way to be able to read\n//boh operator name and MNC MCC codes\n\nreturn [msg,msg2];","outputs":"2","noerr":0,"x":987,"y":263,"wires":[["d14d0d48.bfc5c","93b0f61.92f4308"],["93b0f61.92f4308"]]},{"id":"d14d0d48.bfc5c","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":2,"width":0,"height":0,"name":"","label":"Operator","format":"{{msg.payload}}","layout":"row-spread","x":1202,"y":270,"wires":[]},{"id":"3ef9b632.ebe8ca","type":"delay","z":"cb334c13.148f2","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":314,"y":178,"wires":[["dde8589c.07b868"]]},{"id":"e632c8fc.b2f838","type":"function","z":"cb334c13.148f2","name":"parseManifacturerID","func":"var index = msg.output.indexOf(' ');\nvar id = msg.output.substring(index,msg.output.length);\nmsg.payload = id.trim().slice(1 , -1);\n\nreturn msg;","outputs":1,"noerr":0,"x":1008,"y":333,"wires":[["15e8679b.3d5e88"]]},{"id":"15e8679b.3d5e88","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":3,"width":0,"height":0,"name":"","label":"Manifacturer ID","format":"{{msg.payload}}","layout":"row-spread","x":1217,"y":333,"wires":[]},{"id":"939ed13d.5e199","type":"function","z":"cb334c13.148f2","name":"getManifacturerID","func":"msg.payload = msg.payload.getManifacturerID;\n\nreturn msg;","outputs":1,"noerr":0,"x":664,"y":508,"wires":[["582134b6.f4be8c"]]},{"id":"3bc57482.a6c35c","type":"function","z":"cb334c13.148f2","name":"parseModelID","func":"var index = msg.output.indexOf(' ');\nvar id = msg.output.substring(index,msg.output.length);\nid = id.split(',')[1];\nmsg.payload = id.trim().slice(1 , -1);\n\nreturn msg;","outputs":1,"noerr":0,"x":990,"y":372,"wires":[["fcf56a68.c7f7c8"]]},{"id":"fcf56a68.c7f7c8","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":4,"width":0,"height":0,"name":"","label":"Model ID","format":"{{msg.payload}}","layout":"row-spread","x":1198,"y":372,"wires":[]},{"id":"bcaf61fd.ad0e5","type":"function","z":"cb334c13.148f2","name":"getModelID","func":"msg.payload = msg.payload.getModelID;\n\nreturn msg;","outputs":1,"noerr":0,"x":646,"y":552,"wires":[["582134b6.f4be8c"]]},{"id":"582134b6.f4be8c","type":"link out","z":"cb334c13.148f2","name":"writeSerial","links":["3004ad23.99e3e2"],"x":874,"y":555,"wires":[]},{"id":"67b6c4.eb65593c","type":"function","z":"cb334c13.148f2","name":"parseRevision","func":"var index = msg.output.indexOf(' ');\nvar id = msg.output.substring(index,msg.output.length);\nmsg.payload = id.trim().slice(1 , -1);\n\nreturn msg;","outputs":1,"noerr":0,"x":989,"y":413,"wires":[["6d855e81.1222"]]},{"id":"6d855e81.1222","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":5,"width":0,"height":0,"name":"","label":"Revision","format":"{{msg.payload}}","layout":"row-spread","x":1197,"y":413,"wires":[]},{"id":"61d411eb.934b","type":"function","z":"cb334c13.148f2","name":"parseIMEI","func":"var index = msg.output.indexOf(' ');\nvar id = msg.output.substring(index,msg.output.length);\nmsg.payload = id.trim().slice(1 , -1);\n\nreturn msg;","outputs":1,"noerr":0,"x":979,"y":454,"wires":[["c2204a6d.6adad8"]]},{"id":"c2204a6d.6adad8","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":6,"width":0,"height":0,"name":"","label":"IMEI","format":"{{msg.payload}}","layout":"row-spread","x":1187,"y":454,"wires":[]},{"id":"a0815e78.1d95f","type":"function","z":"cb334c13.148f2","name":"getRevision","func":"msg.payload = msg.payload.getRevision;\n\nreturn msg;","outputs":1,"noerr":0,"x":647,"y":597,"wires":[["582134b6.f4be8c"]]},{"id":"6468fa6e.b3bda4","type":"function","z":"cb334c13.148f2","name":"getIMEI","func":"msg.payload = msg.payload.getIMEI;\n\nreturn msg;","outputs":1,"noerr":0,"x":639,"y":640,"wires":[["582134b6.f4be8c"]]},{"id":"ea68dfcb.06011","type":"function","z":"cb334c13.148f2","name":"getNetwork","func":"msg.payload = msg.payload.getNetwork;\n\nreturn msg;","outputs":1,"noerr":0,"x":651,"y":680,"wires":[["582134b6.f4be8c"]]},{"id":"a92e8752.c9c3e8","type":"function","z":"cb334c13.148f2","name":"getGPRS","func":"msg.payload = msg.payload.getGPRS;\n\nreturn msg;","outputs":1,"noerr":0,"x":641,"y":722,"wires":[["582134b6.f4be8c"]]},{"id":"ba6b1bf1.de5618","type":"function","z":"cb334c13.148f2","name":"parseGPRS","func":"var index = msg.output.indexOf(' ');\nvar gprs = msg.output.substring(index,msg.output.length);\ngprs = gprs.split(',');\n\nvar locationInfo = flow.get('locationInfo') || {};\n\nvar n = parseInt(gprs[0]);\n\nif(n === 0 || n == 1){\n    msg.topic = \"get\";\n}\nelse if(n == 2){\n    msg.topic =\"set\";\n    msg.payload = {};\n    var stat = parseInt(gprs[1]);\n    \n    switch(stat){\n        case 0: stat = \"Not registered\";\n            break;\n        case 1: stat = \"Registered - Home network\";\n            break;\n        case 2: stat = \"Searching...\";\n            break;\n        case 3: stat = \"Registration denied\";\n            break;\n        case 4: stat = \"Unknown\";\n            break;\n        case 5: stat = \"Registered - Roaming\";\n            break;\n    }\n    \n    msg.payload.status = stat;\n    \n    if(n == 2){\n        var lac = parseInt(gprs[2].trim().slice(1 , -1),16);\n        var cellID = parseInt(gprs[3].trim().slice(1 , -1),16);\n        if(lac)\n            locationInfo.lac= lac;\n        if(cellID)\n            locationInfo.cellID = cellID;\n    }\n    \n}\n\nflow.set('locationInfo', locationInfo);\n\nreturn msg;","outputs":1,"noerr":0,"x":977,"y":96,"wires":[["ebda1670.ef98a8"]]},{"id":"6e010c30.5c0164","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":7,"width":0,"height":0,"name":"","label":"GPRS Status","format":"{{msg.payload.status}}","layout":"row-spread","x":1310,"y":116,"wires":[]},{"id":"ebda1670.ef98a8","type":"switch","z":"cb334c13.148f2","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"get","vt":"str"},{"t":"eq","v":"set","vt":"str"}],"checkall":"true","outputs":2,"x":1137,"y":96,"wires":[["5a7ae1af.ce926"],["6e010c30.5c0164"]]},{"id":"5a7ae1af.ce926","type":"link out","z":"cb334c13.148f2","name":"","links":["e23e5a60.b30658","7757fd9.30fd604","6bf13325.d4c26c"],"x":1257,"y":77,"wires":[]},{"id":"a00cbc12.518d4","type":"function","z":"cb334c13.148f2","name":"parseNetwork","func":"\nvar index = msg.output.indexOf(' ');\nvar network = msg.output.substring(index,msg.output.length);\nnetwork = network.split(',');\n\nvar locationInfo = flow.get('locationInfo') || {};\n\n\nvar n = parseInt(network[0]);\n\nif(n === 0 || n == 1){\n    msg.topic = \"get\";\n}\nelse if(n == 2){\n    msg.topic =\"set\";\n    msg.payload = {};\n    var stat = parseInt(network[1]);\n    switch(stat){\n        case 0: stat = \"Not registered\";\n            break;\n        case 1: stat = \"Registered - Home network\";\n            break;\n        case 2: stat = \"Searching...\";\n            break;\n        case 3: stat = \"Registration denied\";\n            break;\n        case 4: stat = \"Unknown\";\n            break;\n        case 5: stat = \"Registered - Roaming\";\n            break;\n    }\n    \n    msg.payload.status = stat;\n    \n    if(n == 2){\n        var lac = parseInt(network[2].trim().slice(1 , -1),16);\n        var cellID = parseInt(network[3].trim().slice(1 , -1),16);\n        if(lac)\n            locationInfo.lac= lac;\n        if(cellID)\n            locationInfo.cellID = cellID;\n    }\n    \n}\n\nflow.set('locationInfo', locationInfo);\n\n\nreturn msg;","outputs":1,"noerr":0,"x":985,"y":184,"wires":[["a7819f9.8c8096"]]},{"id":"e0cafb4c.937d68","type":"ui_text","z":"cb334c13.148f2","group":"dee76989.5e3358","order":10,"width":0,"height":0,"name":"","label":"Network Status","format":"{{msg.payload.status}}","layout":"row-spread","x":1320,"y":204,"wires":[]},{"id":"a7819f9.8c8096","type":"switch","z":"cb334c13.148f2","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"get","vt":"str"},{"t":"eq","v":"set","vt":"str"}],"checkall":"true","outputs":2,"x":1141,"y":184,"wires":[["42356833.7f0838"],["e0cafb4c.937d68"]]},{"id":"42356833.7f0838","type":"link out","z":"cb334c13.148f2","name":"","links":["c589cb7e.733828","e1e8c2b6.dbabf","d28a6e8a.82986"],"x":1257,"y":156,"wires":[]},{"id":"93b0f61.92f4308","type":"link out","z":"cb334c13.148f2","name":"switchOperatorFormat","links":["de455ec6.11c1c","f368f253.128ea","cd361816.e3aa78"],"x":1159,"y":234,"wires":[]},{"id":"ba569226.796e9","type":"delay","z":"cb334c13.148f2","name":"wait","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":444,"y":576,"wires":[["ef2723d9.c445a","5c4b90e4.399b2","939ed13d.5e199","bcaf61fd.ad0e5","a0815e78.1d95f","6468fa6e.b3bda4","ea68dfcb.06011","a92e8752.c9c3e8"]]},{"id":"7535d184.cc2c9","type":"inject","z":"cb334c13.148f2","name":"getLocationInfo","topic":"","payload":"locationInfo","payloadType":"flow","repeat":"","crontab":"","once":false,"x":522,"y":104,"wires":[["f78b1188.28228"]]},{"id":"f78b1188.28228","type":"debug","z":"cb334c13.148f2","name":"","active":true,"console":"false","complete":"false","x":712,"y":104,"wires":[]},{"id":"a9b577dd.6e25f8","type":"switch","z":"cb334c13.148f2","name":"","property":"ok","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","outputs":2,"x":618,"y":237,"wires":[["c20b4215.70588"],["8c992bd0.ddbd58"]]},{"id":"8c992bd0.ddbd58","type":"ui_template","z":"cb334c13.148f2","group":"bead796f.4719c8","name":"errors","order":2,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":610,"y":337,"wires":[["10a7a9d9.c39e26"]]},{"id":"10a7a9d9.c39e26","type":"debug","z":"cb334c13.148f2","name":"err","active":false,"console":"false","complete":"payload","x":754,"y":337,"wires":[]},{"id":"a4e9d9bc.e63ef8","type":"comment","z":"cb334c13.148f2","name":"Readme - FIBOCOM G510 Dashboard","info":"## General\n\nThis Flow allows users to retrive informations from their\n**G510 GSM/GPRS** Module like: signal strength, Operator name, \nMCC MNC CellID and LAC (for **localization** purposes), IMEI code\naND other manifacturer specific codes.\n\n`node-red-node-serialport` is used to send *AT comands* to the\n`ttyAMA0` interface and read the output response from the module.\nMore info about AT commands input/output formats can be found\nin *AT COMMANDS* function node.\n\nLocation info codes are stored in a flow variabile named\n`locationInfo`. You can find a trigger node that can be used\nto send the current location object in the debug console.\n\n## Usage\n\n```\nvar location = flow.get('locationInfo');\n```\n\nIn a function node to retrive the current location everywhere in this flow\n\n## License\n\nMIT License\n\nCopyright (c) 2017 Daniel Lando\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","x":183,"y":34,"wires":[]},{"id":"67489962.e778c8","type":"function","z":"cb334c13.148f2","name":"enableNetwork","func":"msg.payload = flow.get(\"at_commands\").enableNetwork;\n\nreturn msg;","outputs":1,"noerr":0,"x":228,"y":328,"wires":[["4788ed8f.8ab664"]]},{"id":"eafe433b.2f038","type":"function","z":"cb334c13.148f2","name":"enableGPRS","func":"msg.payload = flow.get(\"at_commands\").enableGPRS;\n\nreturn msg;","outputs":1,"noerr":0,"x":225,"y":375,"wires":[["4788ed8f.8ab664"]]},{"id":"e1e8c2b6.dbabf","type":"link in","z":"cb334c13.148f2","name":"enableNetwork","links":["42356833.7f0838"],"x":63,"y":328,"wires":[["67489962.e778c8"]]},{"id":"7757fd9.30fd604","type":"link in","z":"cb334c13.148f2","name":"enableGPRS","links":["5a7ae1af.ce926"],"x":62,"y":375,"wires":[["eafe433b.2f038"]]},{"id":"e0bf7a70.19cc18","type":"function","z":"cb334c13.148f2","name":"switchOperatorFormat","func":"var numeric = flow.get(\"numericOperator\");\n\nmsg.payload = numeric ? flow.get(\"at_commands\").setStringOperator : flow.get(\"at_commands\").setNumericOperator;\n\nreturn msg;","outputs":1,"noerr":0,"x":255,"y":423,"wires":[["4788ed8f.8ab664"]]},{"id":"f368f253.128ea","type":"link in","z":"cb334c13.148f2","name":"setOperatorFormat","links":["93b0f61.92f4308"],"x":62,"y":423,"wires":[["e0bf7a70.19cc18"]]},{"id":"4788ed8f.8ab664","type":"link out","z":"cb334c13.148f2","name":"writeSerial","links":["3004ad23.99e3e2"],"x":453,"y":367,"wires":[]},{"id":"455573ea.0d22ac","type":"status","z":"cb334c13.148f2","name":"serialStatus","scope":["c2932b4e.8c0338"],"x":119.99999237060547,"y":501.1110773086548,"wires":[["d32aabb2.e6d988"]]},{"id":"d32aabb2.e6d988","type":"function","z":"cb334c13.148f2","name":"","func":"msg.payload = msg.status.text.indexOf('connected') >= 0;\nreturn msg;","outputs":1,"noerr":0,"x":272.5555419921875,"y":501.77777099609375,"wires":[["ec7f84bf.45dcb8"]]},{"id":"ec7f84bf.45dcb8","type":"ui_switch","z":"cb334c13.148f2","name":"status","label":"Serial Connection","group":"bead796f.4719c8","order":1,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"done","oncolor":"#4CAF50","offvalue":"false","offvalueType":"bool","officon":"close","offcolor":"#f44336","x":409.9999694824219,"y":501.5555419921875,"wires":[[]]},{"id":"ae0328ec.beffc8","type":"ui_button","z":"cb334c13.148f2","name":"update","group":"dee76989.5e3358","order":0,"width":0,"height":0,"passthru":false,"label":"UPDATE","color":"","bgcolor":"","icon":"","payload":"at_commands","payloadType":"flow","topic":"","x":147.50000381469727,"y":640.0000095367432,"wires":[["7355b30.3e7da4c"]]},{"id":"7355b30.3e7da4c","type":"delay","z":"cb334c13.148f2","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":298.75000381469727,"y":640.0000095367432,"wires":[["ba569226.796e9"]]},{"id":"d0261c99.c3a95","type":"inject","z":"cb334c13.148f2","name":"Read Cell Info","topic":"","payload":"locationInfo","payloadType":"flow","repeat":"120","crontab":"","once":true,"x":146.9999771118164,"y":826.4444179534912,"wires":[["648cd107.63caf"]]},{"id":"648cd107.63caf","type":"function","z":"cb334c13.148f2","name":"geolocationAPIs","func":"var OCID_APIKEY = \"<OpenCellID-API-KEY>\";\nvar GOOGLE_APIKEY = \"<GoogleAPIKey>\";\n\nvar lastCellID = flow.get(\"lastCellID\");\n\nif(msg.payload && Object.keys(msg.payload).length == 4 && (!lastCellID || lastCellID != msg.payload.cellID)){\n    \n    msg.cellID = msg.payload.cellID;\n    \n    var url = \"https://eu1.unwiredlabs.com/v2/process.php\";\n    \n     //prepare google packet in case opencellID geolocation fails\n    var data = {};\n    \n    data.url = \"https://www.googleapis.com/geolocation/v1/geolocate?key=\"+GOOGLE_APIKEY;\n    \n    data.payload = {\n      \"cellTowers\": [\n        {\n          \"cellId\": msg.payload.cellID,\n          \"locationAreaCode\": msg.payload.lac,\n          \"mobileCountryCode\": msg.payload.mcc,\n          \"mobileNetworkCode\": msg.payload.mnc\n        }\n      ]\n    };\n    \n    flow.set(\"cellData\", data);\n    \n    //prepare payload for request Opencellid\n    \n    msg.payload = {\n        \"token\": OCID_APIKEY,\n        \"radio\": \"gsm\",\n        \"mcc\":  msg.payload.mcc,\n        \"mnc\": msg.payload.mnc,\n        \"cells\": [{\n            \"lac\": msg.payload.lac,\n            \"cid\": msg.payload.cellID\n        }]\n        \n    };\n        \n    msg.url = url;\n    \n}\nelse\n    msg = null;\n\nreturn msg;","outputs":"1","noerr":0,"x":379.2300796508789,"y":827.182505607605,"wires":[["4af27b18.0af684"]]},{"id":"4af27b18.0af684","type":"http request","z":"cb334c13.148f2","name":"","method":"POST","ret":"obj","url":"","tls":"","x":581.388858795166,"y":826.7062864303589,"wires":[["49204c4e.e7d234"]]},{"id":"49204c4e.e7d234","type":"function","z":"cb334c13.148f2","name":"checkErrorO","func":"var msg2 = null;\n\nif(msg.payload && !isNaN(msg.payload.lat) && !isNaN(msg.payload.lon)){\n    var data = {\n        \"lat\" : msg.payload.lat,\n        \"lon\" : msg.payload.lon,\n        \"range\" : msg.payload.accuracy\n    };\n    \n    flow.set(\"lastCellID\", msg.cellID);\n    \n    msg.payload = data;\n}\nelse{\n    msg2 = flow.get(\"cellData\");\n    node.error(msg.payload);\n    msg = null;\n}\n\n\nreturn [msg, msg2];","outputs":"2","noerr":0,"x":758.388858795166,"y":826.7062864303589,"wires":[["11cdcbeb.4e9414"],["d325d74.a56df28"]]},{"id":"11cdcbeb.4e9414","type":"function","z":"cb334c13.148f2","name":"checkNew","func":"var lastLocation = flow.get(\"lastLocation\");\nvar location = msg.payload;\n\nif(!lastLocation || (lastLocation.lon != location.lon && lastLocation.lat != location.lat))\n    flow.set(\"lastLocation\", location);\nelse\n    msg = null;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":1237.1030960083008,"y":817.7062425613403,"wires":[["9320f3.42871f1"]]},{"id":"d325d74.a56df28","type":"http request","z":"cb334c13.148f2","name":"","method":"POST","ret":"obj","url":"","tls":"","x":904.8888664245605,"y":902.2776975631714,"wires":[["1c54667a.3181fa"]]},{"id":"1c54667a.3181fa","type":"function","z":"cb334c13.148f2","name":"checkErrorG","func":"\nif(msg.payload.location && !isNaN(msg.payload.location.lat) && !isNaN(msg.payload.location.lng)){\n    var data = {\n        \"lat\" : msg.payload.location.lat,\n        \"lon\" : msg.payload.location.lng,\n        \"range\" : msg.payload.accuracy\n    };\n    \n    msg.payload = data;\n    flow.set(\"lastCellID\", msg.cellID);\n}\nelse msg = null\n\n\nreturn msg;","outputs":"1","noerr":0,"x":1070.8888664245605,"y":902.2776975631714,"wires":[["11cdcbeb.4e9414"]]},{"id":"294ab63.3d20c4a","type":"inject","z":"cb334c13.148f2","name":"reset last location","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":148.53966522216797,"y":923.8810386657715,"wires":[["e18cd410.2c4f38"]]},{"id":"e18cd410.2c4f38","type":"function","z":"cb334c13.148f2","name":"","func":"flow.set(\"lastLocation\", null);\nflow.set(\"lastCellID\", null)","outputs":"0","noerr":0,"x":356.11111668178023,"y":923.8810349873133,"wires":[]},{"id":"c1589d68.3c68e","type":"inject","z":"cb334c13.148f2","name":"getLastLocation","topic":"","payload":"lastLocation","payloadType":"flow","repeat":"","crontab":"","once":false,"x":150.11107853480758,"y":975.4998427799769,"wires":[["344e5449.2d34cc"]]},{"id":"344e5449.2d34cc","type":"debug","z":"cb334c13.148f2","name":"","active":true,"console":"false","complete":"false","x":358.11107853480746,"y":975.4998427799765,"wires":[]},{"id":"bbfb9087.2e3cb","type":"inject","z":"cb334c13.148f2","name":"getCellData","topic":"","payload":"cellData","payloadType":"flow","repeat":"","crontab":"","once":false,"x":592.1110785348076,"y":973.4998427799769,"wires":[["e760b141.7f776"]]},{"id":"e760b141.7f776","type":"debug","z":"cb334c13.148f2","name":"","active":true,"console":"false","complete":"false","x":810.1110785348075,"y":973.4998427799765,"wires":[]},{"id":"e494816.1f22e8","type":"comment","z":"cb334c13.148f2","name":"Get location from Modem Data","info":"","x":170.49995803833008,"y":755.0554523468018,"wires":[]},{"id":"9320f3.42871f1","type":"debug","z":"cb334c13.148f2","name":"","active":true,"console":"false","complete":"false","x":1420,"y":818,"wires":[]},{"id":"741b4068.5a76a","type":"serial-port","z":"","serialport":"/dev/ttyAMA0","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false},{"id":"dee76989.5e3358","type":"ui_group","z":"","name":"Info","tab":"e5fe4de3.d04e9","disp":true,"width":"6"},{"id":"bead796f.4719c8","type":"ui_group","z":"","name":"Errors","tab":"e5fe4de3.d04e9","disp":true,"width":"6"},{"id":"e5fe4de3.d04e9","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
robertsLando

Flow Info

created 3 weeks ago

Node Types

Core
  • comment (x2)
  • debug (x5)
  • delay (x3)
  • function (x29)
  • http request (x2)
  • inject (x7)
  • range (x1)
  • serial in (x1)
  • serial out (x1)
  • serial-port (x1)
  • switch (x4)
Other
  • join (x1)
  • link in (x4)
  • link out (x5)
  • status (x1)
  • tab (x1)
  • ui_button (x1)
  • ui_gauge (x1)
  • ui_group (x2)
  • ui_switch (x1)
  • ui_tab (x1)
  • ui_template (x1)
  • ui_text (x7)

Tags

  • localization
  • at-commands
  • at
  • commands
  • fibocom
  • g510
  • neuron
  • unipi
  • roberts_lando
  • S-103G
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option