RickyHamm
RickyHamm

Reputation: 43

Is there a better package to publish to Aws Iot Core than AWSSDK.Iot using C#?

I am using the awssdk.iot nuget package for C#, and I cannot find a method to publish. I have found a method Amazon.IoT.AmazonIoTClient(region).UpdateThing(UpdateThingRequest) that states in the document that it "Updates the data for a thing."

https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/IoT/TIoTClient.html

Where Amazon.IoT.Model.UpdateThingRequest has the properties AttributePayload, ExpectedVersion, RemoveThingType, ThingName, ThingTypeName. However, it does not have any properties that I can actually attach my data too. I can send attribute payloads, but this only attaches the attributes to the thing. I looked into UpdateStream but that updates iot from S3 files. Is there a better wat to publish?

using Amazon;

public static string Iot()
{
    var Region = RegionEndpoint.USEast1;
    Amazon.IoT.Model.UpdateThingResponse response;

    using (var client = new Amazon.IoT.AmazonIoTClient(region: Region))
    {

        var request = new Amazon.IoT.Model.UpdateThingRequest();
        request.ThingName = name;
        request.AttributePayload = new Amazon.IoT.Model.AttributePayload();
        request.AttributePayload.Attributes = new Dictionary<string, string>()
        {
            {"data","myvalue"}
        };
        response = client.UpdateThing(request);

    }
    return response.HttpStatusCode.ToString() ;
}

Upvotes: 2

Views: 1248

Answers (1)

Ben T
Ben T

Reputation: 4946

MQTT Publish messages are sent using the AmazonIotDataClient

The Publish and PublishAsync methods are available.

From https://docs.aws.amazon.com/sdkfornet/v3/apidocs/index.html?page=IotData/MIotDataPublishAsyncPublishRequestCancellationToken.html&tocid=Amazon_IotData_AmazonIotDataClient the PublishAsync method:

Initiates the asynchronous execution of the Publish operation.

Which uses the PublishRequest type. This has payload, QoS and topic fields.

Upvotes: 4

Related Questions