@@ -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
0 commit comments