Improved motion sensor made with Raspberry Pi

Introduction

Posted last time completed a practical sensor, and after operating it for a while, some points I wanted to improve came out.

  1. The pop-up is not good
  2. I want to make a sound at the same time as the pop-up display
  3. I want to support multiple clients

As for 1., I thought from the beginning that the standard Windows pop-up looks ugly anyway, so I wanted to make it look fashionable and modern.

Regarding 2., the pop-up does not appear when playing a game in full screen, so I experienced it badly unless I noticed it with sound.

  1. I wanted to be able to use either PC because I have multiple PCs in my room.

Pop-up improvement

After consulting with an acquaintance, I think growl is good. I got a suggestion I decided to use it because it can be used on Windows, it can be easily operated from the command line, it looks modern and cool, and it also produces sound. I made it to execute from a batch file by referring to this site

growl setting

First, install growl for windows and pass it through the path. (I noticed after finishing, but I feel that if I write the full path in a batch file, I do not have to pass the path) After that, set the password, appearance, and sound from the growl setting screen and complete (Since it is as per this site, it is omitted)

Batch file creation

Create a batch file to pop up

popup.bat


growlnotify.exe /t:"Emergency!" /s:False /pass:"password"Please evacuate

If you set / s: True, the pop-up will not disappear unless you click it, but it is troublesome if it comes continuously, so I set it to False

When I executed this, a pop-up was displayed, but when I executed the batch file, the command prompt was displayed for a moment. After a lot of research, the method of calling a batch file from vbs seems to be the royal road (I don't really know) So I didn't get it, but I created vbs

popup.vbs


Dim oShell
Dim path

Set oShell = WScript.CreateObject ("WSCript.shell")

path = oShell.CurrentDirectory
path = path & "\PopUp.bat"

oShell.run path,0

Set oShell = Nothing

It works as desired, so I decided to execute this vbs from a script.

Script change

The part that displays the pop-up created last time

python


def popup(): #Send a message on the Windows screen
  user32 = windll.user32
  user32.MessageBoxA( 0, "Enemy Will Come Here!!", "Caution!!", 0x00000030)

Change as below

def growl(): #Run vbs to show growl
  path = os.path.abspath(os.path.dirname(__file__))
  filename = "popup.vbs"
  path = os.path.join(path,filename)
  os.system(path) h

As a whole it became like this

sencer_server.py


from __future__ import print_function
import socket
import time
import os

from contextlib import closing
from ctypes import *


def main():
  while True:
    print('listen,start')
    recv()
    time.sleep(1)

def recv():
  host = '192.168.1.xx'
  port = 8080
  backlog = 10
  bufsize = 4096
  socket.timeout(1)
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  try:
    with closing(sock):
      sock.bind((host, port))
      sock.listen(backlog)
      conn, address = sock.accept() 
      msg = conn.recv(bufsize) 
      if (msg == 'raspberry'):
        print('recieve')
        growl()
        
  except socket.timeout:
    print('connect,timeout')
  except socket.error:
    print('connect,error')

def growl():
  path = os.path.abspath(os.path.dirname(__file__))
  filename = "popup.vbs"
  path = os.path.join(path,filename)
  os.system(path)
  
if __name__ == '__main__':
  main()

Completed I was able to realize the fashionable pop-up I was looking for

Supports multiple clients

I examined various methods and listed candidates

  1. Change from TCP to UDP to broadcast
  2. Make the transmission part multi-threaded
  3. Do it well in the cloud

It seems easy to broadcast 1., and I didn't have to write each IP address in the source, so I tried it, but I was frustrated because it didn't work. I'm frustrated, so I want to revenge as soon as I ask someone

Regarding 3., it takes time to review the overall specifications, select the cloud and make a contract, so it is reserved.

I'm reluctant, but in 2., I decided to deal with it for the time being

So, I changed the following

sencer_cliant.py


from __future__ import print_function
import socket
import time

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)

from contextlib import closing
import threading

def main():
  print('start,waiting')
  while True:
    inputValue = GPIO.input(25)
    host = ['192.168.1.xx','192.168.1.yy']
    if (inputValue == True):
      print('inputTrue')
      for ip in host:
        thread = threading.Thread(target=send, args=(ip,))
        thread.start()
      time.sleep(5)

def send(host):
  port = 8080
  bufsize = 4096
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.settimeout(1)
  
  with closing(sock):
    try:
      sock.connect((host, port))
      sock.send('raspberry')
      print(host + ' send')
    except socket.timeout:
      print(host + ' socketTimeout')
    except socket.error:
      print(host + ' socketError')
  return

if __name__ == '__main__':
  main()

Completed

Impressions

Practical dissatisfaction in my environment has been almost eliminated, and I am living a comfortable life in my room. I just made a weird toy with an impure motive, but when I touched python for the first time, the tension went up and I was quite absorbed in it. I would like to try cloud computing during the winter vacation Also, since it's almost a copy, the contents of the sauce will be terrible, I will not be able to make it unless I make it while examining it a little more, so I would like to devote myself little by little.

If you have any suggestions or guidance, please do not hesitate to contact us.

Recommended Posts

Improved motion sensor made with Raspberry Pi
Use PIR motion sensor with raspberry Pi
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Stock investment analysis app made with Raspberry Pi
Mutter plants with Raspberry Pi
Using the digital illuminance sensor TSL2561 with Raspberry Pi
Check! Get sensor data via Bluetooth with Raspberry Pi ~ Preparation
I made a resource monitor for Raspberry Pi with a spreadsheet
I tried using the DS18B20 temperature sensor with Raspberry Pi
I made a surveillance camera with my first Raspberry PI.
[Raspberry Pi] Stepping motor control with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Servo motor control with Raspberry Pi
Serial communication with Raspberry Pi + PySerial
OS setup with Raspberry Pi Imager
Try L Chika with raspberry pi
VPN server construction with Raspberry Pi
Detects people with motion sensor module
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
I made a web server with Raspberry Pi to watch anime
Periodically log the value of Omron environment sensor with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
Build a Tensorflow environment with Raspberry Pi [2020]
Get BITCOIN LTP information with Raspberry PI
Try fishing for smelt with Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Use the Grove sensor on the Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
Working with sensors on Mathematica on Raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Infer Custom Vision model with Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Inkbird IBS-TH1 value logged with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
[Electronic work] I made a Suica touch sound detector with Raspberry Pi
Note: I want to do home automation with Home Assistant + Raspberry Pi + sensor # 1
Get GrovePi + sensor value with Raspberry Pi and store it in kintone
Logging the value of Omron environment sensor with Raspberry Pi (USB type)
Discord bot with python raspberry pi zero with [Notes]
Media programming with Raspberry Pi (preparation for audio)
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
I tried L-Chika with Raspberry Pi 4 (Python edition)
Raspberry Pi backup
Enjoy electronic work with GPIO on Raspberry Pi
MQTT RC car with Arduino and Raspberry Pi
Power on / off your PC with raspberry pi
Use Majoca Iris elongated LCD with Raspberry Pi
CSV output of pulse data with Raspberry Pi (CSV output)
Observe the Geminids meteor shower with Raspberry Pi 4
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Get CPU information of Raspberry Pi with Python
Play with your Ubuntu desktop on your Raspberry Pi 4
Raspberry + am2302 Measure temperature and humidity with temperature and humidity sensor
Get temperature and humidity with DHT11 and Raspberry Pi
Logging Inkbird IBS-TH1 mini values with Raspberry Pi