Hi,
For context:
I am playing around with the Cheap Yellow Display and LVGL+Squareline studio (LVGL for short) (trying to have some buttons for my HomeAssisyance instance.
With LVGL, the events are handled in a separate file called ui_events.cpp, extraction here:
/ This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.6
// Project name: COCINA
#include "ui.h"
#include <Arduino.h>
#include "config.h"
void CambiaHormo(lv_event_t * e)
{
String Str4 = lv_label_get_text(ui_LabelHornoStatus1);
Serial.println( Str4 );
if (Str4== "OFF"){
lv_label_set_text(ui_LabelHornoStatus1, "ON");
client.publish(horno_topic_cmnd, "ON");
Serial.print("ON");
}
if (Str4== "ON"){
lv_label_set_text(ui_LabelHornoStatus1, "OFF");
client.publish(horno_topic_cmnd, "OFF");
Serial.print("OFF");
}
}
But, the main part of the program is in the main.cpp file, in particular the wifi and Mqtt client
As you can read above, I am trying to publish in the MQTT broker once the button is clicked
So I read that I need to use the Keyword extern, and I used for the the follwoing lines in the main.cpp
extern WiFiClient espClient;
extern PubSubClient client(espClient);
But seem that that the compiler does not like it, as I receive the following error:
Compiling .pio\build\esp32dev\src\ui_events.cpp.o
In file included from src/main.cpp:5:
.pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.h:973:8: warning: #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available! [-Wcpp]
#warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!
^~~~~~~
src/ui_events.cpp: In function 'void CambiaHormo(lv_event_t*)':
src/ui_events.cpp:17:3: error: 'client' was not declared in this scope
client.publish(horno_topic_cmnd, "ON");
^~~~~~
src/ui_events.cpp:17:3: note: suggested alternative: 'Client'
client.publish(horno_topic_cmnd, "ON");
^~~~~~
Client
src/ui_events.cpp:22:3: error: 'client' was not declared in this scope
client.publish(horno_topic_cmnd, "OFF");
^~~~~~
src/ui_events.cpp:22:3: note: suggested alternative: 'Client'
client.publish(horno_topic_cmnd, "OFF");
^~~~~~
Client
src/main.cpp:30:37: warning: 'client' initialized and declared 'extern'
extern PubSubClient client(espClient);
How can I access the espclient from the ui_events.cpp?
I guess that I can create flag variables and push the MQTT messages from the Main.cpp Loop() function… but I am wondering how to do splitting CPP files in VCS+PlatformnIO (for the sake of learning)
Thanks in advance for your help.
Regards