Neeraj Rane
Published © CC BY-NC-SA

IoT Notifier using ESP-12E

Stuck at home away from your loved one? This fun little project will definitely try to bring a smile to your faces.

IntermediateFull instructions provided540
IoT Notifier using ESP-12E

Things used in this project

Story

Read more

Custom parts and enclosures

Main+Body.stl

Stand.stl

Schematics

Schematic

Code

Code

Arduino
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>             //Install the library using Library Manager
#include "FastLED.h"                 //Install the library using Library Manager
            
const char* ssid = "SSID";          //Enter your WiFi SSID
const char* password = "Password";  //Enter your WiFi
const char* key = "Noti";
String thing = "indoorgeek";        //Enter your unique Dweet thing name
#define NUM_LEDS 27                      
#define PIN 1 
#define COLOR_ORDER RGB             //Change this to GRB if the colour displayed is wrong

String ans;
int button = 2;
int httpCode = 0;
int i = 0;
int fadeAmount = 5;  
int brightness = 0;

HTTPClient http;  
CRGB leds[NUM_LEDS];

void setup () {
  FastLED.addLeds<WS2812B, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  pinMode(button, INPUT_PULLUP);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.print("Connecting..");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }
  http.setTimeout(20000);
  setKeyToFalse();
  turnOffLeds();
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) { 
    
    http.begin("http://dweet.io/get/latest/dweet/for/" + thing);  
    httpCode = http.GET();                                                                 
    Serial.println(httpCode);
    if (httpCode > 0){
       
      String response = http.getString();   
      int start = 10 + response.indexOf("\"content\"");
      int sstop = response.indexOf("}]}");
      response = response.substring(start,sstop);
       Serial.println(response);
      StaticJsonBuffer<200> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(response);
      if (!root.success()){
        Serial.println("parseObject() failed");
        ans = "parse error.";
       } 
       else{
        const char* val  = root[key];
        ans = String(val);
        Serial.println(ans);
        }      
    http.end();   
  }        
  }
  if(ans == "button"){
    setKeyToFalse();
    buttonPress();
  }
  if(ans == "batt"){
    setKeyToFalse();
    batt();
  }
  if(ans == "tweet"){
    setKeyToFalse();
    twitter();
  }
  delay(10000);    //Send a request every 10 seconds
}

void buttonPress(){
  while(digitalRead(button) != LOW){ 
  for(int i = 0; i < NUM_LEDS; i++ ){
   leds[i] = CRGB(0,255,0);  // Set Color HERE!!!
   leds[i].fadeLightBy(brightness);
  }
  FastLED.show();
  brightness = brightness + fadeAmount;
  if(brightness == 0 || brightness == 255)
  {
    fadeAmount = -fadeAmount ; 
  }    
  delay(18);  
}
turnOffLeds();
}

void batt(){
  while(digitalRead(button) != LOW){
    for(i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB::Red;
      FastLED.show();
      delay(1);
    }
    delay(500);
    for(i = 21; i < NUM_LEDS; i++){
      leds[i] = CRGB::Black;
      FastLED.show();
      delay(1);
    }
    delay(500);
    for(i = 11; i < NUM_LEDS; i++){
      leds[i] = CRGB::Black;
      FastLED.show();
      delay(1);
    }
    delay(500);
    for(i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB::Black;
      FastLED.show();
      delay(1);
    }
    delay(500);
  }
  turnOffLeds();
}

void twitter(){
  while(digitalRead(button) != LOW){
  i = random(0,28);
  leds[i] = CRGB::Blue;
  FastLED.show();
  delay(10);
  fadeall();
  i = random(0,28);
  leds[i] = CRGB::White;
  FastLED.show();
  delay(10);
  fadeall();
}
turnOffLeds();
}

void setKeyToFalse(){
  http.begin("http://dweet.io/dweet/for/" + thing + "?" + String(key)+ "=False");
  http.addHeader("Content-Type","text/plain");
  httpCode = http.GET();
  Serial.println(httpCode);
  Serial.println("Value has been set to False");
  http.end();
}

void turnOffLeds(){
  for(int i = 0; i < NUM_LEDS; i++){
  leds[i] = CRGB::Black;
  FastLED.show();
  delay(1);
  }
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

ArduinoJson

FastLED

https://github.com/FastLED/FastLED

Credits

Neeraj Rane

Neeraj Rane

18 projects • 46 followers
Electrical Engineer and a Maker from India. Engineering is fun once you start applying it!

Comments