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.
per1234
4,2782 gold badges23 silver badges43 bronze badges
asked Aug 13, 2017 at 18:31
2
  • 1
    error: unknown type name 'class' Classes only exist in C++. Try changing the file extension to ".cpp". Commented Aug 13, 2017 at 22:08
  • And if that doesn't work, make sure the class in IRremoteESP8266.h has a ; after the closing } Commented Aug 14, 2017 at 9:21

1 Answer 1

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;
}
Avamander
6242 gold badges11 silver badges35 bronze badges
answered Aug 15, 2017 at 9:13
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.