Deep sleep problem

9 years 5 months ago - 9 years 5 months ago #1921 by VasilijHCN
Hi, i trying to make deep sleep working on esp-01, i soldered required wire from rst to gpio16.
Blue led flashing all time, module not sending any data...
After removing wire from gpio16, blue led working normal.
Soldering 150R resistor from Vcc to rst solves blue led flashing, esp still not sleeping...
This
system_deep_sleep_set_option(4);
system_deep_sleep(30000000);
does sleep, sleep forever...
/*
  Created by Igor Jarc
 See http://iot-playground.com for details
 Please use community fourum on website do not contact author directly
 
 Code based on https://github.com/DennisSc/easyIoT-ESPduino/blob/master/sketches/ds18b20.ino
 
 External libraries:
 - https://github.com/adamvr/arduino-base64
 - https://github.com/milesburton/Arduino-Temperature-Control-Library
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
 extern "C" {
#include "user_interface.h" //for sleep
}
#include <ESP8266WiFi.h>
#include <Base64.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//AP definitions
#define AP_SSID "ssid"
#define AP_PASSWORD "password"

// EasyIoT server definitions
#define EIOT_USERNAME    "admin"
#define EIOT_PASSWORD    "password"
#define EIOT_IP_ADDRESS  "192.168.1.105"
#define EIOT_PORT        80
#define EIOT_NODE        "N9S0"

#define REPORT_INTERVAL 60 // in sec


#define ONE_WIRE_BUS 2  // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);


#define USER_PWD_LEN 40
char unameenc[USER_PWD_LEN];
float oldTemp;


void setup() {
  Serial.begin(115200);
  
  wifiConnect();
    
  char uname[USER_PWD_LEN];
  String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);  
  str.toCharArray(uname, USER_PWD_LEN); 
  memset(unameenc,0,sizeof(unameenc));
  base64_encode(unameenc, uname, strlen(uname));
  oldTemp = -1;
}

void loop() {
  float temp;
  
  do {
    DS18B20.requestTemperatures(); 
    temp = DS18B20.getTempCByIndex(0);
    Serial.print("Temperature: ");
    Serial.println(temp);
  } while (temp == 85.0 || temp == (-127.0));
  
  if (temp != oldTemp)
  {
    sendTeperature(temp);
    oldTemp = temp;
  }
  
  int cnt = REPORT_INTERVAL;
  
  while(cnt--)
    delay(1000);
}

void wifiConnect()
{
    Serial.print("Connecting to AP");
    WiFi.begin(AP_SSID, AP_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected");  
}

void sendTeperature(float temp)
{  
   WiFiClient client;
   
   while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
    Serial.println("connection failed");
    wifiConnect(); 
  }
 
  String url = "";
  url += "/Api/EasyIoT/Control/Module/Virtual/"+ String(EIOT_NODE) + "/ControlLevel/"+String(temp); // generate EasIoT server node URL

  Serial.print("POST data to URL: ");
  Serial.println(url);
  
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" + 
               "Connection: close\r\n" + 
               "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");

  delay(100);
    while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  
  Serial.println();
  Serial.println("Connection closed");
   client.stop();
   delay(100);
   ESP.deepSleep(6000000, WAKE_RF_DEFAULT);
   delay(1000);
}

Please Log in or Create an account to join the conversation.

8 years 11 months ago #2753 by UncleChris
Replied by UncleChris on topic Deep sleep problem
Hi,
Try moving everything out of loop() into setup() and replace the while() loop with ESP.deepSleep(cnt, WAKE_RF_DEFAULT).

eg

void setup() {
Serial.begin(115200);

wifiConnect();

char uname[USER_PWD_LEN];
String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);
str.toCharArray(uname, USER_PWD_LEN);
memset(unameenc,0,sizeof(unameenc));
base64_encode(unameenc, uname, strlen(uname));
float temp;

do {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.println(temp);
} while (temp == 85.0 || temp == (-127.0));

sendTeperature(temp);
int cnt = REPORT_INTERVAL * 1000000;
ESP.deepSleep(cnt, WAKE_RF_DEFAULT);
}

void loop() {
}

All the rest of the program remains the same as the example.

The program will come out of reset, run setup() , connect to the WiFi, read & send the temperature and then go into deep sleep. It will never run loop() and when it comes out of deep sleep it will run setup() again.

Please Log in or Create an account to join the conversation.

8 years 9 months ago #3110 by michel
Hello or have you telcharger library eps8266WIFI THANK YOU
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Time to create page: 0.272 seconds

Forum latest

  • No posts to display.