Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTAA activation not working on TTN #22

Closed
mo-norant opened this issue Aug 9, 2020 · 4 comments
Closed

OTAA activation not working on TTN #22

mo-norant opened this issue Aug 9, 2020 · 4 comments

Comments

@mo-norant
Copy link

Hi,

when i am activating over OTAA the Activation frame gets recognized, but the payload frames are not transmitted because it's not connected on the TTN network. APB activation does work without any problems.

Theory, does the low RSSI of -119 mean something?

image

Here you can find my code.

`

#include <HardwareSerial.h>
#include <TinyGPS++.h>
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include "WiFi.h"
#include <CayenneLPP.h>

#define BUILTIN_LED 25

char s[32]; // used to sprintf for Serial output

TinyGPSPlus gps;
static u1_t DEVEUI[8] = {0xF3, 0x4B, 0x37, 0x43, 0x98, 0x3B, 0xAC, 0x00};
static u1_t APPEUI[8] = {0x9C, 0x03, 0x03, 0xD0, 0x7E, 0xD5, 0xB3, 0x70};
static u1_t APPKEY[16] = {0x71, 0x3B, 0x80, 0x81, 0xB0, 0xA1, 0x7A, 0xEA, 0x5D, 0xD8, 0xBA, 0xCC, 0xCF, 0x13, 0xE6, 0x10};

RTC_NOINIT_ATTR int RTCseqnoUp, RTCseqnoDn;
RTC_NOINIT_ATTR u4_t otaaDevAddr;
RTC_NOINIT_ATTR u1_t otaaNetwKey[16];
RTC_NOINIT_ATTR u1_t otaaApRtKey[16];

void os_getDevEui(u1_t *buf)
{
memcpy_P(buf, DEVEUI, 8);
}
void os_getArtEui(u1_t *buf) { memcpy_P(buf, APPEUI, 8); }
void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); }

static osjob_t sendjob;
const unsigned TX_INTERVAL = 30;

const lmic_pinmap lmic_pins = {
.nss = 18,
.rxtx = LMIC_UNUSED_PIN,
.rst = 14,
.dio = {26, 33, 32},
};

unsigned long last_update = 0;
String toLog;
uint8_t txBuffer[] = "Hey mo alles goed.";

void storeFrameCounters()
{
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
sprintf(s, "Counters stored as %d/%d", LMIC.seqnoUp, LMIC.seqnoDn);
Serial.println(s);
}

void restoreFrameCounters()
{
LMIC.seqnoUp = RTCseqnoUp;
LMIC.seqnoDn = RTCseqnoDn;
sprintf(s, "Restored counters as %d/%d", LMIC.seqnoUp, LMIC.seqnoDn);
Serial.println(s);
}

void setOrRestorePersistentCounters()
{
esp_reset_reason_t reason = esp_reset_reason();
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW))
{
Serial.println(F("Counters both set to 0"));
LMIC.seqnoUp = 0;
LMIC.seqnoDn = 0;
}
else
{
restoreFrameCounters();
}
}
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
{

    CayenneLPP lpp(160);

    lpp.reset();
    lpp.addDigitalInput(1, random(2));
    lpp.addDigitalOutput(2, 1);
    lpp.addAnalogInput(3, 1.23f);
    lpp.addAnalogOutput(4, 3.45f);
    lpp.addLuminosity(5, 20304);

    LMIC_setTxData2(1, txBuffer, sizeof(txBuffer), 1);
    // LMIC_setTxData2(1, lpp.getBuffer(), lpp.getSize(), 0);
    Serial.println(F("Packet queued"));
    digitalWrite(BUILTIN_LED, HIGH);
}
// Next TX is scheduled after TX_COMPLETE event.

}

void onEvent(ev_t ev)
{
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"));
// Disable link check validation (automatically enabled
// during join, but not supported by TTN at this time).
LMIC_setLinkCheckMode(0);
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;
break;
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
digitalWrite(BUILTIN_LED, LOW);
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"));
}
storeFrameCounters();

    // 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 setup()
{
Serial.begin(115200);
//Turn off WiFi and Bluetooth
WiFi.mode(WIFI_OFF);
btStop();

SPI.begin(5, 19, 27);
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();

esp_reset_reason_t reason = esp_reset_reason();
if ((reason == ESP_RST_DEEPSLEEP) || (reason == ESP_RST_SW))
{
    LMIC_setSession(0x1, otaaDevAddr, otaaNetwKey, otaaApRtKey);
}

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
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);  // g-band
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);  // g-band
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);  // g-band
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);  // g-band
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);  // g-band
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI);   // g2-band

// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);

// Disable link check validation
LMIC_setLinkCheckMode(0);

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

// Start job
do_send(&sendjob);
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, LOW);

}

void loop()
{
os_runloop_once();
}`

@vincegre
Copy link

OTAA is confirmed not working: #21 (comment) only ABP !

@mo-norant
Copy link
Author

Yeah indeed, does somebody has an answer to the code?

@mo-norant mo-norant reopened this Aug 10, 2020
@vincegre
Copy link

Yeah indeed, does somebody has an answer to the code?

Hum not sure to understand what is your problem as you stated it works fine in ABP mode no ? Which version of board do you have ? mine is 1.1 and not working with that code (no TTN connection and OLED display doesn't work too :(

@DeuxVis
Copy link
Owner

DeuxVis commented Aug 11, 2020

OTAA was working with the supported versions of the boards (up to V0.7) last time I checked.

Let's concentrate on the support of the newer (V1.0 / V1.1) board versions before talking about OTAA, see #21 #19

@DeuxVis DeuxVis closed this as completed Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants