Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rgot-org committed Apr 24, 2024
1 parent 74043ba commit a74ec72
Showing 1 changed file with 81 additions and 45 deletions.
126 changes: 81 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,89 @@
# API Reference

The `TTN_esp32` class enables ESP32 devices with supported LoRaWAN modules to communicate via The Things Network. This library is a wrapper for MCCI-Catena/arduino-lmic library. the pre-integrated boards are the same as mcci-catena library plus :
# EzLoRaWAN
**EzLoRaWAN** is an evolution of the [TheThingsNetwork_esp32](https://github.com/rgot-org/TheThingsNetwork_esp32) library. Indeed TheThingsNetwork_esp32 does not support SX126X type chips. This library uses the **[BasicMAC](https://github.com/lacunaspace/basicmac)** library as a replacement for [mcci-catena/arduino-lmic](https://github.com/mcci-catena/arduino-lmic/tree/master). The objective of this library is to simplify as much as possible the configuration, the connection, the sending and receiving of frames to a LoRaWan network.

- HELTEC Wifi Lora 32 (V1 & V2)
- HELTEC Wireless Stick
# Configuration
Like MCCI-Catena/arduino-lmic library the configuration is setup by editing `project_config/lmic_project_config.h`. See https://github.com/mcci-catena/arduino-lmic#configuration for more informations

## Class: `TTN_esp32`

Include and instantiate the TTN_esp32 class. The constructor initialize the library with the Streams it should communicate with.

```c
#include <TTN_esp32.h>

TTN_esp32 ttn;
The library is tested for EU868 frequency plan (SX1262 & SX1276 chips). TODO enhance and verify for other frenquency plans

Pin assignment and initialization is automatic for some boards (see list below). In this case an `AUTOPIN` constant is declared.
the following boards are tested with `AUTOPIN` :
- HELTEC WIRELESS STICK (SX1276)
- HELTEC WIRELESS STICK V3 (SX1262)
- HELTEC WIFI LORA 32 V1 (SX1276)
- HELTEC WIFI LORA 32 V2 (SX1276)
- HELTEC WIRELESS PAPER (SX1262)
- HELTEC WIRELESS TRACKER V1.1 (SX1262)
- TTGO TBEAM 1 (SX1276)

To add new board edit the file [**target-config.h**](https://github.com/rgot-org/EzLoRaWAN/blob/main/src/target-config.h)

Without AUTOPIN (for example for generic cards) you must define the board type, the SPI and LoRa chip pins as follow :
- for **SX1262**
```c
#define BRD_sx1262_radio 1
#define RADIO_SCLK_PIN CHANGE_ME // depends on the pinout of the card
#define RADIO_MISO_PIN CHANGE_ME
#define RADIO_MOSI_PIN CHANGE_ME
#define RADIO_TX_PIN LMIC_CONTROLLED_BY_DIO2
#define RADIO_RX_PIN LMIC_UNUSED_PIN
#define RADIO_CS_PIN CHANGE_ME
#define RADIO_DIO0_PIN LMIC_UNUSED_PIN
#define RADIO_DIO1_PIN CHANGE_ME
#define RADIO_DIO2_PIN LMIC_UNUSED_PIN
#define RADIO_BUSY_PIN CHANGE_ME
#define RADIO_RST_PIN CHANGE_ME
#define RADIO_TCXO_PIN LMIC_CONTROLLED_BY_DIO3
```
You can see an example for LILYGO T3S3 in [board_config.h](https://github.com/rgot-org/EzLoRaWAN/blob/main/examples/ttn-otaa/board_config.h) in the ttn-otaa example
- for **SX1276**
```c
#define BRD_sx1276_radio 1
#define RADIO_SCLK_PIN CHANGE_ME // depends on the pinout of the card
#define RADIO_MISO_PIN CHANGE_ME
#define RADIO_MOSI_PIN CHANGE_ME
#define RADIO_CS_PIN CHANGE_ME
#define RADIO_DIO0_PIN CHANGE_ME
#define RADIO_DIO1_PIN CHANGE_ME
#define RADIO_DIO2_PIN CHANGE_ME
#define RADIO_RST_PIN CHANGE_ME
#define RADIO_BUSY_PIN LMIC_UNUSED_PIN
#define RADIO_TCXO_PIN LMIC_UNUSED_PIN
#define RADIO_TX_PIN LMIC_UNUSED_PIN
#define RADIO_RX_PIN LMIC_UNUSED_PIN
```
## Method: `begin`

Start the LMIC stack with Pre-integrated boards (see https://github.com/mcci-catena/arduino-lmic#pre-integrated-boards)

Following boards are tested :
- HELTEC WIRELESS STICK
- HELTEC WIFI LORA 32 V1
- HELTEC WIFI LORA 32 V2

In the sketch declare a `const` as follow:
```c
void begin();
const lmic_pinmap lmic_pins = {
.nss = RADIO_CS_PIN,
.tx = RADIO_TX_PIN,
.rx = RADIO_RX_PIN,
.rst = RADIO_RST_PIN,
.dio = {RADIO_DIO0_PIN , RADIO_DIO1_PIN, RADIO_DIO2_PIN},
.busy = RADIO_BUSY_PIN,
.tcxo = RADIO_TCXO_PIN,
};
```
Initialize the stack with pointer to pin mapping (see https://github.com/mcci-catena/arduino-lmic#pin-mapping)
In setup function add :
```c
bool begin(const TTN_esp32_LMIC::HalPinmap_t* pPinmap);
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
```
Initialize the LMIC stack with pinout as arguments

then call de `begin()` method. (See `ttn-otaa.ino` with `board-config.h` in [ttn-otaa example](https://github.com/rgot-org/EzLoRaWAN/blob/main/examples/ttn-otaa) for more details)
# API Reference
## Class: EzLoRaWAN

Include and instantiate the EzLoRaWAN class. The constructor initialize the library with the Streams it should communicate with.

```c
void begin(uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0, uint8_t dio1, uint8_t dio2);
#include <EzLoRaWAN.h>
EzLoRaWAN ttn;
```
Example for HELTEC WIRELESS STICK
# API methods
## Method: `begin`
Start the **LoRaWAN** stack.
The LoRa chip type and the pinout (LoRa & SPI) must be declared before call this method. (see the above and the [target-config.h](https://github.com/rgot-org/EzLoRaWAN/blob/main/src/target-config.h) file for more details)
```c
// wireless stick pinout
#define UNUSED_PIN 0xFF
#define SS 18
#define RST_LoRa 14
#define DIO0 26
#define DIO1 35
#define DIO2 34
...
ttn.begin(SS, UNUSED_PIN, RST_LoRa, DIO0,DIO1,DIO2);
void begin();
```
## Method: `getAppEui`

Expand Down Expand Up @@ -92,12 +128,12 @@ Will write something like:

```bash
---------------Status--------------
Device EUI: 004D22F44E5DCE53
Application EUI: 70B3D57ED0015575
Device EUI: 004D22F44E5DXXXX
Application EUI: 70B3D57ED001XXXX
netid: 13
devaddr: 26011B24
NwkSKey: 6A2D3C24AD3C0D17614D7325BCAA976
AppSKey: 9E68DCBEBF8AE9D891252FB7E6054
devaddr: 2601XXXX
NwkSKey: 6A2D3C24AD3C0D17614D7325BCXXXX
AppSKey: 9E68DCBEBF8AE9D891252FB7EXXXX
data rate: 5
tx power: 14dB
freq: 867100000Hz
Expand All @@ -116,7 +152,7 @@ void onMessage(void (*cb)(const uint8_t *payload, size_t size, int rssi));
- `size_t size`: Number of bytes.
- `int rssi`: the rssi in dB.
See the [ttn-otaa](https://github.com/rgot-org/TheThingsNetwork_esp32/blob/master/examples/ttn-otaa/ttn-otaa.ino) example.
See the [ttn-otaa]https://github.com/rgot-org/EzLoRaWAN/blob/main/examples/ttn-otaa/ttn-otaa.ino) example.
## Method: `join`
Expand Down

0 comments on commit a74ec72

Please sign in to comment.