ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#pragma once
2
3#include <RadioLib.h>
4
5#include "libtockHal.h"
6
7// first you have to set your radio model and pin configuration
8// this is provided just as a default example
9
10// create a new instance of the HAL class
11
12// if you have RadioBoards (https://github.com/radiolib-org/RadioBoards)
13// and are using one of the supported boards, you can do the following:
14/*
15#define RADIO_BOARD_AUTO
16#include <RadioBoards.h>
17
18Radio radio = new RadioModule();
19*/
20
21// how often to send an uplink - consider legal & FUP constraints - see notes
22const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
23
24// joinEUI - previous versions of LoRaWAN called this AppEUI
25// for development purposes you can use all zeros - see wiki for details
26#define RADIOLIB_LORAWAN_JOIN_EUI 01, 01, 01, 01, 01, 01, 01, 01
27
28// the Device EUI & two keys can be generated on the TTN console
29#ifndef RADIOLIB_LORAWAN_DEV_EUI // Replace with your Device EUI
30// #define RADIOLIB_LORAWAN_DEV_EUI 05,38,04,D9,00,80,E1,15
31#define RADIOLIB_LORAWAN_DEV_EUI 70, B3, D5, 7E, D0, 07, 74, 17
32#endif
33#ifndef RADIOLIB_LORAWAN_APP_KEY // Replace with your App Key
34#define RADIOLIB_LORAWAN_APP_KEY \
35 2B,7E,15,16,28,AE,D2,A6,AB,F7,15,88,09,CF,4F,3C
36#endif
37#ifndef RADIOLIB_LORAWAN_NWK_KEY // Put your Nwk Key here
38#define RADIOLIB_LORAWAN_NWK_KEY \
39 2B,7E,15,16,28,AE,D2,A6,AB,F7,15,88,09,CF,4F,3C
40#endif
41
42// for the curious, the #ifndef blocks allow for automated testing &/or you can
43// put your EUI & keys in to your platformio.ini - see wiki for more tips
44
45// regional choices: EU868, US915, AU915, AS923, AS923_2, AS923_3, AS923_4,
46// IN865, KR920, CN470
47const LoRaWANBand_t* Region = &US915;
48
49// subband choice: for US915/AU915 set to 2, for CN470 set to 1, otherwise leave
50// on 0
51const uint8_t subBand = 2;
52
53#define RAW_TO_INT8A(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
54 {0x##a, 0x##b, 0x##c, 0x##d, 0x##e, 0x##f, 0x##g, 0x##h, \
55 0x##i, 0x##j, 0x##k, 0x##l, 0x##m, 0x##n, 0x##o, 0x##p}
56
57#define RAW8_TO_INT8A(a, b, c, d) 0x##a##b##c##d
58#define RAW32_TO_INT8A(a, b, c, d, e, f, g, h) \
59 {0x##a, 0x##b, 0x##c, 0x##d, 0x##e, 0x##f, 0x##g, 0x##h}
60
61#define FORMAT_KEY(...) RAW_TO_INT8A(__VA_ARGS__)
62#define FORMAT8_KEY(...) RAW8_TO_INT8A(__VA_ARGS__)
63#define FORMAT32_KEY(...) RAW32_TO_INT8A(__VA_ARGS__)
64
65// Big-endian: b[0] is MSB, b[7] is LSB
66static inline uint64_t bytes_to_u64_be(const uint8_t b[8]) {
67 return ((uint64_t)b[0] << 56) | ((uint64_t)b[1] << 48) |
68 ((uint64_t)b[2] << 40) | ((uint64_t)b[3] << 32) |
69 ((uint64_t)b[4] << 24) | ((uint64_t)b[5] << 16) |
70 ((uint64_t)b[6] << 8) | ((uint64_t)b[7]);
71}
72
73static inline uint64_t bytes_to_u64_le(const uint8_t b[8]) {
74 return ((uint64_t)b[7] << 56) | ((uint64_t)b[6] << 48) |
75 ((uint64_t)b[5] << 40) | ((uint64_t)b[4] << 32) |
76 ((uint64_t)b[3] << 24) | ((uint64_t)b[2] << 16) |
77 ((uint64_t)b[1] << 8) | ((uint64_t)b[0]);
78}
79
80static inline void u64_to_bytes_be(uint64_t value, uint8_t b[8]) {
81 b[0] = (value >> 56) & 0xFF;
82 b[1] = (value >> 48) & 0xFF;
83 b[2] = (value >> 40) & 0xFF;
84 b[3] = (value >> 32) & 0xFF;
85 b[4] = (value >> 24) & 0xFF;
86 b[5] = (value >> 16) & 0xFF;
87 b[6] = (value >> 8) & 0xFF;
88 b[7] = value & 0xFF;
89}
90
91static inline void u64_to_bytes_le(uint64_t value, uint8_t b[8]) {
92 b[7] = (value >> 56) & 0xFF;
93 b[6] = (value >> 48) & 0xFF;
94 b[5] = (value >> 40) & 0xFF;
95 b[4] = (value >> 32) & 0xFF;
96 b[3] = (value >> 24) & 0xFF;
97 b[2] = (value >> 16) & 0xFF;
98 b[1] = (value >> 8) & 0xFF;
99 b[0] = value & 0xFF;
100}
101
102// ============================================================================
103// Below is to support the sketch - only make changes if the notes say so ...
104
105// copy over the EUI's & keys in to the something that will not compile if
106// incorrectly formatted build a byte array first (can't pass a braced-init-list
107// directly to the function)
108
109// devEUI: if you want to provide 8 raw bytes, define RADIOLIB_LORAWAN_DEV_EUI
110// as 8 comma-separated bytes. If RADIOLIB_LORAWAN_DEV_EUI is a single integer,
111// keep the cast below.
112/* Example for 8-byte DEV EUI:
113 #define RADIOLIB_LORAWAN_DEV_EUI 01,02,03,04,05,06,07,08
114 then use:
115 static const uint8_t devEUI_bytes[8] =
116 FORMAT32_KEY(RADIOLIB_LORAWAN_DEV_EUI); static const uint64_t devEUI =
117 bytes_to_u64_be(devEUI_bytes);
118*/
const LoRaWANBand_t * Region
Definition config.h:47
const uint8_t subBand
Definition config.h:51
const uint32_t uplinkIntervalSeconds
Definition config.h:22