Srivishnu Piratla
Published © GPL3+

Fire Fury

Helping firefighters save the most people.

IntermediateFull instructions provided14 hours2,810

Things used in this project

Hardware components

Walabot Developer Pack
Walabot Developer Pack
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Echo Dot
Amazon Alexa Echo Dot
×1

Software apps and online services

Microsoft Windows
Walabot Developer Pack Walabot API

Hand tools and fabrication machines

Keyboard
Mouse
Monitor
Router

Story

Read more

Schematics

How the Architecture Works

1) The Walabot connected to the raspberry pi posts information to the server
2) The server stores the information in a MySQL Database
3) The Alexa intent is placed through the dash wand
4) It goes through the Alexa Skills Kit and the intent is passed to the server
5) The server calculates the amount of people on each floor and returns the floors in order of most people to least people
6) Emergency Services can save the most lives

Code

Raspberry Pi Walabot Code

Python
This is the code that connects the Walabot to the Raspberry Pi and sends requests to the server
from __future__ import print_function 
from sys import platform
from os import system
from imp import load_source
from enum import Enum
from os.path import join
import time
import requests
import json
 
if platform == 'win32':
    modulePath = join('C:/', 'Program Files', 'Walabot', 'WalabotSDK',
        'python', 'WalabotAPI.py')
elif platform.startswith('linux'):
    modulePath = join('/usr', 'share', 'walabot', 'python', 'WalabotAPI.py')    
 
import WalabotAPI as walabotAPI
walabotAPI.Init()
 
wlbt = load_source('WalabotAPI', modulePath)
wlbt.Init()
 
def PrintTrackerTargets(targets):
    system('cls' if platform == 'win32' else 'clear')
    if targets:
        for i, target in enumerate(targets):
            print(('y: {}'.format(target.yPosCm)))
    else:
        print('No Target Detected')
 
 
 
class Placement(Enum):
    Empty = 0 
    Back = 1 
    Front = 2  
 
 
class State(Enum):
    Idle = 0 
    Bi = 1  
    Fi = 2  
    Bo = 3  
    Fo = 4 
 
 
def _get_placement(targets):
    if len(targets) is 0:
        return Placement.Empty
    if targets[0].yPosCm > 0:
        return Placement.Front
    if targets[0].yPosCm <= 0:
        return Placement.Back
 
 
class PeopleCounter:
    def __init__(self):
        self.placement = Placement.Empty
        self.state = State.Idle
        self.count = 0
        self.state_machine = {
            State.Idle:
                {Placement.Empty: State.Idle,
                 Placement.Back: State.Bi,
                 Placement.Front: State.Fo},
            State.Bi:
                {Placement.Empty: State.Idle,
                 Placement.Back: State.Bi,
                 Placement.Front: State.Fi},
            State.Fi:
                {Placement.Empty: State.Idle,
                 Placement.Back: State.Bi,
                 Placement.Front: State.Fi},
            State.Fo:
                {Placement.Empty: State.Idle,
                 Placement.Back: State.Bo,
                 Placement.Front: State.Fo},
            State.Bo:
                {Placement.Empty: State.Idle,  
                 Placement.Back: State.Bo,
                 Placement.Front: State.Fo},
        }
 
    def update_state_get_count(self, targets):
        self.placement = _get_placement(targets)
        prev_state = self.state
        self.state = self.state_machine[self.state][self.placement]
 
        if prev_state == State.Bo and self.state == State.Idle:
            self._decrement()
        elif prev_state == State.Fi and self.state == State.Idle:
            self._increment()
 
        return self.count
 
    def _increment(self):
        self.count += 1
        return State.Idle
 
    def _decrement(self):
        self.count = max(self.count - 1, 0)
        return State.Idle
 
 
def PeopleCounterApp():

    people_counter = PeopleCounter()

    rArenaMin, rArenaMax, rArenaRes = 5, 120, 5

    phiArenaMin, phiArenaMax, phiArenaRes = -60, 60, 3
   
    thetaArenaMin, thetaArenaMax, thetaArenaRes = -20, 20, 10

    walabotAPI.SetSettingsFolder()
 
    walabotAPI.ConnectAny()

    walabotAPI.SetProfile(wlbt.PROF_SENSOR)

    walabotAPI.SetArenaR(rArenaMin, rArenaMax, rArenaRes)
    walabotAPI.SetArenaPhi(phiArenaMin, phiArenaMax, phiArenaRes)
    walabotAPI.SetArenaTheta(thetaArenaMin, thetaArenaMax, thetaArenaRes)

    walabotAPI.SetDynamicImageFilter(walabotAPI.FILTER_TYPE_MTI)

    walabotAPI.Start()
 
    try:
        num_of_people = 0
        while True:
            walabotAPI.Trigger()

            targets = walabotAPI.GetSensorTargets()
            print (targets)
            targets1 = len(walabotAPI.GetSensorTargets())
            Address = "75 mountain street brockton ca"
            floor = 3
            Room = "12A"
            payload={'Address':Address, 'floor' : floor, 'Room' : Room, 'Peeps': targets1}
            r=requests.post("http://84199c9b.ngrok.io/post",json=payload)
 
            targets = sorted(targets, key=lambda x: x.zPosCm, reverse=True)
           
            prev_num_of_people = num_of_people
         
            num_of_people = people_counter.update_state_get_count(targets)
         
            if prev_num_of_people != num_of_people:
                print('# {} #\n'.format(num_of_people))
               
               
            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
       
        walabotAPI.Stop()
        walabotAPI.Disconnect()
     
    print('Terminated successfully!')
 
 
if __name__ == '__main__':
    PeopleCounterApp()

flaskaskpy.py

Python
from flask import Flask
from flask_ask import Ask, request, session, question, statement
from flask_cors import CORS
import json
from app1 import GetPeopleCounts

app = Flask(__name__)
ask = Ask(app, '/')
app.config["DEBUG"] = True

@ask.launch
def launch():
    speech_text = "Dibhu check"
    return question(speech_text)

@ask.intent('MainIntent')
def MainIntent(Address):
    #return statement("{}".format(Address))
    #print (GetPeopleCounts("{}".format(Address)))
    return statement(GetPeopleCounts("{}".format(Address)))


if __name__ == '__main__':
    app.run(debug=True, port = 5001)

app1.py

Python
from flask import Flask
from flask import request
from flask_cors import CORS
import json
import requests
import pymysql


app = Flask(__name__)
CORS(app)
app.config["DEBUG"] = True
db = pymysql.connect(host='localhost',port=3306,user='root',passwd='Srivibhu10',db='users')

@app.route('/post', methods=['POST'])
def Us():
    Given_Address = request.json['Address']
    Given_floor = request.json['floor']
    Given_Room = request.json['Room']
    Given_Peeps = request.json['Peeps']

    cursor = db.cursor()

    select_Address =  ("select count(*) from users.user where Address=%s ")
    select_Addrss_Floor = ("select count(*) from users.user where Address=%s and floor=%s")
    select_Addrss_Floor_Room = ("select count(*) from users.user where Address=%s and floor=%s and Room=%s")

    if len(Given_Address) > 0 and len(Given_floor) > 0 and len(Given_Room) > 0 and Given_Peeps != "0":
        #check if all values are present in database
        check_allfields=(Given_Address,Given_floor,Given_Room)
        cursor.execute(select_Addrss_Floor_Room,check_allfields)
        rows = cursor.fetchone()
        if rows[0] > 0:
            Update_noofpeople = ("UPDATE users.user set Peeps= %s where Address=%s and Floor=%s and Room=%s")
            updated_data=(Given_Peeps,Given_Address,Given_floor,Given_Room)
            cursor.execute(Update_noofpeople,updated_data)
            db.commit()
            cursor.close()
            return ("Hi..Updated")
        else:
            # Add new record
             Insert_newrecord=("Insert into users.user(Address,floor,Room,Peeps) VALUES (%s,%s,%s,%s)")
             Insert_allfields=(Given_Address,Given_floor,Given_Room,Given_Peeps)
             cursor = db.cursor()
             cursor.execute(Insert_newrecord,Insert_allfields)
             db.commit()
             cursor.close()

             return ("Hi....Inserted")

    else:
        return ("Hi in ELSE BLOCK ....")

def GetPeopleCounts(Address):
    #return (Address)

    Input_Address = Address
    # check if this record is already present
    select_noofrows=("select floor,sum(peeps) from users.user where UPPER(Address)=UPPER(%s) group by floor order by sum(peeps) desc")
    cursor = db.cursor()
    cursor.execute(select_noofrows,Input_Address)
    #print(cursor.description)

    if cursor.rowcount > 0:

         #data = cursor.fetchall()
         return_msg = "Number of people in each floor at this address  "
         for row in cursor:
             return_msg = return_msg + "  Floor  "+row[0]+" People  "+str(int(row[1]))
         return (return_msg)
         '''
         for row in cursor:
            #print(row)

            return(row)
         '''
    else:
        return("No Records Found")

    db.commit()
    cursor.close()


if __name__ == '__main__':
    app.run()

Credits

Srivishnu Piratla

Srivishnu Piratla

5 projects • 47 followers

Comments