Different RFM69 library

This commit is contained in:
Paul Warren 2022-12-31 14:23:45 +11:00
parent 84da1314f0
commit 18b537c359
2 changed files with 27 additions and 59 deletions

View file

@ -15,5 +15,5 @@ framework = arduino
upload_speed = 57600 upload_speed = 57600
upload_port = /dev/ttyUSB0 upload_port = /dev/ttyUSB0
lib_deps = lib_deps =
lowpowerlab/RFM69@^1.5.2
lowpowerlab/SPIFlash@^101.1.3 lowpowerlab/SPIFlash@^101.1.3
jf002/cfRFM69@^0.1.2

View file

@ -1,78 +1,46 @@
#include <Arduino.h> #include <Arduino.h>
#include <RFM69.h> #include <RFM69.h>
#include <RFM69_ATC.h> #include <SPI.h>
#include <SPIFlash.h>
#define NODEID 122
#define FREQUENCY RF69_915MHZ
#define SERIAL_BAUD 115200 #define SERIAL_BAUD 115200
//#define IS_RFM69HW_HCW
RFM69 radio; using namespace Codingfield::Communication;
int networkID = 1; SPIClass spi(HSPI);
long tryCount = 0; std::unique_ptr<CodingField::Communication::RFM69> radio;
int packetCount = 0;
bool found = false;
//SPIFlash flash(SS_FLASHMEM, 0xEF30);
void initRadio() {
radio.initialize(FREQUENCY,NODEID,networkID);
radio.spyMode(true);
//radio.setFrequency(915230000);
}
void setup() { void setup() {
Serial.begin(SERIAL_BAUD); Serial.begin(SERIAL_BAUD);
delay(10); delay(10);
Serial.println("Init started"); Serial.println("Init started");
initRadio(); spi.begin();
char buff[50]; radio.reset(new RFM69($spi, 15));
sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(buff);
byte temperature = radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient
Serial.print( "Radio Temp is ");
Serial.print(temperature);
Serial.println("C");
uint32_t freq = radio.getFrequency(); if(radio->IsRfm69()) {
Serial.print("Listening Frequency: "); auto temperature = radio->ReadTemperature();
Serial.println(freq); Serial.println("Temp: " + String(temperature));
// Turn off LED radio->SetOperatingMode(RFM69::Standby);
pinMode(LED_BUILTIN, OUTPUT); radio->SetDataModulation(RFM69::ModulationShapings::NoShaping,
digitalWrite(LED_BUILTIN, LOW); RFM69::ModulationTypes::FSK,
RFM69DataModes::Packet);
radio->setBitRate(0x0116); // 115200
radio->setFrequencyDevian(0x047C); // 70kHz
radio->setFrequency(0x00d913e8); // 915.25MHz
radio->SetOperatingMode();
} else {
Serial.println("No RFM69 found");
}
Serial.println("Starting loop()"); Serial.println("Starting loop()");
} }
void loop() { void loop() {
delay(1000);
if (radio.receiveDone()) Serial.println("Loop");
{
Serial.print("#[");
Serial.print(++packetCount);
Serial.print(']');
Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
Serial.print("to [");Serial.print(radio.TARGETID, DEC);Serial.print("] ");
for (byte i = 0; i < radio.DATALEN; i++)
Serial.print((char)radio.DATA[i]);
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
}
tryCount++;
if (tryCount > 180000) {
Serial.print("Network: ");
Serial.print(networkID);
Serial.println(" No packets heard, incrementing");
tryCount = 0;
networkID++;
if (networkID == 256)
networkID=1;
initRadio();
}
} }