Simple sample that demonstrates reading the FXOS8700CQ accelerometer, convert the data to JSON and send to an Azure IoT Hub.
Dependencies: azure_umqtt_c iothub_mqtt_transport mbed-rtos mbed wolfSSL Socket lwip-eth lwip-sys lwip
uniqueid_stub.c
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #include <stdlib.h> 00005 #include <stdint.h> 00006 #include "azure_c_shared_utility/uniqueid.h" 00007 #include "azure_c_shared_utility/xlogging.h" 00008 #include <time.h> 00009 00010 DEFINE_ENUM_STRINGS(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES); 00011 00012 static const char tochar[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 00013 static void generate128BitUUID(unsigned char* arrayOfByte) 00014 { 00015 size_t arrayIndex; 00016 00017 for (arrayIndex = 0; arrayIndex < 16; arrayIndex++) 00018 { 00019 arrayOfByte[arrayIndex] = (unsigned char)rand(); 00020 } 00021 00022 // 00023 // Stick in the version field for random uuid. 00024 // 00025 arrayOfByte[7] &= 0x0f; //clear the bit field 00026 arrayOfByte[7] |= 0x40; //set the ones we care about 00027 00028 // 00029 // Stick in the variant field for the random uuid. 00030 // 00031 arrayOfByte[8] &= 0xf3; // Clear 00032 arrayOfByte[8] |= 0x08; // Set 00033 00034 } 00035 00036 // TODO: The User will need to call srand before calling this function 00037 UNIQUEID_RESULT UniqueId_Generate(char* uid, size_t len) 00038 { 00039 UNIQUEID_RESULT result; 00040 unsigned char arrayOfChar[16]; 00041 00042 /* Codes_SRS_UNIQUEID_07_002: [If uid is NULL then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */ 00043 /* Codes_SRS_UNIQUEID_07_003: [If len is less then 37 then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */ 00044 if (uid == NULL || len < 37) 00045 { 00046 result = UNIQUEID_INVALID_ARG; 00047 LogError("Buffer Size is Null or length is less then 37 bytes"); 00048 } 00049 else 00050 { 00051 size_t arrayIndex; 00052 size_t shiftCount; 00053 size_t characterPosition = 0; 00054 00055 /* Codes_SRS_UNIQUEID_07_001: [UniqueId_Generate shall create a unique Id 36 character long string.] */ 00056 generate128BitUUID(arrayOfChar); 00057 for (arrayIndex = 0; arrayIndex < 16; arrayIndex++) 00058 { 00059 for (shiftCount = 0; shiftCount <= 1; shiftCount++) 00060 { 00061 char hexChar = tochar[arrayOfChar[arrayIndex] & 0xf]; 00062 if ((characterPosition == 8) || (characterPosition == 13) || (characterPosition == 18) || (characterPosition == 23)) 00063 { 00064 uid[characterPosition] = '-'; 00065 characterPosition++; 00066 } 00067 uid[characterPosition] = hexChar; 00068 characterPosition++; 00069 arrayOfChar[arrayIndex] = arrayOfChar[arrayIndex] >> 4; 00070 } 00071 } 00072 uid[characterPosition] = 0; 00073 result = UNIQUEID_OK; 00074 } 00075 return result; 00076 }
Generated on Wed Jul 13 2022 07:19:04 by 1.7.2