Arduino: 1.8.10 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200" panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x7855fb] goroutine 1 [running]: github.com/arduino/arduino-cli/legacy/builder.ResolveLibrary(0x11ce45a0, 0x11d28079, 0x5, 0x11d28079) /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/resolve_library.go:64 +0x14b github.com/arduino/arduino-cli/legacy/builder.findIncludesUntilDone(0x11ce45a0, 0x12062ae0, 0x88ed00, 0x11c94d20, 0x11c07ce8, 0x11fc1a00, 0x0) /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:358 +0x3b6 github.com/arduino/arduino-cli/legacy/builder.(*ContainerFindIncludes).Run(0xdebc68, 0x11ce45a0, 0xdebc68, 0x0) /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:152 +0x3e5 github.com/arduino/arduino-cli/legacy/builder.runCommands(0x11ce45a0, 0x11c3fe1c, 0x20, 0x20, 0x1, 0x184ffff, 0x800) /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:210 +0xbd github.com/arduino/arduino-cli/legacy/builder.(*Builder).Run(0x11c7df40, 0x11ce45a0, 0xdebbb4, 0x11c4ec90) /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:117 +0xb9c github.com/arduino/arduino-cli/legacy/builder.RunBuilder(...) /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:226 main.main() /home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-builder/main.go:398 +0x6d2 C:\Program Files (x86)\Arduino\arduino-builder returned 2 Error compiling for board NodeMCU 0.9 (ESP-12 Module). This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com/home-automation-using-esp8266/
*********/
// Loading libraries
#include
#include “DHT.h”
// Uncomment one of the lines below for whatever DHT sensor type you’re using
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
// REPLACE THOSE VARIABLES WITH YOUR SSID and PASSWORD
const char* ssid = “*******”;
const char* password = “******”;
// Web server runs on port 8888
WiFiServer server(8888);
// Header page
String header;
// GPIOs variables
String output1State = “Off”;
String output2State = “Off”;
int output1 = 16;
int output2 = 2;
// DHT sensor pin
const int DHTPin = 5;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);
// Temporary variables to store DHT data
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];
// Smoke sensor pin
int smokePin = A0;
// Smoke threshold, you can adjust this value for your own readings
int smokeThres = 60;
// PIR mtion sensor
const int motionSensor = 4;
// Control variables for smoke and motion sensors
boolean armSmoke = false;
boolean smokeTriggered = false;
boolean armMotion = false;
boolean motionTriggered = false;
// LEDs for smoke and motion status
const int smokeLED = 13;
const int motionLED = 12;
// Buzzer pin
const int buzzerPin = 14;
// Timers auxiliar variables
unsigned long now = millis();
unsigned long lastSmokeCheck = 0;
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
// Only runs once
void setup() {
// Preparing GPIOs
pinMode(output1, OUTPUT);
digitalWrite(output1, LOW);
pinMode(output2, OUTPUT);
digitalWrite(output2, LOW);
pinMode(smokeLED, OUTPUT);
digitalWrite(smokeLED, LOW);
pinMode(motionLED, OUTPUT);
digitalWrite(motionLED, LOW);
pinMode(buzzerPin, OUTPUT);
pinMode(smokePin, INPUT);
// Setting motionSensor as an interrupt
attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);
// Initializing DHT sensor
dht.begin();
// Initializing serial port for debugging purposes
Serial.begin(115200);
delay(10);
// Connecting to WiFi network
Serial.println();
Sorry for the break in code
Continued
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
// Starting the web server
server.begin();
Serial.println(“Web server running. Waiting for the ESP IP…”);
delay(10000);
// Printing the ESP IP address in the serial monitor
Serial.print(“http://”);
Serial.print(WiFi.localIP());
Serial.println(“:8888”);
}
// Runs over and over again
void loop() {
now = millis();
// Checks current smoke value every 500 milliseconds
if (now – lastSmokeCheck > 500) {
lastSmokeCheck = now;
int smokeValue = analogRead(smokePin);
// If the smoke sensor is armed and smoke is detected. It sends a notification saying “Smoke Detected” that is printed in the dashboard
if (smokeValue > smokeThres && armSmoke) {
Serial.print(“Pin A0: “);
Serial.println(smokeValue);
tone(buzzerPin, 1000, 200);
if (!smokeTriggered) {
Serial.println(“SMOKE DETECTED!”);
smokeTriggered = true;
}
}
}
// Listenning for new clients
WiFiClient client = server.available();
// When a client is available
if (client) {
previousTime = now;
Serial.println(“New client”);
// Reads temperature and humidity
readTemperatureHumidity();
// Bolean to locate when the http request ends
boolean blank_line = true;
while (client.connected() && now – previousTime = 0) {
//successful login
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”);
client.println();
// Checks the current URL that you opened in your web server
// For example the URL /output1off turns the output 1 off
// The /armSmoke URL arms the smoke sensor and so on…
// These URL are opened when you press the buttons in your dashboard
if (header.indexOf(“GET / HTTP/1.1”) >= 0) {
Serial.println(“Main Web Page”);
}
else if (header.indexOf(“GET /output1on HTTP/1.1”) >= 0) {
Serial.println(“Output 1 On”);
output1State = “On”;
digitalWrite(output1, HIGH);
}
else if (header.indexOf(“GET /output1off HTTP/1.1”) >= 0) {
Serial.println(“Output 1 Off”);
output1State = “Off”;
digitalWrite(output1, LOW);
}
else if (header.indexOf(“GET /output2on HTTP/1.1”) >= 0) {
Serial.println(“Output 2 On”);
output2State = “On”;
digitalWrite(output2, HIGH);
}
else if (header.indexOf(“GET /output2off HTTP/1.1”) >= 0) {
Serial.println(“Output 2 Off”);
output2State = “Off”;
digitalWrite(output2, LOW);
}
else if (header.indexOf(“GET /armSmoke HTTP/1.1”) >= 0) {
Serial.println(“Smoke sensor is: Armed”);
digitalWrite(smokeLED, HIGH);
armSmoke = true;
}
else if (header.indexOf(“GET /disarmSmoke HTTP/1.1”) >= 0) {
Serial.println(“Smoke sensor is: Disarmed”);
digitalWrite(smokeLED, LOW);
armSmoke = false;
smokeTriggered = false;
}
else if (header.indexOf(“GET /armMotion HTTP/1.1”) >= 0) {
Serial.println(“Motion sensor is: Armed”);
digitalWrite(motionLED, HIGH);
armMotion = true;
}
else if (header.indexOf(“GET /disarmMotion HTTP/1.1”) >= 0) {
Serial.println(“Motion sensor is: Disarmed”);
digitalWrite(motionLED, LOW);
armMotion = false;
motionTriggered = false;
}
// Displays your html web page
client.println(“”);
client.println(“”);
client.println(“”);
client.println(“”);
// Loads Bootstrap framework to give you the mobile reponsive web page and the buttons look
client.println(“”);
client.println(“”);
client.println(“”);
client.println(“ESP8266 Web Server – Refresh“);
// Generates buttons to control the outputs
client.println(“Output 1 – State: ” + output1State + “”);
// If LED is off, it shows the button to turn the output 1 on
if (output1State == “Off”) {
client.println(“ON“);
}
// If LED is on, it shows the button to turn the output 1 off
else if (output1State == “On”) {
client.println(“OFF“);
}
client.println(“Output 2 – State: ” + output2State + “”);
// If LED is off, it shows the button to turn the output 2 on
if (output2State == “Off”) {
client.println(“ON“);
}
// If LED is on, it shows the button to turn the output 2 off
else if (output2State == “On”) {
client.println(“OFF“);
}
// Checks if there was smoke detected in your room and prints a message according to the current state (smoke detected or no smoke)
if (smokeTriggered) {
client.println(“Smoke Sensor – State: Smoke detected”);
}
else {
client.println(“Smoke Sensor – State: No smoke”);
}
// If the smoke sensor is armed, it shows the button to disarm the sensor
if (armSmoke) {
client.println(“Disarm“);
}
// If the smoke sensor is disarmed, it shows the button to arm the sensor
else {
client.println(“Arm“);
}
// Checks if there was motion detected in your room and prints a message according to the current state (motion detected or no motion)
if (motionTriggered) {
client.println(“Motion Sensor – State: Motion detected”);
}
else {
client.println(“Motion Sensor – State: No motion”);
}
// If the motion sensor is armed, it shows the button to disarm the sensor
if (armMotion) {
client.println(“Disarm“);
}
// If the motion sensor is disarmed, it shows the button to arm the sensor
else {
client.println(“Arm“);
}
// Prints the latest temperatuer and humidity readings
client.println(“Temperature: “);
client.println(celsiusTemp);
client.println(“*CTemperature: “);
client.println(fahrenheitTemp);
client.println(“*FHumidity: “);
client.println(humidityTemp);
client.println(“%”);
client.println(“”);
}
// If you enter wrong user or password, the http request fails…
else {
client.println(“HTTP/1.1 401 Unauthorized”);
client.println(“WWW-Authenticate: Basic realm=\”Secure\””);
client.println(“Content-Type: text/html”);
client.println();
client.println(“Authentication failed”);
}
header = “”;
break;
}
if (c == ‘\n’) {
// When starts reading a new line
blank_line = true;
}
else if (c != ‘\r’) {
// When finds a character on the current line
blank_line = false;
}
}
}
// Closing the client connection
delay(1);
client.stop();
Serial.println(“Client disconnected.”);
}
}
void readTemperatureHumidity() {
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
// Computes temperature values in Celsius
float hic = dht.computeHeatIndex(t, h, false);
dtostrf(hic, 6, 2, celsiusTemp);
// Computes temperature values in Fahrenheit
float hif = dht.computeHeatIndex(f, h);
dtostrf(hif, 6, 2, fahrenheitTemp);
// Stores humidity
dtostrf(h, 6, 2, humidityTemp);
// Serial prints that are used for debugging purposes
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t Heat index: “);
Serial.print(hic);
Serial.println(” *C “);
Serial.print(hif);
Serial.println(” *F”);
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t Heat index: “);
Serial.print(hic);
Serial.println(” *C “);
Serial.print(hif);
Serial.println(” *F”);
return;
}
// Detects motion
ICACHE_RAM_ATTR void detectsMovement() {
Serial.println(“MOTION!”);
// If the motion sensor is armed and motion is detected. It sends a notification saying “Motion Detected” that is printed in the dashboard
if (armMotion && !motionTriggered) {
Serial.println(“MOTION DETECTED!”);
motionTriggered = true;
}
}