diff --git a/Configurations.json b/Configurations.json index 7c095fc..8efcca3 100644 --- a/Configurations.json +++ b/Configurations.json @@ -1,10 +1,12 @@ { "FridayConfigs": { - "ID": "Sexta-Feira" + "ID": "Sexta-Feira", + "ServerHost": "gazeboindustries.hopto.org", + "Port": 5000 }, "ServerConfigs": { "ID": "Server", - "Host": "localhost", + "Host": "192.168.0.4", "Port": 5000 }, "InterfaceConfigs": { diff --git a/Server/Configurations.py b/Server/Configurations.py index 5f71b1b..49e954f 100644 --- a/Server/Configurations.py +++ b/Server/Configurations.py @@ -1,13 +1,5 @@ import json -def fridayConfigs(): - file = open('Configurations.json', 'r') - return json.load(file)['FridayConfigs'] - -def interfaceConfigs(): - file = open('Configurations.json', 'r') - return json.load(file)['InterfaceConfigs'] - def serverConfigs(): file = open('Configurations.json', 'r') return json.load(file)['ServerConfigs'] diff --git a/Server/Server.py b/Server/Server.py index 06d21d1..d7191eb 100644 --- a/Server/Server.py +++ b/Server/Server.py @@ -5,10 +5,12 @@ configs = serverConfigs() -host = configs['Host'] -port = configs['Port'] +#host = configs['Host'] +#port = configs['Port'] + +host = '192.168.0.5' +port = 3000 -print(configs['ID']) print('---SERVER STARTED---') @@ -21,7 +23,7 @@ def handle(self): print(f'Connected by {self.client_address} at {dateTimeNow.hour}:{dateTimeNow.minute} ') while True: - data = self.request.recv(1024).decode('utf-8') + data = self.request.recv(1024).decode() print(data) try: @@ -30,8 +32,16 @@ def handle(self): if clientRequest['header'] == 'gazeboindustries09082004': - if clientRequest['request'] == 'startFriday': - print(dataBaseConnection.getDevices()) + if clientRequest['request'] == 'getDevicesJsons': + devicesJsons = dataBaseConnection.getDevices() + devicesIndex = list() + + for deviceIndex in range(1, len(devicesJsons)+1): + devicesIndex.append('Device ' + str(deviceIndex)) + + device = dict(zip(devicesIndex, devicesJsons)) + print(device) + self.request.send(json.dumps(device).encode()) else: break diff --git a/Server/__pycache__/Configurations.cpython-36.pyc b/Server/__pycache__/Configurations.cpython-36.pyc index 081c6d6..8ced3a0 100644 Binary files a/Server/__pycache__/Configurations.cpython-36.pyc and b/Server/__pycache__/Configurations.cpython-36.pyc differ diff --git a/Sexta-Feira(A.I.)/Functions.py b/Sexta-Feira(A.I.)/Functions.py new file mode 100644 index 0000000..8d99773 --- /dev/null +++ b/Sexta-Feira(A.I.)/Functions.py @@ -0,0 +1,76 @@ +import speech_recognition as sr +import pyttsx3, random, json +from unicodedata import normalize +from socket import socket, AF_INET, SOCK_STREAM + +def Recognition(): + recognizer = sr.Recognizer() + + with sr.Microphone() as source: + recognizer.adjust_for_ambient_noise(source) + + print('Say:') + + sound = recognizer.listen(source) + speech = recognizer.recognize_google(sound, language='pt').lower() + print('You said: ', speech) + + return ' ' + speech + ' ' + +def speak(text): + speaker = pyttsx3.init('sapi5') + speaker.say(text) + speaker.runAndWait() + +def responseSelector(): + return random.randint(3, 5) + +def languageUnderstanding(phrase): + phraseFilter = [' o ', ' a ', ' os ', ' as ', ' um ', ' uma ', ' uns ', ' umas ', ' ante ', ' apos ', + ' ate ', ' com ',' contra ', ' de ' , + ' desde ', ' entre ', ' para ', ' perante ', ' por ', ' sem ', ' sob ', ' sobre ', + ' como ', ' e ', ' ainda ', ' tambem ', ' contudo ', ' entretanto ', ' mas ', ' entanto ', + ' porem ', ' todavia ', ' assim ', ' entao ', ' logo ', ' pois ', ' porque ', ' por ', + ' que ', ' para ', ' no ',' na '] + + phraseFiltered = normalize('NFKD', phrase).encode('ASCII', 'ignore').decode('ASCII') + + for word in phraseFilter: + if word in phraseFiltered: + phraseFiltered = phraseFiltered.replace(word, ' ') + + print('Filtered: ', phraseFiltered) + return phraseFiltered + + +class ServerConnection: + def __init__(self): + file = open('E:/Sexta-Feira-Mark_6/Configurations.json', 'r') + configs = json.load(file)['FridayConfigs'] + + self.connection = socket(AF_INET, SOCK_STREAM, 0) + #connection.connect((configs['ServerHost'], configs['Port'] )) + self.connection.connect(('192.168.0.5', 3000 )) + + message = json.dumps({ + 'header': 'gazeboindustries09082004', + 'request': 'getDevicesJsons' + + }).encode() + + self.connection.send(message) + + self.devicesJson = json.loads(self.connection.recv(1024).decode()) + + def send(self, dict): + message = json.dumps(dict).encode() + + self.connection.send(message) + + return self.connection.recv(1024) + + + + + + diff --git a/Sexta-Feira(A.I.)/Sexta-Feira(A.I.).py b/Sexta-Feira(A.I.)/Sexta-Feira(A.I.).py new file mode 100644 index 0000000..fb1b54b --- /dev/null +++ b/Sexta-Feira(A.I.)/Sexta-Feira(A.I.).py @@ -0,0 +1,11 @@ +import Functions + +server = Functions.ServerConnection() + +msg = { + 'header': 'gazeboindustries09082004', + 'request': 'getDevicesJsons' + } + + +#print(server.send(msg)) \ No newline at end of file diff --git a/Sexta-Feira(A.I.)/__pycache__/Functions.cpython-36.pyc b/Sexta-Feira(A.I.)/__pycache__/Functions.cpython-36.pyc new file mode 100644 index 0000000..3ac72ec Binary files /dev/null and b/Sexta-Feira(A.I.)/__pycache__/Functions.cpython-36.pyc differ