2020-04-17 13:08:26 +00:00
|
|
|
import logging
|
2018-05-03 16:37:18 +00:00
|
|
|
import socket
|
|
|
|
import json
|
|
|
|
|
|
|
|
PORT = 8023
|
|
|
|
MESSAGE = "yo"
|
|
|
|
RETRY_LIMIT = 5
|
|
|
|
IP = 0
|
2020-04-15 11:27:26 +00:00
|
|
|
s = None
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2018-05-03 16:37:18 +00:00
|
|
|
def initialize(ip):
|
|
|
|
global s, IP
|
|
|
|
IP = ip
|
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2018-05-03 16:37:18 +00:00
|
|
|
def send_message(message, count=1):
|
|
|
|
try:
|
2020-04-15 11:27:26 +00:00
|
|
|
sock = socket.socket()
|
|
|
|
sock.connect((IP, PORT))
|
|
|
|
sock.send(bytes(message, "utf-8"))
|
|
|
|
sock.close()
|
2018-05-03 16:37:18 +00:00
|
|
|
except ConnectionRefusedError:
|
2020-04-17 13:08:26 +00:00
|
|
|
logging.info("Connection Refused, please turn on service on mobile")
|
2018-05-03 16:37:18 +00:00
|
|
|
except TimeoutError:
|
2020-04-17 13:08:26 +00:00
|
|
|
logging.info("Timeout Error")
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
if count < RETRY_LIMIT:
|
|
|
|
send_message(message, count+1)
|
|
|
|
|
|
|
|
|
|
|
|
def sendHoleDeplete(count):
|
2020-04-15 11:27:26 +00:00
|
|
|
message = {"action": "holeDeplete", "fishCount": count}
|
2018-05-03 16:37:18 +00:00
|
|
|
jsonString = json.dumps(message)
|
|
|
|
send_message(jsonString)
|
|
|
|
|
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
initialize("192.168.0.192")
|
|
|
|
sendHoleDeplete(2)
|