Azure direct method text mangling

Hi, 

I'm using a Azure IoT Hub to connect some devices to the cloud and then uses the Direct Method to send messages to the devices. I can send messages and receive the response from a device through the hub, however the response text is somehow getting mangled. My code is written in C++, but I'm using the "azure_iot_hub.h" library which is in C. The problem is that the response has to be a azure_iot_hub_result struct, which has a char* type as payload. I've tested different scenarios and it seems like if I'm creating a char* and directly give it some text value (see test2) it works, but when I initialize it with my response string converted to a char* (see test), it mangles the start of the text when received by Azure. When debugging the project I can see in the raw memory that both test and test2 has the exact same characters and length before sending the response and assigning the result.payload.ptr with test or test2 gives the same result (see memory). So how can the response received by Azure be different?

struct azure_iot_hub_result result = {
		.request_id = {
			.ptr = method_data.request_id,
			.size = strlen(method_data.request_id),
		},
	};
	
	
	std::string string = "\"This is a long test string to test the functionality\"";

	char* test = string.data();
	char* test2 = "\"This is a long test string to test the functionality\"";
	printk("test: %s\n", test);
	printk("test len: %d\n", strlen(test));

	printk("test2: %s\n", test2);
	printk("test2 len: %d\n", strlen(test2));

	result.payload.ptr = test2;
	result.payload.size = strlen(test2);

Parents Reply Children
No Data
Related