Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GatewayHostName #64

Closed
AdamMachera opened this issue Jul 24, 2018 · 14 comments
Closed

GatewayHostName #64

AdamMachera opened this issue Jul 24, 2018 · 14 comments
Labels
bug Something isn't working customer-reported iotedge

Comments

@AdamMachera
Copy link

Unable to get device twin using GatewayHostName in .net framework 4.6.2 (When using .net core project application is able to download device twin.
The connection string that is used:
HostName=someiothub.azure-devices.net;DeviceId=21219-00260;SharedAccessKey=somekey;GatewayHostName=192.0.2.5

Expected Behavior

Behaviour should be same for .net core and application in .net framework 4.6.2

Current Behavior

When starting 462 application I don't see anything in edge logs.

If I run .net core application I see some logs that were attached to this issue.

Steps to Reproduce

Open DeviceTwinTester.sln and try getting device twin using .net core and later using .net framework 462 application.

Context (Environment)

Device (Host) Operating System

Windows 7 is connecting to iot edge to get device twin.
Iot edge is running on Ubuntu 18.04.

Architecture

amd64

Container Operating System

Runtime Versions

iotedged

iotedge 1.0.0 (52ef77d)

Edge Agent

mcr.microsoft.com/azureiotedge-agent:1.0

Edge Hub

mcr.microsoft.com/azureiotedge-hub:1.0

Docker

Client:
Version: 18.06.0-dev
API version: 1.37
Go version: go1.10.2
Git commit: daf021fe
Built: Mon Jun 25 21:07:53 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm

Server:
Engine:
Version: dev
API version: 1.37 (minimum version 1.12)
Go version: go1.10.2
Git commit: 9aac187
Built: Mon Jun 25 20:43:05 2018
OS/Arch: linux/amd64
Experimental: false

logWhenConnectedFromNetCore.txt
DeviceTwin.zip

Logs

Additional Information

@dsajanice
Copy link
Member

Thanks for reporting this. Is the .net framework application able to get its device twin directly from the cloud i.e. without the GatewayHostName?

@AdamMachera
Copy link
Author

Yes, if I run it locally on my machine and same connection string without providing GatewayHost name it works. In customer environment we can't have direct connection over mqtt to iothub hence using iotedge.

@dsajanice
Copy link
Member

dsajanice commented Jul 24, 2018

We have a known issue connecting from a .Net framework module to EdgeHub. This issue might be related to that. I am investigating further.

@dsajanice
Copy link
Member

I was able to reproduce the issue on my setup. What I observed is that connecting with Mqtt is causing an exception in EdgeHub and that is what is preventing the twin operation from succeeding. I would like to confirm that this is the same issue in your setup. Could you please check your EdgeHub logs (sudo docker logs edgeHub) to verify that an exception is being thrown when the device tries to get its twin.

A workaround for this issue is to use Amqp to connect. I verified that this works on my setup. Please let me know if you encounter further issues.

@dsajanice dsajanice added the bug Something isn't working label Jul 24, 2018
@dsajanice
Copy link
Member

I will file a bug for a leaf device not being to connect to EdgeHub using MQTT. @AdamMachera confirmed that .Net framework and .Net core leaf devices can connect to EdgeHub over AMQP.

@varunpuranik
Copy link
Contributor

This was related to this issue - Azure/azure-iot-sdk-csharp#558 (comment)
We have confirmed that with Device SDK 1.18.0, you can connect to using MQTT (with both .Net framework and .Net core).
@AdamMachera - Can you please try with Device SDK 1.18.0? If that works for you, we can close this issue.

@AdamMachera
Copy link
Author

It is still not working for MQTT for .net framework 4.6.2 after updating Microsoft.Azure.Device.Client to version 1.18.0.

SDK team can use this code to replicate this issue

       try
        {
            Console.WriteLine("Starting application");
            var connection = ConfigurationManager.AppSettings["IotHubConnectionString"];

            var client = DeviceClient.CreateFromConnectionString(connection, new ITransportSettings[]
            {
                new MqttTransportSettings(TransportType.Mqtt_Tcp_Only)
                {
                    RemoteCertificateValidationCallback = (sender, certificate, chain, errors) => true
                }
            });

            client.OperationTimeoutInMilliseconds = 30 * 1000;
            var twin = client.GetTwinAsync().Result;
            Console.WriteLine(twin.ToJson());
            Console.WriteLine("Starting application");
        }
        catch (Exception e)
        {
            Console.WriteLine($"Unable to get device twin: {e}");
        }

I received exception:
Unable to get device twin: System.AggregateException: One or more errors occurred. ---> System.TimeoutException: Operation timeout expired.
at Microsoft.Azure.Devices.Client.InternalClient.<>c.b__64_2(Task1 t) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result()
at DeviceTwinTester462LatestDeviceClient.Program.Main(String[] args) in c:\src\DeviceTwinTester462LatestDeviceClient\Program.cs:line 34
---> (Inner Exception #0) System.TimeoutException: Operation timeout expired.
at Microsoft.Azure.Devices.Client.InternalClient.<>c.b__64_2(Task1 t) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()<---

In the connection string

@varunpuranik
Copy link
Contributor

Hi Adam, We actually tested the scenario before we released and it did work for us. We will try again today with your code and get back to you.

@AdamMachera
Copy link
Author

Probably this is not relevant (if this was deviceclient sdk issue) but my iotedge is still using edgeHub and edgeAgent in version 1.0.0

@varunpuranik
Copy link
Contributor

So we ran the same code that you provided, and it connected fine. Can you try upgrading to EdgeHub 1.0.1, just in case?

Also, could there be any network issues that are preventing you from connecting? (like some firewall, ports, etc?).

Btw, you are using Linux containers, right?

@AdamMachera
Copy link
Author

I don't know what I'm doing wrong.
I'm connecting from windows machine to linux ubuntu 18.04 that is running on hyper-v.
I have both amqp and mqtt enabled

mcr.microsoft.com/azureiotedge-hub:1.0.1 "/bin/sh -c 'echo "$…" 6 minutes ago Up 6 minutes 0.0.0.0:443->443/tcp, 0.0.0.0:5671->5671/tcp, 0.0.0.0:8883->8883/tcp

I'm able to get device twin using amqp but unable to get it using mqtt.

@varunpuranik
Copy link
Contributor

Is there any exception on the EdgeHub, when you try to connect or get the twin?

@AdamMachera
Copy link
Author

It is throwing same exception - timeoutexception.
I also ruled out that this is firewall issue.
Using wireshark I'm able to check that for .net core and telnet communication is working over 8883
Trace for .net core
netcore2.1.pcap.zip

Trace for connecting using telnet on port 8883
telnet1.zip

For application running .net 4.6.2 and latest DeviceClient sdk I see no SYN and ACK packages being exchanged.

@AdamMachera
Copy link
Author

I did some further investigation.

On one windows 10 machine that was hosting iotedge on VM I was able to telnet on 8883, connect and get device twin.
On the second windows 10 that was hosting iotedge on VM I was able to telnet on 8883 but unable to connect with DeviceClient and get device twin.

Once I added on second machine to file c:\Windows\system32\drivers\etc\hosts entry
192.0.2.5 iotedge
everything worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working customer-reported iotedge
Projects
None yet
Development

No branches or pull requests

4 participants