Closed aniket1002 closed 6 years ago
You have to use the same communication lib at both side. Otherwise with RadioHead lib, check here: https://github.com/CongducPham/LowCostLoRaGw/tree/master/Arduino#using-the-radiohead-library-for-the-end-device
Thanks @CongducPham sir for your reply... Sir how can I use radiohead library at the gateway as it seems to be configured in SX1272??
If you want to use RadioHead at both side, then change the call to our send and receive functions and replace them with RadioHead functions.
thanks @CongducPham sir for a prompt reply.. Sir I even tried the LoRa Ping_Pong example:
// Include the SX1272
// IMPORTANT /////////////////////////////////////////////////////////////////////////////////////////////////////////// // please uncomment only 1 choice //
//#define FCC_US_REGULATION //#define SENEGAL_REGULATION ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT /////////////////////////////////////////////////////////////////////////////////////////////////////////// // // uncomment if your radio is an HopeRF RFM92W, HopeRF RFM95W, Modtronix inAir9B, NiceRF1276 // or you known from the circuit diagram that output use the PABOOST line instead of the RFO line
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT /////////////////////////////////////////////////////////////////////////////////////////////////////////// // please uncomment only 1 choice
//#define BAND900 //#define BAND433 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
const uint32_t DEFAULT_CHANNEL=CH_04_868;
const uint32_t DEFAULT_CHANNEL=CH_10_868;
const uint32_t DEFAULT_CHANNEL=CH_05_900;
const uint32_t DEFAULT_CHANNEL=CH_00_433;
/////////////////////////////////////////////////////////////////// // CHANGE HERE THE LORA MODE, NODE ADDRESS
//////////////////////////////////////////////////////////////////
// we wrapped Serial.println to support the Arduino Zero or M0
uint8_t message[100];
int loraMode=LORAMODE;
void setup() { int e;
// Open serial communications and wait for port to open:
SerialUSB.begin(38400);
Serial.begin(38400);
// Print a start message PRINT_CSTSTR("%s","Simple LoRa ping-pong with the gateway\n");
PRINT_CSTSTR("%s","Arduino Pro Mini detected\n");
PRINT_CSTSTR("%s","Arduino Nano detected\n");
PRINT_CSTSTR("%s","Arduino MINI/Nexus detected\n");
PRINT_CSTSTR("%s","Arduino Mega2560 detected\n");
PRINT_CSTSTR("%s","Arduino Due detected\n");
PRINT_CSTSTR("%s","Teensy36 MK66FX1M0 detected\n");
PRINT_CSTSTR("%s","Teensy35 MK64FX512 detected\n");
PRINT_CSTSTR("%s","Teensy31/32 MK20DX256 detected\n");
PRINT_CSTSTR("%s","TeensyLC MKL26Z64 detected\n");
PRINT_CSTSTR("%s","Arduino M0/Zero detected\n");
PRINT_CSTSTR("%s","Adafruit Feather32U4 detected\n");
PRINT_CSTSTR("%s","Adafruit FeatherM0 detected\n");
// See http://www.nongnu.org/avr-libc/user-manual/using_tools.html // for the list of define from the AVR compiler
PRINT_CSTSTR("%s","ATmega328P detected\n");
PRINT_CSTSTR("%s","ATmega32U4 detected\n");
PRINT_CSTSTR("%s","ATmega2560 detected\n");
PRINT_CSTSTR("%s","SAMD21G18A ARM Cortex-M0+ detected\n");
PRINT_CSTSTR("%s","SAM3X8E ARM Cortex-M3 detected\n");
// for the Heltec ESP32 WiFi LoRa module sx1272.setCSPin(5);
// Power ON the module sx1272.ON();
// Set transmission mode and print the result e = sx1272.setMode(loraMode); PRINT_CSTSTR("%s","Setting Mode: state "); PRINT_VALUE("%d", e); PRINTLN;
// enable carrier sense
sx1272._enableCarrierSense=true;
// Select frequency channel
e = sx1272.setChannel(10);
PRINT_CSTSTR("%s","Setting Channel: state ");
PRINT_VALUE("%d", e);
PRINTLN;
// Select amplifier line; PABOOST or RFO
sx1272._needPABOOST=true; // previous way for setting output power // powerLevel='x';
// previous way for setting output power // powerLevel='M';
// previous way for setting output power // e = sx1272.setPower(powerLevel);
e = sx1272.setPowerDBM(10); PRINT_CSTSTR("%s","Setting Power: state "); PRINT_VALUE("%d", e); PRINTLN;
// Set the node address and print the result e = sx1272.setNodeAddress(node_addr); PRINT_CSTSTR("%s","Setting node addr: state "); PRINT_VALUE("%d", e); PRINTLN;
// Print a success message PRINT_CSTSTR("%s","SX1272 successfully configured\n");
delay(500); }
void loop(void) { uint8_t r_size; int e;
sx1272.CarrierSense();
sx1272.setPacketType(PKT_TYPE_DATA);
r_size=sprintf((char*)message, "Ping");
while (1) {
PRINT_CSTSTR("%s","Sending Ping");
PRINTLN;
e = sx1272.sendPacketTimeoutACK(DEFAULT_DEST_ADDR, message, r_size);
// this is the no-ack version
// e = sx1272.sendPacketTimeout(DEFAULT_DEST_ADDR, message, r_size);
PRINT_CSTSTR("%s","Packet sent, state ");
PRINT_VALUE("%d", e);
PRINTLN;
if (e==3)
PRINT_CSTSTR("%s","No Pong from gw!");
if (e==0) {
char message[20];
sprintf(message,"SNR at gw=%d ", sx1272._rcv_snr_in_ack);
PRINT_CSTSTR("%s","Pong received from gateway!");
PRINTLN;
PRINT_STR("%s", message);
}
PRINTLN;
delay(1000);
}
}
and I'm getting this in my serial monitor:
Sir, I have also set the CS PIN AS 5 in the code..
how can I solve this issue?
you have to use the setCSPin outside the #ifdef statement because you may not have the #if defined ARDUINO_Heltec_WIFI_LoRa_32 || defined ARDUINO_WIFI_LoRa_32 || defined HELTEC_LORA true. So just remove the #ifdef
Hello @CongducPham sir,
setting the CS PIN outside the #ifdef statement worked and i got the following display on my serial monitor:
how can we receive pong back from the gateway?
also the gateway and end-device are configured at same PABOOST.
Regards
Sir I'm geting the RSSI = -126 can this be the reason for not receiving ping on gateway ?
Shall I try changing the antenna so that I get RSSI in the order of -60s?
Currently I'm using this antenna :
hello @CongducPham Sir , I'm currently working on a transmitter and reciever program for LoRa development Kit. I'm trying to upload the following sketch on my LoRa development kit(http://ethicstech.in/products/iot/lora-iot). `
include
include
define RFM95_CS 5 //nss pin
define RFM95_RST 9
define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
define RF95_FREQ 865.0
// Singleton instance of the radio driver RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup() { pinMode(RFM95_RST, OUTPUT); digitalWrite(RFM95_RST, HIGH);
while (!Serial); Serial.begin(9600); delay(100);
Serial.println("Arduino LoRa TX Test!");
// manual reset digitalWrite(RFM95_RST, LOW); delay(10); digitalWrite(RFM95_RST, HIGH); delay(10);
while (!rf95.init()) { Serial.println("LoRa radio init failed"); while (1); } Serial.println("LoRa radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM if (!rf95.setFrequency(RF95_FREQ)) { Serial.println("setFrequency failed"); while (1); } Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// 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 // you can set transmitter powers from 5 to 23 dBm: rf95.setTxPower(23, true); }
int16_t packetnum = 0; // packet counter, we increment per xmission
void loop() { Serial.println("Sending to rf95_server"); // Send a message to rf95_server
char radiopacket[20] = "HELLO WORLD # "; itoa(packetnum++, radiopacket+13, 10); Serial.print("Sending "); Serial.println(radiopacket); radiopacket[19] = 0;
Serial.println("Sending..."); delay(10); rf95.send((uint8_t *)radiopacket, 20);
Serial.println("Waiting for packet to complete..."); delay(10); rf95.waitPacketSent(); // Now wait for a reply uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf);
Serial.println("Waiting for reply..."); delay(10); if (rf95.waitAvailableTimeout(1000)) { // Should be a reply message for us now
if (rf95.recv(buf, &len)) { Serial.print("Got reply: "); Serial.println((char*)buf); Serial.print("RSSI: "); Serial.println(rf95.lastRssi(), DEC);
} else { Serial.println("Receive failed"); } } else { Serial.println("No reply, is there a listener around?"); } delay(5000); }` my serial monitor is displaying:
Yet the gateway is not receiving any packets. Gateway is configured according to your tutorials. Gateway :
Looking forward to your response.