Esp32 external eeprom

`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;
}

... so what's the question?

How to upload eeprom data to cloud server(ubidots) when wifi is reconnected?

So the rest of your program works? ... how do you know that? Some Serial.print statements would help.

Forget about the EEPROM... have you EVER successfully uploaded ANYTHING to the cloud?

It works.

Either provide more information or stop wasting people's time.

WHAT works? WHAT doesn't work? We are not able to read your mind.

Recording of the data happens in eeprom . I am able to see that in a serial Monitor.

void eeprom_new()
{
  Serial.println("Displaying Temperature fot T1 & T2 sensor....");
  Serial.print("\t");
  Serial.print("Room Temperature");
  Serial.print("\t");
  Serial.println("Coil Temperature");
  for (int deviceaddress = 1; deviceaddress <= maxaddress; deviceaddress++)
  {
    sensors.requestTemperatures();

    Room_Temperature = sensors.getTempC(sensor1);
    Coil_Temperature = sensors.getTempC(sensor2);
    writeEEPROM(deviceaddress, Room_Temperature, Coil_Temperature, eeprom);
    Serial.print("ADDR= ");
    Serial.print(deviceaddress);
    Serial.print("\t");
    Serial.print(Room_Temperature);
    Serial.print("C°");
    Serial.print("           \t");;
    Serial.print(Coil_Temperature);
    Serial.println("C°");
  }

  Serial.println("EEPROM Writing Finished:");
  delay(5000);

  Serial.println("EEPROM Retreiving the data:");

  for (int deviceaddress = 1; deviceaddress < maxaddress; deviceaddress++)
  {
    readval = readEEPROM(deviceaddress, eeprom);
    Serial.print("ADDR= ");
    Serial.print(deviceaddress);
    Serial.print("\t");
    //Serial.println(readval);
    Serial.print(Room_Temperature);
    Serial.print("C°");
    Serial.print("           \t");;
    Serial.print(Coil_Temperature);
    Serial.println("C°");
  }
}

WIFI CODE

void ConnectWiFi()
{
  while (WiFi.status() != WL_CONNECTED)
  {
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    Serial.print(".");
    //eeprom_new();
    delay(5000);
  }

  if (WiFi.status() == WL_CONNECTED )
  {
    Serial.println("Wifi Connected");
    Serial.println(WiFi.localIP());
    WiFi.mode(WIFI_STA);
  }
  for (;;)
  {
    if (WiFi.status() != WL_CONNECTED )
    {
      Serial.println("attempting to reconnect");
      Serial.print(".");
      WiFi.disconnect();
      WiFi.reconnect();
      delay(5000);
     
    }
    else
    {
      Serial.println("Wifi is connected");
    }
    
    //Serial.println("Wifi is connected");
    //continue;
  }
  
}

WTF! ... where did this code come from? Never mentioned in your first post???

POST. ALL. YOUR. CODE.

@red_car EEPROM DATA storing Works but it's not getting uploaded to cloud server(ubidots).

ALL.

ALL.

ALL.

sorry man . I had written all the code in seperate files using function

#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 1(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

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;
}

void eeprom_new()
{
  Serial.println("Displaying Temperature fot T1 & T2 sensor....");
  Serial.print("\t");
  Serial.print("Room Temperature");
  Serial.print("\t");
  Serial.println("Coil Temperature");
  for (int deviceaddress = 1; deviceaddress <= maxaddress; deviceaddress++)
  {
    sensors.requestTemperatures();

    Room_Temperature = sensors.getTempC(sensor1);
    Coil_Temperature = sensors.getTempC(sensor2);
    writeEEPROM(deviceaddress, Room_Temperature, Coil_Temperature, eeprom);
    Serial.print("ADDR= ");
    Serial.print(deviceaddress);
    Serial.print("\t");
    Serial.print(Room_Temperature);
    Serial.print("C°");
    Serial.print("           \t");;
    Serial.print(Coil_Temperature);
    Serial.println("C°");
  }

  Serial.println("EEPROM Writing Finished:");
  delay(5000);

  Serial.println("EEPROM Retreiving the data:");

  for (int deviceaddress = 1; deviceaddress < maxaddress; deviceaddress++)
  {
    readval = readEEPROM(deviceaddress, eeprom);
    Serial.print("ADDR= ");
    Serial.print(deviceaddress);
    Serial.print("\t");
    //Serial.println(readval);
    Serial.print(Room_Temperature);
    Serial.print("C°");
    Serial.print("           \t");;
    Serial.print(Coil_Temperature);
    Serial.println("C°");
  }
}


void ConnectWiFi()
{
  while (WiFi.status() != WL_CONNECTED)
  {
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    Serial.print(".");
    //eeprom_new();
    delay(5000);
  }

  if (WiFi.status() == WL_CONNECTED )
  {
    Serial.println("Wifi Connected");
    Serial.println(WiFi.localIP());
    WiFi.mode(WIFI_STA);
  }
  for (;;)
  {
    if (WiFi.status() != WL_CONNECTED )
    {
      Serial.println("attempting to reconnect");
      Serial.print(".");
      WiFi.disconnect();
      WiFi.reconnect();
      delay(5000);
     
    }
    else
    {
      Serial.println("Wifi is connected");
    }
    
    //Serial.println("Wifi is connected");
    //continue;
  }
  
}

You never call this code?

I commented it out recently . But it is a part of the code.

so during the regular looping process one could check for a WiFi connection. If no then set a bit. If bit is set do an action. When bit becomes unset do the other action.

bool wifiisconnected = false
bool iamdoingthewifnotconnectedthings = false;
voiding loopy()
{

if wifi connected wifiisconnected = true

if wifiisconnected then do iamdoingthewifnotconnectedthings and other things things 
else
do these things, set the iamdoingthewifnotconnectedthings=true



}

You also say that it is storing the data to the EEPROM but you say that you don't see the serial output and nothing is getting uploaded. So, how do you know the data is being stored to the EEPROM?

EEPROM Data i am able to see that on the Serial monitor . But how to upload those data to ubidots cloud is my question.

Regular loop i.e void loop right?