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:
- 13:18de9ee3a461
- Parent:
- 12:ed33c53afcaf
- Child:
- 14:7ac0add1123e
--- a/mac/LoRaMac.cpp Wed Jul 05 18:50:32 2017 +0000 +++ b/mac/LoRaMac.cpp Sat Jul 08 00:35:03 2017 +0000 @@ -279,6 +279,16 @@ LowPowerTimer lp_timer; +#ifdef DEBUG_GWTX_JUMPER +InterruptIn gwtx_pin(DEBUG_GWTX_JUMPER); +unsigned int gwtx_rise_us; + +void gwtx_pin_callback() +{ + gwtx_rise_us = lp_timer.read_us(); +} +#endif + /*! * LoRaMac parameters */ @@ -376,7 +386,8 @@ unsigned int LastBeaconRx_us; // updated only at beacon reception unsigned int LastBeaconStart_us; // updated at beacon reception and beacon reception timeout unsigned int next_beacon_expected_us; - int BeaconRxTimerError_us; + int last_BeaconRxTimerError_us; + int known_working_BeaconRxTimerError_us; float symbol_period_secs; @@ -882,16 +893,17 @@ unsigned int us_since_last = ThisBeaconRx_us - BeaconCtx.LastBeaconRx_us; //unsigned int intervals_since_last = (ThisBeaconRx_us / BEACON_INTERVAL_us) - (BeaconCtx.LastBeaconRx_us / BEACON_INTERVAL_us); unsigned int intervals_since_last = us_since_last / BEACON_INTERVAL_us; + BeaconCtx.known_working_BeaconRxTimerError_us = BeaconCtx.last_BeaconRxTimerError_us; /* get average of error history */ - BeaconCtx.BeaconRxTimerError_us = (ThisBeaconRx_us - BeaconCtx.LastBeaconRx_us) % BEACON_INTERVAL_us; + BeaconCtx.last_BeaconRxTimerError_us = (ThisBeaconRx_us - BeaconCtx.LastBeaconRx_us) % BEACON_INTERVAL_us; /* BeaconRxTimerError: positive means our clock is fast * negative means our clock is slow */ - if (BeaconCtx.BeaconRxTimerError_us > (BEACON_INTERVAL_us/2)) - BeaconCtx.BeaconRxTimerError_us -= BEACON_INTERVAL_us; // negative value representing slow crystal + if (BeaconCtx.last_BeaconRxTimerError_us > (BEACON_INTERVAL_us/2)) + BeaconCtx.last_BeaconRxTimerError_us -= BEACON_INTERVAL_us; // negative value representing slow crystal if (intervals_since_last > 1) { /* timer error is measured over more than one beacon period */ - BeaconCtx.BeaconRxTimerError_us /= intervals_since_last; + BeaconCtx.last_BeaconRxTimerError_us /= intervals_since_last; } if (BeaconCtx.state == BEACON_STATE_ACQ_ERROR) { @@ -907,14 +919,17 @@ BeaconCtx.state = BEACON_STATE_ACQ_ERROR; } - isr_printf("err%d=%u-%u ", BeaconCtx.BeaconRxTimerError_us, ThisBeaconRx_us, BeaconCtx.LastBeaconRx_us); +#ifdef DEBUG_GWTX_JUMPER + isr_printf("rx-before-gwtx:%d ", gwtx_rise_us - BeaconCtx.RxBeaconSetupAt_us); +#endif /* DEBUG_GWTX_JUMPER */ + isr_printf("err%d=%u-%u ", BeaconCtx.last_BeaconRxTimerError_us, ThisBeaconRx_us, BeaconCtx.LastBeaconRx_us); isr_printf(" rx-before-tx:%d ", BeaconCtx.rx_precession_us); BeaconCtx.LastBeaconRx_us = ThisBeaconRx_us; BeaconCtx.LastBeaconStart_us = BeaconCtx.LastBeaconRx_us; if (BeaconCtx.state == BEACON_STATE_LOCKED_) { if (compensate_precession) { - compensation = BeaconCtx.rx_precession_us - TARGET_PRECESSION_US + BeaconCtx.BeaconRxTimerError_us; + compensation = BeaconCtx.rx_precession_us - TARGET_PRECESSION_US + BeaconCtx.last_BeaconRxTimerError_us; isr_printf(" comp%ld", compensation); } } @@ -1127,7 +1142,8 @@ BeaconCtx.state = BEACON_STATE_FIRST_ACQ; BeaconCtx.num_missed = 0; BeaconCtx.rx_precession_us = 0; - BeaconCtx.BeaconRxTimerError_us = -PPM_100_BEACON_INTERVAL; + BeaconCtx.last_BeaconRxTimerError_us = -PPM_100_BEACON_INTERVAL; + BeaconCtx.known_working_BeaconRxTimerError_us = -PPM_100_BEACON_INTERVAL; BeaconCtx.symbol_period_secs = get_symbol_period(GetRxBandwidth(LORAMAC_DEFAULT_DATARATE), Datarates[LORAMAC_DEFAULT_DATARATE]); // N-ms: slot resolution + minimum for preamble detector + 100ppm fast crystal rxing 12ms early BeaconCtx.Precess_symbols = TARGET_PRECESSION_US * (BeaconCtx.symbol_period_secs); @@ -1462,24 +1478,27 @@ if (expecting_beacon) { /* generate simulated last beacon start */ - BeaconCtx.LastBeaconStart_us += BEACON_INTERVAL_us + BeaconCtx.BeaconRxTimerError_us; + BeaconCtx.LastBeaconStart_us += BEACON_INTERVAL_us + BeaconCtx.known_working_BeaconRxTimerError_us; BeaconCtx.next_beacon_expected_us = BEACON_INTERVAL_us; BeaconCtx.num_missed++; unsigned now_us = lp_timer.read_us(); if (BeaconCtx.state == BEACON_STATE_FIRST_ACQ) { BeaconCtx.next_beacon_expected_us -= 1000000; - set_beacon_symbol_timeout(2.000); + set_beacon_symbol_timeou t(2.000); } else { - BeaconCtx.next_beacon_expected_us += BeaconCtx.BeaconRxTimerError_us; + BeaconCtx.next_beacon_expected_us += BeaconCtx.known_working_BeaconRxTimerError_us; // for measurement resolution and temperature drift while missing beacons: - BeaconCtx.next_beacon_expected_us -= 3000; - set_beacon_symbol_timeout(BeaconCtx.SymbolTimeout_sec + 0.006); + BeaconCtx.next_beacon_expected_us -= 5000; + set_beacon_symbol_timeout(BeaconCtx.SymbolTimeout_sec + 0.010); } unsigned us_since_rx_setup = now_us - BeaconCtx.RxBeaconSetupAt_us; BeaconCtx.timeout.attach_us(&OnRxBeaconSetup, BeaconCtx.next_beacon_expected_us - us_since_rx_setup); - - isr_printf("beacon-rx-timeout %u %u next in %uus (%u)\r\n", BeaconCtx.num_missed, BeaconCtx.SymbolTimeout, BeaconCtx.next_beacon_expected_us, us_since_rx_setup); + +#ifdef DEBUG_GWTX_JUMPER + isr_printf("rx-before-gwtx:%d ", gwtx_rise_us - BeaconCtx.RxBeaconSetupAt_us); +#endif /* DEBUG_GWTX_JUMPER */ + isr_printf("beacon-rx-timeout %u %u next in %uus (rxing for %u)\r\n", BeaconCtx.num_missed, BeaconCtx.SymbolTimeout, BeaconCtx.next_beacon_expected_us, us_since_rx_setup); MlmeIndication.MlmeIndication = MLME_BEACON; MlmeIndication.Status = LORAMAC_EVENT_INFO_STATUS_BEACON_LOST; @@ -2281,6 +2300,10 @@ lp_timer.start(); RxWindowsParam = ComputeRxWindowParameters(LORAMAC_DEFAULT_DATARATE, LoRaMacParams.SystemMaxRxError); + +#ifdef DEBUG_GWTX_JUMPER + gwtx_pin.rise(&gwtx_pin_callback); +#endif return LORAMAC_STATUS_OK; }