Commit initial du projet
This commit is contained in:
commit
a8ed96cb5f
23 files changed
+3037
No files matched your search
@@ -0,0 +1,69 @@
|
||||
#include <SPI.h>
|
||||
#include <RH_RF95.h>
|
||||
#include <M5Stack.h>
|
||||
|
||||
//Déclaration des constantes
|
||||
//Communication avec le module LoRa
|
||||
#define RFM95_CS 5 //M5 LoRa
|
||||
#define RFM95_DIO0 36 //M5 LoRa
|
||||
RH_RF95 rf95(RFM95_CS, RFM95_DIO0);
|
||||
|
||||
//Constantes d'état
|
||||
#define EMISSION 0
|
||||
#define DELAI 1
|
||||
|
||||
uint8_t state; //État courant
|
||||
uint8_t data[16]; //Buffer d'émission
|
||||
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
Serial.println("========Emetteur CAP1========");
|
||||
M5.Lcd.println("========Emetteur CAP1========");
|
||||
|
||||
delay(1000);
|
||||
|
||||
if(!rf95.init()){
|
||||
Serial.println("Echec de la mise en place");
|
||||
M5.Lcd.println("Echec de la mise en place");
|
||||
}
|
||||
else{
|
||||
Serial.println("Mise en place reussie !!!");
|
||||
M5.Lcd.println("Mise en place reussie !!!");
|
||||
//Configuration de la radio
|
||||
rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128);
|
||||
rf95.setFrequency(867.8);
|
||||
state=EMISSION;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
switch(state){
|
||||
case EMISSION: //Code source à l'état d'émission
|
||||
Serial.println("EMISSION");
|
||||
M5.Lcd.println("EMISSION");
|
||||
data[0]=0xAA;
|
||||
data[1]=0x55;
|
||||
data[2]=0x25;
|
||||
data[3]=0x24;
|
||||
data[4]=0x98;
|
||||
rf95.send(data,5); //Envoi des données
|
||||
rf95.waitPacketSent();
|
||||
|
||||
state=DELAI;
|
||||
break;
|
||||
|
||||
case DELAI:
|
||||
Serial.println("DELAI");
|
||||
M5.Lcd.println("DELAI");
|
||||
delay(1000);
|
||||
state=EMISSION;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#include <SPI.h>
|
||||
#include <RH_RF95.h>
|
||||
#include <M5Stack.h>
|
||||
|
||||
//Déclaration des constantes
|
||||
//Communication avec le module LoRa
|
||||
#define RFM95_CS 5 //M5 LoRa
|
||||
#define RFM95_DIO0 36 //M5 LoRa
|
||||
RH_RF95 rf95(RFM95_CS, RFM95_DIO0);
|
||||
|
||||
//Déclaration des constantes
|
||||
uint8_t state; //État courant
|
||||
|
||||
uint8_t rxbuf[RH_RF95_MAX_MESSAGE_LEN]; //buffer en reception
|
||||
uint8_t rxbuflen = sizeof(rxbuf); //taille du buffer en repection
|
||||
int rxFrames; //Numéro de la trame reçue
|
||||
|
||||
//Constantes d'état
|
||||
#define ECOUTE 1
|
||||
#define TEST_RX 2 //Les différents états
|
||||
#define AFFICHAGE 3
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
Serial.println("========Recepteur CAP1========");
|
||||
M5.Lcd.println("========Recepteur CAP1========");
|
||||
|
||||
delay(1000);
|
||||
|
||||
if(!rf95.init()){
|
||||
Serial.println("Echec de la mise en place");
|
||||
M5.Lcd.println("Echec de la mise en place");
|
||||
}
|
||||
else{
|
||||
Serial.println("Mise en place reussie !!!");
|
||||
M5.Lcd.println("Mise en place reussie !!!");
|
||||
rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128);
|
||||
rf95.setFrequency(867.8);
|
||||
|
||||
state=ECOUTE;
|
||||
Serial.println("Boucle principale");
|
||||
M5.Lcd.println("Boucle principale");
|
||||
rxFrames = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
switch(state){
|
||||
|
||||
case ECOUTE:
|
||||
Serial.println("ECOUTE");
|
||||
M5.Lcd.println("ECOUTE");
|
||||
rf95.setModeRx();
|
||||
state=TEST_RX;
|
||||
break;
|
||||
|
||||
case TEST_RX:
|
||||
Serial.println("TEST-RX");
|
||||
M5.Lcd.println("TEST-RX");
|
||||
if(rf95.available()){
|
||||
state=AFFICHAGE;
|
||||
}
|
||||
//Ajout d'un delai pour laisser le temps de récupérer et d'afficher le message sur l'écran du M5
|
||||
delay(2000);
|
||||
break;
|
||||
|
||||
case AFFICHAGE:
|
||||
if(rf95.recv(rxbuf, &rxbuflen)){
|
||||
rxFrames+=1;
|
||||
|
||||
Serial.println();
|
||||
M5.Lcd.println();
|
||||
|
||||
Serial.printf("AFFICHAGE : Trame[%d] de ", rxFrames);
|
||||
M5.Lcd.printf("AFFICHAGE : Trame[%d] de ", rxFrames);
|
||||
|
||||
Serial.printf("%d octets : |",rxbuflen);
|
||||
M5.Lcd.printf("%d octets : |",rxbuflen);
|
||||
|
||||
for(int j=0;j<rxbuflen;j++){
|
||||
Serial.printf("%02x|", rxbuf[j]);
|
||||
M5.Lcd.printf("%02x|", rxbuf[j]);
|
||||
}
|
||||
Serial.println("\n");
|
||||
M5.Lcd.println("\n");
|
||||
}
|
||||
state=ECOUTE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user