PaparazziBot_nodered

A raspberry Pi 3 that communicates with an ARM mbed with motor control to look for celebrities.

[
    {
        "id": "5d4e9bc0.c22ee4",
        "type": "exec",
        "z": "8f026b9e.9a8278",
        "command": "raspistill -o /usr/lib/node_modules/node-red/public/campi/image1.jpg -q 5",
        "addpay": true,
        "append": "",
        "useSpawn": "",
        "timer": "",
        "name": "Smile click photo",
        "x": 361,
        "y": 146.5,
        "wires": [
            [],
            [
                "dd630fe0.effb5"
            ],
            []
        ]
    },
    {
        "id": "2b82306.32705d",
        "type": "file in",
        "z": "8f026b9e.9a8278",
        "name": "image1.jpg",
        "filename": "/usr/lib/node_modules/node-red/public/campi/image1.jpg",
        "format": "",
        "x": 402.5,
        "y": 229,
        "wires": [
            [
                "b2028380.70ceb"
            ]
        ]
    },
    {
        "id": "b2028380.70ceb",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Reading image",
        "func": "msg.headers = {\n \"Content-Type\":\"image/jpeg\"\n};\n\nvar img = msg.payload;\ncontext.global.img = img;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 564.5,
        "y": 276,
        "wires": [
            [
                "9d9a315e.58a1d"
            ]
        ]
    },
    {
        "id": "9d9a315e.58a1d",
        "type": "visual-recognition-v3",
        "z": "8f026b9e.9a8278",
        "name": "Execute Face Detection",
        "apikey": "__PWRD__",
        "image-feature": "detectFaces",
        "lang": "en",
        "x": 770.5,
        "y": 328,
        "wires": [
            [
                "7586b430.4a121c",
                "11a75eb8.a11831",
                "ec2e4bc4.01d768"
            ]
        ]
    },
    {
        "id": "7586b430.4a121c",
        "type": "debug",
        "z": "8f026b9e.9a8278",
        "name": " Print Visual Recognition Result",
        "active": true,
        "console": "false",
        "complete": "result",
        "x": 1057,
        "y": 395,
        "wires": []
    },
    {
        "id": "dd630fe0.effb5",
        "type": "delay",
        "z": "8f026b9e.9a8278",
        "name": "Delay",
        "pauseType": "delay",
        "timeout": "0.1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 535,
        "y": 152,
        "wires": [
            [
                "2b82306.32705d"
            ]
        ]
    },
    {
        "id": "fbfe9795.960ab8",
        "type": "wiotp out",
        "z": "8f026b9e.9a8278",
        "authType": "d",
        "qs": "false",
        "qsDeviceId": "",
        "deviceKey": "4771cca8.1c73f4",
        "deviceType": "",
        "deviceId": "",
        "event": "event",
        "format": "json",
        "name": "Iot Output Pic Info to IBM Watson Cloud",
        "x": 1335,
        "y": 322,
        "wires": []
    },
    {
        "id": "11a75eb8.a11831",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Stringifiy msg.result",
        "func": "msg = {\n    payload: JSON.stringify(msg.result)\n    \n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1033,
        "y": 325,
        "wires": [
            [
                "fbfe9795.960ab8"
            ]
        ]
    },
    {
        "id": "c4d028d2.2a6c98",
        "type": "wiotp in",
        "z": "8f026b9e.9a8278",
        "authType": "d",
        "deviceKey": "4771cca8.1c73f4",
        "deviceType": "",
        "deviceId": "",
        "command": "takeapic",
        "commandType": "g",
        "name": "Iot Receive Start Command",
        "x": 144,
        "y": 63,
        "wires": [
            [
                "4c2bc609.144388"
            ]
        ]
    },
    {
        "id": "970a0714.0f7398",
        "type": "inject",
        "z": "8f026b9e.9a8278",
        "name": "Manual Start",
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 127,
        "y": 112,
        "wires": [
            [
                "4c2bc609.144388"
            ]
        ]
    },
    {
        "id": "b3c79aa5.6cf6c8",
        "type": "serial out",
        "z": "8f026b9e.9a8278",
        "name": "Serial Output to Mbed",
        "serial": "884229bd.d500c8",
        "x": 957,
        "y": 522,
        "wires": []
    },
    {
        "id": "3adb6db7.5b38d2",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Determine Direction",
        "func": "if (msg.payload[0] == 0x52) { \n    msg.payload = '3';\n} else if (msg.payload[0] == 0x4C) {\n    msg.payload = '2';\n} else if (msg.payload[0] == 0x46 ) {\n    msg.payload = '1';\n} else if (msg.payload[0] == 0x42) {\n    msg.payload = '4';\n} else if (msg.payload[0] == 0x53) {\n    msg.payload = '0';\n} \n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 684,
        "y": 498,
        "wires": [
            [
                "b3c79aa5.6cf6c8"
            ]
        ]
    },
    {
        "id": "3c7b7eaa.7fbc62",
        "type": "serial in",
        "z": "8f026b9e.9a8278",
        "name": "Take A Pic from Mbed",
        "serial": "884229bd.d500c8",
        "x": 135,
        "y": 330,
        "wires": [
            [
                "71cc10d9.0a486"
            ]
        ]
    },
    {
        "id": "8e55d8d8.30aa68",
        "type": "wiotp in",
        "z": "8f026b9e.9a8278",
        "authType": "d",
        "deviceKey": "4771cca8.1c73f4",
        "deviceType": "",
        "deviceId": "",
        "command": "+",
        "commandType": "g",
        "name": "Iot Receive Movement Commands",
        "x": 394,
        "y": 464,
        "wires": [
            [
                "3adb6db7.5b38d2"
            ]
        ]
    },
    {
        "id": "860ee866.53f878",
        "type": "twitter out",
        "z": "8f026b9e.9a8278",
        "twitter": "",
        "name": "Tweet",
        "x": 1200,
        "y": 75,
        "wires": []
    },
    {
        "id": "ec2e4bc4.01d768",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Tweet img data",
        "func": "var mode = context.global.mode;\nvar celebArray;\n\nif (mode == \"Manual\") {\n    msg.payload = \"No face detected\";\n    for (var i = 0; i < msg.result[\"images\"][0][\"faces\"].length; i++) {\n        try {\n            var gender = \"Gender: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"gender\"][\"gender\"]);\n            var gscore = \"Gender Score: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"gender\"][\"score\"]);\n            var max = \"Max: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"age\"][\"max\"]);\n            var min = \"Min: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"age\"][\"min\"]);\n            var agescore = \"Age Score: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"age\"][\"score\"]);\n            try {\n                var celebrity = \"Celebrity Found! \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"identity\"][\"name\"]);    \n                msg.payload = msg.payload + celebrity + \"\\n\";\n                msg.media = context.global.img;\n            } catch(err) {\n                msg.payload = msg.payload + gender + \"\\n\" + gscore + \"\\nAge Range: \" + min + \" \" + max + \"\\n\" + agescore;\n            }\n        } catch(err) {\n            msg.payload = \"No face detected\";\n        }\n    }\n    return msg;\n} else {\n    var celeb = context.global.celeb;\n    msg.payload = \"No celebrity found\";\n    for (var i = 0; i < msg.result[\"images\"][0][\"faces\"].length; i++) {\n        try {\n            if (JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"identity\"][\"name\"])==(celeb)) {\n                var gender = \"Gender: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"gender\"][\"gender\"]);\n                var gscore = \"Gender Score: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"gender\"][\"score\"]);\n                var max = \"Max: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"age\"][\"max\"]);\n                var min = \"Min: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"age\"][\"min\"]);\n                var agescore = \"Age Score: \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"age\"][\"score\"]);\n                var celebrity = \"Celebrity Found! \" + JSON.stringify(msg.result[\"images\"][0][\"faces\"][i][\"identity\"][\"name\"]);\n                msg.payload = celebrity + \"\\n\" + gender + \"\\n\" + gscore + \"\\nAge Range: \" + min + \" \" + max + \"\\n\" + agescore;\n                msg.media = context.global.img;\n                return msg;\n            } else {\n                msg.payload = \"Wrong Celebrity\";\n            }\n            \n        } catch(err) {\n            msg.payload = \"No celebrity found\";\n        }\n    }\n    return msg;\n}    ",
        "outputs": 1,
        "noerr": 0,
        "x": 940,
        "y": 118,
        "wires": [
            [
                "860ee866.53f878",
                "18c549fe.aa1d06",
                "b827faf1.dfc4f8"
            ]
        ]
    },
    {
        "id": "71cc10d9.0a486",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Start Camera",
        "func": "if (msg.payload[0] == \"P\") {\n    msg.payload = \"\";\n    return msg;\n}\n",
        "outputs": 1,
        "noerr": 0,
        "x": 342,
        "y": 366,
        "wires": [
            [
                "5d4e9bc0.c22ee4"
            ]
        ]
    },
    {
        "id": "4c2bc609.144388",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Initiate Camera",
        "func": "msg.payload = \"\";\nvar mode = \"Manual\";\ncontext.global.mode = mode;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 391,
        "y": 66,
        "wires": [
            [
                "5d4e9bc0.c22ee4"
            ]
        ]
    },
    {
        "id": "beeda734.3496d8",
        "type": "serial out",
        "z": "8f026b9e.9a8278",
        "name": "Mbed Continue Auto Mode",
        "serial": "884229bd.d500c8",
        "x": 1326,
        "y": 228,
        "wires": []
    },
    {
        "id": "d08cf8f4.1fcab8",
        "type": "wiotp in",
        "z": "8f026b9e.9a8278",
        "authType": "d",
        "deviceKey": "4771cca8.1c73f4",
        "deviceType": "",
        "deviceId": "",
        "command": "Auto",
        "commandType": "g",
        "name": "Start Auto Mode",
        "x": 418,
        "y": 670,
        "wires": [
            [
                "ad55fb39.24a598"
            ]
        ]
    },
    {
        "id": "ad55fb39.24a598",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Determine Celebrity",
        "func": "if (msg.payload[0] == 0x4A) {\n    var celeb = \"\\\"Jackie Chan\\\"\";\n    context.global.celeb = celeb;\n    context.global.mode = \"Auto\";\n    msg.payload = \"A\";\n    return msg;\n} else if (msg.payload[0] == 0x41) {\n    var celeb = \"\\\"Angelina Jolie\\\"\";\n    context.global.celeb = celeb;\n    context.global.mode = \"Auto\";\n    msg.payload = \"A\";\n    return msg;\n}  else if (msg.payload[0] == 0x48) {\n    var celeb = \"\\\"Hillary Rodham Clinton\\\"\";\n    context.global.celeb = celeb;\n    context.global.mode = \"Auto\";\n    msg.payload = \"A\";\n    return msg;\n}  else if (msg.payload[0] == 0x45) {\n    var celeb = \"\\\"Emma Watson\\\"\";\n    context.global.celeb = celeb;\n    context.global.mode = \"Auto\";\n    msg.payload = \"A\";\n    return msg;\n}  else if (msg.payload[0] == 0x58) {\n    var celeb = \"\\\"Barack Obama\\\"\";\n    context.global.celeb = celeb;\n    context.global.mode = \"Auto\";\n    msg.payload = \"A\";\n    return msg;\n} else if (msg.payload[0] == 0x43) {\n    var celeb = \"\\\"Leonardo DiCaprio\\\"\";\n    context.global.celeb = celeb;\n    context.global.mode = \"Auto\";\n    msg.payload = \"A\";\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "x": 663,
        "y": 676,
        "wires": [
            [
                "c5bb13e7.a85d1"
            ]
        ]
    },
    {
        "id": "c5bb13e7.a85d1",
        "type": "serial out",
        "z": "8f026b9e.9a8278",
        "name": "Mbed Start Auto Mode",
        "serial": "884229bd.d500c8",
        "x": 929,
        "y": 675,
        "wires": []
    },
    {
        "id": "18c549fe.aa1d06",
        "type": "function",
        "z": "8f026b9e.9a8278",
        "name": "Continue Auto Mode",
        "func": "var mode = context.global.mode;\nvar celeb = context.global.celeb;\n\n    if (mode == \"Auto\") {\n        if (msg.payload == \"No celebrity found\") {\n            msg.payload = 'A';\n        } else if (msg.payload == \"Wrong Celebrity\") {\n            msg.payload = 'A';\n        } else {\n            msg.payload = 'D';\n        }\n        return msg;\n    }",
        "outputs": 1,
        "noerr": 0,
        "x": 1056,
        "y": 227,
        "wires": [
            [
                "beeda734.3496d8"
            ]
        ]
    },
    {
        "id": "b827faf1.dfc4f8",
        "type": "debug",
        "z": "8f026b9e.9a8278",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 1252,
        "y": 145,
        "wires": []
    },
    {
        "id": "4771cca8.1c73f4",
        "type": "wiotp-credentials",
        "z": "",
        "name": "a2g6k39sl6r5",
        "org": "73k64g",
        "devType": "Raspberry_Pi3",
        "devId": "Device02"
    },
    {
        "id": "884229bd.d500c8",
        "type": "serial-port",
        "z": "",
        "serialport": "/dev/ttyACM0",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": false
    }
]
aismail1997

Flow Info

created 7 months, 3 weeks ago

Node Types

Core
  • debug (x2)
  • delay (x1)
  • exec (x1)
  • file in (x1)
  • function (x8)
  • inject (x1)
  • serial in (x1)
  • serial out (x3)
  • serial-port (x1)
  • twitter out (x1)
Other

Tags

  • visual-recognition
  • serial
  • Raspberry-Pi3
  • mbed
  • twitter
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option