我有一个带有EP8266的项目,使用网络服务器控制一些LED并读取BMP180传感器。我收到了一个名为Soft WDT reset
的错误。我的代码工作正常,但出于某种原因现在我尝试使用9V电池时没有。我不知道该怎么做。我希望你能帮助我理解。所有提示都会有所帮助。
提前感谢您的帮助。
#include "NeoPixelBus.h" // Library to control Pixel Stick
#include "ESP8266WiFi.h" // WiFi Library
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
#define PixelCount 16 // Number of LEDS on stick
#define PixelPin 2 // NodeMCU pin 2 (RX) connected to Digital In of Pixel
Stick
const char* ssid = "Louise"; // Name of WiFi Network
const char* password = "xxxx"; // Password of WiFi Network
double referencePressure;
int firstrun = 0; // Check if system was just powered on
int buttonpressed = 5; // To hold which button was pressed on Web Page
// Initialize Library
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
RgbColor black(0);
// Define Arrays for colors
long switchled01[] = {
0x19257B, 0x7B7A19, 0x19257B, 0x7B7A19, 0x19257B, 0x7B7A19, 0x19257B,
0x7B7A19
};
WiFiServer server(80); // Define Web Server Port
void setup() {
Serial.begin(115200);
delay(10);
if (!bmp.begin()) {
Serial.println("Could not find BMP180 or BMP085 sensor at 0x77");
while (1) {}
}
strip.Begin(); // Init of Pixel Stick
strip.Show(); // Clears any lit up LEDS
// Connect to WiFi network
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// Wait until connected to WiFi
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
// Confirmation that WiFi is connected
Serial.println("");
Serial.println("WiFi connected");
// Start the Web Server
server.begin();
Serial.println("Web Server Started");
// Display IP address
Serial.print("You can connect to the Server here: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println();
Serial.println();
}
void loop() {
// Check if someone is connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Read which button was pressed on the Web Page
String request = client.readStringUntil('\r');
// Light up LEDS based on the button pressed
if (request.indexOf("/OFF=1") != -1) {
for (int led = 0; led < 8; led++) {
strip.SetPixelColor(0, black);
strip.SetPixelColor(0, black);
strip.SetPixelColor(1, black);
strip.SetPixelColor(2, black);
strip.SetPixelColor(3, black);
strip.SetPixelColor(4, black);
strip.SetPixelColor(5, black);
strip.SetPixelColor(6, black);
strip.SetPixelColor(7, black);
strip.Show();
}
strip.Show();
buttonpressed = LOW;
firstrun = 1;
}
if (request.indexOf("/ON=1") != -1) {
for (int led = 0; led < 8; led++) {
strip.SetPixelColor(led, HtmlColor(switchled01[led]));
}
strip.Show();
buttonpressed = HIGH;
firstrun = 1;
}
// Display the HTML web page
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
// Web Page Heading
client.println("<body><h1>Sistema de LEDS off babby room</h1>");
// Create Web Page
client.println("HTTP/1.1 200 OK"); // HTML Header
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<meta charset=ISO-8859-15>");
client.println("<html>"); // Start of HTML
client.println("<style>");
client.println("body {background-color: #ACAEAD;}"); // Set Background Color
client.println("Button {background-color: #195B6A; border: none; color: white; padding: 16px 40px;"); // Set Background Color
client.println("</style>");
client.println("<h1>LEDS shelf</h1>");
client.println("<h4>Liga sistema de LEDS nas prateleiras de nuvem e ativa sensor de temperatura</h4>");
if (buttonpressed == LOW) {
client.print("OFF");
}
if (buttonpressed == HIGH) {
client.print("ON");
}
client.println("<br><br>");
client.println("<a href=\"/ON=1\"\"><button class=\"/Butme\">Ligar</button></a><br />");
client.println("<br><br>");
client.println("<a href=\"/OFF=1\"\"><button class=\"/Butme\">Desligar</button></a>");
client.println("<br><br>");
client.println("<h1>Dados Metereológicos</h1>"); client.println("<br><br>");
client.println("<img border=\"0\" src=\"https://www.dropbox.com/s/11n8oio8f6yady9/ESPWheater.png?dl=0\" /><br />");
client.println("<br><br>");
client.println("<h3>Temperatura agora = ");
client.println(bmp.readTemperature());
client.println("°C</h3><h3>Pressão do Ar = ");
client.println(bmp.readPressure());
client.println("%</h3><h3>Altitude = ");
client.println(bmp.readAltitude());
client.println(" Metros</h3>");
client.println("</html>");
delay(10);
}
答案 0 :(得分:2)
如果在更换电源时它停止工作,则可能是由电源引起的。考虑使用18650电池和类似TP4056的电池,它可以帮助您调节输出电压并为电池充电。