Ruche connectée 2 correction de poids
Dependencies: mbed Message HX711 DHT22 GPS
main.cpp@2:3248370d6bc4, 2019-02-01 (annotated)
- Committer:
- Sidibe
- Date:
- Fri Feb 01 17:14:30 2019 +0000
- Revision:
- 2:3248370d6bc4
- Parent:
- 1:25a290929b47
- Child:
- 3:33d642087cca
correction de poids
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sidibe | 0:126a8e290bd5 | 1 | #include "mbed.h" |
Sidibe | 0:126a8e290bd5 | 2 | #include <iostream> |
Sidibe | 0:126a8e290bd5 | 3 | #include <vector> |
Sidibe | 0:126a8e290bd5 | 4 | #include "sigfox.h" |
Sidibe | 0:126a8e290bd5 | 5 | #include "SoftSerial.h" |
Sidibe | 0:126a8e290bd5 | 6 | #include "message_1.h" |
Sidibe | 0:126a8e290bd5 | 7 | #include "message_2.h" |
Sidibe | 0:126a8e290bd5 | 8 | #include "DHT22.h" |
Sidibe | 0:126a8e290bd5 | 9 | #include "HX711.h" |
Sidibe | 0:126a8e290bd5 | 10 | #include "DS1820.h" |
Sidibe | 0:126a8e290bd5 | 11 | |
Sidibe | 0:126a8e290bd5 | 12 | using namespace std; |
Sidibe | 0:126a8e290bd5 | 13 | |
Sidibe | 0:126a8e290bd5 | 14 | void mesureTempExtHumidite(int &humidite, float &temperature); |
Sidibe | 0:126a8e290bd5 | 15 | void mesureTempInt(float &temperatureInt); |
Sidibe | 0:126a8e290bd5 | 16 | void mesureMasse(float &masse, long valeurTare); |
Sidibe | 0:126a8e290bd5 | 17 | void mesureGps(float &longit, float &lat); |
Sidibe | 2:3248370d6bc4 | 18 | DigitalOut myled(D13); |
Sidibe | 0:126a8e290bd5 | 19 | //Serial sc(SERIAL_TX, SERIAL_RX, 9600); |
Sidibe | 0:126a8e290bd5 | 20 | //Serial device(PA_9, PA_10); |
Sidibe | 0:126a8e290bd5 | 21 | DHT22 dht22(D3); |
Sidibe | 0:126a8e290bd5 | 22 | HX711 Balance(D12,D11); |
Sidibe | 0:126a8e290bd5 | 23 | DS1820 probe = A6; |
Sidibe | 0:126a8e290bd5 | 24 | |
Sidibe | 0:126a8e290bd5 | 25 | //SoftSerial device(D3, D4); |
Sidibe | 0:126a8e290bd5 | 26 | //Serial sc2(D5, D4); |
Sidibe | 0:126a8e290bd5 | 27 | |
Sidibe | 2:3248370d6bc4 | 28 | ///////////Déclaration des Variables Correction de la masse |
Sidibe | 2:3248370d6bc4 | 29 | |
Sidibe | 2:3248370d6bc4 | 30 | float temperature_actuelle=12; |
Sidibe | 2:3248370d6bc4 | 31 | float temperature_prvious=0; |
Sidibe | 2:3248370d6bc4 | 32 | float delta =0; |
Sidibe | 2:3248370d6bc4 | 33 | float asser_err= -0.15; |
Sidibe | 2:3248370d6bc4 | 34 | float masse_reelle=0; |
Sidibe | 2:3248370d6bc4 | 35 | /////////////////// |
Sidibe | 0:126a8e290bd5 | 36 | |
Sidibe | 0:126a8e290bd5 | 37 | int main() { |
Sidibe | 0:126a8e290bd5 | 38 | // device.baud(9600); |
Sidibe | 0:126a8e290bd5 | 39 | //sc.printf("---New start ---\n"); |
Sidibe | 0:126a8e290bd5 | 40 | // while (!device.writeable()) { } |
Sidibe | 0:126a8e290bd5 | 41 | //sc.printf("coucou 1 \n"); |
Sidibe | 0:126a8e290bd5 | 42 | |
Sidibe | 0:126a8e290bd5 | 43 | /* device.printf("AT\r");; |
Sidibe | 0:126a8e290bd5 | 44 | char a = device.getc(); |
Sidibe | 0:126a8e290bd5 | 45 | char b = device.getc(); |
Sidibe | 0:126a8e290bd5 | 46 | sc.printf("%c%c \n", a, b); |
Sidibe | 0:126a8e290bd5 | 47 | sc.printf("%c", device.getc()); |
Sidibe | 0:126a8e290bd5 | 48 | */ |
Sidibe | 0:126a8e290bd5 | 49 | float longit = 12.3, lat = 18.6; |
Sidibe | 0:126a8e290bd5 | 50 | int humidite= 18; |
Sidibe | 0:126a8e290bd5 | 51 | float temperatureExt = 12; |
Sidibe | 0:126a8e290bd5 | 52 | float temperatureInt = 15; |
Sidibe | 2:3248370d6bc4 | 53 | //coefficient asservissement |
Sidibe | 2:3248370d6bc4 | 54 | |
Sidibe | 0:126a8e290bd5 | 55 | |
Sidibe | 0:126a8e290bd5 | 56 | long valeur; |
Sidibe | 0:126a8e290bd5 | 57 | long valeurTare ; |
Sidibe | 2:3248370d6bc4 | 58 | float masse=13.2; |
Sidibe | 2:3248370d6bc4 | 59 | |
Sidibe | 0:126a8e290bd5 | 60 | |
Sidibe | 0:126a8e290bd5 | 61 | valeurTare = Balance.getValue(); |
Sidibe | 0:126a8e290bd5 | 62 | probe.search_ROM(); |
Sidibe | 0:126a8e290bd5 | 63 | char temp; |
Sidibe | 0:126a8e290bd5 | 64 | while(1) { |
Sidibe | 0:126a8e290bd5 | 65 | mesureTempExtHumidite(humidite, temperatureExt); |
Sidibe | 0:126a8e290bd5 | 66 | mesureMasse(masse, valeurTare); |
Sidibe | 0:126a8e290bd5 | 67 | mesureTempInt(temperatureInt); |
Sidibe | 0:126a8e290bd5 | 68 | //sc.printf("temperature externe: %.2f humidity: %d temperature interne: %.2f \n\r",temperatureExt, humidite, temperatureInt); |
Sidibe | 0:126a8e290bd5 | 69 | //sc.printf("masse: %f\n\r", masse); |
Sidibe | 2:3248370d6bc4 | 70 | |
Sidibe | 2:3248370d6bc4 | 71 | //////Correction des la masse |
Sidibe | 2:3248370d6bc4 | 72 | |
Sidibe | 2:3248370d6bc4 | 73 | temperature_actuelle=temperatureExt; |
Sidibe | 2:3248370d6bc4 | 74 | |
Sidibe | 2:3248370d6bc4 | 75 | |
Sidibe | 2:3248370d6bc4 | 76 | |
Sidibe | 2:3248370d6bc4 | 77 | delta=temperature_actuelle-temperature_prvious; |
Sidibe | 2:3248370d6bc4 | 78 | |
Sidibe | 2:3248370d6bc4 | 79 | masse_reelle=masse+(delta*asser_err); |
Sidibe | 2:3248370d6bc4 | 80 | |
Sidibe | 2:3248370d6bc4 | 81 | temperature_prvious=temperature_actuelle; |
Sidibe | 2:3248370d6bc4 | 82 | ////// |
Sidibe | 0:126a8e290bd5 | 83 | |
Sidibe | 2:3248370d6bc4 | 84 | //Message_1 msg1(1, temperatureExt, temperatureInt, humidite, masse);//envoyé données sigfox sans la correction de la masse |
Sidibe | 2:3248370d6bc4 | 85 | |
Sidibe | 2:3248370d6bc4 | 86 | Message_1 msg1(1, temperatureExt, temperatureInt, humidite, masse_reelle); |
Sidibe | 0:126a8e290bd5 | 87 | msg1.send(); |
Sidibe | 0:126a8e290bd5 | 88 | |
Sidibe | 2:3248370d6bc4 | 89 | myled = 1 ; |
Sidibe | 2:3248370d6bc4 | 90 | wait(15); |
Sidibe | 2:3248370d6bc4 | 91 | myled = 0 ; |
Sidibe | 0:126a8e290bd5 | 92 | } |
Sidibe | 0:126a8e290bd5 | 93 | } |
Sidibe | 0:126a8e290bd5 | 94 | |
Sidibe | 0:126a8e290bd5 | 95 | void mesureTempExtHumidite(int &humidite, float &temperatureExt){ |
Sidibe | 2:3248370d6bc4 | 96 | |
Sidibe | 0:126a8e290bd5 | 97 | dht22.sample() ; |
Sidibe | 0:126a8e290bd5 | 98 | humidite=dht22.getHumidity()/10.0; |
Sidibe | 0:126a8e290bd5 | 99 | temperatureExt=dht22.getTemperature()/10.0; |
Sidibe | 2:3248370d6bc4 | 100 | |
Sidibe | 0:126a8e290bd5 | 101 | // humidite = 57; |
Sidibe | 0:126a8e290bd5 | 102 | // temperatureExt = 17; |
Sidibe | 0:126a8e290bd5 | 103 | }; |
Sidibe | 0:126a8e290bd5 | 104 | |
Sidibe | 2:3248370d6bc4 | 105 | |
Sidibe | 0:126a8e290bd5 | 106 | void mesureMasse(float &masse, long valeurTare){ |
Sidibe | 2:3248370d6bc4 | 107 | |
Sidibe | 0:126a8e290bd5 | 108 | wait_ms(200); // Attente de 200 millisecondes |
Sidibe | 0:126a8e290bd5 | 109 | float valeur = Balance.getValue(); // On récupère la valeur du module |
Sidibe | 2:3248370d6bc4 | 110 | masse = ((double)valeur-(double)valeurTare)/-11900; |
Sidibe | 2:3248370d6bc4 | 111 | |
Sidibe | 0:126a8e290bd5 | 112 | }; |
Sidibe | 0:126a8e290bd5 | 113 | |
Sidibe | 0:126a8e290bd5 | 114 | void mesureTempInt(float &temperatureInt){ |
Sidibe | 0:126a8e290bd5 | 115 | probe.convert_temperature(DS1820::all_devices); |
Sidibe | 0:126a8e290bd5 | 116 | temperatureInt = probe.temperature('c'); |
Sidibe | 0:126a8e290bd5 | 117 | }; |
Sidibe | 0:126a8e290bd5 | 118 | |
Sidibe | 0:126a8e290bd5 | 119 | void mesureGps(float &longit, float &lat){ |
Sidibe | 0:126a8e290bd5 | 120 | }; |
Sidibe | 0:126a8e290bd5 | 121 | |
Sidibe | 0:126a8e290bd5 | 122 | /*bool sendMessageToSigfox(Vector<Message*> msg){ |
Sidibe | 0:126a8e290bd5 | 123 | for(int i =0; i<msg.size(); i++){ |
Sidibe | 0:126a8e290bd5 | 124 | msg[i].send(); |
Sidibe | 0:126a8e290bd5 | 125 | wait_ms(100); |
Sidibe | 0:126a8e290bd5 | 126 | }; |
Sidibe | 0:126a8e290bd5 | 127 | };*/ |