ttn-esp32 4.2.1
The Things Network device library for ESP-IDF (ESP32)
Loading...
Searching...
No Matches
ttn.h
1/*******************************************************************************
2 *
3 * ttn-esp32 - The Things Network device library for ESP-IDF / SX127x
4 *
5 * Copyright (c) 2018-2021 Manuel Bleichenbacher
6 *
7 * Licensed under MIT License
8 * https://opensource.org/licenses/MIT
9 *
10 * High-level C API for ttn-esp32.
11 *******************************************************************************/
12
17#ifndef TTN_C_H
18#define TTN_C_H
19
20#include "driver/spi_master.h"
21#include <stdint.h>
22
23#ifdef __cplusplus
24extern "C"
25{
26#endif
27
37#define TTN_NOT_CONNECTED 0xff
38
42 typedef uint8_t ttn_port_t;
43
58
81
120
124 typedef enum
125 {
141 TTN_BW_500 = 3
143
150 typedef enum
151 {
184
249
282
311
336
393
399
418
426 typedef void (*ttn_message_cb)(const uint8_t *payload, size_t length, ttn_port_t port);
427
433 void ttn_init(void);
434
452 void ttn_configure_pins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0,
453 uint8_t dio1);
454
467 void ttn_set_subband(int band);
468
485 bool ttn_provision(const char *dev_eui, const char *app_eui, const char *app_key);
486
500 bool ttn_provision_transiently(const char *dev_eui, const char *app_eui, const char *app_key);
501
527 bool ttn_provision_with_mac(const char *app_eui, const char *app_key);
528
535
544
558 bool ttn_join(void);
559
575 bool ttn_join_with_keys(const char *dev_eui, const char *app_eui, const char *app_key);
576
589
611 bool ttn_resume_after_power_off(int off_duration);
612
629
648
656
673 TickType_t ttn_busy_duration(void);
674
684 void ttn_shutdown(void);
685
700 ttn_response_code_t ttn_transmit_message(const uint8_t *payload, size_t length, ttn_port_t port, bool confirm);
701
717
725
735 void ttn_set_rssi_cal(int8_t rssi_cal);
736
742 bool ttn_adr_enabled(void);
743
752 void ttn_set_adr_enabled(bool enabled);
753
763
773 void ttn_set_max_tx_pow(int tx_pow);
774
780
786
792
798
804
812 int ttn_rssi();
813
818#ifdef __cplusplus
819}
820#endif
821
822#endif
ttn_bandwidth_t
Bandwidth.
Definition ttn.h:125
void ttn_on_message(ttn_message_cb callback)
Sets the function to be called when a message is received.
void ttn_configure_pins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0, uint8_t dio1)
Configures the pins used to communicate with the LoRaWAN radio chip.
bool ttn_adr_enabled(void)
bool ttn_resume_after_deep_sleep(void)
Resumes TTN communication after deep sleep.
bool ttn_join_with_keys(const char *dev_eui, const char *app_eui, const char *app_key)
Activates the device via OTAA using the provided keys.
void ttn_prepare_for_power_off(void)
Stops all activies and prepares for power off.
TickType_t ttn_busy_duration(void)
Returns the minimum duration the TTN device will be busy.
void(* ttn_message_cb)(const uint8_t *payload, size_t length, ttn_port_t port)
Callback for recieved messages.
Definition ttn.h:426
void ttn_set_max_tx_pow(int tx_pow)
Sets the maximum power for transmission.
ttn_rf_settings_t ttn_get_rf_settings(ttn_rx_tx_window_t window)
Gets the RF settings for the specified window.
void ttn_shutdown(void)
Stops all activies.
void ttn_wait_for_idle(void)
Waits until the TTN device is idle.
void ttn_prepare_for_deep_sleep(void)
Stops all activies and prepares for deep sleep.
bool ttn_provision(const char *dev_eui, const char *app_eui, const char *app_key)
Sets the keys needed to activate the device via OTAA, without activating it.
ttn_data_rate_t
Data Rate.
Definition ttn.h:151
bool ttn_provision_with_mac(const char *app_eui, const char *app_key)
Sets the information needed to activate the device via OTAA, using the MAC to generate the DevEUI and...
ttn_rx_tx_window_t ttn_rx_tx_window(void)
Gets current RX/TX window.
uint8_t ttn_port_t
Integer data type for specifiying the port of an uplink or downlink message.
Definition ttn.h:42
void ttn_set_subband(int band)
Sets the frequency sub-band to be used.
void ttn_init(void)
Initializes The Things Network device instance.
ttn_rf_settings_t ttn_tx_settings(void)
Gets the RF settings of the last (or ongoing) transmission.
ttn_rx_tx_window_t
RX/TX window.
Definition ttn.h:63
void ttn_set_data_rate(ttn_data_rate_t data_rate)
Sets the transmission data rate (i.e. the data rate for uplink messages).
bool ttn_join(void)
Activates the device via OTAA using previously provisioned keys.
ttn_rf_settings_t ttn_rx2_settings(void)
Gets the RF settings of the last (or ongoing) reception of RX window 2.
bool ttn_provision_transiently(const char *dev_eui, const char *app_eui, const char *app_key)
Sets the keys needed to activate the device via OTAA, without activating it.
int ttn_rssi()
Gets the received signal strength indicator (RSSI).
void ttn_set_adr_enabled(bool enabled)
Enables or disabled Adaptive Data Rate (ADR).
void ttn_wait_for_provisioning(void)
Waits until the DevEUI, AppEUI/JoinEUI and AppKey have been provisioned by the provisioning task.
bool ttn_resume_after_power_off(int off_duration)
Resumes TTN communication after power off.
ttn_response_code_t
Response codes.
Definition ttn.h:48
ttn_response_code_t ttn_transmit_message(const uint8_t *payload, size_t length, ttn_port_t port, bool confirm)
Transmits a message.
bool ttn_is_provisioned(void)
Checks if DevEUI, AppEUI/JoinEUI and AppKey have been stored in non-volatile storage or have been pro...
void ttn_set_rssi_cal(int8_t rssi_cal)
Sets the RSSI calibration value for LBT (Listen Before Talk).
ttn_rf_settings_t ttn_rx1_settings(void)
Gets the RF settings of the last (or ongoing) reception of RX window 1.
void ttn_start_provisioning_task(void)
Starts task listening on configured UART for AT commands.
ttn_spreading_factor_t
Spreading Factor.
Definition ttn.h:86
@ TTN_BW_125
Bandwidth of 125 kHz.
Definition ttn.h:133
@ TTN_BW_250
Bandwidth of 250 kHz.
Definition ttn.h:137
@ TTN_BW_500
Bandwidth of 500 kHz.
Definition ttn.h:141
@ TTN_BW_NONE
Undefined/unused bandwidth.
Definition ttn.h:129
@ TTN_DR_AU915_SF8_BW500_DR12
Data rate for region AU915 using SF8 and 500 kHz bandwidth.
Definition ttn.h:242
@ TTN_DR_AU915_SF8_BW500
Data rate for region AU915 using SF8 and 500 kHz bandwidth.
Definition ttn.h:212
@ TTN_DR_US915_SF10_BW500
Data rate for region US915 using SF10 and 500 kHz bandwidth.
Definition ttn.h:374
@ TTN_DR_KR920_SF11
Data rate for region KR920 using SF11 and 125 kHz bandwidth.
Definition ttn.h:319
@ TTN_DR_EU868_SF9
Data rate for region EU868 using SF9 and 125 kHz bandwidth.
Definition ttn.h:265
@ TTN_DR_AS923_FSK
Data rate for region AS923 using FSK and 50 kpbs.
Definition ttn.h:183
@ TTN_DR_US915_SF10
Data rate for region US915 using SF10 and 125 kHz bandwidth.
Definition ttn.h:340
@ TTN_DR_US915_SF11_BW500
Data rate for region US915 using SF11 and 500 kHz bandwidth.
Definition ttn.h:368
@ TTN_DR_AU915_SF7_BW500
Data rate for region AU915 using SF7 and 500 kHz bandwidth.
Definition ttn.h:248
@ TTN_DR_IN866_SF12
Data rate for region IN866 using SF12 and 125 kHz bandwidth.
Definition ttn.h:286
@ TTN_DR_IN866_SF10
Data rate for region IN866 using SF10 and 125 kHz bandwidth.
Definition ttn.h:294
@ TTN_DR_AS923_SF8
Data rate for region AS923 using SF8 and 125 kHz bandwidth.
Definition ttn.h:171
@ TTN_DR_EU868_SF7_BW125
Data rate for region EU868 using SF7 and 125 kHz bandwidth.
Definition ttn.h:273
@ TTN_DR_EU868_FSK
Data rate for region EU868 using FSK and 50 kpbs.
Definition ttn.h:281
@ TTN_DR_EU868_SF12
Data rate for region EU868 using SF12 and 125 kHz bandwidth.
Definition ttn.h:253
@ TTN_DR_US915_SF8_BW500_DR12
Data rate for region US915 using SF8 and 500 kHz bandwidth.
Definition ttn.h:386
@ TTN_DR_IN866_SF9
Data rate for region IN866 using SF9 and 125 kHz bandwidth.
Definition ttn.h:298
@ TTN_DR_KR920_SF8
Data rate for region KR920 using SF8 and 125 kHz bandwidth.
Definition ttn.h:331
@ TTN_DR_AS923_SF10
Data rate for region AS923 using SF10 and 125 kHz bandwidth.
Definition ttn.h:163
@ TTN_DR_US915_SF12_BW500
Data rate for region US915 using SF12 and 500 kHz bandwidth.
Definition ttn.h:362
@ TTN_DR_EU868_SF7_BW250
Data rate for region EU868 using SF7 and 250 kHz bandwidth.
Definition ttn.h:277
@ TTN_DR_IN866_SF11
Data rate for region IN866 using SF11 and 125 kHz bandwidth.
Definition ttn.h:290
@ TTN_DR_EU868_SF10
Data rate for region EU868 using SF10 and 125 kHz bandwidth.
Definition ttn.h:261
@ TTN_DR_US915_SF7_BW500
Data rate for region US915 using SF7 and 500 kHz bandwidth.
Definition ttn.h:392
@ TTN_DR_AU915_SF12_BW500
Data rate for region AU915 using SF12 and 500 kHz bandwidth.
Definition ttn.h:218
@ TTN_DR_JOIN_DEFAULT
Default data rate for joining.
Definition ttn.h:397
@ TTN_DR_AU915_SF12
Data rate for region AU915 using SF12 and 125 kHz bandwidth.
Definition ttn.h:188
@ TTN_DR_AU915_SF10_BW500
Data rate for region AU915 using SF10 and 500 kHz bandwidth.
Definition ttn.h:230
@ TTN_DR_AS923_SF12
Data rate for region AS923 using SF12 and 125 kHz bandwidth.
Definition ttn.h:155
@ TTN_DR_US915_SF8_BW500
Data rate for region US915 using SF8 and 500 kHz bandwidth.
Definition ttn.h:356
@ TTN_DR_KR920_SF7
Data rate for region KR920 using SF7 and 125 kHz bandwidth.
Definition ttn.h:335
@ TTN_DR_AU915_SF8
Data rate for region AU915 using SF8 and 125 kHz bandwidth.
Definition ttn.h:204
@ TTN_DR_AU915_SF7
Data rate for region AU915 using SF7 and 125 kHz bandwidth.
Definition ttn.h:208
@ TTN_DR_AU915_SF10
Data rate for region AU915 using SF10 and 125 kHz bandwidth.
Definition ttn.h:196
@ TTN_DR_US915_SF9
Data rate for region US915 using SF9 and 125 kHz bandwidth.
Definition ttn.h:344
@ TTN_DR_EU868_SF8
Data rate for region EU868 using SF8 and 125 kHz bandwidth.
Definition ttn.h:269
@ TTN_DR_IN866_FSK
Data rate for region IN866 using FSK and 50 kpbs.
Definition ttn.h:310
@ TTN_DR_US915_SF9_BW500
Data rate for region US915 using SF9 and 500 kHz bandwidth.
Definition ttn.h:380
@ TTN_DR_AS923_SF7_BW250
Data rate for region AS923 using SF7 and 250 kHz bandwidth.
Definition ttn.h:179
@ TTN_DR_IN866_SF7
Data rate for region IN866 using SF7 and 125 kHz bandwidth.
Definition ttn.h:306
@ TTN_DR_US915_SF7
Data rate for region US915 using SF7 and 125 kHz bandwidth.
Definition ttn.h:352
@ TTN_DR_AU915_SF9
Data rate for region AU915 using SF9 and 125 kHz bandwidth.
Definition ttn.h:200
@ TTN_DR_KR920_SF9
Data rate for region KR920 using SF9 and 125 kHz bandwidth.
Definition ttn.h:327
@ TTN_DR_US915_SF8
Data rate for region US915 using SF8 and 125 kHz bandwidth.
Definition ttn.h:348
@ TTN_DR_AS923_SF9
Data rate for region AS923 using SF9 and 125 kHz bandwidth.
Definition ttn.h:167
@ TTN_DR_KR920_SF10
Data rate for region KR920 using SF10 and 125 kHz bandwidth.
Definition ttn.h:323
@ TTN_DR_AU915_SF11
Data rate for region AU915 using SF11 and 125 kHz bandwidth.
Definition ttn.h:192
@ TTN_DR_EU868_SF11
Data rate for region EU868 using SF11 and 125 kHz bandwidth.
Definition ttn.h:257
@ TTN_DR_KR920_SF12
Data rate for region KR920 using SF12 and 125 kHz bandwidth.
Definition ttn.h:315
@ TTN_DR_IN866_SF8
Data rate for region IN866 using SF8 and 125 kHz bandwidth.
Definition ttn.h:302
@ TTN_DR_AS923_SF11
Data rate for region AS923 using SF11 and 125 kHz bandwidth.
Definition ttn.h:159
@ TTN_DR_AU915_SF9_BW500
Data rate for region AU915 using SF9 and 500 kHz bandwidth.
Definition ttn.h:236
@ TTN_DR_AS923_SF7_BW125
Data rate for region AS923 using SF7 and 125 kHz bandwidth.
Definition ttn.h:175
@ TTN_DR_AU915_SF11_BW500
Data rate for region AU915 using SF11 and 500 kHz bandwidth.
Definition ttn.h:224
@ TTN_WINDOW_IDLE
Outside RX/TX window.
Definition ttn.h:67
@ TTN_WINDOW_TX
Transmission window (up to RX1 window)
Definition ttn.h:71
@ TTN_WINDOW_RX2
Reception window 2.
Definition ttn.h:79
@ TTN_WINDOW_RX1
Reception window 1 (up to RX2 window)
Definition ttn.h:75
@ TTN_SUCCESSFUL_RECEIVE
Successful receipt of a downlink message.
Definition ttn.h:56
@ TTN_ERROR_TRANSMISSION_FAILED
Transmission failed error.
Definition ttn.h:50
@ TTN_SUCCESSFUL_TRANSMISSION
Successful transmission of an uplink message.
Definition ttn.h:54
@ TTN_ERROR_UNEXPECTED
Unexpected or internal error.
Definition ttn.h:52
@ TTN_SF10
Spreading Factor 10 (SF10)
Definition ttn.h:110
@ TTN_SF_NONE
Unused / undefined spreading factor.
Definition ttn.h:90
@ TTN_SF11
Spreading Factor 11 (SF11)
Definition ttn.h:114
@ TTN_SF8
Spreading Factor 8 (SF8)
Definition ttn.h:102
@ TTN_SF9
Spreading Factor 9 (SF9)
Definition ttn.h:106
@ TTN_SF7
Spreading Factor 7 (SF7)
Definition ttn.h:98
@ TTN_SF12
Spreading Factor 12 (SF12)
Definition ttn.h:118
@ TTN_FSK
Frequency Shift Keying (FSK)
Definition ttn.h:94
RF settings for TX or RX.
Definition ttn.h:404
uint32_t frequency
Frequency, in Hz.
Definition ttn.h:416
ttn_spreading_factor_t spreading_factor
Spreading Factor (SF)
Definition ttn.h:408
ttn_bandwidth_t bandwidth
Bandwidth (BW)
Definition ttn.h:412