Commit 6bba404aebff4cadd4e41c89dbf345c83d2c8ab2

Authored by omahieux
1 parent 7d26eb18

Mise à jour de LORA_terrestre

Showing 1 changed file with 25 additions and 59 deletions   Show diff stats
LORA_terrestre.ino
1 -// Feather9x_RX  
2 -// -*- mode: C++ -*-  
3 -// Example sketch showing how to create a simple messaging client (receiver)  
4 -// with the RH_RF95 class. RH_RF95 class does not provide for addressing or  
5 -// reliability, so you should only use RH_RF95 if you do not need the higher  
6 -// level messaging abilities.  
7 -// It is designed to work with the other example Feather9x_TX 1 +/*Programme implanté dans le module FEATHER Adafruit restant au sol*/
8 #include <SPI.h> 2 #include <SPI.h>
9 #include <RH_RF95.h> 3 #include <RH_RF95.h>
10 4
11 - //for feather m0 5 + //constantes pour ce module feather
12 #define RFM95_CS 8 6 #define RFM95_CS 8
13 #define RFM95_RST 4 7 #define RFM95_RST 4
14 #define RFM95_INT 3 8 #define RFM95_INT 3
15 9
16 //taille des paquets Lora envoyés à chaque émission 10 //taille des paquets Lora envoyés à chaque émission
17 -#define TAILLE_RADIOPACKET 20 11 +#define TAILLE_RADIOPACKET 100
18 12
19 -// Change to 434.0 or other frequency, must match RX's freq! 13 +// Définition de la fréquence
20 #define RF95_FREQ 434.0 14 #define RF95_FREQ 434.0
21 -// Singleton instance of the radio driver 15 +// Configuration
22 RH_RF95 rf95(RFM95_CS, RFM95_INT); 16 RH_RF95 rf95(RFM95_CS, RFM95_INT);
23 -// Blinky on receipt 17 +
24 #define LED 13 18 #define LED 13
25 19
26 20
27 21
28 -//Fonction vidage de buffer série 22 +//Fonction vidage du buffer série
29 void serialFlush(){ 23 void serialFlush(){
30 - pinMode(LED, OUTPUT); 24 + //pinMode(LED, OUTPUT);
31 while(Serial.available() > 0) { 25 while(Serial.available() > 0) {
32 char t = Serial.read(); 26 char t = Serial.read();
33 } 27 }
34 } 28 }
35 29
36 -void RAZradiopacket(uint8_t radiopacket[TAILLE_RADIOPACKET]){  
37 - int j;  
38 - for(j=0;j<TAILLE_RADIOPACKET;j++){  
39 - radiopacket[j] = '0';  
40 - }  
41 -}  
42 -  
43 -  
44 -  
45 void setup() 30 void setup()
46 { 31 {
47 pinMode(LED, OUTPUT); 32 pinMode(LED, OUTPUT);
48 pinMode(RFM95_RST, OUTPUT); 33 pinMode(RFM95_RST, OUTPUT);
49 digitalWrite(RFM95_RST, HIGH); 34 digitalWrite(RFM95_RST, HIGH);
50 while (!Serial); 35 while (!Serial);
51 -Serial.begin(9600); 36 +Serial.begin(9600); //liaison série
52 delay(100); 37 delay(100);
53 -//Serial.println("Feather LoRa RX Test!");  
54 -// manual reset  
55 digitalWrite(RFM95_RST, LOW); 38 digitalWrite(RFM95_RST, LOW);
56 delay(10); 39 delay(10);
57 digitalWrite(RFM95_RST, HIGH); 40 digitalWrite(RFM95_RST, HIGH);
@@ -60,8 +43,8 @@ while (!rf95.init()) { @@ -60,8 +43,8 @@ while (!rf95.init()) {
60 Serial.println("LoRa radio init failed"); 43 Serial.println("LoRa radio init failed");
61 while (1); 44 while (1);
62 } 45 }
63 -Serial.println("Projet IMA Ballon atmospherique ");  
64 -// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM 46 +Serial.println("Projet IMA Ballon atmospherique - 2017 ");
  47 +// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250
65 if (!rf95.setFrequency(RF95_FREQ)) { 48 if (!rf95.setFrequency(RF95_FREQ)) {
66 Serial.println("setFrequency failed"); 49 Serial.println("setFrequency failed");
67 while (1); 50 while (1);
@@ -69,17 +52,13 @@ serialFlush(); @@ -69,17 +52,13 @@ serialFlush();
69 52
70 } 53 }
71 Serial.print("Set Freq to: "); Serial.println(RF95_FREQ); 54 Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
72 -// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on  
73 -// The default transmitter power is 13dBm, using PA_BOOST.  
74 -// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then  
75 -// you can set transmitter powers from 5 to 23 dBm:  
76 -rf95.setTxPower(23, false);  
77 -//RAZradiopacket(radiopacket_tmp);  
78 -//RAZradiopacket(radiopacket);  
79 -}  
80 55
  56 +rf95.setTxPower(23, false); //Puissance d'émission à 23 dBm
  57 +
  58 +}
81 59
82 -int nb_envoi; 60 +//variables servant à ne pas envoyer deux fois la même chaîne
  61 +int nb_envoi;
83 uint8_t radiopacket[TAILLE_RADIOPACKET] ="null"; //Chaîne contenant la requête à envoyer à la nacelle 62 uint8_t radiopacket[TAILLE_RADIOPACKET] ="null"; //Chaîne contenant la requête à envoyer à la nacelle
84 uint8_t radiopacket_tmp[TAILLE_RADIOPACKET]="null"; 63 uint8_t radiopacket_tmp[TAILLE_RADIOPACKET]="null";
85 64
@@ -107,7 +86,6 @@ void loop() @@ -107,7 +86,6 @@ void loop()
107 86
108 //si la donnée reçu est différente de la précédente 87 //si la donnée reçu est différente de la précédente
109 if(memcmp(radiopacket,radiopacket_tmp,TAILLE_RADIOPACKET)!=0){ 88 if(memcmp(radiopacket,radiopacket_tmp,TAILLE_RADIOPACKET)!=0){
110 - Serial.print("\nRequete differente\n");  
111 nb_envoi = 0; 89 nb_envoi = 0;
112 } 90 }
113 91
@@ -117,41 +95,29 @@ void loop() @@ -117,41 +95,29 @@ void loop()
117 rf95.send((uint8_t *)radiopacket, sizeof(radiopacket)); 95 rf95.send((uint8_t *)radiopacket, sizeof(radiopacket));
118 Serial.print("Envoi commande\n"); 96 Serial.print("Envoi commande\n");
119 nb_envoi++; 97 nb_envoi++;
120 - Serial.print("Nb_envoi:");  
121 - Serial.println(nb_envoi);  
122 - //radiopacket[0] = '0';  
123 - //RAZradiopacket(radiopacket);  
124 - }  
125 -  
126 -  
127 - 98 + }
  99 +
128 //LECTURE DONNEES VENANT DE LA NACELLE 100 //LECTURE DONNEES VENANT DE LA NACELLE
129 if (rf95.available()) 101 if (rf95.available())
130 { 102 {
131 - // Should be a message for us now  
132 uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; 103 uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
133 uint8_t len = sizeof(buf); 104 uint8_t len = sizeof(buf);
134 if (rf95.recv(buf, &len)) 105 if (rf95.recv(buf, &len))
135 { 106 {
136 digitalWrite(LED, HIGH); 107 digitalWrite(LED, HIGH);
137 - // RH_RF95::printBuffer("Received: ", buf, len);  
138 Serial.print("Reception: "); 108 Serial.print("Reception: ");
139 Serial.println((char*)buf); 109 Serial.println((char*)buf);
140 - serialFlush();  
141 -  
142 -  
143 -  
144 - // Send a reply  
145 - //rf95.send(data, sizeof(data));  
146 - //rf95.waitPacketSent();  
147 - //Serial.println("Sent a reply");  
148 - //digitalWrite(LED, LOW);  
149 - } 110 +
  111 + //Puissance du signal lors de la dernière réception (en dBm)
  112 + Serial.print("RSSI: ");
  113 + Serial.println(rf95.lastRssi(), DEC);
  114 + }
150 else 115 else
151 { 116 {
152 Serial.println("Receive failed"); 117 Serial.println("Receive failed");
153 } 118 }
154 } 119 }
155 - delay(200); 120 + delay(100);
156 } 121 }
157 122
  123 +