1

In the C file in simplesample_mqtt.c, which connects Arduino to the Azure IoT hub, I need to use the IRsend and IrRemoteESP8266 libraries to send an infrared signal with Azure IoT hub.

 #include <IRremoteESP8266.h>
 #include <IRsend.h>
 IRsend irsend(10); // An IR LED is controlled by GPIO pin 4 (D2)

I don't have any problem when I use this code in my main Arduino file. But when I use these includes in a C file (simplesample_mqtt.c), I get this error from line 3: "unknown type name 'IRsend'".

enter image description here

error full info :

Arduino: 1.8.2 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"

In file included from sketch\simplesample_mqtt.c:29:0:

C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266\src/IRsend.h:29:1: error: unknown type name 'class'

class IRsend {

C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266\src/IRsend.h:29:14: error: expected '=', ',', ';', 'asm' or 'attribute' before '{' token

class IRsend {

simplesample_mqtt.c:31: error: unknown type name 'IRsend'

IRsend irsend(10); // An IR LED is controlled by GPIO pin 4 (D2)


simplesample_mqtt.c:31: error: expected declaration specifiers or '...' before numeric constant

IRsend irsend(10); // An IR LED is controlled by GPIO pin 4 (D2)

exit status 1
unknown type name 'IRsend'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
  • 1
    error: unknown type name 'class' Classes only exist in C++. Try changing the file extension to ".cpp". – Johnny Mopp Aug 13 '17 at 22:08
  • And if that doesn't work, make sure the class in IRremoteESP8266.h has a ; after the closing } – Code Gorilla Aug 14 '17 at 9:21
1

I solved this problem. The reason for this is because main Arduino is c++ and simplesample_mqtt.c is c code and we have to use c++ code in c code:

In main Arduino file you have to declare function like this :

extern "C" void TurnOn();
void TurnOn()
{
    digitalWrite(RELAY_SONOFF, HIGH);     
    digitalWrite(LED_SONOFF, HIGH);
}

and use this function in c code:

void TurnOn();
EXECUTE_COMMAND_RESULT TurnOn(ContosoAnemometer* device)
{
    (void)device;
    TurnOn();
    (void)printf("Turning fan on.\r\n");
    return EXECUTE_COMMAND_SUCCESS;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.