Hi there,
to keep it clearer i created a new thread.
My code can be compiled but for some reasons my raspberry can’t receive the temp and humid.
I use an ESP32 NodeMCU with a raspberry pi (influxdb, mqtt & grafana).
With help from this community (manuelbl) i changed my code from Arduino to PlatformIO. I added some void’s and *void mqttPublish(const char topic, float payload);
This is the code:
....
void setup() {
Serial.begin(115200);
while (! Serial);
if (!bme.begin(MY_BME280_ADDRESS)) {
Serial.println("Could not find a valid BME280 sensor, check wiring or BME-280 address!");
while (1);
}
// Use force mode so that the sensor returns to sleep mode when the measurement is finished
bme.setSampling(Adafruit_BME280::MODE_FORCED,
Adafruit_BME280::SAMPLING_X1, // temperature
Adafruit_BME280::SAMPLING_NONE, // pressure
Adafruit_BME280::SAMPLING_X1, // humidity
Adafruit_BME280::FILTER_OFF);
void setupWifi();
mqttClient.setServer(MQTT_SERVER, 1883);
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
}
void mqttPublish(const char *topic, float payload);
void loop() {
if (!mqttClient.connected()) {
void mqttReconnect();
}
mqttClient.loop();
long now = millis();
if (now - lastMsgTime > MQTT_PUBLISH_DELAY) {
lastMsgTime = now;
// Reading BME280 sensor data
bme.takeForcedMeasurement(); // has no effect in normal mode
humidity = bme.readHumidity();
temperature = bme.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println(temperature);
Serial.println(humidity);
Serial.println("BME280 reading issues");
return;
}
// Publishing sensor data
mqttPublish(MQTT_TOPIC_TEMPERATURE, temperature);
mqttPublish(MQTT_TOPIC_HUMIDITY, humidity);
delay(100);
esp_deep_sleep_start();
}
}
void setupWifi() {
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void mqttReconnect() {
while (!mqttClient.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (mqttClient.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASSWORD,
MQTT_TOPIC_STATE, 1, true, "disconnected", false)) {
Serial.println("connected");
// Once connected, publish an announcement...
mqttClient.publish(MQTT_TOPIC_STATE, "connected", true);
} else {
Serial.print("failed, rc=");
Serial.print(mqttClient.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void mqttPublish(const char *topic, float payload) {
Serial.print(topic);
Serial.print(": ");
Serial.println(payload);
mqttClient.publish(topic, String(payload).c_str(), true);
}
After i uploaded it to my ESP32 i got the following messages into the monitor:
Code used and edited with Platformio:
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:928
ho 0 tail 12 room 4
load:0x40078000,len:8740
load:0x40080400,len:5800
entry 0x4008069c
home/bme280/temperature: 20.92
home/bme280/humidity: 56.32
Nothing to see of my serial.print
This is my ‘old’ code that works with Arduino:
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Connecting to Unifi
.
WiFi connected
IP address: 10.0.1.66
Attempting MQTT connection...connected
home/bme280/temperature: 21.14
home/bme280/humidity: 55.48
I got following tip: Arduino file compile errors - #12 by manuelbl
I need help please, i changed only voids but it doenst work i have no idea why.