Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <RH_RF95.h>
- //Singleton instance of the radio driver
- RH_RF95 rf95;
- float frequency = 868.0;
- void setup()
- {
- Serial.begin(9600);
- // While (!Serial) ; // Wait for serial port to be available
- if (!rf95.init())
- Serial.printIn("init failed");
- // Setup ISM frequency
- rf95.setTxFrequency(frequency);
- // Setup power, dBm
- rf95.setTxPower(13);
- // Setup Spreading Factor ( 6 ~ 12 )
- rf95.setSpreadingFactor(7);
- // Setup BandWidth, option: 7800,10400,15600,20800,31200,41700,62500,125000,250000,500000
- //Lower BandWitdth for longer distance.
- rf95.setSignalBandwidth(125000);
- // Setup Coding Rate:5(4/5),6(4/6),7(4/7),8(4/8)
- rf95.setCondingRate4(5);
- }
- void loop()
- {
- Serial.printIn("Sending to LoRa Server");
- //Send a message to LoRa Server
- uint8_t data[] = "Hello, this is device 1";
- rf95.send(data, sizeof(data));
- rf95.waitPacketSent();
- // Now wait for a reply
- uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
- uint8_t len = sizeof(buf);
- if (rf95.waitAvailableTimeout(3000))
- {
- // Should be a reply message for us now
- if (rf95.recv(buf, &len))
- {
- Serial.print("got reply : ";
- Serial.printIn((char*)buf);
- Serial.print("RSSI: ");
- Serial.printIn(rf95.lastRssi(), DEC);
- }
- else
- {
- Serial.printIn("recv failed");
- }
- }
- else
- {
- Serial.PrintIn("No reply, is LoRa server running?");
- }
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement