I'm trying to add char* variable which contains date to the Azure telemetry payload. But error is occurring.
az_span temp_span = az_span_create(telemetry_payload, sizeof(telemetry_payload));
temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR("{ \"Humidity\": "));
(void)az_span_u32toa(temp_span, humidity, &temp_span);
temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR(", \n \"Temperature\": "));
(void)az_span_u32toa(temp_span, temperature, &temp_span);
temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR(", \n \"LocalTime\": "));
temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
//Error from above line
temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR(" }"));
temp_span = az_span_copy_u8(temp_span, '\0');
getCurrentLocalTimeString function definition is here
static char* getCurrentLocalTimeString()
{
time_t now = time(NULL);
return ctime(&now);
}
Error
In file included from C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_base64.h:20,
from C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_core.h:18,
from G:\AZURE Messaging IoT\Azure_IoT_Hub_ESP8266\Azure_IoT_Hub_ESP8266.ino:40:
G:\AZURE Messaging IoT\Azure_IoT_Hub_ESP8266\Azure_IoT_Hub_ESP8266.ino: In function 'char* getTelemetryPayload()':
Azure_IoT_Hub_ESP8266:335:57: error: cast from 'char*' to 'uint8_t' {aka 'unsigned char'} loses precision [-fpermissive]
335 | temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:108:25: note: in definition of macro 'AZ_SPAN_LITERAL_FROM_STR'
108 | .ptr = (uint8_t*)(STRING_LITERAL), \
| ^~~~~~~~~~~~~~
G:\AZURE Messaging IoT\Azure_IoT_Hub_ESP8266\Azure_IoT_Hub_ESP8266.ino:335:39: note: in expansion of macro 'AZ_SPAN_FROM_STR'
335 | temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
| ^~~~~~~~~~~~~~~~
Azure_IoT_Hub_ESP8266:335:57: error: cast from 'char*' to 'uint8_t' {aka 'unsigned char'} loses precision [-fpermissive]
335 | temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:93:43: note: in definition of macro '_az_STRING_LITERAL_LEN'
93 | #define _az_STRING_LITERAL_LEN(S) (sizeof(S "") - 1)
| ^
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:125:52: note: in expansion of macro 'AZ_SPAN_LITERAL_FROM_STR'
125 | #define AZ_SPAN_FROM_STR(STRING_LITERAL) (az_span) AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL)
| ^~~~~~~~~~~~~~~~~~~~~~~~
G:\AZURE Messaging IoT\Azure_IoT_Hub_ESP8266\Azure_IoT_Hub_ESP8266.ino:335:39: note: in expansion of macro 'AZ_SPAN_FROM_STR'
335 | temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
| ^~~~~~~~~~~~~~~~
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:93:45: error: expected ')' before string constant
93 | #define _az_STRING_LITERAL_LEN(S) (sizeof(S "") - 1)
| ~ ^~
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:109:15: note: in expansion of macro '_az_STRING_LITERAL_LEN'
109 | .size = _az_STRING_LITERAL_LEN(STRING_LITERAL), \
| ^~~~~~~~~~~~~~~~~~~~~~
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:125:52: note: in expansion of macro 'AZ_SPAN_LITERAL_FROM_STR'
125 | #define AZ_SPAN_FROM_STR(STRING_LITERAL) (az_span) AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL)
| ^~~~~~~~~~~~~~~~~~~~~~~~
G:\AZURE Messaging IoT\Azure_IoT_Hub_ESP8266\Azure_IoT_Hub_ESP8266.ino:335:39: note: in expansion of macro 'AZ_SPAN_FROM_STR'
335 | temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
| ^~~~~~~~~~~~~~~~
C:\Users\hansa\Documents\Arduino\libraries\Azure_SDK_for_C\src/az_span.h:125:50: error: expected primary-expression before ')' token
125 | #define AZ_SPAN_FROM_STR(STRING_LITERAL) (az_span) AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL)
| ^
G:\AZURE Messaging IoT\Azure_IoT_Hub_ESP8266\Azure_IoT_Hub_ESP8266.ino:335:39: note: in expansion of macro 'AZ_SPAN_FROM_STR'
335 | temp_span = az_span_copy(temp_span, AZ_SPAN_FROM_STR( (uint8_t)getCurrentLocalTimeString() ));
| ^~~~~~~~~~~~~~~~
exit status 1
cast from 'char*' to 'uint8_t' {aka 'unsigned char'} loses precision [-fpermissive]