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

Fetch DeviceTwin properties on connect doesnt work #160

Closed
carocad opened this issue Oct 10, 2017 · 4 comments
Closed

Fetch DeviceTwin properties on connect doesnt work #160

carocad opened this issue Oct 10, 2017 · 4 comments
Assignees
Labels
bug fix checked in Fix checked into main or preview, but not yet released.

Comments

@carocad
Copy link

carocad commented Oct 10, 2017

  • OS and version used: MAC OS X 10.11.6

  • Java runtime used: Android JDK 1.7

  • SDK version used: iot-device-client:1.5.35

Description of the issue:

Hey guys, I am trying to get the device properties on client.connect(). I have already registered a MessageCallback and an IotHubEventCallback. Through these I can get the properties changes once I am connected and I correctly get the messages sent from the iot Hub.

However I dont get the complete desired properties on connect. I only get the changed values after I have connected.

If I delete the device twin from the iot hub and then connect, I do get the full desired properties !!. I would expect this to be the behavior whenever I connect to the iot hub.

Additionally I also tried using the Node.js sdk and there the complete desired properties are fetched on connect.

Code sample exhibiting the issue:

String connString = CONNECTION_TEMPLATE.replace(PLACEHOLDER_HOSTNAME, object.data.azure.hostname)
                                                        .replace(PLACEHOLDER_ID, myID)
                                                        .replace(PLACEHOLDER_AZURE_PRIMARY_KEY, object.data.azure.primarykey);
                try {
                    IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;
                    client = new DeviceClient(connString, protocol);
                    MessageCallbackMqtt callback = new MessageCallbackMqtt();
                    //Counter counter = new Counter(0);
                    client.setMessageCallback(callback, java.util.UUID.randomUUID().toString());
                    // Create a Device object to store the device twin properties
                    Device dataCollector = new Device() {
                        // Print details when a property value changes
                        @Override
                        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
                            Log.i(TAG, propertyKey + " changed to " + propertyValue);
                        }
                    };
                    dataCollector.setDesiredPropertyCallback(new com.microsoft.azure.sdk.iot.device.DeviceTwin.Property("foo", false),
                            new PropertyCallBack<String, Object>() {
                                @Override
                                public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
                                    Log.i(TAG, "My FOO changed to " + propertyValue);
                                }
                            }, null);
                    // Create a reported property and send it to your IoT hub.
                    //dataCollector.setReportedProp(new com.microsoft.azure.sdk.iot.device.DeviceTwin.Property("connectivityType", "cellular"));
                    // start client connection
                    client.open();
                    client.startDeviceTwin(new EventCallback(), null, dataCollector, null);
                    //client.sendReportedProperties(dataCollector.getReportedProp());
                    client.subscribeToDesiredProperties(dataCollector.getDesiredProp());
                }
                catch(IOException e1) {
                    Log.e(TAG, "Exception while opening IoTHub connection: " + e1.toString());
                } catch(Exception e2)
                {
                    Log.e(TAG, "Exception while opening IoTHub connection: " + e2.toString());
                }

Console log of the issue:

10-10 17:07:16.695 20759-20759/my.app W/System.err: log4j:WARN No appenders could be found for logger (com.microsoft.azure.sdk.iot.device.IotHubConnectionString).
10-10 17:07:17.515 20759-20914/my.app V/AzureSystemStatePlugin: IoT Hub responded to message 7626ad3c-b4e8-4b1f-b669-93ec8eca5fb7 with status OK_EMPTY
10-10 17:07:19.875 20759-20915/my.app V/AzureSystemStatePlugin: IoT Hub responded to message 1d01a59c-1f3e-426d-acaf-0de8f14161c0 with status OK_EMPTY
10-10 17:07:20.925 20759-20915/my.app V/AzureSystemStatePlugin: IoT Hub responded to message 0d200d03-0619-43f8-b522-af880342e060 with status OK_EMPTY
10-10 17:07:21.415 20759-20914/my.app V/AzureSystemStatePlugin: IoT Hub responded to message be5a205d-04e6-48a0-981e-efcfec6651f4 with status OK_EMPTY
10-10 17:07:22.105 20759-20914/my.app V/AzureSystemStatePlugin: IoT Hub responded to message ed0956c0-bbe5-4dff-ada9-20afb68b9cb1 with status OK_EMPTY
10-10 17:07:22.795 20759-20914/my.app V/AzureSystemStatePlugin: IoT Hub responded to message 058417cb-d7de-4318-bc2e-8b574620dcf6 with status OK_EMPTY
10-10 17:07:26.856 20759-20915/my.app V/AzureSystemStatePlugin: IoT Hub responded to message 96923f94-87a8-438e-9fa8-364128cdc925 with status OK_EMPTY
10-10 17:07:31.906 20759-20914/my.app V/AzureSystemStatePlugin: IoT Hub responded to message aa4780c5-25fd-4657-87ed-262053e1274f with status OK_EMPTY
10-10 17:07:33.495 20759-20914/my.app V/AzureSystemStatePlugin: IoT Hub responded to message 7336c4b7-f45e-47a6-9989-e4dc6213c395 with status OK_EMPTY
@prmathur-microsoft
Copy link
Member

Thanks for filing this issue. We will investigate and get back to you soon.

@mamokarz
Copy link
Contributor

I'm investigating.

@mamokarz
Copy link
Contributor

This issue is caused by a local buffer that we have in the TwinParser. We are removing it from the code.

@mamokarz mamokarz added bug fix checked in Fix checked into main or preview, but not yet released. and removed investigation-required labels Jan 30, 2018
@prmathur-microsoft
Copy link
Member

New maven packages with a fix for this issue are released. Feel free to reopen this issue if you still see any problems. Closing this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix checked in Fix checked into main or preview, but not yet released.
Projects
None yet
Development

No branches or pull requests

3 participants