end node on synchronous star LoRa network.
Dependencies: SX127x sx12xx_hal TSL2561
radio chip selection
Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
This project for use with LoRaWAN_singlechannel_gateway project.
Alternately gateway running on raspberry pi can be used as gateway.
LoRaWAN on single radio channel
Network description is at gateway project page. Synchronous star network.
Hardware Support
This project supports SX1276 and SX1272, sx126x kit, sx126x shield, and sx128x 2.4GHz. The ST board B-L072Z-LRWAN1 is also supported (TypeABZ module). When B-L072Z-LRWAN1
target is selected, TARGET_DISCO_L072CZ_LRWAN1
is defined by tools, allowing correct radio driver configuration for this platform. Alternately, any mbed board that can use LoRa radio shield board should work, but NUCLEO boards are tested.
End-node Unique ID
DevEUI is created from CPU serial number. AppEUI and AppKey are declared as software constants.
End-node Configuration
Data rate definition LORAMAC_DEFAULT_DATARATE
configured in LoRaMac-definitions.h
. See gateway project page for configuration of gateway.
LoRaWAN addressing is configured in Comissioning.h
; only OTA mode is functional.
Header file board/lora_config.h
, selects application layer options (i.e. sensors) to be compiled in.
Serial Interface
Serial port operates at 115200bps.
Application layer single_us915_main.cpp
User button triggers uplink (i.e. blue button on nucleo board), or jumper enables continuously sends repeated uplink packets. The MAC layer holds each uplink request until the allocated timeslot.
command | arguments | description |
---|---|---|
? | - | print available commands |
. (period) | - | print status (DevEUI, DevAddr, etc) |
ul | length integer | set payload length of test uplink packets |
sensor demo
Selected grove sensors may be plugged into SX1272 shield.
To enable, edit lora_config.h
to define SENSORS
.
Sensor connections on SX1272MB2xAS:
D8 D9: button | RX TX: (unused) | A3 A4: Rotary Angle Sensor |
D6 D7: RGB LED | SCL SDA: digital light sensor | A1 A2: Rotary Angle Sensor |
Digital input pin, state reported via uplink: PC8
Digital output pin, controlled via downlink: PC6
PWM out: PB_10
Jumper enables auto-repeated transmit: PC10
and PC12
on NUCLEO board, located on end of morpho headers nearby JP4.
Diff: mac/LoRaMac.cpp
- Revision:
- 18:9ac71c0eb70d
- Parent:
- 17:3215f12051f9
- Child:
- 20:42839629a5dc
--- a/mac/LoRaMac.cpp Fri Jul 28 22:18:46 2017 +0000 +++ b/mac/LoRaMac.cpp Wed Aug 02 11:42:33 2017 -0700 @@ -210,70 +210,106 @@ */ static uint8_t MacCommandsBufferToRepeat[LORA_MAC_COMMAND_MAX_LENGTH]; +#define BEACON_SIZE 6 /* bytes */ +#define BEACON_CHANNEL_DR LORAMAC_DEFAULT_DATARATE + + #if defined( USE_BAND_915_SINGLE ) -/*! - * Data rates table definition - */ -const uint8_t Datarates[] = { 10, 9, 8, 7, 8, 0, 0, 0, 12, 11, 10, 9, 8, 7, 0, 0 }; - -/*! - * Bandwidths table definition in Hz - */ -const uint32_t Bandwidths[] = { 125000, 125000, 125000, 125000, 500000, 0, 0, 0, 500000, 500000, 500000, 500000, 500000, 500000, 0, 0 }; - -/*! - * LoRaMac bands - */ -/*static Band_t Bands[LORA_MAX_NB_BANDS] = -{ - BAND0, -};*/ - -/*! - * LoRaMAC channels - */ -static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS]; - -/*! - * Tx output powers table definition - */ -const int8_t TxPowers[] = { 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10 }; -#define LORAMAC_FIRST_CHANNEL ( (uint32_t)910.0e6 ) -#define LORAMAC_STEPWIDTH_CHANNEL ( (uint32_t)800e3 ) - -#define BEACON_SIZE 6 /* bytes */ -#define BEACON_CHANNEL_BW 2 /* 2=500KHz */ -#define BEACON_CHANNEL_DR LORAMAC_DEFAULT_DATARATE - -/* measured beacon duration (all at bw500, 6 byte fixed payload length) - * latency assigned for correct rx-before-tx measurement */ -#if (LORAMAC_DEFAULT_DATARATE == DR_8) - #define BEACON_RXDONE_LATENCY_us 6000 - #define BEACON_TOA_us 209000 -#elif (LORAMAC_DEFAULT_DATARATE == DR_9) - #define BEACON_RXDONE_LATENCY_us 3500 - #define BEACON_TOA_us 105000 -#elif (LORAMAC_DEFAULT_DATARATE == DR_10) - #define BEACON_RXDONE_LATENCY_us 1460 - #define BEACON_TOA_us 52800 -#elif (LORAMAC_DEFAULT_DATARATE == DR_11) - #define BEACON_RXDONE_LATENCY_us 2000 - #define BEACON_TOA_us 26000 -#elif (LORAMAC_DEFAULT_DATARATE == DR_12) - #define BEACON_RXDONE_LATENCY_us 1500 - #define BEACON_TOA_us 12800 -#elif (LORAMAC_DEFAULT_DATARATE == DR_13) - #define BEACON_RXDONE_LATENCY_us 1300 - #define BEACON_TOA_us 6560 + /*! + * Data rates table definition + */ + const uint8_t Datarates[] = { 10, 9, 8, 7, 8, 0, 0, 0, 12, 11, 10, 9, 8, 7, 0, 0 }; + + /*! + * Bandwidths table definition in Hz + */ + const uint32_t Bandwidths[] = { 125000, 125000, 125000, 125000, 500000, 0, 0, 0, 500000, 500000, 500000, 500000, 500000, 500000, 0, 0 }; + + /*! + * LoRaMac bands + */ + /*static Band_t Bands[LORA_MAX_NB_BANDS] = + { + BAND0, + };*/ + + /*! + * Tx output powers table definition + */ + const int8_t TxPowers[] = { 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10 }; + #define LORAMAC_FIRST_CHANNEL ( (uint32_t)910.0e6 ) + #define LORAMAC_STEPWIDTH_CHANNEL ( (uint32_t)800e3 ) + #define LORA_MAX_NB_CHANNELS 8 + + #define LORA_BANDWIDTH 2 /* 2=500KHz */ + + /* measured beacon duration (all at bw500, 6 byte fixed payload length) + * latency assigned for correct rx-before-tx measurement */ + #if (LORAMAC_DEFAULT_DATARATE == DR_8) + #define BEACON_RXDONE_LATENCY_us 6000 + #define BEACON_TOA_us 209000 + #elif (LORAMAC_DEFAULT_DATARATE == DR_9) + #define BEACON_RXDONE_LATENCY_us 3500 + #define BEACON_TOA_us 105000 + #elif (LORAMAC_DEFAULT_DATARATE == DR_10) + #define BEACON_RXDONE_LATENCY_us 1460 + #define BEACON_TOA_us 52800 + #elif (LORAMAC_DEFAULT_DATARATE == DR_11) + #define BEACON_RXDONE_LATENCY_us 2000 + #define BEACON_TOA_us 26000 + #elif (LORAMAC_DEFAULT_DATARATE == DR_12) + #define BEACON_RXDONE_LATENCY_us 1500 + #define BEACON_TOA_us 12800 + #elif (LORAMAC_DEFAULT_DATARATE == DR_13) + #define BEACON_RXDONE_LATENCY_us 1300 + #define BEACON_TOA_us 6560 + #else + #error datarate + #endif + + /* end us915 */ +#elif defined(USE_BAND_433) && defined(ENABLE_SX1276) + const uint8_t Datarates[] = { 12, 11, 10, 9, 8, 7, 7, 50 }; + const uint32_t Bandwidths[] = { 125000, 125000, 125000, 125000, 125000, 125000, 250000, 0 }; + const int8_t TxPowers[] = { 10, 7, 4, 1, -2, -5 }; + #define LORA_BANDWIDTH 0 /* 0=125KHz */ + + #define LORAMAC_FIRST_CHANNEL ( (uint32_t)433.32e6 ) + #define LORAMAC_STEPWIDTH_CHANNEL ( (uint32_t)200e3 ) + #define LORA_MAX_NB_CHANNELS 7 + + #if (LORAMAC_DEFAULT_DATARATE == DR_0) + #define BEACON_RXDONE_LATENCY_us 27500 + #define BEACON_TOA_us 828100 + #elif (LORAMAC_DEFAULT_DATARATE == DR_1) + #define BEACON_RXDONE_LATENCY_us 12500 + #define BEACON_TOA_us 414400 + #elif (LORAMAC_DEFAULT_DATARATE == DR_2) + #define BEACON_RXDONE_LATENCY_us 6000 + #define BEACON_TOA_us 207500 + #elif (LORAMAC_DEFAULT_DATARATE == DR_3) + #define BEACON_RXDONE_LATENCY_us 3840 + #define BEACON_TOA_us 103000 + #elif (LORAMAC_DEFAULT_DATARATE == DR_4) + #define BEACON_RXDONE_LATENCY_us 2800 + #define BEACON_TOA_us 51000 + #elif (LORAMAC_DEFAULT_DATARATE == DR_5) + #define BEACON_RXDONE_LATENCY_us 1400 + #define BEACON_TOA_us 25800 + #else + #error datarate + #endif + + /* end USE_BAND_433 */ +#else + #error "Please define a frequency band in the compiler options." #endif +static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS]; // populated in init + #define BEACON_GUARD_us 2000000 // pre-beacon start #define BEACON_RESERVED_us 2120000 // post-beacon start -#else - #error "Please define a frequency band in the compiler options." -#endif - #define BEACON_MIN_SYMBOL_TIMEOUT 8 LowPowerTimer lp_timer; @@ -741,10 +777,12 @@ void send_callback() { if (BeaconCtx.guard) { - McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR_INCOMPLETE; - MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR_INCOMPLETE; - LoRaMacFlags.Bits.MacDone = 1; - LoRaMacPrimitives->MacMcpsConfirm( &McpsConfirm ); + if (LoRaMacFlags.Bits.pending_tx) { + McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR_INCOMPLETE; + MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR_INCOMPLETE; + LoRaMacFlags.Bits.MacDone = 1; + LoRaMacPrimitives->MacMcpsConfirm( &McpsConfirm ); + } return; } @@ -757,7 +795,7 @@ /* RadioModems_t modem */ MODEM_LORA, /* int8_t power */ TxPowers[LoRaMacParams.ChannelsTxPower], /* uint32_t fdev */ 0, - /* uint32_t bandwidth */ 2, + /* uint32_t bandwidth */ LORA_BANDWIDTH, /* uint32_t datarate */ Datarates[LoRaMacParams.ChannelsDatarate_fixed], /* uint8_t coderate */ 1, /* uint16_t preambleLen */ 8, @@ -784,7 +822,7 @@ Radio.SetRxConfig( /* RadioModems_t */ MODEM_LORA, - /* uint32_t bandwidth */ BEACON_CHANNEL_BW, + /* uint32_t bandwidth */ LORA_BANDWIDTH, /* uint32_t datarate */ Datarates[BEACON_CHANNEL_DR], /* uint8_t coderate */ 1, /* uint32_t bandwidthAfc */ 0, @@ -2000,12 +2038,34 @@ Radio.SetChannel( channel.Frequency ); +#if defined( USE_BAND_915_SINGLE ) if( LoRaMacParams.ChannelsDatarate_fixed >= DR_8 ) { // High speed LoRa channel BW500 kHz - //Radio.SetTxConfig( MODEM_LORA, txPower, 0, 2, datarate, 1, 8, false, true, 0, 0, false, 3e3 ); + Radio.SetTxConfig( MODEM_LORA, txPower, 0, 2, datarate, 1, 8, false, true, 0, 0, false, 3e3 ); TxTimeOnAir = Radio.TimeOnAir( MODEM_LORA, LoRaMacBufferPktLen ); } else return LORAMAC_STATUS_DATARATE_INVALID; +#elif defined(USE_BAND_433) && defined (ENABLE_SX1276) + if( LoRaMacParams.ChannelsDatarate_fixed == DR_7 ) + { // High Speed FSK channel + //Radio.SetMaxPayloadLength( MODEM_FSK, LoRaMacBufferPktLen ); + Radio.SetTxConfig( MODEM_FSK, txPower, 25e3, 0, datarate * 1e3, 0, 5, false, true, 0, 0, false, 3e3 ); + TxTimeOnAir = Radio.TimeOnAir( MODEM_FSK, LoRaMacBufferPktLen ); + + } + else if( LoRaMacParams.ChannelsDatarate_fixed == DR_6 ) + { // High speed LoRa channel + //Radio.SetMaxPayloadLength( MODEM_LORA, LoRaMacBufferPktLen ); + Radio.SetTxConfig( MODEM_LORA, txPower, 0, 1, datarate, 1, 8, false, true, 0, 0, false, 3e3 ); + TxTimeOnAir = Radio.TimeOnAir( MODEM_LORA, LoRaMacBufferPktLen ); + } + else + { // Normal LoRa channel + //Radio.SetMaxPayloadLength( MODEM_LORA, LoRaMacBufferPktLen ); + Radio.SetTxConfig( MODEM_LORA, txPower, 0, 0, datarate, 1, 8, false, true, 0, 0, false, 3e3 ); + TxTimeOnAir = Radio.TimeOnAir( MODEM_LORA, LoRaMacBufferPktLen ); + } +#endif // Store the time on air McpsConfirm.TxTimeOnAir = TxTimeOnAir; @@ -2022,7 +2082,6 @@ LoRaMacHeader_t* macHdr = (LoRaMacHeader_t*)&LoRaMacBuffer[0]; if (macHdr->Bits.MType == FRAME_TYPE_JOIN_REQ) { // Send now - Radio.SetTxConfig( MODEM_LORA, txPower, 0, 2, datarate, 1, 8, false, true, 0, 0, false, 3e3 ); Radio.Send( LoRaMacBuffer, LoRaMacBufferPktLen ); } else { @@ -2095,16 +2154,12 @@ LoRaMacParamsDefaults.ChannelsNbRep = 1; LoRaMacParamsDefaults.Rx1DrOffset = 0; - -#if defined(USE_BAND_915_SINGLE) - // 500 kHz channels for( uint8_t i = 0; i < LORA_MAX_NB_CHANNELS; i++ ) { Channels[i].Frequency = LORAMAC_FIRST_CHANNEL + (i * LORAMAC_STEPWIDTH_CHANNEL); - Channels[i].DrRange.Value = ( DR_13 << 4 ) | DR_8; + Channels[i].DrRange.Value = (LORAMAC_MAX_DATARATE << 4) | LORAMAC_MIN_DATARATE; Channels[i].Band = 0; } -#endif // Init parameters which are not set in function ResetMacParameters LoRaMacParams.SystemMaxRxError = LoRaMacParamsDefaults.SystemMaxRxError;