sharpstef/iot-foosball

NodeRED bugs and fixes from deploying to Bluemix

Closed this issue · 1 comments

ISSUE: Team goals are backwards
Goal Handling (switch node) --> 2 and 1 are flipped
Location: Top middle

ISSUE: Timeline reports both team shooters as Team Yellow
Set Team Two as Shooter (function node) --> team:1 should be team:2
Location: Middle middle-right

ISSUE: Database records both users as losing
Use 2 global variables instead of 1 to store "winner".
Location: Top right
NodeRED code:
[{"id":"97ef7107.2773c","type":"subflow","name":"Search for Player (3)","info":"","in":[{"x":50,"y":30,"wires":[{"id":"cf627932.667968"}]}],"out":[{"x":520,"y":115,"wires":[{"id":"cf627932.667968","port":0}]}]},{"id":"7f74df07.25574","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"fcb4ac2f.c3109","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"e1504e6.3c3dab","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"2d7fdfc1.17237","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"89ec00b0.9562e","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"34f38525.21617a","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"5aeeb85d.254818","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"cf627932.667968","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"2ae0e15e.d3fcbe","type":"subflow","name":"Update Player 1","info":"","in":[{"x":50,"y":30,"wires":[{"id":"cb448a29.84cd18"}]}],"out":[]},{"id":"14b8ca0e.2433a6","type":"function","z":"2ae0e15e.d3fcbe","name":"Set Cloudant Update Command","func":"gameID = global.get(\"gameID\").toString();\nvar win = global.get(\"winner1\");\nif(win===true){\n gamesWon = msg.payload.gamesWon + 1;\n msg.payload.gamesWon = gamesWon;\n}\nelse{\n gamesLost = msg.payload.gamesLost + 1;\n msg.payload.gamesLost = gamesLost;\n}\n\n\nvar goals = global.get(\"goals\");\nvar goals2 = global.get(\"goals2\");\nmsg.payload.pointsFor = msg.payload.pointsFor + goals;\nmsg.payload.pointsAgainst = msg.payload.pointsAgainst + goals2;\n\n\nmsg.payload = {\n \"_id\": msg.payload._id,\n \"_rev\": msg.payload._rev,\n \"handle\":msg.payload.handle,\n \"name\": msg.payload.name,\n \"photo\": msg.payload.photo,\n \"gamesWon\": msg.payload.gamesWon,\n \"gamesLost\": msg.payload.gamesLost,\n \"pointsFor\": msg.payload.pointsFor,\n \"pointsAgainst\":msg.payload.pointsAgainst,\n \"lastPlayed\": global.get(\"endTime\"),\n \"lastGame\": gameID\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":120,"wires":[["3fb83077.455a1"]]},{"id":"3fb83077.455a1","type":"cloudant out","z":"2ae0e15e.d3fcbe","name":"Update","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","payonly":true,"operation":"insert","x":655.5,"y":302,"wires":[]},{"id":"f8290569.f98638","type":"comment","z":"2ae0e15e.d3fcbe","name":"PLAYER 1","info":"","x":301.6666679382324,"y":247.77778244018555,"wires":[]},{"id":"cb448a29.84cd18","type":"subflow:97ef7107.2773c","z":"2ae0e15e.d3fcbe","name":"","x":265.5,"y":101,"wires":[["14b8ca0e.2433a6"]]},{"id":"97ef7107.2773c","type":"subflow","name":"Search for Player (3)","info":"","in":[{"x":50,"y":30,"wires":[{"id":"cf627932.667968"}]}],"out":[{"x":520,"y":115,"wires":[{"id":"cf627932.667968","port":0}]}]},{"id":"7f74df07.25574","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"fcb4ac2f.c3109","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"e1504e6.3c3dab","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"2d7fdfc1.17237","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"89ec00b0.9562e","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"34f38525.21617a","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"5aeeb85d.254818","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"cf627932.667968","type":"cloudant in","z":"97ef7107.2773c","name":"","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":246.5,"y":78,"wires":[[]]},{"id":"70778200.0b377","type":"subflow","name":"Update Player 2","info":"","in":[{"x":50,"y":30,"wires":[{"id":"3ee098ef.e8ad88"}]}],"out":[]},{"id":"9eedfc63.c4c47","type":"function","z":"70778200.0b377","name":"Set Cloudant Update Command","func":"gameID = global.get(\"gameID\").toString();\nvar win = global.get(\"winner2\");\nif(win===true){\n gamesWon = msg.payload.gamesWon + 1;\n msg.payload.gamesWon = gamesWon;\n}\nelse{\n gamesLost = msg.payload.gamesLost + 1;\n msg.payload.gamesLost = gamesLost;\n}\n\n\nvar goals = global.get(\"goals\");\nvar goals2 = global.get(\"goals2\");\nmsg.payload.pointsFor = msg.payload.pointsFor + goals;\nmsg.payload.pointsAgainst = msg.payload.pointsAgainst + goals2;\n\n\nmsg.payload = {\n \"_id\": msg.payload._id,\n \"_rev\": msg.payload._rev,\n \"handle\":msg.payload.handle,\n \"name\": msg.payload.name,\n \"photo\": msg.payload.photo,\n \"gamesWon\": msg.payload.gamesWon,\n \"gamesLost\": msg.payload.gamesLost,\n \"pointsFor\": msg.payload.pointsFor,\n \"pointsAgainst\":msg.payload.pointsAgainst,\n \"lastPlayed\": global.get(\"endTime\"),\n \"lastGame\": gameID\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":495.55553436279297,"y":66.66666603088379,"wires":[["61783d53.b5ea34"]]},{"id":"61783d53.b5ea34","type":"cloudant out","z":"70778200.0b377","name":"Update","cloudant":"","database":"players","service":"foosbuzz-cloudantNoSQLDB","payonly":true,"operation":"insert","x":547.7222290039062,"y":232.0000114440918,"wires":[]},{"id":"3ee098ef.e8ad88","type":"subflow:97ef7107.2773c","z":"70778200.0b377","name":"","x":233.5,"y":70,"wires":[["9eedfc63.c4c47"]]},{"id":"a496a767.32fc98","type":"function","z":"2e819c41.e119a4","name":"Update Player 1","func":"msg.payload = global.get(\"idTeamOne\");\n\nvar goals = global.get(\"goalsTeamOne\");\nglobal.set(\"goals\",goals);\nvar goals2 = global.get(\"goalsTeamTwo\");\nglobal.set(\"goals2\",goals2);\n\n\nvar time = global.get(\"endTime\");\nvar lastGame = global.get(\"gameID\").toString();\n//flipped < sign to >\nif(goals>goals2){\n global.set(\"winner1\",true);\n}\nelse{\n global.set(\"winner1\",false);\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":3221,"y":318.8461561936599,"wires":[["ca6555ce.e21778","78d5906e.9868d"]]},{"id":"be5d0cbc.039f8","type":"function","z":"2e819c41.e119a4","name":"Update Player 2","func":"msg.payload = global.get(\"idTeamTwo\");\n//originally had goalsTeamOne and goalsTeamTwo swapped\nvar goals = global.get(\"goalsTeamOne\");\nglobal.set(\"goals\",goals);\nvar goals2 = global.get(\"goalsTeamTwo\");\nglobal.set(\"goals2\",goals2);\n\nvar time = global.get(\"endTime\");\nvar lastGame = global.get(\"gameID\").toString();\n//flipped > sign to <\nif(goals<goals2){\n global.set(\"winner2\",true);\n}\nelse{\n global.set(\"winner2\",false);\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":3221,"y":358.8461561936599,"wires":[["7cc7068.cbe1cf8","6c45455f.d546ec"]]},{"id":"6c45455f.d546ec","type":"subflow:70778200.0b377","z":"2e819c41.e119a4","name":"","x":3442.666835784912,"y":357.7350493211013,"wires":[]},{"id":"ca6555ce.e21778","type":"subflow:2ae0e15e.d3fcbe","z":"2e819c41.e119a4","name":"updateplayer 1","x":3441,"y":318.8461561936599,"wires":[]}]

Ah it appears this is due to some changes we made for an event in Austin and I completely forgot to revert the flow back to what it was. I apologize for the error.