Azure / azure-iot-arduino

Azure IoT library for the Arduino
Other
167 stars 96 forks source link

get_epoch_time in iothub_client_diagnostic.c throws errors #129

Open Axeinator opened 3 years ago

Axeinator commented 3 years ago

I'm trying to run a simple piece of test code for a ESP8266 board.

#include <AzureIoTHub.h>

void setup() {

}
void loop() {

}         

When I run this, I get the following error.

/.../AzureIoTHub/src/iothub_client_diagnostic.c:34:36: error: expected ')' before '__INT64'
   34 |         if (sprintf(timeBuffer, "%"PRIu64, (int64_t)epochTime) < 0)
      |                                    ^
      |                                    )
/.../AzureIoTHub/src/iothub_client_diagnostic.c:46:36: error: expected ')' before '__INT32'
   46 |         if (sprintf(timeBuffer, "%"PRIu32, (int32_t)epochTime) < 0)
      |                                    ^
      |                                    )

This is running on an M1 Mac but I'm having the same errors on a Ubuntu system (Intel). I completed all the steps that were in the README and used the automate_board_config.py to set up the board library. The packages were installed through the Arduino IDE.

mikeboharsik commented 3 years ago

I was able to hack around this issue by modifying the inttypes.h that comes with the ESP8266. For some reason the implementation seems to deviate from the gcc implementation in a way that breaks the compilation. This is where the file appears to come from.

The path to the file on my Windows machine is "%UserProfile%\Documents\ArduinoData\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\xtensa-lx106-elf\include\inttypes.h". I've modified the lines involving #defines that correlate with the compilation errors. The line changes are as follows:

Line 31
#define __PRI8(x) /*__INT8*/ __STRINGIFY(x)

Line 108
#define __PRI16(x) /*__INT16*/ __STRINGIFY(x)

Line 158
#define __PRI32(x) /*__INT32*/ __STRINGIFY(x)

Line 208
#define __PRI64(x) /*__INT64*/ __STRINGIFY(x)

Note that each __INTX has been commented out.

I do not know what side-effect this has, but it gets my Arduino sketch building, uploading, and running as expected.