Posted last time completed a practical sensor, and after operating it for a while, some points I wanted to improve came out.
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.
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
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)
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.
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
I examined various methods and listed candidates
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
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