Hello all,
This is my first post here I hope it is in the correct format and place.
I have an ESP32 along with an RFM95C (915mhz). I have a gateway that is a Dragino model LPS8
I am attempting to send data to TTN through my gateway. I am using otaa as this seems to be the most recommended.
I am using the Arduino IDE, Version 1.8.12, on Linux Mint. I am using the libraries lmic.h and hal/hal.h
When I attempt to send data, connection will join the gateway after some time. and will send data. however, the issue is that this will only happen ONCE. Any future attempts will not result in TTN console displaying that any data has been received. Is this, by any change by design? Is it hiding dup payload data? Or am I doing something wrong?
This applies to both sending and recieving data. When I use TTN console to simulate sending data to the esp32, the esp32 will report on the arduino IDE’s serial console that the data was received from TTN… but only once, the next requests will not be received UNTIL i reboot the ESP32.
Below is the full sketch I am using:
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
const lmic_pinmap lmic_pins = {
.nss = 5,
.rxtx = LMIC_UNUSED_PIN,
.rst = 27,
.dio = {26, 25, LMIC_UNUSED_PIN},
};
static const u1_t PROGMEM APPEUI[8]= { 0x79, 0x07, 0x03, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
static const u1_t PROGMEM DEVEUI[8]= { 0xB4, 0xA5, 0xC2, 0xC8, 0x53, 0x5C, 0xF4, 0x00 };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
static const u1_t PROGMEM APPKEY[16] = { 0xC0, 0xFF, 0xBE, 0xBB, 0x88, 0x9A, 0x33, 0x39, 0x5D, 0x7C, 0x76, 0x80, 0x39, 0x47, 0x76, 0x46 };
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
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 = 60;
void setup() {
Serial.begin(9600);
Serial.println(F("Starting"));
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
// Start job (sending automatically starts OTAA too)
do_send(&sendjob);
}
void onEvent (ev_t ev) {
switch(ev) {
case EV_JOINING:
Serial.println(F("EV_JOINING"));
break;
case EV_JOINED:
Serial.println(F("EV_JOINED SUCCESS"));
LMIC_setLinkCheckMode(0);
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.print(F("Received "));
Serial.print(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
break;
case EV_RXCOMPLETE:
// data received in ping slot
Serial.println(F("EV_RXCOMPLETE"));
break;
case EV_TXSTART:
Serial.println(F("EV_TXSTART"));
break;
case EV_JOIN_TXCOMPLETE:
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
break;
default:
Serial.print(F("Unknown event: "));
Serial.println((unsigned) ev);
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 loop() {
os_runloop_once();
}
Here is my IDE’s Serial output:
Starting
Packet queued
3362: EV_JOINING
3390: EV_TXSTART
344445: EV_JOINED
Joined
344451: EV_TXCOMPLETE (includes waiting for RX windows)
4094484: EV_TXSTART
Packet queued
4235905: EV_TXCOMPLETE (includes waiting for RX windows)
7985934: EV_TXSTART
Packet queued
8064706: EV_TXCOMPLETE (includes waiting for RX windows)
Received 1 bytes of payload
8095348: EV_TXSTART
8234201: EV_TXCOMPLETE (includes waiting for RX windows)
11984230: EV_TXSTART
Packet queued
12125649: EV_TXCOMPLETE (includes waiting for RX windows)
15875678: EV_TXSTART
Packet queued
16017102: EV_TXCOMPLETE (includes waiting for RX windows)
19767131: EV_TXSTART
Packet queued
19908549: EV_TXCOMPLETE (includes waiting for RX windows)
23658579: EV_TXSTART
Packet queued
23799998: EV_TXCOMPLETE (includes waiting for RX windows)
27550028: EV_TXSTART
Packet queued
27691446: EV_TXCOMPLETE (includes waiting for RX windows)
31441476: EV_TXSTART
Packet queued
31582894: EV_TXCOMPLETE (includes waiting for RX windows)
35332924: EV_TXSTART
Packet queued
35474343: EV_TXCOMPLETE (includes waiting for RX windows)
39224378: EV_TXSTART
Packet queued
39365796: EV_TXCOMPLETE (includes waiting for RX windows)
And here is all that I see in the console:
Update:
I figured that I should have added my gateway config and my integration. My integration is a Node.JS server that has been running for quite some time. It works 100% I have tested it using swagger and can simulate multiple POST requests. The integration does send the data over (but again… only once per boot)
Here are the pics of my gateway config:
Another Update…
I figure maybe the 1 request I get at the Node.JS side may be of use:
Received uplink from test-device1
{
app_id: 'cropwatchus',
dev_id: 'test-device1',
hardware_serial: '000E87281C6C2B48',
port: 1,
counter: 0,
payload_raw: <Buffer 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21>,
payload_fields: { result: 'Hello, world!' },
metadata: {
time: '2020-06-23T03:34:16.067490565Z',
frequency: 902.7,
modulation: 'LORA',
data_rate: 'SF9BW125',
airtime: 205824000,
coding_rate: '4/5',
gateways: [ [Object] ]
}
}
gateways:
{
gtw_id: 'eui-a840411d91384150',
timestamp: 133387876,
time: '2020-06-23T03:34:16.022732Z',
channel: 2,
rssi: -120,
snr: -6.8,
rf_chain: 0
}
My goal is to send data from sensors, I am sure getting it into the uint8_t will be a challange too. But I would love to get this solved first.
If there is any more detail you would like me to provide, please let me know.
Thank you very much for the assistance!
-Kevin