From 54e838cee406313c55daddcf82eaa3710a97613e Mon Sep 17 00:00:00 2001 From: 4or5trees <4or5trees@github.com> Date: Sun, 3 Mar 2019 16:01:52 +0100 Subject: [PATCH 1/2] certificate failure fixes for tutorial 1 --- .../deployment.template.json | 2 +- .../modules/temperature-sensor/hubmanager.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/seeed/1-temperature-sensor/deployment.template.json b/seeed/1-temperature-sensor/deployment.template.json index d0bf0d2..985fdfe 100644 --- a/seeed/1-temperature-sensor/deployment.template.json +++ b/seeed/1-temperature-sensor/deployment.template.json @@ -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": { diff --git a/seeed/1-temperature-sensor/modules/temperature-sensor/hubmanager.py b/seeed/1-temperature-sensor/modules/temperature-sensor/hubmanager.py index 18119e8..b9224e0 100644 --- a/seeed/1-temperature-sensor/modules/temperature-sensor/hubmanager.py +++ b/seeed/1-temperature-sensor/modules/temperature-sensor/hubmanager.py @@ -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) From ccccc1c7a4557a02a5ed32ed33d8f2c014c8a526 Mon Sep 17 00:00:00 2001 From: 4or5trees <4or5trees@github.com> Date: Sun, 3 Mar 2019 16:18:33 +0100 Subject: [PATCH 2/2] fixes for certiicate failure in tutorial 3; NLP module response bug fix --- .../deployment.template.json | 2 +- .../deployment.template.json | 2 +- .../modules/speech-to-text/hubmanager.py | 18 ++++++++++++++++-- .../modules/speech-to-text/main.py | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/seeed/2-image-classifier/deployment.template.json b/seeed/2-image-classifier/deployment.template.json index a31e4a0..e518d1e 100644 --- a/seeed/2-image-classifier/deployment.template.json +++ b/seeed/2-image-classifier/deployment.template.json @@ -23,7 +23,7 @@ "status": "running", "restartPolicy": "always", "settings": { - "image": "microsoft/azureiotedge-hub:1.0-preview", + "image": "microsoft/azureiotedge-hub:1.0", "createOptions": "" } } diff --git a/seeed/3-speech-recognizer/deployment.template.json b/seeed/3-speech-recognizer/deployment.template.json index cc3c57c..0451a5b 100644 --- a/seeed/3-speech-recognizer/deployment.template.json +++ b/seeed/3-speech-recognizer/deployment.template.json @@ -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": { diff --git a/seeed/3-speech-recognizer/modules/speech-to-text/hubmanager.py b/seeed/3-speech-recognizer/modules/speech-to-text/hubmanager.py index 18119e8..b9224e0 100644 --- a/seeed/3-speech-recognizer/modules/speech-to-text/hubmanager.py +++ b/seeed/3-speech-recognizer/modules/speech-to-text/hubmanager.py @@ -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) diff --git a/seeed/3-speech-recognizer/modules/speech-to-text/main.py b/seeed/3-speech-recognizer/modules/speech-to-text/main.py index 3ea8176..91d24b0 100644 --- a/seeed/3-speech-recognizer/modules/speech-to-text/main.py +++ b/seeed/3-speech-recognizer/modules/speech-to-text/main.py @@ -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)