programme intégré
Dependencies: MODSERIAL Servo mbed
main.cpp@2:566244a93a7a, 2018-06-12 (annotated)
- Committer:
- matth420
- Date:
- Tue Jun 12 09:15:30 2018 +0000
- Revision:
- 2:566244a93a7a
- Parent:
- 1:ca1ad3dc37b3
programme IoPChati?re final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matth420 | 0:d811d2c0da76 | 1 | #include "mbed.h" // |
matth420 | 0:d811d2c0da76 | 2 | #include <iostream> // |
matth420 | 0:d811d2c0da76 | 3 | #include <string> // |
matth420 | 0:d811d2c0da76 | 4 | #include <fstream> //Déclaration des librairies utilisées |
matth420 | 0:d811d2c0da76 | 5 | #include "MODSERIAL.h" // |
matth420 | 0:d811d2c0da76 | 6 | #include "Servo.h" // |
matth420 | 0:d811d2c0da76 | 7 | #include <Serial.h> |
matth420 | 0:d811d2c0da76 | 8 | #include "stdio.h" |
matth420 | 2:566244a93a7a | 9 | |
matth420 | 0:d811d2c0da76 | 10 | Serial pc(USBTX, USBRX); |
matth420 | 0:d811d2c0da76 | 11 | Serial rfid1(p9, NC); |
matth420 | 0:d811d2c0da76 | 12 | Serial rfid2(NC, p10); |
matth420 | 0:d811d2c0da76 | 13 | MODSERIAL esp(p28, p27); // tx, rx |
matth420 | 2:566244a93a7a | 14 | DigitalOut reset(p26); //Pin reset WIFI |
matth420 | 0:d811d2c0da76 | 15 | Timer t; //Timer |
matth420 | 0:d811d2c0da76 | 16 | Servo myservo(p21); //Servomoteur |
matth420 | 0:d811d2c0da76 | 17 | DigitalIn manuel1 (p20); //Mode manuel position n°1 (entrée seulement) |
matth420 | 2:566244a93a7a | 18 | //DigitalIn manuel2 (p19); //Mode manuel position n°2 (sortie seulement)(non réalisé car changement de servomoteur) |
matth420 | 1:ca1ad3dc37b3 | 19 | DigitalOut ledmm (p18); //Led indiquant si le mode manuel est activé |
matth420 | 2:566244a93a7a | 20 | DigitalIn manuel2 (p17); //Mode manuel position n°2 (entréé ou sortie) |
matth420 | 2:566244a93a7a | 21 | DigitalIn manuel3 (p16); //Mode manuel position n°3 (verrouillage complet) |
matth420 | 0:d811d2c0da76 | 22 | DigitalIn bpmanuel (p15); //Bouton ON/OFF du mode manuel |
matth420 | 1:ca1ad3dc37b3 | 23 | DigitalIn capteurfermeture (p14); //Capteur détectant la fermeture |
matth420 | 0:d811d2c0da76 | 24 | DigitalIn capext (p12) ; //Capteur de présence extérieur |
matth420 | 1:ca1ad3dc37b3 | 25 | DigitalIn capint (p11) ; //Capteur de présence intérieur |
matth420 | 2:566244a93a7a | 26 | DigitalIn CTS(p8); |
matth420 | 0:d811d2c0da76 | 27 | DigitalIn F411 (p7); //Detection alimentation servomoteur (CHALLENGE LEGRAND !!!!!!!!!!!) |
matth420 | 0:d811d2c0da76 | 28 | |
matth420 | 0:d811d2c0da76 | 29 | DigitalOut led1(LED1); //Led n°1 du mbed |
matth420 | 0:d811d2c0da76 | 30 | DigitalOut led2(LED2); //Led n°2 du mbed |
matth420 | 0:d811d2c0da76 | 31 | DigitalOut led3(LED3); //Led n°3 du mbed |
matth420 | 0:d811d2c0da76 | 32 | DigitalOut led4(LED4); //Led n°4 du mbed |
matth420 | 0:d811d2c0da76 | 33 | |
matth420 | 1:ca1ad3dc37b3 | 34 | int egal1 = 0; //TAG RFID n°1 |
matth420 | 1:ca1ad3dc37b3 | 35 | int egal2 = 0; //TAG RFID n°2 |
matth420 | 1:ca1ad3dc37b3 | 36 | int egal3 = 0; //TAG RFID n°3 |
matth420 | 1:ca1ad3dc37b3 | 37 | int egal4 = 0; //TAG RFID n° |
matth420 | 1:ca1ad3dc37b3 | 38 | int egal5 = 0; //TAG RFID n° |
matth420 | 1:ca1ad3dc37b3 | 39 | int tag1[4]= {0xAE,0xFB,0x63,0x10}; //Identifiant TAG RFID n°1 |
matth420 | 1:ca1ad3dc37b3 | 40 | int tag2[4]= {0x25,0x02,0x64,0x10}; //Identifiant TAG RFID n°2 |
matth420 | 1:ca1ad3dc37b3 | 41 | int tag3[4]= {0x3F,0xFC,0x63,0x10}; //Identifiant TAG RFID n°3 |
matth420 | 1:ca1ad3dc37b3 | 42 | int tag4[4]= {0xCE,0xEE,0x63,0x10}; //Identifiant TAG RFID n°4 |
matth420 | 1:ca1ad3dc37b3 | 43 | int tag5[4]= {0xD6,0xD9,0x63,0x10}; //Identifiant TAG RFID n°5 |
matth420 | 1:ca1ad3dc37b3 | 44 | int tag[4]= {0x00,0x00,0x00,0x00}; //Tableau relevant l'identifiant du TAG RFID |
matth420 | 1:ca1ad3dc37b3 | 45 | int reponse_rfid[5]; |
matth420 | 0:d811d2c0da76 | 46 | int reponse_rfid1[255]; |
matth420 | 0:d811d2c0da76 | 47 | int lireuid[8]= {0x52,0x00}; |
matth420 | 0:d811d2c0da76 | 48 | |
matth420 | 0:d811d2c0da76 | 49 | int position ; //Position de la chatière |
matth420 | 1:ca1ad3dc37b3 | 50 | float pos1 = 1.0 ; //Position n°1 (entrée seulement) |
matth420 | 2:566244a93a7a | 51 | float pos2 = 0.42 ; //Position n°2 (complétement ouvert) |
matth420 | 2:566244a93a7a | 52 | float pos3 = 0.001 ; //Position n°3 (complétement fermé) |
matth420 | 1:ca1ad3dc37b3 | 53 | |
matth420 | 0:d811d2c0da76 | 54 | |
matth420 | 0:d811d2c0da76 | 55 | int i = 0; |
matth420 | 0:d811d2c0da76 | 56 | int e = 0; |
matth420 | 0:d811d2c0da76 | 57 | int count,ended,timeout; |
matth420 | 2:566244a93a7a | 58 | int pass = 0 ; // |
matth420 | 2:566244a93a7a | 59 | int pass1 = 0 ; // |
matth420 | 2:566244a93a7a | 60 | int pass3 = 0 ; //Variable permettant d'écrire le mode manuel actif/inactif/position |
matth420 | 2:566244a93a7a | 61 | int pass2 = 0 ; // |
matth420 | 2:566244a93a7a | 62 | int pass5 = 0 ; // |
matth420 | 2:566244a93a7a | 63 | int secu=0; |
matth420 | 0:d811d2c0da76 | 64 | |
matth420 | 0:d811d2c0da76 | 65 | char buf[1024]; |
matth420 | 0:d811d2c0da76 | 66 | char snd[255]; |
matth420 | 0:d811d2c0da76 | 67 | |
matth420 | 0:d811d2c0da76 | 68 | char ssid[32] = "IOP_LEGRAND_2"; //Nom du WIFI IOP |
matth420 | 0:d811d2c0da76 | 69 | char pwd [32] = "legrandMDP"; //Mot de passe du WIFI IOP |
matth420 | 0:d811d2c0da76 | 70 | |
matth420 | 0:d811d2c0da76 | 71 | char ECHA[5] = "ECHA"; //Le chat vient de l'extérieur |
matth420 | 0:d811d2c0da76 | 72 | char ICHA[5] = "ICHA"; //Le chat vient de l'intérieur |
matth420 | 0:d811d2c0da76 | 73 | |
matth420 | 0:d811d2c0da76 | 74 | |
matth420 | 2:566244a93a7a | 75 | char tcpip[14] = "192.168.2.20"; //Adresse IP du module ESP8666 |
matth420 | 0:d811d2c0da76 | 76 | char tcpport[3] = "23"; |
matth420 | 0:d811d2c0da76 | 77 | |
matth420 | 1:ca1ad3dc37b3 | 78 | int longueur_recue = 0; |
matth420 | 0:d811d2c0da76 | 79 | int nouvelle_reception = 0; |
matth420 | 0:d811d2c0da76 | 80 | int a = 0; |
matth420 | 0:d811d2c0da76 | 81 | int b = 0; |
matth420 | 0:d811d2c0da76 | 82 | |
matth420 | 0:d811d2c0da76 | 83 | char recept[18]; |
matth420 | 0:d811d2c0da76 | 84 | char tabconnect[10] = {0}; |
matth420 | 0:d811d2c0da76 | 85 | char tabclosed[9] = {0}; |
matth420 | 0:d811d2c0da76 | 86 | char tabrec[5] = {0}; |
matth420 | 0:d811d2c0da76 | 87 | char connect[10] = "0,CONNECT"; |
matth420 | 0:d811d2c0da76 | 88 | char closed[9] = "0,CLOSED"; |
matth420 | 0:d811d2c0da76 | 89 | |
matth420 | 1:ca1ad3dc37b3 | 90 | int drapeau = 1; |
matth420 | 1:ca1ad3dc37b3 | 91 | |
matth420 | 2:566244a93a7a | 92 | void HandShake(); // |
matth420 | 2:566244a93a7a | 93 | void Antenna(); // |
matth420 | 2:566244a93a7a | 94 | void field(); //Déclaration des voids |
matth420 | 2:566244a93a7a | 95 | void SendCMD(),getreply(),ESPconfig(),ESPsetbaudrate(),WIFI(), Donnee(); // |
matth420 | 0:d811d2c0da76 | 96 | |
matth420 | 0:d811d2c0da76 | 97 | using namespace std; |
matth420 | 0:d811d2c0da76 | 98 | |
matth420 | 0:d811d2c0da76 | 99 | int main() //Début du int main |
matth420 | 2:566244a93a7a | 100 | { |
matth420 | 1:ca1ad3dc37b3 | 101 | ledmm = 0; |
matth420 | 2:566244a93a7a | 102 | myservo = pos3 ; //La chatière est fermé |
matth420 | 1:ca1ad3dc37b3 | 103 | wait_ms(200); |
matth420 | 1:ca1ad3dc37b3 | 104 | |
matth420 | 0:d811d2c0da76 | 105 | reset=0; //Reset du module ESP8266 |
matth420 | 0:d811d2c0da76 | 106 | pc.baud(9600); //Vitesse de transmission du terminal |
matth420 | 0:d811d2c0da76 | 107 | pc.printf("\f\n\r--------------- Demarrage du module WIFI ---------------\n\r"); //Démarrage du module WIFI ESP8266 |
matth420 | 1:ca1ad3dc37b3 | 108 | wait(0.25); |
matth420 | 0:d811d2c0da76 | 109 | reset=1; |
matth420 | 0:d811d2c0da76 | 110 | timeout=2; |
matth420 | 0:d811d2c0da76 | 111 | getreply(); |
matth420 | 0:d811d2c0da76 | 112 | |
matth420 | 0:d811d2c0da76 | 113 | esp.baud(115200); //Vitesse de transmission du module WIFI ESP8266 |
matth420 | 1:ca1ad3dc37b3 | 114 | |
matth420 | 0:d811d2c0da76 | 115 | ESPconfig(); //Configuration du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 116 | |
matth420 | 0:d811d2c0da76 | 117 | pc.printf("\f\n\r- Module pret -\n\r"); //Le module WIFI ESP8266 |
matth420 | 2:566244a93a7a | 118 | // pc.printf("-------------------- La chatiere est verrouillee ----------------\n\r"); |
matth420 | 1:ca1ad3dc37b3 | 119 | |
matth420 | 2:566244a93a7a | 120 | while(1) |
matth420 | 2:566244a93a7a | 121 | { |
matth420 | 2:566244a93a7a | 122 | // Partie RFID |
matth420 | 1:ca1ad3dc37b3 | 123 | led4=1; |
matth420 | 1:ca1ad3dc37b3 | 124 | ledmm = 0; |
matth420 | 2:566244a93a7a | 125 | egal1=0; //Variable TAG RFID n°1 |
matth420 | 2:566244a93a7a | 126 | egal2=0; //Variable TAG RFID n°2 |
matth420 | 2:566244a93a7a | 127 | egal3=0; //Variable TAG RFID n°3 |
matth420 | 2:566244a93a7a | 128 | egal4=0; //Variable TAG RFID n°4 |
matth420 | 2:566244a93a7a | 129 | egal5=0; //Variable TAG RFID n°5 |
matth420 | 0:d811d2c0da76 | 130 | |
matth420 | 1:ca1ad3dc37b3 | 131 | |
matth420 | 0:d811d2c0da76 | 132 | |
matth420 | 2:566244a93a7a | 133 | if (CTS == 0) //Vérification des câblages |
matth420 | 2:566244a93a7a | 134 | { |
matth420 | 1:ca1ad3dc37b3 | 135 | led4=0; |
matth420 | 1:ca1ad3dc37b3 | 136 | led2=1; |
matth420 | 1:ca1ad3dc37b3 | 137 | |
matth420 | 2:566244a93a7a | 138 | for (int i=0; i<2; i++) |
matth420 | 2:566244a93a7a | 139 | { |
matth420 | 0:d811d2c0da76 | 140 | rfid2.putc(lireuid[i]); |
matth420 | 0:d811d2c0da76 | 141 | } |
matth420 | 0:d811d2c0da76 | 142 | wait_ms(25); |
matth420 | 2:566244a93a7a | 143 | for (int e=0; e<1; e++) |
matth420 | 2:566244a93a7a | 144 | { |
matth420 | 0:d811d2c0da76 | 145 | reponse_rfid1[e]=(rfid1.getc()); |
matth420 | 0:d811d2c0da76 | 146 | led1=1; |
matth420 | 0:d811d2c0da76 | 147 | } |
matth420 | 2:566244a93a7a | 148 | if (reponse_rfid1[0] == 0xD6) |
matth420 | 2:566244a93a7a | 149 | { |
matth420 | 2:566244a93a7a | 150 | for (int i=0; i<2; i++) |
matth420 | 2:566244a93a7a | 151 | { |
matth420 | 0:d811d2c0da76 | 152 | rfid2.putc(lireuid[i]); |
matth420 | 0:d811d2c0da76 | 153 | led2=1; |
matth420 | 0:d811d2c0da76 | 154 | } |
matth420 | 0:d811d2c0da76 | 155 | wait_ms(50); |
matth420 | 2:566244a93a7a | 156 | for (int e=1; e<5; e++) |
matth420 | 2:566244a93a7a | 157 | { |
matth420 | 0:d811d2c0da76 | 158 | reponse_rfid[e]=(rfid1.getc()); |
matth420 | 0:d811d2c0da76 | 159 | led3=1; |
matth420 | 0:d811d2c0da76 | 160 | } |
matth420 | 1:ca1ad3dc37b3 | 161 | |
matth420 | 0:d811d2c0da76 | 162 | pc.printf("---------------------------------------"); |
matth420 | 0:d811d2c0da76 | 163 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 164 | pc.printf("Trame de reponse du PCB en hexa : "); |
matth420 | 0:d811d2c0da76 | 165 | for (int i=0; i<2; i++) pc.printf("%X ",lireuid[i]); |
matth420 | 0:d811d2c0da76 | 166 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 167 | pc.printf("Status = %X\n\r",reponse_rfid1[0]); |
matth420 | 0:d811d2c0da76 | 168 | pc.printf("UID = "); |
matth420 | 0:d811d2c0da76 | 169 | for (int i=1; i<5; i++) pc.printf("%X ",reponse_rfid[i]); |
matth420 | 0:d811d2c0da76 | 170 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 171 | pc.printf("---------------------------------------"); |
matth420 | 0:d811d2c0da76 | 172 | pc.printf("\n\r"); |
matth420 | 2:566244a93a7a | 173 | } |
matth420 | 2:566244a93a7a | 174 | else if (reponse_rfid1[0] == 0xC0) |
matth420 | 2:566244a93a7a | 175 | { |
matth420 | 0:d811d2c0da76 | 176 | field(); |
matth420 | 0:d811d2c0da76 | 177 | } |
matth420 | 2:566244a93a7a | 178 | if (reponse_rfid1[0] == 0xE0) |
matth420 | 2:566244a93a7a | 179 | { |
matth420 | 0:d811d2c0da76 | 180 | Antenna(); |
matth420 | 0:d811d2c0da76 | 181 | } |
matth420 | 2:566244a93a7a | 182 | for(int i=1; i<5; i++) |
matth420 | 2:566244a93a7a | 183 | { |
matth420 | 0:d811d2c0da76 | 184 | tag[i-1] = reponse_rfid[i]; |
matth420 | 2:566244a93a7a | 185 | } |
matth420 | 2:566244a93a7a | 186 | if(tag[0] != 0x00) |
matth420 | 2:566244a93a7a | 187 | { |
matth420 | 0:d811d2c0da76 | 188 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 189 | pc.printf("tableau de 0: %X", tag[0]); |
matth420 | 0:d811d2c0da76 | 190 | pc.printf("\n\r"); |
matth420 | 1:ca1ad3dc37b3 | 191 | |
matth420 | 2:566244a93a7a | 192 | for(int i=0; i<4; i++) //Identification du TAG RFID n°1 |
matth420 | 2:566244a93a7a | 193 | { |
matth420 | 2:566244a93a7a | 194 | if(tag[i] == tag1[i]) |
matth420 | 2:566244a93a7a | 195 | { |
matth420 | 2:566244a93a7a | 196 | egal1 = 1; //Le TAG RFID n°1 est détecté |
matth420 | 0:d811d2c0da76 | 197 | pc.printf("Tag1 - OK "); |
matth420 | 0:d811d2c0da76 | 198 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 199 | break; |
matth420 | 2:566244a93a7a | 200 | } |
matth420 | 2:566244a93a7a | 201 | else if(tag[i] != tag1[i]) |
matth420 | 2:566244a93a7a | 202 | { |
matth420 | 0:d811d2c0da76 | 203 | pc.printf("Tag1 - NOK "); |
matth420 | 0:d811d2c0da76 | 204 | pc.printf("\n\r"); |
matth420 | 2:566244a93a7a | 205 | egal1 = 0; //Le TAG RFID n°1 n'est pas détecté |
matth420 | 0:d811d2c0da76 | 206 | break; |
matth420 | 0:d811d2c0da76 | 207 | } |
matth420 | 0:d811d2c0da76 | 208 | } |
matth420 | 2:566244a93a7a | 209 | for(int i=0; i<4; i++) //Identification du TAG RFID n°2 |
matth420 | 2:566244a93a7a | 210 | { |
matth420 | 2:566244a93a7a | 211 | if(tag[i] == tag2[i]) |
matth420 | 2:566244a93a7a | 212 | { |
matth420 | 2:566244a93a7a | 213 | egal2 = 1; //Le TAG RFID n°2 est détecté |
matth420 | 0:d811d2c0da76 | 214 | pc.printf("Tag2 - OK "); |
matth420 | 0:d811d2c0da76 | 215 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 216 | break; |
matth420 | 2:566244a93a7a | 217 | } |
matth420 | 2:566244a93a7a | 218 | else if(tag[i] != tag2[i]) |
matth420 | 2:566244a93a7a | 219 | { |
matth420 | 0:d811d2c0da76 | 220 | pc.printf("Tag2 - NOK "); |
matth420 | 0:d811d2c0da76 | 221 | pc.printf("\n\r"); |
matth420 | 2:566244a93a7a | 222 | egal2 = 0; //Le TAG RFID n°2 n'est pas détecté |
matth420 | 0:d811d2c0da76 | 223 | break; |
matth420 | 0:d811d2c0da76 | 224 | } |
matth420 | 0:d811d2c0da76 | 225 | } |
matth420 | 2:566244a93a7a | 226 | for(int i=0; i<4; i++) //Identification du TAG RFID n°3 |
matth420 | 2:566244a93a7a | 227 | { |
matth420 | 2:566244a93a7a | 228 | if(tag[i] == tag3[i]) |
matth420 | 2:566244a93a7a | 229 | { |
matth420 | 2:566244a93a7a | 230 | egal3 = 1; //Le TAG RFID n°3 est détecté |
matth420 | 0:d811d2c0da76 | 231 | pc.printf("Tag3 - OK "); |
matth420 | 0:d811d2c0da76 | 232 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 233 | break; |
matth420 | 2:566244a93a7a | 234 | } |
matth420 | 2:566244a93a7a | 235 | else if(tag[i] != tag3[i]) |
matth420 | 2:566244a93a7a | 236 | { |
matth420 | 0:d811d2c0da76 | 237 | pc.printf("Tag3 - NOK "); |
matth420 | 0:d811d2c0da76 | 238 | pc.printf("\n\r"); |
matth420 | 2:566244a93a7a | 239 | egal3 = 0; //Le TAG RFID n°3 n'est pas détecté |
matth420 | 0:d811d2c0da76 | 240 | break; |
matth420 | 0:d811d2c0da76 | 241 | } |
matth420 | 0:d811d2c0da76 | 242 | } |
matth420 | 2:566244a93a7a | 243 | for(int i=0; i<4; i++) //Identification du TAG RFID n°4 |
matth420 | 2:566244a93a7a | 244 | { |
matth420 | 2:566244a93a7a | 245 | if(tag[i] == tag4[i]) |
matth420 | 2:566244a93a7a | 246 | { |
matth420 | 2:566244a93a7a | 247 | egal4 = 1; //Le TAG RFID n°4 est détecté |
matth420 | 0:d811d2c0da76 | 248 | pc.printf("Tag4 - OK "); |
matth420 | 0:d811d2c0da76 | 249 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 250 | break; |
matth420 | 2:566244a93a7a | 251 | } |
matth420 | 2:566244a93a7a | 252 | else if(tag[i] != tag4[i]) |
matth420 | 2:566244a93a7a | 253 | { |
matth420 | 0:d811d2c0da76 | 254 | pc.printf("Tag4 - NOK "); |
matth420 | 0:d811d2c0da76 | 255 | pc.printf("\n\r"); |
matth420 | 2:566244a93a7a | 256 | egal4 = 0; //Le TAG RFID n°4 n'est détecté |
matth420 | 0:d811d2c0da76 | 257 | break; |
matth420 | 0:d811d2c0da76 | 258 | } |
matth420 | 0:d811d2c0da76 | 259 | } |
matth420 | 2:566244a93a7a | 260 | for(int i=0; i<4; i++) //Identification du TAG RFID n°5 |
matth420 | 2:566244a93a7a | 261 | { |
matth420 | 2:566244a93a7a | 262 | if(tag[i] == tag5[i]) |
matth420 | 2:566244a93a7a | 263 | { |
matth420 | 2:566244a93a7a | 264 | egal5 = 1; //Le TAG RFID n°5 est détecté |
matth420 | 0:d811d2c0da76 | 265 | pc.printf("Tag5 - OK "); |
matth420 | 0:d811d2c0da76 | 266 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 267 | break; |
matth420 | 2:566244a93a7a | 268 | } else if(tag[i] != tag5[i]) |
matth420 | 2:566244a93a7a | 269 | { |
matth420 | 0:d811d2c0da76 | 270 | pc.printf("Tag5 - NOK "); |
matth420 | 0:d811d2c0da76 | 271 | pc.printf("\n\r"); |
matth420 | 2:566244a93a7a | 272 | egal5 = 0; //Le TAG RFID n°5 n'est pas détecté |
matth420 | 0:d811d2c0da76 | 273 | break; |
matth420 | 1:ca1ad3dc37b3 | 274 | } |
matth420 | 0:d811d2c0da76 | 275 | } |
matth420 | 1:ca1ad3dc37b3 | 276 | reponse_rfid[1]=0x00; |
matth420 | 0:d811d2c0da76 | 277 | } |
matth420 | 0:d811d2c0da76 | 278 | |
matth420 | 0:d811d2c0da76 | 279 | led1=0; |
matth420 | 0:d811d2c0da76 | 280 | led2=0; |
matth420 | 1:ca1ad3dc37b3 | 281 | led3=1; |
matth420 | 0:d811d2c0da76 | 282 | |
matth420 | 0:d811d2c0da76 | 283 | wait_ms(500); |
matth420 | 1:ca1ad3dc37b3 | 284 | |
matth420 | 1:ca1ad3dc37b3 | 285 | } |
matth420 | 1:ca1ad3dc37b3 | 286 | |
matth420 | 1:ca1ad3dc37b3 | 287 | |
matth420 | 2:566244a93a7a | 288 | if(capext ==1 && egal1 ==1) //Si le capteur extérieur est à 1 & le TAG 1 est détecté |
matth420 | 2:566244a93a7a | 289 | { |
matth420 | 1:ca1ad3dc37b3 | 290 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 291 | pc.printf("---------- L'animal vient de l'exterieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 292 | pc.printf("---------- Le TAG numero 1 est detecte ----------\r\n"); |
matth420 | 1:ca1ad3dc37b3 | 293 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 1:ca1ad3dc37b3 | 294 | SendCMD(); |
matth420 | 2:566244a93a7a | 295 | timeout=3; |
matth420 | 1:ca1ad3dc37b3 | 296 | getreply(); |
matth420 | 1:ca1ad3dc37b3 | 297 | pc.printf(buf); |
matth420 | 1:ca1ad3dc37b3 | 298 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 1:ca1ad3dc37b3 | 299 | SendCMD(); |
matth420 | 2:566244a93a7a | 300 | timeout=3; |
matth420 | 1:ca1ad3dc37b3 | 301 | getreply(); |
matth420 | 1:ca1ad3dc37b3 | 302 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 1:ca1ad3dc37b3 | 303 | if (F411==1) |
matth420 | 1:ca1ad3dc37b3 | 304 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 305 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 306 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 307 | wait(2) ; |
matth420 | 2:566244a93a7a | 308 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 309 | { |
matth420 | 2:566244a93a7a | 310 | led3=1; |
matth420 | 2:566244a93a7a | 311 | |
matth420 | 2:566244a93a7a | 312 | } |
matth420 | 2:566244a93a7a | 313 | led3=0; |
matth420 | 2:566244a93a7a | 314 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 315 | wait(2); |
matth420 | 1:ca1ad3dc37b3 | 316 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 317 | { |
matth420 | 1:ca1ad3dc37b3 | 318 | led2=1; |
matth420 | 1:ca1ad3dc37b3 | 319 | } |
matth420 | 2:566244a93a7a | 320 | wait(1); |
matth420 | 2:566244a93a7a | 321 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 322 | myservo = pos3 ; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 323 | position=3; |
matth420 | 1:ca1ad3dc37b3 | 324 | } |
matth420 | 2:566244a93a7a | 325 | else |
matth420 | 2:566244a93a7a | 326 | { |
matth420 | 2:566244a93a7a | 327 | pc.printf("++++++++ L'animal n'est pas autorise a entrer ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 328 | } |
matth420 | 2:566244a93a7a | 329 | } |
matth420 | 0:d811d2c0da76 | 330 | |
matth420 | 1:ca1ad3dc37b3 | 331 | if(capint ==1 && egal1 ==1) //Si le capteur intérieur est à 1 & le TAG 1 est détecté |
matth420 | 1:ca1ad3dc37b3 | 332 | { |
matth420 | 0:d811d2c0da76 | 333 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 334 | pc.printf("---------- L'animal vient de l'interieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 335 | pc.printf("---------- Le TAG numero 1 est detecte ----------\r\n"); |
matth420 | 0:d811d2c0da76 | 336 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 0:d811d2c0da76 | 337 | SendCMD(); |
matth420 | 2:566244a93a7a | 338 | timeout=3; |
matth420 | 0:d811d2c0da76 | 339 | getreply(); |
matth420 | 0:d811d2c0da76 | 340 | pc.printf(buf); |
matth420 | 1:ca1ad3dc37b3 | 341 | strcpy(snd, "ICHA\r\n"); //Le chat vient de l'intérieur |
matth420 | 0:d811d2c0da76 | 342 | SendCMD(); |
matth420 | 2:566244a93a7a | 343 | timeout=3; |
matth420 | 0:d811d2c0da76 | 344 | getreply(); |
matth420 | 0:d811d2c0da76 | 345 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 1:ca1ad3dc37b3 | 346 | if (F411 ==1) |
matth420 | 1:ca1ad3dc37b3 | 347 | { //Vérification alimentation servo par F411 (MyHome) |
matth420 | 2:566244a93a7a | 348 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 349 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 350 | wait(2) ; |
matth420 | 2:566244a93a7a | 351 | while(capteurfermeture==0) |
matth420 | 0:d811d2c0da76 | 352 | { |
matth420 | 1:ca1ad3dc37b3 | 353 | led3=1; |
matth420 | 2:566244a93a7a | 354 | |
matth420 | 1:ca1ad3dc37b3 | 355 | } |
matth420 | 1:ca1ad3dc37b3 | 356 | led3=0; |
matth420 | 2:566244a93a7a | 357 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 358 | wait(2); |
matth420 | 2:566244a93a7a | 359 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 360 | { |
matth420 | 2:566244a93a7a | 361 | led2=1; |
matth420 | 2:566244a93a7a | 362 | } |
matth420 | 2:566244a93a7a | 363 | wait(1); |
matth420 | 2:566244a93a7a | 364 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 365 | myservo = pos3 ; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 366 | position=3; |
matth420 | 2:566244a93a7a | 367 | } |
matth420 | 2:566244a93a7a | 368 | else |
matth420 | 2:566244a93a7a | 369 | { |
matth420 | 2:566244a93a7a | 370 | pc.printf("++++++++ L'animal n'est pas autorise a sortir ++++++++\n\r"); |
matth420 | 1:ca1ad3dc37b3 | 371 | } |
matth420 | 1:ca1ad3dc37b3 | 372 | } |
matth420 | 1:ca1ad3dc37b3 | 373 | |
matth420 | 2:566244a93a7a | 374 | if(capext ==1 && egal2 ==1) //Si le capteur extérieur est à 1 & le TAG 2 est détecté |
matth420 | 2:566244a93a7a | 375 | { |
matth420 | 2:566244a93a7a | 376 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 377 | pc.printf("---------- L'animal vient de l'exterieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 378 | pc.printf("---------- Le TAG numero 2 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 379 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 380 | SendCMD(); |
matth420 | 2:566244a93a7a | 381 | timeout=3; |
matth420 | 2:566244a93a7a | 382 | getreply(); |
matth420 | 2:566244a93a7a | 383 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 384 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 385 | SendCMD(); |
matth420 | 2:566244a93a7a | 386 | timeout=3; |
matth420 | 2:566244a93a7a | 387 | getreply(); |
matth420 | 2:566244a93a7a | 388 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 389 | if (F411==1) |
matth420 | 2:566244a93a7a | 390 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 391 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 392 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 393 | wait(2); |
matth420 | 2:566244a93a7a | 394 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 395 | { |
matth420 | 2:566244a93a7a | 396 | led2=1; |
matth420 | 2:566244a93a7a | 397 | } |
matth420 | 2:566244a93a7a | 398 | led2=0; |
matth420 | 2:566244a93a7a | 399 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 400 | wait(2); |
matth420 | 2:566244a93a7a | 401 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 402 | { |
matth420 | 2:566244a93a7a | 403 | led2=1; |
matth420 | 2:566244a93a7a | 404 | } |
matth420 | 2:566244a93a7a | 405 | wait(1); |
matth420 | 2:566244a93a7a | 406 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 407 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 408 | position = 3; |
matth420 | 1:ca1ad3dc37b3 | 409 | } |
matth420 | 2:566244a93a7a | 410 | else |
matth420 | 2:566244a93a7a | 411 | { |
matth420 | 2:566244a93a7a | 412 | pc.printf("++++++++ L'animal n'est pas autorise a entrer ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 413 | } |
matth420 | 2:566244a93a7a | 414 | } |
matth420 | 2:566244a93a7a | 415 | |
matth420 | 2:566244a93a7a | 416 | if(capint ==1 && egal2 ==1) //Si le capteur extérieur est à 1 & le TAG 2 est détecté |
matth420 | 2:566244a93a7a | 417 | { |
matth420 | 2:566244a93a7a | 418 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 419 | pc.printf("---------- L'animal vient de l'interieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 420 | pc.printf("---------- Le TAG numero 2 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 421 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 422 | SendCMD(); |
matth420 | 2:566244a93a7a | 423 | timeout=3; |
matth420 | 2:566244a93a7a | 424 | getreply(); |
matth420 | 2:566244a93a7a | 425 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 426 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 427 | SendCMD(); |
matth420 | 2:566244a93a7a | 428 | timeout=3; |
matth420 | 2:566244a93a7a | 429 | getreply(); |
matth420 | 2:566244a93a7a | 430 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 431 | if (F411==1) |
matth420 | 2:566244a93a7a | 432 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 433 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 434 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 435 | wait(2); |
matth420 | 2:566244a93a7a | 436 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 437 | { |
matth420 | 2:566244a93a7a | 438 | led2=1; |
matth420 | 2:566244a93a7a | 439 | } |
matth420 | 2:566244a93a7a | 440 | led2=0; |
matth420 | 2:566244a93a7a | 441 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 442 | wait(2); |
matth420 | 2:566244a93a7a | 443 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 444 | { |
matth420 | 2:566244a93a7a | 445 | led2=1; |
matth420 | 2:566244a93a7a | 446 | } |
matth420 | 2:566244a93a7a | 447 | wait(1); |
matth420 | 2:566244a93a7a | 448 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 449 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 450 | position = 3; |
matth420 | 2:566244a93a7a | 451 | } |
matth420 | 2:566244a93a7a | 452 | else |
matth420 | 2:566244a93a7a | 453 | { |
matth420 | 2:566244a93a7a | 454 | pc.printf("++++++++ L'animal n'est pas autorise a sortir ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 455 | } |
matth420 | 2:566244a93a7a | 456 | } |
matth420 | 2:566244a93a7a | 457 | if(capext ==1 && egal3 ==1) //Si le capteur extérieur est à 1 & le TAG 3 est détecté |
matth420 | 2:566244a93a7a | 458 | { |
matth420 | 2:566244a93a7a | 459 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 460 | pc.printf("---------- L'animal vient de l'exterieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 461 | pc.printf("---------- Le TAG numero 3 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 462 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 463 | SendCMD(); |
matth420 | 2:566244a93a7a | 464 | timeout=3; |
matth420 | 2:566244a93a7a | 465 | getreply(); |
matth420 | 2:566244a93a7a | 466 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 467 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 468 | SendCMD(); |
matth420 | 2:566244a93a7a | 469 | timeout=3; |
matth420 | 2:566244a93a7a | 470 | getreply(); |
matth420 | 2:566244a93a7a | 471 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 472 | if (F411==1) |
matth420 | 2:566244a93a7a | 473 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 474 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 475 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 476 | wait(2); |
matth420 | 2:566244a93a7a | 477 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 478 | { |
matth420 | 2:566244a93a7a | 479 | led2=1; |
matth420 | 1:ca1ad3dc37b3 | 480 | |
matth420 | 2:566244a93a7a | 481 | } |
matth420 | 2:566244a93a7a | 482 | led2=0; |
matth420 | 2:566244a93a7a | 483 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 484 | wait(2); |
matth420 | 2:566244a93a7a | 485 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 486 | { |
matth420 | 2:566244a93a7a | 487 | led2=1; |
matth420 | 2:566244a93a7a | 488 | } |
matth420 | 2:566244a93a7a | 489 | wait(1); |
matth420 | 2:566244a93a7a | 490 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 491 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 492 | position = 3; |
matth420 | 2:566244a93a7a | 493 | } |
matth420 | 2:566244a93a7a | 494 | else |
matth420 | 2:566244a93a7a | 495 | { |
matth420 | 2:566244a93a7a | 496 | pc.printf("++++++++ L'animal n'est pas autorise a entrer ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 497 | } |
matth420 | 2:566244a93a7a | 498 | } |
matth420 | 2:566244a93a7a | 499 | if(capint ==1 && egal3 ==1) //Si le capteur inérieur est à 1 & le TAG 3 est détecté |
matth420 | 2:566244a93a7a | 500 | { |
matth420 | 2:566244a93a7a | 501 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 502 | pc.printf("---------- L'animal vient de l'interieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 503 | pc.printf("---------- Le TAG numero 3 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 504 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 505 | SendCMD(); |
matth420 | 2:566244a93a7a | 506 | timeout=3; |
matth420 | 2:566244a93a7a | 507 | getreply(); |
matth420 | 2:566244a93a7a | 508 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 509 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 510 | SendCMD(); |
matth420 | 2:566244a93a7a | 511 | timeout=3; |
matth420 | 2:566244a93a7a | 512 | getreply(); |
matth420 | 2:566244a93a7a | 513 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 514 | if (F411==1) |
matth420 | 2:566244a93a7a | 515 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 516 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 517 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 518 | wait(2); |
matth420 | 2:566244a93a7a | 519 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 520 | { |
matth420 | 2:566244a93a7a | 521 | led2=1; |
matth420 | 2:566244a93a7a | 522 | } |
matth420 | 2:566244a93a7a | 523 | led2=0; |
matth420 | 2:566244a93a7a | 524 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 525 | wait(2); |
matth420 | 2:566244a93a7a | 526 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 527 | { |
matth420 | 2:566244a93a7a | 528 | led2=1; |
matth420 | 2:566244a93a7a | 529 | } |
matth420 | 2:566244a93a7a | 530 | wait(1); |
matth420 | 2:566244a93a7a | 531 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 532 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 533 | position = 3; |
matth420 | 2:566244a93a7a | 534 | } |
matth420 | 2:566244a93a7a | 535 | else |
matth420 | 2:566244a93a7a | 536 | { |
matth420 | 2:566244a93a7a | 537 | pc.printf("++++++++ L'animal n'est pas autorise a sortir ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 538 | } |
matth420 | 2:566244a93a7a | 539 | } |
matth420 | 2:566244a93a7a | 540 | if(capext ==1 && egal4 ==1) //Si le capteur extérieur est à 1 & le TAG 4 est détecté |
matth420 | 2:566244a93a7a | 541 | { |
matth420 | 2:566244a93a7a | 542 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 543 | pc.printf("---------- L'animal vient de l'exterieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 544 | pc.printf("---------- Le TAG numero 4 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 545 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 546 | SendCMD(); |
matth420 | 2:566244a93a7a | 547 | timeout=3; |
matth420 | 2:566244a93a7a | 548 | getreply(); |
matth420 | 2:566244a93a7a | 549 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 550 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 551 | SendCMD(); |
matth420 | 2:566244a93a7a | 552 | timeout=3; |
matth420 | 2:566244a93a7a | 553 | getreply(); |
matth420 | 2:566244a93a7a | 554 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 555 | if (F411==1) |
matth420 | 2:566244a93a7a | 556 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 557 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 558 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 559 | wait(2); |
matth420 | 2:566244a93a7a | 560 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 561 | { |
matth420 | 2:566244a93a7a | 562 | led2=1; |
matth420 | 2:566244a93a7a | 563 | } |
matth420 | 2:566244a93a7a | 564 | led2=0; |
matth420 | 2:566244a93a7a | 565 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 566 | wait(2); |
matth420 | 2:566244a93a7a | 567 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 568 | { |
matth420 | 2:566244a93a7a | 569 | led2=1; |
matth420 | 2:566244a93a7a | 570 | } |
matth420 | 2:566244a93a7a | 571 | wait(1); |
matth420 | 2:566244a93a7a | 572 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 573 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 574 | position = 3; |
matth420 | 2:566244a93a7a | 575 | } |
matth420 | 2:566244a93a7a | 576 | else |
matth420 | 2:566244a93a7a | 577 | { |
matth420 | 2:566244a93a7a | 578 | pc.printf("++++++++ L'animal n'est pas autorise a entrer ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 579 | } |
matth420 | 2:566244a93a7a | 580 | } |
matth420 | 2:566244a93a7a | 581 | if(capint ==1 && egal4 ==1) //Si le capteur intérieur est à 1 & le TAG 1 est détecté |
matth420 | 2:566244a93a7a | 582 | { |
matth420 | 2:566244a93a7a | 583 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 584 | pc.printf("---------- L'animal vient de l'interieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 585 | pc.printf("---------- Le TAG numero 4 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 586 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 587 | SendCMD(); |
matth420 | 2:566244a93a7a | 588 | timeout=3; |
matth420 | 2:566244a93a7a | 589 | getreply(); |
matth420 | 2:566244a93a7a | 590 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 591 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 592 | SendCMD(); |
matth420 | 2:566244a93a7a | 593 | timeout=3; |
matth420 | 2:566244a93a7a | 594 | getreply(); |
matth420 | 2:566244a93a7a | 595 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 596 | if (F411==1) |
matth420 | 2:566244a93a7a | 597 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 598 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 599 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 600 | wait(2); |
matth420 | 2:566244a93a7a | 601 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 602 | { |
matth420 | 2:566244a93a7a | 603 | led2=1; |
matth420 | 2:566244a93a7a | 604 | } |
matth420 | 2:566244a93a7a | 605 | led2=0; |
matth420 | 2:566244a93a7a | 606 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 607 | wait(2); |
matth420 | 2:566244a93a7a | 608 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 609 | { |
matth420 | 2:566244a93a7a | 610 | led2=1; |
matth420 | 2:566244a93a7a | 611 | } |
matth420 | 2:566244a93a7a | 612 | wait(1); |
matth420 | 2:566244a93a7a | 613 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 614 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 615 | position = 3; |
matth420 | 2:566244a93a7a | 616 | } |
matth420 | 2:566244a93a7a | 617 | else |
matth420 | 2:566244a93a7a | 618 | { |
matth420 | 2:566244a93a7a | 619 | pc.printf("++++++++ L'animal n'est pas autorise a sortir ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 620 | } |
matth420 | 2:566244a93a7a | 621 | } |
matth420 | 2:566244a93a7a | 622 | if(capext ==1 && egal5 ==1) //Si le capteur extérieur est à 1 & le TAG 4 est détecté |
matth420 | 2:566244a93a7a | 623 | { |
matth420 | 2:566244a93a7a | 624 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 625 | pc.printf("---------- L'animal vient de l'exterieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 626 | pc.printf("---------- Le TAG numero 5 est detecte ----------\r\n"); |
matth420 | 2:566244a93a7a | 627 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 628 | SendCMD(); |
matth420 | 2:566244a93a7a | 629 | timeout=3; |
matth420 | 2:566244a93a7a | 630 | getreply(); |
matth420 | 2:566244a93a7a | 631 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 632 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 633 | SendCMD(); |
matth420 | 2:566244a93a7a | 634 | timeout=3; |
matth420 | 2:566244a93a7a | 635 | getreply(); |
matth420 | 2:566244a93a7a | 636 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 637 | if (F411==1) |
matth420 | 2:566244a93a7a | 638 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 639 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 640 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 641 | wait(2); |
matth420 | 2:566244a93a7a | 642 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 643 | { |
matth420 | 2:566244a93a7a | 644 | led2=1; |
matth420 | 2:566244a93a7a | 645 | } |
matth420 | 2:566244a93a7a | 646 | led2=0; |
matth420 | 2:566244a93a7a | 647 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 648 | wait(2); |
matth420 | 2:566244a93a7a | 649 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 650 | { |
matth420 | 2:566244a93a7a | 651 | led2=1; |
matth420 | 2:566244a93a7a | 652 | } |
matth420 | 2:566244a93a7a | 653 | wait(1); |
matth420 | 2:566244a93a7a | 654 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 655 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 656 | position = 3; |
matth420 | 2:566244a93a7a | 657 | } |
matth420 | 2:566244a93a7a | 658 | else |
matth420 | 2:566244a93a7a | 659 | { |
matth420 | 2:566244a93a7a | 660 | pc.printf("++++++++ L'animal n'est pas autorise a entrer ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 661 | } |
matth420 | 2:566244a93a7a | 662 | } |
matth420 | 2:566244a93a7a | 663 | if(capint ==1 && egal5 ==1) //Si le capteur intérieur est à 1 & le TAG 1 est détecté |
matth420 | 2:566244a93a7a | 664 | { |
matth420 | 2:566244a93a7a | 665 | pc.printf("---------- Envoi de donnees au serveur -----------\r\n"); //Envoi de données au serveur |
matth420 | 2:566244a93a7a | 666 | pc.printf("---------- L'animal vient de l'interieur ---------\r\n"); |
matth420 | 2:566244a93a7a | 667 | pc.printf("---------- Le TAG numero 5 est detecte -----------\r\n"); |
matth420 | 2:566244a93a7a | 668 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 2:566244a93a7a | 669 | SendCMD(); |
matth420 | 2:566244a93a7a | 670 | timeout=3; |
matth420 | 2:566244a93a7a | 671 | getreply(); |
matth420 | 2:566244a93a7a | 672 | pc.printf(buf); |
matth420 | 2:566244a93a7a | 673 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 2:566244a93a7a | 674 | SendCMD(); |
matth420 | 2:566244a93a7a | 675 | timeout=3; |
matth420 | 2:566244a93a7a | 676 | getreply(); |
matth420 | 2:566244a93a7a | 677 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 2:566244a93a7a | 678 | if (F411==1) |
matth420 | 2:566244a93a7a | 679 | { //Vérification alimentation servo par F411 |
matth420 | 2:566244a93a7a | 680 | pc.printf("++++++++ Deblocage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 681 | myservo = pos2 ; //Position du servomoteur n°2 (ouvert) |
matth420 | 2:566244a93a7a | 682 | wait(1); |
matth420 | 2:566244a93a7a | 683 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 684 | { |
matth420 | 2:566244a93a7a | 685 | led2=1; |
matth420 | 2:566244a93a7a | 686 | } |
matth420 | 2:566244a93a7a | 687 | led2=0; |
matth420 | 2:566244a93a7a | 688 | pc.printf("++++++++ Passage de l'animal ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 689 | wait(2); |
matth420 | 2:566244a93a7a | 690 | while(capteurfermeture==0) |
matth420 | 2:566244a93a7a | 691 | { |
matth420 | 2:566244a93a7a | 692 | led2=1; |
matth420 | 2:566244a93a7a | 693 | } |
matth420 | 2:566244a93a7a | 694 | wait(1); |
matth420 | 2:566244a93a7a | 695 | pc.printf("++++++++ Verrouillage de la chatiere ++++++++\r\n"); |
matth420 | 2:566244a93a7a | 696 | myservo=pos3; //Position du servomoteur n°3(bloqué) |
matth420 | 2:566244a93a7a | 697 | position = 3; |
matth420 | 2:566244a93a7a | 698 | } |
matth420 | 2:566244a93a7a | 699 | else |
matth420 | 2:566244a93a7a | 700 | { |
matth420 | 2:566244a93a7a | 701 | pc.printf("++++++++ L'animal n'est pas autorise a sortir ++++++++\n\r"); |
matth420 | 2:566244a93a7a | 702 | } |
matth420 | 2:566244a93a7a | 703 | } |
matth420 | 2:566244a93a7a | 704 | |
matth420 | 2:566244a93a7a | 705 | while(bpmanuel ==1 ) |
matth420 | 2:566244a93a7a | 706 | { //Activation du mode manuel |
matth420 | 2:566244a93a7a | 707 | if(pass==0) |
matth420 | 2:566244a93a7a | 708 | { |
matth420 | 2:566244a93a7a | 709 | pc.printf("\r------------------- Le mode manuel est actif ---------------------\r\n\n"); |
matth420 | 2:566244a93a7a | 710 | pass = 1 ; |
matth420 | 2:566244a93a7a | 711 | } |
matth420 | 2:566244a93a7a | 712 | pass5 = 0; |
matth420 | 2:566244a93a7a | 713 | ledmm = 1 ; //Allumage Led indiquant que le mode manuel est activé |
matth420 | 2:566244a93a7a | 714 | if (manuel1==1) |
matth420 | 2:566244a93a7a | 715 | { |
matth420 | 2:566244a93a7a | 716 | position = 1; |
matth420 | 2:566244a93a7a | 717 | } |
matth420 | 2:566244a93a7a | 718 | if (manuel2==1) |
matth420 | 2:566244a93a7a | 719 | { |
matth420 | 2:566244a93a7a | 720 | position = 2; |
matth420 | 2:566244a93a7a | 721 | } |
matth420 | 2:566244a93a7a | 722 | if (manuel3==1) |
matth420 | 2:566244a93a7a | 723 | { |
matth420 | 2:566244a93a7a | 724 | position = 3; |
matth420 | 2:566244a93a7a | 725 | } |
matth420 | 2:566244a93a7a | 726 | switch(position) //Switch en fonction de la position de la chatière pour le mode manuel |
matth420 | 2:566244a93a7a | 727 | { |
matth420 | 2:566244a93a7a | 728 | case 1 : //Mode manuel position n°1 (entrée seulement) |
matth420 | 2:566244a93a7a | 729 | pass2=0; |
matth420 | 2:566244a93a7a | 730 | pass3=0; |
matth420 | 2:566244a93a7a | 731 | if(capteurfermeture==1) //Vérification de la fermeture de la chatière |
matth420 | 2:566244a93a7a | 732 | { |
matth420 | 2:566244a93a7a | 733 | myservo = pos1 ; //Position du servomoteur n°1 |
matth420 | 2:566244a93a7a | 734 | position = 1; //La chatière est en position n°1 (entrée seulement) |
matth420 | 2:566244a93a7a | 735 | if(pass1==0) |
matth420 | 2:566244a93a7a | 736 | { |
matth420 | 2:566244a93a7a | 737 | pc.printf("++++++++ La chatiere est en position numero 1 : entree seulement +++++++\r\n\n"); |
matth420 | 2:566244a93a7a | 738 | pass1 = 1 ; |
matth420 | 2:566244a93a7a | 739 | }} |
matth420 | 2:566244a93a7a | 740 | break; //Fin du case n°1 |
matth420 | 2:566244a93a7a | 741 | case 2 : //Mode manuel position n°2 (entréé ou sortie) |
matth420 | 2:566244a93a7a | 742 | pass1=0; |
matth420 | 2:566244a93a7a | 743 | pass3=0; |
matth420 | 2:566244a93a7a | 744 | if(capteurfermeture==1) //Vérification de la fermeture de la chatière |
matth420 | 2:566244a93a7a | 745 | { |
matth420 | 2:566244a93a7a | 746 | myservo = pos2 ; //Position du servomoteur n°2 |
matth420 | 2:566244a93a7a | 747 | position = 2; //La chatière est en position n°2 (entréé ou sortie) |
matth420 | 2:566244a93a7a | 748 | if(pass2==0) |
matth420 | 2:566244a93a7a | 749 | { |
matth420 | 2:566244a93a7a | 750 | pc.printf("++++++++ La chatiere est en position numero 2 : ouverte ++++++++\r\n\n"); |
matth420 | 2:566244a93a7a | 751 | pass2 = 1; |
matth420 | 2:566244a93a7a | 752 | }} |
matth420 | 2:566244a93a7a | 753 | break; //Fin du case n°2 |
matth420 | 2:566244a93a7a | 754 | case 3 : //Mode manuel position n°3 (verrouillage complet) |
matth420 | 2:566244a93a7a | 755 | pass1=0; |
matth420 | 2:566244a93a7a | 756 | pass2=0; |
matth420 | 2:566244a93a7a | 757 | if(capteurfermeture==1) //Vérification de la fermeture de la chatière |
matth420 | 2:566244a93a7a | 758 | { |
matth420 | 2:566244a93a7a | 759 | myservo = pos3 ; //Position du servomoteur n°3 |
matth420 | 2:566244a93a7a | 760 | position = 3; //La chatière est en position n°3 (verrouillage complet) |
matth420 | 2:566244a93a7a | 761 | if(pass3==0) |
matth420 | 2:566244a93a7a | 762 | { |
matth420 | 2:566244a93a7a | 763 | pc.printf("++++++++ La chatiere est en position numero 3 : verouillage complet ++++++++\r\n\n"); |
matth420 | 2:566244a93a7a | 764 | pass3 = 1 ; |
matth420 | 2:566244a93a7a | 765 | }} //Fin du case n°3 |
matth420 | 2:566244a93a7a | 766 | break; |
matth420 | 2:566244a93a7a | 767 | default : |
matth420 | 2:566244a93a7a | 768 | } //Fin du switch |
matth420 | 2:566244a93a7a | 769 | } //Fin du mode manuel |
matth420 | 2:566244a93a7a | 770 | if(pass5==0) |
matth420 | 2:566244a93a7a | 771 | { |
matth420 | 2:566244a93a7a | 772 | pc.printf("-------------------- Le mode manuel est inactif -----------------\r\n\n"); |
matth420 | 2:566244a93a7a | 773 | pc.printf("-------------------- La chatiere est verrouillee ----------------\r\n\n"); |
matth420 | 2:566244a93a7a | 774 | pass5=1; |
matth420 | 2:566244a93a7a | 775 | } |
matth420 | 2:566244a93a7a | 776 | pass = 0 ; |
matth420 | 2:566244a93a7a | 777 | |
matth420 | 2:566244a93a7a | 778 | pass5 = 1 ; |
matth420 | 2:566244a93a7a | 779 | myservo=pos3; |
matth420 | 2:566244a93a7a | 780 | }} //Fin du int main |
matth420 | 1:ca1ad3dc37b3 | 781 | //+++++++++++++++++++++++++++++ Voids RFID +++++++++++++++++++++++++++++ |
matth420 | 0:d811d2c0da76 | 782 | |
matth420 | 0:d811d2c0da76 | 783 | void Antenna() |
matth420 | 0:d811d2c0da76 | 784 | { |
matth420 | 0:d811d2c0da76 | 785 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 786 | pc.printf("ANTENNA NOT DETECTED"); |
matth420 | 0:d811d2c0da76 | 787 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 788 | } |
matth420 | 0:d811d2c0da76 | 789 | |
matth420 | 0:d811d2c0da76 | 790 | void field() |
matth420 | 0:d811d2c0da76 | 791 | { |
matth420 | 0:d811d2c0da76 | 792 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 793 | pc.printf("NOT TAG IN FIELD"); |
matth420 | 0:d811d2c0da76 | 794 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 795 | } |
matth420 | 0:d811d2c0da76 | 796 | |
matth420 | 0:d811d2c0da76 | 797 | // +++++++++++++++++++++++++++++++++ This is for ESP8266 config only, run this once to set up the ESP8266 +++++++++++++++ |
matth420 | 0:d811d2c0da76 | 798 | void ESPconfig() |
matth420 | 0:d811d2c0da76 | 799 | { |
matth420 | 2:566244a93a7a | 800 | wait(2); |
matth420 | 0:d811d2c0da76 | 801 | strcpy(snd,"AT\r\n"); |
matth420 | 0:d811d2c0da76 | 802 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 803 | timeout=1; |
matth420 | 0:d811d2c0da76 | 804 | getreply(); |
matth420 | 0:d811d2c0da76 | 805 | wait(1); |
matth420 | 0:d811d2c0da76 | 806 | pc.printf("-------------- Redemarrage du module --------------\r\n"); //Redémarrage du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 807 | strcpy(snd,"AT+RST\r\n"); //Commande redémarrage du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 808 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 809 | timeout=5; |
matth420 | 0:d811d2c0da76 | 810 | getreply(); |
matth420 | 0:d811d2c0da76 | 811 | pc.printf(buf); |
matth420 | 0:d811d2c0da76 | 812 | |
matth420 | 2:566244a93a7a | 813 | wait(2); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 814 | |
matth420 | 0:d811d2c0da76 | 815 | pc.printf("\n---------- Mode Wifi ----------\r\n"); //Initialisation du mode WIFI |
matth420 | 0:d811d2c0da76 | 816 | strcpy(snd, "AT+CWMODE=3\r\n"); //Commande initialisation du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 817 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 818 | timeout=4; |
matth420 | 0:d811d2c0da76 | 819 | getreply(); |
matth420 | 0:d811d2c0da76 | 820 | pc.printf(buf); |
matth420 | 0:d811d2c0da76 | 821 | |
matth420 | 2:566244a93a7a | 822 | wait(1); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 823 | |
matth420 | 0:d811d2c0da76 | 824 | pc.printf("\n---------- Connexion au point d acces ----------\r\n"); //Connection au serveur IOP |
matth420 | 0:d811d2c0da76 | 825 | pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd); |
matth420 | 0:d811d2c0da76 | 826 | strcpy(snd, "AT+CWJAP=\""); //Commande de connection au serveur IOP |
matth420 | 0:d811d2c0da76 | 827 | strcat(snd, ssid); |
matth420 | 0:d811d2c0da76 | 828 | strcat(snd, "\",\""); |
matth420 | 0:d811d2c0da76 | 829 | strcat(snd, pwd); |
matth420 | 0:d811d2c0da76 | 830 | strcat(snd, "\"\r\n"); |
matth420 | 0:d811d2c0da76 | 831 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 832 | timeout=10; |
matth420 | 0:d811d2c0da76 | 833 | getreply(); |
matth420 | 0:d811d2c0da76 | 834 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 0:d811d2c0da76 | 835 | |
matth420 | 1:ca1ad3dc37b3 | 836 | wait(2); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 837 | |
matth420 | 0:d811d2c0da76 | 838 | pc.printf("\n---------- Adresse IP local ----------\r\n"); //Adressage IP |
matth420 | 0:d811d2c0da76 | 839 | strcpy(snd, "AT+CIFSR\r\n"); //Commande affichant adresse IP et MAC du PC ainsi que du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 840 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 841 | timeout=3; |
matth420 | 0:d811d2c0da76 | 842 | getreply(); |
matth420 | 0:d811d2c0da76 | 843 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 0:d811d2c0da76 | 844 | |
matth420 | 2:566244a93a7a | 845 | wait(2); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 846 | |
matth420 | 0:d811d2c0da76 | 847 | pc.printf("\n---------- TCP Client ----------\r\n"); //Connection au serveur en tant que client |
matth420 | 1:ca1ad3dc37b3 | 848 | strcpy(snd, "AT+CIPSTART=\"TCP\",\"192.168.2.1\",55555\r\n"); //Commande connection au serveur : Protocol , Adresse IP serveur , port |
matth420 | 0:d811d2c0da76 | 849 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 850 | timeout=5; |
matth420 | 0:d811d2c0da76 | 851 | getreply(); |
matth420 | 0:d811d2c0da76 | 852 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 1:ca1ad3dc37b3 | 853 | |
matth420 | 2:566244a93a7a | 854 | wait(2); //Délai inter-étape |
matth420 | 1:ca1ad3dc37b3 | 855 | |
matth420 | 1:ca1ad3dc37b3 | 856 | |
matth420 | 0:d811d2c0da76 | 857 | } //Fin du void config |
matth420 | 0:d811d2c0da76 | 858 | |
matth420 | 0:d811d2c0da76 | 859 | void SendCMD() |
matth420 | 0:d811d2c0da76 | 860 | { |
matth420 | 0:d811d2c0da76 | 861 | esp.printf("%s", snd); |
matth420 | 1:ca1ad3dc37b3 | 862 | } |
matth420 | 0:d811d2c0da76 | 863 | |
matth420 | 0:d811d2c0da76 | 864 | void getreply() |
matth420 | 0:d811d2c0da76 | 865 | { |
matth420 | 0:d811d2c0da76 | 866 | memset(buf, '\0', sizeof(buf)); |
matth420 | 0:d811d2c0da76 | 867 | t.start(); |
matth420 | 0:d811d2c0da76 | 868 | ended=0; |
matth420 | 0:d811d2c0da76 | 869 | count=0; |
matth420 | 0:d811d2c0da76 | 870 | while(!ended) { |
matth420 | 0:d811d2c0da76 | 871 | if(esp.readable()) { |
matth420 | 0:d811d2c0da76 | 872 | buf[count] = esp.getc(); |
matth420 | 0:d811d2c0da76 | 873 | count++; |
matth420 | 0:d811d2c0da76 | 874 | } |
matth420 | 0:d811d2c0da76 | 875 | if(t.read() > timeout) { |
matth420 | 0:d811d2c0da76 | 876 | ended = 1; |
matth420 | 0:d811d2c0da76 | 877 | t.stop(); |
matth420 | 0:d811d2c0da76 | 878 | t.reset(); |
matth420 | 0:d811d2c0da76 | 879 | } |
matth420 | 0:d811d2c0da76 | 880 | } |
matth420 | 0:d811d2c0da76 | 881 | } |