programme intégré
Dependencies: MODSERIAL Servo mbed
main.cpp@1:ca1ad3dc37b3, 2018-05-30 (annotated)
- Committer:
- matth420
- Date:
- Wed May 30 21:46:48 2018 +0000
- Revision:
- 1:ca1ad3dc37b3
- Parent:
- 0:d811d2c0da76
- Child:
- 2:566244a93a7a
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 | 0:d811d2c0da76 | 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 | 0:d811d2c0da76 | 14 | DigitalOut reset(p26); |
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 | 1:ca1ad3dc37b3 | 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 | 0:d811d2c0da76 | 20 | DigitalIn manuel3 (p17); //Mode manuel position n°3 (entréé ou sortie) |
matth420 | 0:d811d2c0da76 | 21 | DigitalIn manuel4 (p16); //Mode manuel position n°4 (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 | 0:d811d2c0da76 | 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 | 1:ca1ad3dc37b3 | 51 | float pos3 = 0.001 ; //Position n°3 (complétement ouvert) |
matth420 | 1:ca1ad3dc37b3 | 52 | float pos4 = 0.42 ; //Position n°4 (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 | 0:d811d2c0da76 | 58 | |
matth420 | 0:d811d2c0da76 | 59 | char buf[1024]; |
matth420 | 0:d811d2c0da76 | 60 | char snd[255]; |
matth420 | 0:d811d2c0da76 | 61 | |
matth420 | 0:d811d2c0da76 | 62 | char ssid[32] = "IOP_LEGRAND_2"; //Nom du WIFI IOP |
matth420 | 0:d811d2c0da76 | 63 | char pwd [32] = "legrandMDP"; //Mot de passe du WIFI IOP |
matth420 | 0:d811d2c0da76 | 64 | |
matth420 | 0:d811d2c0da76 | 65 | char ECHA[5] = "ECHA"; //Le chat vient de l'extérieur |
matth420 | 0:d811d2c0da76 | 66 | char ICHA[5] = "ICHA"; //Le chat vient de l'intérieur |
matth420 | 0:d811d2c0da76 | 67 | |
matth420 | 0:d811d2c0da76 | 68 | |
matth420 | 1:ca1ad3dc37b3 | 69 | char tcpip[14] = "192.168.1.42"; //Adresse IP du module ESP8666 |
matth420 | 0:d811d2c0da76 | 70 | char tcpport[3] = "23"; |
matth420 | 0:d811d2c0da76 | 71 | |
matth420 | 1:ca1ad3dc37b3 | 72 | int longueur_recue = 0; |
matth420 | 0:d811d2c0da76 | 73 | int nouvelle_reception = 0; |
matth420 | 0:d811d2c0da76 | 74 | int a = 0; |
matth420 | 0:d811d2c0da76 | 75 | int b = 0; |
matth420 | 0:d811d2c0da76 | 76 | |
matth420 | 0:d811d2c0da76 | 77 | char recept[18]; |
matth420 | 0:d811d2c0da76 | 78 | char tabconnect[10] = {0}; |
matth420 | 0:d811d2c0da76 | 79 | char tabclosed[9] = {0}; |
matth420 | 0:d811d2c0da76 | 80 | char tabrec[5] = {0}; |
matth420 | 0:d811d2c0da76 | 81 | char connect[10] = "0,CONNECT"; |
matth420 | 0:d811d2c0da76 | 82 | char closed[9] = "0,CLOSED"; |
matth420 | 0:d811d2c0da76 | 83 | |
matth420 | 1:ca1ad3dc37b3 | 84 | int drapeau = 1; |
matth420 | 1:ca1ad3dc37b3 | 85 | |
matth420 | 0:d811d2c0da76 | 86 | void HandShake(); |
matth420 | 0:d811d2c0da76 | 87 | void Antenna(); |
matth420 | 0:d811d2c0da76 | 88 | void field(); |
matth420 | 1:ca1ad3dc37b3 | 89 | void SendCMD(),getreply(),ESPconfig(),ESPsetbaudrate(),WIFI(), Donnee(); //Déclaration des voids |
matth420 | 0:d811d2c0da76 | 90 | |
matth420 | 0:d811d2c0da76 | 91 | using namespace std; |
matth420 | 0:d811d2c0da76 | 92 | |
matth420 | 0:d811d2c0da76 | 93 | int main() //Début du int main |
matth420 | 0:d811d2c0da76 | 94 | { |
matth420 | 1:ca1ad3dc37b3 | 95 | ledmm = 0; |
matth420 | 1:ca1ad3dc37b3 | 96 | myservo = 0.001 ; //La chatière est fermé |
matth420 | 1:ca1ad3dc37b3 | 97 | wait_ms(200); |
matth420 | 1:ca1ad3dc37b3 | 98 | |
matth420 | 0:d811d2c0da76 | 99 | reset=0; //Reset du module ESP8266 |
matth420 | 0:d811d2c0da76 | 100 | pc.baud(9600); //Vitesse de transmission du terminal |
matth420 | 0:d811d2c0da76 | 101 | pc.printf("\f\n\r--------------- Demarrage du module WIFI ---------------\n\r"); //Démarrage du module WIFI ESP8266 |
matth420 | 1:ca1ad3dc37b3 | 102 | wait(0.25); |
matth420 | 0:d811d2c0da76 | 103 | reset=1; |
matth420 | 0:d811d2c0da76 | 104 | timeout=2; |
matth420 | 0:d811d2c0da76 | 105 | getreply(); |
matth420 | 0:d811d2c0da76 | 106 | |
matth420 | 0:d811d2c0da76 | 107 | esp.baud(115200); //Vitesse de transmission du module WIFI ESP8266 |
matth420 | 1:ca1ad3dc37b3 | 108 | |
matth420 | 0:d811d2c0da76 | 109 | ESPconfig(); //Configuration du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 110 | |
matth420 | 0:d811d2c0da76 | 111 | pc.printf("\f\n\r- Module pret -\n\r"); //Le module WIFI ESP8266 |
matth420 | 1:ca1ad3dc37b3 | 112 | |
matth420 | 1:ca1ad3dc37b3 | 113 | while(1) { |
matth420 | 1:ca1ad3dc37b3 | 114 | // Partie RFID |
matth420 | 1:ca1ad3dc37b3 | 115 | led4=1; |
matth420 | 1:ca1ad3dc37b3 | 116 | ledmm = 0; |
matth420 | 1:ca1ad3dc37b3 | 117 | egal1=0; |
matth420 | 1:ca1ad3dc37b3 | 118 | egal2=0; |
matth420 | 1:ca1ad3dc37b3 | 119 | egal3=0; |
matth420 | 1:ca1ad3dc37b3 | 120 | egal4=0; |
matth420 | 1:ca1ad3dc37b3 | 121 | egal5=0; |
matth420 | 0:d811d2c0da76 | 122 | |
matth420 | 1:ca1ad3dc37b3 | 123 | |
matth420 | 0:d811d2c0da76 | 124 | |
matth420 | 1:ca1ad3dc37b3 | 125 | if (CTS == 0) { |
matth420 | 1:ca1ad3dc37b3 | 126 | led4=0; |
matth420 | 1:ca1ad3dc37b3 | 127 | led2=1; |
matth420 | 1:ca1ad3dc37b3 | 128 | |
matth420 | 1:ca1ad3dc37b3 | 129 | for (int i=0; i<2; i++) { |
matth420 | 0:d811d2c0da76 | 130 | rfid2.putc(lireuid[i]); |
matth420 | 0:d811d2c0da76 | 131 | } |
matth420 | 0:d811d2c0da76 | 132 | wait_ms(25); |
matth420 | 1:ca1ad3dc37b3 | 133 | for (int e=0; e<1; e++) { |
matth420 | 0:d811d2c0da76 | 134 | reponse_rfid1[e]=(rfid1.getc()); |
matth420 | 0:d811d2c0da76 | 135 | led1=1; |
matth420 | 0:d811d2c0da76 | 136 | } |
matth420 | 1:ca1ad3dc37b3 | 137 | if (reponse_rfid1[0] == 0xD6) { |
matth420 | 1:ca1ad3dc37b3 | 138 | for (int i=0; i<2; i++) { |
matth420 | 0:d811d2c0da76 | 139 | rfid2.putc(lireuid[i]); |
matth420 | 0:d811d2c0da76 | 140 | led2=1; |
matth420 | 0:d811d2c0da76 | 141 | } |
matth420 | 0:d811d2c0da76 | 142 | wait_ms(50); |
matth420 | 0:d811d2c0da76 | 143 | for (int e=1; e<5; e++) { |
matth420 | 0:d811d2c0da76 | 144 | reponse_rfid[e]=(rfid1.getc()); |
matth420 | 0:d811d2c0da76 | 145 | led3=1; |
matth420 | 0:d811d2c0da76 | 146 | } |
matth420 | 1:ca1ad3dc37b3 | 147 | |
matth420 | 0:d811d2c0da76 | 148 | pc.printf("---------------------------------------"); |
matth420 | 0:d811d2c0da76 | 149 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 150 | pc.printf("Trame de reponse du PCB en hexa : "); |
matth420 | 0:d811d2c0da76 | 151 | for (int i=0; i<2; i++) pc.printf("%X ",lireuid[i]); |
matth420 | 0:d811d2c0da76 | 152 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 153 | pc.printf("Status = %X\n\r",reponse_rfid1[0]); |
matth420 | 0:d811d2c0da76 | 154 | pc.printf("UID = "); |
matth420 | 0:d811d2c0da76 | 155 | for (int i=1; i<5; i++) pc.printf("%X ",reponse_rfid[i]); |
matth420 | 0:d811d2c0da76 | 156 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 157 | pc.printf("---------------------------------------"); |
matth420 | 0:d811d2c0da76 | 158 | pc.printf("\n\r"); |
matth420 | 1:ca1ad3dc37b3 | 159 | } else if (reponse_rfid1[0] == 0xC0) { |
matth420 | 0:d811d2c0da76 | 160 | field(); |
matth420 | 0:d811d2c0da76 | 161 | } |
matth420 | 1:ca1ad3dc37b3 | 162 | if (reponse_rfid1[0] == 0xE0) { |
matth420 | 0:d811d2c0da76 | 163 | Antenna(); |
matth420 | 0:d811d2c0da76 | 164 | } |
matth420 | 1:ca1ad3dc37b3 | 165 | for(int i=1; i<5; i++) { |
matth420 | 0:d811d2c0da76 | 166 | tag[i-1] = reponse_rfid[i]; |
matth420 | 0:d811d2c0da76 | 167 | } |
matth420 | 1:ca1ad3dc37b3 | 168 | if(tag[0] != 0x00) { |
matth420 | 0:d811d2c0da76 | 169 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 170 | pc.printf("tableau de 0: %X", tag[0]); |
matth420 | 0:d811d2c0da76 | 171 | pc.printf("\n\r"); |
matth420 | 1:ca1ad3dc37b3 | 172 | |
matth420 | 1:ca1ad3dc37b3 | 173 | for(int i=0; i<4; i++) { |
matth420 | 1:ca1ad3dc37b3 | 174 | if(tag[i] == tag1[i]) { |
matth420 | 0:d811d2c0da76 | 175 | egal1 = 1; |
matth420 | 0:d811d2c0da76 | 176 | pc.printf("Tag1 - OK "); |
matth420 | 0:d811d2c0da76 | 177 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 178 | break; |
matth420 | 0:d811d2c0da76 | 179 | //pc.printf(tag[i]); |
matth420 | 1:ca1ad3dc37b3 | 180 | } else if(tag[i] != tag1[i]) { |
matth420 | 0:d811d2c0da76 | 181 | pc.printf("Tag1 - NOK "); |
matth420 | 0:d811d2c0da76 | 182 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 183 | egal1 = 0; |
matth420 | 0:d811d2c0da76 | 184 | break; |
matth420 | 0:d811d2c0da76 | 185 | //pc.printf(tag[i]); |
matth420 | 0:d811d2c0da76 | 186 | } |
matth420 | 0:d811d2c0da76 | 187 | } |
matth420 | 1:ca1ad3dc37b3 | 188 | for(int i=0; i<4; i++) { |
matth420 | 1:ca1ad3dc37b3 | 189 | if(tag[i] == tag2[i]) { |
matth420 | 0:d811d2c0da76 | 190 | egal2 = 1; |
matth420 | 0:d811d2c0da76 | 191 | pc.printf("Tag2 - OK "); |
matth420 | 0:d811d2c0da76 | 192 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 193 | break; |
matth420 | 0:d811d2c0da76 | 194 | //pc.printf(tag[i]); |
matth420 | 1:ca1ad3dc37b3 | 195 | } else if(tag[i] != tag2[i]) { |
matth420 | 0:d811d2c0da76 | 196 | pc.printf("Tag2 - NOK "); |
matth420 | 0:d811d2c0da76 | 197 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 198 | egal2 = 0; |
matth420 | 0:d811d2c0da76 | 199 | break; |
matth420 | 0:d811d2c0da76 | 200 | //pc.printf(tag[i]); |
matth420 | 0:d811d2c0da76 | 201 | } |
matth420 | 0:d811d2c0da76 | 202 | } |
matth420 | 1:ca1ad3dc37b3 | 203 | for(int i=0; i<4; i++) { |
matth420 | 1:ca1ad3dc37b3 | 204 | if(tag[i] == tag3[i]) { |
matth420 | 0:d811d2c0da76 | 205 | egal3 = 1; |
matth420 | 0:d811d2c0da76 | 206 | pc.printf("Tag3 - OK "); |
matth420 | 0:d811d2c0da76 | 207 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 208 | break; |
matth420 | 0:d811d2c0da76 | 209 | //pc.printf(tag[i]); |
matth420 | 1:ca1ad3dc37b3 | 210 | } else if(tag[i] != tag3[i]) { |
matth420 | 0:d811d2c0da76 | 211 | pc.printf("Tag3 - NOK "); |
matth420 | 0:d811d2c0da76 | 212 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 213 | egal3 = 0; |
matth420 | 0:d811d2c0da76 | 214 | break; |
matth420 | 0:d811d2c0da76 | 215 | //pc.printf(tag[i]); |
matth420 | 0:d811d2c0da76 | 216 | } |
matth420 | 0:d811d2c0da76 | 217 | } |
matth420 | 1:ca1ad3dc37b3 | 218 | for(int i=0; i<4; i++) { |
matth420 | 1:ca1ad3dc37b3 | 219 | if(tag[i] == tag4[i]) { |
matth420 | 0:d811d2c0da76 | 220 | egal4 = 1; |
matth420 | 0:d811d2c0da76 | 221 | pc.printf("Tag4 - OK "); |
matth420 | 0:d811d2c0da76 | 222 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 223 | break; |
matth420 | 0:d811d2c0da76 | 224 | //pc.printf(tag[i]); |
matth420 | 1:ca1ad3dc37b3 | 225 | } else if(tag[i] != tag4[i]) { |
matth420 | 0:d811d2c0da76 | 226 | pc.printf("Tag4 - NOK "); |
matth420 | 0:d811d2c0da76 | 227 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 228 | egal4 = 0; |
matth420 | 0:d811d2c0da76 | 229 | break; |
matth420 | 0:d811d2c0da76 | 230 | //pc.printf(tag[i]); |
matth420 | 0:d811d2c0da76 | 231 | } |
matth420 | 0:d811d2c0da76 | 232 | } |
matth420 | 1:ca1ad3dc37b3 | 233 | for(int i=0; i<4; i++) { |
matth420 | 1:ca1ad3dc37b3 | 234 | if(tag[i] == tag5[i]) { |
matth420 | 0:d811d2c0da76 | 235 | egal5 = 1; |
matth420 | 0:d811d2c0da76 | 236 | pc.printf("Tag5 - OK "); |
matth420 | 0:d811d2c0da76 | 237 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 238 | break; |
matth420 | 0:d811d2c0da76 | 239 | //pc.printf(tag[i]); |
matth420 | 1:ca1ad3dc37b3 | 240 | } else if(tag[i] != tag5[i]) { |
matth420 | 0:d811d2c0da76 | 241 | pc.printf("Tag5 - NOK "); |
matth420 | 0:d811d2c0da76 | 242 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 243 | egal5 = 0; |
matth420 | 0:d811d2c0da76 | 244 | break; |
matth420 | 0:d811d2c0da76 | 245 | //pc.printf(tag[i]); |
matth420 | 1:ca1ad3dc37b3 | 246 | } |
matth420 | 0:d811d2c0da76 | 247 | } |
matth420 | 1:ca1ad3dc37b3 | 248 | reponse_rfid[1]=0x00; |
matth420 | 0:d811d2c0da76 | 249 | } |
matth420 | 0:d811d2c0da76 | 250 | |
matth420 | 0:d811d2c0da76 | 251 | led1=0; |
matth420 | 0:d811d2c0da76 | 252 | led2=0; |
matth420 | 1:ca1ad3dc37b3 | 253 | led3=1; |
matth420 | 0:d811d2c0da76 | 254 | |
matth420 | 0:d811d2c0da76 | 255 | wait_ms(500); |
matth420 | 1:ca1ad3dc37b3 | 256 | |
matth420 | 1:ca1ad3dc37b3 | 257 | } |
matth420 | 1:ca1ad3dc37b3 | 258 | |
matth420 | 1:ca1ad3dc37b3 | 259 | |
matth420 | 1:ca1ad3dc37b3 | 260 | if(capext ==1 && egal1 ==1) { //Si le capteur extérieur est à 1 & le TAG 1 est détecté |
matth420 | 1:ca1ad3dc37b3 | 261 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 1:ca1ad3dc37b3 | 262 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 1:ca1ad3dc37b3 | 263 | SendCMD(); |
matth420 | 1:ca1ad3dc37b3 | 264 | timeout=5; |
matth420 | 1:ca1ad3dc37b3 | 265 | getreply(); |
matth420 | 1:ca1ad3dc37b3 | 266 | pc.printf(buf); |
matth420 | 1:ca1ad3dc37b3 | 267 | strcpy(snd, "ECHA\r\n"); //Le chat vient de l'extérieur |
matth420 | 1:ca1ad3dc37b3 | 268 | SendCMD(); |
matth420 | 1:ca1ad3dc37b3 | 269 | timeout=5; |
matth420 | 1:ca1ad3dc37b3 | 270 | getreply(); |
matth420 | 1:ca1ad3dc37b3 | 271 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 1:ca1ad3dc37b3 | 272 | wait(2); |
matth420 | 1:ca1ad3dc37b3 | 273 | if (F411==1) |
matth420 | 1:ca1ad3dc37b3 | 274 | { //Vérification alimentation servo par F411 |
matth420 | 1:ca1ad3dc37b3 | 275 | myservo = 0.42 ; //Position du servomoteur n°3 (ouvert) |
matth420 | 1:ca1ad3dc37b3 | 276 | wait(5); |
matth420 | 1:ca1ad3dc37b3 | 277 | while(capteurfermeture==0) |
matth420 | 1:ca1ad3dc37b3 | 278 | { |
matth420 | 1:ca1ad3dc37b3 | 279 | led2=1; |
matth420 | 1:ca1ad3dc37b3 | 280 | } |
matth420 | 1:ca1ad3dc37b3 | 281 | led2=0; |
matth420 | 1:ca1ad3dc37b3 | 282 | wait(2); |
matth420 | 1:ca1ad3dc37b3 | 283 | myservo=0.001; |
matth420 | 1:ca1ad3dc37b3 | 284 | position = 4; |
matth420 | 1:ca1ad3dc37b3 | 285 | } |
matth420 | 1:ca1ad3dc37b3 | 286 | } |
matth420 | 1:ca1ad3dc37b3 | 287 | |
matth420 | 1:ca1ad3dc37b3 | 288 | myservo = 0.001 ; //La chatière est fermé |
matth420 | 1:ca1ad3dc37b3 | 289 | position = 4; |
matth420 | 1:ca1ad3dc37b3 | 290 | |
matth420 | 1:ca1ad3dc37b3 | 291 | } |
matth420 | 1:ca1ad3dc37b3 | 292 | |
matth420 | 0:d811d2c0da76 | 293 | |
matth420 | 0:d811d2c0da76 | 294 | |
matth420 | 1:ca1ad3dc37b3 | 295 | |
matth420 | 1:ca1ad3dc37b3 | 296 | if(capint ==1 && egal1 ==1) //Si le capteur intérieur est à 1 & le TAG 1 est détecté |
matth420 | 1:ca1ad3dc37b3 | 297 | { |
matth420 | 0:d811d2c0da76 | 298 | pc.printf("---------- Envoi de donnees au serveur ----------\r\n"); //Envoi de données au serveur |
matth420 | 0:d811d2c0da76 | 299 | strcpy(snd, "AT+CIPSEND=4\r\n"); //Commande envoyant le nombre de bytes voulu |
matth420 | 0:d811d2c0da76 | 300 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 301 | timeout=5; |
matth420 | 0:d811d2c0da76 | 302 | getreply(); |
matth420 | 0:d811d2c0da76 | 303 | pc.printf(buf); |
matth420 | 1:ca1ad3dc37b3 | 304 | strcpy(snd, "ICHA\r\n"); //Le chat vient de l'intérieur |
matth420 | 0:d811d2c0da76 | 305 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 306 | timeout=5; |
matth420 | 0:d811d2c0da76 | 307 | getreply(); |
matth420 | 0:d811d2c0da76 | 308 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 1:ca1ad3dc37b3 | 309 | wait(2); |
matth420 | 1:ca1ad3dc37b3 | 310 | if (F411 ==1) |
matth420 | 1:ca1ad3dc37b3 | 311 | { //Vérification alimentation servo par F411 (MyHome) |
matth420 | 1:ca1ad3dc37b3 | 312 | myservo = 0.42 ; //Position du servomoteur n°3 (ouvert) |
matth420 | 1:ca1ad3dc37b3 | 313 | wait(5) ; |
matth420 | 1:ca1ad3dc37b3 | 314 | while(capteurfermeture==0) |
matth420 | 0:d811d2c0da76 | 315 | { |
matth420 | 1:ca1ad3dc37b3 | 316 | led3=1; |
matth420 | 1:ca1ad3dc37b3 | 317 | } |
matth420 | 1:ca1ad3dc37b3 | 318 | led3=0; |
matth420 | 1:ca1ad3dc37b3 | 319 | wait(2); |
matth420 | 1:ca1ad3dc37b3 | 320 | myservo = 0.001 ; //La chatière est fermé |
matth420 | 1:ca1ad3dc37b3 | 321 | position=4; |
matth420 | 1:ca1ad3dc37b3 | 322 | } |
matth420 | 1:ca1ad3dc37b3 | 323 | } |
matth420 | 1:ca1ad3dc37b3 | 324 | |
matth420 | 1:ca1ad3dc37b3 | 325 | |
matth420 | 1:ca1ad3dc37b3 | 326 | |
matth420 | 1:ca1ad3dc37b3 | 327 | |
matth420 | 1:ca1ad3dc37b3 | 328 | |
matth420 | 1:ca1ad3dc37b3 | 329 | while(bpmanuel ==1 ) { //Activation du mode manuel |
matth420 | 1:ca1ad3dc37b3 | 330 | ledmm = 1 ; //Allumage Led indiquant que le mode manuel est activé |
matth420 | 1:ca1ad3dc37b3 | 331 | if (manuel1==1){ |
matth420 | 1:ca1ad3dc37b3 | 332 | position = 1; |
matth420 | 0:d811d2c0da76 | 333 | } |
matth420 | 1:ca1ad3dc37b3 | 334 | if (manuel3==1){ |
matth420 | 1:ca1ad3dc37b3 | 335 | position = 3; |
matth420 | 1:ca1ad3dc37b3 | 336 | } |
matth420 | 1:ca1ad3dc37b3 | 337 | if (manuel4==1){ |
matth420 | 1:ca1ad3dc37b3 | 338 | position = 4; |
matth420 | 1:ca1ad3dc37b3 | 339 | } |
matth420 | 1:ca1ad3dc37b3 | 340 | switch(position) { //Switch en fonction de la position de la chatière pour le mode manuel |
matth420 | 1:ca1ad3dc37b3 | 341 | case 1 : //Mode manuel position n°1 (entrée seulement) |
matth420 | 1:ca1ad3dc37b3 | 342 | |
matth420 | 1:ca1ad3dc37b3 | 343 | //Position du servomoteur n°1 |
matth420 | 1:ca1ad3dc37b3 | 344 | if(capteurfermeture==1) { //Vérification de la fermeture de la chatière |
matth420 | 1:ca1ad3dc37b3 | 345 | myservo = pos1 ; |
matth420 | 1:ca1ad3dc37b3 | 346 | position = 1; |
matth420 | 1:ca1ad3dc37b3 | 347 | //La chatière est en position n°1 (entrée seulement) |
matth420 | 1:ca1ad3dc37b3 | 348 | |
matth420 | 0:d811d2c0da76 | 349 | } |
matth420 | 1:ca1ad3dc37b3 | 350 | break; //Fin du case n°1 |
matth420 | 1:ca1ad3dc37b3 | 351 | |
matth420 | 1:ca1ad3dc37b3 | 352 | case 4 : //Mode manuel position n°3 (entréé ou sortie) |
matth420 | 1:ca1ad3dc37b3 | 353 | //Vérification alimentation servo par F411 |
matth420 | 1:ca1ad3dc37b3 | 354 | //Position du servomoteur n°3 |
matth420 | 1:ca1ad3dc37b3 | 355 | if(capteurfermeture==1) { //Vérification de la fermeture de la chatière |
matth420 | 1:ca1ad3dc37b3 | 356 | myservo = pos3 ; |
matth420 | 1:ca1ad3dc37b3 | 357 | position = 3; //La chatière est en position n°3 (entréé ou sortie) |
matth420 | 1:ca1ad3dc37b3 | 358 | |
matth420 | 0:d811d2c0da76 | 359 | } |
matth420 | 1:ca1ad3dc37b3 | 360 | break; //Fin du case n°3 |
matth420 | 1:ca1ad3dc37b3 | 361 | case 3 : //Mode manuel position n°4 (verrouillage complet) |
matth420 | 1:ca1ad3dc37b3 | 362 | //Position du servomoteur n°4 |
matth420 | 1:ca1ad3dc37b3 | 363 | if(capteurfermeture==1) { //Vérification de la fermeture de la chatière |
matth420 | 1:ca1ad3dc37b3 | 364 | myservo = pos4 ; |
matth420 | 1:ca1ad3dc37b3 | 365 | position = 4; //La chatière est en position n°4 (verrouillage complet) |
matth420 | 1:ca1ad3dc37b3 | 366 | |
matth420 | 0:d811d2c0da76 | 367 | } |
matth420 | 0:d811d2c0da76 | 368 | break; //Fin du case n°4 |
matth420 | 1:ca1ad3dc37b3 | 369 | default : //Fin du mode manuel |
matth420 | 1:ca1ad3dc37b3 | 370 | } //Fin du switch |
matth420 | 1:ca1ad3dc37b3 | 371 | } myservo=0.001; |
matth420 | 1:ca1ad3dc37b3 | 372 | |
matth420 | 1:ca1ad3dc37b3 | 373 | //Fin du mode manuel |
matth420 | 1:ca1ad3dc37b3 | 374 | } //Fin du int main |
matth420 | 1:ca1ad3dc37b3 | 375 | //+++++++++++++++++++++++++++++ Voids RFID +++++++++++++++++++++++++++++ |
matth420 | 0:d811d2c0da76 | 376 | /*void HandShake(){ |
matth420 | 0:d811d2c0da76 | 377 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 378 | pc.printf("CTS IS TO 0"); |
matth420 | 0:d811d2c0da76 | 379 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 380 | }*/ |
matth420 | 0:d811d2c0da76 | 381 | |
matth420 | 0:d811d2c0da76 | 382 | void Antenna() |
matth420 | 0:d811d2c0da76 | 383 | { |
matth420 | 0:d811d2c0da76 | 384 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 385 | pc.printf("ANTENNA NOT DETECTED"); |
matth420 | 0:d811d2c0da76 | 386 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 387 | } |
matth420 | 0:d811d2c0da76 | 388 | |
matth420 | 0:d811d2c0da76 | 389 | void field() |
matth420 | 0:d811d2c0da76 | 390 | { |
matth420 | 0:d811d2c0da76 | 391 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 392 | pc.printf("NOT TAG IN FIELD"); |
matth420 | 0:d811d2c0da76 | 393 | pc.printf("\n\r"); |
matth420 | 0:d811d2c0da76 | 394 | } |
matth420 | 0:d811d2c0da76 | 395 | |
matth420 | 0:d811d2c0da76 | 396 | // +++++++++++++++++++++++++++++++++ This is for ESP8266 config only, run this once to set up the ESP8266 +++++++++++++++ |
matth420 | 0:d811d2c0da76 | 397 | void ESPconfig() |
matth420 | 0:d811d2c0da76 | 398 | { |
matth420 | 0:d811d2c0da76 | 399 | wait(5); |
matth420 | 0:d811d2c0da76 | 400 | strcpy(snd,"AT\r\n"); |
matth420 | 0:d811d2c0da76 | 401 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 402 | timeout=1; |
matth420 | 0:d811d2c0da76 | 403 | getreply(); |
matth420 | 0:d811d2c0da76 | 404 | wait(1); |
matth420 | 0:d811d2c0da76 | 405 | pc.printf("-------------- Redemarrage du module --------------\r\n"); //Redémarrage du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 406 | strcpy(snd,"AT+RST\r\n"); //Commande redémarrage du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 407 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 408 | timeout=5; |
matth420 | 0:d811d2c0da76 | 409 | getreply(); |
matth420 | 0:d811d2c0da76 | 410 | pc.printf(buf); |
matth420 | 0:d811d2c0da76 | 411 | |
matth420 | 0:d811d2c0da76 | 412 | wait(3); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 413 | |
matth420 | 0:d811d2c0da76 | 414 | pc.printf("\n---------- Mode Wifi ----------\r\n"); //Initialisation du mode WIFI |
matth420 | 0:d811d2c0da76 | 415 | strcpy(snd, "AT+CWMODE=3\r\n"); //Commande initialisation du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 416 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 417 | timeout=4; |
matth420 | 0:d811d2c0da76 | 418 | getreply(); |
matth420 | 0:d811d2c0da76 | 419 | pc.printf(buf); |
matth420 | 0:d811d2c0da76 | 420 | |
matth420 | 0:d811d2c0da76 | 421 | wait(2); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 422 | |
matth420 | 0:d811d2c0da76 | 423 | pc.printf("\n---------- Connexion au point d acces ----------\r\n"); //Connection au serveur IOP |
matth420 | 0:d811d2c0da76 | 424 | pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd); |
matth420 | 0:d811d2c0da76 | 425 | strcpy(snd, "AT+CWJAP=\""); //Commande de connection au serveur IOP |
matth420 | 0:d811d2c0da76 | 426 | strcat(snd, ssid); |
matth420 | 0:d811d2c0da76 | 427 | strcat(snd, "\",\""); |
matth420 | 0:d811d2c0da76 | 428 | strcat(snd, pwd); |
matth420 | 0:d811d2c0da76 | 429 | strcat(snd, "\"\r\n"); |
matth420 | 0:d811d2c0da76 | 430 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 431 | timeout=10; |
matth420 | 0:d811d2c0da76 | 432 | getreply(); |
matth420 | 0:d811d2c0da76 | 433 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 0:d811d2c0da76 | 434 | |
matth420 | 1:ca1ad3dc37b3 | 435 | wait(2); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 436 | |
matth420 | 0:d811d2c0da76 | 437 | pc.printf("\n---------- Adresse IP local ----------\r\n"); //Adressage IP |
matth420 | 0:d811d2c0da76 | 438 | strcpy(snd, "AT+CIFSR\r\n"); //Commande affichant adresse IP et MAC du PC ainsi que du module WIFI ESP8266 |
matth420 | 0:d811d2c0da76 | 439 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 440 | timeout=3; |
matth420 | 0:d811d2c0da76 | 441 | getreply(); |
matth420 | 0:d811d2c0da76 | 442 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 0:d811d2c0da76 | 443 | |
matth420 | 1:ca1ad3dc37b3 | 444 | wait(3); //Délai inter-étape |
matth420 | 0:d811d2c0da76 | 445 | |
matth420 | 0:d811d2c0da76 | 446 | pc.printf("\n---------- TCP Client ----------\r\n"); //Connection au serveur en tant que client |
matth420 | 1:ca1ad3dc37b3 | 447 | strcpy(snd, "AT+CIPSTART=\"TCP\",\"192.168.2.1\",55555\r\n"); //Commande connection au serveur : Protocol , Adresse IP serveur , port |
matth420 | 0:d811d2c0da76 | 448 | SendCMD(); |
matth420 | 0:d811d2c0da76 | 449 | timeout=5; |
matth420 | 0:d811d2c0da76 | 450 | getreply(); |
matth420 | 0:d811d2c0da76 | 451 | pc.printf(buf); //Statut de l'étape (OK/ERROR) |
matth420 | 1:ca1ad3dc37b3 | 452 | |
matth420 | 1:ca1ad3dc37b3 | 453 | wait(3); //Délai inter-étape |
matth420 | 1:ca1ad3dc37b3 | 454 | |
matth420 | 1:ca1ad3dc37b3 | 455 | |
matth420 | 0:d811d2c0da76 | 456 | } //Fin du void config |
matth420 | 0:d811d2c0da76 | 457 | |
matth420 | 0:d811d2c0da76 | 458 | void SendCMD() |
matth420 | 0:d811d2c0da76 | 459 | { |
matth420 | 0:d811d2c0da76 | 460 | esp.printf("%s", snd); |
matth420 | 1:ca1ad3dc37b3 | 461 | } |
matth420 | 0:d811d2c0da76 | 462 | |
matth420 | 0:d811d2c0da76 | 463 | void getreply() |
matth420 | 0:d811d2c0da76 | 464 | { |
matth420 | 0:d811d2c0da76 | 465 | memset(buf, '\0', sizeof(buf)); |
matth420 | 0:d811d2c0da76 | 466 | t.start(); |
matth420 | 0:d811d2c0da76 | 467 | ended=0; |
matth420 | 0:d811d2c0da76 | 468 | count=0; |
matth420 | 0:d811d2c0da76 | 469 | while(!ended) { |
matth420 | 0:d811d2c0da76 | 470 | if(esp.readable()) { |
matth420 | 0:d811d2c0da76 | 471 | buf[count] = esp.getc(); |
matth420 | 0:d811d2c0da76 | 472 | count++; |
matth420 | 0:d811d2c0da76 | 473 | } |
matth420 | 0:d811d2c0da76 | 474 | if(t.read() > timeout) { |
matth420 | 0:d811d2c0da76 | 475 | ended = 1; |
matth420 | 0:d811d2c0da76 | 476 | t.stop(); |
matth420 | 0:d811d2c0da76 | 477 | t.reset(); |
matth420 | 0:d811d2c0da76 | 478 | } |
matth420 | 0:d811d2c0da76 | 479 | } |
matth420 | 0:d811d2c0da76 | 480 | } |