Door and Temperature Status Logger Project

Introduction: Door and Temperature Status Logger Project

This Instructable will show you how to make a simple door and temperature status logger for under $10.00 using an ESP8266 NodeMCU, a DHT11 temperature and humidity sensor, a door/window reed switch, a 10K ohm resistor and some hookup wire.

The genesis of this project came from my desire to do more home automation with the Arduino board, Since I had been reading a lot about the Arduino compatible EPS8266 NodeMCU, I decided this board would be the perfect low cost board to do some experimenting with. After searching the Internet for home automation projects using the ESP8266 boards, I settled on combining a temperature and door status logger for my first attempt. Eventually this project will be combined with servos, moisture sensors and other electronics to automate a small green house my grandfather designed and built 50 years ago. The temperature sensor will be used to determine if the heating system should be engaged or disengaged as well as signal the servos to open and close the venting system when needed. The state of the venting system will be monitored by the use of the magnetic reed switches. Finally, the moisture sensors will be used to automate a watering system.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Disclaimer

Just a quick disclaimer to state that we take NO responsibility for anything that happens as a result of following this instructable. It's always best to follow the manufacturers instructions and safety sheets when building anything so please consult those documents for any of the parts and tools you use to build your own. We are simply just providing information on the steps we used to create ours. We are not professionals. As a matter of fact, 2 out of 3 of the individuals who participated in this build are children.

Step 2: Setup Free IFTTT Account

If you don't already have one, now is the time to setup a free IFTTT account by going to their home page.. IFTTT stands for If This Then That and is a free platform that allows you connect internet based services in new ways to enable you to leverage those services in new ways. For this project we are going to use IFTTT to allow a ESP8266 to log the status of a door via a reed switch and temperature and humidity via the DHT11 sensor in a Google Sheets document.

Step 3: Create an IFTTT Applet

While still in IFTTT, proceed to the “My Applets” section and create a new applet by clicking the “New Applet” button.

Step 4: Configure the "this" Portion of Your Applet.

Click on the “this” word that is in a blue color – as highlighted in the figure above.

Step 5: Add the WebHooks Service to Your Applet.

In the search bar, search for the “Webhooks” service and select the Webhooks icon.

Once you find the "Webhooks" service, click on it.

Step 6: Setup the Receive a Web Request Trigger.

Choose the “Receive a web request” trigger.

Step 7: Provide an Event Name

In the text box provide your new applet with an event name. I selected "Data Logger" but you can choose whatever you like.

Step 8: Configure the "that" Portion of Your Applet.

Click on the “that” word that is in a blue color – as highlighted in the figure above.

Step 9: Setup an Action Service

In the search box, search for the “Google Sheets” service, and click the Google Sheets icon.

Step 10: Connect to Google Sheets

If you haven't already done so, you will need t connect your IFTTT account to Google Sheets. Press the Connect button shown above and follow the on-screen instructions.

Step 11: Choose an Action

Click on "Add Row to Spreadsheet".

Step 12: Setup the Action

Provide a name in the "Spreadsheet name" text box. I choose to use "Data_Logger" for consistency. Leave the rest of the setting alone (you can experiment with those setting at some other time) and then press the "Create Action" button at the bottom of the screen.

Step 13: Review and Finalize Your Applet.

Once satisfied with your applet configuration press the "Finish" button.

Step 14: Retrieve Configuration Information Needed Later.

Click on "Webhooks" as highlighted above.

Step 15: Proceed to the Webhooks Documentation for the API Key

It may seem strange but click on the Documentation link in the upper right to proceed to the page with your unique API Key.

Step 16: Save the API Key

The first line of the Documentation screen displays your unique API Key. Copy and Save this key for use later.

It is also a good idea to test the applet here. Remember to change the {event} to Data_Logger or whatever you named your event and add some data to the 3 empty values then click the "Test It" button at the bottom of the page. You should see a green message saying “Event has been triggered”. If so, proceed to Google Docs and confirm that the data you entered in the test page showed up in the Google Sheets document.

Step 17: Gather the Components

Step 18: Assemble the Components

1) Connect one of the 3v3 pin on the ESP8266 to the vcc pin on the DHT11.

2) Connect one of the ground pins on the ESP8266 to the ground pin on the DHT11.

3) Connect pin D4 (a.k.a. pin 2 in the IDE) on the ESP8266 to the data pin on the DHT11.

4) Connect another 3v3 pin on the ESP8266 to the one side of the door/window reed switch.

5) Connect pin D5 (a.k.a. pin 14 in the IDE) on the ESP8266 to the other side of the door/window reed switch and also connect it to one side of the 10k ohm resistor.

6) Connect the other side of the 10k ohm resistor to another ground pin on the ESP8266.

For ESP8266 pin selections please refer to this helpful diagram or the very helpful video.

Step 19: Write the Arduino Code

Copy and paste the code below into your Arduino IDE.

<p>#include <ESP8266WiFi.h><br>#include <ESP8266HTTPClient.h>
#include "DHT.h"</p><p>#define DHTPIN 2     // what digital pin we're connected to
#define DOORPIN 14    // what digital pin the door switch is on. </p><p>#define DHTTYPE DHT11   // DHT 11</p><p>DHT dht(DHTPIN, DHTTYPE);</p><p>int count = 1;
   
const char* ssid =      "some_ssid";   // change this to use your ssid  
const char* password =  "some_password";  // change this to use your password  
int sleepTime = 100;  </p><p>// Maker Webhooks IFTTT
const char* server = "maker.ifttt.com";</p><p>// IFTTT URL resource
const char* resource = "/trigger/SOME_SERVICE_NAME/with/key/SOME_API_KEY";  //Make sure to use your service name and your api key.</p><p>String doorStatus = "Closed";
volatile bool stateChanged = false;</p><p>// If sleeping for hours then set interval by hr * 60 minutes * 60 seconds * 1000 milliseconds
const long interval = 1.0 * 60 * 60 * 1000;  // 1 hour
unsigned long previousMillis = 0 - (2 * interval); </p><p>void setup () {
  Serial.begin(115200);
  attachInterrupt(digitalPinToInterrupt(DOORPIN), eventTriggered, CHANGE);
  pinMode(DOORPIN, INPUT);  //Door Sensor 
  dht.begin();
  WiFi.begin(ssid, password);</p><p>  Serial.print("\nConnecting..");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.print("\n"); 
}</p><p>void eventTriggered(){
  stateChanged = true;
  Serial.println("Checking the door!");
  if (digitalRead(DOORPIN)==HIGH) // Check to see if door is open
  {
    Serial.println("Door is closed!");
    doorStatus = "Closed";
  } else {
    Serial.println("Door is open!");
    doorStatus = "Opened";
  }
}</p><p>void checkStatus(){
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status      
      // Reading temperature or humidity takes about 250 milliseconds!
      // 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!"); //Serial.print(".");  //Failed to read from DHT sensor!
        return;
      }    
  
      // Compute heat index in Fahrenheit (the default)
      float hif = dht.computeHeatIndex(f, h);
      // Compute heat index in Celsius (isFahreheit = false)
      float hic = dht.computeHeatIndex(t, h, false);</p><p>      Serial.print("\n");
      Serial.print("Temperature: ");
      Serial.print(f);
      Serial.print(" *F (");
      Serial.print(t);
      Serial.print(" *C)");
      Serial.print("\t");
      Serial.print("Heat index: ");
      Serial.print(hif);
      Serial.print(" *F (");
      Serial.print(hic);
      Serial.print(" *C)%");
      Serial.print("\t");
      Serial.print("Humidity: ");
      Serial.println(h);</p><p>      if (digitalRead(DOORPIN)==HIGH) // Check to see if door is open
      {
        Serial.println("Door is closed!");
        doorStatus = "Closed";
      } else {
        Serial.println("Door is open!");
        doorStatus = "Opened";
      }
    
      String jsonObject = String("{\"value1\":\"")  + f +"*F (" + t + "*C) / "+ hif +"*F (" + hic + "*C)" + "\",\"value2\":\"" + h
                      + "\",\"value3\":\"" + doorStatus + " \"}";
 
      HTTPClient http;
      String completeUrl = "https://maker.ifttt.com/trigger/bme280_readings/with/key/cZFasEvy5_3JlrUSVAxQK9";
      http.begin(completeUrl); //    http.begin(server);
      http.addHeader("Content-Type", "application/json");
      http.POST(jsonObject);
      http.writeToStream(&Serial);
      http.end();   //Close connection</p><p>      stateChanged = false;
      int sleepTimeInMinutes = interval / 1000 / 60;
      Serial.print("\n\nGo to sleep for ");      
      Serial.print(sleepTimeInMinutes);
      Serial.println(" minute(s) ...");
    }    
}</p><p>void loop() {
    unsigned long currentMillis = millis();
    delay(4000);
    //If we surpassed the elapsed time then force a check of the door and temp.
    if(currentMillis - previousMillis >= interval){
      stateChanged = true;
      previousMillis = currentMillis;  
      Serial.print(count++);
      Serial.println(") Checking because of elapsed time!");  
    }else if(stateChanged){
      Serial.print(count++);
      Serial.println(") Checking because of state change!");      
    }</p><p>    //If state changed then check the door and temp.
    if(stateChanged){        
      checkStatus();
    }</p><p>    delay(sleepTime);      
}</p>

Step 20: Results

Once you upload the source code in the previous step you should have results like the example shown above.

Step 21: Credits

I found a lot of helpful hints and tips from Random Nerd Tutorials and would like to thank them for all of their help. Especially their excellent tutorial on ESP32 ESP8266 Publish Sensor Readings to Google Sheets which major portions of this Instructable are based upon.

Additionally, the DHT11 Instructable from TheCircuit helped me understand how to use this very inexpensive but interesting little sensor.

Furthermore, there are many tutorials dealing with monitoring your doors like the Garage Door Monitor and another one from Random Nerd Tutorials. I used bits and pieces of these to help me understand how to get my reed switch working properly.

Finally, with this information as well as other details I found around the Internet I was able to create a system that met my needs. I hope you find this Instructable useful and build one of your own.

Be the First to Share

    Recommendations

    • Tiny Speed Challenge

      Tiny Speed Challenge
    • Clocks Contest

      Clocks Contest
    • PCB Design Challenge

      PCB Design Challenge

    16 Discussions

    0
    hestonmoyers92
    hestonmoyers92

    6 months ago

    So I want to do this but only want it to report when the door opens. I don't need any of the other sensors just when the door opens and shuts. Is this a possibility?

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 6 months ago

    Yes, just eliminate the temperature and humidity sensor from the hardware and eliminate the code that supports it.

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 6 months ago

    Yes, just eliminate the temperature/humidity sensor from the components and within the code.

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    10 months ago

    I'm not sure by just looking at it. I'll have to test it out myself. Unfortunately I do not have the hardware with me at this time. I will do my best to get access to the hardware this week. However, if you don't hear back from me by weeks end then please drop me a little reminder.

    0
    afirdaus96
    afirdaus96

    Reply 10 months ago

    hi sir, so how its going ? does the coding function ok, or there is some mistake on why the row in the google sheets not updated when the reed switch is triggered .

    hope to get the answer from you, if you do not have the access to the hardware yet, just take your time

    tq

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 10 months ago

    Unfortunately due to some family matters I was not able to look at it yet. Hopefully tonight or tomorrow night. Sorry

    0
    afirdaus96
    afirdaus96

    Reply 10 months ago

    tq sir, no problem

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 10 months ago

    I was able to find some time this evening to turn on the system. I didn't have any issues with it logging the reed switch. I also have an EPS32 that I might try the code on tomorrow if I have enough time but as far as the ESP8266, everything is still working as layout in the Instructable. I did modify the code once to send SMS messages when the door is open after a certain timeframe (9:00 PM EDT). Would you like to see that code too?

    0
    afirdaus96
    afirdaus96

    Reply 10 months ago

    Can i see the coding that you use for the reed swich, or are you using the one that i modified on the comment below ? because i still can't update the data inside the google sheet automatically but in the serial monitor is all good.. Yes i want to see the new code to send SMS that you modify, maybe i can get something from there.. if possible can i see the connection that you do to the nodemcu, reed switch, resistor i want to compare with mine..

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 10 months ago

    Here is my latest code. It has a few extras with the SMS Message and Email:

    /**
    * This Arduino Project will monitor a reed switch attached to any door/window to determine if the door/window is opened or closed.
    * It will also capture the temperature and humidity from a DHT11 sensor.
    * It logs the status of the door and the DHT11 sensor in Google Doc and after dark it sends SMS messages when the door/window is left open.
    * It also makes use of the TimeZone database to set the internal system clock to accurately measure time.
    *
    * Major components of this project were derived by observing various examples on the internet espically from Instructables.com
    */
    #include <ESP8266WiFi.h>
    #include <ESP8266HTTPClient.h>
    #include <ArduinoJson.h>
    #include <TimeLib.h>
    #include "DHT.h"
    #include "DataToMaker.h"
    #define DOORPIN 14 // what digital pin the door switch is on.
    #define DHTPIN 2 // what digital pin we're connected to
    #define DHTTYPE DHT11 // DHT 11
    DHT dht(DHTPIN, DHTTYPE); //Configure the DHT object
    float h; //humidity
    float f; //temp in fahrenheit
    float t; //temp in celsius
    float hif; //heat index in fahrenheit
    float hic; //heat index in celsius
    const char* ssid = "" ; // Your WiFi Access Point
    const char* password = "" ; // Your WiFi Password
    // IFTTT Maker Webhooks
    const char* myIftttKey = ""; // your maker key here
    DataToMaker eventLog(myIftttKey, "statusLogger"); // configure the status logger.
    DataToMaker eventSms(myIftttKey, "statusLoggerSms"); // configure the SMS messenger.
    DataToMaker eventEmail(myIftttKey, "statusLoggerEmail"); // Configure the Email messenger.
    // statuses
    String doorStatus = "Closed"; // door status
    String previousDoorStatus = "Opened"; // previous door status
    volatile bool statusChanged = false; // status change flag
    // Set interval by hr * 60 minutes * 60 seconds * 1000 milliseconds
    const long interval = 5 * 60 * 60 * 1000; // .25 * 60 * 60 * 1000; // 5 * 60 * 60 * 1000;
    const long eveningInterval = 0.5 * 60 * 60 * 1000; // 0.25 * 60 * 60 * 1000;
    unsigned long previousMillis = 0 - (2 * interval);
    int hourCheckStart = 21; //2100 in millitary time is 9:00
    int hourCheckEnd = 07; //0600 in millitary time is 9:00
    int sleepTime = 1000;
    int previousDay = -1;
    /**
    * Method used to configure the application.
    */
    void setup() {
    Serial.begin(115200);
    attachInterrupt(digitalPinToInterrupt(DOORPIN), eventTriggered, CHANGE);
    pinMode(DOORPIN, INPUT); //Door Sensor
    dht.begin();
    Serial.print("\nConnecting to ");
    Serial.println(ssid);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    Serial.print("\nConnecting..");
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
    }
    Serial.println("\nIP address: ");
    IPAddress ip = WiFi.localIP();
    Serial.println(ip);
    Serial.print("\n");
    }
    /**
    * Method that is triggered each time a door sensor state changes.
    */
    void eventTriggered() {
    statusChanged = true;
    Serial.println("Event was triggered!");
    // May not need to check the status here because the main loop forces the check too.
    // checkStatus();
    }
    /**
    * Method used to determine the status of a door.
    */
    void checkStatus() {
    previousDoorStatus = doorStatus;
    Serial.println("Checking the door!");
    if (digitalRead(DOORPIN) == HIGH) { // Check to see if door is open
    Serial.println("Door is closed!");
    doorStatus = "Closed";
    } else {
    Serial.println("Door is open!");
    doorStatus = "Opened";
    }
    }
    /**
    * Method used to capture the temp from the DHT11 sensor
    */
    bool checkTemperature() {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    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!"); //Serial.print("."); //Failed to read from DHT sensor!
    return false;
    }
    // Compute heat index in Fahrenheit (the default)
    hif = dht.computeHeatIndex(f, h);
    // Compute heat index in Celsius (isFahreheit = false)
    hic = dht.computeHeatIndex(t, h, false);
    return true;
    }
    /**
    * Method used to send the status to both SMS and Email.
    */
    void sendStatusToSmsAndEmail(){
    sendStatusToSms();
    sendStatusToEmail();
    }
    /**
    * Method used to send the status of the door via SMS.
    */
    void sendStatusToSms() {
    delay(100);
    eventSms.setValue(1, "Door is " + doorStatus);
    if (eventSms.connect()) {
    Serial.println("Connected To Maker Sms.");
    eventSms.post();
    Serial.println("Posted status to Maker Sms!");
    eventSms.post();
    } else {
    Serial.println("Failed To Connect To Maker Sms!");
    }
    }
    /**
    * Method used to send the status of the door via Email.
    */
    void sendStatusToEmail(){
    delay(100);
    eventEmail.setValue(1, "Door is " + doorStatus);
    if (eventEmail.connect()) {
    Serial.println("Connected To Maker Email.");
    eventEmail.post();
    Serial.println("Posted status to Maker Email!");
    eventEmail.post();
    } else {
    Serial.println("Failed To Connect To Maker Email!");
    }
    }
    /**
    * Method used to send the status of the door and temperature to Google Docs.
    */
    void sendStatusToLog(String oper) {
    delay(100);
    // Read the temperature and humidity
    while (!checkTemperature()) {
    delay(10);
    }
    Serial.print("\n");
    Serial.print("Temperature: ");
    Serial.print(f);
    Serial.print(" *F (");
    Serial.print(t);
    Serial.print(" *C)");
    Serial.print("\t");
    Serial.print("Heat index: ");
    Serial.print(hif);
    Serial.print(" *F (");
    Serial.print(hic);
    Serial.print(" *C)%");
    Serial.print("\t");
    Serial.print("Humidity: ");
    Serial.println(h);
    eventLog.setValue(1,
    String(f) + "*F (" + String(t) + "*C) / " + String(hif) + "*F ("
    + String(hic) + "*C)");
    eventLog.setValue(2, String(h));
    String statusString = doorStatus + " " + oper;
    Serial.println(statusString);
    eventLog.setValue(3, statusString);
    if (eventLog.connect()) {
    Serial.println("Connected To Maker Log");
    eventLog.post();
    Serial.println("Posted status to Maker Log!");
    } else {
    Serial.println("Failed To Connect To Maker Log!");
    }
    // sendStatusToEmail();
    }
    /**
    * Main loop
    */
    void loop() {
    delay(sleepTime); // Give the CPU a break.
    unsigned long currentMillis = millis();
    //If this is a new day then syncronize the internal clock with UTC.
    if (previousDay != day()) {
    syncToUtcWithLocalTimezone();
    previousDay = day();
    }
    //If we surpassed the elapsed time then force a check of the door and temp.
    if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    Serial.print("\nChecking statuses because of elapsed time of ");
    if(interval/1000/60 <= 60){
    Serial.print(interval/1000/60); //due to 1000 milliseconds in a second and 60 seconds in a minute.
    Serial.println(" minutes!");
    }else{
    Serial.print(interval/1000/60/60); //due to 1000 milliseconds in a second, 60 seconds in a minute, and 60 minutes in an hour.
    Serial.println(" hours!");
    }
    checkStatus();
    sendStatusToLog("TimeLapsed"); //Since we surpassed the elapsed time we will send the status to the log regardless.
    Serial.print("\nGoing to sleep for ");
    if(interval/1000/60 <= 60){
    Serial.print(interval/1000/60); //due to 1000 milliseconds in a second and 60 seconds in a minute.
    Serial.println(" minutes!");
    }else{
    Serial.print(interval/1000/60/60); //due to 1000 milliseconds in a second, 60 seconds in a minute, and 60 minutes in an hour.
    Serial.println(" hours!");
    }
    } else if ((hour() >= hourCheckStart || hour() <= hourCheckEnd) && currentMillis - previousMillis >= eveningInterval && doorStatus == "Opened") {
    //We want to check here if we are past 9:00 PM and the door is stil opened.
    previousMillis = currentMillis;
    Serial.print("\nChecking statuses because it's between ");
    Serial.print(hourCheckStart);
    Serial.print("00 hours & ");
    Serial.print(hourCheckEnd);
    Serial.print("00 hours and the door was open the last time we checked!\n");
    checkStatus();
    sendStatusToSmsAndEmail(); //Since it is after hours send a warning of the status via SMS.
    Serial.print("\nGoing to sleep for ");
    if(interval/1000/60 <= 60){
    Serial.print(interval/1000/60); //due to 1000 milliseconds in a second and 60 seconds in a minute.
    Serial.println(" minutes!");
    }else{
    Serial.print(interval/1000/60/60); //due to 1000 milliseconds in a second, 60 seconds in a minute, and 60 minutes in an hour.
    Serial.println(" hours!");
    }
    } else if (statusChanged) {
    Serial.println("\nChecking statuses because of state change!");
    checkStatus();
    sendStatusToLog("statusChanged"); //Since the state changed we will send the status to the log regardless.
    statusChanged = false;
    if ((hour() >= hourCheckStart || hour() <= hourCheckEnd) && previousDoorStatus != doorStatus) { // Need to check hour here too because of possible status change.
    //Since it is after hours send a warning of the status via SMS.
    sendStatusToSmsAndEmail();
    }
    Serial.print("\nGoing to sleep for ");
    if(interval/1000/60 <= 60){
    Serial.print(interval/1000/60); //due to 1000 milliseconds in a second and 60 seconds in a minute.
    Serial.println(" minutes!");
    }else{
    Serial.print(interval/1000/60/60); //due to 1000 milliseconds in a second, 60 seconds in a minute, and 60 minutes in an hour.
    Serial.println(" hours!");
    }
    }
    }
    /**
    * Method used to set the system time to the UTC time adjusted for the Eastern USA Timezone.
    */
    void syncToUtcWithLocalTimezone() {
    StaticJsonDocument < 700 > doc; // Object used to parse the json response from the Time Server.
    if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
    HTTPClient http; //Declare an object of class HTTPClient
    String baseUrl = "http://api.timezonedb.com/v2.1/get-time-zone?key=3LQ5H5VQINP6&format=json&by=zone&zone=America/New_York";
    Serial.print("Calling ");
    Serial.println(baseUrl);
    http.begin(baseUrl); //Specify request destination
    int httpCode = http.GET(); //Send the request
    Serial.print("HTTP Response Code: ");
    Serial.println(httpCode);
    if (httpCode > 0) { //Check the returning code
    String jsonResponse = http.getString(); //Get the request response payload
    Serial.print("Length: ");
    Serial.println(jsonResponse.length());
    Serial.println(jsonResponse); //Print the response payload
    // Deserialize the JSON document
    DeserializationError error = deserializeJson(doc, jsonResponse);
    // Test if parsing succeeds.
    if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.c_str());
    } else {
    // Get the root object in the document
    JsonObject root = doc.as<JsonObject>();
    Serial.print("TimeStamp:\t");
    const char* formattedTimeStamp = root["formatted"];
    Serial.println(formattedTimeStamp);
    int unixTime = root["timestamp"];
    Serial.print("Setting system time to: ");
    Serial.println(unixTime);
    setTime(unixTime);
    Serial.printf("\n\nLocal Time:\t %02d:%02d:%02d\t%02d-%02d-%4d", hour(), minute(), second(), month(), day(), year());
    Serial.print("\n");
    }
    }
    http.end(); //Close connection
    }
    }

    0
    afirdaus96
    afirdaus96

    Reply 10 months ago

    can i have your email, i want to show some video about my google sheet still not update automatically.. i still cant figure out why in the serial monitor the event has been triggered.. but in the IFTTT activity also no update..
    and also i do not use DHT sensor so i delete the coding, so that the notification is the only left in the code.. i dont have the sensor, i have the reed switch only
    const char* myIftttKey = ""; // your maker key here. For this line we take only the key right for example 3Dnbcun9ccnc....

    -Is the update on the spot or there is some time taken for the google sheet to update after the triggered event ?

    -there are some screen shot of my progress.. the activity is from the test it! not from the reed switch

    -the google sheet shows the event that i test to triggered

    dd.pngss.pngsssdf.pngUntitled.png
    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 10 months ago

    I sent you a private message. You should see it under your Instructables profile.

    0
    afirdaus96
    afirdaus96

    Reply 10 months ago

    alright i will for your solution.. tq

    0
    afirdaus96
    afirdaus96

    Question 10 months ago

    hi sir i want to ask some question,
    1)why every time i triggered the reed switch(try open and close), there is nothing update/changes in the google sheet i try to refresh but still nothing change (but in the serial monitor there is the status door open and door closed) ? i already test and try input value1, value2, value3 and there is output in google sheet, but for door status how you do it ? im a bit confuse
    2)for the row 1 in your picture, Date, Service... Door status how you do this? i am a bit slow for google sheet
    3)if the service is offline can it update itself in the google sheets ?

    that all, i hope i can get some solution from you
    tq

    0
    SpecialRobotBuilders
    SpecialRobotBuilders

    Reply 10 months ago

    Do you have the 10k ohm resistor connected to the reed switch? If not, that is probably your problem. Also, I bought several inexpensive reed switches and found that at least 1 of those was faulty. So, if you are confident that the reed switch is properly connected to the 3.3 volts, ground and the 10k ohm resistor then you may just have a faulty reed switch. As for off-line recording of the events, I actually have not tried off-line storage, so I can't provide you with any guidance on that subject.

    Good luck!

    0
    afirdaus96
    afirdaus96

    Reply 10 months ago

    #include <ESP8266WiFi.h>
    #include <ESP8266HTTPClient.h>
    #define DOORPIN 14 // what digital pin the door switch is on.
    int count = 1;
    const char* ssid = "testing"; // change this to use your ssid
    const char* password = "password"; // change this to use your password
    int sleepTime = 100; // Maker Webhooks IFTTT
    const char* server = "maker.ifttt.com"; // IFTTT URL resource
    const char* resource = "/trigger/Data_Logger/with/key/iD3laajozuEUI68x2w3vn"; //Make sure to use your service name and your api key.
    String doorStatus = "Closed";
    volatile bool stateChanged = false;// If sleeping for hours then set interval by hr * 60 minutes * 60 seconds * 1000 milliseconds
    const long interval = 1.0 * 60 * 60 * 1000; // 1 hour
    unsigned long previousMillis = 0 - (2 * interval);
    void setup ()
    {
    Serial.begin(115200);
    attachInterrupt(digitalPinToInterrupt(DOORPIN), eventTriggered, CHANGE);
    pinMode(DOORPIN, INPUT); //Door Sensor
    WiFi.begin(ssid, password);
    Serial.print("\nConnecting..");
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
    }
    Serial.print("\n");
    }
    void eventTriggered()
    {
    stateChanged = true;
    Serial.println("Checking the door!");
    if (digitalRead(DOORPIN)==HIGH) // Check to see if door is open
    {
    Serial.println("Door is closed!");
    doorStatus = "Closed";
    } else {
    Serial.println("Door is open!");
    doorStatus = "Opened";
    }
    }
    void checkStatus(){
    if (WiFi.status() == WL_CONNECTED)
    {
    if (digitalRead(DOORPIN)==HIGH) // Check to see if door is open
    {
    Serial.println("Door is closed!");
    doorStatus = "Closed";
    } else {
    Serial.println("Door is open!");
    doorStatus = "Opened";
    }
    String jsonObject ="value1\":\"" + doorStatus + " \"}";
    HTTPClient http;
    String completeUrl = "maker.ifttt.com/trigger/Data_Logger/with/key/iD3laajozuEUI68x2w3vn";
    http.begin(completeUrl); // http.begin(server);
    http.addHeader("Content-Type", "application/json");
    http.POST(jsonObject);
    http.writeToStream(&Serial);
    http.end(); //Close connection
    stateChanged = false;
    int sleepTimeInMinutes = interval / 1000 / 60;
    Serial.print("\n\nGo to sleep for ");
    Serial.print(sleepTimeInMinutes);
    Serial.println(" minute(s) ...");
    }
    }
    void loop()
    {
    unsigned long currentMillis = millis();
    delay(4000);
    //If we surpassed the elapsed time then force a check of the door and temp.
    if(currentMillis - previousMillis >= interval){
    stateChanged = true;
    previousMillis = currentMillis;
    Serial.print(count++);
    Serial.println(") Checking because of elapsed time!");
    }else if(stateChanged){
    Serial.print(count++);
    Serial.println(") Checking because of state change!");
    } //If state changed then check the door and temp.
    if(stateChanged){
    checkStatus();
    }
    delay(sleepTime);
    }
    ok sir this is my modified coding i just get rid off the DHT coding and i just want the reed switch only to function for the door status. In the serial monitor work just fine closed and open.. when test(triggered an event in the IFTTT) one row added to the google sheet.. but when i try to open and closed the reed switch (physically) there is no value(row) added in the google sheet.. it will only added a new row if i press test it! in the IFTTT to trigger an event, but if physically try the reed switch no new row added in the google sheet.. i already put the 10kohm and new reed switch but still nohing happen in the google sheet.. and i only put value1 only. is there anything wrong with my coding ?
    i really appreciate if you can help me..
    thank you in advance

    Untitled.pngIFTTT.png