// Feather9x_RX // -*- mode: C++ -*- // Example sketch showing how to create a simple messaging client (receiver) // with the RH_RF95 class. RH_RF95 class does not provide for addressing or // reliability, so you should only use RH_RF95 if you do not need the higher // level messaging abilities. // It is designed to work with the other example Feather9x_TX #include #include //for feather m0 #define RFM95_CS 8 #define RFM95_RST 4 #define RFM95_INT 3 //taille des paquets Lora envoyés à chaque émission #define TAILLE_RADIOPACKET 20 // Change to 434.0 or other frequency, must match RX's freq! #define RF95_FREQ 434.0 // Singleton instance of the radio driver RH_RF95 rf95(RFM95_CS, RFM95_INT); // Blinky on receipt #define LED 13 //Fonction vidage de buffer série void serialFlush(){ pinMode(LED, OUTPUT); while(Serial.available() > 0) { char t = Serial.read(); } } void RAZradiopacket(uint8_t radiopacket[TAILLE_RADIOPACKET]){ int j; for(j=0;j 0) //tant qu'il y a des caractères à lire { caractere_lu = Serial.read(); //on lit le caractère radiopacket[i_chaine] = caractere_lu; Serial.print(caractere_lu); //puis on le renvoi à l’expéditeur tel quel caractere_dispo = Serial.available(); //on relit le nombre de caractères dispo i_chaine++; } radiopacket[i_chaine] = 0; // marquage fin du packet //si la donnée reçu est différente de la précédente if(memcmp(radiopacket,radiopacket_tmp,TAILLE_RADIOPACKET)!=0){ Serial.print("\nRequete differente\n"); nb_envoi = 0; } //ENVOI REQUETE if (nb_envoi==0){ rf95.send((uint8_t *)radiopacket, sizeof(radiopacket)); Serial.print("Envoi commande\n"); nb_envoi++; Serial.print("Nb_envoi:"); Serial.println(nb_envoi); //radiopacket[0] = '0'; //RAZradiopacket(radiopacket); } //LECTURE DONNEES VENANT DE LA NACELLE if (rf95.available()) { // Should be a message for us now uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (rf95.recv(buf, &len)) { digitalWrite(LED, HIGH); // RH_RF95::printBuffer("Received: ", buf, len); Serial.print("Reception: "); Serial.println((char*)buf); serialFlush(); // Send a reply //rf95.send(data, sizeof(data)); //rf95.waitPacketSent(); //Serial.println("Sent a reply"); //digitalWrite(LED, LOW); } else { Serial.println("Receive failed"); } } delay(200); }