#include "secrets.h"
#include <WiFiClientSecure.h>
#include <MQTTClient.h>
#include <ArduinoJson.h>
#include "WiFi.h"
#include <M5Core2.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"
#include "SHT3X.h"
SHT3X sht30;
Adafruit_BMP280 bme;
float tmp = 0.0;
float hum = 0.0;
float pressure = 0.0;
// The MQTT topics that this device should publish/subscribe
#define AWS_IOT_PUBLISH_TOPIC "core2/env"
#define AWS_IOT_SUBSCRIBE_TOPIC "core2/msg"
WiFiClientSecure net = WiFiClientSecure();
MQTTClient client = MQTTClient(256);
void messageHandler(String &topic, String &payload) {
Serial.println("incoming: " + topic + " - " + payload);
}
void connectAWS()
{
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
// Configure WiFiClientSecure to use the AWS IoT device credentials
net.setCACert(AWS_CERT_CA);
net.setCertificate(AWS_CERT_CRT);
net.setPrivateKey(AWS_CERT_PRIVATE);
// Connect to the MQTT broker on the AWS endpoint we defined earlier
client.begin(AWS_IOT_ENDPOINT, 8883, net);
// Create a message handler
client.onMessage(messageHandler);
Serial.print("Connecting to AWS IOT");
while (!client.connect(THINGNAME)) {
Serial.print(".");
delay(100);
}
if(!client.connected()){
Serial.println("AWS IoT Timeout!");
return;
}
// Subscribe to a topic
client.subscribe(AWS_IOT_SUBSCRIBE_TOPIC);
Serial.println("AWS IoT Connected!");
}
void publishMessage()
{
pressure = bme.readPressure();
if(sht30.get()==0){
tmp = sht30.cTemp;
hum = sht30.humidity;
}
Serial.printf("Temperatura: %2.2f*C Humedad: %0.2f%% Pressure: %0.2fPa\r\n", tmp, hum, pressure);
delay(100);
StaticJsonDocument<200> doc;
doc["tmp"] = tmp;
doc["hum"] = hum;
doc["pressure"] = pressure;
char jsonBuffer[512];
serializeJson(doc, jsonBuffer); // print to client
client.publish(AWS_IOT_PUBLISH_TOPIC, jsonBuffer);
}
void setup() {
M5.begin();
Wire.begin();
bme.begin(0x76);
connectAWS();
}
void loop() {
publishMessage();
client.loop();
delay(1000);
}
````Preformatted text`
error message
c:/users/user/appdata/local/arduino15/packages/m5stack/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\user\AppData\Local\Temp\arduino_cache_292836\core\core_74931c40ecb81851eef067ecc51fba4b.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to `setup()'
c:/users/user/appdata/local/arduino15/packages/m5stack/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\user\AppData\Local\Temp\arduino_cache_292836\core\core_74931c40ecb81851eef067ecc51fba4b.a(main.cpp.o):(.literal._Z8loopTaskPv+0xc): undefined reference to `loop()'
c:/users/user/appdata/local/arduino15/packages/m5stack/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\user\AppData\Local\Temp\arduino_cache_292836\core\core_74931c40ecb81851eef067ecc51fba4b.a(main.cpp.o): in function `loopTask(void*)':
C:\Users\user\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.0.3\cores\esp32/main.cpp:42: undefined reference to `setup()'
c:/users/user/appdata/local/arduino15/packages/m5stack/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\user\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.0.3\cores\esp32/main.cpp:48: undefined reference to `loop()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board M5Stack-Core2.
How did you miss this ?
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.

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