![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
une 30aine passés sans pb entre les trames
Dependencies: ADS1015 ARNSRS_SENSORS DmTftLibrary MS5803_14BA SDFileSystem mbed
Fork of ARNSRS_SERVOS_USB_TFT by
main.cpp@15:c9205e490740, 2017-05-09 (annotated)
- Committer:
- POTLESS_2
- Date:
- Tue May 09 10:56:26 2017 +0000
- Revision:
- 15:c9205e490740
- Parent:
- 14:e6686a44db84
- Child:
- 16:fc7d8cc6bf4b
Derni?re version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
potless | 1:bef7856b5c0a | 1 | /* procédure lecture capteur COZIR ou MINIR - CO2 seul |
potless | 1:bef7856b5c0a | 2 | sur broches F401RE SERIAL PA_11 et PA_12 |
potless | 1:bef7856b5c0a | 3 | renvoie sur moniteur (IDE arduino par exemple) de la valeur lue |
potless | 2:4a8bf1d53439 | 4 | |
potless | 2:4a8bf1d53439 | 5 | procédures possibles sont : |
potless | 2:4a8bf1d53439 | 6 | request (char commande) - renvoie la valeur lue si la commande ne représente qu'un seul caractère (entre '') |
potless | 2:4a8bf1d53439 | 7 | cozirSend (string commande) - permet d'envoyer des commandes multicaractères (entre "") - exemple A 32 - donne la réponse obtenue |
potless | 2:4a8bf1d53439 | 8 | |
potless | 2:4a8bf1d53439 | 9 | |
potless | 2:4a8bf1d53439 | 10 | la fonction cozirSend est davantage "sécurisée" |
POTLESS_2 | 4:d84250f67dec | 11 | */ |
potless | 0:69d4b21d58e0 | 12 | |
potless | 0:69d4b21d58e0 | 13 | |
potless | 1:bef7856b5c0a | 14 | #include "mbed.h" |
POTLESS_2 | 5:e1d0dc7940a6 | 15 | #include "SDFileSystem.h" |
POTLESS_2 | 5:e1d0dc7940a6 | 16 | #include "ARNSRS_SENSORS.h" |
POTLESS_2 | 13:aa620707126d | 17 | #include "ble/BLE.h" |
POTLESS_2 | 14:e6686a44db84 | 18 | |
POTLESS_2 | 13:aa620707126d | 19 | #include "ble/services/UARTService.h" |
POTLESS_2 | 13:aa620707126d | 20 | #include <string> |
POTLESS_2 | 13:aa620707126d | 21 | |
POTLESS_2 | 15:c9205e490740 | 22 | //Ecrit dans le moniteur série de l'ordi à 9600 bds si sur 1 |
POTLESS_2 | 15:c9205e490740 | 23 | #define NEED_CONSOLE_OUTPUT 1 |
POTLESS_2 | 15:c9205e490740 | 24 | //Pour utiliser le traceur du moniteur Arduino. Mettre NEED_CONSOLE_OUTPUT 0 si utilisé |
POTLESS_2 | 15:c9205e490740 | 25 | #define NEED_GRAPH_OUTPUT 0 |
POTLESS_2 | 15:c9205e490740 | 26 | //Datalog carte SD si sur 1 |
POTLESS_2 | 15:c9205e490740 | 27 | #define NEED_SD_DATA_LOG 1 |
POTLESS_2 | 15:c9205e490740 | 28 | |
POTLESS_2 | 15:c9205e490740 | 29 | #if NEED_CONSOLE_OUTPUT |
POTLESS_2 | 14:e6686a44db84 | 30 | #define DEBUG(...) { serialMonit.printf(__VA_ARGS__); } |
POTLESS_2 | 15:c9205e490740 | 31 | #else |
POTLESS_2 | 15:c9205e490740 | 32 | #define DEBUG(...) |
POTLESS_2 | 15:c9205e490740 | 33 | #endif |
POTLESS_2 | 15:c9205e490740 | 34 | |
POTLESS_2 | 15:c9205e490740 | 35 | #if NEED_GRAPH_OUTPUT |
POTLESS_2 | 15:c9205e490740 | 36 | #define TRACE(...) { serialMonit.printf(__VA_ARGS__); } |
POTLESS_2 | 15:c9205e490740 | 37 | #else |
POTLESS_2 | 15:c9205e490740 | 38 | #define TRACE(...) |
POTLESS_2 | 15:c9205e490740 | 39 | #endif |
POTLESS_2 | 13:aa620707126d | 40 | |
POTLESS_2 | 13:aa620707126d | 41 | //Init BLE |
POTLESS_2 | 13:aa620707126d | 42 | BLEDevice ble; |
POTLESS_2 | 13:aa620707126d | 43 | UARTService *uartServicePtr; |
POTLESS_2 | 5:e1d0dc7940a6 | 44 | |
POTLESS_2 | 5:e1d0dc7940a6 | 45 | //Init de la lib ARNSRS; |
POTLESS_2 | 5:e1d0dc7940a6 | 46 | ARNSRS arnsrs; |
POTLESS_2 | 5:e1d0dc7940a6 | 47 | |
POTLESS_2 | 5:e1d0dc7940a6 | 48 | //Quelque FLAG... |
POTLESS_2 | 5:e1d0dc7940a6 | 49 | bool FLAG_SIMPLE_TIME = false; |
potless | 1:bef7856b5c0a | 50 | |
POTLESS_2 | 9:d945fa4be3a5 | 51 | //COM Série vers l'ordi, Serial 2 par défaut |
POTLESS_2 | 14:e6686a44db84 | 52 | Serial serialMonit (USBTX,USBRX); |
potless | 2:4a8bf1d53439 | 53 | |
POTLESS_2 | 5:e1d0dc7940a6 | 54 | //Variable des capteurs |
POTLESS_2 | 12:9ac5be447764 | 55 | int co2 = 0; |
POTLESS_2 | 12:9ac5be447764 | 56 | int ppO2 = 0; |
POTLESS_2 | 12:9ac5be447764 | 57 | float pression = 0; |
POTLESS_2 | 12:9ac5be447764 | 58 | float Temp1 = 0; |
POTLESS_2 | 12:9ac5be447764 | 59 | float Temp2 = 0; |
POTLESS_2 | 12:9ac5be447764 | 60 | float Humi = 0; |
POTLESS_2 | 12:9ac5be447764 | 61 | |
POTLESS_2 | 15:c9205e490740 | 62 | //Pour stocker le format date / heure |
POTLESS_2 | 5:e1d0dc7940a6 | 63 | string DateHeure; |
potless | 2:4a8bf1d53439 | 64 | |
POTLESS_2 | 6:1c2212891714 | 65 | //SD card |
POTLESS_2 | 6:1c2212891714 | 66 | SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS |
POTLESS_2 | 6:1c2212891714 | 67 | FILE *fp; |
POTLESS_2 | 7:c5a5d8f678ff | 68 | char fileName[32]; |
POTLESS_2 | 7:c5a5d8f678ff | 69 | int points = 1; |
POTLESS_2 | 4:d84250f67dec | 70 | |
POTLESS_2 | 15:c9205e490740 | 71 | |
POTLESS_2 | 15:c9205e490740 | 72 | //Fonction pour créer et envoyer la chaine d'infos en BLE |
POTLESS_2 | 15:c9205e490740 | 73 | //On balance tout en float, même pour des int...Qui peut le plus peut le moins... |
POTLESS_2 | 14:e6686a44db84 | 74 | //3 par 3 ça passe juste avec un décimal....Sinon faire deux par deux ??? |
POTLESS_2 | 14:e6686a44db84 | 75 | void build_send_Message(string com, float A, float B, float C) |
POTLESS_2 | 14:e6686a44db84 | 76 | { |
POTLESS_2 | 14:e6686a44db84 | 77 | char buf[50]; |
POTLESS_2 | 15:c9205e490740 | 78 | sprintf(buf,"%s%.1f:%.1f:%.1f\r\n", com, A, B, C); |
POTLESS_2 | 14:e6686a44db84 | 79 | uartServicePtr->writeString(buf); |
POTLESS_2 | 14:e6686a44db84 | 80 | } |
POTLESS_2 | 13:aa620707126d | 81 | |
POTLESS_2 | 13:aa620707126d | 82 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
POTLESS_2 | 13:aa620707126d | 83 | { |
POTLESS_2 | 14:e6686a44db84 | 84 | //DEBUG("Disconnected!\n\r"); |
POTLESS_2 | 14:e6686a44db84 | 85 | //DEBUG("Restarting the advertising process\n\r"); |
POTLESS_2 | 13:aa620707126d | 86 | ble.startAdvertising(); |
POTLESS_2 | 13:aa620707126d | 87 | } |
POTLESS_2 | 13:aa620707126d | 88 | |
POTLESS_2 | 13:aa620707126d | 89 | void onDataWritten(const GattWriteCallbackParams *params) |
POTLESS_2 | 13:aa620707126d | 90 | { |
POTLESS_2 | 13:aa620707126d | 91 | if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) { |
POTLESS_2 | 13:aa620707126d | 92 | uint16_t bytesRead = params->len; |
POTLESS_2 | 14:e6686a44db84 | 93 | /* |
POTLESS_2 | 14:e6686a44db84 | 94 | // les chaines de réponse |
POTLESS_2 | 15:c9205e490740 | 95 | uint8_t press_mb_ToSend[14]; |
POTLESS_2 | 14:e6686a44db84 | 96 | uint8_t co2_ppm_ToSend[14]; |
POTLESS_2 | 14:e6686a44db84 | 97 | uint8_t o2_mb_ToSend[14]; |
POTLESS_2 | 14:e6686a44db84 | 98 | |
POTLESS_2 | 14:e6686a44db84 | 99 | // fabrication des chaines de réponse |
POTLESS_2 | 14:e6686a44db84 | 100 | // on suppose que chaque donnee peut être représentée par 5 digits |
POTLESS_2 | 14:e6686a44db84 | 101 | char s_press_mb [50]; |
POTLESS_2 | 14:e6686a44db84 | 102 | sprintf(s_press_mb,"PRESS %i mb ",press_mb); // mef ! laisser les espaces de la fin |
POTLESS_2 | 14:e6686a44db84 | 103 | |
POTLESS_2 | 14:e6686a44db84 | 104 | char s_co2_ppm [50]; |
POTLESS_2 | 14:e6686a44db84 | 105 | sprintf(s_co2_ppm,"CO2 %i ppm ",co2_ppm); |
POTLESS_2 | 14:e6686a44db84 | 106 | |
POTLESS_2 | 14:e6686a44db84 | 107 | char s_o2_mb [50]; |
POTLESS_2 | 14:e6686a44db84 | 108 | sprintf(s_o2_mb,"O2 %i mb ",o2_mb); |
POTLESS_2 | 14:e6686a44db84 | 109 | |
POTLESS_2 | 14:e6686a44db84 | 110 | // convertir les chaines en uint8_t |
POTLESS_2 | 14:e6686a44db84 | 111 | for(int j=0;j<sizeof(s_press_mb);j++){ // hypothèse : les chaines press, co2, o2 ont la même longeur |
POTLESS_2 | 14:e6686a44db84 | 112 | press_mb_ToSend[j]=s_press_mb[j]; |
POTLESS_2 | 14:e6686a44db84 | 113 | co2_ppm_ToSend[j]=s_co2_ppm[j]; |
POTLESS_2 | 14:e6686a44db84 | 114 | o2_mb_ToSend[j]=s_o2_mb[j]; |
POTLESS_2 | 14:e6686a44db84 | 115 | } |
POTLESS_2 | 15:c9205e490740 | 116 | */ |
POTLESS_2 | 14:e6686a44db84 | 117 | // chaine reçue de l'app android (à dimensionner selon besoin) |
POTLESS_2 | 14:e6686a44db84 | 118 | char commande [bytesRead] ; |
POTLESS_2 | 14:e6686a44db84 | 119 | |
POTLESS_2 | 13:aa620707126d | 120 | // conversion de la commande uint8_t en chaine pour permettre comparaison avec commandes connues |
POTLESS_2 | 14:e6686a44db84 | 121 | for (int j=0; j<bytesRead; j++) { |
POTLESS_2 | 14:e6686a44db84 | 122 | commande [j] = (*((params->data)+j)); |
POTLESS_2 | 13:aa620707126d | 123 | } |
POTLESS_2 | 14:e6686a44db84 | 124 | /* |
POTLESS_2 | 13:aa620707126d | 125 | DEBUG("received %u bytes => ", bytesRead); |
POTLESS_2 | 13:aa620707126d | 126 | DEBUG("commande recue -%s-\r\n",commande); |
POTLESS_2 | 13:aa620707126d | 127 | DEBUG ( "comparaison a commande 'p' vaut %d\r\n",strcmp(commande, "p")); |
POTLESS_2 | 13:aa620707126d | 128 | DEBUG ( "comparaison a commande 'o' vaut %d\r\n",strcmp(commande, "o")); |
POTLESS_2 | 13:aa620707126d | 129 | DEBUG ( "comparaison a commande 'c' vaut %d\r\n",strcmp(commande, "c")); |
POTLESS_2 | 14:e6686a44db84 | 130 | DEBUG ( "comparaison a commande 't' vaut %d\r\n",strcmp(commande, "t")); |
POTLESS_2 | 14:e6686a44db84 | 131 | DEBUG ( "comparaison a commande 'u' vaut %d\r\n",strcmp(commande, "t")); |
POTLESS_2 | 14:e6686a44db84 | 132 | |
POTLESS_2 | 14:e6686a44db84 | 133 | // envoi des réponses en fonction de la commande recue |
POTLESS_2 | 14:e6686a44db84 | 134 | if (strcmp(commande, "p") == 0) { |
POTLESS_2 | 14:e6686a44db84 | 135 | DEBUG("s_press_mb %s +++> data to send %s \r\n",s_press_mb,press_mb_ToSend); |
POTLESS_2 | 14:e6686a44db84 | 136 | ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), press_mb_ToSend, sizeof(press_mb_ToSend)); |
POTLESS_2 | 14:e6686a44db84 | 137 | } |
POTLESS_2 | 14:e6686a44db84 | 138 | if (strcmp(commande, "c") == 0) { |
POTLESS_2 | 14:e6686a44db84 | 139 | DEBUG("s_co2_ppm %s +++> data to send %s \r\n",s_co2_ppm,co2_ppm_ToSend); |
POTLESS_2 | 14:e6686a44db84 | 140 | ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), co2_ppm_ToSend, sizeof(co2_ppm_ToSend)); |
POTLESS_2 | 14:e6686a44db84 | 141 | } |
POTLESS_2 | 14:e6686a44db84 | 142 | if (strcmp(commande, "o") == 0) { |
POTLESS_2 | 14:e6686a44db84 | 143 | DEBUG("s_o2_mb %s +++> data to send %s \r\n",s_o2_mb,o2_mb_ToSend); |
POTLESS_2 | 14:e6686a44db84 | 144 | ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), o2_mb_ToSend, sizeof(o2_mb_ToSend)); |
POTLESS_2 | 14:e6686a44db84 | 145 | } |
POTLESS_2 | 15:c9205e490740 | 146 | else |
POTLESS_2 | 15:c9205e490740 | 147 | */ |
POTLESS_2 | 14:e6686a44db84 | 148 | if (strcmp(commande, "t") == 0) { |
POTLESS_2 | 14:e6686a44db84 | 149 | build_send_Message("t", ppO2, co2, pression); |
POTLESS_2 | 14:e6686a44db84 | 150 | }else |
POTLESS_2 | 14:e6686a44db84 | 151 | if (strcmp(commande, "u") == 0) { |
POTLESS_2 | 14:e6686a44db84 | 152 | build_send_Message("u", Temp1, Temp2, Humi); |
POTLESS_2 | 14:e6686a44db84 | 153 | } |
POTLESS_2 | 14:e6686a44db84 | 154 | } |
POTLESS_2 | 13:aa620707126d | 155 | } |
POTLESS_2 | 14:e6686a44db84 | 156 | |
POTLESS_2 | 7:c5a5d8f678ff | 157 | //Fonction qui change le nom du fichier ouvert pour le LOG |
POTLESS_2 | 7:c5a5d8f678ff | 158 | FILE *nextLogFile(void) |
POTLESS_2 | 7:c5a5d8f678ff | 159 | { |
POTLESS_2 | 7:c5a5d8f678ff | 160 | static unsigned int fileNumber = 0; |
POTLESS_2 | 7:c5a5d8f678ff | 161 | FILE *filePtr = NULL; |
POTLESS_2 | 7:c5a5d8f678ff | 162 | do { |
POTLESS_2 | 7:c5a5d8f678ff | 163 | if (filePtr != NULL) |
POTLESS_2 | 7:c5a5d8f678ff | 164 | fclose(filePtr); |
POTLESS_2 | 7:c5a5d8f678ff | 165 | sprintf(fileName,"/sd/LOG_Capteurs_%04u.txt",fileNumber++); |
POTLESS_2 | 7:c5a5d8f678ff | 166 | filePtr = fopen(fileName,"r"); |
POTLESS_2 | 7:c5a5d8f678ff | 167 | } while (filePtr != NULL); |
POTLESS_2 | 7:c5a5d8f678ff | 168 | return fopen( fileName,"w"); |
POTLESS_2 | 7:c5a5d8f678ff | 169 | } |
POTLESS_2 | 15:c9205e490740 | 170 | |
POTLESS_2 | 14:e6686a44db84 | 171 | void SetTime() |
POTLESS_2 | 14:e6686a44db84 | 172 | { |
POTLESS_2 | 14:e6686a44db84 | 173 | //Reglage date / heure depuis le terminal |
POTLESS_2 | 7:c5a5d8f678ff | 174 | struct tm t; |
POTLESS_2 | 15:c9205e490740 | 175 | serialMonit.printf("Entrer la date et l'heure :\n"); |
POTLESS_2 | 15:c9205e490740 | 176 | serialMonit.printf("YYYY MM DD HH MM SS [enter]\n"); |
POTLESS_2 | 7:c5a5d8f678ff | 177 | scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday |
POTLESS_2 | 14:e6686a44db84 | 178 | , &t.tm_hour, &t.tm_min, &t.tm_sec); |
POTLESS_2 | 7:c5a5d8f678ff | 179 | t.tm_year = t.tm_year - 1900; |
POTLESS_2 | 7:c5a5d8f678ff | 180 | t.tm_mon = t.tm_mon - 1; |
POTLESS_2 | 14:e6686a44db84 | 181 | |
POTLESS_2 | 7:c5a5d8f678ff | 182 | // set the time |
POTLESS_2 | 14:e6686a44db84 | 183 | set_time(mktime(&t)); |
POTLESS_2 | 15:c9205e490740 | 184 | if(NEED_CONSOLE_OUTPUT == 0) serialMonit.printf("OK. Vous pouvez fermer le moniteur serie"); |
POTLESS_2 | 12:9ac5be447764 | 185 | } |
POTLESS_2 | 12:9ac5be447764 | 186 | |
POTLESS_2 | 14:e6686a44db84 | 187 | void init_DATALOG() |
POTLESS_2 | 14:e6686a44db84 | 188 | { |
POTLESS_2 | 12:9ac5be447764 | 189 | //Initialisation DATA LOG |
POTLESS_2 | 14:e6686a44db84 | 190 | DEBUG("Initialisation SD card\r\n"); |
POTLESS_2 | 15:c9205e490740 | 191 | DEBUG("\r\n", ""); |
POTLESS_2 | 12:9ac5be447764 | 192 | fp = nextLogFile(); |
POTLESS_2 | 14:e6686a44db84 | 193 | |
POTLESS_2 | 14:e6686a44db84 | 194 | if (!fp) { |
POTLESS_2 | 14:e6686a44db84 | 195 | DEBUG("Probleme SD card...Fin du programme...\r\n"); |
POTLESS_2 | 14:e6686a44db84 | 196 | //exit(0); |
POTLESS_2 | 14:e6686a44db84 | 197 | } else { |
POTLESS_2 | 14:e6686a44db84 | 198 | DEBUG("Nouveau fichier LOG cree = %s\r\n", fileName); |
POTLESS_2 | 14:e6686a44db84 | 199 | DEBUG("\r\n", ""); |
POTLESS_2 | 12:9ac5be447764 | 200 | } |
POTLESS_2 | 14:e6686a44db84 | 201 | } |
POTLESS_2 | 14:e6686a44db84 | 202 | |
POTLESS_2 | 14:e6686a44db84 | 203 | void DATA_LOG() |
POTLESS_2 | 14:e6686a44db84 | 204 | { |
POTLESS_2 | 12:9ac5be447764 | 205 | time_t seconds = time(NULL); |
POTLESS_2 | 12:9ac5be447764 | 206 | if (fp) { |
POTLESS_2 | 14:e6686a44db84 | 207 | fprintf(fp, "%s,%d,%d,%f,%f,%f,%f\r\n", ctime(&seconds), co2 , ppO2, pression, Temp1, Temp2, Humi); |
POTLESS_2 | 14:e6686a44db84 | 208 | DEBUG(" Enregistrement d'un point sur la carte SD\r\n"); |
POTLESS_2 | 14:e6686a44db84 | 209 | DEBUG(" Nombre de points = %d\r\n", points); |
POTLESS_2 | 14:e6686a44db84 | 210 | DEBUG("\r\n", ""); |
POTLESS_2 | 14:e6686a44db84 | 211 | points++; |
POTLESS_2 | 14:e6686a44db84 | 212 | } else { |
POTLESS_2 | 14:e6686a44db84 | 213 | DEBUG(" Probleme carte SD\r\n"); |
POTLESS_2 | 14:e6686a44db84 | 214 | } |
POTLESS_2 | 14:e6686a44db84 | 215 | } |
potless | 2:4a8bf1d53439 | 216 | /////////////////////////////////// |
potless | 2:4a8bf1d53439 | 217 | // fonction initialisation ///// |
potless | 2:4a8bf1d53439 | 218 | /////////////////////////////////// |
POTLESS_2 | 4:d84250f67dec | 219 | void setup() |
POTLESS_2 | 4:d84250f67dec | 220 | { |
POTLESS_2 | 7:c5a5d8f678ff | 221 | //Réglage de l'heure |
POTLESS_2 | 11:278bdb497ba3 | 222 | SetTime(); |
POTLESS_2 | 14:e6686a44db84 | 223 | |
POTLESS_2 | 15:c9205e490740 | 224 | //Initialisation du Data log |
POTLESS_2 | 15:c9205e490740 | 225 | if (NEED_SD_DATA_LOG == 1) init_DATALOG(); |
POTLESS_2 | 14:e6686a44db84 | 226 | |
POTLESS_2 | 7:c5a5d8f678ff | 227 | //Initialisation capteurs |
POTLESS_2 | 8:e864edfe656e | 228 | arnsrs.Sensors_INIT(false, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
potless | 0:69d4b21d58e0 | 229 | } |
potless | 0:69d4b21d58e0 | 230 | |
potless | 1:bef7856b5c0a | 231 | ///////////////////////////////////// |
potless | 1:bef7856b5c0a | 232 | /// procédure principale ///////// |
potless | 1:bef7856b5c0a | 233 | ///////////////////////////////////// |
potless | 0:69d4b21d58e0 | 234 | |
POTLESS_2 | 4:d84250f67dec | 235 | int main() |
POTLESS_2 | 4:d84250f67dec | 236 | { |
POTLESS_2 | 7:c5a5d8f678ff | 237 | setup(); |
potless | 2:4a8bf1d53439 | 238 | |
POTLESS_2 | 14:e6686a44db84 | 239 | //DEBUG("Initialising....\n\r"); |
POTLESS_2 | 13:aa620707126d | 240 | ble.init(); |
POTLESS_2 | 13:aa620707126d | 241 | ble.onDisconnection(disconnectionCallback); |
POTLESS_2 | 13:aa620707126d | 242 | ble.onDataWritten(onDataWritten); |
POTLESS_2 | 14:e6686a44db84 | 243 | |
POTLESS_2 | 13:aa620707126d | 244 | /* setup advertising */ |
POTLESS_2 | 13:aa620707126d | 245 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
POTLESS_2 | 13:aa620707126d | 246 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
POTLESS_2 | 13:aa620707126d | 247 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
POTLESS_2 | 13:aa620707126d | 248 | (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1); |
POTLESS_2 | 13:aa620707126d | 249 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
POTLESS_2 | 13:aa620707126d | 250 | (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); |
POTLESS_2 | 14:e6686a44db84 | 251 | |
POTLESS_2 | 13:aa620707126d | 252 | ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */ |
POTLESS_2 | 13:aa620707126d | 253 | ble.startAdvertising(); |
POTLESS_2 | 14:e6686a44db84 | 254 | |
POTLESS_2 | 13:aa620707126d | 255 | UARTService uartService(ble); |
POTLESS_2 | 13:aa620707126d | 256 | uartServicePtr = &uartService; |
POTLESS_2 | 14:e6686a44db84 | 257 | |
POTLESS_2 | 4:d84250f67dec | 258 | while (1) { |
POTLESS_2 | 5:e1d0dc7940a6 | 259 | |
POTLESS_2 | 14:e6686a44db84 | 260 | ble.waitForEvent(); |
POTLESS_2 | 14:e6686a44db84 | 261 | |
POTLESS_2 | 15:c9205e490740 | 262 | //wait_ms(500); |
POTLESS_2 | 14:e6686a44db84 | 263 | |
POTLESS_2 | 5:e1d0dc7940a6 | 264 | //RTC |
POTLESS_2 | 7:c5a5d8f678ff | 265 | time_t seconds = time(NULL); |
POTLESS_2 | 14:e6686a44db84 | 266 | |
POTLESS_2 | 14:e6686a44db84 | 267 | DEBUG(" Date / Heure = %s\r\n", ctime(&seconds)); |
POTLESS_2 | 14:e6686a44db84 | 268 | |
POTLESS_2 | 4:d84250f67dec | 269 | //CO2 / H / T sur Cozir |
POTLESS_2 | 6:1c2212891714 | 270 | co2 = arnsrs.requestCO2(); |
POTLESS_2 | 6:1c2212891714 | 271 | Humi = arnsrs.requestHUMI(); |
POTLESS_2 | 14:e6686a44db84 | 272 | Temp1 = arnsrs.requestTEMP(); |
POTLESS_2 | 14:e6686a44db84 | 273 | |
POTLESS_2 | 6:1c2212891714 | 274 | //P / T sur MS5803_14BA |
POTLESS_2 | 5:e1d0dc7940a6 | 275 | pression = arnsrs.requestPress(); |
POTLESS_2 | 5:e1d0dc7940a6 | 276 | Temp2 = arnsrs.requestTemp(); |
POTLESS_2 | 5:e1d0dc7940a6 | 277 | |
POTLESS_2 | 5:e1d0dc7940a6 | 278 | //PPO2 sur ADS1015 |
POTLESS_2 | 8:e864edfe656e | 279 | ppO2 = arnsrs.requestPpO2(false); |
POTLESS_2 | 5:e1d0dc7940a6 | 280 | |
POTLESS_2 | 5:e1d0dc7940a6 | 281 | //Affichage sur moniteur série |
POTLESS_2 | 14:e6686a44db84 | 282 | DEBUG(" CO2 = %d\r\n" , co2); |
POTLESS_2 | 15:c9205e490740 | 283 | DEBUG(" Humidite = %f\r\n" , Humi); |
POTLESS_2 | 15:c9205e490740 | 284 | DEBUG(" Temperature = %f\r\n" ,Temp1); |
POTLESS_2 | 4:d84250f67dec | 285 | //P / T sur MS5803 |
POTLESS_2 | 14:e6686a44db84 | 286 | DEBUG(" Pression = %f\r\n", pression); |
POTLESS_2 | 15:c9205e490740 | 287 | DEBUG(" Temperature = %f\r\n", Temp2); |
POTLESS_2 | 4:d84250f67dec | 288 | //PPO2 sur ADS1015 |
POTLESS_2 | 14:e6686a44db84 | 289 | DEBUG(" PPO2 = %d\r\n", ppO2); |
POTLESS_2 | 14:e6686a44db84 | 290 | DEBUG("\r\n", ""); |
POTLESS_2 | 5:e1d0dc7940a6 | 291 | |
POTLESS_2 | 15:c9205e490740 | 292 | //Traceur |
POTLESS_2 | 15:c9205e490740 | 293 | TRACE("%d\r\n" , co2); |
POTLESS_2 | 15:c9205e490740 | 294 | TRACE("%d\r\n" , ppO2); |
POTLESS_2 | 15:c9205e490740 | 295 | TRACE("%f\r\n" , Humi); |
POTLESS_2 | 15:c9205e490740 | 296 | TRACE("%f\r\n" , Temp1); |
POTLESS_2 | 15:c9205e490740 | 297 | TRACE("%f\r\n" , Temp2); |
POTLESS_2 | 15:c9205e490740 | 298 | TRACE("%f\r\n" , pression); |
POTLESS_2 | 15:c9205e490740 | 299 | |
POTLESS_2 | 7:c5a5d8f678ff | 300 | //Data LOG |
POTLESS_2 | 15:c9205e490740 | 301 | if (NEED_SD_DATA_LOG == 1) DATA_LOG(); |
POTLESS_2 | 15:c9205e490740 | 302 | |
POTLESS_2 | 15:c9205e490740 | 303 | build_send_Message("t", ppO2, co2, pression); |
POTLESS_2 | 15:c9205e490740 | 304 | build_send_Message("u", Temp1, Temp2, Humi); |
POTLESS_2 | 15:c9205e490740 | 305 | |
POTLESS_2 | 13:aa620707126d | 306 | } |
POTLESS_2 | 4:d84250f67dec | 307 | } |