CongducPham / LowCostLoRaGw

Low-cost LoRa IoT & gateway with SX12XX (SX1261/62/68; SX1272/76/77/78/79; SX1280/81), RaspberryPI and Arduino boards
695 stars 352 forks source link

Gateway not recieving packet #202

Closed aniket1002 closed 6 years ago

aniket1002 commented 6 years ago

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:

capture

Yet the gateway is not receiving any packets. Gateway is configured according to your tutorials. Gateway :

2018-05-30-151750_1824x984_scrot

Looking forward to your response.

CongducPham commented 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

aniket1002 commented 6 years ago

Thanks @CongducPham sir for your reply... Sir how can I use radiohead library at the gateway as it seems to be configured in SX1272??

CongducPham commented 6 years ago

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.

aniket1002 commented 6 years ago

thanks @CongducPham sir for a prompt reply.. Sir I even tried the LoRa Ping_Pong example:

include

// Include the SX1272

include "SX1272.h"

// IMPORTANT /////////////////////////////////////////////////////////////////////////////////////////////////////////// // please uncomment only 1 choice //

define ETSI_EUROPE_REGULATION

//#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

define PABOOST

///////////////////////////////////////////////////////////////////////////////////////////////////////////

// IMPORTANT /////////////////////////////////////////////////////////////////////////////////////////////////////////// // please uncomment only 1 choice

define BAND868

//#define BAND900 //#define BAND433 ///////////////////////////////////////////////////////////////////////////////////////////////////////////

ifdef ETSI_EUROPE_REGULATION

define MAX_DBM 14

elif defined SENEGAL_REGULATION

define MAX_DBM 10

elif defined FCC_US_REGULATION

define MAX_DBM 14

endif

ifdef BAND868

ifdef SENEGAL_REGULATION

const uint32_t DEFAULT_CHANNEL=CH_04_868;

else

const uint32_t DEFAULT_CHANNEL=CH_10_868;

endif

elif defined BAND900

const uint32_t DEFAULT_CHANNEL=CH_05_900;

elif defined BAND433

const uint32_t DEFAULT_CHANNEL=CH_00_433;

endif

/////////////////////////////////////////////////////////////////// // CHANGE HERE THE LORA MODE, NODE ADDRESS

define LORAMODE 1

define node_addr 8

//////////////////////////////////////////////////////////////////

// we wrapped Serial.println to support the Arduino Zero or M0

if defined SAMD21G18A && not defined ARDUINO_SAMD_FEATHER_M0

define PRINTLN SerialUSB.println("")

define PRINT_CSTSTR(fmt,param) SerialUSB.print(F(param))

define PRINT_STR(fmt,param) SerialUSB.print(param)

define PRINT_VALUE(fmt,param) SerialUSB.print(param)

define FLUSHOUTPUT SerialUSB.flush();

else

define PRINTLN Serial.println("")

define PRINT_CSTSTR(fmt,param) Serial.print(F(param))

define PRINT_STR(fmt,param) Serial.print(param)

define PRINT_VALUE(fmt,param) Serial.print(param)

define FLUSHOUTPUT Serial.flush();

endif

define DEFAULT_DEST_ADDR 1

uint8_t message[100];

int loraMode=LORAMODE;

void setup() { int e;

// Open serial communications and wait for port to open:

if defined SAMD21G18A && not defined ARDUINO_SAMD_FEATHER_M0

SerialUSB.begin(38400);

else

Serial.begin(38400);

endif

// Print a start message PRINT_CSTSTR("%s","Simple LoRa ping-pong with the gateway\n");

ifdef ARDUINO_AVR_PRO

PRINT_CSTSTR("%s","Arduino Pro Mini detected\n");

endif

ifdef ARDUINO_AVR_NANO

PRINT_CSTSTR("%s","Arduino Nano detected\n");

endif

ifdef ARDUINO_AVR_MINI

PRINT_CSTSTR("%s","Arduino MINI/Nexus detected\n");

endif

ifdef ARDUINO_AVR_MEGA2560

PRINT_CSTSTR("%s","Arduino Mega2560 detected\n");

endif

ifdef ARDUINO_SAM_DUE

PRINT_CSTSTR("%s","Arduino Due detected\n");

endif

ifdef MK66FX1M0

PRINT_CSTSTR("%s","Teensy36 MK66FX1M0 detected\n");

endif

ifdef MK64FX512

PRINT_CSTSTR("%s","Teensy35 MK64FX512 detected\n");

endif

ifdef MK20DX256

PRINT_CSTSTR("%s","Teensy31/32 MK20DX256 detected\n");

endif

ifdef MKL26Z64

PRINT_CSTSTR("%s","TeensyLC MKL26Z64 detected\n");

endif

if defined ARDUINO_SAMD_ZERO && not defined ARDUINO_SAMD_FEATHER_M0

PRINT_CSTSTR("%s","Arduino M0/Zero detected\n");

endif

ifdef ARDUINO_AVR_FEATHER32U4

PRINT_CSTSTR("%s","Adafruit Feather32U4 detected\n");

endif

ifdef ARDUINO_SAMD_FEATHER_M0

PRINT_CSTSTR("%s","Adafruit FeatherM0 detected\n");

endif

// See http://www.nongnu.org/avr-libc/user-manual/using_tools.html // for the list of define from the AVR compiler

ifdef __AVR_ATmega328P__

PRINT_CSTSTR("%s","ATmega328P detected\n");

endif

ifdef __AVR_ATmega32U4__

PRINT_CSTSTR("%s","ATmega32U4 detected\n");

endif

ifdef __AVR_ATmega2560__

PRINT_CSTSTR("%s","ATmega2560 detected\n");

endif

ifdef SAMD21G18A

PRINT_CSTSTR("%s","SAMD21G18A ARM Cortex-M0+ detected\n");

endif

ifdef SAM3X8E

PRINT_CSTSTR("%s","SAM3X8E ARM Cortex-M3 detected\n");

endif

if defined ARDUINO_Heltec_WIFI_LoRa_32 || defined ARDUINO_WIFI_LoRa_32 || defined HELTEC_LORA

// for the Heltec ESP32 WiFi LoRa module sx1272.setCSPin(5);

endif

// 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

ifdef PABOOST

sx1272._needPABOOST=true; // previous way for setting output power // powerLevel='x';

else

// previous way for setting output power // powerLevel='M';

endif

// 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: capture4 Sir, I have also set the CS PIN AS 5 in the code.. how can I solve this issue?

CongducPham commented 6 years ago

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

aniket1002 commented 6 years ago

Hello @CongducPham sir, setting the CS PIN outside the #ifdef statement worked and i got the following display on my serial monitor: capture6 how can we receive pong back from the gateway? also the gateway and end-device are configured at same PABOOST. Regards

aniket1002 commented 6 years ago

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 : img_20180604_163053