import RPi.GPIO as GPIO
import time
import datetime
from random import randint
import sc2
import socket

sc2.init()

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print("Socket Created")

host = '10.1.1.13'
port = 1688
time.sleep(5)
s.connect((host,port))

i = 0
mode = 2
while True:
    
    data = s.recv(1024)
    recvdata = str(data.decode('utf-8'))

    if data:
       mode=mode+1
       mode=mode%3
    
    data = "Hi"
    if mode == 0:
        sc2.showTime()
        s.sendall(data.encode('utf-8'))
    elif mode ==1:
        sc2.countDown()
        mode=mode+1
    elif mode ==2:
        data = "start"
        s.sendall(data.encode('utf-8'))
        data = "hi"
        time.sleep(290)
        s.sendall(data.encode('utf-8'))
        time.sleep(98)
        s.sendall(data.encode('utf-8'))
        time.sleep(1594)
        s.sendall(data.encode('utf-8'))
        time.sleep(374)
        s.sendall(data.encode('utf-8'))
        time.sleep(1086)
        s.sendall(data.encode('utf-8'))
        time.sleep(4415)
        s.sendall(data.encode('utf-8'))
        time.sleep(2019)
        s.sendall(data.encode('utf-8'))
        time.sleep(5751)
        s.sendall(data.encode('utf-8'))
        time.sleep(1750)
        s.sendall(data.encode('utf-8'))
        time.sleep(108)
        s.sendall(data.encode('utf-8'))
        time.sleep(467)
        s.sendall(data.encode('utf-8'))
        time.sleep(363)
        s.sendall(data.encode('utf-8'))
        time.sleep(1011)
        s.sendall(data.encode('utf-8'))
        time.sleep(255)
        s.sendall(data.encode('utf-8'))
        time.sleep(1927)
        s.sendall(data.encode('utf-8'))
        time.sleep(766)
        s.sendall(data.encode('utf-8'))
        time.sleep(1248)
        s.sendall(data.encode('utf-8'))
        time.sleep(981)
        s.sendall(data.encode('utf-8'))
        time.sleep(988)
        s.sendall(data.encode('utf-8'))
        time.sleep(1472)
        s.sendall(data.encode('utf-8'))
        time.sleep(1454)
        s.sendall(data.encode('utf-8'))
        time.sleep(996)
        s.sendall(data.encode('utf-8'))
        time.sleep(977)
        s.sendall(data.encode('utf-8'))
        time.sleep(952)
        s.sendall(data.encode('utf-8'))
        time.sleep(1012)
        s.sendall(data.encode('utf-8'))
        time.sleep(1013)
        s.sendall(data.encode('utf-8'))
        time.sleep(1940)
        s.sendall(data.encode('utf-8'))
        time.sleep(986)
        s.sendall(data.encode('utf-8'))
        time.sleep(988)
        s.sendall(data.encode('utf-8'))
        time.sleep(1482)
        s.sendall(data.encode('utf-8'))
        time.sleep(1444)
        s.sendall(data.encode('utf-8'))
        time.sleep(998)
        s.sendall(data.encode('utf-8'))
        time.sleep(1722)
        s.sendall(data.encode('utf-8'))
        time.sleep(1250)
        s.sendall(data.encode('utf-8'))
        time.sleep(995)
        s.sendall(data.encode('utf-8'))
        time.sleep(937)
        s.sendall(data.encode('utf-8'))
        time.sleep(1010)
        s.sendall(data.encode('utf-8'))
        time.sleep(952)
        s.sendall(data.encode('utf-8'))
        time.sleep(985)
        s.sendall(data.encode('utf-8'))
        time.sleep(1993)
        s.sendall(data.encode('utf-8'))
        time.sleep(950)
        s.sendall(data.encode('utf-8'))
        time.sleep(997)
        s.sendall(data.encode('utf-8'))
        time.sleep(1510)
        s.sendall(data.encode('utf-8'))
        time.sleep(1460)
        s.sendall(data.encode('utf-8'))
        time.sleep(998)
        s.sendall(data.encode('utf-8'))
        time.sleep(1915)
        s.sendall(data.encode('utf-8'))
        time.sleep(374)
        s.sendall(data.encode('utf-8'))
        time.sleep(1603)
        s.sendall(data.encode('utf-8'))
        time.sleep(371)
        s.sendall(data.encode('utf-8'))
        time.sleep(383)
        s.sendall(data.encode('utf-8'))
        time.sleep(1226)
        s.sendall(data.encode('utf-8'))
        time.sleep(1953)
        s.sendall(data.encode('utf-8'))
        time.sleep(2990)
        s.sendall(data.encode('utf-8'))
        time.sleep(941)
        s.sendall(data.encode('utf-8'))
        time.sleep(1007)
        s.sendall(data.encode('utf-8'))
        time.sleep(515)
        s.sendall(data.encode('utf-8'))
        time.sleep(1705)
        s.sendall(data.encode('utf-8'))
        time.sleep(738)
        s.sendall(data.ncode('utf-8'))
        time.sleep(981)
        s.sendall(data.encode('utf-8'))
        time.sleep(1925)
        s.sendall(data.encode('utf-8'))
        time.sleep(1012)
        s.sendall(data.encode('utf-8'))
        time.sleep(1469)
        s.sendall(data.encode('utf-8'))
        time.sleep(531)
        s.sendall(data.encode('utf-8'))
        time.sleep(951)
        s.sendall(data.encode('utf-8'))
        time.sleep(1001)
        s.sendall(data.encode('utf-8'))
        time.sleep(2978)
        s.sendall(data.encode('utf-8'))
        time.sleep(946)
        s.sendall(data.encode('utf-8'))
        time.sleep(1709)
        s.sendall(data.encode('utf-8'))
        time.sleep(1249)
        s.sendall(data.encode('utf-8'))
        time.sleep(998)
        s.sendall(data.encode('utf-8'))
        time.sleep(986)
        s.sendall(data.encode('utf-8'))
        time.sleep(983)
        s.sendall(data.encode('utf-8'))
        time.sleep(931)
        s.sendall(data.encode('utf-8'))
        time.sleep(1013)
        s.sendall(data.encode('utf-8'))
        time.sleep(1962)
        s.sendall(data.encode('utf-8'))
        time.sleep(976)
        s.sendall(data.encode('utf-8'))
        time.sleep(999)
        s.sendall(data.encode('utf-8'))
        time.sleep(1494)
        s.sendall(data.encode('utf-8'))
        time.sleep(465)
        s.sendall(data.encode('utf-8'))
        time.sleep(1011)
        s.sendall(data.encode('utf-8'))
        time.sleep(987)
        s.sendall(data.encode('utf-8'))
        time.sleep(2299)
        s.sendall(data.encode('utf-8'))
        time.sleep(1637)
        s.sendall(data.encode('utf-8'))
        time.sleep(2701)
        s.sendall(data.encode('utf-8'))
        time.sleep(1560)
        s.sendall(data.encode('utf-8'))
        time.sleep(386)
        s.sendall(data.encode('utf-8'))
        time.sleep(368)
        s.sendall(data.encode('utf-8'))
        time.sleep(374)
        s.sendall(data.encode('utf-8'))
        data = "end"
        time.sleep(1000)
        s.sendall(data.encode('utf-8'))
conn.close()
