ESP32-WROOM-32E-N8 - LoRa868 - MCCI LoRaWan LMIC library

Started by Steff, May 02, 2024, 09:03:46 AM

Previous topic - Next topic

Steff

Hi there

I try to connect a LoRa868 module to a ESP32-WROOM-32E-N8 using mcci-catena arduino-lmic (https://github.com/mcci-catena/arduino-lmic).
I use this repo https://github.com/lnlp/LMIC-node/tree/v1.3.0.

What ever i do, e get this error after flashing the ESP32 on the serial port.
.pio/libdeps/sbc_olimex_v1/MCCI LoRaWAN LMIC library/src/lmic/oslmic.c:53
The LoRa868 board is connected as following to the ESP32

LoRa868  --  ESP32
NSS      -- GPIO5
MOSI    -- GPIO23
MISO    -- GPIO19
SCK      -- GPIO18
DIO0    -- GPIO26
DIO1    -- 22R Resistor -- GPIO33
DIO2    -- 22R Resistor -- GPIO32
RESET    -- GPIO21


I've created a boards file with the pin-definition by copying the ttgo-lora32-v1.h
// Pin mappings for LoRa tranceiver
const lmic_pinmap lmic_pins = {
    .nss = 5,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 21,
    .dio = { /*dio0*/ 26, /*dio1*/ 33, /*dio2*/ 32 }
#ifdef MCCI_LMIC
    ,
    .rxtx_rx_active = 0,
    .rssi_cal = 8,
    .spi_freq = 8000000    /* 8 MHz */
#endif   
};

I've added to MCCI LoRaWAN LMIC library/src/arduino_lmic_hal_boards.h
const HalPinmap_t *GetPinmap_sbc_olmiex_v1();
I've added to MCCI LoRaWAN LMIC library/src/hal/getpinmap_thisboard.cpp
#elif defined(ARDUINO_SBC_OLIMEX_V1)
        return GetPinmap_sbc_olmiex_v1();

I've added getpinmap_sbc_olimex_v1.cpp to MCCI LoRaWAN LMIC library/src/hal by copying getpinmap_ttgo_lora21_v1.cpp

This all leads to no errors during compilation. But some how i do always get the error mentioned above.

Was anybody able to get the LoRa868 Module, connected to an ESP32 running with the MCCI Library? In the end, I'd like to connect the Module to thingpark.

Thank you for any help.
Stefan

LubOlimex

Technical support and documentation manager at Olimex

Steff

OK that's great. After taking it all apart and rebuilding the whole setup, i now can read the registers with this
https://github.com/StuartsProjects/SX12XX-LoRa/tree/master/examples/SX127x_examples/Basics/2_Register_Test

And the MCCI LMIC 4.1.1  does not crash on the ESP32 ;D

But I do not see a Join-Request. Not on Thingpark, not on TTN.
The APPEUI, DEVEUI and APPKEY are correct. I've tested this with a LilyGo Lora32 1.6. This works.

The MCCI debug output is this
RXMODE_RSSI
691735: EV_JOINING
691741: engineUpdate, opmode=0x4
802330: engineUpdate, opmode=0x4
802349: EV_TXSTART
802429: TXMODE, freq=868500000, len=23, SF=7, BW=125, CR=4/5, IH=0
1118044: setupRx1 txrxFlags 00 --> 01
start single rx: now-rxtime: 4
1118678: RXMODE_SINGLE, freq=868500000, SF=7, BW=125, CR=4/5, IH=0
rxtimeout: entry: 1119204 rxtime: 1118669 entry-rxtime: 535 now-entry: 5 rxtime-txend: 312375
1180544: setupRx2 txrxFlags 0x1 --> 02
start single rx: now-rxtime: 5
1181178: RXMODE_SINGLE, freq=869525000, SF=12, BW=125, CR=4/5, IH=0
rxtimeout: entry: 1195530 rxtime: 1181169 entry-rxtime: 14361 now-entry: 5 rxtime-txend: 374875
1195559: processRx2Jacc txrxFlags 0x2 --> 00
1196212: EV_JOIN_TXCOMPLETE: no JoinAccept

So if some one has an idea, please let me know. If i should open a new thread, let me know.

I've spent so many hours on this, i'm probably overlooking a detail.

LubOlimex

If you are using Olimex LoRa868 - you need to check your software for the state of PA_BOOST. Did you disable PA_BOOST mode in the library? Again check here:

https://forum.mcci.io/t/olimex-mod-lora868/264/2
Technical support and documentation manager at Olimex

Steff

Thank you so much LubOlimex. You are a hero.

Sorry for not reading all the details in your first post.

LubOlimex

Did it work? If yes, and if and when you have the time can you make a short post with description and maybe code on how you get it working. That would be helpful for a lot of people. The problem we face with the LoRa boards is that we don't have any public TTN network anymore in our town to help us test (we used to have a couple of such points, but they are no longer operational).Thank you in advance.
Technical support and documentation manager at Olimex

Steff

Yes it works  ;D

My Code is based on https://github.com/lnlp/LMIC-node and i'm using platform.io in VSCode.
Thanks to LubOlimex this post directed me in the right direction https://forum.mcci.io/t/olimex-mod-lora868/264

Created /include/HalConfig.h
// HalConfig.h

#ifndef _HalConfig_h_
#define _HalConfig_h_

#include <arduino_lmic_hal_configuration.h>

class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {

public:
    MyHalConfig_t();
    virtual TxPowerPolicy_t getTxPowerPolicy (TxPowerPolicy_t policy, int8_t requestedPower, uint32_t frequency) override;
};

#endif

then created src/HalConfig.cpp
// HalConfig.cpp

#include <arduino_lmic_hal_configuration.h>
#include "HalConfig.h"
#include "Boards.h"

#define LMIC_FORCE_POWER_POLICY Arduino_LMIC::HalConfiguration_t::TxPowerPolicy_t::RFO

// Init
MyHalConfig_t::MyHalConfig_t(){};

// Override getTxPowerPolicy
Arduino_LMIC::HalConfiguration_t::TxPowerPolicy_t MyHalConfig_t::getTxPowerPolicy (
    Arduino_LMIC::HalConfiguration_t::TxPowerPolicy_t policy,
    int8_t requestedPower,
    uint32_t frequency
) {
    LMIC_API_PARAMETER(policy);
    LMIC_API_PARAMETER(requestedPower);
    LMIC_API_PARAMETER(frequency);

    #ifdef LMIC_FORCE_POWER_POLICY
        return LMIC_FORCE_POWER_POLICY;
    #endif

    // default: use PA_BOOST exclusively
    return Arduino_LMIC::HalConfiguration_t::TxPowerPolicy_t::PA_BOOST;
};


Create src/baords/sbc_olimex_v1.h (copy from bsf_ttgo_lora32_v1.h)
I've changed the definitions, added include and myHalconfig and changed the pinmap
#pragma once

#ifndef BSF_SBC_OLIMEX_V1
#define BSF_SBC_OLIMEX_V1

#include "config.h" // from packages/toolchain-xtensa-esp32
#include "LMIC-node.h"

#define DEVICEID_DEFAULT "sbc-olimex-v1"  // Default deviceid value


#ifndef LMIC_CLOCK_ERROR_PPM
    #define LMIC_CLOCK_ERROR_PPM 0
#endif   

// https://forum.mcci.io/t/olimex-mod-lora868/264/2
#include "HalConfig.h"
static MyHalConfig_t myHalConfig{};

const lmic_pinmap lmic_pins = {
    .nss = 5,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 21,
    .dio = {26, 33, 32},
    .rxtx_rx_active = 0,
    .rssi_cal = 10,
    .spi_freq = 8000000,
    .pConfig = &myHalConfig
};

// nothing changed after this.

platformio.ini
[platformio]
default_envs =
  sbc_olimex_v1 ;added new

[common]
lib_deps =
  olikraus/U8g2 ;even if there is no oled. make sure it is included. Otherwise i got compiling errors - OLED display library

[esp32]
build_flags =
-D hal_init=LMICHAL_init


[env:sbc_olimex_v1]
platform = espressif32
board = upesy_wroom
framework = arduino
upload_speed = 921600
monitor_speed = ${common.monitor_speed}
lib_deps =
${common.lib_deps}
${mcci_lmic.lib_deps}
build_flags =
    ${common.build_flags}
    ${esp32.build_flags}
    ${mcci_lmic.build_flags}
    -D BSFILE=\"boards/sbc_olimex_v1.h\"
    -D MONITOR_SPEED=${common.monitor_speed}
    -D LMIC_PRINTF_TO=Serial   
    -D USE_SERIAL

There are a lot of other configs in the platformio.ini. I reduced it to the changes and important things.

I hope I didn't forget anything  ???