ESP8266/NodeMCU Deep Sleep

dsleep() function accepts microseconds as its parameter (1,000,000 microseconds = 1 second), and the multiplication performed inline here is just to make it clearer that we’re sleeping for 15 minutes total. With the current 1.5.1 SDK, the maximum value accepted is 4,294,967,295, which is about 71 minutes. Earlier SDK versions had a lower limit, closer to 35 minutes. One common way to extend this is to maintain a counter in NVM (i.e., Flash or RTC Memory), and increment the counter each time that the device wakes up. If it reaches a certain threshold, then do the work, otherwise go back to sleep.

node.dsleep(15 * 60 * 1000000)

In this case, you don’t need to connect GPIO16 to the RESET pin, and you don’t need to specify an alarm value when calling dsleep(). Or, rather, use a value of zero to specify that the ESP should sleep forever (until reset, that is):

This permits very long idle periods (hours, days, or weeks possible) so long as you have a reliable method of waking the device up by triggering the RESET pin.


Deep Sleep for the ESP8266 ESP-01

Because the ESP-01 does not have the necessary pin exposed for Deep Sleep (GPIO 16) we will need to do some surgical soldering on it.
We need to solder a very thin piece of wire from the reset pin to one of those very small pads on the esp chip.

Don’t worry, it’s a lot easier than it looks.

Get the piece of wire, solder it on the reset pin, tin the other end and bend it into position
What I did next is applying head somewhere near the end of the wire, this melted the solder on the wire and on the pad and I got a connection. Easy peasy.

You will also need to remove at least the red LED to lower consumption.

I have also added some hot glue on top of the wire, it’s quite easy to pull it away together with the esp’s pad otherwise.

ในขั้นตอน จะมีฟังก์ชั่นการทำงานดังนี้

– try to connect to wifi, if fail start in config mode
– read dht22 data
– post dht22 data to cloud

– go to sleep
– awake and repeat




วัดอุณหภูมิ ความชื้น ขึ้น LINE NOTIFY

void Line_Notify(String message);

#include <ESP8266WiFi.h>
#include <DHT.h>

#define DHTPIN D2

// Existing WiFi network
const char* ssid = “xxxxx”; // your wifi name
const char* password = “xxxxx”; // your wifi password

#define LINE_TOKEN “xxxxxxxxxxxxxxx” // LINE Notify token

#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)


void setup() {
Serial.println(“Weather station by kittipongint!”);


// Connect to your WiFi network
WiFi.begin(ssid, password);

// Wait for successful connection
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“Connected to: “);
Serial.print(“IP address: “);
void read_sensor() {

// 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!”);

// 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);

Serial.print(“Humidity: “);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(” *C “);
Serial.print(” *F\t”);
Serial.print(“Heat index: “);
Serial.print(” *C “);
Serial.println(” *F”);

String message = “%E0%B8%AD%E0%B8%B8%E0%B8%93%E0%B8%AB%E0%B8%A0%E0%B8%B9%E0%B8%A1%E0%B8%B4%20”;
// Send notificatin with LINE Notify
Line_Notify(message + t + “%C2%B0C”);

void loop() {
void Line_Notify(String message) {
WiFiClientSecure client;

if (!client.connect(“”, 443)) {
Serial.println(“connection failed”);

String req = “”;
req += “POST /api/notify HTTP/1.1\r\n”;
req += “Host:\r\n”;
req += “Authorization: Bearer ” + String(LINE_TOKEN) + “\r\n”;
req += “Cache-Control: no-cache\r\n”;
req += “User-Agent: ESP8266\r\n”;
req += “Content-Type: application/x-www-form-urlencoded\r\n”;
req += “Content-Length: ” + String(String(“message=” + message).length()) + “\r\n”;
req += “\r\n”;
req += “message=” + message;



// Serial.println(“—–“);
while(client.connected()) {
String line = client.readStringUntil(‘\n’);
if (line == “\r”) {
// Serial.println(“—–“);



MMC Error CSLID: FX:{18ea3f92-d6aa-41d9-a205-2023400c8fbb}

เป็นใน windows 2008 ขึ้นว่า MMC could not create the snap-in CSLID: FX:{18ea3f92-d6aa-41d9-a205-2023400c8fbb}


This problem occurs if the .Net Framework 3.0 feature is not enabled and an update for .net framework 3.5SP1 is installed (which could be through the windows update or through a deployment tool).

The command removes the entries added in the machine.config during Framework updates.


To fix the problem, run the following command:

c:\Windows\Microsoft.NET\Framework\v3.5\WFServicesReg.exe /r /b

After running the command enable the feature .net framework 3.0 under Add features in Server Manager.

Open Server Manager
Select Features
Click on Add features
Select the check box for .Net Framework 3.0
Click Next and follow the steps to complete the Add Features Wizard

If these steps do not alleviate the issue, carry out the following steps to replace the Machine.config file with a known good version:

1. Navigate to C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG

2. Rename Machine.config to Machine.config.old

3. Copy Machine.config from a known good server.