Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 396d71b

Browse files
author
iwahdan88
committed
Merge remote-tracking branch 'iwahdan/master'
2 parents 448f3cf + 7cb1a38 commit 396d71b

File tree

6 files changed

+93
-6
lines changed

6 files changed

+93
-6
lines changed

esp32/mods/modbt.c

+24-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
******************************************************************************/
5959
#define BT_SCAN_QUEUE_SIZE_MAX (16)
6060
#define BT_GATTS_QUEUE_SIZE_MAX (2)
61-
#define BT_CHAR_VALUE_SIZE_MAX (20)
61+
#define BT_MTU_SIZE_MAX (200)
62+
#define BT_CHAR_VALUE_SIZE_MAX (BT_MTU_SIZE_MAX - 3)
6263

6364
#define MOD_BT_CLIENT_APP_ID (0)
6465
#define MOD_BT_SERVER_APP_ID (1)
@@ -209,6 +210,9 @@ static volatile bt_obj_t bt_obj;
209210
static QueueHandle_t xScanQueue;
210211
static QueueHandle_t xGattsQueue;
211212

213+
static esp_ble_adv_data_t adv_data;
214+
static esp_ble_adv_data_t scan_rsp_data;
215+
212216
static const mp_obj_type_t mod_bt_connection_type;
213217
static const mp_obj_type_t mod_bt_service_type;
214218
static const mp_obj_type_t mod_bt_characteristic_type;
@@ -219,7 +223,7 @@ static const mp_obj_type_t mod_bt_gatts_char_type;
219223

220224
static esp_ble_adv_params_t bt_adv_params = {
221225
.adv_int_min = 0x20,
222-
.adv_int_max = 0x20,
226+
.adv_int_max = 0x40,
223227
.adv_type = ADV_TYPE_IND,
224228
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
225229
.channel_map = ADV_CHNL_ALL,
@@ -451,6 +455,7 @@ static void gattc_events_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc
451455
bt_obj.busy = false;
452456
// intentional fall through
453457
case ESP_GATTC_CLOSE_EVT:
458+
case ESP_GATTC_DISCONNECT_EVT:
454459
close_connection(p_data->close.conn_id);
455460
break;
456461
default:
@@ -684,7 +689,7 @@ static mp_obj_t bt_init_helper(bt_obj_t *self, const mp_arg_val_t *args) {
684689
esp_ble_gattc_app_register(MOD_BT_CLIENT_APP_ID);
685690
esp_ble_gatts_app_register(MOD_BT_SERVER_APP_ID);
686691

687-
esp_ble_gatt_set_local_mtu(200);
692+
esp_ble_gatt_set_local_mtu(BT_MTU_SIZE_MAX);
688693

689694
self->init = true;
690695
}
@@ -989,7 +994,6 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
989994
{ MP_QSTR_service_uuid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
990995
};
991996

992-
esp_ble_adv_data_t adv_data;
993997
mp_buffer_info_t manuf_bufinfo;
994998
mp_buffer_info_t srv_bufinfo;
995999
mp_buffer_info_t uuid_bufinfo;
@@ -1056,7 +1060,21 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
10561060
adv_data.appearance = 0x00;
10571061
adv_data.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT);
10581062

1063+
// copy all the info to the scan response
1064+
memcpy(&scan_rsp_data, &adv_data, sizeof(esp_ble_adv_data_t));
1065+
scan_rsp_data.set_scan_rsp = true;
1066+
// do not include the name or the tx power in the scan response
1067+
scan_rsp_data.include_name = false;
1068+
scan_rsp_data.include_txpower = false;
1069+
// do not include the service uuid or service data in the advertisement, only in the scan response
1070+
adv_data.manufacturer_len = 0;
1071+
adv_data.p_manufacturer_data = NULL;
1072+
adv_data.service_data_len = 0;
1073+
adv_data.p_service_data = NULL;
1074+
adv_data.service_uuid_len = 0;
1075+
adv_data.p_service_uuid = NULL;
10591076
esp_ble_gap_config_adv_data(&adv_data);
1077+
esp_ble_gap_config_adv_data(&scan_rsp_data);
10601078

10611079
// wait for the advertisement data to be configured
10621080
bt_gatts_event_result_t gatts_event;
@@ -1068,6 +1086,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bt_set_advertisement_obj, 1, bt_set_advertisem
10681086

10691087
STATIC mp_obj_t bt_advertise(mp_obj_t self_in, mp_obj_t enable) {
10701088
if (mp_obj_is_true(enable)) {
1089+
// some sensible time to wait for the advertisement configuration to complete
1090+
mp_hal_delay_ms(50);
10711091
esp_ble_gap_start_advertising(&bt_adv_params);
10721092
bt_obj.advertising = true;
10731093
} else {

esp32/mods/modlora.c

+8
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,10 @@ static void TASK_LoRa (void *pvParameters) {
967967
#if defined(FIPY) || defined(LOPY4)
968968
xSemaphoreTake(xLoRaSigfoxSem, portMAX_DELAY);
969969
#endif
970+
mibReq.Type = MIB_NETWORK_ACTIVATION;
971+
mibReq.Param.NetworkActivation = ACTIVATION_TYPE_OTAA;
972+
LoRaMacMibSetRequestConfirm( &mibReq );
973+
970974
TimerStart( &TxNextActReqTimer );
971975
mlmeReq.Type = MLME_JOIN;
972976
mlmeReq.Req.Join.DevEui = (uint8_t *)lora_obj.u.otaa.DevEui;
@@ -976,6 +980,10 @@ static void TASK_LoRa (void *pvParameters) {
976980
mlmeReq.Req.Join.DR = (uint8_t) lora_obj.otaa_dr;
977981
LoRaMacMlmeRequest( &mlmeReq );
978982
} else {
983+
mibReq.Type = MIB_NETWORK_ACTIVATION;
984+
mibReq.Param.NetworkActivation = ACTIVATION_TYPE_ABP;
985+
LoRaMacMibSetRequestConfirm( &mibReq );
986+
979987
mibReq.Type = MIB_NET_ID;
980988
mibReq.Param.NetID = lora_obj.net_id;
981989
LoRaMacMibSetRequestConfirm( &mibReq );

esp32/mods/modlora.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define LORA_DATA_QUEUE_SIZE_MAX (3)
2222
#define LORA_CB_QUEUE_SIZE_MAX (7)
2323
#define LORA_STACK_SIZE (2560)
24-
#define LORA_TIMER_STACK_SIZE (2048)
24+
#define LORA_TIMER_STACK_SIZE (3072)
2525
#define LORA_TASK_PRIORITY (6)
2626
#define LORA_TIMER_TASK_PRIORITY (8)
2727

esp32/pycom_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.18.2.r4"
13+
#define SW_VERSION_NUMBER "1.18.2.r5"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

lib/lora/mac/LoRaMac.c

+27
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ static MulticastParams_t *MulticastChannels = NULL;
120120
*/
121121
static DeviceClass_t LoRaMacDeviceClass;
122122

123+
/*
124+
* End-Device network activation
125+
*/
126+
static ActivationType_t NetworkActivation;
127+
123128
/*!
124129
* Indicates if the node is connected to a private or public network
125130
*/
@@ -1458,6 +1463,10 @@ static void OnRxWindow2TimerEvent( void )
14581463
else
14591464
{
14601465
RxWindow2Config.RxContinuous = true;
1466+
1467+
if (NetworkActivation == ACTIVATION_TYPE_ABP){
1468+
RxWindow2Config.Datarate = McpsIndication.RxDatarate;
1469+
}
14611470
}
14621471

14631472
if( RegionRxConfig( LoRaMacRegion, &RxWindow2Config, ( int8_t* )&McpsIndication.RxDatarate ) == true )
@@ -2301,6 +2310,7 @@ LoRaMacStatus_t LoRaMacInitialization( LoRaMacPrimitives_t *primitives, LoRaMacC
23012310

23022311
LoRaMacDeviceClass = CLASS_A;
23032312
LoRaMacState = LORAMAC_IDLE;
2313+
NetworkActivation = ACTIVATION_TYPE_NONE;
23042314

23052315
JoinRequestTrials = 0;
23062316
MaxJoinRequestTrials = 1;
@@ -2501,6 +2511,11 @@ LoRaMacStatus_t LoRaMacMibGetRequestConfirm( MibRequestConfirm_t *mibGet )
25012511
mibGet->Param.Class = LoRaMacDeviceClass;
25022512
break;
25032513
}
2514+
case MIB_NETWORK_ACTIVATION:
2515+
{
2516+
mibGet->Param.NetworkActivation = NetworkActivation;
2517+
break;
2518+
}
25042519
case MIB_NETWORK_JOINED:
25052520
{
25062521
mibGet->Param.IsNetworkJoined = IsLoRaMacNetworkJoined;
@@ -2705,6 +2720,18 @@ LoRaMacStatus_t LoRaMacMibSetRequestConfirm( MibRequestConfirm_t *mibSet )
27052720
}
27062721
break;
27072722
}
2723+
case MIB_NETWORK_ACTIVATION:
2724+
{
2725+
if( mibSet->Param.NetworkActivation != ACTIVATION_TYPE_OTAA )
2726+
{
2727+
NetworkActivation = mibSet->Param.NetworkActivation;
2728+
}
2729+
else
2730+
{
2731+
status = LORAMAC_STATUS_PARAMETER_INVALID;
2732+
}
2733+
break;
2734+
}
27082735
case MIB_NETWORK_JOINED:
27092736
{
27102737
IsLoRaMacNetworkJoined = mibSet->Param.IsNetworkJoined;

lib/lora/mac/LoRaMac.h

+32
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ typedef enum eDeviceClass
142142
CLASS_C,
143143
}DeviceClass_t;
144144

145+
/*!
146+
* End-Device activation type
147+
*/
148+
typedef enum eActivationType
149+
{
150+
/*!
151+
* None
152+
*/
153+
ACTIVATION_TYPE_NONE = 0,
154+
/*!
155+
* Activation By Personalization (ACTIVATION_TYPE_ABP)
156+
*/
157+
ACTIVATION_TYPE_ABP = 1,
158+
/*!
159+
* Over-The-Air Activation (ACTIVATION_TYPE_OTAA)
160+
*/
161+
ACTIVATION_TYPE_OTAA = 2,
162+
}ActivationType_t;
163+
145164
/*!
146165
* LoRaMAC channels parameters definition
147166
*/
@@ -1111,6 +1130,7 @@ typedef struct sMlmeConfirm
11111130
* Attribute | Get | Set
11121131
* --------------------------------- | :-: | :-:
11131132
* \ref MIB_DEVICE_CLASS | YES | YES
1133+
* \ref MIB_NETWORK_ACTIVATION | YES | YES
11141134
* \ref MIB_NETWORK_JOINED | YES | YES
11151135
* \ref MIB_ADR | YES | YES
11161136
* \ref MIB_NET_ID | YES | YES
@@ -1156,6 +1176,12 @@ typedef enum eMib
11561176
* LoRaWAN Specification V1.0.2
11571177
*/
11581178
MIB_DEVICE_CLASS,
1179+
/*!
1180+
* LoRaWAN Network End-Device Activation
1181+
*
1182+
* LoRaWAN Specification V1.0.2
1183+
*/
1184+
MIB_NETWORK_ACTIVATION,
11591185
/*!
11601186
* LoRaWAN Network joined attribute
11611187
*
@@ -1359,6 +1385,12 @@ typedef union uMibParam
13591385
* Related MIB type: \ref MIB_DEVICE_CLASS
13601386
*/
13611387
DeviceClass_t Class;
1388+
/*!
1389+
* LoRaWAN Network End-Device Activation ( ACTIVATION_TYPE_NONE, ACTIVATION_TYPE_ABP or OTTA )
1390+
*
1391+
* Related MIB type: \ref MIB_NETWORK_ACTIVATION
1392+
*/
1393+
ActivationType_t NetworkActivation;
13621394
/*!
13631395
* LoRaWAN network joined attribute
13641396
*

0 commit comments

Comments
 (0)