I use DS18B20 sensor for recording the temperature and LD33CV voltage regulator for stable input Voltage.
My first problem is that ESP reads and sends about 3072 (3,072 Volts) and 22,56 Celsius to the DB, but the multimeter shows 3,300 Volts and the real temperature is 20,50 Celsius in the room.
The second problem is that I set 10 minutes for deep sleep mode, but the ESP woke up after about 9min 30 second.
It seems that there is relation between these two things (incorrect timer, and the wrong C/V values).
I uploaded the latest firmware (ESP8266_NONOS_SDK_2_0) but the problem has not been solved.
Do you have any idea?
// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Replace with your network details
const char* ssid = "xxxxx";
const char* password = "yyyyy";
float min = 10;
int vcc;
float tempC;
// Enable ADC MODE for VCC scanning
ADC_MODE(ADC_VCC);
// Data wire is plugged into pin D1, GPIO 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature DS18B20(&oneWire);
char temperatureCString[6];
char temperatureFString[6];
const char* host = "xyxyxyxy.com";
// only runs once on boot
void setup() {
// Initializing serial port for debugging purposes
Serial.begin(115200);
delay(10);
// Display MAC Address
String MAC_ADDR = WiFi.macAddress();
// IC Default 9 bit.
DS18B20.begin();
// Connecting to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Get actual VCC
vcc = ESP.getVcc();
delay(20);
// last two bytes of the MAC (HEX'd) for the DB:
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.softAPmacAddress(mac);
String macIDend = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
// Get temperature
do {
DS18B20.requestTemperatures();
tempC = DS18B20.getTempCByIndex(0);
dtostrf(tempC, 2, 2, temperatureCString);
delay(100);
} while (tempC == 85.0 || tempC == (-127.0));
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// This will send the request to the server
client.print(String("GET /insert_temp_logs.php?temp_id=" + macIDend +"&temp_val=" + temperatureCString +"&temp_vcc=" + vcc + "") + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.print("Going to sleep.");
//sleep and try again
ESP.deepSleep(min * 60000000); //val * 1 min
}
void loop(void)
{
}