Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IRIS-UDP.py #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 62 additions & 15 deletions IRIS-UDP.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,69 @@
#!/usr/bin/python

import socket
import getopt
import sys
import time

UDP_IP = "192.168.1.157"
UDP_PORT = 2390
msg = "VAULT"

try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("",8888))
except:
sys.exit()
def usage():

print("Ayuda: IRIS UDP")
print("")
print("-d Direccion")
print("-p Puerto")
print("-m Mensaje")
print("-h Ayuda")

while(1):
#msgbts = bytes(msg, 'utf-8')
msgbts = str(msg).encode("utf-8")
s.sendto(msgbts, (UDP_IP, UDP_PORT))
d = s.recvfrom(1024) #Prender Led cuando se recibe algo?
time.sleep(120)
def main():
'Main function'
global Action, x, y, z, UDP_IP, UDP_PORT, msgbts, s

try:
opts, args = getopt.getopt(sys.argv[1:], "d:p:m:h")

except getopt.GetoptError as err:
print("Error: "+str(err)+", -h para ayuda\n\n")
usage()
sys.exit(2)

if len(opts) == 0:
print("Definir atgumentos, -h for ayuda")
sys.exit()
for o, a in opts:
if o in ("-h"):
usage()
sys.exit()
if o in ("-d"):
try:
UDP_IP = str(a).encode("utf-8")
except ValueError:
print("-- Direccion")
sys.exit(2)
if o in ("-p"):
try:
UDP_PORT=int(a)
except ValueError:
print ("--to argument is taking only numeric values")
sys.exit(2)
if o in ("-d"):
try:
msgbts = str(a).encode("utf-8")
except ValueError:
print("-- mensaje")
sys.exit(2)

try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("",8888))
except:
sys.exit()
try:
d = s.recvfrom(1024)
print("Mensaje recibido:" + d)
except:
sys.exit()

print("Listo")

if __name__ == "__main__":
main()