Hey guys, Neophyte here and need your guidance. I have followed this particular project from the beginning and all has been good until now. Does anyone have any suggestions?
MODULE 2 – Unit 5: Followed instructions for Code for ESP8266 circuit
https://rntlab.com/module-2/controlling-outlets-optional/
Monitor feedback after the upload (with or without inserting the 433 Transmitter in my breadboard)
12:29:36.831 -> load 0x3fff20b8, len 40, room 4
12:29:36.831 -> tail 4
12:29:36.831 -> chksum 0xc9
12:29:36.831 -> csum 0xc9
12:29:36.831 -> v00048a60
12:29:36.831 -> ~ld
12:29:36.967 ->
12:29:36.967 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
12:29:36.967 ->
12:29:36.967 -> load 0x4010f000, len 3460, room 16
12:29:36.967 -> tail 4
12:29:37.000 -> chksum 0xcc
12:29:37.000 -> load 0x3fff20b8, len 40, room 4
12:29:37.000 -> tail 4
12:29:37.000 -> chksum 0xc9
12:29:37.000 -> csum 0xc9
12:29:37.000 -> v00048a60
12:29:37.000 -> ~ld
12:29:37.143 ->
Thanks you in advance and please if this has already been addressed or I am just a dumdum…please be gentle.
I’m retired and very happy to have made it this far. 🙂
SHale
Hi.
Replace this line:
void detectsMovement() {
With this one:
ICACHE_RAM_ATTR void detectsMovement() {
Tell me if that solves the issue.
Regards,
Sara
Hi.
That error usually happens when there is some sort of hardware problem.
What peripherals do you have connected to your board?
How are you powering your board?
Disconnect any peripherals before uploading code, and then, disconnect power, wire the circuit and power the board again.
Try uploading a blinking LED sketch just to check if the board is working fine. Then, tell me what you got.
Regards,
Sara
Thanks for getting back to me Sara.
I am using every peripheral that the lab requires. The previous labs using same 8266 hardware and upload all works fine, I get to my web page, all button on the site work and the Temperature is displayed. Without adding the Transmitter or anything, I proceed to start a new program using and uploading the code provide (same device, added transmitter and removed it to try) for the Control Outlets. It never connects to the wi-fi and the Monitor displays the info I shared in my initial question. If you need anything else please let me know. I will be back early afternoon. USB NODEMCU E12-E
Kind regards,
Sandy
Hi.
Did you install the library we recommend?
Can you share your code?
Regards,
Sara
Yes, the only other library that was not included in the previous lab that I had to install for this project was the RC Switch Library. Provide code below and ‘X” out SSID & Password
Start your code here
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
#include “DHT.h”
// Loading the RCSwitch library to control the outlets
#include <RCSwitch.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 = “XXXXXX”;
const char* password = “XXXXXXXXX”;
// Web Server on port 8888
WiFiServer server(8888);
// variables
String header;
String output1State = “Off”;
String output2State = “Off”;
// DHT Sensor
const int DHTPin = 5;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);
// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];
// Smoke Sensor
int smokePin = A0;
// Smoke Threshold
int smokeThres = 60;
// Control Variables
boolean armSmoke = false;
boolean smokeTriggered = false;
boolean armMotion = false;
boolean motionTriggered = false;
// PIR Motion Sensor
const int motionSensor = 4;
// Status LEDs
const int smokeLED = 13;
const int motionLED = 12;
// Buzzer
const int buzzerPin = 14;
// Timers auxiliar variables
long now = millis();
long lastSmokeCheck = 0;
// Initializes the RCSwitch
RCSwitch mySwitch = RCSwitch();
// only runs once
void setup() {
mySwitch.enableTransmit(16);
// YOU MUST REPLACE WITH YOUR PULSE LENGTH
mySwitch.setPulseLength(199);
pinMode(smokeLED, OUTPUT);
pinMode(motionLED, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(smokePin, INPUT);
attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);
dht.begin();
// Initializing serial prt for debugging purposes
Serial.begin(115200);
delay(10);
// Connecting to WiFi network
Serial.println();
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
Serial.println(WiFi.localIP());
}
// runs over and over again
void loop() {
now = millis();
// Detects smoke and when smoke is detected enables a notification for the dashboard
if (now – lastSmokeCheck > 500) {
lastSmokeCheck = now;
int smokeValue = analogRead(smokePin);
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){
Serial.println(“New client”);
// Reads temperature and humidity
readTemperatureHumidity();
// bolean to locate when the http request ends
boolean blank_line = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
header += c;
if (c == ‘\n’ && blank_line) {
// checking if header is valid
// dXNlcjpwYXNz = ‘user:pass’ (user:pass) base64 encode
Serial.print(header);
// Finding the right credential string
if(header.indexOf(“dXNlcjpwYXNz”) >= 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…
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”;
// Sends binary code to turn on Desk Light
// BINARY CODE EXAMPLE. REPLACE WITH YOUR BINARY CODE
mySwitch.send(“001011101001111100001010”);
}
else if(header.indexOf(“GET /output1off HTTP/1.1”) >= 0){
Serial.println(“Output 1 Off”);
output1State = “Off”;
// Sends binary code to turn off Desk Light
// BINARY CODE EXAMPLE. REPLACE WITH YOUR BINARY CODE
mySwitch.send(“001011101001111100000010”);
}
else if(header.indexOf(“GET /output2on HTTP/1.1”) >= 0){
Serial.println(“Output 2 On”);
output2State = “On”;
// Sends binary code to turn on Workbench Light
// BINARY CODE EXAMPLE. REPLACE WITH YOUR BINARY CODE
mySwitch.send(“001011101001111100001010”);
}
else if(header.indexOf(“GET /output2off HTTP/1.1”) >= 0){
Serial.println(“Output 2 Off”);
output2State = “Off”;
// Sends binary code to turn off Workbench Light
// BINARY CODE EXAMPLE. REPLACE WITH YOUR BINARY CODE
mySwitch.send(“001011101001111100000010”);
}
else if(header.indexOf(“GET /armSmoke HTTP/1.1”) >= 0){
Serial.println(“Smoke sensor is: Armed”);
digitalWrite(smokeLED, HIGH);
armSmoke = true;
smokeTriggered = false;
}
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;
motionTriggered = false;
}
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 that
client.println(“<!DOCTYPE HTML>”);
client.println(“<html>”);
client.println(“<head>”);
client.println(“<meta name=\”viewport\” content=\”width=device-width, initial-scale=1\”>”);
// Loads
client.println(“<link rel=\”stylesheet\” href=\”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css\”>”);
client.println(“<script src=\”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js\”></script>”);
client.println(“</head><div class=\”container\”>”);
client.println(“<h1>Smalls Bad Ass ESP8266 Web Server – <a href=\”/\”>Refresh</a></h1>”);
// Generates buttons to control the outputs
client.println(“<h2>Output 1 – State: ” + output1State + “</h2><div class=\”row\”>”);
// If LED is off, it shows the button to turn the output on
if(output1State == “Off”){
client.println(“<div class=\”col-md-2\”><a href=\”/output1on\” class=\”btn btn-block btn-lg btn-success\” role=\”button\”>ON</a></div></div>”);
}
// If LED is on, it shows the button to turn the output off
else if(output1State == “On”){
client.println(“<div class=\”col-md-2\”><a href=\”/output1off\” class=\”btn btn-block btn-lg btn-danger\” role=\”button\”>OFF</a></div></div>”);
}
client.println(“<h2>Output 2 – State: ” + output2State + “</h2><div class=\”row\”>”);
if(output2State == “Off”){
client.println(“<div class=\”col-md-2\”><a href=\”/output2on\” class=\”btn btn-block btn-lg btn-success\” role=\”button\”>ON</a></div></div>”);
}
else if(output2State == “On”){
client.println(“<div class=\”col-md-2\”><a href=\”/output2off\” class=\”btn btn-block btn-lg btn-danger\” role=\”button\”>OFF</a></div></div>”);
}
// 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(“<h2>Smoke Sensor – State: Smoke detected</h2><div class=\”row\”>”);
}
else {
client.println(“<h2>Smoke Sensor – State: No smoke</h2><div class=\”row\”>”);
}
// If the smoke sensor is armed, it shows the button to disarm the sensor
if(armSmoke){
client.println(“<div class=\”col-md-2\”><a href=\”/disarmSmoke\” class=\”btn btn-block btn-lg btn-default\” role=\”button\”>Disarm</a></div></div>”);
}
// If the smoke sensor is disarmed, it shows the button to arm the sensor
else {
client.println(“<div class=\”col-md-2\”><a href=\”/armSmoke\” class=\”btn btn-block btn-lg btn-primary\” role=\”button\”>Arm</a></div></div>”);
}
// 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(“<h2>Motion Sensor – State: Motion detected</h2><div class=\”row\”>”);
}
else {
client.println(“<h2>Motion Sensor – State: No motion</h2><div class=\”row\”>”);
}
// If the motion sensor is armed, it shows the button to disarm the sensor
if(armMotion){
client.println(“<div class=\”col-md-2\”><a href=\”/disarmMotion\” class=\”btn btn-block btn-lg btn-default\” role=\”button\”>Disarm</a></div></div>”);
}
// If the motion sensor is disarmed, it shows the button to arm the sensor
else {
client.println(“<div class=\”col-md-2\”><a href=\”/armMotion\” class=\”btn btn-block btn-lg btn-primary\” role=\”button\”>Arm</a></div></div>”);
}
// Prints the latest temperatuer and humidity readings
client.println(“<div class=\”row\”><h3>Temperature: “);
client.println(celsiusTemp);
client.println(“*C</h3><h3>Temperature: “);
client.println(fahrenheitTemp);
client.println(“*F</h3><h3>Humidity: “);
client.println(humidityTemp);
client.println(“%</h3></div>”);
client.println(“</div></div></html>”);
}
// wrong user or password, so 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(“<html>Authentication failed</html>”);
}
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.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 and when motion is detected enables a notification for the dashboard
void detectsMovement() {
Serial.println(“MOTION!”);
if (armMotion && !motionTriggered) {
Serial.println(“MOTION DETECTED!”);
motionTriggered = true;
}
}
Kind regards,
Sandy
OMG!!!!!! You are great!!!!! It worked 🙂
I wish I could buy you a cup of coffee or take you to Happy Hour with me because I am HAPPY!!!!! Thank you so much Sara!
Kindest regards,
Sandy