","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":750,"y":440,"wires":[[]]},{"id":"1232549f946e27e2","type":"ui_template","z":"72e629e582bb7399","group":"83dfbdc5d81da0f4","name":"codigo de erro","order":10,"width":12,"height":2,"format":"
{{msg.payload.FRZ[0]}}
\n
{{msg.payload.FRZ[1]}}
","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":340,"y":680,"wires":[[]]},{"id":"42329a9d43d4d88d","type":"ui_text","z":"72e629e582bb7399","group":"83dfbdc5d81da0f4","order":9,"width":0,"height":0,"name":"","label":"Código de Erro","format":"{{msg.payload}}","layout":"row-spread","className":"","x":340,"y":640,"wires":[]},{"id":"7667e8eb31082b17","type":"ui_button","z":"72e629e582bb7399","name":"detalhes","group":"83dfbdc5d81da0f4","order":11,"width":0,"height":0,"passthru":false,"label":"Ver Detalhes","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"Detalhes","payloadType":"str","topic":"topic","topicType":"msg","x":320,"y":720,"wires":[["399b64db4aa110df"]]},{"id":"ffbaf10fc78f5835","type":"ui_artlessgauge","z":"72e629e582bb7399","group":"83dfbdc5d81da0f4","order":2,"width":0,"height":0,"name":"RPM","icon":"","label":"RPM","unit":"","layout":"linear","decimals":"2","differential":false,"minmax":false,"colorTrack":"#555555","style":"","colorFromTheme":true,"property":"payload.RPM","secondary":"secondary","inline":false,"animate":true,"sectors":[{"val":0,"col":"#0055ff","t":"min","dot":0},{"val":500,"col":"#66ff69","t":"sec","dot":0},{"val":3000,"col":"#fbff00","t":"sec","dot":0},{"val":5000,"col":"#ff9500","t":"sec","dot":0},{"val":8000,"col":"#ff0000","t":"sec","dot":0},{"val":9000,"col":"#ff0000","t":"max","dot":0}],"lineWidth":3,"bgcolorFromTheme":true,"diffCenter":"","x":310,"y":100,"wires":[]},{"id":"161b383572c5d0f5","type":"ui_artlessgauge","z":"72e629e582bb7399","group":"83dfbdc5d81da0f4","order":3,"width":0,"height":0,"name":"Velocidade","icon":"","label":"Velocidade","unit":"KM/H","layout":"linear","decimals":"2","differential":false,"minmax":false,"colorTrack":"#555555","style":"","colorFromTheme":true,"property":"payload.SPD","secondary":"secondary","inline":false,"animate":true,"sectors":[{"val":0,"col":"#0055ff","t":"min","dot":0},{"val":30,"col":"#009919","t":"sec","dot":0},{"val":50,"col":"#cccc00","t":"sec","dot":0},{"val":80,"col":"#ffa200","t":"sec","dot":0},{"val":130,"col":"#ff0000","t":"sec","dot":0},{"val":255,"col":"#ff0000","t":"max","dot":0}],"lineWidth":3,"bgcolorFromTheme":true,"diffCenter":"","x":330,"y":140,"wires":[]},{"id":"41df52cb719a18cf","type":"ui_artlessgauge","z":"72e629e582bb7399","group":"83dfbdc5d81da0f4","order":4,"width":0,"height":0,"name":"Coolant","icon":"","label":"Temperatura Motor","unit":"°C","layout":"linear","decimals":"2","differential":false,"minmax":false,"colorTrack":"#555555","style":"","colorFromTheme":true,"property":"payload.COL","secondary":"secondary","inline":true,"animate":true,"sectors":[{"val":80,"col":"#1100ff","t":"min","dot":0},{"val":87,"col":"#03cc00","t":"sec","dot":0},{"val":100,"col":"#e1ff00","t":"sec","dot":0},{"val":105,"col":"#ff0000","t":"sec","dot":0},{"val":150,"col":"#ff0000","t":"max","dot":0}],"lineWidth":3,"bgcolorFromTheme":true,"diffCenter":"","x":320,"y":180,"wires":[]},{"id":"399b64db4aa110df","type":"ui_ui_control","z":"72e629e582bb7399","name":"","events":"change","x":480,"y":720,"wires":[[]]},{"id":"588bd75a649d8b02","type":"link in","z":"72e629e582bb7399","name":"freeze frame error","links":["5164c25b0505c4df"],"x":185,"y":680,"wires":[["1232549f946e27e2"]]},{"id":"bbe448e170e4d3e4","type":"link in","z":"72e629e582bb7399","name":"current data","links":["95b2eacab91265c3"],"x":115,"y":100,"wires":[["ffbaf10fc78f5835","161b383572c5d0f5","41df52cb719a18cf","9c066f890345e0c8","58b36c42dd22451d","aea15776539df8cd","b1fa2c0902ccec41"]]},{"id":"67086cb1a048d121","type":"switch","z":"72e629e582bb7399","name":"MIL","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":150,"y":600,"wires":[["9f1dc1deeb346fab"],["506c8de005876a3d"]]},{"id":"9f1dc1deeb346fab","type":"change","z":"72e629e582bb7399","name":"MIL on","rules":[{"t":"set","p":"mil_alert","pt":"msg","to":"orange","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":560,"wires":[["497278fd7c775bce"]]},{"id":"506c8de005876a3d","type":"change","z":"72e629e582bb7399","name":"MIL off","rules":[{"t":"set","p":"mil_alert","pt":"msg","to":"black","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":600,"wires":[["497278fd7c775bce"]]},{"id":"ed3765da020faa88","type":"link in","z":"72e629e582bb7399","name":"engine error ","links":["290a2f511e1b4811"],"x":105,"y":560,"wires":[["67086cb1a048d121"]]},{"id":"9c066f890345e0c8","type":"switch","z":"72e629e582bb7399","name":"rpm alert","property":"payload.RPM","propertyType":"msg","rules":[{"t":"gt","v":"rpm_threshold","vt":"global"},{"t":"lte","v":"rpm_threshold","vt":"global"}],"checkall":"true","repair":false,"outputs":2,"x":320,"y":260,"wires":[["324f14276ea2a235"],["1b2fc0e360f9c8cd"]]},{"id":"324f14276ea2a235","type":"change","z":"72e629e582bb7399","name":"rpm above max","rules":[{"t":"set","p":"rpm_alert","pt":"msg","to":"orange","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":240,"wires":[["fdfcaa1ef0bb4427"]]},{"id":"1b2fc0e360f9c8cd","type":"change","z":"72e629e582bb7399","name":"rpm ok","rules":[{"t":"set","p":"rpm_alert","pt":"msg","to":"black","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":280,"wires":[["fdfcaa1ef0bb4427"]]},{"id":"58b36c42dd22451d","type":"switch","z":"72e629e582bb7399","name":"coolant alert","property":"payload.COL","propertyType":"msg","rules":[{"t":"gt","v":"coolant_threshold","vt":"global"},{"t":"lte","v":"coolant_threshold","vt":"global"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":360,"wires":[["d81ea16881c8221d"],["b66b727061c4344f"]]},{"id":"b66b727061c4344f","type":"change","z":"72e629e582bb7399","name":"coolant ok","rules":[{"t":"set","p":"col_alert","pt":"msg","to":"black","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":380,"wires":[["381683d94cf54d05"]]},{"id":"d81ea16881c8221d","type":"change","z":"72e629e582bb7399","name":"coolant above max","rules":[{"t":"set","p":"col_alert","pt":"msg","to":"orange","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":340,"wires":[["381683d94cf54d05"]]},{"id":"aea15776539df8cd","type":"switch","z":"72e629e582bb7399","name":"speed alert","property":"payload.SPD","propertyType":"msg","rules":[{"t":"gt","v":"spd_threshold","vt":"global"},{"t":"lte","v":"spd_threshold","vt":"global"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":460,"wires":[["648edd80ec4609e5"],["453180198fe4b092"]]},{"id":"648edd80ec4609e5","type":"change","z":"72e629e582bb7399","name":"speed above max","rules":[{"t":"set","p":"spd_alert","pt":"msg","to":"orange","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":440,"wires":[["1369f66da95c140c"]]},{"id":"453180198fe4b092","type":"change","z":"72e629e582bb7399","name":"speed ok","rules":[{"t":"set","p":"spd_alert","pt":"msg","to":"black","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":480,"wires":[["1369f66da95c140c"]]},{"id":"3f60c185f0f316f1","type":"ui_text","z":"72e629e582bb7399","group":"83dfbdc5d81da0f4","order":1,"width":0,"height":0,"name":"timestamp","label":"Últimos dados:","format":"{{msg.payload.timestamp}}","layout":"row-spread","className":"","x":330,"y":60,"wires":[]},{"id":"b1fa2c0902ccec41","type":"function","z":"72e629e582bb7399","name":"Convert timestamp","func":"msg.payload.timestamp = new Date(msg.payload.timestamp* 1000);\nlet ts = msg.payload.timestamp.toLocaleString();\nmsg.payload.timestamp = ts;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":150,"y":60,"wires":[["3f60c185f0f316f1"]]},{"id":"8218571184381fe1","type":"tab","label":"car logic","disabled":false,"info":"","env":[]},{"id":"1d0479f6bc979bb1","type":"mqtt in","z":"8218571184381fe1","name":"","topic":"python/obdata","qos":"2","datatype":"auto","broker":"6992075b538d96f8","nl":true,"rap":true,"rh":0,"inputs":0,"x":150,"y":120,"wires":[["1a33aae22e09835e"]]},{"id":"1a33aae22e09835e","type":"json","z":"8218571184381fe1","name":"format rx message","property":"payload","action":"obj","pretty":false,"x":370,"y":120,"wires":[["274778b25ca84f0b","10e36d154fbc92ee","fa93d4231885566d","95b2eacab91265c3","28a1532308b7437e"]]},{"id":"e817ca7d0a68a820","type":"inject","z":"8218571184381fe1","name":"fail","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"timestamp\":1668370055,\"RPM\":3100,\"SPD\":140,\"PDL\":16.6666,\"INT\":20.0656,\"COL\":110,\"TRB\":true,\"ERR\":{\"LST\":[[\"P0104\",\"Mass or Volume Air Flow Circuit Intermittent\"],[\"B0003\",\"\"],[\"C0123\",\"\"]],\"FRZ\":[\"P0104\",\"Mass or Volume Air Flow Circuit Intermittent\"],\"RPM\":700,\"SPD\":0,\"PDL\":12.3333333,\"INT\":70,\"COL\":100}}","payloadType":"json","x":150,"y":160,"wires":[["1a33aae22e09835e"]]},{"id":"274778b25ca84f0b","type":"change","z":"8218571184381fe1","name":"engine light check","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.TRB","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":400,"wires":[["e30fdc6b1627c8cc"]]},{"id":"3e4833bd97a2ddf9","type":"file","z":"8218571184381fe1","name":"save file","filename":"arquivo-carro.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":940,"y":120,"wires":[[]]},{"id":"4ff3240a4383860e","type":"inject","z":"8218571184381fe1","name":"good","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"timestamp\":1665607045,\"RPM\":807.25,\"SPD\":2,\"PDL\":13.72549019607843,\"INT\":48,\"COL\":97,\"TRB\":false,\"ERR\":null}","payloadType":"json","x":150,"y":200,"wires":[["1a33aae22e09835e"]]},{"id":"2c39208b4dfade7f","type":"file in","z":"8218571184381fe1","name":"read prev. car data","filename":"arquivo-carro.txt","format":"lines","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":390,"y":860,"wires":[["1243ed31402252ce"]]},{"id":"1de8634d5a1db0f0","type":"json","z":"8218571184381fe1","name":"read json from file","property":"payload","action":"obj","pretty":false,"x":390,"y":940,"wires":[["11045786c2726e7f"]]},{"id":"10e36d154fbc92ee","type":"json","z":"8218571184381fe1","name":"prep to save","property":"payload","action":"str","pretty":false,"x":790,"y":120,"wires":[["3e4833bd97a2ddf9"]]},{"id":"1243ed31402252ce","type":"switch","z":"8218571184381fe1","name":"not empty check","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":380,"y":900,"wires":[["1de8634d5a1db0f0"]]},{"id":"1092d949ee4050d6","type":"join","z":"8218571184381fe1","name":"join parts","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":600,"y":940,"wires":[["4e719f79721d1d9c"]]},{"id":"2f9b359d2edbfa9d","type":"change","z":"8218571184381fe1","name":"load error values","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ERR","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":320,"wires":[["47581b3b6d664858","5164c25b0505c4df"]]},{"id":"fa93d4231885566d","type":"switch","z":"8218571184381fe1","name":"car has error?","property":"payload.ERR","propertyType":"msg","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":800,"y":320,"wires":[["2f9b359d2edbfa9d"],["02a6382425d23121"]]},{"id":"02a6382425d23121","type":"change","z":"8218571184381fe1","name":"clear error values","rules":[{"t":"set","p":"payload.ERR","pt":"msg","to":"{\"LST\":null,\"FRZ\":null,\"RPM\":null,\"SPD\":null,\"PDL\":null,\"INT\":null,\"COL\":null}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":360,"wires":[["2f9b359d2edbfa9d"]]},{"id":"47581b3b6d664858","type":"change","z":"8218571184381fe1","name":"get error code list","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.LST","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":360,"wires":[["38f0ccdac745359e"]]},{"id":"38f0ccdac745359e","type":"function","z":"8218571184381fe1","name":"order error codes to table","func":"if (msg.payload != null){\n var tmp = msg.payload;\n msg.payload = [];\n for (i = 0; i < tmp.length; i++)\n {\n msg.payload[i] = {\n \"CODE\" : tmp[i][0],\n \"DESC\" : tmp[i][1]\n };\n }\n}\nelse\n{\n msg.payload = [{\"CODE\":null,\"DESC\":null}];\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1270,"y":360,"wires":[["107e18e2f30352fe"]]},{"id":"647cdc791eedecf9","type":"switch","z":"8218571184381fe1","name":"clear file request","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Sim","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":380,"y":700,"wires":[["26151946b7fc1074"]]},{"id":"4fa12a21fdcba3c7","type":"file","z":"8218571184381fe1","name":"delete","filename":"arquivo-carro.txt","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":350,"y":620,"wires":[["ea9894f622a06121"]]},{"id":"26151946b7fc1074","type":"change","z":"8218571184381fe1","name":"clear file","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":660,"wires":[["4fa12a21fdcba3c7"]]},{"id":"a7b709f91159494d","type":"inject","z":"8218571184381fe1","name":"startup","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":860,"wires":[["2c39208b4dfade7f"]]},{"id":"ea9894f622a06121","type":"function","z":"8218571184381fe1","name":"reset values","func":"msg.payload = [\n {\n \"RPM\" : null,\n \"SPD\" : null,\n \"PDL\" : null,\n \"INT\" : null,\n \"COL\" : null,\n \"TRB\" : null,\n \"ERR\" : null\n }\n ];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":580,"wires":[["fa93d4231885566d","4e719f79721d1d9c","95b2eacab91265c3"]]},{"id":"e30fdc6b1627c8cc","type":"switch","z":"8218571184381fe1","name":"engine light turned on?","property":"payload","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":1020,"y":400,"wires":[["1627e07b5c12e95c"],["290a2f511e1b4811"]]},{"id":"1627e07b5c12e95c","type":"change","z":"8218571184381fe1","name":"engine light turned off","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":400,"wires":[["290a2f511e1b4811"]]},{"id":"c8778fc95a5f3a55","type":"watch","z":"8218571184381fe1","name":"watch prev. car data","files":"arquivo-carro.txt","recursive":"","x":390,"y":820,"wires":[["2c39208b4dfade7f"]]},{"id":"28a1532308b7437e","type":"debug","z":"8218571184381fe1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":80,"wires":[]},{"id":"5164c25b0505c4df","type":"link out","z":"8218571184381fe1","name":"formatted freeze frame data","mode":"link","links":["7ded16e4c8781f69","588bd75a649d8b02","78176010f4c32e32"],"x":1195,"y":320,"wires":[]},{"id":"107e18e2f30352fe","type":"link out","z":"8218571184381fe1","name":"formatted car error msg","mode":"link","links":["abc242fa2d577bec"],"x":1415,"y":360,"wires":[]},{"id":"290a2f511e1b4811","type":"link out","z":"8218571184381fe1","name":"engine light check","mode":"link","links":["4d0417acb90a1287","ed3765da020faa88"],"x":1175,"y":460,"wires":[]},{"id":"4e719f79721d1d9c","type":"link out","z":"8218571184381fe1","name":"car table prep","mode":"link","links":["6afd0641f0b1bd76"],"x":715,"y":940,"wires":[]},{"id":"cc60f3d0d8d4725c","type":"link in","z":"8218571184381fe1","name":"request clear file","links":["77199d94f4abf95d"],"x":225,"y":660,"wires":[["647cdc791eedecf9"]]},{"id":"95b2eacab91265c3","type":"link out","z":"8218571184381fe1","name":"car values","mode":"link","links":["35482836fa6bbe10","bbe448e170e4d3e4"],"x":735,"y":280,"wires":[]},{"id":"866d8bfacaea6f0c","type":"file in","z":"8218571184381fe1","name":"cfg file","filename":"config_car.cfg","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":930,"y":620,"wires":[["0c08b74485670f0a"]]},{"id":"3c493bbbc2f674b9","type":"json","z":"8218571184381fe1","name":"","property":"payload","action":"obj","pretty":false,"x":1090,"y":620,"wires":[["af4d7b6b1e62b7c3"]]},{"id":"af4d7b6b1e62b7c3","type":"change","z":"8218571184381fe1","name":"set config","rules":[{"t":"move","p":"payload.spd_threshold","pt":"msg","to":"spd_threshold","tot":"global"},{"t":"move","p":"payload.coolant_threshold","pt":"msg","to":"coolant_threshold","tot":"global"},{"t":"move","p":"payload.rpm_threshold","pt":"msg","to":"rpm_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":620,"wires":[[]]},{"id":"fa01d7bfb8c43d0f","type":"change","z":"8218571184381fe1","name":"defaults","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"spd_threshold\":130,\"rpm_threshold\":3000,\"coolant_threshold\":105}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":680,"wires":[["af4d7b6b1e62b7c3"]]},{"id":"0c08b74485670f0a","type":"switch","z":"8218571184381fe1","name":"check cfg file","property":"payload","propertyType":"msg","rules":[{"t":"nempty"},{"t":"null"},{"t":"empty"}],"checkall":"true","repair":false,"outputs":3,"x":950,"y":660,"wires":[["3c493bbbc2f674b9"],["fa01d7bfb8c43d0f"],["fa01d7bfb8c43d0f"]]},{"id":"746279b21d92655e","type":"catch","z":"8218571184381fe1","name":"file read fail","scope":["866d8bfacaea6f0c"],"uncaught":false,"x":950,"y":700,"wires":[["fa01d7bfb8c43d0f"]]},{"id":"75e203eb34ed333f","type":"comment","z":"8218571184381fe1","name":"reset_historico()","info":"","x":380,"y":540,"wires":[]},{"id":"6b2ec685f65d401d","type":"comment","z":"8218571184381fe1","name":"carregar_historico()","info":"","x":390,"y":780,"wires":[]},{"id":"c4a1a29f1fc477a9","type":"comment","z":"8218571184381fe1","name":"carregar_configuracao()","info":"","x":980,"y":580,"wires":[]},{"id":"c7865daede096b0e","type":"comment","z":"8218571184381fe1","name":"receber_dados()","info":"","x":160,"y":80,"wires":[]},{"id":"9fca6e1c7a9c667c","type":"comment","z":"8218571184381fe1","name":"buscar_dados()","info":"","x":840,"y":280,"wires":[]},{"id":"01d6817bb1c69276","type":"comment","z":"8218571184381fe1","name":"salvar_configuracao()","info":"","x":980,"y":760,"wires":[]},{"id":"0b79afd0c563bdc5","type":"link in","z":"8218571184381fe1","name":"save request","links":["42e7d064c5fa77c6"],"x":895,"y":800,"wires":[["3ab3b3f91913b672"]]},{"id":"42d632e2748f4037","type":"file","z":"8218571184381fe1","name":"save cfg","filename":"config_car.cfg","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":1100,"y":840,"wires":[[]]},{"id":"3ab3b3f91913b672","type":"function","z":"8218571184381fe1","name":"get global variables","func":"msg.payload = {\n \"spd_threshold\": global.get(\"spd_threshold\"),\n \"rpm_threshold\": global.get(\"rpm_threshold\"),\n \"coolant_threshold\": global.get(\"coolant_threshold\")\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1010,"y":800,"wires":[["8f8d77c24bf121a6"]]},{"id":"8f8d77c24bf121a6","type":"json","z":"8218571184381fe1","name":"","property":"payload","action":"str","pretty":false,"x":970,"y":840,"wires":[["42d632e2748f4037"]]},{"id":"5bdfe88720725589","type":"catch","z":"8218571184381fe1","name":"file write error","scope":["42d632e2748f4037"],"uncaught":false,"x":990,"y":880,"wires":[["8db84e02f7b80bec"]]},{"id":"8db84e02f7b80bec","type":"change","z":"8218571184381fe1","name":"save error","rules":[{"t":"set","p":"payload","pt":"msg","to":"Erro ao salvar configurações!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":880,"wires":[["a0d45aba2b89d406"]]},{"id":"a0d45aba2b89d406","type":"ui_toast","z":"8218571184381fe1","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"UI Notif - FAIL to Save CFG","x":1040,"y":920,"wires":[]},{"id":"11045786c2726e7f","type":"function","z":"8218571184381fe1","name":"timestamp convert","func":"msg.payload.timestamp = new Date(msg.payload.timestamp * 1000);\nlet ts = msg.payload.timestamp.toLocaleString();\nmsg.payload.timestamp = ts;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":900,"wires":[["1092d949ee4050d6"]]},{"id":"136a8c4f343daf25","type":"catch","z":"8218571184381fe1","name":"fail history write","scope":["3e4833bd97a2ddf9"],"uncaught":false,"x":800,"y":160,"wires":[["b318ceec4590a609"]]},{"id":"b318ceec4590a609","type":"change","z":"8218571184381fe1","name":"save file error","rules":[{"t":"set","p":"payload","pt":"msg","to":"Erro ao gravar dados!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":200,"wires":[["3b379f2eabeba6a7"]]},{"id":"3b379f2eabeba6a7","type":"ui_toast","z":"8218571184381fe1","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"UI Notif - Error while saving data","x":1070,"y":160,"wires":[]},{"id":"09708fc6cfab28dd","type":"ui_template","z":"8218571184381fe1","group":"2a745e6b.07df92","name":"Dashboard Theme : Modern Dark","order":2,"width":0,"height":0,"format":"
\n \n \n
","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"global","className":"","x":220,"y":280,"wires":[[]],"icon":"node-red-dashboard/ui_colour_picker.png","info":"# Modern Dark Theme for node-red-dashboard\n\nInspired by Victor Lucachi with his [Node Red Dashboard Concept](https://dribbble.com/shots/10356530-Node-Red-Dashboard-Concept) on Dribbble. Thank you for your work.\n\n## Customize\n\n1. Go on dashboard customisation tab (At the right of Debug Console).\n2. Select the style `Dark`.\n3. Pick the color you want. Example `#66B5F8`\n\n## Buttons\n\nUse `2x2` size for buttons with icon and text on the screenshot"},{"id":"f7537559217ab1d4","type":"ui_template","z":"8218571184381fe1","group":"83dfbdc5d81da0f4","name":"car style status","order":12,"width":0,"height":0,"format":"","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"global","className":"","x":160,"y":240,"wires":[[]]},{"id":"6f8787c644bd95e5","type":"inject","z":"8218571184381fe1","name":"startup","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":800,"y":620,"wires":[["866d8bfacaea6f0c"]]},{"id":"8979f63c92c22d1a","type":"comment","z":"8218571184381fe1","name":"salvar_dados()","info":"","x":800,"y":80,"wires":[]},{"id":"d66e6816e4a992f5","type":"tab","label":"configure car threshold","disabled":false,"info":"","env":[]},{"id":"b1bd4c7be6b97692","type":"ui_slider","z":"d66e6816e4a992f5","name":"","label":"Aviso de Excesso de Rotação - RPM","tooltip":"","group":"09e0956ae89c1ddc","order":1,"width":0,"height":0,"passthru":false,"outs":"end","topic":"topic","topicType":"msg","min":0,"max":"12000","step":"250","className":"","x":950,"y":340,"wires":[["f6f47d2b7dfe0f8d"]]},{"id":"9ab649b674050e22","type":"ui_slider","z":"d66e6816e4a992f5","name":"","label":"Aviso de Excesso de Temperatura (°C)","tooltip":"","group":"09e0956ae89c1ddc","order":2,"width":0,"height":0,"passthru":false,"outs":"end","topic":"topic","topicType":"msg","min":0,"max":"200","step":"5","className":"","x":970,"y":380,"wires":[["74d06077350fe130"]]},{"id":"f542bd851549d63e","type":"ui_slider","z":"d66e6816e4a992f5","name":"","label":"Aviso de Excesso de Velocidade (KM/H)","tooltip":"","group":"09e0956ae89c1ddc","order":3,"width":0,"height":0,"passthru":false,"outs":"end","topic":"topic","topicType":"msg","min":0,"max":"400","step":"5","className":"","x":960,"y":420,"wires":[["559e14631cb2b113"]]},{"id":"09b8c60f3110cc66","type":"link in","z":"d66e6816e4a992f5","name":"read config data","links":["fd8d3aad0e17029c"],"x":455,"y":380,"wires":[["5082556d93933a79","9b82ee3bb975e870","18ac7205f74de7a5"]]},{"id":"18ac7205f74de7a5","type":"change","z":"d66e6816e4a992f5","name":"spd_threshold","rules":[{"t":"set","p":"payload","pt":"msg","to":"spd_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":420,"wires":[["f542bd851549d63e"]]},{"id":"9b82ee3bb975e870","type":"change","z":"d66e6816e4a992f5","name":"coolant_threshold","rules":[{"t":"set","p":"payload","pt":"msg","to":"coolant_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":380,"wires":[["9ab649b674050e22"]]},{"id":"5082556d93933a79","type":"change","z":"d66e6816e4a992f5","name":"rpm_threshold","rules":[{"t":"set","p":"payload","pt":"msg","to":"rpm_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":340,"wires":[["b1bd4c7be6b97692"]]},{"id":"f6f47d2b7dfe0f8d","type":"change","z":"d66e6816e4a992f5","name":"change rpm_threshold","rules":[{"t":"move","p":"payload","pt":"msg","to":"rpm_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":500,"wires":[["f56837c8a9e1c2c9"]]},{"id":"74d06077350fe130","type":"change","z":"d66e6816e4a992f5","name":"change coolant_threshold","rules":[{"t":"move","p":"payload","pt":"msg","to":"coolant_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":540,"wires":[["e7d25f97688e3422"]]},{"id":"559e14631cb2b113","type":"change","z":"d66e6816e4a992f5","name":"change spd_threshold","rules":[{"t":"move","p":"payload","pt":"msg","to":"spd_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":580,"wires":[["93245b39dcc70a26"]]},{"id":"f56837c8a9e1c2c9","type":"change","z":"d66e6816e4a992f5","name":"UI Message - RPM Settings Change","rules":[{"t":"set","p":"payload","pt":"msg","to":"Limite de RPM alterado.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":500,"wires":[["a7fbd19f5e684c8c","42e7d064c5fa77c6"]]},{"id":"e7d25f97688e3422","type":"change","z":"d66e6816e4a992f5","name":"UI Message - Coolant Settings Change","rules":[{"t":"set","p":"payload","pt":"msg","to":"Limite de Temperatura Alterado.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":540,"wires":[["a7fbd19f5e684c8c","42e7d064c5fa77c6"]]},{"id":"93245b39dcc70a26","type":"change","z":"d66e6816e4a992f5","name":"UI Message - Speed Settings Change","rules":[{"t":"set","p":"payload","pt":"msg","to":"Limite de Velocidade Alterado.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":580,"wires":[["a7fbd19f5e684c8c","42e7d064c5fa77c6"]]},{"id":"a7fbd19f5e684c8c","type":"ui_toast","z":"d66e6816e4a992f5","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"UI Notifications - Settings","x":1490,"y":280,"wires":[]},{"id":"42e7d064c5fa77c6","type":"link out","z":"d66e6816e4a992f5","name":"save new settings","mode":"link","links":["0b79afd0c563bdc5"],"x":1325,"y":540,"wires":[]},{"id":"6cedaaca1d91f3f9","type":"ui_button","z":"d66e6816e4a992f5","name":"voltar","group":"09e0956ae89c1ddc","order":4,"width":0,"height":0,"passthru":false,"label":"Voltar","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"Detalhes","payloadType":"str","topic":"topic","topicType":"msg","x":590,"y":620,"wires":[["e6f771c5c0f5c4ff"]]},{"id":"e6f771c5c0f5c4ff","type":"ui_ui_control","z":"d66e6816e4a992f5","name":"","events":"change","x":760,"y":620,"wires":[[]]},{"id":"9406153a015f1650","type":"ui_button","z":"d66e6816e4a992f5","name":"Reset","group":"09e0956ae89c1ddc","order":5,"width":0,"height":0,"passthru":false,"label":"Reset Configuração","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":490,"y":280,"wires":[["dd1861cfaff3c354"]]},{"id":"dd1861cfaff3c354","type":"change","z":"d66e6816e4a992f5","name":"defaults","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"spd_threshold\":130,\"rpm_threshold\":3000,\"coolant_threshold\":105}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":280,"wires":[["3345270b662c5b02","5082556d93933a79","9b82ee3bb975e870","18ac7205f74de7a5"]]},{"id":"3345270b662c5b02","type":"change","z":"d66e6816e4a992f5","name":"set config","rules":[{"t":"move","p":"payload.spd_threshold","pt":"msg","to":"spd_threshold","tot":"global"},{"t":"move","p":"payload.coolant_threshold","pt":"msg","to":"coolant_threshold","tot":"global"},{"t":"move","p":"payload.rpm_threshold","pt":"msg","to":"rpm_threshold","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":280,"wires":[["42e7d064c5fa77c6","026776b906112346"]]},{"id":"026776b906112346","type":"change","z":"d66e6816e4a992f5","name":"UI Message - Reset Settings","rules":[{"t":"set","p":"payload","pt":"msg","to":"Configurações Resetadas.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":280,"wires":[["a7fbd19f5e684c8c"]]},{"id":"3c7d50b1062eacd4","type":"ui_group","name":"Status","tab":"5792de6dd51026ca","order":2,"disp":true,"width":8,"collapse":false,"className":""},{"id":"43933c66e4feb46d","type":"ui_group","name":"Check","tab":"5792de6dd51026ca","order":2,"disp":true,"width":8,"collapse":false,"className":""},{"id":"2f6e17de8989bbd7","type":"ui_group","name":"Ações","tab":"5792de6dd51026ca","order":4,"disp":true,"width":"8","collapse":false,"className":""},{"id":"83dfbdc5d81da0f4","type":"ui_group","name":"STATUS","tab":"c69ae39536c7dc05","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"6992075b538d96f8","type":"mqtt-broker","name":"personal","broker":"raszeja.xyz","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"2a745e6b.07df92","type":"ui_group","name":"Default","tab":"e63bce2d.68925","order":5,"disp":true,"width":"6","collapse":true},{"id":"09e0956ae89c1ddc","type":"ui_group","name":"Ações","tab":"a3894c28d2befccb","order":1,"disp":true,"width":12,"collapse":false,"className":""},{"id":"5792de6dd51026ca","type":"ui_tab","name":"Detalhes","icon":"dashboard","order":10,"disabled":false,"hidden":true},{"id":"c69ae39536c7dc05","type":"ui_tab","name":"Menu Carro","icon":"dashboard","order":9,"disabled":false,"hidden":false},{"id":"e63bce2d.68925","type":"ui_tab","name":"Tema","icon":"dashboard","order":4,"disabled":false,"hidden":false},{"id":"a3894c28d2befccb","type":"ui_tab","name":"Configurações","icon":"dashboard","order":11,"disabled":false,"hidden":true}]
\ No newline at end of file
diff --git a/py/python-obd-device.py b/py/python-obd-device.py
new file mode 100644
index 0000000..c5731b8
--- /dev/null
+++ b/py/python-obd-device.py
@@ -0,0 +1,159 @@
+#!/usr/bin/python
+
+import obd
+from obd import OBDStatus
+
+from paho.mqtt import client as mqtt_client
+import json
+import time
+
+class mqtt_handle:
+ def __init__(self, broker, port, topic, client_id, user, password):
+ self.broker = broker
+ self.port = port
+ self.topic = topic
+ self.client_id = client_id
+ self.user = user
+ self.password = password
+
+ def connect(self):
+ def on_connect(client, userdata, flags, rc):
+ if rc == 0:
+ print("Connect OK!")
+ client.subscribe("$SYS/#")
+ else:
+ print(f"Connect fail! RC: {rc}")
+
+ self.client = mqtt_client.Client(self.client_id)
+ self.client.username_pw_set(self.user, self.password)
+ self.client.on_connect = on_connect
+ try:
+ self.client.loop_start()
+ self.client.connect(self.broker, self.port, 60)
+ except:
+ print("Rede tem problemas!")
+
+ def publish(self, data):
+ result = self.client.publish(self.topic, data)
+ status = result[0]
+ if status == 0:
+ print(f"Msg enviada ao topico `{self.topic}`")
+ else:
+ print(f"Falha ao enviar msg no topico `{self.topic}`")
+
+class dados:
+ def __init__(self):
+ self.timestamp = 0
+ self.RPM = 0
+ self.VELOCIDADE = 0.0
+ self.PEDAL_ACELERADOR = 0.0
+ self.TEMPERATURA_INTAKE = 0
+ self.TEMPERATURA_ARREFECIMENTO = 0
+ self.MIL = False
+ self.FREEZE_FRAME = None
+
+ def toJson(self):
+ out = {
+ "timestamp": self.timestamp,
+ "RPM" : self.RPM,
+ "SPD" : self.VELOCIDADE,
+ "PDL" : self.PEDAL_ACELERADOR,
+ "INT" : self.TEMPERATURA_INTAKE,
+ "COL" : self.TEMPERATURA_ARREFECIMENTO,
+ "TRB" : self.MIL,
+ "ERR" : self.FREEZE_FRAME
+ }
+ return json.dumps(out, indent = 4)
+
+class freeze_frame:
+ def __init__(self):
+ self.DTC = None
+ self.LISTA_DTC = None
+ self.RPM = 0
+ self.VELOCIDADE = 0.0
+ self.PEDAL_ACELERADOR = 0.0
+ self.TEMPERATURA_INTAKE = 0.0
+ self.TEMPERATURA_ARREFECIMENTO = 0.0
+
+# Para criar o cliente mqtt:
+# hostname, porta, topico, client_id, usuario, senha
+cliente_mqtt = mqtt_handle("XXXXXX", 1883, "XXXXXX/XXXXXX", "XXXXXX", "XXXXXX", "XXXXXX")
+cliente_mqtt.connect()
+
+#porta OBD
+porta = "XXXXXX"
+con = obd.OBD(porta)
+while True:
+ print(con.status())
+ if con.status() == OBDStatus.CAR_CONNECTED:
+ data = dados()
+ print("Coletando dados...")
+ try:
+ rpm = con.query(obd.commands.RPM)
+ speed = con.query(obd.commands.SPEED)
+ pedal = con.query(obd.commands.THROTTLE_POS)
+ trouble = con.query(obd.commands.STATUS)
+ coolant = con.query(obd.commands.COOLANT_TEMP)
+ intake = con.query(obd.commands.INTAKE_TEMP)
+ except:
+ print("FAIL RECV DATA")
+ con.close()
+ con = obd.OBD(porta)
+ continue
+
+ if not rpm.is_null():
+ dados.RPM = rpm.value.magnitude
+
+ if not speed.is_null():
+ dados.VELOCIDADE = speed.value.magnitude
+
+ if not pedal.is_null():
+ dados.PEDAL_ACELERADOR = pedal.value.magnitude
+
+ if not trouble.is_null():
+ dados.MIL = trouble.value.MIL
+
+ if not coolant.is_null():
+ dados.TEMPERATURA_ARREFECIMENTO = coolant.value.magnitude
+
+ if not intake.is_null():
+ dados.TEMPERATURA_INTAKE = intake.value.magnitude
+
+
+ if dados.MIL == True:
+ frame = freeze_frame()
+ try:
+ errors = con.query(obd.commands.GET_DTC)
+ if not errors.is_null():
+ frame.LISTA_DTC = errors.value
+ errors = con.query(obd.commands.FREEZE_DTC)
+ frame.DTC = errors.value
+ errors = con.query(obd.commands.DTC_RPM)
+ frame.RPM = errors.value.magnitude
+ errors = con.query(obd.commands.DTC_SPEED)
+ frame.VELOCIDADE = errors.value.magnitude
+ errors = con.query(obd.commands.DTC_THROTTLE_POS)
+ frame.PEDAL_ACELERADOR = errors.value.magnitude
+ errors = con.query(obd.commands.DTC_INTAKE_TEMP)
+ frame.TEMPERATURA_INTAKE = errors.value.magnitude
+ errors = con.query(obd.commands.DTC_COOLANT_TEMP)
+ frame.TEMPERATURA_ARREFECIMENTO = errors.value.magnitude
+ dados.FREEZE_FRAME = frame
+ except:
+ print("FAIL RECV DATA")
+ con.close()
+ con = obd.OBD(porta)
+ continue
+
+ dados.timestamp = int(time.time())
+ try:
+ cliente_mqtt.publish(dados.toJson)
+ except:
+ print("FAIL SEND")
+ else:
+ print("FAIL CONNECT CAR")
+ con.close()
+ con = obd.OBD(porta)
+con.close()
+
+