17#ifndef _THETHINGSNETWORK_H_
18#define _THETHINGSNETWORK_H_
454 void configurePins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0, uint8_t dio1)
492 bool provision(
const char *devEui,
const char *appEui,
const char *appKey)
601 bool join(
const char *devEui,
const char *appEui,
const char *appKey)
void(* TTNMessageCallback)(const uint8_t *payload, size_t length, ttn_port_t port)
Callback for recieved messages.
Definition TheThingsNetwork.h:411
TTNBandwidth
Bandwidth.
Definition TheThingsNetwork.h:110
@ kTTNBW250
Bandwidth of 250 kHz.
Definition TheThingsNetwork.h:122
@ kTTNBW125
Bandwidth of 125 kHz.
Definition TheThingsNetwork.h:118
@ kTTNBWNone
Undefined/unused bandwidth.
Definition TheThingsNetwork.h:114
@ kTTNBW500
Bandwidth of 500 kHz.
Definition TheThingsNetwork.h:126
TTNResponseCode
Response codes.
Definition TheThingsNetwork.h:33
@ kTTNErrorUnexpected
Unexpected or internal error.
Definition TheThingsNetwork.h:37
@ kTTNSuccessfulReceive
Successful receipt of a downlink message.
Definition TheThingsNetwork.h:41
@ kTTNSuccessfulTransmission
Successful transmission of an uplink message.
Definition TheThingsNetwork.h:39
@ kTTNErrorTransmissionFailed
Transmission failed error.
Definition TheThingsNetwork.h:35
TTNRxTxWindow
RX/TX window.
Definition TheThingsNetwork.h:48
@ kTTNRx1Window
Reception window 1 (up to RX2 window)
Definition TheThingsNetwork.h:60
@ kTTNRx2Window
Reception window 2.
Definition TheThingsNetwork.h:64
@ kTTNTxWindow
Transmission window (up to RX1 window)
Definition TheThingsNetwork.h:56
@ kTTNIdleWindow
Outside RX/TX window.
Definition TheThingsNetwork.h:52
TTNDataRate
Data Rate.
Definition TheThingsNetwork.h:136
@ kTTNDataRate_AS923_SF9
Data rate for region AS923 using SF9 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:152
@ kTTNDataRate_AS923_SF7_BW125
Data rate for region AS923 using SF7 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:160
@ kTTNDataRate_AU915_SF8
Data rate for region AU915 using SF8 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:189
@ kTTNDataRate_IN866_SF12
Data rate for region IN866 using SF12 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:271
@ kTTNDataRate_US915_SF10
Data rate for region US915 using SF10 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:325
@ kTTNDataRate_AU915_SF10
Data rate for region AU915 using SF10 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:181
@ kTTNDataRate_AU915_SF12_BW500
Data rate for region AU915 using SF12 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:203
@ kTTNDataRate_EU868_SF9
Data rate for region EU868 using SF9 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:250
@ kTTNDataRate_KR920_SF10
Data rate for region KR920 using SF10 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:308
@ kTTNDataRate_AU915_SF7
Data rate for region AU915 using SF7 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:193
@ kTTNDataRate_AU915_SF8_BW500_DR12
Data rate for region AU915 using SF8 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:227
@ kTTNDataRate_EU868_SF10
Data rate for region EU868 using SF10 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:246
@ kTTNDataRate_US915_SF9_BW500
Data rate for region US915 using SF9 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:365
@ kTTNDataRate_AS923_FSK
Data rate for region AS923 using FSK and 50 kpbs.
Definition TheThingsNetwork.h:168
@ kTTNDataRate_AU915_SF8_BW500
Data rate for region AU915 using SF8 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:197
@ kTTNDataRate_AU915_SF12
Data rate for region AU915 using SF12 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:173
@ kTTNDataRate_KR920_SF8
Data rate for region KR920 using SF8 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:316
@ kTTNDataRate_EU868_SF7_BW250
Data rate for region EU868 using SF7 and 250 kHz bandwidth.
Definition TheThingsNetwork.h:262
@ kTTNDataRate_EU868_SF8
Data rate for region EU868 using SF8 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:254
@ kTTNDataRate_AU915_SF7_BW500
Data rate for region AU915 using SF7 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:233
@ kTTNDataRate_AU915_SF11_BW500
Data rate for region AU915 using SF11 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:209
@ kTTNDataRate_IN866_SF10
Data rate for region IN866 using SF10 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:279
@ kTTNDataRate_AS923_SF12
Data rate for region AS923 using SF12 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:140
@ kTTNDataRate_AU915_SF11
Data rate for region AU915 using SF11 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:177
@ kTTNDRJoinDdefault
Default data rate for joining.
Definition TheThingsNetwork.h:382
@ kTTNDataRate_IN866_FSK
Data rate for region IN866 using FSK and 50 kpbs.
Definition TheThingsNetwork.h:295
@ kTTNDataRate_KR920_SF7
Data rate for region KR920 using SF7 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:320
@ kTTNDataRate_US915_SF9
Data rate for region US915 using SF9 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:329
@ kTTNDataRate_EU868_SF7_BW125
Data rate for region EU868 using SF7 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:258
@ kTTNDataRate_US915_SF12_BW500
Data rate for region US915 using SF12 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:347
@ kTTNDataRate_EU868_SF12
Data rate for region EU868 using SF12 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:238
@ kTTNDataRate_AU915_SF9
Data rate for region AU915 using SF9 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:185
@ kTTNDataRate_US915_SF8_BW500
Data rate for region US915 using SF8 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:341
@ kTTNDataRate_KR920_SF12
Data rate for region KR920 using SF12 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:300
@ kTTNDataRate_AS923_SF7_BW250
Data rate for region AS923 using SF7 and 250 kHz bandwidth.
Definition TheThingsNetwork.h:164
@ kTTNDataRate_AU915_SF9_BW500
Data rate for region AU915 using SF9 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:221
@ kTTNDataRate_US915_SF7
Data rate for region US915 using SF7 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:337
@ kTTNDataRate_US915_SF10_BW500
Data rate for region US915 using SF10 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:359
@ kTTNDataRate_AS923_SF8
Data rate for region AS923 using SF8 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:156
@ kTTNDataRate_AU915_SF10_BW500
Data rate for region AU915 using SF10 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:215
@ kTTNDataRate_US915_SF7_BW500
Data rate for region US915 using SF7 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:377
@ kTTNDataRate_US915_SF8
Data rate for region US915 using SF8 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:333
@ kTTNDataRate_AS923_SF11
Data rate for region AS923 using SF11 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:144
@ kTTNDataRate_KR920_SF9
Data rate for region KR920 using SF9 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:312
@ kTTNDataRate_IN866_SF8
Data rate for region IN866 using SF8 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:287
@ kTTNDataRate_IN866_SF9
Data rate for region IN866 using SF9 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:283
@ kTTNDataRate_KR920_SF11
Data rate for region KR920 using SF11 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:304
@ kTTNDataRate_EU868_FSK
Data rate for region EU868 using FSK and 50 kpbs.
Definition TheThingsNetwork.h:266
@ kTTNDataRate_IN866_SF11
Data rate for region IN866 using SF11 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:275
@ kTTNDataRate_US915_SF8_BW500_DR12
Data rate for region US915 using SF8 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:371
@ kTTNDataRate_IN866_SF7
Data rate for region IN866 using SF7 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:291
@ kTTNDataRate_EU868_SF11
Data rate for region EU868 using SF11 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:242
@ kTTNDataRate_AS923_SF10
Data rate for region AS923 using SF10 and 125 kHz bandwidth.
Definition TheThingsNetwork.h:148
@ kTTNDataRate_US915_SF11_BW500
Data rate for region US915 using SF11 and 500 kHz bandwidth.
Definition TheThingsNetwork.h:353
TTNSpreadingFactor
Spreading Factor.
Definition TheThingsNetwork.h:71
@ kTTNFSK
Frequency Shift Keying (FSK)
Definition TheThingsNetwork.h:79
@ kTTNSF11
Spreading Factor 11 (SF11)
Definition TheThingsNetwork.h:99
@ kTTNSF12
Spreading Factor 12 (SF12)
Definition TheThingsNetwork.h:103
@ kTTNSFNone
Unused / undefined spreading factor.
Definition TheThingsNetwork.h:75
@ kTTNSF10
Spreading Factor 10 (SF10)
Definition TheThingsNetwork.h:95
@ kTTNSF8
Spreading Factor 8 (SF8)
Definition TheThingsNetwork.h:87
@ kTTNSF9
Spreading Factor 9 (SF9)
Definition TheThingsNetwork.h:91
@ kTTNSF7
Spreading Factor 7 (SF7)
Definition TheThingsNetwork.h:83
ttn_port_t port_t
Integer data type for specified the port of an uplink or downlink message.
Definition TheThingsNetwork.h:27
TTN device.
Definition TheThingsNetwork.h:422
void startProvisioningTask()
Starts task listening on configured UART for AT commands.
Definition TheThingsNetwork.h:550
void setDataRate(TTNDataRate data_rate)
Sets the transmission data rate (i.e. the data rate for uplink messages).
Definition TheThingsNetwork.h:832
bool provisionWithMAC(const char *appEui, const char *appKey)
Sets the information needed to activate the device via OTAA, using the MAC to generate the DevEUI and...
Definition TheThingsNetwork.h:540
void onMessage(TTNMessageCallback callback)
Sets the function to be called when a message is received.
Definition TheThingsNetwork.h:770
bool join(const char *devEui, const char *appEui, const char *appKey)
Activates the device via OTAA using the provided keys.
Definition TheThingsNetwork.h:601
void setRSSICal(int8_t rssiCal)
Sets the RSSI calibration value for LBT (Listen Before Talk).
Definition TheThingsNetwork.h:796
void waitForProvisioning()
Waits until the DevEUI, AppEUI/JoinEUI and AppKey have been provisioned by the provisioning task.
Definition TheThingsNetwork.h:563
bool provision(const char *devEui, const char *appEui, const char *appKey)
Sets the keys needed to activate the device via OTAA, without activating it.
Definition TheThingsNetwork.h:492
bool resumeAfterPowerOff(int off_duration)
Resumes TTN communication after power off.
Definition TheThingsNetwork.h:643
void setMaxTxPower(int tx_pow)
Sets the maximum power for transmission.
Definition TheThingsNetwork.h:846
int rssi()
Gets the received signal strength indicator (RSSI).
Definition TheThingsNetwork.h:900
void configurePins(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.
Definition TheThingsNetwork.h:454
void shutdown()
Stops all activies.
Definition TheThingsNetwork.h:732
TTNRFSettings getRFSettings(TTNRxTxWindow window)
Gets the RF settings for the specified window.
TTNRFSettings rx2Settings()
Gets the RF settings of the last (or ongoing) reception of RX window 2.
Definition TheThingsNetwork.h:888
bool join()
Activates the device via OTAA using previously provisioned keys.
Definition TheThingsNetwork.h:581
TTNRFSettings rx1Settings()
Gets the RF settings of the last (or ongoing) reception of RX window 1.
Definition TheThingsNetwork.h:879
void prepareForPowerOff()
Stops all activies and prepares for power off.
Definition TheThingsNetwork.h:685
~TheThingsNetwork()
Destroys the The Things Network device instance.
Definition TheThingsNetwork.h:435
void setSubband(int band)
Sets the frequency sub-band to be used.
Definition TheThingsNetwork.h:471
void prepareForDeepSleep()
Stops all activies and prepares for deep sleep.
Definition TheThingsNetwork.h:663
TickType_t busyDuration()
Returns the minimum duration the TTN device is busy.
Definition TheThingsNetwork.h:717
TTNResponseCode transmitMessage(const uint8_t *payload, size_t length, ttn_port_t port=1, bool confirm=false)
Transmits a message.
Definition TheThingsNetwork.h:751
TTNRFSettings txSettings()
Gets the RF settings of the last (or ongoing) transmission.
Definition TheThingsNetwork.h:870
TheThingsNetwork()
Constructs a new The Things Network device instance.
Definition TheThingsNetwork.h:427
bool isProvisioned()
Checks if DevEUI, AppEUI/JoinEUI and AppKey have been stored in non-volatile storage or have been pro...
Definition TheThingsNetwork.h:782
bool adrEnabled()
Definition TheThingsNetwork.h:806
bool resumeAfterDeepSleep()
Resumes TTN communication after deep sleep.
Definition TheThingsNetwork.h:617
bool provisionTransiently(const char *devEui, const char *appEui, const char *appKey)
Sets the keys needed to activate the device via OTAA, without activating it.
Definition TheThingsNetwork.h:510
void waitForIdle()
Waits until the TTN device is idle.
Definition TheThingsNetwork.h:696
TTNRxTxWindow rxTxWindow()
Gets current RX/TX window.
Definition TheThingsNetwork.h:855
void setAdrEnabled(bool enabled)
Enables or disabled Adaptive Data Rate (ADR).
Definition TheThingsNetwork.h:819
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_set_max_tx_pow(int tx_pow)
Sets the maximum power for transmission.
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.
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.
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 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).
void ttn_start_provisioning_task(void)
Starts task listening on configured UART for AT commands.
@ 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_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 TheThingsNetwork.h:389
TTNSpreadingFactor spreadingFactor
Spreading Factor (SF)
Definition TheThingsNetwork.h:393
uint32_t frequency
Frequency, in Hz.
Definition TheThingsNetwork.h:401
TTNBandwidth bandwidth
Bandwidth (BW)
Definition TheThingsNetwork.h:397