<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to IIoT Library-Azure_IoT_Hub_Client_SL Conexion not possible</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/65da59c339/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/65da59c339/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/65da59c339/</id><updated>2022-09-02T07:52:10.928000Z</updated><subtitle>Recent posts to IIoT Library-Azure_IoT_Hub_Client_SL Conexion not possible</subtitle><entry><title>IIoT Library-Azure_IoT_Hub_Client_SL Conexion not possible</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/65da59c339/?limit=25#e13a" rel="alternate"/><published>2022-09-02T07:52:10.928000Z</published><updated>2022-09-02T07:52:10.928000Z</updated><author><name>alebrije</name><uri>https://forge.codesys.com/u/alebrije/</uri></author><id>https://forge.codesys.com42bb4d985aefa7ede0bb925f2216f3e31e10b78e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Update:&lt;br/&gt;
I mange to create a connection, but as soon as i am connected to the device, after one minute my Codesys Control Win service just stop. each and every time, any ideas why?&lt;br/&gt;
If anybody has an update also about the certificates and licences that are required to have this kind of communication, I will appreciate any help.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>IIoT Library-Azure_IoT_Hub_Client_SL Conexion not possible</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/65da59c339/?limit=25#32ac" rel="alternate"/><published>2022-09-01T06:22:08.278000Z</published><updated>2022-09-01T06:22:08.278000Z</updated><author><name>alebrije</name><uri>https://forge.codesys.com/u/alebrije/</uri></author><id>https://forge.codesys.com809f8cacd01e8822d40cefeefe64c653549ebe06</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;So I would like to implement this library into my project, I spent yesterday the whole day before deciding to write in this forum.&lt;br/&gt;
The situation is as follows:&lt;br/&gt;
First my setup: Codesys V3.18.20, I'm using Control win x64 V3.18.20, Azure portal and Azure IoT explorer&lt;br/&gt;
I am using the example project and another empty project with only the function block.&lt;/p&gt;
&lt;p&gt;First azure.&lt;br/&gt;
I created my IoT Hub Host name "HotTest.azure-devices.net", and there I created my device "TestDevice" which is enabled and the Authentication type is SaS.&lt;br/&gt;
In Azure IoT Explorer I am connected to the hub and i can see the Device and generate an SaS Token &lt;/p&gt;
&lt;p&gt;Codesys:&lt;/p&gt;
&lt;p&gt;I am using the example project with the function block &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;VAR&lt;/span&gt;
    &lt;span class="n"&gt;sSubDomainName&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'HotTest'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="s1"&gt;'YOUR_IOT_HUB_NAME'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;Azure&lt;/span&gt; &lt;span class="n"&gt;IoT&lt;/span&gt; &lt;span class="n"&gt;Hub&lt;/span&gt;
    &lt;span class="n"&gt;sDeviceId&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'TestDevice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="s1"&gt;'YOUR_DEVICE_NAME'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;
    &lt;span class="n"&gt;wsDeviceSaS&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;WSTRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;"SharedAccessSignature sr=HotTest.azure-devices.net%2Fdevices%2FTestDevice&amp;amp;sig=wXOzM%2BsWTGlcrMcAtD6kw3oLvTpCFiaq1KDoPqARHg8%3D&amp;amp;se=**********"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="ss"&gt;"SharedAccessSignature sr=YOUR_IOT_HUB_SAS_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;Your&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="n"&gt;SaS&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;needed&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c2d&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;d2c&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;azureMqttClient&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;AZURE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AzureMQTTClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;Function&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;establish&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;MQTT&lt;/span&gt; &lt;span class="k"&gt;connection&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;Azure&lt;/span&gt; &lt;span class="n"&gt;IoT&lt;/span&gt; &lt;span class="n"&gt;Hub&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;connection&lt;/span&gt; &lt;span class="n"&gt;via&lt;/span&gt; &lt;span class="n"&gt;MQTT&lt;/span&gt;
&lt;span class="n"&gt;azureMqttClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;    &lt;span class="n"&gt;xEnable&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;xConnect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;uiKeepAlive&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;sHubDomainName&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sSubDomainName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;sDeviceId&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sDeviceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;wsSaS&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wsDeviceSaS&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So my IoT Hub name is HotTest&lt;br/&gt;
My device is TestDevice&lt;br/&gt;
and the SaS connection string is as follows:&lt;br/&gt;
HostName=HotTest.azure-devices.net;DeviceId=TestDevice;SharedAccessSignature=SharedAccessSignature sr=HotTest.azure-devices.net%2Fdevices%2FTestDevice&amp;amp;sig=cxphNRGt%2BdqY0SwfOFzu2nz0eAYD711Qut3XpdAlmYQ%3D&amp;amp;se=&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;br/&gt;
(I am using &lt;/em&gt;&lt;/strong&gt;&lt;em&gt; at the end to protect the connection&lt;strong&gt;)&lt;br/&gt;
    So i read about the SaS token and notice that the part that is required is the one after SharedAccessSignature=:&lt;br/&gt;
SharedAccessSignature sr=HotTest.azure-devices.net%2Fdevices%2FTestDevice&amp;amp;sig=cxphNRGt%2BdqY0SwfOFzu2nz0eAYD711Qut3XpdAlmYQ%3D&amp;amp;se=&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;But after putting all the information that I mentioned before&lt;br/&gt;
The function block only shows the xBusy signal as TRUE and nothing more, no timeout error, no error, nothing!&lt;br/&gt;
And the documentation is not used with IoT explorer but with device explorer from azure which I could not find.&lt;br/&gt;
So I have the following questions:&lt;br/&gt;
* Is there any pre configuration required from my Codesys control / gateway? like permissions? or should be enough if its connected to the internet?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Is there something different that I need to do from azure side? The manuals show that this should be sufficient.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Extra:&lt;br/&gt;
I found an error in the example visualization, the field for the SaS token is linked to the Host name. Just for you to take it in count.&lt;/p&gt;
&lt;p&gt;I hope you can help me so I can connect my Codesys controller with my azure IoT Hub, let me know if you need more information.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br/&gt;
Alebrije&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>