ajustement valeur batterie + save des données en local

This commit is contained in:
noah cazeaudumec 2024-06-14 14:46:44 +02:00
parent 3215912edd
commit 0b04918e65
3 changed files with 88 additions and 24 deletions

View file

@ -37,7 +37,7 @@
#define BATTERY_MIN_ADC VOLTAGE_TO_ADC(VOLTAGE_OUT(VOLTAGE_MIN)) #define BATTERY_MIN_ADC VOLTAGE_TO_ADC(VOLTAGE_OUT(VOLTAGE_MIN))
// Solder apply on all riders behind the ESP32 for the battery voltage captor // Solder apply on all riders behind the ESP32 for the battery voltage captor
#define ADC_PIN 35 #define ADC_PIN 35
#define CONV_FACTOR 1.7 #define CONV_FACTOR 1.78
#define READS 20 #define READS 20
const long gmtOffset_sec = 3600; const long gmtOffset_sec = 3600;

View file

@ -68,28 +68,51 @@ double Pangodream_18650_CL::getConvFactor()
/** /**
* Loads each voltage value in its matching charge element (index) * Loads each voltage value in its matching charge element (index)
*/ */
// void Pangodream_18650_CL::_initVoltsArray(){
// _vs[0] = 3.200;
// _vs[1] = 3.250; _vs[2] = 3.300; _vs[3] = 3.350; _vs[4] = 3.400; _vs[5] = 3.450;
// _vs[6] = 3.500; _vs[7] = 3.550; _vs[8] = 3.600; _vs[9] = 3.650; _vs[10] = 3.700;
// _vs[11] = 3.703; _vs[12] = 3.706; _vs[13] = 3.710; _vs[14] = 3.713; _vs[15] = 3.716;
// _vs[16] = 3.719; _vs[17] = 3.723; _vs[18] = 3.726; _vs[19] = 3.729; _vs[20] = 3.732;
// _vs[21] = 3.735; _vs[22] = 3.739; _vs[23] = 3.742; _vs[24] = 3.745; _vs[25] = 3.748;
// _vs[26] = 3.752; _vs[27] = 3.755; _vs[28] = 3.758; _vs[29] = 3.761; _vs[30] = 3.765;
// _vs[31] = 3.768; _vs[32] = 3.771; _vs[33] = 3.774; _vs[34] = 3.777; _vs[35] = 3.781;
// _vs[36] = 3.784; _vs[37] = 3.787; _vs[38] = 3.790; _vs[39] = 3.794; _vs[40] = 3.797;
// _vs[41] = 3.800; _vs[42] = 3.805; _vs[43] = 3.811; _vs[44] = 3.816; _vs[45] = 3.821;
// _vs[46] = 3.826; _vs[47] = 3.832; _vs[48] = 3.837; _vs[49] = 3.842; _vs[50] = 3.847;
// _vs[51] = 3.853; _vs[52] = 3.858; _vs[53] = 3.863; _vs[54] = 3.868; _vs[55] = 3.874;
// _vs[56] = 3.879; _vs[57] = 3.884; _vs[58] = 3.889; _vs[59] = 3.895; _vs[60] = 3.900;
// _vs[61] = 3.906; _vs[62] = 3.911; _vs[63] = 3.917; _vs[64] = 3.922; _vs[65] = 3.928;
// _vs[66] = 3.933; _vs[67] = 3.939; _vs[68] = 3.944; _vs[69] = 3.950; _vs[70] = 3.956;
// _vs[71] = 3.961; _vs[72] = 3.967; _vs[73] = 3.972; _vs[74] = 3.978; _vs[75] = 3.983;
// _vs[76] = 3.989; _vs[77] = 3.994; _vs[78] = 4.000; _vs[79] = 4.008; _vs[80] = 4.015;
// _vs[81] = 4.023; _vs[82] = 4.031; _vs[83] = 4.038; _vs[84] = 4.046; _vs[85] = 4.054;
// _vs[86] = 4.062; _vs[87] = 4.069; _vs[88] = 4.077; _vs[89] = 4.085; _vs[90] = 4.092;
// _vs[91] = 4.100; _vs[92] = 4.111; _vs[93] = 4.122; _vs[94] = 4.133; _vs[95] = 4.144;
// _vs[96] = 4.156; _vs[97] = 4.167; _vs[98] = 4.178; _vs[99] = 4.189; _vs[100] = 4.200;
// }
void Pangodream_18650_CL::_initVoltsArray(){ void Pangodream_18650_CL::_initVoltsArray(){
_vs[0] = 3.200; _vs[0] = 3.300;
_vs[1] = 3.250; _vs[2] = 3.300; _vs[3] = 3.350; _vs[4] = 3.400; _vs[5] = 3.450; _vs[1] = 3.309; _vs[2] = 3.318; _vs[3] = 3.327; _vs[4] = 3.336; _vs[5] = 3.345;
_vs[6] = 3.500; _vs[7] = 3.550; _vs[8] = 3.600; _vs[9] = 3.650; _vs[10] = 3.700; _vs[6] = 3.354; _vs[7] = 3.363; _vs[8] = 3.372; _vs[9] = 3.381; _vs[10] = 3.390;
_vs[11] = 3.703; _vs[12] = 3.706; _vs[13] = 3.710; _vs[14] = 3.713; _vs[15] = 3.716; _vs[11] = 3.399; _vs[12] = 3.408; _vs[13] = 3.417; _vs[14] = 3.426; _vs[15] = 3.435;
_vs[16] = 3.719; _vs[17] = 3.723; _vs[18] = 3.726; _vs[19] = 3.729; _vs[20] = 3.732; _vs[16] = 3.444; _vs[17] = 3.453; _vs[18] = 3.462; _vs[19] = 3.471; _vs[20] = 3.480;
_vs[21] = 3.735; _vs[22] = 3.739; _vs[23] = 3.742; _vs[24] = 3.745; _vs[25] = 3.748; _vs[21] = 3.489; _vs[22] = 3.498; _vs[23] = 3.507; _vs[24] = 3.516; _vs[25] = 3.525;
_vs[26] = 3.752; _vs[27] = 3.755; _vs[28] = 3.758; _vs[29] = 3.761; _vs[30] = 3.765; _vs[26] = 3.534; _vs[27] = 3.543; _vs[28] = 3.552; _vs[29] = 3.561; _vs[30] = 3.570;
_vs[31] = 3.768; _vs[32] = 3.771; _vs[33] = 3.774; _vs[34] = 3.777; _vs[35] = 3.781; _vs[31] = 3.579; _vs[32] = 3.588; _vs[33] = 3.597; _vs[34] = 3.606; _vs[35] = 3.615;
_vs[36] = 3.784; _vs[37] = 3.787; _vs[38] = 3.790; _vs[39] = 3.794; _vs[40] = 3.797; _vs[36] = 3.624; _vs[37] = 3.633; _vs[38] = 3.642; _vs[39] = 3.651; _vs[40] = 3.660;
_vs[41] = 3.800; _vs[42] = 3.805; _vs[43] = 3.811; _vs[44] = 3.816; _vs[45] = 3.821; _vs[41] = 3.669; _vs[42] = 3.678; _vs[43] = 3.687; _vs[44] = 3.696; _vs[45] = 3.705;
_vs[46] = 3.826; _vs[47] = 3.832; _vs[48] = 3.837; _vs[49] = 3.842; _vs[50] = 3.847; _vs[46] = 3.714; _vs[47] = 3.723; _vs[48] = 3.732; _vs[49] = 3.741; _vs[50] = 3.750;
_vs[51] = 3.853; _vs[52] = 3.858; _vs[53] = 3.863; _vs[54] = 3.868; _vs[55] = 3.874; _vs[51] = 3.759; _vs[52] = 3.768; _vs[53] = 3.777; _vs[54] = 3.786; _vs[55] = 3.795;
_vs[56] = 3.879; _vs[57] = 3.884; _vs[58] = 3.889; _vs[59] = 3.895; _vs[60] = 3.900; _vs[56] = 3.804; _vs[57] = 3.813; _vs[58] = 3.822; _vs[59] = 3.831; _vs[60] = 3.840;
_vs[61] = 3.906; _vs[62] = 3.911; _vs[63] = 3.917; _vs[64] = 3.922; _vs[65] = 3.928; _vs[61] = 3.849; _vs[62] = 3.858; _vs[63] = 3.867; _vs[64] = 3.876; _vs[65] = 3.885;
_vs[66] = 3.933; _vs[67] = 3.939; _vs[68] = 3.944; _vs[69] = 3.950; _vs[70] = 3.956; _vs[66] = 3.894; _vs[67] = 3.903; _vs[68] = 3.912; _vs[69] = 3.921; _vs[70] = 3.930;
_vs[71] = 3.961; _vs[72] = 3.967; _vs[73] = 3.972; _vs[74] = 3.978; _vs[75] = 3.983; _vs[71] = 3.939; _vs[72] = 3.948; _vs[73] = 3.957; _vs[74] = 3.966; _vs[75] = 3.975;
_vs[76] = 3.989; _vs[77] = 3.994; _vs[78] = 4.000; _vs[79] = 4.008; _vs[80] = 4.015; _vs[76] = 3.984; _vs[77] = 3.993; _vs[78] = 4.002; _vs[79] = 4.011; _vs[80] = 4.020;
_vs[81] = 4.023; _vs[82] = 4.031; _vs[83] = 4.038; _vs[84] = 4.046; _vs[85] = 4.054; _vs[81] = 4.029; _vs[82] = 4.038; _vs[83] = 4.047; _vs[84] = 4.056; _vs[85] = 4.065;
_vs[86] = 4.062; _vs[87] = 4.069; _vs[88] = 4.077; _vs[89] = 4.085; _vs[90] = 4.092; _vs[86] = 4.074; _vs[87] = 4.083; _vs[88] = 4.092; _vs[89] = 4.101; _vs[90] = 4.110;
_vs[91] = 4.100; _vs[92] = 4.111; _vs[93] = 4.122; _vs[94] = 4.133; _vs[95] = 4.144; _vs[91] = 4.119; _vs[92] = 4.128; _vs[93] = 4.137; _vs[94] = 4.146; _vs[95] = 4.155;
_vs[96] = 4.156; _vs[97] = 4.167; _vs[98] = 4.178; _vs[99] = 4.189; _vs[100] = 4.200; _vs[96] = 4.164; _vs[97] = 4.173; _vs[98] = 4.182; _vs[99] = 4.191; _vs[100] = 4.200;
} }
int Pangodream_18650_CL::getBatteryChargeLevel() int Pangodream_18650_CL::getBatteryChargeLevel()

View file

@ -6,6 +6,7 @@
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
#include "Preferences.h"
#define STORAGE_NAMESPACE "storage" #define STORAGE_NAMESPACE "storage"
#define _OPEN_SYS_ITOA_EXT #define _OPEN_SYS_ITOA_EXT
@ -16,6 +17,8 @@
using namespace std; using namespace std;
Preferences preferences;
// Array of DHT sensors with their respective pins and types // Array of DHT sensors with their respective pins and types
DHT sensors[SENSORS_NUMBER] = {DHT(04, DHT22), DHT(18, DHT22), DHT(05, DHT22), DHT(17, DHT22), DHT(16, DHT22)}; DHT sensors[SENSORS_NUMBER] = {DHT(04, DHT22), DHT(18, DHT22), DHT(05, DHT22), DHT(17, DHT22), DHT(16, DHT22)};
@ -266,9 +269,46 @@ unsigned long getTime()
*/ */
void writeMessage(char *txt, float *temp, float *hum, int number) void writeMessage(char *txt, float *temp, float *hum, int number)
{ {
int chargelvl = Battery.getBatteryChargeLevel(); int chargelvl1 = Battery.getBatteryChargeLevel();
int chargelvl2 = Battery.getBatteryChargeLevel();
int chargelvl3 = Battery.getBatteryChargeLevel();
int chargelvl4 = Battery.getBatteryChargeLevel();
int chargelvl5 = Battery.getBatteryChargeLevel();
int chargelvl6 = Battery.getBatteryChargeLevel();
int chargelvl7 = Battery.getBatteryChargeLevel();
int chargelvl8 = Battery.getBatteryChargeLevel();
int chargelvl9 = Battery.getBatteryChargeLevel();
int chargelvl10 = Battery.getBatteryChargeLevel();
/*début de l'enregistrement des données */
preferences.begin("chargelvl-hum-temp", false);
int chargelvl = preferences.getInt("chargelvl", 1);
for (int i = 0; i < 5; i++) // debut de la boucle pour récuperer les valeur dans le tableau puis les enregistrer
{
char Temp[5];
char Humi[5];
float newTemp = preferences.getFloat(Temp, temp[i]);
float newHum = preferences.getFloat(Humi, hum[i]);
preferences.putFloat("temp", newTemp);
preferences.putFloat("hum", newHum);
Serial.printf("temp: %0.2f\n", newTemp); // print pour vérifier si les valeurs enregistrées sont les bonnes
Serial.printf("hum: %0.2f\n", newHum);
}
chargelvl = (chargelvl1 + chargelvl2 + chargelvl3 + chargelvl4 + chargelvl5 + chargelvl6 + chargelvl7 + chargelvl8 + chargelvl9 + chargelvl10) / 10; // Calcul de la moyenne du niveau de charge de la batterie
// time_t rawtime = TimeClient.getEpochTime(); // time_t rawtime = TimeClient.getEpochTime();
Serial.printf("chargelvl: %d\n", chargelvl); // print pour vérifier si les valeurs enregistrées sont les bonnes
preferences.putInt("chargelvl", chargelvl);
preferences.end();
/* Fin de l'enregistrement des données sur le micro-controleur*/
delay(2000); delay(2000);
switch (number) switch (number)
@ -389,7 +429,6 @@ bool TestBoot(bool resOrRfsh)
nvs_close(my_handle); nvs_close(my_handle);
return false; return false;
} }
//-------------------- Initialisation --------------------// //-------------------- Initialisation --------------------//
/** /**
@ -430,6 +469,8 @@ void setup()
{ {
TestBoot(REFRESHMEMBOOT); TestBoot(REFRESHMEMBOOT);
} }
preferences.end();
// // ######### test time part ######### // // ######### test time part #########
// Serial.println('\n'); // Serial.println('\n');
// Serial.println(hours,DEC); // Serial.println(hours,DEC);