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

Commit 93ead40

Browse files
committed
Add support for pybytes LTE configuration via config block/firmware updater
1 parent 53a5cd9 commit 93ead40

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

esp32/frozen/Pybytes/_pybytes_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ def __read_cb_config(self):
174174
'network_preferences' : pycom.pybytes_network_preferences().split(),
175175
'wifi_ssid' : pycom.wifi_ssid_sta() if hasattr(pycom, 'wifi_ssid_sta') else pycom.wifi_ssid(),
176176
'wifi_pwd': pycom.wifi_pwd_sta() if hasattr(pycom, 'wifi_pwd_sta') else pycom.wifi_pwd(),
177-
'extra_preferences' : pycom.pybytes_extra_preferences()
177+
'extra_preferences' : pycom.pybytes_extra_preferences(),
178+
'carrier' : pycom.pybytes_lte_config()[0],
179+
'apn' : pycom.pybytes_lte_config()[1],
180+
'cid' : pycom.pybytes_lte_config()[2],
181+
'band' : pycom.pybytes_lte_config()[3],
182+
'protocol' : pycom.pybytes_lte_config()[4],
183+
'reset' : pycom.pybytes_lte_config()[5]
178184
}
179185
except:
180186
pass

esp32/mods/modpycom.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,86 @@ STATIC mp_obj_t mod_pycom_lte_modem_on_boot (mp_uint_t n_args, const mp_obj_t *a
555555
}
556556
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_pycom_lte_modem_on_boot_obj, 0, 1, mod_pycom_lte_modem_on_boot);
557557

558+
STATIC mp_obj_t mod_pycom_pybytes_lte_config (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
559+
enum { ARG_carrier, ARG_apn, ARG_cid, ARG_band, ARG_type, ARG_reset };
560+
STATIC const mp_arg_t allowed_args[] = {
561+
{ MP_QSTR_carrier, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
562+
{ MP_QSTR_apn, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
563+
{ MP_QSTR_cid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
564+
{ MP_QSTR_band, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
565+
{ MP_QSTR_type, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
566+
{ MP_QSTR_reset, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
567+
568+
};
569+
570+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
571+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
572+
573+
pycom_pybytes_lte_config_t pycom_pybytes_lte_config = config_get_pybytes_lte_config();
574+
575+
if (n_args == 0) {
576+
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(6, NULL));
577+
578+
if(pycom_pybytes_lte_config.carrier[0] == 0xFF && pycom_pybytes_lte_config.carrier[1] == 0xFF && pycom_pybytes_lte_config.carrier[2] == 0xFF)
579+
{
580+
t->items[ARG_carrier] = mp_const_none;
581+
}
582+
else
583+
{
584+
t->items[ARG_carrier] = mp_obj_new_str((const char *)pycom_pybytes_lte_config.carrier, strlen((const char *)pycom_pybytes_lte_config.carrier));
585+
}
586+
587+
if(pycom_pybytes_lte_config.apn[0] == 0xFF && pycom_pybytes_lte_config.apn[1] == 0xFF && pycom_pybytes_lte_config.apn[2] == 0xFF)
588+
{
589+
t->items[ARG_apn] = mp_const_none;
590+
}
591+
else
592+
{
593+
t->items[ARG_apn] = mp_obj_new_str((const char *)pycom_pybytes_lte_config.apn, strlen((const char *)pycom_pybytes_lte_config.apn));
594+
}
595+
if(pycom_pybytes_lte_config.cid == 0xFF)
596+
{
597+
t->items[ARG_cid] = mp_obj_new_int(1);
598+
}
599+
else
600+
{
601+
t->items[ARG_cid] = mp_obj_new_int(pycom_pybytes_lte_config.cid);
602+
}
603+
if(pycom_pybytes_lte_config.band == 0xFF)
604+
{
605+
t->items[ARG_band] = mp_const_none;
606+
}
607+
else
608+
{
609+
t->items[ARG_band] = mp_obj_new_int(pycom_pybytes_lte_config.band);
610+
}
611+
if(pycom_pybytes_lte_config.type[0] == 0xFF)
612+
{
613+
t->items[ARG_type] = mp_const_none;
614+
}
615+
else
616+
{
617+
t->items[ARG_type] = mp_obj_new_str((const char *)pycom_pybytes_lte_config.type, strlen((const char *)pycom_pybytes_lte_config.type));
618+
}
619+
if(pycom_pybytes_lte_config.reset == 0xff)
620+
{
621+
t->items[ARG_reset] = mp_const_false;
622+
}
623+
else
624+
{
625+
t->items[ARG_reset] = mp_obj_new_bool(pycom_pybytes_lte_config.reset);
626+
}
627+
return MP_OBJ_FROM_PTR(t);
628+
629+
} else {
630+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Error this functionality is not yet supported!"));
631+
}
632+
633+
return mp_const_none;
634+
}
635+
636+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_pycom_pybytes_lte_config_obj, 0, mod_pycom_pybytes_lte_config);
637+
558638
STATIC mp_obj_t mod_pycom_bootmgr (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
559639
enum { ARG_boot_partition, ARG_fs_type, ARG_safeboot, ARG_status };
560640
STATIC const mp_arg_t allowed_args[] = {
@@ -731,6 +811,7 @@ STATIC const mp_map_elem_t pycom_module_globals_table[] = {
731811
{ MP_OBJ_NEW_QSTR(MP_QSTR_pybytes_extra_preferences), (mp_obj_t)&mod_pycom_pybytes_extra_preferences_obj },
732812
{ MP_OBJ_NEW_QSTR(MP_QSTR_pybytes_force_update), (mp_obj_t)&mod_pycom_pybytes_force_update_obj },
733813
{ MP_OBJ_NEW_QSTR(MP_QSTR_smart_config_on_boot), (mp_obj_t)&mod_pycom_smartConfig_obj },
814+
{ MP_OBJ_NEW_QSTR(MP_QSTR_pybytes_lte_config), (mp_obj_t)&mod_pycom_pybytes_lte_config_obj },
734815
#endif //(VARIANT == PYBYTES)
735816
{ MP_OBJ_NEW_QSTR(MP_QSTR_bootmgr), (mp_obj_t)&mod_pycom_bootmgr_obj },
736817

esp32/pycom_config.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,15 @@ uint8_t config_get_boot_fs_type (void) {
384384
return pycom_config_block.pycom_config.boot_fs_type;
385385
}
386386

387+
pycom_pybytes_lte_config_t config_get_pybytes_lte_config (void) {
388+
return pycom_config_block.pycom_pybytes_lte_config;
389+
}
390+
391+
bool config_set_pybytes_lte_config(const pycom_pybytes_lte_config_t pycom_pybytes_lte_config) {
392+
pycom_config_block.pycom_pybytes_lte_config=pycom_pybytes_lte_config;
393+
return config_write();
394+
}
395+
387396
bool config_set_boot_fs_type (const uint8_t boot_fs_type) {
388397
pycom_config_block.pycom_config.boot_fs_type=boot_fs_type;
389398
return config_write();

esp32/pycom_config.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ typedef struct {
8181
uint8_t lte_modem_en_on_boot;
8282
} pycom_lte_config_t;
8383

84+
typedef struct {
85+
uint8_t carrier[129];
86+
uint8_t apn[129];
87+
uint8_t type[17];
88+
uint8_t cid;
89+
uint8_t band;
90+
uint8_t reset;
91+
} pycom_pybytes_lte_config_t;
92+
8493
typedef struct {
8594
pycom_lpwan_config_t lpwan_config;
8695
pycom_wifi_config_t wifi_config;
@@ -91,7 +100,8 @@ typedef struct {
91100
pycom_lte_config_t lte_config;
92101
pycom_config_t pycom_config;
93102
pycom_wifi_ap_config_t wifi_ap_config;
94-
uint8_t pycom_reserved[390];
103+
pycom_pybytes_lte_config_t pycom_pybytes_lte_config;
104+
uint8_t pycom_reserved[112];
95105
} pycom_config_block_t;
96106

97107
typedef enum
@@ -197,6 +207,10 @@ uint8_t config_get_boot_fs_type (void);
197207

198208
bool config_set_boot_fs_type (const uint8_t boot_fs_type);
199209

210+
pycom_pybytes_lte_config_t config_get_pybytes_lte_config (void);
211+
212+
bool config_set_pybytes_lte_config(const pycom_pybytes_lte_config_t pycom_pybytes_lte_config);
213+
200214
uint8_t config_get_boot_partition (void);
201215

202216
bool config_set_boot_partition (const uint8_t boot_partition);

0 commit comments

Comments
 (0)