Help with nodemcu and sx1276

Hello
I want to connect my nodemcu to ttn over the sx1276 board. Can somebody help me with that. I tried a lot but nothing worked.

1 Like

We need details - what have you tried, what did you see, what specific hardware & firmware are you using, what IDE, lorawan library, how configured, etc. Please dont have us ask as those who may know how best to advise may be least inclined to play 20 questions :wink:

Hello

Pinmapp for nodemcu v3
dio0 D0
dio1 D2
nss D8
sck D5
miso D6
mosi D7
rst D1

The Serial Output is:


⸮⸮⸮⸮5⸮⸮⸮@H⸮⸮⸮⸮⸮Starting
FAILURE 
oslmic.c:53


Iam using the sx1276 board

It would be supremely useful for you to give us the details requested - if you want free advice from volunteers, it’s not a stretch for you to help us to help you.

And if you actually looked at the line in the source code, you’ll get your answer.

Lib: https://github.com/mcci-catena/arduino-lmic
Version 4.1.1

nodemcu with sx1276 eu868
Arduino ide

I just changed this in my lib config

// project-specific definitions
#define CFG_eu868 1
//#define CFG_us915 1
//#define CFG_au915 1
//#define CFG_as923 1
// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP      /* for as923-JP; also define CFG_as923 */
//#define CFG_kr920 1
//#define CFG_in866 1
#define CFG_sx1276_radio 1
//#define LMIC_USE_INTERRUPTS

From

// project-specific definitions
//#define CFG_eu868 1
//#define CFG_us915 1
#define CFG_au915 1
//#define CFG_as923 1
// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP      /* for as923-JP; also define CFG_as923 */
//#define CFG_kr920 1
//#define CFG_in866 1
#define CFG_sx1276_radio 1
//#define LMIC_USE_INTERRUPTS


Which source code or what do you mean?

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


//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
# define FILLMEIN 0
#else
# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
#endif

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8]={ ***** };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { ****** };
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 = 10;

// Pin mapping
const lmic_pinmap lmic_pins = {
    .nss = 15,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 5,
    .dio = {16, 4, LMIC_UNUSED_PIN},
};

void printHex2(unsigned v) {
    v &= 0xff;
    if (v < 16)
        Serial.print('0');
    Serial.print(v, HEX);
}

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"));
            {
              u4_t netid = 0;
              devaddr_t devaddr = 0;
              u1_t nwkKey[16];
              u1_t artKey[16];
              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
              Serial.print("netid: ");
              Serial.println(netid, DEC);
              Serial.print("devaddr: ");
              Serial.println(devaddr, HEX);
              Serial.print("AppSKey: ");
              for (size_t i=0; i<sizeof(artKey); ++i) {
                if (i != 0)
                  Serial.print("-");
                printHex2(artKey[i]);
              }
              Serial.println("");
              Serial.print("NwkSKey: ");
              for (size_t i=0; i<sizeof(nwkKey); ++i) {
                      if (i != 0)
                              Serial.print("-");
                      printHex2(nwkKey[i]);
              }
              Serial.println();
            }
            // Disable link check validation (automatically enabled
            // during join, but because slow data rates change max TX
	    // size, we don't use it in this example.
            LMIC_setLinkCheckMode(0);
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || 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.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_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;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_SCAN_FOUND:
        ||    Serial.println(F("EV_SCAN_FOUND"));
        ||    break;
        */
        case EV_TXSTART:
            Serial.println(F("EV_TXSTART"));
            break;
        case EV_TXCANCELED:
            Serial.println(F("EV_TXCANCELED"));
            break;
        case EV_RXSTART:
            /* do not print anything -- it wrecks timing */
            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 setup() {
    Serial.begin(9600);
    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();

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
    os_runloop_once();
}

The source code file and line number in the log you supplied - you’ve had the answer handed to you before your first post.

50 void os_init() {
51    if (os_init_ex((const void *)&lmic_pins))
52        return;
53    ASSERT(0);
54 }

I already knew what it said thanks, this is not my first debug a device topic.

What do YOU think this is saying.

PS, lack of brackets is a big no, but that’s LMIC for you, so don’t let that fool you when assessing those four lines.

I think the pin mapping is false but idk. What do you mean with lack of brackets?

What do you think is the problem?

Have a look at LMIC-node.
It supports NodeMCU with an external SX1276 board.

It’s critical which GPIO ports you use for connecting the SX1276 (and which not) and then of course the pin mapping should correspond and be correct.

Be aware that ESP8266 has a very limited number of available GPIO ports which severely limits what sensors you can connect to it in combination with SPI based SX1276 (e.g. I2C support is not possible due to shortage of usable GPIO’s) and is therefore not a preferred choice for LoRaWAN applications.

It may also be wise to disable WiFi (I’m not sure, LMIC-node does not disable it). If the ESP8266 is busy for too long in user code e.g. in some loop (without any yield instructions) it will crash.

There’s a time for leading educational questions, and then there’s a time to recognize that trying to play guessing games isn’t productive.

The assert() is firing because something about your attempted pinmap is failing, though it’s unclear exactly what. That the numbers in your code mismatch your statement of connections seems notable. Exactly what could cause the pin initialization code to return an error could be investigated, by reading the actual initialization code.

As for the brackets complaint, that’s an aesthetic one. A C compiler has no issue with that code as it fully complies with the C standard (or in this case, the C++ one); some optional code standards dislike bracket free if clauses because they feel that one could easily forget that a second line of code there wouldn’t be contingent. But in the present form there is no functional issue.

Thanks a lot. Which Lib do you preffer when i want to use an arduino uno with the sx1276 board?

None due to the small amount of memory on the ATmega328P - but if you must, then the legacy mode of LMIC-node will get you started. Why not stick with the NodeMCU you have?

Whilst compliant, it is prone to mis-interpretation as well as the recognised edit issue and the OP was not demonstrating fluency with the nuances. It may be considered an aesthetic but there seems to be a body of opinion from people that develop critical firmware and many held in high esteem in researching best practise that brackets are better than the shortcut in typing.

I certainly catch myself doing it occasionally, but more often than not it gets caught in a code review by someone (usually half my age), so simpler not to.

Whats about an Arduino Mega? And do i have to have a logic level shifter or can i use the sx1276 also with 5v?

What about checking the list of popular boards supported by LMIC-node?..

And if you don’t fancy checking the hand-wrapped delivered-on-a-plate package that LMIC-node provides, what are the voltage requirements on any of the typical SX1276 boards? If you want to go DIY, then reading the data sheets are a must. Or you could pick the one of the gold standards off the LMIC-node list - like the Adafruit Feather M0 with RFM95.