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