-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.ino
244 lines (203 loc) · 6.07 KB
/
code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#if defined(ESP32)
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <SPI.h> // SPI
#include <MFRC522.h> // RFID
#include <ESP32Servo.h>
#include <DHT.h>
#include "ThingSpeak.h"
#endif
//////////DHT11 PART
char ssid[] = "TOPNET_CD70"; // your network SSID (name)
char pass[] = "fwh29fy4eo"; // your network password
WiFiClient client;
unsigned long myChannelNumber = "this is changable";
const char * myWriteAPIKey = "this is changable";
DHT dht(5, DHT11);
float temp = 0; // setup a int to simulate a temp
float hum = 0;
///////////////////////////
//Provide the token generation process info.
#include <addons/TokenHelper.h>
//Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "this is changeable"
#define WIFI_PASSWORD "this is changeable"
#define SS_PIN 21
#define RST_PIN 22
// Déclaration
MFRC522 rfid(SS_PIN, RST_PIN);
// Tableau contentent l'ID
byte nuidPICC[4];
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
//For the following credentials, see examples/Authentications/SignInAsUser/EmailPassword/EmailPassword.ino
/* 2. Define the API Key */
#define API_KEY "this is changeable"
/* 3. Define the RTDB URL */
#define DATABASE_URL this is changeable
//Define Firebase Data object
FirebaseData fbdo;
FirebaseData fbdo2;
FirebaseAuth auth;
FirebaseConfig config;
String main="";
String ch="";
String ch1,ch2;
String chtry;
String a,a1;
String tryy="valeur";
String tryy4="name";
int tryy2=1;
int verif=0;
int b, y;
int compt=0;
int capteurdeflamme = 13;
void setup()
{
// Init SPI bus
SPI.begin();
// Init MFRC522
rfid.PCD_Init();
Serial.begin(115200);
delay(2000);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
/* Assign the api key (required) */
config.api_key = API_KEY;
config.database_url = DATABASE_URL;
//////////////////////////////////////////////////////////////////////////////////////////////
//Please make sure the device free Heap is not lower than 80 k for ESP32 and 10 k for ESP8266,
//otherwise the SSL connection will fail.
//////////////////////////////////////////////////////////////////////////////////////////////
Firebase.begin(DATABASE_URL, API_KEY);
//Comment or pass false value when WiFi reconnection will control by your code or third party library
// Firebase.reconnectWiFi(true);
Firebase.setDoubleDigits(5);
delay(3000);
WiFi.begin(ssid, pass);
ThingSpeak.begin(client);
dht.begin();
////flamee
pinMode (capteurdeflamme, INPUT);
myservo.attach(4); // attaches the servo on pin 13 to the servo object
}
void loop()
{
////////////FLAMME PART
int etatducapteur = digitalRead (capteurdeflamme);
if (etatducapteur == 0){
ThingSpeak.writeField(myChannelNumber, 3, 100, myWriteAPIKey);
Serial.println(" IL YA FLAMME");
}
else
{
ThingSpeak.writeField(myChannelNumber, 3, 0, myWriteAPIKey);
Serial.println("NOO FLAMME ");
}
///////////////////DHT11 PART
delay(1000);
temp = dht.readTemperature();
hum = dht.readHumidity();
Serial.print("H= ");
Serial.println(hum);
Serial.print("T= ");
Serial.println(temp);
ThingSpeak.writeField(myChannelNumber, 1, temp, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 2, hum, myWriteAPIKey);
// Initialisé la boucle si aucun badge n'est présent
if ( !rfid.PICC_IsNewCardPresent())
{
return;
}
// Vérifier la présence d'un nouveau badge
if ( !rfid.PICC_ReadCardSerial())
{
return;
}
// Enregistrer l'ID du badge (4 octets)
for (byte i = 0; i < 4; i++)
{
nuidPICC[i] = rfid.uid.uidByte[i];
}
// Affichage de l'ID
Serial.println("Un badge est détecté");
Serial.println(" L'UID du tag est:");
for (byte i = 0; i < 4; i++)
{
Serial.print(nuidPICC[i], HEX);
ch=ch+" "+nuidPICC[i];
Serial.print(" ");
}
Serial.println();
/// this code makes the rfid read the carte once (or you'll get in a loop when the card stay in front of rfid
// Re-Init RFID
rfid.PICC_HaltA(); // Halt PICC
rfid.PCD_StopCrypto1(); // Stop encryption on PCD
verif=0;
if (Firebase.ready())
{
for(byte i=1;i<5;i++)
{
tryy2=i;
ch1="/table/"+tryy+tryy2;
ch2="/names/"+tryy4+tryy2;
Firebase.getString(fbdo, ch1);
Firebase.getString(fbdo2, ch2);
a=(fbdo.to<String>());
a1=(fbdo2.to<String>());
if (ch==a)
{
verif=1;
compt++;
a1=ch+" "+a1;
if (compt==1)
Firebase.setString(fbdo,"/test/verif", a1);
else if (compt==2)
Firebase.setString(fbdo,"/test/verif1", a1);
else if (compt==3)
Firebase.setString(fbdo,"/test/verif2", a1);
else if (compt==4)
Firebase.setString(fbdo,"/test/verif3", a1);
else if (compt==5)
{
Firebase.setString(fbdo,"/test/verif4", a1);
compt=0;
}
}
}
ch="";
delay(200);
if(verif==1)
{
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Serial.println();
Serial.print("a:");
Serial.print(a);
}
Serial.println();
Serial.println("------------------");
Serial.println();
delay(2500);
}
}