Arduino UNO doesn't work if I add a header file

Hi! I have a sketch with the main logic of my program and 2 header files, one with an alarm class, and the other with an alarmHandler class, which includes an alarm instance. If I run the program without my included AlarmHandler, the program runs fine and prints all data via the serial monitor but if I run the program with the included ones of my classes, the program displays nothing via the serial monitor and I don't know if it's running.

I would like run the sketch with my header files.

Currently I've the main.cpp (with setup and loop functions), alarm.h and alarmHandler.h.

Thanks!

What is preventing you from using your own header files?

I've my own header files and I don't have any problem when I build and upload my program but I think my program is not running because it doesn't show anything through serial monitor. Instead, when I remove the include of my header files the program works fine and print my prints through serial monitor.

What do you think you need to do to help others help you?

Consider. It seems you are asking for help with code, correct? Now if I asked you for help with my code what would you want to see?

Okay here I paste a part of my code:

Here I've the code from main.cpp

#include <Arduino.h>

#include <CSV_Parser.h>

#include "AlarmController.h"

typedef struct {
    uint16_t id;
    uint32_t position;
}flag;

#define _HAL01 "HAL01"
#define _HAL02 "HAL02"
#define _HAL03 "HAL03"
#define _HAL04 "HAL04"
#define _HAL05 "HAL05"
#define _HAL06 "HAL06"
#define _HAL07 "HAL07"
#define _HAL08 "HAL08"


flag currentFlag;
flag lastFlag;
int speed;
unsigned int telemeterValue;
int alarm;
bool orientation; // 1 => from origin to final | 0 => from final to origin
unsigned int cycle;
flag * flags;
int flagsSize;
uint32_t currentPosition;
uint32_t lastPosition;
int index;
bool confIsLoaded;

// the order of data configuration should be from minor to major
const char *csv_str = "";

uint32_t segmentDistance;
uint32_t flagOffset;
HirukiAlarmController hac;


/**
 * Function to send the bit to activate the alarm of PCT in CCT
 */
void generateAlarm(char *description){
    //TODO here we should add the call to OPC-UA function to send a bit to change the status of the PCT alarm
    Serial.println("Alarm generation: ");
    Serial.println(description);
}


/**
 * Read data from telemeter
 */
int readTelemeter(){

    //return random(0, 20000);
}


/**
 * Write position in OPC-UA server
 */
void sendPosition(int position){
    Serial.print("Updated position: ");
    Serial.println(position);
}


/**
 * Calculate and send speed
 */
void sendSpeed(int position,int lastPosition,int cycle){
    Serial.print("Current speed: ");
    Serial.println((position-lastPosition)/cycle);
}

/**
 * Print flags loaded in memory
 */
void printFlags(flag *flags, int flagsSize){
    Serial.print("Loaded ");
    Serial.print(flagsSize, DEC);
    Serial.println(" flags from configuration file");

    for(int i = 0;i<flagsSize;i++){
        Serial.print("Id = ");
        Serial.print(flags[i].id, DEC);
        // Serial.print(" | Position = ");
        Serial.println(flags[i].position, DEC);
    }
}


/**
 * Load all flags from configuration file
 */
void loadConfiguration(flag *flags[],int flagsSize, const char *filename){
    CSV_Parser cp(filename, /*format*/ "uduL");
    uint16_t *strings = (uint16_t*)cp[0];
    uint32_t *numbers = (uint32_t*)cp[1];
    *flags = new flag[flagsSize];

    //cp.print();

    for (int row = 0; row<cp.getRowsCount(); row++){
        (*flags)[row].id = strings[row];
        (*flags)[row].position = numbers[row];
    }

}


/**
 * Count lines of configuration file
 */
int countLines(const char *filename){
    CSV_Parser cp(filename, /*format*/ "sL");
    return cp.getRowsCount();
}

void setup() {
    Serial.begin(9600);
//  delay(5000);
    currentFlag = {0,0};
    lastFlag = {0,0};
    speed = 0;
    telemeterValue = 0;
    alarm = 0;
    orientation = 0;
    cycle = 1;
    currentPosition = 0;
    index = 0;
    confIsLoaded = false;
    lastPosition = 1;
    segmentDistance = 0;
    flagOffset = 0;
    hac = HirukiAlarmController();
    Serial.println("PCT is setted succesfully!");

}


void loop() {

    int pole = orientation ? -1 : 1;

    //configuration load
    if(!confIsLoaded){

        flagsSize = countLines(csv_str);
        Serial.println(flagsSize);
        if(!flagsSize){
            hac.throwAlarm(_HAL06);
        }else{
            loadConfiguration(&flags, flagsSize, csv_str);
            printFlags(flags, flagsSize);
            segmentDistance = flags[1].position - flags[0].position;
            confIsLoaded = true;
        }

    }else{
        unsigned int input = 0;


        if(lastPosition != NULL){// here instead of lastPosition we would need another process checking if the current position is maximum or minimum in a segment between flags and in this case we'll need add a timeout for wait the response of RFID, if the timeout is ended we should generate a new Alarm in PCT related with the RFID. This process will permise us detect which flag is failing
            telemeterValue = int(input);

            if(telemeterValue <= flagOffset + flags[index+(pole*-1)].position && telemeterValue >= flags[index+(pole*-1)].position - flagOffset ){
                lastFlag.id = currentFlag.id;
                lastFlag.position = currentFlag.position;

                index += (pole*-1);
                currentFlag.id = flags[index].id;
                currentFlag.position = flags[index].position;
                lastPosition = currentPosition;
                currentPosition = currentFlag.position;


            }else{
                currentPosition = flags[index+pole].position + (telemeterValue * pole);
                sendPosition(currentPosition);
            }



        }else{
            generateAlarm("ALARM! Last position is NULL.");
        }
    }

}


Here my code of my alarm handler

#include "alarm.h"




#ifndef UNTITLED_ALARMCONTROLLER_H
#define UNTITLED_ALARMCONTROLLER_H


class AlarmController {
private:
    Alarm *alarms;
    int alarmSize;
    //TODO OPC-UA client object
    void initOPCUAClient();
    void writeNode(Alarm alarm);
    void loadOPCUAVars();
    void loadAlarmDefinitions();
    String readNode(Alarm alarm);
    int getAlarmSize();
    void setAlarmSize();
    int getAlarmIndex(String finder);
public:
    AlarmController();
    void pushAlarm(Alarm alarm, int index);
    Alarm removeAlarm(String finder, int finderType);
    Alarm getAlarm(String finder);
    void loadConfig();
    void throwAlarm(String finder);
    bool alarmIsActive();



};

AlarmController::AlarmController() {
    this->setAlarmSize();
    this->loadConfig();
}

void AlarmController::loadConfig() {
    this->initOPCUAClient();
    this->loadAlarmDefinitions();
    this->loadOPCUAVars();
}



void AlarmController::pushAlarm(Alarm alarm, int index) {
    //add new alarm
    this->alarms[index] = alarm;

}

void AlarmController::initOPCUAClient() {
    //initialization of OPC-UA Client, to do this action is necessary the OPC-UA Client library
}

void AlarmController::loadOPCUAVars(){
  //load all OPC-UA vars from server
}

void AlarmController::loadAlarmDefinitions(){
  const char *csv_str = "code,description,type,node\n"
                   "HAL01,PREOVERHEATING,WARNING,NULL\n"
                   "HAL02,OVERHEATING,ERROR,NULL\n"
                   "HAL03,POWER SURGE,WARNING,NULL\n"
                   "HAL04,NETWORK ERROR,ERROR,NULL\n"
                   "HAL05,OVERUSE,WARNING,NULL\n"
                   "HAL06,MISSED CONFIG FILE,ERROR,NULL\n"
                   "HAL07,CORRUPTED DATA,ERROR,NULL\n"
                   "HAL08,ACTION TIMEOUT,ERROR,NULL\n";

    CSV_Parser cp(csv_str, /*format*/ "ssss");
    char **codes = (char**)cp[0];
    char **descriptions = (char**)cp[1];
    char **types = (char**)cp[2];
    char **nodes = (char**)cp[3];

    

    for (int row = 0; row<cp.getRowsCount(); row++){
      Alarm alarm(codes[row],descriptions[row],types[row],nodes[row]);
      this->pushAlarm(alarm, row);
    }
  
}

void AlarmController::setAlarmSize(){
  this->alarmSize = 8;
}

int AlarmController::getAlarmSize(){
  return this->alarmSize;
}

bool AlarmController::alarmIsActive(){
  for(int i = 0;i<this->getAlarmSize();i++){
    if(this->alarms[i].isActive()) return true;
  }
  return false;
}

void AlarmController::writeNode(Alarm alarm){
  //write specific value in node
}

String AlarmController::readNode(Alarm alarm){
  //read specific value from node
}

Alarm AlarmController::getAlarm(String finder){
    for(int i = 0;i<this->getAlarmSize();i++){
    if(this->alarms[i].getCode() == finder){
      return this->alarms[i];
    }
  }
  return Alarm();
}

int AlarmController::getAlarmIndex(String finder){
    for(int i = 0;i<this->getAlarmSize();i++){
      if(this->alarms[i].getCode() == finder){
        return i;
      }
  }
  return -1;
}

void AlarmController::throwAlarm(String finder){
  if(this->getAlarmIndex(finder)>=0)alarms[this->getAlarmIndex(finder)].setIsActive(true);
  else{
    Serial.print("The ");
    Serial.print(finder);
    Serial.println(" was not found!");
  }
}

#endif //UNTITLED_LARMCONTROLLER_H

And here my code of alarm class

#ifndef ALARM_H
#define ALARM_H

#include <WString.h>

class Alarm{
private:
    String code;
    String description;
    String type;
    String node;
    bool active;
public:
    Alarm();
    Alarm(String code, String description, String type, String node);

    void setCode(String code);
    void setDescription(String description);
    void setType(String type);
    void setNode(String node);
    void setIsActive(bool isActive);
    String getCode();
    String getDescription();
    String getType();
    String getNode();
    bool isActive();

    String* getAlarm();
};


Alarm::Alarm() {
    this->code = String("");
    this->description = String("");
    this->type = String("warning");
    this->node = String("");
    this->active = false;

}

Alarm::Alarm(String code, String description, String type, String node) {
    this->code = code;
    this->description = description;
    this->type = type;
    this->node = node;
    this->active = false;
}

void Alarm::setCode(String code) {
    this->code = code;
}

void Alarm::setDescription(String description) {
    this->description = description;
}

void Alarm::setType(String type) {
    this->type = type;
}

void Alarm::setNode(String node) {
    this->node = node;
}

void Alarm::setIsActive(bool isActive) {
    this->active = isActive;
    Serial.println(this->code);
    Serial.println(this->description);
}

String Alarm::getCode() {
    return this->code;
}

String Alarm::getDescription() {
    return this->description;
}

String Alarm::getType() {
    return this->type;
}

String Alarm::getNode() {
    return this->node;
}

bool Alarm::isActive(){
  return this->active;
}

String* Alarm::getAlarm() {
    String* array = new String[4];
    array[0] = this->code;
    array[1] = this->description;
    array[2] = this->type;
    array[3] = this->node;
    return array;
}
#endif //ALARM_H```

That's all the code you are running on an Uno under the Arduino IDE?

Here is how my code looks when I use external header files.

#include <ESP32Time.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include "certs.h" // include the connection info for WiFi and MQTT
#include "sdkconfig.h" // used for log printing
#include "esp_system.h"
#include "freertos/FreeRTOS.h" //freeRTOS items to be used
#include "freertos/task.h"
#include <driver/adc.h>
#include <SimpleKalmanFilter.h>
////
WiFiClient      wifiClient; // do the WiFi instantiation thing
PubSubClient    MQTTclient( mqtt_server, mqtt_port, wifiClient ); //do the MQTT instantiation thing
ESP32Time       rtc;
////
#define evtDoParticleRead  ( 1 << 0 ) // declare an event
#define evtADCreading      ( 1 << 3 )
EventGroupHandle_t eg; // variable for the event group handle
////
SemaphoreHandle_t sema_MQTT_KeepAlive;
SemaphoreHandle_t sema_mqttOK;
////
QueueHandle_t xQ_RemainingMoistureMQTT;
QueueHandle_t xQ_RM;
QueueHandle_t xQ_Message;
////
struct stu_message
{
  char payload [150] = {'\0'};
  String topic;
} x_message;
////
int    mqttOK = 0;
bool   TimeSet = false;
bool   manualPumpOn = false;
////
// interrupt service routine for WiFi events put into IRAM
void IRAM_ATTR WiFiEvent(WiFiEvent_t event)
{
  switch (event) {
    case SYSTEM_EVENT_STA_CONNECTED:
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      log_i("Disconnected from WiFi access point");
      break;
    case SYSTEM_EVENT_AP_STADISCONNECTED:
      log_i("WiFi client disconnected");
      break;
    default: break;
  }
} // void IRAM_ATTR WiFiEvent(WiFiEvent_t event)
////
void IRAM_ATTR mqttCallback(char* topic, byte * payload, unsigned int length)
{
  // clear locations
  memset( x_message.payload, '\0', 150 );
  x_message.topic = ""; //clear string buffer
  x_message.topic = topic;
  int i = 0;
  for ( i; i < length; i++)
  {
    x_message.payload[i] = ((char)payload[i]);
  }
  x_message.payload[i] = '\0';
  xQueueOverwrite( xQ_Message, (void *) &x_message );// send data
} // void mqttCallback(char* topic, byte* payload, unsigned int length)
////
void setup()
{
  x_message.topic.reserve(150);
  //
  xQ_Message = xQueueCreate( 1, sizeof(stu_message) );
  xQ_RemainingMoistureMQTT = xQueueCreate( 1, sizeof(float) ); // sends a queue copy
  xQ_RM = xQueueCreate( 1, sizeof(float) );
  //
  eg = xEventGroupCreate(); // get an event group handle
  //
  sema_mqttOK =  xSemaphoreCreateBinary();
  xSemaphoreGive( sema_mqttOK );
  //
  gpio_config_t io_cfg = {}; // initialize the gpio configuration structure
  io_cfg.mode = GPIO_MODE_INPUT; // set gpio mode. GPIO_NUM_0 input from water level sensor
  io_cfg.pull_down_en = GPIO_PULLDOWN_ENABLE; // enable pull down
  io_cfg.pin_bit_mask = ( (1ULL << GPIO_NUM_0) ); //bit mask of the pins to set, assign gpio number to be configured
  gpio_config(&io_cfg); // configure the gpio based upon the parameters as set in the configuration structure
  //
  io_cfg = {}; //set configuration structure back to default values
  io_cfg.mode = GPIO_MODE_OUTPUT;
  io_cfg.pin_bit_mask = ( (1ULL << GPIO_NUM_4) | (1ULL << GPIO_NUM_5) ); //bit mask of the pins to set, assign gpio number to be configured
  gpio_config(&io_cfg);
  gpio_set_level( GPIO_NUM_4, LOW); // deenergize relay module
  gpio_set_level( GPIO_NUM_5, LOW); // deenergize valve
  // set up A:D channels  https://dl.espressif.com/doc/esp-idf/latest/api-reference/peripherals/adc.html
  adc1_config_width(ADC_WIDTH_12Bit);
  adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11);// using GPIO 39
  //
  xTaskCreatePinnedToCore( MQTTkeepalive, "MQTTkeepalive", 10000, NULL, 6, NULL, 1 );
  xTaskCreatePinnedToCore( fparseMQTT, "fparseMQTT", 10000, NULL, 5, NULL, 1 ); // assign all to core 1, WiFi in use.
  xTaskCreatePinnedToCore( fPublish, "fPublish", 9000, NULL, 3, NULL, 1 );
  xTaskCreatePinnedToCore( fReadAD, "fReadAD", 9000, NULL, 3, NULL, 1 );
  xTaskCreatePinnedToCore( fDoMoistureDetector, "fDoMoistureDetector", 70000, NULL, 4, NULL, 1 );
  xTaskCreatePinnedToCore( fmqttWatchDog, "fmqttWatchDog", 3000, NULL, 2, NULL, 1 );
} //void setup()
////
void fReadAD( void * parameter )
{
  float    ADbits = 4096.0f;
  float    uPvolts = 3.3f;
  float    adcValue_b = 0.0f; //plant in yellow pot
  uint64_t TimePastKalman  = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
  float    WetValue = 1.07f; // value found by putting sensor in water
  float    DryValue = 2.732f; // value of probe when held in air
  float    Range = DryValue - WetValue;
  float    RemainingMoisture = 100.0f;
  SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
  for (;;)
  {
    xEventGroupWaitBits (eg, evtADCreading, pdTRUE, pdTRUE, portMAX_DELAY ); //
    adcValue_b = float( adc1_get_raw(ADC1_CHANNEL_3) ); //take a raw ADC reading
    adcValue_b = ( adcValue_b * uPvolts ) / ADbits; //calculate voltage
    KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
    adcValue_b = KF_ADC_b.updateEstimate( adcValue_b ); // apply simple Kalman filter
    TimePastKalman = esp_timer_get_time(); // time of update complete
    RemainingMoisture = 100.0f * (1 - ((adcValue_b - WetValue) / (DryValue - WetValue))); //remaining moisture =  1-(xTarget - xMin) / (xMax - xMin) as a percentage of the sensor wet dry volatges
    xQueueOverwrite( xQ_RM, (void *) &RemainingMoisture );
    //log_i( "adcValue_b = %f remaining moisture %f%", adcValue_b, RemainingMoisture );
  }
  vTaskDelete( NULL );
}
////
void fPublish( void * parameter )
{
  float  RemainingMoisture = 100.0f;
  for (;;)
  {
    if ( xQueueReceive(xQ_RemainingMoistureMQTT, &RemainingMoisture, portMAX_DELAY) == pdTRUE )
    {
      xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY ); // whiles MQTTlient.loop() is running no other mqtt operations should be in process
      MQTTclient.publish( topicRemainingMoisture_0, String(RemainingMoisture).c_str() );
      xSemaphoreGive( sema_MQTT_KeepAlive );
    }
  } // for (;;)
  vTaskDelete( NULL );
} //void fPublish( void * parameter )
////
void WaterPump0_off()
{
  gpio_set_level( GPIO_NUM_4, LOW); //denergize relay module
  vTaskDelay( 1 );
  gpio_set_level( GPIO_NUM_5, LOW); //denergize/close valve
}
////
void WaterPump0_on()
{
  gpio_set_level( GPIO_NUM_5, HIGH); //energize/open valve
  vTaskDelay( 1 );
  gpio_set_level( GPIO_NUM_4, HIGH); //energize relay module
}
////
void fmqttWatchDog( void * paramater )
{
  int UpdateImeTrigger = 86400; //seconds in a day
  int UpdateTimeInterval = 85000; // get another reading when = UpdateTimeTrigger
  int maxNonMQTTresponse = 12;
  TickType_t xLastWakeTime = xTaskGetTickCount();
  const TickType_t xFrequency = 5000; //delay for mS
  for (;;)
  {
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
    xSemaphoreTake( sema_mqttOK, portMAX_DELAY ); // update mqttOK
    mqttOK++;
    xSemaphoreGive( sema_mqttOK );
    if ( mqttOK >= maxNonMQTTresponse )
    {
      ESP.restart();
    }
    UpdateTimeInterval++; // trigger new time get
    if ( UpdateTimeInterval >= UpdateImeTrigger )
    {
      TimeSet = false; // sets doneTime to false to get an updated time after a days count of seconds
      UpdateTimeInterval = 0;
    }
  }
  vTaskDelete( NULL );
} //void fmqttWatchDog( void * paramater )
////
void fDoMoistureDetector( void * parameter )
{
  //wait for a mqtt connection
  while ( !MQTTclient.connected() )
  {
    vTaskDelay( 250 );
  }
  int      TimeToPublish = 5000000; //5000000uS
  int      TimeForADreading = 100 * 1000; // 100mS
  uint64_t TimePastPublish = esp_timer_get_time(); // used by publish
  uint64_t TimeADreading   = esp_timer_get_time();
  TickType_t xLastWakeTime = xTaskGetTickCount();
  const TickType_t xFrequency = 10; //delay for 10mS
  float    RemainingMoisture = 100.0f; //prevents pump turn on during start up
  bool     pumpOn = false;
  uint64_t PumpOnTime = esp_timer_get_time();
  int      PumpRunTime = 11000000;
  uint64_t PumpOffWait = esp_timer_get_time();
  uint64_t PumpOffWaitFor = 60000000; //one minute
  float    lowMoisture = 23.0f;
  float    highMoisture = 40.0f;
  for (;;)
  {
    //read AD values every 100mS.
    if ( (esp_timer_get_time() - TimeADreading) >= TimeForADreading )
    {
      xEventGroupSetBits( eg, evtADCreading );
      TimeADreading = esp_timer_get_time();
    }
    xQueueReceive(xQ_RM, &RemainingMoisture, 0 ); //receive queue stuff no waiting
    //read gpio 0 is water level good. Yes: OK to run pump : no pump off.   remaining moisture good, denergize water pump otherwise energize water pump.
    if ( RemainingMoisture >= highMoisture )
    {
      WaterPump0_off();
    }
    if ( !pumpOn )
    {
      log_i( "not pump on ");
      if ( gpio_get_level( GPIO_NUM_0 ) )
      {
        if ( RemainingMoisture <= lowMoisture )
        {
          //has one minute passed since last pump energize, if so then allow motor to run
          if ( (esp_timer_get_time() - PumpOffWait) >= PumpOffWaitFor )
          {
            WaterPump0_on();
            log_i( "pump on " );
            pumpOn = !pumpOn;
            PumpOnTime = esp_timer_get_time();
          }
        }
        //xSemaphoreGive( sema_RemainingMoisture );
      } else {
        log_i( "water level bad " );
        WaterPump0_off();
        PumpOffWait = esp_timer_get_time();
      }
    } else {
      /*
         pump goes on runs for X seconds then turn off, then wait PumpOffWaitTime before being allowed to energize again
      */
      if ( (esp_timer_get_time() - PumpOnTime) >= PumpRunTime )
      {
        log_i( "pump off " );
        WaterPump0_off(); // after 5 seconds turn pump off
        pumpOn = !pumpOn;
        PumpOffWait = esp_timer_get_time();
      }
    }
    // publish to MQTT every 5000000uS
    if ( (esp_timer_get_time() - TimePastPublish) >= TimeToPublish )
    {
      xQueueOverwrite( xQ_RemainingMoistureMQTT, (void *) &RemainingMoisture );// data for mqtt publish
      TimePastPublish = esp_timer_get_time(); // get next publish time
    }
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
  }
  vTaskDelete( NULL );
}// end fDoMoistureDetector()
////
void MQTTkeepalive( void *pvParameters )
{
  sema_MQTT_KeepAlive   = xSemaphoreCreateBinary();
  xSemaphoreGive( sema_MQTT_KeepAlive ); // found keep alive can mess with a publish, stop keep alive during publish
  MQTTclient.setKeepAlive( 90 ); // setting keep alive to 90 seconds makes for a very reliable connection, must be set before the 1st connection is made.
  TickType_t xLastWakeTime = xTaskGetTickCount();
  const TickType_t xFrequency = 250; // 250mS
  for (;;)
  {
    //check for a is-connected and if the WiFi 'thinks' its connected, found checking on both is more realible than just a single check
    if ( (wifiClient.connected()) && (WiFi.status() == WL_CONNECTED) )
    {
      xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY ); // whiles MQTTlient.loop() is running no other mqtt operations should be in process
      MQTTclient.loop();
      xSemaphoreGive( sema_MQTT_KeepAlive );
    }
    else {
      log_i( "MQTT keep alive found MQTT status %s WiFi status %s", String(wifiClient.connected()), String(WiFi.status()) );
      if ( !(wifiClient.connected()) || !(WiFi.status() == WL_CONNECTED) )
      {
        connectToWiFi();
      }
      connectToMQTT();
    }
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
  }
  vTaskDelete ( NULL );
}
////
void connectToMQTT()
{
  // create client ID from mac address
  byte mac[5];
  int count = 0;
  WiFi.macAddress(mac); // get mac address
  String clientID = String(mac[0]) + String(mac[4]);
  log_i( "connect to mqtt as client %s", clientID );
  while ( !MQTTclient.connected() )
  {
    MQTTclient.disconnect();
    MQTTclient.connect( clientID.c_str(), mqtt_username, mqtt_password );
    vTaskDelay( 250 );
    count++;
    if ( count == 5 )
    {
      ESP.restart();
    }
  }
  MQTTclient.setCallback( mqttCallback );
  MQTTclient.subscribe( topicOK );
}
////
void connectToWiFi()
{
  int TryCount = 0;
  while ( WiFi.status() != WL_CONNECTED )
  {
    TryCount++;
    WiFi.disconnect();
    WiFi.begin( SSID, PASSWORD );
    vTaskDelay( 4000 );
    if ( TryCount == 10 )
    {
      ESP.restart();
    }
  }
  WiFi.onEvent( WiFiEvent );
} // void connectToWiFi()
//////
void fparseMQTT( void *pvParameters )
{
  struct stu_message px_message;
  for (;;)
  {
    if ( xQueueReceive(xQ_Message, &px_message, portMAX_DELAY) == pdTRUE )
    {
      if ( px_message.topic == topicOK )
      {
        xSemaphoreTake( sema_mqttOK, portMAX_DELAY );
        mqttOK = 0; // clear mqtt ok count
        xSemaphoreGive( sema_mqttOK );
      }
      if ( !TimeSet )
      {
        String temp = "";
        temp = px_message.payload[0];
        temp += px_message.payload[1];
        temp += px_message.payload[2];
        temp += px_message.payload[3];
        int year =  temp.toInt();
        temp = "";
        temp = px_message.payload[5];
        temp += px_message.payload[6];
        int month =  temp.toInt();
        temp = "";
        temp = px_message.payload[8];
        temp += px_message.payload[9];
        int day =  temp.toInt();
        temp = "";
        temp = px_message.payload[11];
        temp += px_message.payload[12];
        int hour =  temp.toInt();
        temp = "";
        temp = px_message.payload[14];
        temp += px_message.payload[15];
        int min =  temp.toInt();
        rtc.setTime( 0, min, hour, day, month, year );
        log_i( "%s  ", rtc.getTime() );
        TimeSet = true;
      }
      // manual pump control
      if ( str_eTopic == topicPumpState )
      {
        if ( String(strPayload) == "off" )
        {
          WaterPump0_off();
          manualPumpOn = false;
        }
        if ( String(strPayload) == "on" )
        {
          WaterPump0_on();
          manualPumpOn = true;
        }
      }
    }
  } //for(;;)
  vTaskDelete ( NULL );
} // void fparseMQTT( void *pvParameters )
////
void loop() {}

To use your own header file click on the New Tab, eneter a file name, save and add the code to the new tab.

Excuse me, a part of the main.cpp was pasted wrong.

I have now updated the message.

That's the code I run from platformIO with CLion as IDE.

Most likely you'll want help from the platformIO and Clion people as this does not seem to be an Arduino IDE issue.

Not my thing. Good luck.

Sorry, but I developed all the code in Arduino IDE and had the same problem, today I decided to move my project to another IDE to try another way, but I've the same problem with both IDEs. So in this case it doesn't matter what IDE I'm using.

But thanks for your help.

What is the problem you are having under the Arduino IDE?

As you can see in my third message I've the setup and loop functions in the first codeblock.

The problem is explained in my first message.

But I can repeat it you don't worry. When I remove the code lines related with AlarmController, the program runs normally and shows prints through serial monitor, but when I add my alarm controller displays nothing via serial monitor, and I think it doesn't works.

When I upload the sketch always is doing correctly.

You are indicating that when you add the class alarm.h the thing does not works as expected? What does "does not work mean"?

Is alarm.h a tab with your ino? Is alarm.h saved in the same directory as the project file?

Thank you for your answers @Idahowalker finally I solved my problem.

The problem was that I was using the CSVParser library in AlarmController.h, when I changed it, the program works correctly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.