AWS Greengrass Integration with TeamViewer IoT - TeamViewer Support
<main>
<article class="userContent">
<p><em>This article applies to all the customers looking for AWS Integration with TeamViewer IoT Solution.</em></p><ul><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base-EN/AWS-Greengrass-Integration-with-TeamViewer-IoT/ta-p/84448#toc-hId--1326758052" rel="nofollow noreferrer ugc">General</a></li><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base-EN/AWS-Greengrass-Integration-with-TeamViewer-IoT/ta-p/84448#toc-hId--439254371" rel="nofollow noreferrer ugc">Requirements</a></li><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base-EN/AWS-Greengrass-Integration-with-TeamViewer-IoT/ta-p/84448#toc-hId-448249310" rel="nofollow noreferrer ugc">Installing AWS Greengrass</a></li><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base-EN/AWS-Greengrass-Integration-with-TeamViewer-IoT/ta-p/84448#toc-hId-1335752991" rel="nofollow noreferrer ugc">Lambda Functions on AWS IoT Greengrass</a></li><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base-EN/AWS-Greengrass-Integration-with-TeamViewer-IoT/ta-p/84448#toc-hId--2071710624" rel="nofollow noreferrer ugc">Further reading/Realated articles</a></li></ul><h2 data-id="general">General</h2><p>This article helps to establish communication between AWS Greengrass and IoT TV Cloud by publishing and subscribing data from teamviewer-iot-agent to aws greengrass platform and vice-versa.</p><h2 data-id="requirements">Requirements</h2><ul><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base/Install-TeamViewer-IoT-Agent/ta-p/17084" rel="nofollow noreferrer ugc">TeamViewer IoT Agent</a> installed and provisioned to an account. </li><li><a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Knowledge-Base/Edge-Device-Management-Real-Time-Edge-Visualization-amp-more/ta-p/37206" rel="nofollow noreferrer ugc">TeamViewer IoT Edge Management</a> installed on the edge device</li></ul><h2 data-id="installing-aws-greengrass">Installing AWS Greengrass </h2><p><strong>Configure AWS IoT Greengrass on AWS IoT</strong></p><ul><li>Sign in to the <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fconsole.aws.amazon.com%2F" rel="nofollow noreferrer ugc">AWS Management Console</a> on your computer and open the AWS IoT console. If this is your first time opening this console, select Get started. In the navigation pane, select <strong>Greengrass </strong>image</li></ul><p> </p><p><br></p><ul><li>On the <strong>Welcome to AWS IoT Greengrass</strong> page, select <strong>Create a Group</strong>. An AWS IoT Greengrass <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fdocs.aws.amazon.com%2Fgreengrass%2Flatest%2Fdeveloperguide%2Fwhat-is-gg.html%23gg-group" rel="nofollow noreferrer ugc">group</a> contains settings and other information about its components, such as devices, Lambda functions, and connectors. A group defines how its components can interact with each other.</li><li>Greengrass needs your permission to access other services dialog box, select <strong>Grant permission</strong> to allow the console to create or configure the Greengrass service role for you. </li></ul><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14340i9470C402D1273251.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14340i9470C402D1273251.jpg" alt="2.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<p><br></p><ul><li>On the <strong>Set up your Greengrass group</strong> page, select <strong>Use default creation</strong> to create a group.</li></ul><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14341iC2AF2A9390F92D9E.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14341iC2AF2A9390F92D9E.jpg" alt="3.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<p><br></p><ul><li>Enter a name for your group (for example, <code class="code codeInline" spellcheck="false" tabindex="0">MyFirstGroup</code>), and then select <strong>Next</strong>.</li></ul><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14342i55BA8530E9043A91.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14342i55BA8530E9043A91.jpg" alt="4.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<p><br></p><ul><li>Use the default name, and then select <strong>Next</strong>.</li><li>On the <strong>Review Group creation</strong> page, select <strong>Create Group and Core</strong>.</li></ul><p><br></p><ul><li>Download your core's security resources and configuration file. On the confirmation page, under <strong>Download and store your Core's security resources</strong>, choose <strong>Download these resources as a tar.gz</strong>. The name of your downloaded <code class="code codeInline" spellcheck="false" tabindex="0">tar.gz</code> file starts with a 10-digit hash that's also used for the certificate and key file names.</li></ul><p><br></p><ul><li>After you download the security resources, select <strong>Finish</strong>.</li></ul><p><br></p><ul><li>Download the <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fdocs.aws.amazon.com%2Fgreengrass%2Flatest%2Fdeveloperguide%2Fwhat-is-gg.html%23gg-core-download-tab" rel="nofollow noreferrer ugc">AWS IoT Greengrass Core software</a> installation package. select the CPU architecture and distribution (and operating system, if necessary) that best describe your core device. For example:</li></ul><p>For Raspberry Pi Model B or B+, download the Armv7l for Raspbian package.</p><ul><li>For an Amazon EC2 instance, download the x86_64 for Linux package.</li></ul><p><strong>Start AWS IoT Greengrass on the Edge Device</strong></p><p>In a <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fdocs.aws.amazon.com%2Fgreengrass%2Flatest%2Fdeveloperguide%2Fgg-config.html%23gg-core-download" rel="nofollow noreferrer ugc">previous step</a>, you downloaded two files to your computer:</p><ul><li><code class="code codeInline" spellcheck="false" tabindex="0">greengrass-<CODE class="replaceable">OS-architecture</code>-1.10.0.tar.gz. This compressed file contains the AWS IoT Greengrass Core software that runs on the edge device.</li><li><code class="code codeInline" spellcheck="false" tabindex="0"><CODE class="replaceable">hash</code>-setup.tar.gz (for example, <code class="code codeInline" spellcheck="false" tabindex="0">c6973960cc-setup.tar.gz</code>). This compressed file contains security certificates that enable secure communications between AWS IoT and the <code class="code codeInline" spellcheck="false" tabindex="0">config.json</code> file that contains configuration information specific to your AWS IoT Greengrass core and the AWS IoT endpoint.</li><li>Transfer the two compressed files from your local computer to the edge device. To transfer the compressed files from your computer to edge device, using file transfer feature .</li><li>Open a terminal on th edge edevice and navigate to the folder that contains the compressed files (for example, <code class="code codeInline" spellcheck="false" tabindex="0">cd /home/pi</code>).</li><li>Decompress the AWS IoT Greengrass Core software and the security resources.</li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">sudo tar -xzvf greengrass-OS-architecture-1.10.0.tar.gz -C /
sudo tar -xzvf hash-setup.tar.gz -C /greengrass
</pre><ul><li>Review <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fdocs.aws.amazon.com%2Fiot%2Flatest%2Fdeveloperguide%2Fserver-authentication.html" rel="nofollow noreferrer ugc">Server Authentication</a> in the <em>AWS IoT Developer Guide</em> and choose the appropriate root CA certificate. We recommend that you use Amazon Trust Services (ATS) endpoints and ATS root CA certificates. Certificates enable your device to communicate with AWS IoT using the MQTT messaging protocol over TLS.</li><li>For ATS endpoints (preferred), download the appropriate ATS root CA certificate. The following example downloads <code class="code codeInline" spellcheck="false" tabindex="0">AmazonRootCA1.pem</code>. The <code class="code codeInline" spellcheck="false" tabindex="0">wget -O</code> parameter is the capital letter O.</li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">cd /greengrass/certs/ sudo wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
</pre><ul><li>You can run the following command to confirm that the <code class="code codeInline" spellcheck="false" tabindex="0">root.ca.pem</code> file is not empty:<ul><li>cat root.ca.pem (If the <code class="code codeInline" spellcheck="false" tabindex="0">root.ca.pem</code> file is empty, check the <code class="code codeInline" spellcheck="false" tabindex="0">wget</code> URL and try again.)</li></ul></li><li>Start AWS IoT Greengrass on your edge device.</li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">cd /greengrass/ggc/core/
sudo ./greengrassd start
</pre><ul><li>You should see a <code class="code codeInline" spellcheck="false" tabindex="0">Greengrass successfully started</code> message. Make a note of the PID.</li><li>You can run the following command to confirm that the AWS IoT Greengrass Core software (Greengrass daemon) is functioning. Replace <code class="code codeInline" spellcheck="false" tabindex="0">PID-number</code> with your PID:</li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">ps aux | grep PID-number
</pre><h2 data-id="lambda-functions-on-aws-iot-greengrass">Lambda Functions on AWS IoT Greengrass</h2><p>User should copy/paste the code to their lambda function, get the metrics values and use greengrass sdk to push the data to the AWS. </p><p><strong>Don't forget to replace the paths, client id and sensor id with your own</strong> in the lambda functions described below.</p><ul><li>aws_iot_tv_pub: This lambda function subscribes data from mqtt-broker from edge device and publishes is to amazon cloud to the topic ‘tv/greengrass’. </li></ul><p>Below is the sample code attached for aws_iot_tv_pub:</p><pre class="code codeBlock" spellcheck="false" tabindex="0">#!/usr/bin/python
import paho.mqtt.subscribe as subscribe
import paho.mqtt.publish as publish
import traceback
import json
def function_handler(event, context):
return
# AWS part
# Change following parameters
aws_host = "a10kx625z9icrs-ats.iot.eu-central-1.amazonaws.com" # Endpoint
aws_port = 8883
aws_tls = {'certfile': "/home/pi/Downloads/certs/1b9a6e0dcb.cert.pem",
'keyfile': "/home/pi/Downloads/certs/1b9a6e0dcb.private.key",
'ca_certs': "/home/pi/Downloads/certs/root.ca.pem"
}
# TV part
#Change following parameters
tv_iot_api_version = "v1.0"
tv_host = "localhost"
tv_port = 18884
tv_tls = {'certfile': "/home/pi/Downloads/test_client_greengrass/cert-7a2b7efc1ad1473d87e049517a19628b.pem",
'keyfile': "/home/pi/Downloads/test_client_greengrass/key-7a2b7efc1ad1473d87e049517a19628b.pem",
'ca_certs': "/home/pi/Downloads/test_client_greengrass/TeamViewerAuthority.crt"}
client_id = "fd9e67783b7441ffb7cd62dda121567a"
sensor_id = "111804"
def subscribe_data():
try:
mqtt_topic_subscribe_data = "/" + tv_iot_api_version + "/" + client_id + "/sensor/" + sensor_id + "/livedata"
print("Suscribing to " + mqtt_topic_subscribe_data)
subscribe.callback(on_subscribe, mqtt_topic_subscribe_data, hostname=tv_host, port=tv_port, tls=tv_tls)
except Exception as e:
traceback.print_exc()
print(str(e))
def on_subscribe(client, userdata, message):
json_message = json.loads(message.payload.decode('utf8'))
msgArr = []
for metric in json_message["metrics"]:
messageJ = {}
messageJ['metricId'] = metric["metricId"]
messageJ['metricValue'] = metric["value"]
msgArr.append(messageJ)
msgs = []
msgs.append({'topic': "tv/greengrass", 'payload': json.dumps(msgArr)})
print(msgs)
publish.multiple(msgs, hostname=aws_host, port=aws_port, tls=aws_tls)
subscribe_data()
</pre><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14347i78DF375403960F31.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14347i78DF375403960F31.jpg" alt="8.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<ul><li>aws_iot_tv_sub: This lambda function subscribes the data from amazon cloud and pushes the data to teamviewer metrics and real-time data can be visualized on edge and teamviewer-cloud dashboard.</li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">#!/usr/bin/python
import paho.mqtt.subscribe as subscribe
import paho.mqtt.publish as publish
import traceback
import json
import ssl
def function_handler(event, context):
return
# AWS part
# Change following parameters
aws_host = "a10kx625z9icrs-ats.iot.eu-central-1.amazonaws.com" # Endpoint
aws_port = 8883
aws_tls = {'certfile': "/home/pi/Downloads/certs/1b9a6e0dcb.cert.pem",
'keyfile': "/home/pi/Downloads/certs/1b9a6e0dcb.private.key",
'ca_certs': "/home/pi/Downloads/certs/root.ca.pem",
'tls_version': ssl.PROTOCOL_TLSv1_2
}
# TV part
#Change following parameters
tv_iot_api_version = "v1.0"
tv_host = "localhost"
tv_port = 18884
tv_tls = {'certfile': "/home/pi/Downloads/test_client_greengrass/cert-7a2b7efc1ad1473d87e049517a19628b.pem",
'keyfile': "/home/pi/Downloads/test_client_greengrass/key-7a2b7efc1ad1473d87e049517a19628b.pem",
'ca_certs': "/home/pi/Downloads/test_client_greengrass/TeamViewerAuthority.crt"}
client_id = "7a2b7efc1ad1473d87e049517a19628b"
sensor_id = "71b91c40fb2d4f61bec2fa593172085d"
def aws_subscribe():
print("Suscribing to tv/greengrassSub")
subscribe.callback(on_subscribe, "tv/greengrassSub", hostname=aws_host, port=aws_port, tls=aws_tls)
def on_subscribe(client, userdata, message):
try:
metric_data = json.loads(message.payload.decode('utf8'))
mqtt_topic_push_data = "/" + tv_iot_api_version + "/" + client_id + "/sensor/" + sensor_id + "/metric/pushValues"
# metric_data = {"metrics": [{"value": 1, "metricId": "7ad8ad3e2dbe4cdcba0ee3ec0cbd2717"}]}
msgs = []
msgs.append({'topic': mqtt_topic_push_data, 'payload': json.dumps(metric_data)})
print(msgs)
publish.multiple(msgs, hostname=tv_host, port=tv_port, tls=tv_tls)
except Exception as e:
traceback.print_exc()
print(str(e))
aws_subscribe()
</pre><h2 data-id="further-readingrealated-articles">Further reading/Realated articles</h2><ul><li>For Troubleshooting purposes click <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fdocs.aws.amazon.com%2Fgreengrass%2Flatest%2Fdeveloperguide%2Fgg-troubleshooting.html" rel="nofollow noreferrer ugc">here </a>and <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fwww.apdaga.com%2F2018%2F02%2Finstall-aws-amazon-sdk-on-raspberry-pi.htmlhttps%3A%2F%2Fwww.apdaga.com%2F2018%2F02%2Finstall-aws-amazon-sdk-on-raspberry-pi.html" rel="nofollow noreferrer ugc">here</a></li></ul><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14346iF18F557791DC122E.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14346iF18F557791DC122E.jpg" alt="7.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<p><br></p><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14345iB6F3DBD08E334260.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/14345iB6F3DBD08E334260.jpg" alt="6.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<p><br></p><div class="embedExternal embedImage display-large float-none">
<div class="embedExternal-content">
<a class="embedImage-link" href="https://us.v-cdn.net/6032394/uploads/lithium_attachments/15388i1E95AEA34BB2AC32.jpg" rel="nofollow noreferrer noopener ugc" target="_blank">
<img class="embedImage-img" src="https://us.v-cdn.net/6032394/uploads/lithium_attachments/15388i1E95AEA34BB2AC32.jpg" alt="pic_1.PNG" height="180" width="320" loading="lazy" data-display-size="large" data-float="none"></img></a>
</div>
</div>
<p><br></p>
</article>
</main>