Safe Sprinkler
Master/slave irrigation system (ESP-NOW + LoRaWAN)
Loading...
Searching...
No Matches
lorawan_handler.h
Go to the documentation of this file.
1#ifndef LORAWAN_HANDLER_H
2#define LORAWAN_HANDLER_H
3
4#include "esp_err.h"
5
6#include <stdbool.h>
7#include <stdint.h>
8
9// Include TTN credentials from separate config file
11
12// ============================================================================
13// SX1276 Pin Configuration for TTGO T3 LoRa32 V1.6.1
14// These can be overridden via build flags in platformio.ini
15// ============================================================================
16#ifndef LORA_SPI_HOST
17#define LORA_SPI_HOST SPI2_HOST
18#endif
19
20#ifndef LORA_PIN_MISO
21#define LORA_PIN_MISO 19
22#endif
23
24#ifndef LORA_PIN_MOSI
25#define LORA_PIN_MOSI 27
26#endif
27
28#ifndef LORA_PIN_SCK
29#define LORA_PIN_SCK 5
30#endif
31
32#ifndef LORA_PIN_CS
33#define LORA_PIN_CS 18
34#endif
35
36#ifndef LORA_PIN_RST
37#define LORA_PIN_RST 23
38#endif
39
40#ifndef LORA_PIN_DIO0
41#define LORA_PIN_DIO0 26
42#endif
43
44#ifndef LORA_PIN_DIO1
45#define LORA_PIN_DIO1 33
46#endif
47
48#ifndef LORA_PIN_DIO2
49#define LORA_PIN_DIO2 32
50#endif
51
52// ============================================================================
53// LoRaWAN Configuration
54// ============================================================================
55// EU868 frequency plan
56#define LORA_FREQUENCY 868100000 // 868.1 MHz (EU868 default)
57#define LORA_SPREADING_FACTOR 7 // SF7, good balance between range and data rate
58#define LORA_BANDWIDTH 0 // 125 kHz
59#define LORA_CODING_RATE 1 // 4/5
60#define LORA_TX_POWER 20 // dBm (max power for testing)
61
62// ============================================================================
63// LoRaWAN Status
64// ============================================================================
74
75// Callback type for TX complete
76typedef void (*lorawan_tx_done_cb_t)(bool success);
77
78// ============================================================================
79// API Functions
80// ============================================================================
81
89esp_err_t lorawan_init(void);
90
99esp_err_t lorawan_join(void);
100
107
114
124esp_err_t lorawan_send(uint8_t port, const uint8_t* data, uint8_t len, bool confirmed);
125
132
139
143void lorawan_deinit(void);
144
145#endif // LORAWAN_HANDLER_H
void(* lorawan_tx_done_cb_t)(bool success)
Definition lorawan_handler.h:76
int lorawan_send(uint8_t port, const uint8_t *data, uint8_t len, bool confirmed)
Send data uplink to TTN.
lorawan_status_t
Definition lorawan_handler.h:66
@ LORAWAN_STATUS_JOINING
Definition lorawan_handler.h:68
@ LORAWAN_STATUS_IDLE
Definition lorawan_handler.h:67
@ LORAWAN_STATUS_TX_COMPLETE
Definition lorawan_handler.h:71
@ LORAWAN_STATUS_SENDING
Definition lorawan_handler.h:70
@ LORAWAN_STATUS_ERROR
Definition lorawan_handler.h:72
@ LORAWAN_STATUS_JOINED
Definition lorawan_handler.h:69
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)
lorawan_status_t lorawan_get_status(void)
Get current LoRaWAN status.
bool lorawan_is_joined(void)
Check if device has joined the network.
int lorawan_join(void)
Start OTAA join procedure.
int lorawan_init(void)
Initialize the LoRaWAN handler.
void lorawan_deinit(void)
Deinitialize LoRaWAN handler.