Skip to content

Commit

Permalink
ComunicacaoComServer
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSirtoriCorrea committed Jun 3, 2020
1 parent 883a9bf commit 8fd8f27
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Configurations.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 0 additions & 8 deletions Server/Configurations.py
Original file line number Diff line number Diff line change
@@ -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']
Expand Down
22 changes: 16 additions & 6 deletions Server/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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---')

Expand All @@ -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:
Expand All @@ -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

Expand Down
Binary file modified Server/__pycache__/Configurations.cpython-36.pyc
Binary file not shown.
76 changes: 76 additions & 0 deletions Sexta-Feira(A.I.)/Functions.py
Original file line number Diff line number Diff line change
@@ -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)






11 changes: 11 additions & 0 deletions Sexta-Feira(A.I.)/Sexta-Feira(A.I.).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Functions

server = Functions.ServerConnection()

msg = {
'header': 'gazeboindustries09082004',
'request': 'getDevicesJsons'
}


#print(server.send(msg))
Binary file not shown.

0 comments on commit 8fd8f27

Please sign in to comment.