I'm a begginer on c, c++ and Cmake.
I've started from a project that allows me to send the data to Google Cloud IoT Core which is written in C: https://github.com/espressif/esp-google-iot/blob/master/examples/smart_outlet/README.md
As you can see I have a board with an ESP32 chip.
I bought an humidity sensor which I would like to use and the libraries are written in c++, so adding them to the C project has being very difficult. (https://github.com/adafruit/DHT-sensor-library) (https://github.com/adafruit/Adafruit_Sensor)
I'm importing the libraries like this in my CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# This is some google iot librares that are being imported in the project
set (EXTRA_COMPONENT_DIRS "../..")
# Libraries in cpp that are not being compiled correctly
INCLUDE_DIRECTORIES(lib/Adafruit_Sensor)
LINK_DIRECTORIES(lib/Adafruit_Sensor)
INCLUDE_DIRECTORIES(lib/DHT-sensor-library)
LINK_DIRECTORIES(lib/DHT-sensor-library)
project(smart_outlet)
But I'm getting an error message when compiling the c++ libraries.
../lib/DHT-sensor-library/DHT_U.h:45:1: error: unknown type name 'class'
I think that the error is thrown because c++ classes are not supported on c.
This is the c++ .h file that si throwing me the error:
#ifndef DHT_U_H
#define DHT_U_H
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHT_SENSOR_VERSION 1 /**< Sensor Version */
/*!
* @brief Class that stores state and functions for interacting with
* DHT_Unified.
*/
class DHT_Unified {
public:
DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6,
int32_t tempSensorId = -1, int32_t humiditySensorId = -1);
void begin();
/*!
* @brief Class that stores state and functions about Temperature
*/
class Temperature : public Adafruit_Sensor {
public:
Temperature(DHT_Unified *parent, int32_t id);
bool getEvent(sensors_event_t *event);
void getSensor(sensor_t *sensor);
private:
DHT_Unified *_parent;
int32_t _id;
};
/*!
* @brief Class that stores state and functions about Humidity
*/
class Humidity : public Adafruit_Sensor {
public:
Humidity(DHT_Unified *parent, int32_t id);
bool getEvent(sensors_event_t *event);
void getSensor(sensor_t *sensor);
private:
DHT_Unified *_parent;
int32_t _id;
};
/*!
* @brief Returns temperature stored in _temp
* @return Temperature value
*/
Temperature temperature() { return _temp; }
/*!
* @brief Returns humidity stored in _humidity
* @return Humidity value
*/
Humidity humidity() { return _humidity; }
private:
DHT _dht;
uint8_t _type;
Temperature _temp;
Humidity _humidity;
void setName(sensor_t *sensor);
void setMinDelay(sensor_t *sensor);
};
#endif
As you can see in the github repos, the files are with .cpp and .h extensions.
The main project has a dependency of a google library which is written in embedded c and allows to communicate with Google Cloud, which hasn't been a problem so far: https://github.com/GoogleCloudPlatform/iot-device-sdk-embedded-c
Could anyone plis enlight me on how to do this?
Many thanks!