1
votes

Currently I have an IOT Device Simulator Which Sends Message to IOT HUB whith following C# code

   for (int i = 0; i < 50; i++)
    {
        int cnt = new Random().Next(1, 5);
        int Id = new Random().Next(1, 10);

        var telemetryDataPoint = new
        {
            Time = DateTime.Now,
            DeviceId = "myFirstDevice",
            Counter = cnt,
            RestId = Id,

        };
        var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
        var message = new Message(Encoding.ASCII.GetBytes(messageString));

        await deviceClient.SendEventAsync(message);
        Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);

    }

Now I have an another C# console application which tries to read data from the azure table storage as

public class SimulatorDeviceEntity : TableEntity
{
    public SimulatorDeviceEntity(string devId, string time )
    {
        this.PartitionKey = devId;
        this.RowKey = time;
    }

    public SimulatorDeviceEntity() { }
    public string counter { get; set; }
    public string restid { get; set; }
    public string deviceid { get; set; }
}


    static void Main(string[] args)
    {
        StorageCredentials creds = new StorageCredentials(accountName, accountKey);
        CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);

        CloudTableClient client = account.CreateCloudTableClient();




        TableQuery<SimulatorDeviceEntity> query = new TableQuery<SimulatorDeviceEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "myFirstDevice"));


        foreach (SimulatorDeviceEntity entity in table.ExecuteQuery(query))
        {
            Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
                entity.counter, entity.restid);
        }
      }

Now Issue I am facing here is I get is I am getting all the records from table but with 1 ) null entries in the columns couter,restId 2) correct values in PartitionKey and RowKey

How to get the correct values for counter and restid

Azure Storage Table : SimulatorDevice2 here is the screenshot enter image description here

1
Can you also share your code that is adding the messages to table storage? That will help to figure out what's going on. - Dominic Betts
The Simulator send the message to IOT HUB, where I have used Stream Analytics which put the data into Azure Table , the Query is as follows SELECT DeviceId,RestId,Time, Counter INTO v2deviceOutput from v2deviceInput WHERE DeviceId is not null Note : v2deviceInput and v2deviceOutput is input output configured with Stream Analytics - Vaibhav Ramteke
@VaibhavRamteke, any luck yet? - Jackie

1 Answers

1
votes

Try changing the type of counter and restid from string to Int64.

public class SimulatorDeviceEntity : TableEntity
{
    public SimulatorDeviceEntity(string devId, string time)
    {
        this.PartitionKey = devId;
        this.RowKey = time;
    }

    public SimulatorDeviceEntity() { }

    public Int64 counter { get; set; }
    public Int64 restid { get; set; }
    public string deviceId { get; set; }
}

Similarly, if you want to map "time" property, it's DateTime type.