Compare commits

...

17 commits

Author SHA1 Message Date
pgp 6deb0299e9 déplacement pin capteur 05 pour libérer pin i2c (GPIO 21) 2022-03-15 18:22:26 +01:00
pgp dcb41c70c2 ajout du prototype de la fonction wakeup dans le main.h 2022-03-15 16:41:53 +01:00
pgp adee2411eb ajout de la foction de réveil par l'alimentation 1er essai 2022-03-15 16:22:20 +01:00
pgp bc99f15ffa rectif 2022-03-15 15:51:48 +01:00
pgp 5acfec4292 secret.h ajouté au gitignore 2022-03-15 15:47:40 +01:00
pgp ce862ccc0d changement du mdp du hotspot 2022-03-15 15:33:23 +01:00
habsinn e1180bef4e changement de pin et durée extinction ESP 2021-11-30 16:48:13 +01:00
habsinn 70e5ca43ad Merge branch 'site_carreire' of https://git.cohabit.fr/thermo-bibli/code-grappe into site_carreire 2021-11-30 12:28:06 +01:00
habsinn 33af2705ab ajout print connection wifi 2021-11-30 12:27:35 +01:00
pgp a0f058150e passwd variable names update 2021-11-29 15:58:48 +01:00
pgp 9f2baac7fa ajout de commentaires 2021-11-29 15:19:44 +01:00
habsinn 45b659f593 changement nom variable SSID password 2021-11-22 14:52:39 +01:00
pgp e9434729b1 maj authors list 2021-11-08 21:07:15 +01:00
pgp 7e6739f146 maj IP Adress of MQTT server 2021-11-08 21:03:55 +01:00
pgp 899550cfe7 maj secret.h mqtt 2021-11-08 18:01:41 +01:00
pgp 33a8b91668 modif READme + maj secret.h 2021-11-08 12:43:57 +01:00
pgp d9ca365483 modif auto extensions.json 2021-11-08 12:34:28 +01:00
6 changed files with 90 additions and 17 deletions

10
.vscode/extensions.json vendored Normal file
View file

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View file

@ -1,2 +1,5 @@
# code-grappe
## branche carreire
mots de passe dans include/secret.h

View file

@ -1,9 +1,9 @@
/**
* @file main.h
* @brief projet thermo-bibli, Équiper la réserve de l'UB de capteurs de température et hygrométrie autonomes et connectés
* @author Bastien Boineau, Lucas Pallaro, Loris Galland
* @version 1.0
* @date 28/06/2021
* @author Bastien Boineau, Lucas Pallaro, Loris Galland, pgp
* @version 1.0.1
* @date 08/11/2021
*/
#ifndef HEADER_H
#define HEADER_H
@ -14,16 +14,17 @@
#include <PubSubClient.h>
#include <Pangodream_18650_CL.h>
#include <secret.h>
#include <RTClib.h>
#define TOPIC "test1"
#define MQTT_ADDRESS "192.168.0.242"
#define MQTT_ADDRESS "185.233.103.24"
#define MQTT_PORT 1883
#define ESPNAME "esp32-bastien"
#define CLUSTER "grappe1"
#define SENSORS_NUMBER 5
#define DHT22 22
#define TIME_TO_SLEEP 598
#define US_TO_S_FACTOR 1000000
#define TIME_TO_SLEEP 3600 // l'ESp32 est rallumé à plein régime pour prendre une mesure toutes les 3600 secondes (soit 1 fois/heure)
#define US_TO_S_FACTOR 1000000 //1000000 => 1 mesure par 10 min
#define R2 100
#define R3 10
#define VOLTAGE_OUT(Vin) (((Vin)*R3) / (R2 + R3))
@ -45,6 +46,7 @@ void readSensors(DHT sensors[], float temp[], float hum[], int number);
void sleep();
std::tuple<int, int, int> getDate();
void writeMsg(char *txt, float *temp, float *hum, int number);
void wakeup();
//timeClient.getEpochTime().toCharArray(date, 50); = convertir un string en char

View file

@ -1,5 +1,5 @@
#define MQTT_USER "NomUtilisateurMQTT"
#define MQTT_MDP "MotDePasseMQTT"
#define SSID "NomDuWifi"
#define PWD "MotDePasseWifi"
#define MQTT_USER "capteurs"
#define MQTT_MDP "Fablab"
#define SSID "Thermo-Bibli"
#define SSID_PWD "17413278"

View file

@ -19,3 +19,4 @@ lib_deps =
ottowinter/ESPAsyncWebServer-esphome@^1.2.7
ottowinter/AsyncTCP-esphome@^1.2.1
arduino-libraries/NTPClient@^3.1.0
adafruit/RTClib@^2.0.2

View file

@ -1,8 +1,11 @@
// psswd's into include/secret.h
// others settings in main.h
#include "main.h"
using namespace std;
DHT sensors[SENSORS_NUMBER] = {DHT(23, DHT22), DHT(22, DHT22), DHT(21, DHT22), DHT(17, DHT22), DHT(2, DHT22)};
DHT sensors[SENSORS_NUMBER] = {DHT(4, DHT22), DHT(5, DHT22), DHT(18, DHT22), DHT(19, DHT22), DHT(03, DHT22)};
float temp[SENSORS_NUMBER];
float hum[SENSORS_NUMBER];
@ -12,6 +15,10 @@ WiFiUDP NtpUDP;
NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org", 0, 60000);
Pangodream_18650_CL Battery(ADC_PIN, CONV_FACTOR, READS);
RTC_DS3231 rtc;
//---------------- Réveil --------------------//
int mesure_freq = 600; // temps entre deux réveils en secondes
//-------------------- FONCTIONS --------------------//
//-------------- Connexion MQTT --------------//
@ -29,8 +36,9 @@ void setupWIFI(const char *wifi_name, const char *password)
Serial.print("Connecting to ");
Serial.print(wifi_name);
while (WiFi.status() != WL_CONNECTED)
while ((WiFi.status() != WL_CONNECTED) && (millis() <= 60000))
{
Serial.println("Nouvelle tentative de connexion...");
delay(500);
Serial.print('.');
}
@ -46,7 +54,7 @@ void reconnect(void)
while (!MqttClient.connected())
{
Serial.print(".");
if (MqttClient.connect(ESPNAME, MQTT_USER, MQTT_PWD))
if (MqttClient.connect(ESPNAME, MQTT_USER, MQTT_MDP))
{
Serial.println("Connected.");
}
@ -75,7 +83,7 @@ void readSensors(DHT sensors[], float temp[], float hum[], int number)
}
//-------------------- Sleep de l'ESP --------------------//
/*
void sleep()
{
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * US_TO_S_FACTOR);
@ -94,6 +102,50 @@ std::tuple<int, int, int> getDate()
return std::make_tuple(year, month, day);
}
*/
//-------------------- Programmation du réveil de l'alimentation --------------------//
void wakeup(){
// initializing the rtc
if(!rtc.begin()) {
Serial.println("Couldn't find RTC!");
Serial.flush();
while (1) delay(10);
}
if(rtc.lostPower()) {
// this will adjust to the date and time at compilation
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
//we don't need the 32K Pin, so disable it
rtc.disable32K();
// set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)
// if not done, this easily leads to problems, as both register aren't reset on reboot/recompile
rtc.clearAlarm(1);
rtc.clearAlarm(2);
// stop oscillating signals at SQW Pin
// otherwise setAlarm1 will fail
rtc.writeSqwPinMode(DS3231_OFF);
// turn off alarm 2 (in case it isn't off already)
// again, this isn't done at reboot, so a previously set alarm could easily go overlooked
rtc.disableAlarm(2);
// schedule an alarm 10 seconds in the future
if(!rtc.setAlarm1(
rtc.now() + TimeSpan(mesure_freq),
DS3231_A1_Second // this mode triggers the alarm when the seconds match. See Doxygen for other options
)) {
Serial.println("Error, alarm wasn't set!");
}else {
Serial.println("Alarm will happen in 10 seconds!");
}
}
//-------------------- Création de trames --------------------//
@ -131,13 +183,14 @@ void writeMessage(char *txt, float *temp, float *hum, int number)
void setup()
{
Serial.begin(9600);
setupWIFI(SSID, PWD);
setupWIFI(SSID, SSID_PWD);
setupMQTT(MQTT_ADDRESS, MQTT_PORT);
initSensors(sensors, SENSORS_NUMBER);
TimeClient.begin();
delay(2000);
}
//-------------------- Boucle pricipale --------------------//
//-------------------- Boucle pringicipale --------------------//
void loop()
{
@ -156,6 +209,9 @@ void loop()
readSensors(sensors, temp, hum, SENSORS_NUMBER);
writeMessage(msg, temp, hum, SENSORS_NUMBER);
Serial.print("une trame de data : ");
Serial.println(msg);
TimeClient.update();
TimeClient.getFormattedTime().toCharArray(time, 30);
@ -166,6 +222,7 @@ void loop()
MqttClient.publish(TOPIC, date);
delay(2000);
Serial.println("Extinction de l'ESP ! ");
wakeup();
sleep();
}