I have following code. I need to do following :
Read the Temperature and Humidity, Save to EEPROM, Go to deep sleep, Wake after 10 sec. (all of this without Wifi enabled)
When the EEPROM is full i want to turn the Wifi on/connect and send the data from EEPROM. My question is if somebody could help with the EEPROM write/read code that i need ?
// Import required libraries
#include "ESP8266WiFi.h"
#include "DHT.h"
#include <EEPROM.h>
// the current address in the EEPROM (i.e. which byte
// we're going to write to next)
int addr = 0;
// WiFi parameters
const char* ssid = "xxxx";
const char* password = "xxxx";
// Pin
#define DHTPIN 2
// Use DHT11 sensor
#define DHTTYPE DHT11
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE, 15);
// Host
const char* host = "dweet.io";
void setup() {
EEPROM.begin(512);
// Start Serial
Serial.begin(115200);
delay(10);
// Init DHT
dht.begin();
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
Serial.print("Connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// Reading temperature and humidity
int h = dht.readHumidity();
// Read temperature as Celsius
int t = dht.readTemperature();
// This will send the request to the server
client.print(String("GET /dweet/for/XXXXXX?temperature=") + String(t) + "&humidity=" + String(h) + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(30);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
// Repeat every 10 seconds
EEPROM.write(addr, t);
ESP.deepSleep(10000000, WAKE_RF_DEFAULT);
}