vincent wong
Published © GPL3+

KidGuard

Safeguard your kid with this.

IntermediateFull instructions provided2,753

Things used in this project

Story

Read more

Schematics

Raspberry Pi, Walabot and Arduino Uno

Code

KidGuardWalabot.py

Python
from __future__ import print_function
from sys import platform
from os import system

import WalabotAPI as wlbt

import socket, sys

if __name__ == '__main__':
        wlbt.Init()  # load the WalabotSDK to the Python wrapper
        wlbt.SetSettingsFolder()  # set the path to the essetial database files
        wlbt.ConnectAny()  # establishes communication with the Walabot

        wlbt.SetProfile(wlbt.PROF_TRACKER)  # set scan profile out of the possibilities

        #wlbt.SetThreshold(35)
        #wlbt.SetArenaR(50,400,4)
        #wlbt.SetArenaPhi(-45,45,2)
        #wlbt.SetArenaTheta(-20,20,10)

        wlbt.SetDynamicImageFilter(wlbt.FILTER_TYPE_MTI)  # specify filter to use

        wlbt.Start()  # starts Walabot in preparation for scanning

        system('cls' if platform == 'win32' else 'clear')  # clear the terminal
        numOfTargetsToDisplay = 1
        if len(sys.argv) == 2:
                TCP_IP = '127.0.0.1'
                TCP_PORT = int(sys.argv[1])

                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.bind((TCP_IP, TCP_PORT))
                s.listen(1)
                conn, addr = s.accept()
                while True:
                        wlbt.Trigger()  # initiates a scan and records signals
                        targets = wlbt.GetTrackerTargets()  # provides a list of identified targets

                        target = '{"target": ['
                        index = 0

                        for i, t in enumerate(targets):
                                if i < numOfTargetsToDisplay:
                                        index += 1
                                        print('Target #{}\nx = {}\ny = {}\nz = {}\n'.format(i+1, t.xPosCm, t.yPosCm, t.zPosCm))
                                        target += '{"x": "%s", "y": "%s", "z": "%s"}' % (t.xPosCm, t.yPosCm, t.zPosCm)

                        target += ']}'
                        conn.sendall(str.encode(target))
                conn.close()
                wlbt.Stop()  # stops Walabot when finished scanning
                wlbt.Disconnect()  # stops communication with Walabot

KidGuard Flow

JSON
[{"id":"216d9d05.042b12","type":"arduino out","z":"3f44fcdf.307c44","name":"","pin":"7","state":"OUTPUT","arduino":"d4c6e849.844578","x":1270,"y":740,"wires":[]},{"id":"ae716057.e4571","type":"alexa-local","z":"3f44fcdf.307c44","devicename":"buzzer","inputtrigger":false,"x":203.10000610351562,"y":740,"wires":[["216d9d05.042b12"]]},{"id":"7300ed97.589464","type":"arduino in","z":"3f44fcdf.307c44","name":"door switch","pin":"3","state":"INPUT","arduino":"d4c6e849.844578","x":221.10000610351562,"y":634.2000122070312,"wires":[["95296c59.24881","af3799c0.4e39d8"]]},{"id":"32097bae.c00744","type":"debug","z":"3f44fcdf.307c44","name":"","active":false,"console":"false","complete":"false","x":850,"y":504,"wires":[]},{"id":"ad36c7d4.572048","type":"inject","z":"3f44fcdf.307c44","name":"start KidGuardWalabot","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"x":245.10000610351562,"y":367,"wires":[["2162ed1f.a18e72"]]},{"id":"2162ed1f.a18e72","type":"exec","z":"3f44fcdf.307c44","command":"python","addpay":false,"append":"KidGuardWalabot.py 2000","useSpawn":"false","timer":"","oldrc":true,"name":"start KidGuardWalabot.py","x":550,"y":367,"wires":[["70d99112.4a917"],[],[]]},{"id":"d8ee745f.7094a8","type":"tcp in","z":"3f44fcdf.307c44","name":"","server":"client","host":"localhost","port":"2000","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":233.10000610351562,"y":491,"wires":[["dbf05ea7.98ad1"]]},{"id":"dbf05ea7.98ad1","type":"function","z":"3f44fcdf.307c44","name":"set target y and covert to json","func":"raw = msg.payload.toString('UTF-8')\njson = JSON.parse(raw);\nvar m1 = { payload: raw };\nvar m2 = { payload: json };\n\n\nif (raw.length > 20)\n{\n    y = m2.payload.target[0].y;\n    global.set(\"y\", y);\n    var m3 = { payload: y };\n}\n\nreturn [  m1, m2, m3 ];  \n\n","outputs":"3","noerr":0,"x":570,"y":491,"wires":[[],[],["32097bae.c00744"]]},{"id":"95296c59.24881","type":"debug","z":"3f44fcdf.307c44","name":"","active":true,"console":"false","complete":"payload","x":513.1000366210938,"y":636,"wires":[]},{"id":"70d99112.4a917","type":"debug","z":"3f44fcdf.307c44","name":"","active":false,"console":"false","complete":"false","x":850,"y":353,"wires":[]},{"id":"7736213d.98133","type":"alexa-local","z":"3f44fcdf.307c44","devicename":"kid guard","inputtrigger":false,"x":209,"y":820,"wires":[["d881ae8b.9a0d8"]]},{"id":"d881ae8b.9a0d8","type":"function","z":"3f44fcdf.307c44","name":"set kid guard ","func":"global.set(\"kidguard\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":446.10003662109375,"y":820,"wires":[["ab7d78df.6edce8"]]},{"id":"ab7d78df.6edce8","type":"debug","z":"3f44fcdf.307c44","name":"","active":false,"console":"false","complete":"false","x":672.1000366210938,"y":820,"wires":[]},{"id":"398378a.38e5588","type":"inject","z":"3f44fcdf.307c44","name":"print saved variables","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":227.10000610351562,"y":907,"wires":[["3d9d0eaa.b5c1d2"]]},{"id":"3d9d0eaa.b5c1d2","type":"function","z":"3f44fcdf.307c44","name":"build msg","func":"msg.payload = { \"y\": global.get('y'), \"kidguard\": global.get('kidguard')}\nreturn msg;","outputs":1,"noerr":0,"x":439.10003662109375,"y":907,"wires":[["14e58dbb.03a242"]]},{"id":"14e58dbb.03a242","type":"debug","z":"3f44fcdf.307c44","name":"","active":true,"console":"false","complete":"payload","x":644.1000366210938,"y":906,"wires":[]},{"id":"af3799c0.4e39d8","type":"switch","z":"3f44fcdf.307c44","name":"check door switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":1,"x":472.10003662109375,"y":693,"wires":[["f3dd27d1.d39db8"]]},{"id":"f3dd27d1.d39db8","type":"switch","z":"3f44fcdf.307c44","name":"check kid guard","property":"kidguard","propertyType":"global","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","outputs":1,"x":680.1000366210938,"y":693,"wires":[["c4b97926.b46d48"]]},{"id":"c4b97926.b46d48","type":"switch","z":"3f44fcdf.307c44","name":"check y","property":"y","propertyType":"global","rules":[{"t":"lt","v":"0","vt":"num"}],"checkall":"true","outputs":1,"x":847.1000366210938,"y":693,"wires":[["51985380.b6488c"]]},{"id":"51985380.b6488c","type":"function","z":"3f44fcdf.307c44","name":"set buzzer on","func":"msg.payload = 1;\nreturn msg;","outputs":1,"noerr":0,"x":1017.5000305175781,"y":693,"wires":[["216d9d05.042b12"]]},{"id":"d4c6e849.844578","type":"arduino-board","z":"","device":"/dev/ttyACM0"}]

Credits

vincent wong

vincent wong

81 projects • 205 followers

Comments