node-red-contrib-nrpokemon
v0.0.2
Published
A simple node that use to view a pokemon property
Downloads
2
Readme
node-red-contrib-NRpokemon
These simple nodes help to have a pokemon in Node-Red!
The node use a https://pokeapi.co/ API. For more documantation https://pokeapi.co/docs/v2.html#info
Install
On the terminal run the following command to install pokemon nodes:
npm install node-red-contrib-NRpokemon
Usage
The node use msg.name and msg.number of the pokemon.
The status rappresent a call to API https://pokeapi.co.
If you receive a message "Cannot find module 'xmlhttprequest'" or "'XMLHttpRequest' is not defined", you must install:
npm install xmlhttprequest
Example
This is a simple pokedex for use a NRpokemon node.
[{"id":"a430b1b1.b0ffc","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"3834319e.e7eebe","type":"inject","z":"a430b1b1.b0ffc","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":365.80006408691406,"y":143.4000415802002,"wires":[["4200a38d.85569c"]]},{"id":"84288d42.633dc","type":"debug","z":"a430b1b1.b0ffc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":824.8004379272461,"y":109.40008544921875,"wires":[]},{"id":"2ea2ed26.4d7cb2","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"name","pt":"msg","to":"bulbasaur","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":469.80003356933594,"y":230.5999984741211,"wires":[["4200a38d.85569c"]]},{"id":"d6245ef9.86b34","type":"inject","z":"a430b1b1.b0ffc","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":292,"y":230,"wires":[["2ea2ed26.4d7cb2"]]},{"id":"98ef8ac1.399b48","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"number","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":467,"y":285,"wires":[["4200a38d.85569c"]]},{"id":"4ad43208.f4aeac","type":"inject","z":"a430b1b1.b0ffc","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":289.19996643066406,"y":284.4000015258789,"wires":[["98ef8ac1.399b48"]]},{"id":"eb4b2272.f69c4","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":1,"width":"3","height":"1","name":"","label":"Number","format":"{{msg.payload}}","layout":"row-spread","x":1378.80025100708,"y":169.20008945465088,"wires":[]},{"id":"576b35ee.917f8c","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1183.000228881836,"y":170.00005912780762,"wires":[["eb4b2272.f69c4"]]},{"id":"1aee4f4e.811f51","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":2,"width":"3","height":"1","name":"","label":"Name","format":"{{msg.payload}}","layout":"row-spread","x":1371.0001831054688,"y":214.00004768371582,"wires":[]},{"id":"ddd37f20.ce73","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1185.0001831054688,"y":214.00004768371582,"wires":[["1aee4f4e.811f51"]]},{"id":"833ce888.8039a8","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.height","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1186.0001831054688,"y":261.0000476837158,"wires":[["5a2e820a.28475c"]]},{"id":"5a2e820a.28475c","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":7,"width":"3","height":"1","name":"","label":"Height","format":"{{msg.payload}}","layout":"row-spread","x":1372.0001831054688,"y":261.0000476837158,"wires":[]},{"id":"ead35067.97d9a","type":"change","z":"a430b1b1.b0ffc","name":"Remove object","rules":[{"t":"delete","p":"payload.abilities","pt":"msg"},{"t":"delete","p":"payload.base_experience","pt":"msg"},{"t":"delete","p":"payload.forms","pt":"msg"},{"t":"delete","p":"payload.game_indices","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":997.0002937316895,"y":165.00007438659668,"wires":[["576b35ee.917f8c","ddd37f20.ce73","833ce888.8039a8","8d724595.6da8a8","3e9e128c.7aba5e","e6da77b1.a56cb8","5e8a9b9c.85b534","6ceffdf3.6d91d4","6e84468d.ed0938","2f6c01e1.ed22fe","b200753d.fc4e98","4d841c5d.13fc74","f4ad7cf0.86475","df6c2285.35bdb"]]},{"id":"8d724595.6da8a8","type":"debug","z":"a430b1b1.b0ffc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1175.0001182556152,"y":92.00003242492676,"wires":[]},{"id":"470f83f8.d6139c","type":"http request","z":"a430b1b1.b0ffc","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":940.0003128051758,"y":868.6668920516968,"wires":[["afd2fb6d.bb8338","d86ed68a.2bc328"]]},{"id":"5e68df28.cc8ff","type":"ui_template","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","name":"Image","order":4,"width":"6","height":"6","format":"<img ng-src=\"{{msg.payload}}\"/>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1415.0006675720215,"y":872.6671781539917,"wires":[[]]},{"id":"afd2fb6d.bb8338","type":"function","z":"a430b1b1.b0ffc","name":"jpg encode buffer","func":"var getImageResult = msg.payload;\nvar b64encoded = getImageResult.toString('base64');\nmsg.payload = \"data:image/png;base64,\" + b64encoded;\nreturn msg;","outputs":1,"noerr":0,"x":1170.0003128051758,"y":868.6668920516968,"wires":[["5e68df28.cc8ff"]]},{"id":"d490784a.7fb978","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"method","pt":"msg","to":"GET","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"payload.sprites.front_default","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":769.0003128051758,"y":871.0002355575562,"wires":[["470f83f8.d6139c","d86ed68a.2bc328"]]},{"id":"3e9e128c.7aba5e","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.weight","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1194.0000610351562,"y":429.0000476837158,"wires":[["6e202708.ee5158"]]},{"id":"6e202708.ee5158","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":8,"width":"3","height":"1","name":"","label":"Weight","format":"{{msg.payload}}","layout":"row-spread","x":1390.0000610351562,"y":429.0000476837158,"wires":[]},{"id":"53007c08.29c304","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.types[1].type.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1182.0000610351562,"y":309.0000171661377,"wires":[["c078b1fa.f1703"]]},{"id":"c078b1fa.f1703","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":5,"width":"3","height":"1","name":"","label":"Type","format":"{{msg.payload}}","layout":"row-spread","x":1368.0000610351562,"y":309.0000171661377,"wires":[]},{"id":"5e8a9b9c.85b534","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.types[0].type.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190.0000610351562,"y":377.000018119812,"wires":[["95935e17.2ce2d"]]},{"id":"95935e17.2ce2d","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":6,"width":"3","height":"1","name":"type","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1374.0001754760742,"y":377.0000524520874,"wires":[]},{"id":"d3d42631.c737f8","type":"ui_button","z":"a430b1b1.b0ffc","name":"","group":"3d294e32.3d6092","order":18,"width":"6","height":"1","passthru":false,"label":">","tooltip":"","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":144.80002975463867,"y":367.5334167480469,"wires":[["f7d280e6.b9b19"]]},{"id":"3b646efb.0b0722","type":"ui_button","z":"a430b1b1.b0ffc","name":"","group":"3d294e32.3d6092","order":16,"width":"6","height":"1","passthru":false,"label":"<","tooltip":"","color":"","bgcolor":"","icon":"","payload":"-1","payloadType":"num","topic":"","x":144.0000228881836,"y":422.0000534057617,"wires":[["f7d280e6.b9b19"]]},{"id":"57825dc.8aba5a4","type":"function","z":"a430b1b1.b0ffc","name":"","func":"let id=global.get(\"PokId\") || 0;\nlet msg1={};\n\nmsg.number= id + (msg.payload);\n\nif (msg.number<=0)\n{\n msg.number=807;\n}\n\nif (msg.number>=808)\n{\n msg.number=1;\n}\n\nglobal.set(\"PokId\",msg.number);\n\nmsg1.payload=msg.number;\n\nreturn [msg,msg1];","outputs":2,"noerr":0,"x":457.8000831604004,"y":390.1334171295166,"wires":[["4200a38d.85569c"],["fac215.03559de8"]]},{"id":"e6da77b1.a56cb8","type":"switch","z":"a430b1b1.b0ffc","name":"","property":"payload.types[1].type.name","propertyType":"msg","rules":[{"t":"istype","v":"string","vt":"string"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":985.8002414703369,"y":324.1334457397461,"wires":[["53007c08.29c304"],["62507704.825888"]]},{"id":"62507704.825888","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1184,"y":342,"wires":[["c078b1fa.f1703"]]},{"id":"f7d280e6.b9b19","type":"delay","z":"a430b1b1.b0ffc","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":293.8000183105469,"y":388.4666814804077,"wires":[["57825dc.8aba5a4"]]},{"id":"6ceffdf3.6d91d4","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.stats[0].base_stat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1191.6000366210938,"y":498.333327293396,"wires":[["44c669c0.b1ebe8"]]},{"id":"44c669c0.b1ebe8","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":10,"width":"3","height":"1","name":"","label":"Speed","format":"{{msg.payload}}","layout":"row-spread","x":1386.6000442504883,"y":501.333327293396,"wires":[]},{"id":"6e84468d.ed0938","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.stats[1].base_stat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1192.5999755859375,"y":549,"wires":[["b1666f36.9744"]]},{"id":"b1666f36.9744","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":14,"width":"3","height":"1","name":"","label":"Special-defense","format":"{{msg.payload}}","layout":"row-spread","x":1417.599983215332,"y":552,"wires":[]},{"id":"2f6c01e1.ed22fe","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.stats[2].base_stat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1187.5999755859375,"y":609,"wires":[["3bb453c.5f0e7ac"]]},{"id":"3bb453c.5f0e7ac","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":13,"width":"3","height":"1","name":"","label":"Special-attack","format":"{{msg.payload}}","layout":"row-spread","x":1412.599983215332,"y":612,"wires":[]},{"id":"b200753d.fc4e98","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.stats[3].base_stat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1184.5999755859375,"y":670,"wires":[["d1b498c0.4e2bc8"]]},{"id":"d1b498c0.4e2bc8","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":12,"width":"3","height":"1","name":"","label":"Defense","format":"{{msg.payload}}","layout":"row-spread","x":1389.599983215332,"y":673,"wires":[]},{"id":"4d841c5d.13fc74","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.stats[4].base_stat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1175.5999755859375,"y":744,"wires":[["c1145cba.8817f"]]},{"id":"c1145cba.8817f","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":11,"width":"3","height":"1","name":"","label":"Attack","format":"{{msg.payload}}","layout":"row-spread","x":1370.599983215332,"y":747,"wires":[]},{"id":"f4ad7cf0.86475","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.stats[4].base_stat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1161.5999755859375,"y":803,"wires":[["fe559397.dafce"]]},{"id":"fe559397.dafce","type":"ui_text","z":"a430b1b1.b0ffc","group":"3d294e32.3d6092","order":9,"width":"3","height":"1","name":"","label":"Hp","format":"{{msg.payload}}","layout":"row-spread","x":1381.6000442504883,"y":805.0000410079956,"wires":[]},{"id":"fac215.03559de8","type":"ui_slider","z":"a430b1b1.b0ffc","name":"","label":"Number","tooltip":"","group":"ebcb46e5.ba2078","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":"1","max":"807","step":1,"x":98.80003356933594,"y":545.7334804534912,"wires":[["bd438288.1c152"]]},{"id":"bd438288.1c152","type":"ui_numeric","z":"a430b1b1.b0ffc","name":"","label":"Number","tooltip":"","group":"ebcb46e5.ba2078","order":3,"width":0,"height":0,"wrap":true,"passthru":true,"topic":"","format":"{{value}}","min":"1","max":"807","step":1,"x":259.80007553100586,"y":546.733491897583,"wires":[["7792726e.c7cecc"]]},{"id":"946bf254.116c7","type":"debug","z":"a430b1b1.b0ffc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1407.8003311157227,"y":945.4002714157104,"wires":[]},{"id":"a434831a.959a7","type":"catch","z":"a430b1b1.b0ffc","name":"","scope":["470f83f8.d6139c"],"uncaught":false,"x":610.8003005981445,"y":962.4000492095947,"wires":[["e4b961a9.e7586"]]},{"id":"e4b961a9.e7586","type":"switch","z":"a430b1b1.b0ffc","name":"","property":"error.message","propertyType":"msg","rules":[{"t":"eq","v":"No url specified","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":767.8003730773926,"y":959.9334478378296,"wires":[["de2077dd.332438"]]},{"id":"7792726e.c7cecc","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"PokId","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"number","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":434.8000831604004,"y":545.6000394821167,"wires":[["473abfa8.dc91"]]},{"id":"473abfa8.dc91","type":"delay","z":"a430b1b1.b0ffc","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":613.0000305175781,"y":544.0000247955322,"wires":[["4200a38d.85569c"]]},{"id":"de2077dd.332438","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"http://pngimg.com/uploads/pokeball/pokeball_PNG26.png","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1166.8003158569336,"y":948.2668085098267,"wires":[["946bf254.116c7","5e68df28.cc8ff"]]},{"id":"a0b13e73.b6c43","type":"ui_text_input","z":"a430b1b1.b0ffc","name":"","label":"Name","tooltip":"","group":"ebcb46e5.ba2078","order":1,"width":0,"height":0,"passthru":false,"mode":"text","delay":"2000","topic":"","x":141.80001068115234,"y":189.20005798339844,"wires":[["dfe65b07.117c28"]]},{"id":"55ecba57.a5ac74","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"name","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":444.79998779296875,"y":190,"wires":[["4200a38d.85569c"]]},{"id":"c875387a.891888","type":"switch","z":"a430b1b1.b0ffc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"Not Found","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":790,"y":180,"wires":[["ead35067.97d9a"],["5b85112a.7bb29"]]},{"id":"71bd535.fd17eac","type":"ui_toast","z":"a430b1b1.b0ffc","position":"top right","displayTime":"10","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"Alarm","name":"","x":944.066837310791,"y":243.200044631958,"wires":[]},{"id":"5b85112a.7bb29","type":"change","z":"a430b1b1.b0ffc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"pokemon not found","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":751.2668914794922,"y":243.00004482269287,"wires":[["71bd535.fd17eac"]]},{"id":"dfe65b07.117c28","type":"switch","z":"a430b1b1.b0ffc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":277.8000259399414,"y":184.60000896453857,"wires":[["55ecba57.a5ac74"]]},{"id":"4200a38d.85569c","type":"NRpokemon","z":"a430b1b1.b0ffc","name":"","x":650.8000946044922,"y":179.4666748046875,"wires":[["c875387a.891888","84288d42.633dc"]]},{"id":"df6c2285.35bdb","type":"switch","z":"a430b1b1.b0ffc","name":"","property":"payload.sprites.front_default","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":601.0000991821289,"y":871.0001068115234,"wires":[["d490784a.7fb978"],["de2077dd.332438"]]},{"id":"d86ed68a.2bc328","type":"debug","z":"a430b1b1.b0ffc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":984,"y":787,"wires":[]},{"id":"3d294e32.3d6092","type":"ui_group","z":"","name":"Pokemon","tab":"1cef1d94.fe0cf2","order":2,"disp":true,"width":"12","collapse":false},{"id":"ebcb46e5.ba2078","type":"ui_group","z":"","name":"Search","tab":"1cef1d94.fe0cf2","order":1,"disp":true,"width":"6","collapse":false},{"id":"1cef1d94.fe0cf2","type":"ui_tab","z":"","name":"Pokedex","icon":"lens","order":2,"disabled":false,"hidden":false}]