You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _includes/current/arduino.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,12 @@ sections:
5
5
- arduino/_ide.md
6
6
- arduino/_usage.md
7
7
- arduino/_api.md
8
+
- arduino/_bytes.md
8
9
- arduino/_examples.md
9
10
- arduino/_resources.md
10
11
redirect_from:
11
-
- /arduino/
12
+
- /refactor/arduino/
13
+
- /v2-preview/arduino/
12
14
---
13
15
14
16
[Arduino](https://www.arduino.cc/en/Guide/Introduction) is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects.
@@ -17,8 +19,6 @@ With [The Things Network Library](https://github.com/thethingsnetwork/arduino-de
17
19
18
20
## Prerequisites
19
21
20
-
*Access to [staging.thethingsnetwork.org](https://staging.thethingsnetwork.org/).
22
+
*A staging or preview account.
21
23
* Arduino board with [Microchip RN2xx3 module](http://www.microchip.com/design-centers/wireless-connectivity/embedded-wireless/lora-technology) for LoRaWAN.
22
-
* Version 0.x of the [The Things Network Arduino Library](https://github.com/thethingsnetwork/arduino-device-lib).
23
-
24
-
> Since version 0.17, the library now has its [own repository](https://github.com/thethingsnetwork/arduino-device-lib), can be installed via the [Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3) and has been renamed from `TheThingsUno` to `TheThingsNetwork`. I guess it should have been bumped to 1.x - oops! 😝
24
+
* Version 1.x of the [The Things Network Arduino Library](https://github.com/thethingsnetwork/arduino-device-lib).
<!-- EDIT AT https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/docs/TheThingsNetwork.md -->
2
+
1
3
# API Reference
4
+
Include and instantiate the TheThingsNetwork class. The constructor initialize the library with the Streams it should communicate with. It also sets the value of the spreading factor, the front-side Bus and the frequency plan.
2
5
3
-
Include TheThingsNetwork library:
6
+
## Class: TheThingsNetwork
4
7
5
8
```c
6
9
#include<TheThingsNetwork.h>
7
-
```
8
-
9
-
## Method: reset
10
-
Reset the LoRaWAN module. In most cases you'd call this with no arguments before calling `init()`.
11
-
12
-
```c
13
-
voidreset(bool adr = true, int sf = DEFAULT_SF, int fsb = DEFAULT_FSB);
14
-
```
15
10
16
-
- `bool adr = true` **TODO**
17
-
- `int sf = DEFAULT_SF` **TODO**
18
-
- `int fsb = DEFAULT_FSB` **TODO**
19
-
20
-
## Method: init
21
-
Initialize the library with the streams it should communicate with.
- `const byte appEui[8]`: Application EUI the device is registered to.
64
-
- `const byte appKey[16]`: Application Key assigned to the device.
50
+
- `const byte* payload`: Bytes received.
51
+
- `size_t length`: Number of bytes.
52
+
- `port_t port`: The port addressed.
53
+
54
+
See the [Receive](https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/examples/Receive/Receive.ino) example.
65
55
66
-
Returns `true` or `false` depending on whether it received confirmation that the activation was successful. You'll probably call this method in a while to retry until it returns true:
-`int length`: The number of bytes. Use `sizeof(buffer)` to get it.
98
-
-`int port = 1`: The port to address. Defaults to `1`.
99
-
-`bool confirm = false`: Whether to ask for confirmation.
98
+
-`const byte* payload `: Bytes to send.
99
+
-`size_t length`: The number of bytes. Use `sizeof(payload)` to get it.
100
+
-`port_t port = 1`: The port to address. Defaults to `1`.
101
+
-`bool confirm = false`: Whether to ask for confirmation. Defaults to `false`.
100
102
101
-
- **TODO:** How does one check the result?
103
+
Returns a success or error code and logs the related error message:
102
104
103
-
Returns the size of the message received in response, if any. Use `downlink` for the actual bytes received.
105
+
*`-1`: Send command failed.
106
+
*`-2`: Time-out.
107
+
*`1`: Successful transmission.
108
+
*`2`: Successful transmission. Received \<N> bytes
109
+
*`-10`: Unexpected response: \<Response>
104
110
105
-
## Method: sendString
106
-
Send a message to the application using a string, which the library will encode as bytes for you.
111
+
See the [Send](https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/examples/Send/Send.ino) example.
107
112
108
-
> To minimize air time we advise not to use this method and try to use a minimal amount of bytes to communicate your message.
113
+
Also in sendBytes, due to TTN's 30 second fair access policy, we update the airtime each time we uplink a message. This airtime is based on a lot of variables but the most important ones are the spreading factor and the size of the message, the higher it is the less messages you can send in 30 seconds (SF7 around 500 messages of 8 bytes, SF12 around 20 messages of 8 bytes).
114
+
115
+
## Method: poll
116
+
Calls `sendBytes()` with `{ 0x00 }` as payload to poll for incoming messages.
109
117
110
118
```c
111
-
intsendString(String message, int port = 1, bool confirm = false);
119
+
int8_tpoll(port_t port = 1, bool confirm = false);
112
120
```
113
121
114
-
- `String message`: String to encode and send.
115
-
- `int port = 1`: The port to address. Defaults to `1`.
122
+
- `port_t port = 1`: The port to address. Defaults to `1`.
116
123
- `bool confirm = false`: Whether to ask for confirmation.
117
124
118
-
- **TODO:** How does one check the result?
125
+
Returns the result of `sendBytes()`.
119
126
120
-
Returns the size of the message received in response, if any. Use `downlink` for the actual bytes received.
127
+
See the [Receive](https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/examples/Receive/Receive.ino) example.
121
128
122
-
## Property: downlinkPort
123
-
The port the last message received was addressed to.
129
+
## Method: provision
130
+
Sets the information needed to activate the device via OTAA, without actually activating. Call join() without the first 2 arguments to activate.
0 commit comments