SysBee v1
Dependencies: C027_Support mbed
Fork of App_Pese_Ruche_SYSBEE by
main.cpp@1:5639bc1208d5, 2018-04-11 (annotated)
- Committer:
- maxelior
- Date:
- Wed Apr 11 08:44:24 2018 +0000
- Revision:
- 1:5639bc1208d5
- Parent:
- 0:15a06b50e14e
- Child:
- 2:57d040afa937
version fonctionnelle sans essaimage et sans gps
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:5639bc1208d5 | 39 | |
maxelior | 1:5639bc1208d5 | 40 | AnalogIn analog_value(PC_5); |
maxelior | 1:5639bc1208d5 | 41 | |
maxelior | 1:5639bc1208d5 | 42 | static float variation_poids=0; |
maxelior | 1:5639bc1208d5 | 43 | static float poids_ruche=0; |
maxelior | 1:5639bc1208d5 | 44 | static float poids_prece=0; |
maxelior | 1:5639bc1208d5 | 45 | |
maxelior | 1:5639bc1208d5 | 46 | //const char num1[]="0652330722"; //jamoud |
maxelior | 1:5639bc1208d5 | 47 | //const char num1[]="0685350930"; //paul bonnet |
maxelior | 1:5639bc1208d5 | 48 | //const char num1[]="0685209401"; //benji |
maxelior | 1:5639bc1208d5 | 49 | const char num1[]="0609168455"; //garsonnat |
maxelior | 1:5639bc1208d5 | 50 | |
maxelior | 1:5639bc1208d5 | 51 | |
maxelior | 1:5639bc1208d5 | 52 | static char chaine[255]; |
maxelior | 1:5639bc1208d5 | 53 | |
maxelior | 1:5639bc1208d5 | 54 | static int flag = 0; |
maxelior | 1:5639bc1208d5 | 55 | |
maxelior | 1:5639bc1208d5 | 56 | void automate() |
maxelior | 1:5639bc1208d5 | 57 | { |
maxelior | 1:5639bc1208d5 | 58 | static int etat_ruche_courant = RVA; |
maxelior | 1:5639bc1208d5 | 59 | static int etat_ruche_futur; |
maxelior | 1:5639bc1208d5 | 60 | |
maxelior | 1:5639bc1208d5 | 61 | etat_ruche_courant = etat_ruche_futur; |
maxelior | 1:5639bc1208d5 | 62 | variation_poids = poids_ruche - poids_prece; |
maxelior | 1:5639bc1208d5 | 63 | poids_prece = poids_ruche; |
maxelior | 1:5639bc1208d5 | 64 | |
maxelior | 1:5639bc1208d5 | 65 | switch(etat_ruche_courant) { |
maxelior | 1:5639bc1208d5 | 66 | |
maxelior | 1:5639bc1208d5 | 67 | case RVA: |
maxelior | 1:5639bc1208d5 | 68 | if(poids_ruche < 40) { |
maxelior | 1:5639bc1208d5 | 69 | if(variation_poids > 0) { |
maxelior | 1:5639bc1208d5 | 70 | etat_ruche_futur = RVA; |
maxelior | 1:5639bc1208d5 | 71 | } |
maxelior | 1:5639bc1208d5 | 72 | if(variation_poids < 0) { |
maxelior | 1:5639bc1208d5 | 73 | etat_ruche_futur = RVA; |
maxelior | 1:5639bc1208d5 | 74 | } |
maxelior | 1:5639bc1208d5 | 75 | if(variation_poids == 0) { |
maxelior | 1:5639bc1208d5 | 76 | etat_ruche_futur = RVA; |
maxelior | 1:5639bc1208d5 | 77 | } |
maxelior | 1:5639bc1208d5 | 78 | } |
maxelior | 1:5639bc1208d5 | 79 | if(poids_ruche >= 40) { |
maxelior | 1:5639bc1208d5 | 80 | |
maxelior | 1:5639bc1208d5 | 81 | sprintf(chaine, "recolte hausse n1\r\n poids = %2.f", poids_ruche); |
maxelior | 1:5639bc1208d5 | 82 | flag = 1; |
maxelior | 1:5639bc1208d5 | 83 | etat_ruche_futur = RPHVA; |
maxelior | 1:5639bc1208d5 | 84 | } |
maxelior | 1:5639bc1208d5 | 85 | |
maxelior | 1:5639bc1208d5 | 86 | break; |
maxelior | 1:5639bc1208d5 | 87 | |
maxelior | 1:5639bc1208d5 | 88 | case RPHVA: |
maxelior | 1:5639bc1208d5 | 89 | if(poids_ruche < 56) { |
maxelior | 1:5639bc1208d5 | 90 | if(variation_poids > 0) { |
maxelior | 1:5639bc1208d5 | 91 | etat_ruche_futur = RPHVA; |
maxelior | 1:5639bc1208d5 | 92 | } |
maxelior | 1:5639bc1208d5 | 93 | if(variation_poids < 0) { |
maxelior | 1:5639bc1208d5 | 94 | etat_ruche_futur = RPHVA; |
maxelior | 1:5639bc1208d5 | 95 | } |
maxelior | 1:5639bc1208d5 | 96 | if(variation_poids == 0) { |
maxelior | 1:5639bc1208d5 | 97 | etat_ruche_futur = RPHVA; |
maxelior | 1:5639bc1208d5 | 98 | } |
maxelior | 1:5639bc1208d5 | 99 | } |
maxelior | 1:5639bc1208d5 | 100 | if(poids_ruche >= 56) { |
maxelior | 1:5639bc1208d5 | 101 | sprintf(chaine, "recolte hausse n2\r\n poids = %2.f", poids_ruche); |
maxelior | 1:5639bc1208d5 | 102 | flag = 1; |
maxelior | 1:5639bc1208d5 | 103 | etat_ruche_futur = RPHPHVA; |
maxelior | 1:5639bc1208d5 | 104 | } |
maxelior | 1:5639bc1208d5 | 105 | |
maxelior | 1:5639bc1208d5 | 106 | break; |
maxelior | 1:5639bc1208d5 | 107 | |
maxelior | 1:5639bc1208d5 | 108 | case RPHPHVA: |
maxelior | 1:5639bc1208d5 | 109 | if(poids_ruche < 72) { |
maxelior | 1:5639bc1208d5 | 110 | if(variation_poids > 0) { |
maxelior | 1:5639bc1208d5 | 111 | etat_ruche_futur = RPHPHVA; |
maxelior | 1:5639bc1208d5 | 112 | } |
maxelior | 1:5639bc1208d5 | 113 | if(variation_poids < 0) { |
maxelior | 1:5639bc1208d5 | 114 | etat_ruche_futur = RPHPHVA; |
maxelior | 1:5639bc1208d5 | 115 | } |
maxelior | 1:5639bc1208d5 | 116 | if(variation_poids == 0) { |
maxelior | 1:5639bc1208d5 | 117 | etat_ruche_futur = RPHPHVA; |
maxelior | 1:5639bc1208d5 | 118 | } |
maxelior | 1:5639bc1208d5 | 119 | } |
maxelior | 1:5639bc1208d5 | 120 | if(poids_ruche > 72) { |
maxelior | 1:5639bc1208d5 | 121 | sprintf(chaine, "recolte hausse n1 & n2\r\n poids = %2.f", poids_ruche); |
maxelior | 1:5639bc1208d5 | 122 | flag = 1; |
maxelior | 1:5639bc1208d5 | 123 | etat_ruche_futur = RVA; |
maxelior | 1:5639bc1208d5 | 124 | } |
maxelior | 1:5639bc1208d5 | 125 | break; |
maxelior | 1:5639bc1208d5 | 126 | } |
maxelior | 1:5639bc1208d5 | 127 | } |
bennettmatt1977 | 0:15a06b50e14e | 128 | |
bennettmatt1977 | 0:15a06b50e14e | 129 | int main(void) |
bennettmatt1977 | 0:15a06b50e14e | 130 | { |
maxelior | 1:5639bc1208d5 | 131 | Serial pc(USBTX, USBRX); |
maxelior | 1:5639bc1208d5 | 132 | pc.baud(115200); |
bennettmatt1977 | 0:15a06b50e14e | 133 | // Create the modem object |
bennettmatt1977 | 0:15a06b50e14e | 134 | MDMSerial mdm; |
maxelior | 1:5639bc1208d5 | 135 | |
maxelior | 1:5639bc1208d5 | 136 | while(1) { |
maxelior | 1:5639bc1208d5 | 137 | |
maxelior | 1:5639bc1208d5 | 138 | poids_ruche=analog_value.read(); |
maxelior | 1:5639bc1208d5 | 139 | poids_ruche = poids_ruche * 3300; |
maxelior | 1:5639bc1208d5 | 140 | poids_ruche=(0.03*poids_ruche)-6.02; |
maxelior | 1:5639bc1208d5 | 141 | wait(1); |
maxelior | 1:5639bc1208d5 | 142 | pc.printf("%2.2f \r\n",poids_ruche); |
maxelior | 1:5639bc1208d5 | 143 | automate(); |
maxelior | 1:5639bc1208d5 | 144 | if(flag == 1) { |
maxelior | 1:5639bc1208d5 | 145 | // initialize the modem |
maxelior | 1:5639bc1208d5 | 146 | MDMParser::DevStatus devStatus = {}; |
maxelior | 1:5639bc1208d5 | 147 | MDMParser::NetStatus netStatus = {}; |
bennettmatt1977 | 0:15a06b50e14e | 148 | |
maxelior | 1:5639bc1208d5 | 149 | bool mdmOk = mdm.init(SIMPIN, &devStatus, D4); |
maxelior | 1:5639bc1208d5 | 150 | while(mdmOk == false)mdmOk = mdm.init(SIMPIN, &devStatus, D4); |
maxelior | 1:5639bc1208d5 | 151 | |
maxelior | 1:5639bc1208d5 | 152 | bool launchOK = mdm.checkNetStatus(&netStatus); |
maxelior | 1:5639bc1208d5 | 153 | while(launchOK == false)launchOK = mdm.checkNetStatus(&netStatus); |
bennettmatt1977 | 0:15a06b50e14e | 154 | |
maxelior | 1:5639bc1208d5 | 155 | mdm.dumpDevStatus(&devStatus); |
maxelior | 1:5639bc1208d5 | 156 | if (mdmOk) { |
maxelior | 1:5639bc1208d5 | 157 | mdmOk = mdm.registerNet(&netStatus); |
maxelior | 1:5639bc1208d5 | 158 | mdm.dumpNetStatus(&netStatus); |
maxelior | 1:5639bc1208d5 | 159 | mdm.smsSend(num1 ,chaine); |
bennettmatt1977 | 0:15a06b50e14e | 160 | } |
maxelior | 1:5639bc1208d5 | 161 | mdm.powerOff(); |
maxelior | 1:5639bc1208d5 | 162 | flag = 0; |
bennettmatt1977 | 0:15a06b50e14e | 163 | |
bennettmatt1977 | 0:15a06b50e14e | 164 | } |
bennettmatt1977 | 0:15a06b50e14e | 165 | } |
bennettmatt1977 | 0:15a06b50e14e | 166 | } |
maxelior | 1:5639bc1208d5 | 167 | |
maxelior | 1:5639bc1208d5 | 168 | |
maxelior | 1:5639bc1208d5 | 169 | |
maxelior | 1:5639bc1208d5 | 170 | |
maxelior | 1:5639bc1208d5 | 171 |