Creating a Fake packet for Raspberry pi

Hello,

I have checked my Lora System and i wasnt be able to solve my problem.So i had an idea that in order to understand which part is not working i can create a fake package to Lora gateway bridge so i can try to track the package and see where the problem starts.Do you have any ideas about how can i do it?

Thanks for your helps.

First, you mean a fake “packet” not a “package”

But this doesn’t make a lot of sense.

The problem you need to solve is to get your gateway receiving actual packets from a node; until you have uplink attempts being made, there’s no point to having a working gateway to internet path or working server.

Theoretically if you had a valid packet you could perhaps try to hack it into your hacked up single channel packet forwarder and have it send it over the UDP connection as if it were real traffic, but this would just be dodging the actual issue, and besides it would basically only work once before being discarded as a replay attack.

Get your node transmitting and verify by its own logs that your packet forwarder is receiving.

Hello ,

For the last days i have been trying to use my Lora Gps Shield + Arduino Uno as a Lora End Device.No matter how much i try or configure it according to Lorawan Regional Parameters, in the loraserver i cant see my device.When i upload the code i get this message

Packet queued
131289: EV_TXCOMPLETE (includes waiting for RX windows)

I dont know how to solve my problem can anyone suggest me an idea about it?

Here is my code for Arduino IDE

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

// LoRaWAN NwkSKey, network session key
// This is the default Semtech key, which is used by the early prototype TTN
// network.
static const PROGMEM u1_t NWKSKEY[16] = { 0x8A, 0x75, 0x87, 0x4A, 0x3E, 0xF8, 0x17, 0xA6, 0xAB, 0x67, 0x7E, 0xAE, 0xC4, 0x34, 0xD4, 0xF9 };

// LoRaWAN AppSKey, application session key
// This is the default Semtech key, which is used by the early prototype TTN
// network.
static const u1_t PROGMEM APPSKEY[16] = { 0xCD, 0x12, 0x83, 0xA6, 0x4E, 0x47, 0x3E, 0x6F, 0x6A, 0xEC, 0x00, 0x4E, 0x5F, 0x38, 0x09, 0x88 };

// LoRaWAN end-device address (DevAddr)
static const u4_t DEVADDR = 0x00E4A324 ; // ← Change this address for every node!

// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain).
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }

static uint8_t mydata = “Hello, world!”;
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 2000;

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

void onEvent (ev_t ev) {
Serial.print(os_getTime());
Serial.print(": ");
switch(ev) {
case EV_SCAN_TIMEOUT:
Serial.println(F(“EV_SCAN_TIMEOUT”));
break;
case EV_BEACON_FOUND:
Serial.println(F(“EV_BEACON_FOUND”));
break;
case EV_BEACON_MISSED:
Serial.println(F(“EV_BEACON_MISSED”));
break;
case EV_BEACON_TRACKED:
Serial.println(F(“EV_BEACON_TRACKED”));
break;
case EV_JOINING:
Serial.println(F(“EV_JOINING”));
break;
case EV_JOINED:
Serial.println(F(“EV_JOINED”));
break;
case EV_RFU1:
Serial.println(F(“EV_RFU1”));
break;
case EV_JOIN_FAILED:
Serial.println(F(“EV_JOIN_FAILED”));
break;
case EV_REJOIN_FAILED:
Serial.println(F(“EV_REJOIN_FAILED”));
break;
case EV_TXCOMPLETE:
Serial.println(F(“EV_TXCOMPLETE (includes waiting for RX windows)”));
if (LMIC.txrxFlags & TXRX_ACK)
Serial.println(F(“Received ack”));
if (LMIC.dataLen) {
Serial.println(F(“Received “));
Serial.println(LMIC.dataLen);
Serial.println(F(” bytes of payload”));
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
Serial.println(F(“EV_LOST_TSYNC”));
break;
case EV_RESET:
Serial.println(F(“EV_RESET”));
break;
case EV_RXCOMPLETE:
// data received in ping slot
Serial.println(F(“EV_RXCOMPLETE”));
break;
case EV_LINK_DEAD:
Serial.println(F(“EV_LINK_DEAD”));
break;
case EV_LINK_ALIVE:
Serial.println(F(“EV_LINK_ALIVE”));
break;
default:
Serial.println(F(“Unknown event”));
break;
}
}

void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F(“OP_TXRXPEND, not sending”));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
Serial.println(F(“Packet queued”));
}
// Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
Serial.begin(115200);
Serial.println(F(“Starting”));

#ifdef VCC_ENABLE
// For Pinoccio Scout boards
pinMode(VCC_ENABLE, OUTPUT);
digitalWrite(VCC_ENABLE, HIGH);
delay(1000);
#endif

// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();

// Set static session parameters. Instead of dynamically establishing a session
// by joining the network, precomputed session parameters are be provided.
#ifdef PROGMEM
// On AVR, these values are stored in flash and only copied to RAM
// once. Copy them to a temporary buffer here, LMIC_setSession will
// copy them into a buffer of its own again.
uint8_t appskey[sizeof(APPSKEY)];
uint8_t nwkskey[sizeof(NWKSKEY)];
memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
LMIC_setSession (0x1, DEVADDR, nwkskey, appskey);
#else
// If not running an AVR with PROGMEM, just use the arrays directly
LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
#endif

#if defined(CFG_eu868)
// Set up the channels used by the Things Network, which corresponds
// to the defaults of most gateways. Without this, only three base
// channels from the LoRaWAN specification are used, which certainly
// works, so it is good for debugging, but can overload those
// frequencies, so be sure to configure the full frequency range of
// your network here (unless your network autoconfigures them).
// Setting up channels should happen after LMIC_setSession, as that
// configures the minimal channel set.
// NA-US channels 0-71 are configured automatically
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7),  BAND_CENTI);      // g-band
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI);      // g-band
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7),  BAND_CENTI);      // g-band

// TTN defines an additional channel at 869.525Mhz using SF9 for class B
// devices' ping slots. LMIC does not have an easy way to define set this
// frequency and support for class B is spotty and untested, so this
// frequency is not configured here.
#elif defined(CFG_us915)
// NA-US channels 0-71 are configured automatically
// but only one group of 8 should (a subband) should be active
// TTN recommends the second sub band, 1 in a zero based count.
// https://github.com/TheThingsNetwork/gateway-conf/blob/master/US-global_conf.json
LMIC_selectSubBand(1);
#endif

// Disable link check validation
LMIC_setLinkCheckMode(0);

// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;

// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7,14);

// Start job
do_send(&sendjob);

}

void loop() {
os_runloop_once();
}

I have also changed the lorabase.h files frequencies according to my 433 Mhz Lora Gps Shield.

#if defined(CFG_eu868) // ==============================================

enum _dr_eu868_t { DR_SF12=0, DR_SF11, DR_SF10, DR_SF9, DR_SF8, DR_SF7, DR_SF7B, DR_FSK, DR_NONE };
enum { DR_DFLTMIN = DR_SF7 };
enum { DR_PAGE = DR_PAGE_EU868 };

// Default frequency plan for EU 868MHz ISM band
// Bands:
// g1 : 1% 14dBm
// g2 : 0.1% 14dBm
// g3 : 10% 27dBm
// freq band datarates
enum { EU868_F1 = 433175000, // g1 SF7-12
EU868_F2 = 433375000, // g1 SF7-12 FSK SF7/250
EU868_F3 = 433575000, // g1 SF7-12
EU868_F4 = 433775000, // g2 SF7-12
EU868_F5 = 433975000, // g2 SF7-12
EU868_F6 = 434175000, // g3 SF7-12
EU868_J4 = 434375000, // g2 SF7-12 used during join
EU868_J5 = 434575000, // g2 SF7-12 ditto
EU868_J6 = 434775000, // g2 SF7-12 ditto

};
enum { EU868_FREQ_MIN = 433050000,
EU868_FREQ_MAX = 434900000 };

enum { CHNL_PING = 5 };
enum { FREQ_PING = EU868_F6 }; // default ping freq
enum { DR_PING = DR_SF9 }; // default ping DR
enum { CHNL_DNW2 = 5 };
enum { FREQ_DNW2 = EU868_F6 };
enum { DR_DNW2 = DR_SF12 };
enum { CHNL_BCN = 5 };
enum { FREQ_BCN = EU868_F6 };
enum { DR_BCN = DR_SF9 };
enum { AIRTIME_BCN = 144384 }; // micros

enum {
// Beacon frame format EU SF9
OFF_BCN_NETID = 0,
OFF_BCN_TIME = 3,
OFF_BCN_CRC1 = 7,
OFF_BCN_INFO = 8,
OFF_BCN_LAT = 9,
OFF_BCN_LON = 12,
OFF_BCN_CRC2 = 15,
LEN_BCN = 17
};

The first thing you should do is see if your gateway is receiving raw traffic at the times you node transmits

Hello cstratton,

My gateway does not receive anything when my node is transmitting.

Is there a problem in my code?

Can it be a problem because Im using single channel gateway? Or my Loraserver is configured according to EU_433 regional parameters.But all of my programs uses EU_868(but modified version for 433 Mhz).

That is the problem you need to solve.

Can it be a problem because Im using single channel gateway?

Indeed this is generally a rather bad idea. If you are going to pursue that route you are going to have to put a lot of thought into overcoming a wide range of issues before you will have a practical system.

Or my Loraserver is configured according to EU_433 regional parameters.But all of my programs uses EU_868(but modified version for 433 Mhz).

That sounds unwise as well.

You have a long and highly advanced project ahead of you before your task reaches the point of involving LoRaServer at all.

Start by making your node print out the exact air settings it uses when it transmits.

Make your gateway print out the exact air settings it configures its node-class radio to receive with.

Correct any differences.