`ESP 32 is connected with external EEPROM. Objective is to store the temperature values in eeprom irrespective of esp32 connection to wifi or not. When WIFI is connected to esp32 recording of the data should take place in eeprom. Once wifi is disconnected then also it should record the data. When reconnection happens then the stored value in eeprom must be uploaded to cloud server.
Preformatted text
`#include<WiFi.h>
#include "UbidotsEsp32Mqtt.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include<Wire.h>
#define eeprom 0x50
#define ONE_WIRE_BUS 13
OneWire oneWire(ONE_WIRE_BUS); //Access 1-wire temperature sensors, memory and other chips.
DallasTemperature sensors(&oneWire);
//int temp_user_set = 23;
float Room_Temperature, Coil_Temperature;
uint8_t sensor1[8] = {0x28, 0x20, 0x77, 0x07, 0xD6, 0x01, 0x3C, 0x03};
uint8_t sensor2[8] = {0x28, 0x88, 0x55, 0x79, 0xA2, 0x01, 0x03, 0xB6};
const int maxaddress = 10;
const char *WIFI_SSID = " "; // Put here your Wi-Fi SSID
const char *WIFI_PASS = ""; // Put here your Wi-Fi password
const char *UBIDOTS_TOKEN = "";
const char *DEVICE_LABEL = "";
const char *SUBSCRIBE_VARIABLE_LABEL_1 = "temp_coil";
const char *SUBSCRIBE_VARIABLE_LABEL_2 = "temp_room";
//unsigned long previousMillis = 0;
//unsigned long interval = 30000;
float readval = 0.0;
Ubidots ubidots(UBIDOTS_TOKEN);
void setup()
{
Serial.begin(115200);
Wire.begin();
sensors.begin();
//ConnectWiFi();
ubidots.connectToWifi(WIFI_SSID, WIFI_PASS);
//ubidots.setCallback(callback);
ubidots.setup();
ubidots.disconnect();
ubidots.reconnect();
ubidots.subscribeLastValue(DEVICE_LABEL, SUBSCRIBE_VARIABLE_LABEL_1);
ubidots.subscribeLastValue(DEVICE_LABEL, SUBSCRIBE_VARIABLE_LABEL_2);
}
void loop()
{
//unsigned long currentMillis = millis();
if (!ubidots.connected())
{
ubidots.disconnect();
ubidots.reconnect();
ubidots.subscribeLastValue(DEVICE_LABEL, SUBSCRIBE_VARIABLE_LABEL_1); // Insert the device and variable's Labels, respectively
ubidots.subscribeLastValue(DEVICE_LABEL, SUBSCRIBE_VARIABLE_LABEL_2);
}
ubidots.loop();
ubidots.add("temp_coil", Coil_Temperature);
ubidots.publish(DEVICE_LABEL);
ubidots.add("temp_room", Room_Temperature);
ubidots.publish(DEVICE_LABEL);
delay(1000);
}
EEPROM READ AND WRITE
type or paste code here
void writeEEPROM(int deviceaddress, byte Room_Temperature, byte Coil_Temperature, int eeaddress)
{
Wire.beginTransmission(eeaddress);
Wire.write((int)(deviceaddress >> 8)); //writes the MSB
Wire.write((int)(deviceaddress & 0xFF)); //writes the LSB
Wire.write(Room_Temperature);
Wire.write(Coil_Temperature);
Wire.endTransmission();
delay(5);
}
byte readEEPROM(int deviceaddress, int eeaddress)
{
byte rdata = 0xFF;
Wire.beginTransmission(eeaddress);
Wire.write((int)(deviceaddress >> 8)); //writes the MSB
Wire.write((int)(deviceaddress & 0xFF)); //writes the LSB
Wire.endTransmission();
Wire.requestFrom(eeaddress, 1);
rdata = Wire.read();
return rdata;
}