Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Certificate failure fix #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion seeed/1-temperature-sensor/deployment.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.0.2",
"image": "mcr.microsoft.com/azureiotedge-hub:1.0",
"createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}], \"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
},
"env": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@

class HubManager(object):

def __init__(self, protocol = IoTHubTransportProvider.MQTT):
def __init__(self, connection_string = None, protocol = IoTHubTransportProvider.MQTT):
if not connection_string:
connection_string = os.environ['EdgeHubConnectionString']

print("\nPython %s\n" % sys.version)
print("IoT Hub Client for Python")
print("Starting the IoT Hub Python sample using protocol %s..." % protocol)

self.client_protocol = protocol
self.client = IoTHubModuleClient()
self.client.create_from_environment(protocol)

# set the time until a message times out
self.client.set_option("messageTimeout", MESSAGE_TIMEOUT)
# some embedded platforms need certificate information
self.set_certificates()

def set_certificates(self):
CERT_FILE = os.environ['EdgeModuleCACertificateFile']
print("Adding TrustedCerts from: {0}".format(CERT_FILE))

# this brings in x509 privateKey and certificate
with open(CERT_FILE) as file:
try:
self.client.set_option("TrustedCerts", file.read())
print("set_option TrustedCerts successful")
except IoTHubClientError as iothub_client_error:
print("set_option TrustedCerts failed (%s)" % iothub_client_error)
2 changes: 1 addition & 1 deletion seeed/2-image-classifier/deployment.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "microsoft/azureiotedge-hub:1.0-preview",
"image": "microsoft/azureiotedge-hub:1.0",
"createOptions": ""
}
}
Expand Down
2 changes: 1 addition & 1 deletion seeed/3-speech-recognizer/deployment.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.0.2",
"image": "mcr.microsoft.com/azureiotedge-hub:1.0",
"createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}], \"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
},
"env": {
Expand Down
18 changes: 16 additions & 2 deletions seeed/3-speech-recognizer/modules/speech-to-text/hubmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@

class HubManager(object):

def __init__(self, protocol = IoTHubTransportProvider.MQTT):
def __init__(self, connection_string = None, protocol = IoTHubTransportProvider.MQTT):
if not connection_string:
connection_string = os.environ['EdgeHubConnectionString']

print("\nPython %s\n" % sys.version)
print("IoT Hub Client for Python")
print("Starting the IoT Hub Python sample using protocol %s..." % protocol)

self.client_protocol = protocol
self.client = IoTHubModuleClient()
self.client.create_from_environment(protocol)

# set the time until a message times out
self.client.set_option("messageTimeout", MESSAGE_TIMEOUT)
# some embedded platforms need certificate information
self.set_certificates()

def set_certificates(self):
CERT_FILE = os.environ['EdgeModuleCACertificateFile']
print("Adding TrustedCerts from: {0}".format(CERT_FILE))

# this brings in x509 privateKey and certificate
with open(CERT_FILE) as file:
try:
self.client.set_option("TrustedCerts", file.read())
print("set_option TrustedCerts successful")
except IoTHubClientError as iothub_client_error:
print("set_option TrustedCerts failed (%s)" % iothub_client_error)
8 changes: 4 additions & 4 deletions seeed/3-speech-recognizer/modules/speech-to-text/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def mic_callback(text):
def get_response(text):
try:
res = requests.post('http://natural-language-processing:8080/chat', text)
if res.content and type(res.content) is str:
content = res.content.replace('"', '')
print('> {}'.format(content))
return content
if res.text and type(res.text) is str:
response_text = res.text.replace('"', '')
print('> {}'.format(response_text))
return response_text
except Exception as e:
print(e)

Expand Down