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_port = /dev/ttyUSB0
lib_deps =
lowpowerlab/RFM69@^1.5.2
lowpowerlab/SPIFlash@^101.1.3
jf002/cfRFM69@^0.1.2

View file

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