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

Assistance Required in Connecting Robot to IoT Central with Specific Project Settings #113519

Closed
AlanPintor-git opened this issue Aug 14, 2023 · 5 comments

Comments

@AlanPintor-git
Copy link

Dear IoT Team,

I am encountering challenges while attempting to integrate a robot with IoT Central. This is a critical issue as it pertains to one of many units that require connection.

Project Configuration Details:

  • Android OS Version: 7.1
  • Android Studio Version: Arctic Fox
  • Target SDK Version: 27
  • Dependency: implementation 'com.microsoft.azure.sdk.iot:iot-device-client:1.29.2'

The challenges faced are as follows:

  • Utilizing the Android sample from Azure IoT SDK Java was unsuccessful, owing to incompatibility with my project version.
  • Adaptation of the sample code to my project resulted in compatibility issues.
  • Attempts to implement chatGPT were met with errors:
    1. Logs from the Android app reflect a successful connection, but the device in IoT does not register as connected.
    2. An error was encountered when sending telemetries: '//V/IoTest: Telemetry sent with status: ERROR'

Would you be able to provide a sample compatible with my project configuration, or advise me on appropriate solutions?

Enclosed code snippet:

import android.util.Log;
import com.microsoft.azure.sdk.iot.device.;
import com.microsoft.azure.sdk.iot.device.transport.IotHubConnectionStatus;
import com.microsoft.azure.sdk.iot.device.
;
import com.microsoft.azure.sdk.iot.device.transport.IotHubConnectionStatus;
import org.json.JSONObject;

public class AzureIoTHelper {
private DeviceClient deviceClient;

public AzureIoTHelper(String connectionString) {
    try {
        deviceClient = new DeviceClient(connectionString, IotHubClientProtocol.HTTPS);
        deviceClient.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallback() {
            @Override
            public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) {
                Log.v("IoTest", "Connection status changed to: " + status);
            }
        }, null);
    } catch (Exception e) {
        Log.v("IoTest", "Error initializing Azure IoT Central Helper: " + e.getMessage());
    }
}

public void iotConnect() {
    try {
        deviceClient.open();
        Log.v("IoTest", "Connected to Azure IoT Central.");
    } catch (Exception e) {
        Log.v("IoTest", "Error connecting to Azure IoT Central: " + e.getMessage());
    }
}

public void sendTelemetries(JSONObject telemetryData) {
    try {
        Message message = new Message(telemetryData.toString());
        deviceClient.sendEventAsync(message, new EventCallback(), null);
        Log.v("IoTest", "Telemetry sent: " + telemetryData.toString());
    } catch (Exception e) {
        Log.v("IoTest", "sendTelemetries - Exception: " + e.getMessage() + ", cause: " + e.getCause());
        e.printStackTrace();
        //V/IoTest: Telemetry sent with status: ERROR
    }
}

private static class EventCallback implements IotHubEventCallback {
    @Override
    public void execute(IotHubStatusCode responseStatus, Object callbackContext) {
        Log.v("IoTest", "Telemetry sent with status: " + responseStatus.name());
    }
}
}

Best Regards,
Alan


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

@LeelaRajesh-Sayana
Copy link
Contributor

LeelaRajesh-Sayana commented Aug 14, 2023

Hi @AlanPintor-git Greetings! Thank you for posting the question here. This GitHub repository is meant for improvements or address any issues with documentation. Since this question relates to technical challenges with the implementation, I request you to post the question on Microsoft Q&A platform, which is the home to any technical related questions on Azure services. The community members on the platform would be able to assist you with this issue.

I would also like to point that the package you are trying to refer is very outdated. The latest version of package is at 2.1.1. Please refer the Azure-iot-sdk-java release details page for more information on this. Here is a link to the GitHub sample which provides an implementation to connect an Android application to IoT Central app. Hope this guides you with the next steps.

If you need any further assistance on this, kindly post this question on Q&A forum with additional information on the error details you see.

We will now proceed to close this issue.

Best regards,
Leela Rajesh.

@AlanPintor-git
Copy link
Author

Hi @LeelaRajesh-Sayana,
Thank you for your response, I will post my query on Microsoft Q&A.

@timtay-microsoft
Copy link
Contributor

@AlanPintor-git can you post this question to the Java IoT SDK repo as well? We can help you out more over there: https://github.com/Azure/azure-iot-sdk-java/issues

@AlanPintor-git
Copy link
Author

Hi @timtay-microsoft,
Done, this is the ticket: Azure/azure-iot-sdk-java#1735

Thank you

@LeelaRajesh-Sayana
Copy link
Contributor

Hi @AlanPintor-git Thank you for reporting the issue under the Java IoT SDK repository. The product team will help you further through the new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants