@@ -74,9 +74,9 @@ static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS * EVENTS_EVENT_SIZE);
74
74
static void lora_event_handler (lorawan_event_t event);
75
75
76
76
/* *
77
- * Constructing Mbed LoRaWANInterface and passing it down the radio object.
77
+ * Pointer to LoRaWAN interface
78
78
*/
79
- static LoRaWANInterface lorawan (get_lora_radio()) ;
79
+ static LoRaWANInterface* lorawan = NULL ;
80
80
81
81
/* *
82
82
* Application specific callbacks
@@ -88,14 +88,18 @@ static lorawan_app_callbacks_t callbacks;
88
88
*/
89
89
int main (void )
90
90
{
91
+ // Constructing Mbed LoRaWANInterface and passing it down the radio object.
92
+ LoRaWANInterface lora (get_lora_radio ());
93
+ lorawan = &lora;
94
+
91
95
// setup tracing
92
96
setup_trace ();
93
97
94
98
// stores the status of a call to LoRaWAN protocol
95
99
lorawan_status_t retcode;
96
100
97
101
// Initialize LoRaWAN stack
98
- if (lorawan. initialize (&ev_queue) != LORAWAN_STATUS_OK) {
102
+ if (lorawan-> initialize (&ev_queue) != LORAWAN_STATUS_OK) {
99
103
printf (" \r\n LoRa initialization failed! \r\n " );
100
104
return -1 ;
101
105
}
@@ -104,10 +108,10 @@ int main (void)
104
108
105
109
// prepare application callbacks
106
110
callbacks.events = mbed::callback (lora_event_handler);
107
- lorawan. add_app_callbacks (&callbacks);
111
+ lorawan-> add_app_callbacks (&callbacks);
108
112
109
113
// Set number of retries in case of CONFIRMED messages
110
- if (lorawan. set_confirmed_msg_retries (CONFIRMED_MSG_RETRY_COUNTER)
114
+ if (lorawan-> set_confirmed_msg_retries (CONFIRMED_MSG_RETRY_COUNTER)
111
115
!= LORAWAN_STATUS_OK) {
112
116
printf (" \r\n set_confirmed_msg_retries failed! \r\n\r\n " );
113
117
return -1 ;
@@ -117,14 +121,14 @@ int main (void)
117
121
CONFIRMED_MSG_RETRY_COUNTER);
118
122
119
123
// Enable adaptive data rate
120
- if (lorawan. enable_adaptive_datarate () != LORAWAN_STATUS_OK) {
124
+ if (lorawan-> enable_adaptive_datarate () != LORAWAN_STATUS_OK) {
121
125
printf (" \r\n enable_adaptive_datarate failed! \r\n " );
122
126
return -1 ;
123
127
}
124
128
125
129
printf (" \r\n Adaptive data rate (ADR) - Enabled \r\n " );
126
130
127
- retcode = lorawan. connect ();
131
+ retcode = lorawan-> connect ();
128
132
129
133
if (retcode == LORAWAN_STATUS_OK ||
130
134
retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
@@ -161,7 +165,7 @@ static void send_message()
161
165
packet_len = sprintf ((char *) tx_buffer, " Dummy Sensor Value is %3.1f" ,
162
166
sensor_value);
163
167
164
- retcode = lorawan. send (MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
168
+ retcode = lorawan-> send (MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
165
169
MSG_CONFIRMED_FLAG);
166
170
167
171
if (retcode < 0 ) {
@@ -180,7 +184,7 @@ static void send_message()
180
184
static void receive_message ()
181
185
{
182
186
int16_t retcode;
183
- retcode = lorawan. receive (MBED_CONF_LORA_APP_PORT, rx_buffer,
187
+ retcode = lorawan-> receive (MBED_CONF_LORA_APP_PORT, rx_buffer,
184
188
LORAMAC_PHY_MAXPAYLOAD,
185
189
MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG);
186
190
0 commit comments