I have a custom application in Azure IoT Central. I have my device created and can send data up with basic data types (bool, float, int).
From the C api it looks like there is a mechanism to declare a struct, add it to the model, and send that data. So I did, and I see confirmation that my messages are sending and being received, but no data is showing...so I'm guessing either you can't really declare a struct and send it, or I don't have it configured correctly on the Azure side, but I haven't found any documentation that could help.
BEGIN_NAMESPACE(AzureModel);
DECLARE_STRUCT(MyData,
int, num1,
float, num2,
int, num3);
DECLARE_MODEL(Azure1_t,
WITH_DATA(ascii_char_ptr, deviceId),
WITH_DATA(int, messageId),
WITH_DATA(MyData, myData),
WITH_DATA(EDM_DATE_TIME_OFFSET, ts),
/* Methods */
WITH_METHOD(Reboot),
WITH_METHOD(Quit),
WITH_METHOD(FirmwareUpdate, ascii_char_ptr, FwPackageUri),
/* Register Direct Methods with IoT Hub */
WITH_REPORTED_PROPERTY(ascii_char_ptr_no_quotes, SupportedMethods),
/* Telemetry Interval in Seconds... value from 1 to: 0xFFFF/2000 = About 30 Seconds */
WITH_REPORTED_PROPERTY(int,TelemetryInterval),
WITH_REPORTED_PROPERTY(ascii_char_ptr,AzureStatus),
WITH_REPORTED_PROPERTY(ascii_char_ptr, AzureFwVersion)
);
END_NAMESPACE(AzureModel);
Azure1_t *Azure1;
static void SendData(void)
{
EVENT_INSTANCE *messages;
unsigned char* destination;
size_t destinationSize;
time_t now;
/* Read the Time from RTC */
now = TimingSystemGetSystemTime();
/* Time Stamp */
Azure1->ts = GetDateTimeOffset(now);
messages = (EVENT_INSTANCE *) calloc(1,sizeof(EVENT_INSTANCE));
if(messages==NULL) {
AZURE_PRINTF("Err: Allocating Memory for messages to IoT Hub\r\n");
HAL_NVIC_SystemReset();
} else {
messages->this = (void *)messages;
}
SentMessagesCount++;
Azure1->messageId = messages->messageTrackingId = SentMessagesCount;
if (SERIALIZE(&destination, &destinationSize,
Azure1->deviceId,
Azure1->messageId,
Azure1->myData,
Azure1->ts) != CODEFIRST_OK){
AZURE_PRINTF("Err: Failed to serialize\r\n");
}
else
{
/* Only for Debug */
//AZURE_PRINTF("MessageToSend=%.*s\r\n",destinationSize,destination);
if ((messages->messageHandle = IoTHubMessage_CreateFromByteArray(destination, destinationSize)) == NULL) {
AZURE_PRINTF("Err: iotHubMessageHandle is NULL!\r\n");
} else {
char msgText[32];
MAP_HANDLE propMap = IoTHubMessage_Properties(messages->messageHandle);
sprintf_s(msgText, sizeof(msgText), "PropMsg_%zu", SentMessagesCount);
if (Map_AddOrUpdate(propMap, "PropName", msgText) != MAP_OK){
AZURE_PRINTF("Err: Map_AddOrUpdate Failed!\r\n");
}
if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messages->messageHandle, SendConfirmationCallback, messages) != IOTHUB_CLIENT_OK) {
AZURE_PRINTF("Err: IoTHubClient_LL_SendEventAsync..........FAILED!\r\n");
} else {
AZURE_PRINTF("IoTHubClient_LL_SendEventAsync accepted message [%d] for transmission to IoT Hub.\r\n", SentMessagesCount);
}
free(destination);
}
IoTHubMessage_Destroy(messages->messageHandle);
}
}