Safe Sprinkler
Master/slave irrigation system (ESP-NOW + LoRaWAN)
Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions
lorawan_handler.h File Reference
#include "esp_err.h"
#include <stdbool.h>
#include <stdint.h>
#include "master/ttn_credentials.h"
Include dependency graph for lorawan_handler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LORA_SPI_HOST   SPI2_HOST
 
#define LORA_PIN_MISO   19
 
#define LORA_PIN_MOSI   27
 
#define LORA_PIN_SCK   5
 
#define LORA_PIN_CS   18
 
#define LORA_PIN_RST   23
 
#define LORA_PIN_DIO0   26
 
#define LORA_PIN_DIO1   33
 
#define LORA_PIN_DIO2   32
 
#define LORA_FREQUENCY   868100000
 
#define LORA_SPREADING_FACTOR   7
 
#define LORA_BANDWIDTH   0
 
#define LORA_CODING_RATE   1
 
#define LORA_TX_POWER   20
 

Typedefs

typedef void(* lorawan_tx_done_cb_t) (bool success)
 

Enumerations

enum  lorawan_status_t {
  LORAWAN_STATUS_IDLE , LORAWAN_STATUS_JOINING , LORAWAN_STATUS_JOINED , LORAWAN_STATUS_SENDING ,
  LORAWAN_STATUS_TX_COMPLETE , LORAWAN_STATUS_ERROR
}
 

Functions

int lorawan_init (void)
 Initialize the LoRaWAN handler.
 
int lorawan_join (void)
 Start OTAA join procedure.
 
bool lorawan_is_joined (void)
 Check if device has joined the network.
 
lorawan_status_t lorawan_get_status (void)
 Get current LoRaWAN status.
 
int lorawan_send (uint8_t port, const uint8_t *data, uint8_t len, bool confirmed)
 Send data uplink to TTN.
 
void lorawan_set_tx_done_callback (lorawan_tx_done_cb_t callback)
 Set callback for TX complete event.
 
void lorawan_process (void)
 Process LoRaWAN events (call periodically from main loop)
 
void lorawan_deinit (void)
 Deinitialize LoRaWAN handler.
 

Macro Definition Documentation

◆ LORA_BANDWIDTH

#define LORA_BANDWIDTH   0

◆ LORA_CODING_RATE

#define LORA_CODING_RATE   1

◆ LORA_FREQUENCY

#define LORA_FREQUENCY   868100000

◆ LORA_PIN_CS

#define LORA_PIN_CS   18

◆ LORA_PIN_DIO0

#define LORA_PIN_DIO0   26

◆ LORA_PIN_DIO1

#define LORA_PIN_DIO1   33

◆ LORA_PIN_DIO2

#define LORA_PIN_DIO2   32

◆ LORA_PIN_MISO

#define LORA_PIN_MISO   19

◆ LORA_PIN_MOSI

#define LORA_PIN_MOSI   27

◆ LORA_PIN_RST

#define LORA_PIN_RST   23

◆ LORA_PIN_SCK

#define LORA_PIN_SCK   5

◆ LORA_SPI_HOST

#define LORA_SPI_HOST   SPI2_HOST

◆ LORA_SPREADING_FACTOR

#define LORA_SPREADING_FACTOR   7

◆ LORA_TX_POWER

#define LORA_TX_POWER   20

Typedef Documentation

◆ lorawan_tx_done_cb_t

typedef void(* lorawan_tx_done_cb_t) (bool success)

Enumeration Type Documentation

◆ lorawan_status_t

Enumerator
LORAWAN_STATUS_IDLE 
LORAWAN_STATUS_JOINING 
LORAWAN_STATUS_JOINED 
LORAWAN_STATUS_SENDING 
LORAWAN_STATUS_TX_COMPLETE 
LORAWAN_STATUS_ERROR 

Function Documentation

◆ lorawan_deinit()

void lorawan_deinit ( void  )

Deinitialize LoRaWAN handler.

◆ lorawan_get_status()

lorawan_status_t lorawan_get_status ( void  )

Get current LoRaWAN status.

Returns
Current status

◆ lorawan_init()

int lorawan_init ( void  )

Initialize the LoRaWAN handler.

Initializes SPI, configures the SX1276, and prepares for OTAA join.

Returns
ESP_OK on success, error code otherwise

◆ lorawan_is_joined()

bool lorawan_is_joined ( void  )

Check if device has joined the network.

Returns
true if joined, false otherwise

◆ lorawan_join()

int lorawan_join ( void  )

Start OTAA join procedure.

Attempts to join The Things Network using OTAA. This is a non-blocking call - use lorawan_get_status() to check progress.

Returns
ESP_OK if join request sent, error code otherwise

◆ lorawan_process()

void lorawan_process ( void  )

Process LoRaWAN events (call periodically from main loop)

This should be called regularly to process radio events.

◆ lorawan_send()

int lorawan_send ( uint8_t  port,
const uint8_t *  data,
uint8_t  len,
bool  confirmed 
)

Send data uplink to TTN.

Parameters
portLoRaWAN port (1-223)
dataPointer to data buffer
lenLength of data (max 51 bytes for SF7-SF12)
confirmedWhether to request confirmation (ACK)
Returns
ESP_OK if data queued for sending, error code otherwise

◆ lorawan_set_tx_done_callback()

void lorawan_set_tx_done_callback ( lorawan_tx_done_cb_t  callback)

Set callback for TX complete event.

Parameters
callbackFunction to call when TX is complete