{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/iotedgehubdev/issues/143","repository_url":"https://api.github.com/repos/Azure/iotedgehubdev","labels_url":"https://api.github.com/repos/Azure/iotedgehubdev/issues/143/labels{/name}","comments_url":"https://api.github.com/repos/Azure/iotedgehubdev/issues/143/comments","events_url":"https://api.github.com/repos/Azure/iotedgehubdev/issues/143/events","html_url":"https://github.com/Azure/iotedgehubdev/issues/143","id":391485965,"node_id":"MDU6SXNzdWUzOTE0ODU5NjU=","number":143,"title":"Device impersonation does not send event to IoT Hub","user":{"login":"fbeltrao","id":227765,"node_id":"MDQ6VXNlcjIyNzc2NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/227765?v=4","gravatar_id":"","url":"https://api.github.com/users/fbeltrao","html_url":"https://github.com/fbeltrao","followers_url":"https://api.github.com/users/fbeltrao/followers","following_url":"https://api.github.com/users/fbeltrao/following{/other_user}","gists_url":"https://api.github.com/users/fbeltrao/gists{/gist_id}","starred_url":"https://api.github.com/users/fbeltrao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbeltrao/subscriptions","organizations_url":"https://api.github.com/users/fbeltrao/orgs","repos_url":"https://api.github.com/users/fbeltrao/repos","events_url":"https://api.github.com/users/fbeltrao/events{/privacy}","received_events_url":"https://api.github.com/users/fbeltrao/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-16T17:05:29Z","updated_at":"2019-01-03T07:15:27Z","closed_at":"2019-01-03T07:15:27Z","author_association":"NONE","body":"In a module that impersonates leaf devices, sending device to cloud messages does not seem to work. All other operations seem to work (get twin, update twin, c2d messages).\r\n\r\nSee the sample module located at: https://github.com/fbeltrao/Samples/tree/master/IoTEdgeHubDevD2C/iotedgehubdevd2c\r\n\r\nWhat the sample module does:\r\n\r\n- While true\r\n  - Creates a `DeviceClient` connection, gets twin, updates twin, gets c2d message, sends d2c message\r\n  - Every 3 executions of the loop it will switch between connecting through edgeHubDev or not (adding `;GatewayHostName=localhost` to connection string).\r\n\r\nExpected behavior is that device to cloud messages would arrive in IoT Hub, but they don't. They do arrive when not connecting through edgeHubDev. It is important to notice that I am running the sample from a Mac, where the ca certificate had to be added to keychain.\r\n\r\n**Module logs**\r\n\r\n```text\r\n-------------------------------------------------------------------\r\nYou may only use the Microsoft .NET Core Debugger (vsdbg) with\r\nVisual Studio Code, Visual Studio or Visual Studio for Mac software\r\nto help you develop and test your applications.\r\n-------------------------------------------------------------------\r\nIoT Hub module client initialized.\r\n[Gateway: True] Device client created\r\n[Gateway: True] Twin properties read, counter: 0\r\n[Gateway: True] Reported properties updated, counter: 1\r\n[Gateway: True] Sent event 1 <- THIS DOES NOT REACH IOT HUB\r\n[Gateway: True] Device client created\r\n[Gateway: True] Twin properties read, counter: 1\r\n[Gateway: True] Reported properties updated, counter: 2\r\n[Gateway: True] Sent event 2 <- THIS DOES NOT REACH IOT HUB\r\n[Gateway: False] Device client created\r\n[Gateway: False] Twin properties read, counter: 2\r\n[Gateway: False] Reported properties updated, counter: 3\r\n[Gateway: False] Sent event 3 <- THIS DOES REACH IOT HUB\r\n[Gateway: False] Device client created\r\n[Gateway: False] Twin properties read, counter: 3\r\n[Gateway: False] Reported properties updated, counter: 4\r\n[Gateway: False] Sent event 4 <- THIS DOES REACH IOT HUB\r\nThe program '[4944] TransparentGatewayModule.dll' has exited with code 0 (0x0).\r\n```\r\n\r\n\r\n**edgeHubDev logs**\r\n\r\n```text\r\n2018-12-16 16:44:34.151 +00:00 [INF] - New token received on the Cbs link\r\n2018-12-16 16:44:34.152 +00:00 [INF] - Client fbesimulatededge/target in device scope authenticated locally.\r\n2018-12-16 16:44:34.152 +00:00 [INF] - Token updated for fbesimulatededge/target\r\n2018-12-16 16:44:34.239 +00:00 [INF] - New device connection for device fbesimulatededge/target\r\n2018-12-16 16:44:34.239 +00:00 [INF] - Bind device proxy for device fbesimulatededge/target\r\n2018-12-16 16:44:34.239 +00:00 [INF] - Initialized AMQP connection handler for fbesimulatededge/target\r\n2018-12-16 16:44:34.239 +00:00 [INF] - Opened link Events for fbesimulatededge/target\r\n2018-12-16 16:44:47.060 +00:00 [INF] - New token received on the Cbs link\r\n2018-12-16 16:44:47.250 +00:00 [WRN] - Received null device scope result for iotedgehubdev4test2\r\n2018-12-16 16:44:47.250 +00:00 [INF] - Service identity for iotedgehubdev4test2 was removed from device scope, dropping client connection.\r\n2018-12-16 16:44:47.250 +00:00 [INF] - Attempting to connect to IoT Hub for client iotedgehubdev4test2 via AMQP...\r\n2018-12-16 16:44:47.463 +00:00 [INF] - New token requested by client iotedgehubdev4test2, but using existing token as it is usable.\r\n2018-12-16 16:44:47.709 +00:00 [INF] - Cloud connection for iotedgehubdev4test2 is True\r\n2018-12-16 16:44:47.709 +00:00 [INF] - Created cloud proxy for client iotedgehubdev4test2 via AMQP, with client operation timeout 20000.\r\n2018-12-16 16:44:47.709 +00:00 [INF] - Initialized cloud proxy 9158d707-1c2b-4b1a-92d1-d28044b6cc76 for iotedgehubdev4test2\r\n2018-12-16 16:44:47.709 +00:00 [INF] - Created cloud connection for client iotedgehubdev4test2\r\n2018-12-16 16:44:47.709 +00:00 [INF] - New cloud connection created for device iotedgehubdev4test2\r\n2018-12-16 16:44:47.709 +00:00 [INF] - Authenticated iotedgehubdev4test2 with IotHub\r\n2018-12-16 16:44:47.709 +00:00 [INF] - Token updated for iotedgehubdev4test2\r\n2018-12-16 16:44:47.740 +00:00 [INF] - New device connection for device iotedgehubdev4test2\r\n2018-12-16 16:44:47.740 +00:00 [INF] - Bind device proxy for device iotedgehubdev4test2\r\n2018-12-16 16:44:47.740 +00:00 [INF] - Initialized AMQP connection handler for iotedgehubdev4test2\r\n2018-12-16 16:44:47.740 +00:00 [INF] - Opened link TwinReceiving for iotedgehubdev4test2\r\n2018-12-16 16:44:47.746 +00:00 [INF] - Processing subscription DesiredPropertyUpdates for client iotedgehubdev4test2.\r\n2018-12-16 16:44:47.834 +00:00 [INF] - Opened link TwinSending for iotedgehubdev4test2\r\n2018-12-16 16:44:50.649 +00:00 [INF] - Processing subscription C2D for client iotedgehubdev4test2.\r\n2018-12-16 16:44:50.649 +00:00 [INF] - Start listening for C2D messages for device iotedgehubdev4test2\r\n2018-12-16 16:44:50.649 +00:00 [INF] - Opened link C2D for iotedgehubdev4test2\r\n2018-12-16 16:44:52.750 +00:00 [INF] - Opened link Events for iotedgehubdev4test2\r\n2018-12-16 16:44:56.868 +00:00 [INF] - Closing link Events for iotedgehubdev4test2\r\n2018-12-16 16:44:56.869 +00:00 [INF] - Closing link C2D for iotedgehubdev4test2\r\n2018-12-16 16:44:56.886 +00:00 [INF] - Closing link TwinSending for iotedgehubdev4test2\r\n2018-12-16 16:44:56.887 +00:00 [INF] - Closing link TwinReceiving for iotedgehubdev4test2\r\n2018-12-16 16:44:56.887 +00:00 [INF] - Setting proxy inactive for iotedgehubdev4test2.\r\n2018-12-16 16:44:56.887 +00:00 [INF] - Device connection removed for device iotedgehubdev4test2\r\n2018-12-16 16:44:56.887 +00:00 [INF] - Remove device connection for device iotedgehubdev4test2\r\n2018-12-16 16:44:57.103 +00:00 [INF] - New token received on the Cbs link\r\n2018-12-16 16:44:57.103 +00:00 [INF] - Attempting to connect to IoT Hub for client iotedgehubdev4test2 via AMQP...\r\n2018-12-16 16:44:57.103 +00:00 [INF] - New token requested by client iotedgehubdev4test2, but using existing token as it is usable.\r\n2018-12-16 16:44:57.296 +00:00 [INF] - Cloud connection for iotedgehubdev4test2 is True\r\n2018-12-16 16:44:57.296 +00:00 [INF] - Created cloud proxy for client iotedgehubdev4test2 via AMQP, with client operation timeout 20000.\r\n2018-12-16 16:44:57.296 +00:00 [INF] - Initialized cloud proxy c9114eee-71cb-435d-8ca9-d7cb643219c0 for iotedgehubdev4test2\r\n2018-12-16 16:44:57.296 +00:00 [INF] - Closing receiver in cloud proxy 9158d707-1c2b-4b1a-92d1-d28044b6cc76 for iotedgehubdev4test2\r\n2018-12-16 16:45:17.299 +00:00 [INF] - Cloud message receiver stopped for device iotedgehubdev4test2 in cloud proxy 9158d707-1c2b-4b1a-92d1-d28044b6cc76\r\n2018-12-16 16:45:17.299 +00:00 [INF] - Closed cloud proxy 9158d707-1c2b-4b1a-92d1-d28044b6cc76 for iotedgehubdev4test2\r\n2018-12-16 16:45:17.300 +00:00 [INF] - New cloud connection created for device iotedgehubdev4test2\r\n2018-12-16 16:45:17.300 +00:00 [INF] - Authenticated iotedgehubdev4test2 with IotHub\r\n2018-12-16 16:45:17.300 +00:00 [INF] - Token updated for iotedgehubdev4test2\r\n2018-12-16 16:45:17.364 +00:00 [INF] - New device connection for device iotedgehubdev4test2\r\n2018-12-16 16:45:17.364 +00:00 [INF] - Bind device proxy for device iotedgehubdev4test2\r\n2018-12-16 16:45:17.364 +00:00 [INF] - Initialized AMQP connection handler for iotedgehubdev4test2\r\n2018-12-16 16:45:17.364 +00:00 [INF] - Processing subscription DesiredPropertyUpdates for client iotedgehubdev4test2.\r\n2018-12-16 16:45:17.367 +00:00 [INF] - Opened link TwinReceiving for iotedgehubdev4test2\r\n2018-12-16 16:45:37.359 +00:00 [INF] - Opened link TwinSending for iotedgehubdev4test2\r\n2018-12-16 16:45:47.382 +00:00 [INF] - Closing link TwinSending for iotedgehubdev4test2\r\n2018-12-16 16:45:47.382 +00:00 [INF] - Closing link TwinReceiving for iotedgehubdev4test2\r\n2018-12-16 16:45:47.382 +00:00 [INF] - Setting proxy inactive for iotedgehubdev4test2.\r\n2018-12-16 16:45:47.382 +00:00 [INF] - Device connection removed for device iotedgehubdev4test2\r\n2018-12-16 16:45:47.382 +00:00 [INF] - Remove device connection for device iotedgehubdev4test2\r\n2018-12-16 16:45:47.689 +00:00 [INF] - New token received on the Cbs link\r\n2018-12-16 16:45:47.690 +00:00 [INF] - Attempting to connect to IoT Hub for client iotedgehubdev4test2 via AMQP...\r\n2018-12-16 16:45:47.915 +00:00 [INF] - New token requested by client iotedgehubdev4test2, but using existing token as it is usable.\r\n2018-12-16 16:45:48.191 +00:00 [INF] - Cloud connection for iotedgehubdev4test2 is True\r\n2018-12-16 16:45:48.191 +00:00 [INF] - Created cloud proxy for client iotedgehubdev4test2 via AMQP, with client operation timeout 20000.\r\n2018-12-16 16:45:48.191 +00:00 [INF] - Initialized cloud proxy 498f5629-01f3-44c2-8ad0-d7f41e3f7292 for iotedgehubdev4test2\r\n2018-12-16 16:45:48.192 +00:00 [INF] - Closing receiver in cloud proxy c9114eee-71cb-435d-8ca9-d7cb643219c0 for iotedgehubdev4test2\r\n2018-12-16 16:45:48.192 +00:00 [INF] - Closed cloud proxy c9114eee-71cb-435d-8ca9-d7cb643219c0 for iotedgehubdev4test2\r\n2018-12-16 16:45:48.192 +00:00 [INF] - New cloud connection created for device iotedgehubdev4test2\r\n2018-12-16 16:45:48.192 +00:00 [INF] - Authenticated iotedgehubdev4test2 with IotHub\r\n2018-12-16 16:45:48.192 +00:00 [INF] - Token updated for iotedgehubdev4test2\r\n2018-12-16 16:45:48.202 +00:00 [INF] - New device connection for device iotedgehubdev4test2\r\n2018-12-16 16:45:48.202 +00:00 [INF] - Bind device proxy for device iotedgehubdev4test2\r\n2018-12-16 16:45:48.202 +00:00 [INF] - Initialized AMQP connection handler for iotedgehubdev4test2\r\n2018-12-16 16:45:48.202 +00:00 [INF] - Processing subscription DesiredPropertyUpdates for client iotedgehubdev4test2.\r\n2018-12-16 16:45:48.204 +00:00 [INF] - Opened link TwinReceiving for iotedgehubdev4test2\r\n2018-12-16 16:45:48.287 +00:00 [INF] - Opened link TwinSending for iotedgehubdev4test2\r\n2018-12-16 16:45:49.505 +00:00 [WRN] - Unable to send twin update to iotedgehubdev4test2 because ModuleMessages link was not found.\r\n2018-12-16 16:45:49.505 +00:00 [WRN] - Error processing message in TwinReceiving link for iotedgehubdev4test2\r\nMicrosoft.Azure.Amqp.AmqpException: 'receiver299' is closed\r\n   at Microsoft.Azure.Amqp.AmqpObject.ThrowIfClosed()\r\n   at Microsoft.Azure.Devices.Edge.Hub.Amqp.EdgeReceivingAmqpLink.DisposeMessage(AmqpMessage amqpMessage, Outcome outcome, Boolean settled, Boolean batchable) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Amqp/EdgeAmqpLink.cs:line 50\r\n   at Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers.ReceivingLinkHandler.ProcessMessageAsync(AmqpMessage amqpMessage) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Amqp/linkhandlers/ReceivingLinkHandler.cs:line 85\r\n2018-12-16 16:45:51.923 +00:00 [INF] - Processing subscription C2D for client iotedgehubdev4test2.\r\n2018-12-16 16:45:51.923 +00:00 [INF] - Start listening for C2D messages for device iotedgehubdev4test2\r\n2018-12-16 16:45:51.923 +00:00 [INF] - Opened link C2D for iotedgehubdev4test2\r\n2018-12-16 16:45:53.947 +00:00 [INF] - Opened link Events for iotedgehubdev4test2\r\n2018-12-16 16:45:58.046 +00:00 [INF] - Closing link Events for iotedgehubdev4test2\r\n2018-12-16 16:45:58.046 +00:00 [INF] - Closing link C2D for iotedgehubdev4test2\r\n2018-12-16 16:45:58.046 +00:00 [INF] - Closing link TwinSending for iotedgehubdev4test2\r\n2018-12-16 16:45:58.047 +00:00 [INF] - Closing link TwinReceiving for iotedgehubdev4test2\r\n2018-12-16 16:45:58.047 +00:00 [INF] - Setting proxy inactive for iotedgehubdev4test2.\r\n2018-12-16 16:45:58.047 +00:00 [INF] - Device connection removed for device iotedgehubdev4test2\r\n2018-12-16 16:45:58.047 +00:00 [INF] - Remove device connection for device iotedgehubdev4test2\r\n2018-12-16 16:46:14.200 +00:00 [INF] - Closing link Events for fbesimulatededge/target\r\n2018-12-16 16:46:14.200 +00:00 [INF] - Setting proxy inactive for fbesimulatededge/target.\r\n2018-12-16 16:46:14.200 +00:00 [INF] - Device connection removed for device fbesimulatededge/target\r\n2018-12-16 16:46:14.200 +00:00 [INF] - Remove device connection for device fbesimulatededge/target\r\n2018-12-16 16:46:53.475 +00:00 [INF] - Reauthenticating connected clients\r\n```\r\n\r\n**Device to cloud monitor**\r\n\r\n```\r\n[IoTHubMonitor] Start monitoring D2C message for [iotedgehubdev4test2] ...\r\n[IoTHubMonitor] Created partition receiver [0] for consumerGroup [$Default]\r\n[IoTHubMonitor] Created partition receiver [1] for consumerGroup [$Default]\r\n[IoTHubMonitor] Created partition receiver [3] for consumerGroup [$Default]\r\n[IoTHubMonitor] Created partition receiver [2] for consumerGroup [$Default]\r\n[IoTHubMonitor] [5:46:03 PM] Message received from [iotedgehubdev4test2]:\r\n3\r\n[IoTHubMonitor] [5:46:12 PM] Message received from [iotedgehubdev4test2]:\r\n4\r\n```\r\n\r\nPlease let me know if you need more information.\r\n"},"comment":{"url":"https://api.github.com/repos/Azure/iotedgehubdev/issues/comments/451069606","html_url":"https://github.com/Azure/iotedgehubdev/issues/143#issuecomment-451069606","issue_url":"https://api.github.com/repos/Azure/iotedgehubdev/issues/143","id":451069606,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MTA2OTYwNg==","user":{"login":"fbeltrao","id":227765,"node_id":"MDQ6VXNlcjIyNzc2NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/227765?v=4","gravatar_id":"","url":"https://api.github.com/users/fbeltrao","html_url":"https://github.com/fbeltrao","followers_url":"https://api.github.com/users/fbeltrao/followers","following_url":"https://api.github.com/users/fbeltrao/following{/other_user}","gists_url":"https://api.github.com/users/fbeltrao/gists{/gist_id}","starred_url":"https://api.github.com/users/fbeltrao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbeltrao/subscriptions","organizations_url":"https://api.github.com/users/fbeltrao/orgs","repos_url":"https://api.github.com/users/fbeltrao/repos","events_url":"https://api.github.com/users/fbeltrao/events{/privacy}","received_events_url":"https://api.github.com/users/fbeltrao/received_events","type":"User","site_admin":false},"created_at":"2019-01-03T07:15:27Z","updated_at":"2019-01-03T07:15:27Z","author_association":"NONE","body":"@adashen thanks, that was the problem. \r\nUsing this deployment json file worked for me:\r\n\r\n```json\r\n{\r\n    \"moduleContent\": {\r\n        \"$edgeAgent\": {\r\n            \"properties.desired\": {\r\n                \"schemaVersion\": \"1.0\",\r\n                \"runtime\": {\r\n                    \"type\": \"docker\",\r\n                    \"settings\": {\r\n                        \"minDockerVersion\": \"v1.25\",\r\n                        \"loggingOptions\": \"\",\r\n                        \"registryCredentials\": {}\r\n                    }\r\n                },\r\n                \"systemModules\": {\r\n                    \"edgeAgent\": {\r\n                        \"type\": \"docker\",\r\n                        \"settings\": {\r\n                            \"image\": \"mcr.microsoft.com/azureiotedge-agent:1.0\",\r\n                            \"createOptions\": \"\"\r\n                        }\r\n                    },\r\n                    \"edgeHub\": {\r\n                        \"type\": \"docker\",\r\n                        \"status\": \"running\",\r\n                        \"restartPolicy\": \"always\",\r\n                        \"settings\": {\r\n                            \"image\": \"mcr.microsoft.com/azureiotedge-hub:1.0\",\r\n                            \"createOptions\": \"{\\\"HostConfig\\\":{\\\"PortBindings\\\":{\\\"5671/tcp\\\":[{\\\"HostPort\\\":\\\"5671\\\"}], \\\"8883/tcp\\\":[{\\\"HostPort\\\":\\\"8883\\\"}],\\\"443/tcp\\\":[{\\\"HostPort\\\":\\\"443\\\"}]}}}\"\r\n                        }\r\n                    }\r\n                },\r\n                \"modules\": {\r\n                    \"input\": {\r\n                        \"type\": \"docker\",\r\n                        \"status\": \"running\",\r\n                        \"restartPolicy\": \"always\",\r\n                        \"settings\": {\r\n                            \"image\": \"mcr.microsoft.com/azureiotedge-testing-utility:1.0.0-rc1\"\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        },\r\n        \"$edgeHub\": {\r\n            \"properties.desired\": {\r\n                \"schemaVersion\": \"1.0\",\r\n                \"routes\": {\r\n                    \"sensorToIoTHub\": \"FROM /messages/* WHERE NOT IS_DEFINED($connectionModuleId) INTO $upstream\"\r\n                },\r\n                \"storeAndForwardConfiguration\": {\r\n                    \"timeToLiveSecs\": 7200\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nPerhaps adding an example to the documenation using -d to start will be helpfull."}}
{"actor":{"display_login":"fbeltrao"}}