for james

Dependencies:   sendmessages mbed

Fork of C027_SupportTest by Lime

Committer:
maxelior
Date:
Wed Apr 11 14:20:27 2018 +0000
Revision:
2:57d040afa937
Parent:
1:5639bc1208d5
Child:
3:8b90a40df4db
fonction acquisition poids auto traitement du poids envoi sms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bennettmatt1977 0:15a06b50e14e 1 #include "mbed.h"
maxelior 1:5639bc1208d5 2 #include <string.h>
bennettmatt1977 0:15a06b50e14e 3
bennettmatt1977 0:15a06b50e14e 4 //------------------------------------------------------------------------------------
maxelior 1:5639bc1208d5 5 /* This example was tested on C027-U20 and C027-G35 with the on board modem.
maxelior 1:5639bc1208d5 6
maxelior 1:5639bc1208d5 7 Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON
maxelior 1:5639bc1208d5 8 is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this
maxelior 1:5639bc1208d5 9 configuration the following platforms were tested (it is likely that others
bennettmatt1977 0:15a06b50e14e 10 will work as well)
bennettmatt1977 0:15a06b50e14e 11 - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD)
bennettmatt1977 0:15a06b50e14e 12 - NXP: LPC1549v2, LPC4088qsb
bennettmatt1977 0:15a06b50e14e 13 - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F
bennettmatt1977 0:15a06b50e14e 14 - STM: NUCLEO-F401RE, NUCLEO-F030R8
bennettmatt1977 0:15a06b50e14e 15 mount resistors SB13/14 1k, SB62/63 0R
bennettmatt1977 0:15a06b50e14e 16 */
bennettmatt1977 0:15a06b50e14e 17 #include "GPS.h"
bennettmatt1977 0:15a06b50e14e 18 #include "MDM.h"
bennettmatt1977 0:15a06b50e14e 19 //------------------------------------------------------------------------------------
bennettmatt1977 0:15a06b50e14e 20 // You need to configure these cellular modem / SIM parameters.
bennettmatt1977 0:15a06b50e14e 21 // These parameters are ignored for LISA-C200 variants and can be left NULL.
bennettmatt1977 0:15a06b50e14e 22 //------------------------------------------------------------------------------------
bennettmatt1977 0:15a06b50e14e 23 //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
maxelior 1:5639bc1208d5 24 #define SIMPIN "1234"
maxelior 1:5639bc1208d5 25 /*! The APN of your network operator SIM, sometimes it is "internet" check your
maxelior 1:5639bc1208d5 26 contract with the network operator. You can also try to look-up your settings in
bennettmatt1977 0:15a06b50e14e 27 google: https://www.google.de/search?q=APN+list */
bennettmatt1977 0:15a06b50e14e 28 #define APN NULL
bennettmatt1977 0:15a06b50e14e 29 //! Set the user name for your APN, or NULL if not needed
bennettmatt1977 0:15a06b50e14e 30 #define USERNAME NULL
bennettmatt1977 0:15a06b50e14e 31 //! Set the password for your APN, or NULL if not needed
maxelior 1:5639bc1208d5 32 #define PASSWORD NULL
bennettmatt1977 0:15a06b50e14e 33 //------------------------------------------------------------------------------------
bennettmatt1977 0:15a06b50e14e 34
maxelior 1:5639bc1208d5 35 #define RVA 0
maxelior 1:5639bc1208d5 36 #define RPA 1
maxelior 1:5639bc1208d5 37 #define RPHVA 2
maxelior 1:5639bc1208d5 38 #define RPHPHVA 3
maxelior 2:57d040afa937 39 #define essaimage 4
maxelior 1:5639bc1208d5 40
maxelior 1:5639bc1208d5 41 AnalogIn analog_value(PC_5);
maxelior 1:5639bc1208d5 42
maxelior 1:5639bc1208d5 43 static float variation_poids=0;
maxelior 1:5639bc1208d5 44 static float poids_ruche=0;
maxelior 1:5639bc1208d5 45 static float poids_prece=0;
maxelior 1:5639bc1208d5 46
maxelior 1:5639bc1208d5 47 //const char num1[]="0652330722"; //jamoud
maxelior 1:5639bc1208d5 48 //const char num1[]="0685350930"; //paul bonnet
maxelior 1:5639bc1208d5 49 //const char num1[]="0685209401"; //benji
maxelior 1:5639bc1208d5 50 const char num1[]="0609168455"; //garsonnat
maxelior 2:57d040afa937 51 static char chaine[255];
maxelior 2:57d040afa937 52 static int flag = 0;
maxelior 2:57d040afa937 53
maxelior 2:57d040afa937 54
maxelior 2:57d040afa937 55 static int cpt=0;
maxelior 2:57d040afa937 56 static float tabPoids[2000];
maxelior 2:57d040afa937 57 static float poidsMoyenne=0;
maxelior 2:57d040afa937 58 static float offset=0;
maxelior 2:57d040afa937 59
maxelior 2:57d040afa937 60 Serial pc(USBTX, USBRX);
maxelior 2:57d040afa937 61 // Create the modem object
maxelior 2:57d040afa937 62 MDMSerial mdm;
maxelior 1:5639bc1208d5 63
maxelior 1:5639bc1208d5 64
maxelior 2:57d040afa937 65 float moyennagePoids(float poids[]){
maxelior 2:57d040afa937 66
maxelior 2:57d040afa937 67 float poidsFinal;
maxelior 2:57d040afa937 68 int i=0;
maxelior 2:57d040afa937 69 for(i=0;i<2001;i++)
maxelior 2:57d040afa937 70 {
maxelior 2:57d040afa937 71 poidsFinal+=poids[i];
maxelior 2:57d040afa937 72 }
maxelior 2:57d040afa937 73 poidsFinal/=2001;
maxelior 2:57d040afa937 74 return poidsFinal;
maxelior 2:57d040afa937 75 }
maxelior 1:5639bc1208d5 76
maxelior 2:57d040afa937 77 void acquisition(){
maxelior 2:57d040afa937 78
maxelior 2:57d040afa937 79 poids_ruche=analog_value.read();
maxelior 2:57d040afa937 80 offset = poids_ruche;
maxelior 2:57d040afa937 81 poids_ruche = poids_ruche * 3300;
maxelior 2:57d040afa937 82 pc.printf("Poids 1 = %2.2f mV\r\n",poids_ruche);
maxelior 2:57d040afa937 83
maxelior 2:57d040afa937 84 poids_ruche=((0.030151089*poids_ruche)-5.7390218965);
maxelior 2:57d040afa937 85 pc.printf("Poids 2 = %2.2f Kg\r\n",poids_ruche);
maxelior 2:57d040afa937 86
maxelior 2:57d040afa937 87 wait(0.5);
maxelior 2:57d040afa937 88
maxelior 2:57d040afa937 89 if(cpt<2001) {
maxelior 2:57d040afa937 90 tabPoids[cpt]=poids_ruche;
maxelior 2:57d040afa937 91 } else if(cpt==2001) {
maxelior 2:57d040afa937 92 poidsMoyenne=moyennagePoids(tabPoids);
maxelior 2:57d040afa937 93 pc.printf("Poids Moyen = %2.2f Kg\r\n",poidsMoyenne);
maxelior 2:57d040afa937 94 wait(1.5);
maxelior 2:57d040afa937 95 cpt=0;
maxelior 2:57d040afa937 96 }
maxelior 2:57d040afa937 97 cpt++;
maxelior 2:57d040afa937 98 }
maxelior 1:5639bc1208d5 99
maxelior 1:5639bc1208d5 100 void automate()
maxelior 1:5639bc1208d5 101 {
maxelior 1:5639bc1208d5 102 static int etat_ruche_courant = RVA;
maxelior 2:57d040afa937 103 static int etat_ruche_futur, etat_precedent;
maxelior 1:5639bc1208d5 104
maxelior 1:5639bc1208d5 105 etat_ruche_courant = etat_ruche_futur;
maxelior 1:5639bc1208d5 106 variation_poids = poids_ruche - poids_prece;
maxelior 1:5639bc1208d5 107 poids_prece = poids_ruche;
maxelior 1:5639bc1208d5 108
maxelior 1:5639bc1208d5 109 switch(etat_ruche_courant) {
maxelior 1:5639bc1208d5 110
maxelior 1:5639bc1208d5 111 case RVA:
maxelior 1:5639bc1208d5 112 if(poids_ruche < 40) {
maxelior 2:57d040afa937 113 if(variation_poids <= -2)
maxelior 2:57d040afa937 114 { etat_precedent = RVA;
maxelior 2:57d040afa937 115 etat_ruche_futur = essaimage;
maxelior 2:57d040afa937 116 }
maxelior 1:5639bc1208d5 117 if(variation_poids > 0) {
maxelior 1:5639bc1208d5 118 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 119 }
maxelior 1:5639bc1208d5 120 if(variation_poids < 0) {
maxelior 1:5639bc1208d5 121 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 122 }
maxelior 1:5639bc1208d5 123 if(variation_poids == 0) {
maxelior 1:5639bc1208d5 124 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 125 }
maxelior 1:5639bc1208d5 126 }
maxelior 1:5639bc1208d5 127 if(poids_ruche >= 40) {
maxelior 1:5639bc1208d5 128
maxelior 1:5639bc1208d5 129 sprintf(chaine, "recolte hausse n1\r\n poids = %2.f", poids_ruche);
maxelior 1:5639bc1208d5 130 flag = 1;
maxelior 1:5639bc1208d5 131 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 132 }
maxelior 1:5639bc1208d5 133
maxelior 1:5639bc1208d5 134 break;
maxelior 1:5639bc1208d5 135
maxelior 1:5639bc1208d5 136 case RPHVA:
maxelior 1:5639bc1208d5 137 if(poids_ruche < 56) {
maxelior 2:57d040afa937 138 if(variation_poids <= -2)
maxelior 2:57d040afa937 139 { etat_precedent = RPHVA;
maxelior 2:57d040afa937 140 etat_ruche_futur = essaimage;
maxelior 2:57d040afa937 141 }
maxelior 1:5639bc1208d5 142 if(variation_poids > 0) {
maxelior 1:5639bc1208d5 143 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 144 }
maxelior 1:5639bc1208d5 145 if(variation_poids < 0) {
maxelior 1:5639bc1208d5 146 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 147 }
maxelior 1:5639bc1208d5 148 if(variation_poids == 0) {
maxelior 1:5639bc1208d5 149 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 150 }
maxelior 1:5639bc1208d5 151 }
maxelior 1:5639bc1208d5 152 if(poids_ruche >= 56) {
maxelior 1:5639bc1208d5 153 sprintf(chaine, "recolte hausse n2\r\n poids = %2.f", poids_ruche);
maxelior 1:5639bc1208d5 154 flag = 1;
maxelior 1:5639bc1208d5 155 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 156 }
maxelior 1:5639bc1208d5 157
maxelior 1:5639bc1208d5 158 break;
maxelior 1:5639bc1208d5 159
maxelior 1:5639bc1208d5 160 case RPHPHVA:
maxelior 1:5639bc1208d5 161 if(poids_ruche < 72) {
maxelior 2:57d040afa937 162 if(variation_poids <= -2)
maxelior 2:57d040afa937 163 { etat_precedent = RPHPHVA;
maxelior 2:57d040afa937 164 etat_ruche_futur = essaimage;
maxelior 2:57d040afa937 165 }
maxelior 1:5639bc1208d5 166 if(variation_poids > 0) {
maxelior 1:5639bc1208d5 167 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 168 }
maxelior 1:5639bc1208d5 169 if(variation_poids < 0) {
maxelior 1:5639bc1208d5 170 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 171 }
maxelior 1:5639bc1208d5 172 if(variation_poids == 0) {
maxelior 1:5639bc1208d5 173 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 174 }
maxelior 1:5639bc1208d5 175 }
maxelior 1:5639bc1208d5 176 if(poids_ruche > 72) {
maxelior 1:5639bc1208d5 177 sprintf(chaine, "recolte hausse n1 & n2\r\n poids = %2.f", poids_ruche);
maxelior 1:5639bc1208d5 178 flag = 1;
maxelior 1:5639bc1208d5 179 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 180 }
maxelior 1:5639bc1208d5 181 break;
maxelior 2:57d040afa937 182 case essaimage:
maxelior 2:57d040afa937 183 sprintf(chaine, "BELEK essaimage !!! \r\n");
maxelior 2:57d040afa937 184 flag = 1;
maxelior 2:57d040afa937 185 etat_ruche_futur = etat_precedent;
maxelior 2:57d040afa937 186 break;
maxelior 1:5639bc1208d5 187 }
maxelior 1:5639bc1208d5 188 }
bennettmatt1977 0:15a06b50e14e 189
bennettmatt1977 0:15a06b50e14e 190 int main(void)
bennettmatt1977 0:15a06b50e14e 191 {
maxelior 1:5639bc1208d5 192 pc.baud(115200);
maxelior 1:5639bc1208d5 193
maxelior 1:5639bc1208d5 194 while(1) {
maxelior 1:5639bc1208d5 195
maxelior 2:57d040afa937 196 acquisition();
maxelior 1:5639bc1208d5 197 automate();
maxelior 2:57d040afa937 198
maxelior 2:57d040afa937 199 if(flag == 1) {
maxelior 1:5639bc1208d5 200 // initialize the modem
maxelior 1:5639bc1208d5 201 MDMParser::DevStatus devStatus = {};
maxelior 1:5639bc1208d5 202 MDMParser::NetStatus netStatus = {};
bennettmatt1977 0:15a06b50e14e 203
maxelior 1:5639bc1208d5 204 bool mdmOk = mdm.init(SIMPIN, &devStatus, D4);
maxelior 1:5639bc1208d5 205 while(mdmOk == false)mdmOk = mdm.init(SIMPIN, &devStatus, D4);
maxelior 1:5639bc1208d5 206
maxelior 1:5639bc1208d5 207 bool launchOK = mdm.checkNetStatus(&netStatus);
maxelior 1:5639bc1208d5 208 while(launchOK == false)launchOK = mdm.checkNetStatus(&netStatus);
bennettmatt1977 0:15a06b50e14e 209
maxelior 1:5639bc1208d5 210 mdm.dumpDevStatus(&devStatus);
maxelior 1:5639bc1208d5 211 if (mdmOk) {
maxelior 1:5639bc1208d5 212 mdmOk = mdm.registerNet(&netStatus);
maxelior 1:5639bc1208d5 213 mdm.dumpNetStatus(&netStatus);
maxelior 1:5639bc1208d5 214 mdm.smsSend(num1 ,chaine);
bennettmatt1977 0:15a06b50e14e 215 }
maxelior 1:5639bc1208d5 216 mdm.powerOff();
maxelior 1:5639bc1208d5 217 flag = 0;
bennettmatt1977 0:15a06b50e14e 218
bennettmatt1977 0:15a06b50e14e 219 }
bennettmatt1977 0:15a06b50e14e 220 }
bennettmatt1977 0:15a06b50e14e 221 }
maxelior 1:5639bc1208d5 222
maxelior 1:5639bc1208d5 223
maxelior 1:5639bc1208d5 224
maxelior 1:5639bc1208d5 225
maxelior 1:5639bc1208d5 226