Bonjour à tous,
J'ai une demande d'aide à vous faire pour savoir comment m'y prendre pour interrompre un processus.
J'ai une électrovanne qui est commandée par SMS (Vanne_on ou Vanne_off).
Lors de la réception du SMS, l'électrovanne s'active pendant un temps déterminé l'aide de delay(420000) soit 7 minutes.
L'utilisation de delay() suspend donc le reste de l'exécution du script.
Mais si je souhaite interrompre à tout moment et à distance le fonctionnement de l'électrovanne, comment dois-je m'y prendre car l'envoi d'un SMS "Vanne_off" ne sera traité qu'après la fin du delay()
Merci pour votre aide
Voici mon script:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <SoftwareSerial.h> // Library for using serial communication SoftwareSerial SIM900(7, 8); // Pins 7, 8 are used as used as software serial pins String incomingData; // for storing incoming serial data String message = ""; // A String for storing the message int relay_pin = 2; // Initialized a pin for relay module void setup() { Serial.begin(115200); // baudrate for serial monitor SIM900.begin(19200); // baudrate for GSM shield pinMode(relay_pin, OUTPUT); // Setting erlay pin as output pin digitalWrite(relay_pin, HIGH); // Making relay pin initailly low // set SMS mode to text mode SIM900.print("AT+CMGF=1\r"); delay(100); // set gsm module to tp show the output on serial out SIM900.print("AT+CNMI=2,2,0,0,0\r"); delay(100); } void loop() { //Function for receiving sms receive_message(); // if received command is to turn on relay if(incomingData.indexOf("Vanne_on")>=0) { digitalWrite(relay_pin, LOW); message = "Vanne ON"; // Send a sms back to confirm that the relay is turned on send_message(message); delay(420000); } // if received command is to turn off relay if(incomingData.indexOf("Vanne_off")>=0) { digitalWrite(relay_pin, HIGH); message = "Vanne OFF"; // Send a sms back to confirm that the relay is turned off send_message(message); } } void receive_message() { if (SIM900.available() > 0) { incomingData = SIM900.readString(); // Get the data from the serial port. Serial.print(incomingData); delay(10); } } void send_message(String message) { SIM900.println("AT+CMGF=1"); //Set the GSM Module in Text Mode delay(100); SIM900.println("AT+CMGS=\"+12345678\""); delay(100); SIM900.println(message); // The SMS text you want to send delay(100); SIM900.println((char)26); // ASCII code of CTRL+Z delay(100); SIM900.println(); delay(1000); }
Partager