Skip to content

Commit 3816620

Browse files
authored
Merge pull request #572 from mcci-catena/issue550
Fix errors, omissions in examples.
2 parents 54c13ec + 47bfead commit 3816620

File tree

3 files changed

+249
-13
lines changed

3 files changed

+249
-13
lines changed

examples/raw/raw.ino

Lines changed: 208 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,221 @@ void setup() {
139139
// initialize runtime env
140140
os_init();
141141

142-
// Set up these settings once, and use them for both TX and RX
143-
144142
#if defined(CFG_eu868)
145143
// Use a frequency in the g3 which allows 10% duty cycling.
146144
LMIC.freq = 869525000;
145+
// Use a medium spread factor. This can be increased up to SF12 for
146+
// better range, but then, the interval should be (significantly)
147+
// raised to comply with duty cycle limits as well.
148+
LMIC.datarate = DR_SF9;
149+
// Maximum TX power
150+
LMIC.txpow = 27;
147151
#elif defined(CFG_us915)
148-
LMIC.freq = 902300000;
152+
// make it easier for test, by pull the parameters up to the top of the
153+
// block. Ideally, we'd use the serial port to drive this; or have
154+
// a voting protocol where one side is elected the controller and
155+
// guides the responder through all the channels, powers, ramps
156+
// the transmit power from min to max, and measures the RSSI and SNR.
157+
// Even more amazing would be a scheme where the controller could
158+
// handle multiple nodes; in that case we'd have a way to do
159+
// production test and qualification. However, using an RWC5020A
160+
// is a much better use of development time.
161+
162+
// set fDownlink true to use a downlink channel; false
163+
// to use an uplink channel. Generally speaking, uplink
164+
// is more interesting, because you can prove that gateways
165+
// *should* be able to hear you.
166+
const static bool fDownlink = false;
167+
168+
// the downlink channel to be used.
169+
const static uint8_t kDownlinkChannel = 3;
170+
171+
// the uplink channel to be used.
172+
const static uint8_t kUplinkChannel = 8 + 3;
173+
174+
// this is automatically set to the proper bandwidth in kHz,
175+
// based on the selected channel.
176+
uint32_t uBandwidth;
177+
178+
if (! fDownlink)
179+
{
180+
if (kUplinkChannel < 64)
181+
{
182+
LMIC.freq = US915_125kHz_UPFBASE +
183+
kUplinkChannel * US915_125kHz_UPFSTEP;
184+
uBandwidth = 125;
185+
}
186+
else
187+
{
188+
LMIC.freq = US915_500kHz_UPFBASE +
189+
(kUplinkChannel - 64) * US915_500kHz_UPFSTEP;
190+
uBandwidth = 500;
191+
}
192+
}
193+
else
194+
{
195+
// downlink channel
196+
LMIC.freq = US915_500kHz_DNFBASE +
197+
kDownlinkChannel * US915_500kHz_DNFSTEP;
198+
uBandwidth = 500;
199+
}
200+
201+
// Use a suitable spreading factor
202+
if (uBandwidth < 500)
203+
LMIC.datarate = US915_DR_SF7; // DR4
204+
else
205+
LMIC.datarate = US915_DR_SF12CR; // DR8
206+
207+
// default tx power for US: 21 dBm
208+
LMIC.txpow = 21;
209+
#elif defined(CFG_au915)
210+
// make it easier for test, by pull the parameters up to the top of the
211+
// block. Ideally, we'd use the serial port to drive this; or have
212+
// a voting protocol where one side is elected the controller and
213+
// guides the responder through all the channels, powers, ramps
214+
// the transmit power from min to max, and measures the RSSI and SNR.
215+
// Even more amazing would be a scheme where the controller could
216+
// handle multiple nodes; in that case we'd have a way to do
217+
// production test and qualification. However, using an RWC5020A
218+
// is a much better use of development time.
219+
220+
// set fDownlink true to use a downlink channel; false
221+
// to use an uplink channel. Generally speaking, uplink
222+
// is more interesting, because you can prove that gateways
223+
// *should* be able to hear you.
224+
const static bool fDownlink = false;
225+
226+
// the downlink channel to be used.
227+
const static uint8_t kDownlinkChannel = 3;
228+
229+
// the uplink channel to be used.
230+
const static uint8_t kUplinkChannel = 8 + 3;
231+
232+
// this is automatically set to the proper bandwidth in kHz,
233+
// based on the selected channel.
234+
uint32_t uBandwidth;
235+
236+
if (! fDownlink)
237+
{
238+
if (kUplinkChannel < 64)
239+
{
240+
LMIC.freq = AU915_125kHz_UPFBASE +
241+
kUplinkChannel * AU915_125kHz_UPFSTEP;
242+
uBandwidth = 125;
243+
}
244+
else
245+
{
246+
LMIC.freq = AU915_500kHz_UPFBASE +
247+
(kUplinkChannel - 64) * AU915_500kHz_UPFSTEP;
248+
uBandwidth = 500;
249+
}
250+
}
251+
else
252+
{
253+
// downlink channel
254+
LMIC.freq = AU915_500kHz_DNFBASE +
255+
kDownlinkChannel * AU915_500kHz_DNFSTEP;
256+
uBandwidth = 500;
257+
}
258+
259+
// Use a suitable spreading factor
260+
if (uBandwidth < 500)
261+
LMIC.datarate = AU915_DR_SF7; // DR4
262+
else
263+
LMIC.datarate = AU915_DR_SF12CR; // DR8
264+
265+
// default tx power for AU: 30 dBm
266+
LMIC.txpow = 30;
267+
#elif defined(CFG_as923)
268+
// make it easier for test, by pull the parameters up to the top of the
269+
// block. Ideally, we'd use the serial port to drive this; or have
270+
// a voting protocol where one side is elected the controller and
271+
// guides the responder through all the channels, powers, ramps
272+
// the transmit power from min to max, and measures the RSSI and SNR.
273+
// Even more amazing would be a scheme where the controller could
274+
// handle multiple nodes; in that case we'd have a way to do
275+
// production test and qualification. However, using an RWC5020A
276+
// is a much better use of development time.
277+
const static uint8_t kChannel = 0;
278+
uint32_t uBandwidth;
279+
280+
LMIC.freq = AS923_F1 + kChannel * 200000;
281+
uBandwidth = 125;
282+
283+
// Use a suitable spreading factor
284+
if (uBandwidth == 125)
285+
LMIC.datarate = AS923_DR_SF7; // DR7
286+
else
287+
LMIC.datarate = AS923_DR_SF7B; // DR8
288+
289+
// default tx power for AS: 21 dBm
290+
LMIC.txpow = 16;
291+
292+
if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP)
293+
{
294+
LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US);
295+
LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX;
296+
}
297+
#elif defined(CFG_kr920)
298+
// make it easier for test, by pull the parameters up to the top of the
299+
// block. Ideally, we'd use the serial port to drive this; or have
300+
// a voting protocol where one side is elected the controller and
301+
// guides the responder through all the channels, powers, ramps
302+
// the transmit power from min to max, and measures the RSSI and SNR.
303+
// Even more amazing would be a scheme where the controller could
304+
// handle multiple nodes; in that case we'd have a way to do
305+
// production test and qualification. However, using an RWC5020A
306+
// is a much better use of development time.
307+
const static uint8_t kChannel = 0;
308+
uint32_t uBandwidth;
309+
310+
LMIC.freq = KR920_F1 + kChannel * 200000;
311+
uBandwidth = 125;
312+
313+
LMIC.datarate = KR920_DR_SF7; // DR7
314+
// default tx power for KR: 14 dBm
315+
LMIC.txpow = KR920_TX_EIRP_MAX_DBM;
316+
if (LMIC.freq < KR920_F14DBM)
317+
LMIC.txpow = KR920_TX_EIRP_MAX_DBM_LOW;
318+
319+
LMIC.lbt_ticks = us2osticks(KR920_LBT_US);
320+
LMIC.lbt_dbmax = KR920_LBT_DB_MAX;
321+
#elif defined(CFG_in866)
322+
// make it easier for test, by pull the parameters up to the top of the
323+
// block. Ideally, we'd use the serial port to drive this; or have
324+
// a voting protocol where one side is elected the controller and
325+
// guides the responder through all the channels, powers, ramps
326+
// the transmit power from min to max, and measures the RSSI and SNR.
327+
// Even more amazing would be a scheme where the controller could
328+
// handle multiple nodes; in that case we'd have a way to do
329+
// production test and qualification. However, using an RWC5020A
330+
// is a much better use of development time.
331+
const static uint8_t kChannel = 0;
332+
uint32_t uBandwidth;
333+
334+
LMIC.freq = IN866_F1 + kChannel * 200000;
335+
uBandwidth = 125;
336+
337+
LMIC.datarate = IN866_DR_SF7; // DR7
338+
// default tx power for IN: 30 dBm
339+
LMIC.txpow = IN866_TX_EIRP_MAX_DBM;
149340
#else
150-
error Region not supported!
341+
# error Unsupported LMIC regional configuration.
151342
#endif
152343

153-
// Maximum TX power
154-
LMIC.txpow = 27;
155-
// Use a medium spread factor. This can be increased up to SF12 for
156-
// better range, but then the interval should be (significantly)
157-
// lowered to comply with duty cycle limits as well.
158-
LMIC.datarate = DR_SF9;
344+
345+
// disable RX IQ inversion
346+
LMIC.noRXIQinversion = true;
347+
348+
// This sets CR 4/5, BW125 (except for EU/AS923 DR_SF7B, which uses BW250)
349+
LMIC.rps = updr2rps(LMIC.datarate);
350+
351+
Serial.print("Frequency: "); Serial.print(LMIC.freq / 1000000);
352+
Serial.print("."); Serial.print((LMIC.freq / 100000) % 10);
353+
Serial.print("MHz");
354+
Serial.print(" LMIC.datarate: "); Serial.print(LMIC.datarate);
355+
Serial.print(" LMIC.txpow: "); Serial.println(LMIC.txpow);
356+
159357
// This sets CR 4/5, BW125 (except for DR_SF7B, which uses BW250)
160358
LMIC.rps = updr2rps(LMIC.datarate);
161359

examples/ttn-abp/ttn-abp.ino

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ void setup() {
237237
// frequencies, so be sure to configure the full frequency range of
238238
// your network here (unless your network autoconfigures them).
239239
// Setting up channels should happen after LMIC_setSession, as that
240-
// configures the minimal channel set.
240+
// configures the minimal channel set. The LMIC doesn't let you change
241+
// the three basic settings, but we show them here.
241242
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
242243
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band
243244
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
@@ -251,12 +252,39 @@ void setup() {
251252
// devices' ping slots. LMIC does not have an easy way to define set this
252253
// frequency and support for class B is spotty and untested, so this
253254
// frequency is not configured here.
254-
#elif defined(CFG_us915)
255-
// NA-US channels 0-71 are configured automatically
255+
#elif defined(CFG_us915) || defined(CFG_au915)
256+
// NA-US and AU channels 0-71 are configured automatically
256257
// but only one group of 8 should (a subband) should be active
257258
// TTN recommends the second sub band, 1 in a zero based count.
258259
// https://github.com/TheThingsNetwork/gateway-conf/blob/master/US-global_conf.json
259260
LMIC_selectSubBand(1);
261+
#elif defined(CFG_as923)
262+
// Set up the channels used in your country. Only two are defined by default,
263+
// and they cannot be changed. Use BAND_CENTI to indicate 1% duty cycle.
264+
// LMIC_setupChannel(0, 923200000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);
265+
// LMIC_setupChannel(1, 923400000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);
266+
267+
// ... extra definitions for channels 2..n here
268+
#elif defined(CFG_kr920)
269+
// Set up the channels used in your country. Three are defined by default,
270+
// and they cannot be changed. Duty cycle doesn't matter, but is conventionally
271+
// BAND_MILLI.
272+
// LMIC_setupChannel(0, 922100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
273+
// LMIC_setupChannel(1, 922300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
274+
// LMIC_setupChannel(2, 922500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
275+
276+
// ... extra definitions for channels 3..n here.
277+
#elif defined(CFG_in866)
278+
// Set up the channels used in your country. Three are defined by default,
279+
// and they cannot be changed. Duty cycle doesn't matter, but is conventionally
280+
// BAND_MILLI.
281+
// LMIC_setupChannel(0, 865062500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
282+
// LMIC_setupChannel(1, 865402500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
283+
// LMIC_setupChannel(2, 865985000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
284+
285+
// ... extra definitions for channels 3..n here.
286+
#else
287+
# error Region not supported
260288
#endif
261289

262290
// Disable link check validation

examples/ttn-otaa/ttn-otaa.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ void onEvent (ev_t ev) {
192192
case EV_TXSTART:
193193
Serial.println(F("EV_TXSTART"));
194194
break;
195+
case EV_TXCANCELED:
196+
Serial.println(F("EV_TXCANCELED"));
197+
break;
198+
case EV_RXSTART:
199+
/* do not print anything -- it wrecks timing */
200+
break;
201+
case EV_JOIN_TXCOMPLETE:
202+
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
203+
break;
204+
195205
default:
196206
Serial.print(F("Unknown event: "));
197207
Serial.println((unsigned) ev);

0 commit comments

Comments
 (0)