matthijskooijman / arduino-lmic

:warning: This library is deprecated, see the README for alternatives.
710 stars 653 forks source link

Downlink from gateway to LMIC #302

Closed nyxses closed 3 years ago

nyxses commented 3 years ago

Hi All,

I am using Dragino LG308 (LORAWAN Gateway). We are trying to transmit data from MQTT broker to Gateway to our LMIC node which is continuously trying to reading the LORA downlink.

Below is the code used for MQTT publish to gateway. Gateway is subscribing to inc/dragino-1da720/ publish.single("inc/dragino-1da720/", "26041E45,imme,text,11,30,3,SF10,866550000", hostname="test.mosquitto.org")

The above code works fine when trying to get the downlink to a Class C device (Dragino LHT65, temp and humidity sensor)

Below is the code running in Arduino:

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

#define TX_INTERVAL 2000
// Pin mapping
const lmic_pinmap lmic_pins = {
  .nss = 10,
  .rxtx = LMIC_UNUSED_PIN,
  .rst = LMIC_UNUSED_PIN,
  .dio = {2, 6, 7}
};

void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }

void onEvent (ev_t ev) {
}

osjob_t txjob;
osjob_t timeoutjob;

void rx(osjobcb_t func) {
  LMIC.osjob.func = func;
  LMIC.rxtime = os_getTime(); // RX _now_
  os_radio(RADIO_RXON);
  Serial.println("RX");
}

static void rx_func (osjob_t* job) {
  Serial.println(F("Received "));
  Serial.print(LMIC.dataLen);
  Serial.println(F(" bytes of payload"));
  Serial.print("[");
  for (int i=0; i < LMIC.dataLen; i++)
  {
    Serial.print(LMIC.frame[LMIC.dataBeg+i]);
    Serial.print(" ");
  }
  Serial.println("]");

  // Restart RX
  rx(rx_func);
}

// application entry point
  void setup() {
  Serial.begin(115200);
  Serial.println("Starting");
  #ifdef VCC_ENABLE
  // For Pinoccio Scout boards
  pinMode(VCC_ENABLE, OUTPUT);
  digitalWrite(VCC_ENABLE, HIGH);
  delay(1000);
  #endif

  pinMode(LED_BUILTIN, OUTPUT);

  // initialize runtime env
  os_init();

  Serial.println("India Lora Freq");
  const static uint8_t kChannel = 0;
  uint32_t uBandwidth;

  LMIC.freq = IN866_FB + kChannel * 200000;
  Serial.println(LMIC.freq);
  uBandwidth = 125;

  LMIC.dn2Dr = DR_SF10;
  LMIC.datarate = IN866_DR_SF10;         // DR7
  // default tx power for IN: 30 dBm
  LMIC.txpow = IN866_TX_EIRP_MAX_DBM;

  // disable RX IQ inversion
  LMIC.noRXIQinversion = true;

  // This sets CR 4/5, BW125 (except for EU/AS923 DR_SF7B, which uses BW250)
  LMIC.rps = updr2rps(LMIC.datarate);

  Serial.print("Frequency: "); Serial.print(LMIC.freq / 1000000);
  Serial.print("."); Serial.print((LMIC.freq / 100000) % 10);
  Serial.print("MHz");
  Serial.print("  LMIC.datarate: "); Serial.print(LMIC.datarate);
  Serial.print("  LMIC.txpow: "); Serial.println(LMIC.txpow);

  // disable RX IQ inversion
  //LMIC.noRXIQinversion = true;

  Serial.println("Started");
  Serial.flush();

  // setup initial job
  os_setCallback(&txjob, rx_func);
}

void loop() {
  // execute scheduled jobs and events
  os_runloop_once();
}

Below is the Output at Serial monitor connected to Arduino (LMIC), but its not receiving any data as downlink:

Starting
RXMODE_RSSI
india freq
866550000
Frequency: 866.5MHz  LMIC.datarate: 2  LMIC.txpow: 30
Started
Received 
0 bytes of payload
[]
2306: RXMODE_SCAN, freq=866550000, SF=10, BW=125, CR=4/5, IH=0
RX

Request you to please help with the downlink

matthijskooijman commented 3 years ago

Looks like you've used the "raw.ino" example, which is rough hack to do bare LoRa (no LoRaWAN) communication from node to node (which is enabled by LMIC.noRXIQinversion = true;) rather than gateway-to-node. If you have a proper LoRaWAN gateway, you should use one of the other examples instead. Also, I recommend you look at other LMIC ports that are still maintained, I cannot really provide support for this version (see the README).