SysBee v1

Dependencies:   C027_Support mbed

Fork of App_Pese_Ruche_SYSBEE by Sysbee

Committer:
maxelior
Date:
Fri Apr 13 07:24:04 2018 +0000
Revision:
3:8b90a40df4db
Parent:
2:57d040afa937
Child:
4:bee94a4094b6
commit

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 3:8b90a40df4db 40 #define tarage 5
maxelior 1:5639bc1208d5 41
maxelior 1:5639bc1208d5 42 AnalogIn analog_value(PC_5);
maxelior 1:5639bc1208d5 43
maxelior 1:5639bc1208d5 44 static float variation_poids=0;
maxelior 1:5639bc1208d5 45 static float poids_ruche=0;
maxelior 1:5639bc1208d5 46 static float poids_prece=0;
maxelior 1:5639bc1208d5 47
maxelior 1:5639bc1208d5 48 //const char num1[]="0652330722"; //jamoud
maxelior 1:5639bc1208d5 49 //const char num1[]="0685350930"; //paul bonnet
maxelior 1:5639bc1208d5 50 //const char num1[]="0685209401"; //benji
maxelior 1:5639bc1208d5 51 const char num1[]="0609168455"; //garsonnat
maxelior 2:57d040afa937 52 static char chaine[255];
maxelior 2:57d040afa937 53 static int flag = 0;
maxelior 2:57d040afa937 54
maxelior 2:57d040afa937 55
maxelior 2:57d040afa937 56 static int cpt=0;
maxelior 2:57d040afa937 57 static float tabPoids[2000];
maxelior 2:57d040afa937 58 static float poidsMoyenne=0;
maxelior 2:57d040afa937 59 static float offset=0;
maxelior 2:57d040afa937 60
maxelior 2:57d040afa937 61 Serial pc(USBTX, USBRX);
maxelior 2:57d040afa937 62 // Create the modem object
maxelior 2:57d040afa937 63 MDMSerial mdm;
maxelior 1:5639bc1208d5 64
maxelior 3:8b90a40df4db 65 void sendMessage()
maxelior 3:8b90a40df4db 66 {
maxelior 3:8b90a40df4db 67 // initialize the modem
maxelior 3:8b90a40df4db 68 MDMParser::DevStatus devStatus = {};
maxelior 3:8b90a40df4db 69 MDMParser::NetStatus netStatus = {};
maxelior 3:8b90a40df4db 70
maxelior 3:8b90a40df4db 71 bool mdmOk = mdm.init(SIMPIN, &devStatus, D4);
maxelior 3:8b90a40df4db 72 while(mdmOk == false)mdmOk = mdm.init(SIMPIN, &devStatus, D4);
maxelior 3:8b90a40df4db 73
maxelior 3:8b90a40df4db 74 bool launchOK = mdm.checkNetStatus(&netStatus);
maxelior 3:8b90a40df4db 75 while(launchOK == false)launchOK = mdm.checkNetStatus(&netStatus);
maxelior 3:8b90a40df4db 76
maxelior 3:8b90a40df4db 77 mdm.dumpDevStatus(&devStatus);
maxelior 3:8b90a40df4db 78 if (mdmOk) {
maxelior 3:8b90a40df4db 79 mdmOk = mdm.registerNet(&netStatus);
maxelior 3:8b90a40df4db 80 mdm.dumpNetStatus(&netStatus);
maxelior 3:8b90a40df4db 81 mdm.smsSend(num1 ,chaine);
maxelior 3:8b90a40df4db 82 }
maxelior 3:8b90a40df4db 83 mdm.powerOff();
maxelior 3:8b90a40df4db 84 flag = 0;
maxelior 3:8b90a40df4db 85 }
maxelior 1:5639bc1208d5 86
maxelior 2:57d040afa937 87 float moyennagePoids(float poids[]){
maxelior 2:57d040afa937 88
maxelior 2:57d040afa937 89 float poidsFinal;
maxelior 2:57d040afa937 90 int i=0;
maxelior 2:57d040afa937 91 for(i=0;i<2001;i++)
maxelior 2:57d040afa937 92 {
maxelior 2:57d040afa937 93 poidsFinal+=poids[i];
maxelior 2:57d040afa937 94 }
maxelior 2:57d040afa937 95 poidsFinal/=2001;
maxelior 2:57d040afa937 96 return poidsFinal;
maxelior 2:57d040afa937 97 }
maxelior 1:5639bc1208d5 98
maxelior 2:57d040afa937 99 void acquisition(){
maxelior 2:57d040afa937 100
maxelior 2:57d040afa937 101 poids_ruche=analog_value.read();
maxelior 2:57d040afa937 102 offset = poids_ruche;
maxelior 2:57d040afa937 103 poids_ruche = poids_ruche * 3300;
maxelior 3:8b90a40df4db 104 //pc.printf("Poids 1 = %2.2f mV\r\n",poids_ruche);
maxelior 2:57d040afa937 105
maxelior 3:8b90a40df4db 106 poids_ruche=((0.030151089*poids_ruche)-6.3); //0.030151089 * x - 5.7390218965
maxelior 2:57d040afa937 107 pc.printf("Poids 2 = %2.2f Kg\r\n",poids_ruche);
maxelior 2:57d040afa937 108
maxelior 2:57d040afa937 109 wait(0.5);
maxelior 2:57d040afa937 110
maxelior 2:57d040afa937 111 if(cpt<2001) {
maxelior 2:57d040afa937 112 tabPoids[cpt]=poids_ruche;
maxelior 2:57d040afa937 113 } else if(cpt==2001) {
maxelior 2:57d040afa937 114 poidsMoyenne=moyennagePoids(tabPoids);
maxelior 2:57d040afa937 115 pc.printf("Poids Moyen = %2.2f Kg\r\n",poidsMoyenne);
maxelior 2:57d040afa937 116 wait(1.5);
maxelior 2:57d040afa937 117 cpt=0;
maxelior 2:57d040afa937 118 }
maxelior 2:57d040afa937 119 cpt++;
maxelior 2:57d040afa937 120 }
maxelior 1:5639bc1208d5 121
maxelior 1:5639bc1208d5 122 void automate()
maxelior 1:5639bc1208d5 123 {
maxelior 1:5639bc1208d5 124 static int etat_ruche_courant = RVA;
maxelior 2:57d040afa937 125 static int etat_ruche_futur, etat_precedent;
maxelior 1:5639bc1208d5 126
maxelior 1:5639bc1208d5 127 etat_ruche_courant = etat_ruche_futur;
maxelior 1:5639bc1208d5 128 variation_poids = poids_ruche - poids_prece;
maxelior 1:5639bc1208d5 129 poids_prece = poids_ruche;
maxelior 1:5639bc1208d5 130
maxelior 1:5639bc1208d5 131 switch(etat_ruche_courant) {
maxelior 1:5639bc1208d5 132
maxelior 1:5639bc1208d5 133 case RVA:
maxelior 1:5639bc1208d5 134 if(poids_ruche < 40) {
maxelior 3:8b90a40df4db 135 if(variation_poids < -2)
maxelior 2:57d040afa937 136 { etat_precedent = RVA;
maxelior 2:57d040afa937 137 etat_ruche_futur = essaimage;
maxelior 2:57d040afa937 138 }
maxelior 1:5639bc1208d5 139 if(variation_poids > 0) {
maxelior 1:5639bc1208d5 140 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 141 }
maxelior 1:5639bc1208d5 142 if(variation_poids == 0) {
maxelior 1:5639bc1208d5 143 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 144 }
maxelior 1:5639bc1208d5 145 }
maxelior 1:5639bc1208d5 146 if(poids_ruche >= 40) {
maxelior 1:5639bc1208d5 147
maxelior 1:5639bc1208d5 148 sprintf(chaine, "recolte hausse n1\r\n poids = %2.f", poids_ruche);
maxelior 1:5639bc1208d5 149 flag = 1;
maxelior 1:5639bc1208d5 150 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 151 }
maxelior 1:5639bc1208d5 152
maxelior 1:5639bc1208d5 153 break;
maxelior 1:5639bc1208d5 154
maxelior 1:5639bc1208d5 155 case RPHVA:
maxelior 1:5639bc1208d5 156 if(poids_ruche < 56) {
maxelior 3:8b90a40df4db 157 if(variation_poids < -2)
maxelior 2:57d040afa937 158 { etat_precedent = RPHVA;
maxelior 2:57d040afa937 159 etat_ruche_futur = essaimage;
maxelior 2:57d040afa937 160 }
maxelior 1:5639bc1208d5 161 if(variation_poids > 0) {
maxelior 1:5639bc1208d5 162 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 163 }
maxelior 1:5639bc1208d5 164 if(variation_poids == 0) {
maxelior 1:5639bc1208d5 165 etat_ruche_futur = RPHVA;
maxelior 1:5639bc1208d5 166 }
maxelior 1:5639bc1208d5 167 }
maxelior 1:5639bc1208d5 168 if(poids_ruche >= 56) {
maxelior 1:5639bc1208d5 169 sprintf(chaine, "recolte hausse n2\r\n poids = %2.f", poids_ruche);
maxelior 1:5639bc1208d5 170 flag = 1;
maxelior 1:5639bc1208d5 171 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 172 }
maxelior 1:5639bc1208d5 173
maxelior 1:5639bc1208d5 174 break;
maxelior 1:5639bc1208d5 175
maxelior 1:5639bc1208d5 176 case RPHPHVA:
maxelior 1:5639bc1208d5 177 if(poids_ruche < 72) {
maxelior 3:8b90a40df4db 178 if(variation_poids < -2)
maxelior 2:57d040afa937 179 { etat_precedent = RPHPHVA;
maxelior 2:57d040afa937 180 etat_ruche_futur = essaimage;
maxelior 2:57d040afa937 181 }
maxelior 1:5639bc1208d5 182 if(variation_poids > 0) {
maxelior 1:5639bc1208d5 183 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 184 }
maxelior 1:5639bc1208d5 185 if(variation_poids == 0) {
maxelior 1:5639bc1208d5 186 etat_ruche_futur = RPHPHVA;
maxelior 1:5639bc1208d5 187 }
maxelior 1:5639bc1208d5 188 }
maxelior 1:5639bc1208d5 189 if(poids_ruche > 72) {
maxelior 1:5639bc1208d5 190 sprintf(chaine, "recolte hausse n1 & n2\r\n poids = %2.f", poids_ruche);
maxelior 1:5639bc1208d5 191 flag = 1;
maxelior 1:5639bc1208d5 192 etat_ruche_futur = RVA;
maxelior 1:5639bc1208d5 193 }
maxelior 1:5639bc1208d5 194 break;
maxelior 2:57d040afa937 195 case essaimage:
maxelior 2:57d040afa937 196 sprintf(chaine, "BELEK essaimage !!! \r\n");
maxelior 2:57d040afa937 197 flag = 1;
maxelior 2:57d040afa937 198 etat_ruche_futur = etat_precedent;
maxelior 2:57d040afa937 199 break;
maxelior 1:5639bc1208d5 200 }
maxelior 1:5639bc1208d5 201 }
bennettmatt1977 0:15a06b50e14e 202
bennettmatt1977 0:15a06b50e14e 203 int main(void)
bennettmatt1977 0:15a06b50e14e 204 {
maxelior 1:5639bc1208d5 205 pc.baud(115200);
maxelior 1:5639bc1208d5 206
maxelior 1:5639bc1208d5 207 while(1) {
maxelior 1:5639bc1208d5 208
maxelior 2:57d040afa937 209 acquisition();
maxelior 1:5639bc1208d5 210 automate();
maxelior 2:57d040afa937 211
maxelior 3:8b90a40df4db 212 if(flag == 1) {
maxelior 3:8b90a40df4db 213 sendMessage();
bennettmatt1977 0:15a06b50e14e 214 }
bennettmatt1977 0:15a06b50e14e 215 }
bennettmatt1977 0:15a06b50e14e 216 }
maxelior 1:5639bc1208d5 217
maxelior 1:5639bc1208d5 218
maxelior 1:5639bc1208d5 219
maxelior 1:5639bc1208d5 220
maxelior 1:5639bc1208d5 221