Почему мой DEV ESP32 сбрасывается снова и снова?C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Почему мой DEV ESP32 сбрасывается снова и снова?

Сообщение Anonymous »

Итак, я попытался поднять ИИ, но теперь проблема в том, что сообщение об ошибке и сброс ESP32. Нет никаких проблем с SD Reader BC, он работает с моим другим Pruce, и в ESP32 нет ничего, что соединение хорошо припаяно, так что это не проблема. Я был бы признателен за любой комментарий за помощь! Спасибо
Соединения:
mosi: gpio 23
miso: gpio 19 sck: gpio 18 < /p>
cs: gpio 5 < /p>
gnd: gnd
vcc: 5V < /p>
#include
#include
#include
#include
#include
#include
#include

#define SD_CS_PIN 5 // SD Card Chip Select pin

const char* ssid = "ESP32_KI";
const char* password = "12345678";

WebServer server(80);

// Structure to hold a question-answer pair
struct QAPair {
String question;
String answer;
};

std::vector knowledgeBase;
std::map synonyms;
std::set stopwords;

// Function declarations
void loadSynonyms();
void replaceSynonyms(String &sentence);
void loadStopwords();
void removeStopwords(String &sentence);
String findBestAnswer(String question);
void loadKnowledgeBase();
void saveToSD(String question, String answer);

void setup() {
Serial.begin(115200);
Serial.println("Booting...");

// Start WiFi in SoftAP mode
WiFi.softAP(ssid, password);
Serial.println("WiFi AP started");

// Explicitly initialize the SPI bus:
// SCK: GPIO 18, MISO: GPIO 19, MOSI: GPIO 23, CS: SD_CS_PIN (GPIO 5)
SPI.begin(18, 19, 23, SD_CS_PIN);

// Mimic Arduino Nano style for SD initialization (optional)
pinMode(10, OUTPUT);
delay(100);

// Initialize SD card using the defined CS pin
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD Card Error!");
while(1) { delay(1000); } // Halt if SD card fails to initialize
}
Serial.println("SD Card found!");

// Load knowledge base, synonyms, and stopwords from SD card
loadKnowledgeBase();
loadSynonyms();
loadStopwords();

// Define web server routes
server.on("/", HTTP_GET, []() {
File file = SD.open("/index.html");
if (file) {
server.streamFile(file, "text/html");
file.close();
} else {
server.send(404, "text/plain", "Missing index.html on SD card!");
}
});

server.on("/ask", HTTP_GET, []() {
String question = server.arg("question");
replaceSynonyms(question);
removeStopwords(question);
String answer = findBestAnswer(question);
server.send(200, "text/plain", answer);
});

server.on("/teach", HTTP_GET, []() {
String question = server.arg("question");
String answer = server.arg("answer");
replaceSynonyms(question);
removeStopwords(question);
saveToSD(question, answer);
knowledgeBase.push_back({question, answer});
server.send(200, "text/plain", "Learned!");
});

server.begin();
}

void loop() {
server.handleClient();
}

// A simple token matching algorithm to choose the best answer
String findBestAnswer(String question) {
int bestMatch = 0;
String bestAnswer = "I don't know.";

// Tokenize the question
std::vector questionWords;
int start = 0;
int end = 0;
while ((end = question.indexOf(' ', start)) != -1) {
questionWords.push_back(question.substring(start, end));
start = end + 1;
}
questionWords.push_back(question.substring(start));

// Compare with each QA pair in the knowledge base
for (QAPair pair : knowledgeBase) {
int matchCount = 0;
for (String word : questionWords) {
if (pair.question.indexOf(word) >= 0) {
matchCount++;
}
}
if (matchCount > bestMatch) {
bestMatch = matchCount;
bestAnswer = pair.answer;
}
}
return bestAnswer;
}

// Load the knowledge base from the SD card (knowledge.json)
void loadKnowledgeBase() {
File file = SD.open("/knowledge.json", FILE_READ);
if (!file) {
Serial.println("No knowledge found!");
return;
}
while (file.available()) {
String line = file.readStringUntil('\n');
int splitIndex = line.indexOf("|");
if (splitIndex > 0) {
String q = line.substring(0, splitIndex);
String a = line.substring(splitIndex + 1);
knowledgeBase.push_back({q, a});
}
}
file.close();
}

// Save a new question-answer pair to the SD card (knowledge.json)
void saveToSD(String question, String answer) {
File file = SD.open("/knowledge.json", FILE_APPEND);
if (file) {
file.println(question + "|" + answer);
file.close();
} else {
Serial.println("Error saving to knowledge.json");
}
}

// Replace synonyms in the sentence based on synonyms.txt
void replaceSynonyms(String &sentence) {
for (auto const& pair : synonyms) {
sentence.replace(pair.first, pair.second);
}
}

// Load synonyms from the SD card (synonyms.txt)
void loadSynonyms() {
File file = SD.open("/synonyms.txt", FILE_READ);
if (!file) return;
while (file.available()) {
String line = file.readStringUntil('\n');
int splitIndex = line.indexOf("=");
if (splitIndex > 0) {
String key = line.substring(0, splitIndex);
String value = line.substring(splitIndex + 1);
synonyms[key] = value;
}
}
file.close();
}

// Load stopwords from the SD card (stopwords.txt)
void loadStopwords() {
File file = SD.open("/stopwords.txt", FILE_READ);
if (!file) return;
while (file.available()) {
String line = file.readStringUntil('\n');
line.trim();
stopwords.insert(line);
}
file.close();
}

// Remove stopwords from a sentence
void removeStopwords(String &sentence) {
std::vector words;
int start = 0;
int end = 0;
while ((end = sentence.indexOf(' ', start)) != -1) {
String word = sentence.substring(start, end);
if (stopwords.find(word) == stopwords.end()) {
words.push_back(word);
}
start = end + 1;
}
String lastWord = sentence.substring(start);
if (stopwords.find(lastWord) == stopwords.end()) {
words.push_back(lastWord);
}
sentence = "";
for (String word : words) {
if (sentence.length() > 0) sentence += " ";
sentence += word;
}
}
< /code>
Сообщение об ошибке: < /p>
rst:0x8 (TG1WDT_SYS_RESET),boot:0x12 (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:0x3fff0030,len:4832
load:0x40078000,len:16460
load:0x40080400,len:4
load:0x40080404,len:3504
entry 0x400805cc
Booting...
WLAN gestartet
ets Jul 29 2019 12:21:46

rst:0x8 (TG1WDT_SYS_RESET),boot:0x12 (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:0x3fff0030,len:4832
load:0x40078000,len:16460
load:0x40080400,len:4
load:0x40080404,len:3504
entry 0x400805cc


Подробнее здесь: https://stackoverflow.com/questions/794 ... over-again
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Клиент Firebase ESP32: получение ошибки INVALID_EMAIL при анонимной аутентификации на ESP32
    Anonymous » » в форуме C++
    0 Ответы
    30 Просмотры
    Последнее сообщение Anonymous
  • Arduino Mega (Master) читает данные о старой проволоке от Slave (ESP32 Dev Module)
    Anonymous » » в форуме C++
    0 Ответы
    1 Просмотры
    Последнее сообщение Anonymous
  • Arduino Mega (Master) читает данные о старой проволоке от Slave (ESP32 Dev Module)
    Anonymous » » в форуме C++
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous
  • ESP32-S3 сбрасывает счет и снова начинается с 0
    Anonymous » » в форуме C++
    0 Ответы
    11 Просмотры
    Последнее сообщение Anonymous
  • Как определить, какое устройство создало и использует файлы /dev/input/js№ и /dev/input/event№
    Anonymous » » в форуме Linux
    0 Ответы
    106 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C++»