【问题标题】:Giving an Error when adding firebase library and AHT10 library together一起添加 firebase 库和 AHT10 库时出错
【发布时间】:2023-02-21 11:28:26
【问题描述】:

我写了一个代码来获取温度并使用 ESP32 将数据发送到 firebase DB

但是在代码中添加 AHTX0 library 时出现错误。 这是错误。 错误是什么? 提前致谢

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x400e7fcf PS : 0x00060f30 A0 : 0x800e7f16 A1 : 0x3ffb2720
A2 : 0x00000000 A3 : 0x3ffb2747 A4 : 0x00000003 A5 : 0x00000001
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800e85be A9 : 0x3ffb2700
A10 : 0x0000472d A11 : 0x00000000 A12 : 0x0000472d A13 : 0x00006d80
A14 : 0x00003934 A15 : 0x00393430 SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000000c LBEG : 0x40084765 LEND : 0x4008476d LCOUNT : 0x00000027

Backtrace:0x400e7fcc:0x3ffb27200x400e7f13:0x3ffb2740 0x400d36f3:0x3ffb2770 0x400ea895:0x3ffb2820

这是代码。

#include <Arduino.h>
#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include <Wire.h>
#include <Adafruit_AHTX0.h>

#include "time.h"

// Provide the token generation process info.
#include "addons/TokenHelper.h"
// Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"

// Insert your network credentials
#define WIFI_SSID "slt fibre"
#define WIFI_PASSWORD "wifi-password"

// Insert Firebase project API Key
#define API_KEY "xxxxxxxxxxxxxx"

// Insert Authorized Email and Corresponding Password
#define USER_EMAIL "xxxxxxx@gmail.com"
#define USER_PASSWORD "xxxxxxx"

// Insert RTDB URLefine the RTDB URL
#define DATABASE_URL "https://esp32-weather-app-default-rtdb.europe-west1.firebasedatabase.app"

// Define Firebase objects
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;

// Variable to save USER UID
String uid;

// Database main path (to be updated in setup with the user UID)
String databasePath;
// Database child nodes
String tempPath = "/temperature";
String humPath = "/humidity";
String presPath = "/pressure";
String timePath = "/timestamp";

// Parent Node (to be updated in every loop)
String parentPath;

int timestamp;
FirebaseJson json;

const char* ntpServer = "pool.ntp.org";

// BME280 sensor
// I2C
float temperature;
float humidity;
float pressure;

// Timer variables (send new readings every three minutes)
unsigned long sendDataPrevMillis = 0;
unsigned long timerDelay = 180000;

// Initialize BME280


// Initialize WiFi
void initWiFi() {
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
  Serial.println();
}

// Function that gets current epoch time
unsigned long getTime() {
  time_t now;
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    //Serial.println("Failed to obtain time");
    return (0);
  }
  time(&now);
  return now;
}
Adafruit_AHTX0 aht;
void setup() {
  Serial.begin(115200);

  // Initialize BME280 sensor

  initWiFi();
  configTime(0, 0, ntpServer);

  // Assign the api key (required)
  config.api_key = API_KEY;

  // Assign the user sign in credentials
  auth.user.email = USER_EMAIL;
  auth.user.password = USER_PASSWORD;

  // Assign the RTDB URL (required)
  config.database_url = DATABASE_URL;

  Firebase.reconnectWiFi(true);
  fbdo.setResponseSize(4096);

  // Assign the callback function for the long running token generation task */
  config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

  // Assign the maximum retry of token generation
  config.max_token_generation_retry = 5;

  // Initialize the library with the Firebase authen and config
  Firebase.begin(&config, &auth);

  // Getting the user UID might take a few seconds
  Serial.println("Getting User UID");
  while ((auth.token.uid) == "") {
    Serial.print('.');
    delay(1000);
  }

  // Print user UID
  uid = auth.token.uid.c_str();
  Serial.print("User UID: ");
  Serial.println(uid);

  // Update database path
  databasePath = "/UsersData/" + uid + "/readings";

}

void loop() {

  // Send new readings to database
  if (Firebase.ready() && (millis() - sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)) {
    sendDataPrevMillis = millis();

    //Get current timestamp
    timestamp = getTime();
    Serial.print ("time: ");
    Serial.println (timestamp);

    parentPath = databasePath + "/" + String(timestamp);
    sensors_event_t humidity, temp;
    aht.getEvent(&humidity, &temp);

    json.set(tempPath.c_str(), temp.temperature);
    json.set(humPath.c_str(), humidity.relative_humidity);
    json.set(presPath.c_str(), String(22 / 100.0F));
    json.set(timePath, String(timestamp));
    Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
  }
}

我在 Firebase.h 和 FirebaseArduino.h 中寻找问题,但没有发现任何问题

【问题讨论】:

  • 下载 ESPExceptionDecoder 插件,运行跟踪,如果您无法确定原因的来源,请通过添加跟踪来更新您的帖子。

标签: arduino arduino-esp32


【解决方案1】:

您的代码不会调用 aht 对象上的 begin() 方法。 begin() 方法对其进行初始化并准备使用。如果您在使用库中的其他方法之前不调用它,结果将是未定义的,并且可能会导致您所看到的崩溃。

你的代码:

Adafruit_AHTX0 aht;
void setup() {
  Serial.begin(115200);

  // Initialize BME280 sensor

  initWiFi();

应该是这样的:

Adafruit_AHTX0 aht;
void setup() {
  Serial.begin(115200);

  if(!aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while(1)
      delay(10);
  }

  Serial.println("AHT10 or AHT20 found");

  initWiFi();

Adafruit 投入大量精力为其产品和软件编写examplestutorials。如果您对其中之一有疑问,那么这些是一个很好的起点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多