RFM69HCW + radiohead

Moin Zusammen,
bin neu hier; habe mich angemeldet weil ich gerade vor einer Wand sitze.

also:

Ich habe mir zwei Adafruit Feather M0 mit RFM69HCW Modul Onboard besorgt.
Lade ich die Test Sketches aus der Library und passe sie auf die zwei Boards an, funktionieren die sauber.

Adafruit RFM69 Seite

Jetzt kam ich auf die Idee das ich senden will was über den Com Port vom Pc kommt.

das sieht bei mir dann so aus:

#include <SPI.h>
#include <RH_RF69.h>
#include <RHReliableDatagram.h>

// Change to 434.0 or other frequency, must match RX's freq!
#define RF69_FREQ 868.0

// Where to send packets to!
#define DEST_ADDRESS   1
// change addresses for each client board, any number :)
#define MY_ADDRESS     0

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
  #define LED           13
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram rf69_manager(rf69, MY_ADDRESS);

String loratx = "Hello everybody";
char radiopacket[RH_RF69_MAX_MESSAGE_LEN-10] = "Hello everybody";
int alen = RH_RF69_MAX_MESSAGE_LEN-10;
int16_t packetnum = 0;  // packet counter, we increment per xmission

int sinlen = RH_RF69_MAX_MESSAGE_LEN-10;
String sinline = ""; 
char charpack[RH_RF69_MAX_MESSAGE_LEN-10] = {0};

void setup() {
 
  Serial.begin(115200);
  while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer
 
  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);

  if (!rf69.init()) {
  Serial.println("RFM69 radio init failed");
  while (1);
  }
  Serial.println("RFM69 radio init OK!");
      
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
  Serial.println("setFrequency failed");
  }
     
  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW
     
  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);

  pinMode(LED, OUTPUT);  
  Serial.print("buf size: "); 
  Serial.println(RH_RF69_MAX_MESSAGE_LEN);
}


// Dont put this on the stack:
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t data[] = "  OK";

void loop() {
  // put your main code here, to run repeatedly:

  delay(100);

  sinline = Serial.readStringUntil('\n');
  if (sinline!=""){Serial.println(sinline);
//  Serial.println(sinline);

    
    sinlen = sinline.length()+2;
    sinline.toCharArray(charpack, sinlen);
    sinline = "";
    if (sinlen > 0){
  //    Serial.print(charpack);
  //    Serial.print(" ");
  //    Serial.println(sinlen-1);
      
      RFSend(charpack);
    }
  }
  sinlen = 0;
  
}

void Blink(byte PIN, byte DELAY_MS, byte loops) {
  for (byte i=0; i<loops; i++)  {
    digitalWrite(PIN,HIGH);
    delay(DELAY_MS);
    digitalWrite(PIN,LOW);
    delay(DELAY_MS);
  }
}

void RFSend (String loratx){

    loratx.toCharArray(radiopacket,loratx.length()+4);
    Serial.print("prepare to send: "); Serial.println(radiopacket);
    
    if (packetnum > 99){ packetnum = 1; Serial.println("packet counter reset !!!");}
    
    itoa(packetnum++, radiopacket+13, 10);
    
    Serial.print("Sending ");Serial.print(packetnum); Serial.print(" "); Serial.println(radiopacket);
    
    // Send a message!
    if (rf69_manager.sendtoWait((uint8_t *)radiopacket, 30, DEST_ADDRESS)){

    // Now wait for a reply
    
    uint8_t len = sizeof(buf);
    uint8_t from;
   
    if (rf69_manager.recvfromAckTimeout(buf, &len, 1000, &from)){ 
      // Should be a reply message for us now   
      buf[len] = 0;
      
      Serial.print("Got a reply: ");
      Serial.print(from);
      Serial.println((char*)buf);

      Serial.print(" [RSSI :");
      Serial.print(rf69.lastRssi());
      Serial.print("] : ");

      
      Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks
    } else {
      Serial.println("No reply, is anyone listening?");
    }
  } else {
    Serial.println("Sending failed (no ack)");
    Blink(LED, 100, 1);
  }
}

Hier nochmal auf CodePad falls die Formatierung hopps geht

Funktioniert aber nicht ... :stuck_out_tongue:

jemand ne Idee?

Grüße

Leo

PS: Bin nicht so tief in C++ drin kann also passieren das ich doofe Fragen stelle

Oh habe gerade herausgefunden das alles ok ist sobald ich die Broadcast adresse als Ziel angebe ...

Ich checke dann mal meine Adressen ...

Grüße

Leo

PS: vielleicht nutzt der Code ja trozdem Jemandem

#define RF69_FREQ 868.0

In machen Ländern ist das kein freier Bereich.

Stimmt - in Deutschland aber schon.
Da ich den Post im Deutschen Teil des Forum gemacht habe; stört das wirklich?