it works now
This commit is contained in:
@@ -3,13 +3,17 @@
|
||||
#include <string>
|
||||
|
||||
/* for feather m0 */
|
||||
#define RFM95_CS 8
|
||||
#define RFM95_RST 4
|
||||
#define RFM95_INT 3
|
||||
//#define RFM95_CS 8
|
||||
const int RFM95_CS = 8;
|
||||
//#define RFM95_RST 4
|
||||
const int RFM95_RST = 4;
|
||||
//#define RFM95_INT 3
|
||||
const int RFM95_INT = 3;
|
||||
|
||||
|
||||
// Change to 434.0 or other frequency, must match RX's freq!
|
||||
#define RF95_FREQ 915.0
|
||||
|
||||
//#define RF95_FREQ 915.0
|
||||
const float RF95_FREQ = 915.0;
|
||||
// Lower bandwidth means longer distance but lower data rate
|
||||
// Valid values are:
|
||||
// 0-7800khz: 7.8
|
||||
@@ -22,17 +26,18 @@
|
||||
// 62501-12500 125.0 DEFAULT
|
||||
// 12501-250000 250.0
|
||||
// >250000 500.0
|
||||
#define RF95_BANDWIDTH 62.5
|
||||
// #define RF95_BANDWIDTH 125
|
||||
const long RF95_BANDWIDTH = 125;
|
||||
|
||||
// Higher spread factor means longer distance
|
||||
// Valid values are 6-12
|
||||
#define RF95_SPREAD_FACTOR 12
|
||||
// #define RF95_SPREAD_FACTOR 6
|
||||
const uint8_t RF95_SPREAD_FACTOR = 7;
|
||||
|
||||
// Higher TX power means longer distance
|
||||
// Valid values are 5-23
|
||||
#define RF95_TX_POWER 23
|
||||
|
||||
// Make sure you run setLowDatarate() when going for long distance
|
||||
// #define RF95_TX_POWER 23
|
||||
const int8_t RF95_TX_POWER = 23;
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS, RFM95_INT);
|
||||
@@ -68,19 +73,19 @@ void setup() {
|
||||
Serial.print("Set Freq to: ");
|
||||
Serial.println(RF95_FREQ);
|
||||
|
||||
// Set the signal bandwidth
|
||||
rf95.setSignalBandwidth(RF95_BANDWIDTH);
|
||||
Serial.print("Set bandwidth to: ");
|
||||
Serial.println(RF95_BANDWIDTH);
|
||||
// //Set the signal bandwidth
|
||||
// rf95.setSignalBandwidth(RF95_BANDWIDTH);
|
||||
// Serial.print("Set bandwidth to: ");
|
||||
// Serial.println(RF95_BANDWIDTH);
|
||||
|
||||
// Set the signal bandwidth
|
||||
rf95.setSpreadingFactor(RF95_SPREAD_FACTOR);
|
||||
Serial.print("Set spreading factor to: ");
|
||||
Serial.println(RF95_SPREAD_FACTOR);
|
||||
// // Set the spreading factor
|
||||
// rf95.setSpreadingFactor(RF95_SPREAD_FACTOR);
|
||||
// Serial.print("Set spreading factor to: ");
|
||||
// Serial.println(RF95_SPREAD_FACTOR);
|
||||
|
||||
// Set low transmission rate
|
||||
rf95.setLowDatarate();
|
||||
Serial.println("Set low data rate");
|
||||
// rf95.setLowDatarate();
|
||||
// Serial.println("Set low data rate");
|
||||
|
||||
// The default transmitter power is 13dBm, using PA_BOOST.
|
||||
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
|
||||
@@ -108,7 +113,7 @@ void loop() {
|
||||
|
||||
Serial.println("Welcome " + chat_name);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
rf95.send((uint8_t *)reinterpret_cast<const uint8_t *>(&intro_message), RH_RF95_MAX_MESSAGE_LEN);
|
||||
rf95.send((uint8_t *)(intro_message.c_str()), RH_RF95_MAX_MESSAGE_LEN);
|
||||
rf95.waitPacketSent();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
@@ -120,12 +125,13 @@ void loop() {
|
||||
String send_message = chat_name + ": " + chat_message;
|
||||
|
||||
Serial.println(send_message);
|
||||
rf95.send((uint8_t *)reinterpret_cast<const uint8_t *>(&send_message), RH_RF95_MAX_MESSAGE_LEN);
|
||||
rf95.send((uint8_t *)(send_message.c_str()), RH_RF95_MAX_MESSAGE_LEN);
|
||||
rf95.waitPacketSent();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
}
|
||||
// Receiver code
|
||||
delay(100);
|
||||
if (rf95.available()) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
// Should be a message for us now
|
||||
@@ -133,10 +139,10 @@ void loop() {
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
if (rf95.recv(buf, &len)) {
|
||||
// RH_RF95::printBuffer("Received: ", buf, len);
|
||||
RH_RF95::printBuffer("Received: ", buf, len);
|
||||
Serial.println((char *)buf);
|
||||
// Serial.print("RSSI: ");
|
||||
// Serial.println(rf95.lastRssi(), DEC);
|
||||
Serial.print("RSSI: ");
|
||||
Serial.println(rf95.lastRssi(), DEC);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user