ESP32 Long Range Mode 1 km

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
jimmo
Posts: 1769
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 Long Range Mode 1 km

Post by jimmo » Sun Nov 03, 2019 11:52 pm

iotman wrote:
Sun Nov 03, 2019 5:07 pm
Hi, we are still waiting for the bluetooth BLE capability (Micropython version) to be available for the ESP32, so we really haven't started this project yet.
This will be in v1.12 which I think is probably getting pretty close to being released, but in the meantime you can use BLE in the nightly firmware builds at http://micropython.org/download#esp32 (You need the IDF 4.x builds for BLE).

Docs here http://docs.micropython.org/en/latest/l ... tooth.html

Samples here https://github.com/micropython/micropyt ... /bluetooth (peripheral role for now, but central role is also supported by the MicroPython API and I'm working on examples for that too).

User avatar
jimmo
Posts: 1769
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 Long Range Mode 1 km

Post by jimmo » Sun Nov 03, 2019 11:53 pm

uCTRL wrote:
Sun Nov 03, 2019 11:03 am
Is there any information available on the status of micropython using WiFi Long range mode with ESP32?
I'm not aware of anyone working on it, but as you've pointed out, it should be pretty simple to just expose these constants to Python and it should be pretty much "just work".

User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: ESP32 Long Range Mode 1 km

Post by iotman » Mon Nov 04, 2019 12:04 am

Hi @jimmo, thanks for the update on BLE; I was wondering about that. I think we'll wait for v1.12 and see how well that works, so is there a specific forum I can monitor to find out when it is released?

Cheers, AB

User avatar
jimmo
Posts: 1769
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 Long Range Mode 1 km

Post by jimmo » Mon Nov 04, 2019 1:36 am

iotman wrote:
Mon Nov 04, 2019 12:04 am
Hi @jimmo, thanks for the update on BLE; I was wondering about that. I think we'll wait for v1.12 and see how well that works, so is there a specific forum I can monitor to find out when it is released?
I think Damien's plan is to start using the newsletter for this http://micropython.org/newsletter/ and viewforum.php?f=19

But it will also be posted as a release on GitHub -- see past releases here https://github.com/micropython/micropython/releases

User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: ESP32 Long Range Mode 1 km

Post by iotman » Mon Nov 04, 2019 1:57 am

Hi @jimmo, thanks so much, love Micropython!

Cheers, AB

bitrat
Posts: 20
Joined: Fri Jul 26, 2019 4:13 am

Re: ESP32 Long Range Mode 1 km

Post by bitrat » Mon Nov 04, 2019 9:38 pm

Hi,

I've added this rough implementation of phy_mode() to modnetwork.c (with a view to enabling LR mode) and flashed it to a sparkfun thing, but I get ESP_ERR_INVALID_ARG. Calling phy_mode() with no args just returns the error values, (0, 12289, 12292, 258), so I can decode them.

Code: Select all

STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {

       if (n_args == 0) {
		 mp_obj_t tuple[4] = {
		    mp_obj_new_int(ESP_OK),
		    mp_obj_new_int(ESP_ERR_WIFI_NOT_INIT),
		    mp_obj_new_int(ESP_ERR_WIFI_IF),
		    mp_obj_new_int(ESP_ERR_INVALID_ARG),
		};
		return mp_obj_new_tuple(4, tuple);		 
	 }
      
	uint8_t protocol_bitmap = -1;
	esp_err_t esp_err  = ESP_OK;
	wifi_interface_t ifx = WIFI_IF_STA;
	switch(n_args)
	{
		case 1:
			ifx = mp_obj_get_int(args[0]);
		
		//case 0:
			esp_err = esp_wifi_get_protocol(ifx, &protocol_bitmap);
			if(esp_err ==ESP_OK)
			{
				 mp_obj_t tuple[2] = {
					    mp_const_true,
					    mp_obj_new_int(protocol_bitmap),
					};
					return mp_obj_new_tuple(2, tuple);					
			}
			break;
		
		case 2:
			ifx = mp_obj_get_int(args[0]);
			esp_err = esp_wifi_set_protocol(ifx, mp_obj_get_int(args[1]));
			break;
	}
	
	 mp_obj_t tuple[2] = {
		    mp_obj_new_bool(esp_err ==ESP_OK),
		    mp_obj_new_int(esp_err),
		};
		return mp_obj_new_tuple(2, tuple);		
    }

STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 2, esp_phy_mode);
I also added ..

Code: Select all

 STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
.
 { MP_ROM_QSTR(MP_QSTR_MODE_LR), MP_ROM_INT(WIFI_PROTOCOL_LR) },
 .
 

I call it like this..

Code: Select all

import network as nw
wlan = nw.WLAN(nw.STA_IF)
nw.phy_mode(nw.STA_IF, nw.MODE_LR)
If I leave out

Code: Select all

nw.WLAN(nw.STA_IF)
the error I get is ESP_ERR_WIFI_NOT_INIT, which suggests my call to esp_wifi_set_protocol() is executing actual code and not some stub.

Code: Select all

>>>
>>>
>>>
>>>
>>> import network as nw
>>> nw.phy_mode()
(0, 12289, 12292, 258)
>>>
>>> nw.phy_mode(nw.STA_IF, nw.MODE_LR)
(False, 12289)
>>>
>>>
>>> wlan = nw.WLAN(nw.STA_IF)
I (372060) wifi: wifi driver task: 3ffe2e9c, prio:23, stack:3584, core=0
I (386295) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (386305) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (386355) wifi: wifi firmware version: aeed694
I (386355) wifi: config NVS flash: enabled
I (386355) wifi: config nano formating: disabled
I (386355) wifi: Init dynamic tx buffer num: 32
I (386355) wifi: Init data frame dynamic rx buffer num: 32
I (386365) wifi: Init management frame dynamic rx buffer num: 32
I (386365) wifi: Init management short buffer num: 32
I (386375) wifi: Init static rx buffer size: 1600
I (386375) wifi: Init static rx buffer num: 10
I (386385) wifi: Init dynamic rx buffer num: 32
>>>
>>> nw.phy_mode(nw.STA_IF, nw.MODE_LR)
(False, 258)
>>>
>>>
>>> nw.phy_mode(nw.STA_IF)
(True, 7)
>>>
>>> nw.phy_mode(nw.STA_IF, 7)
(False, 258)
>>>
>>>
Note that phy_mode() returns the (presumably) correct mode value: 7 (ie, 11b|11g|11n == 1|2|4)

But also setting mode to this value also fails with ESP_ERR_INVALID_ARG.

This is compiled against idf v3.3

Can anyone suggest what else I need to do to set phy mode, or has anyone out there successfully used ESP32 LR mode?

I'll try using the C code from this example, but it doesn't appear to be doing anything more than I am already...

User avatar
jimmo
Posts: 1769
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 Long Range Mode 1 km

Post by jimmo » Tue Nov 05, 2019 1:22 am

bitrat wrote:
Mon Nov 04, 2019 9:38 pm
I'll try using the C code from this example, but it doesn't appear to be doing anything more than I am already...
The main difference to that code is that it's calling `esp_wifi_set_protocol` after `esp_wifi_set_mode`, whereas in your example, `esp_wifi_set_mode` won't be called unless `wlan.active(True)` is called.

I don't know if you can change the mode after calling `esp_wifi_start`. So you might need to call `phy_mode` before `active`, and save the value so that `active` can apply it.

bitrat
Posts: 20
Joined: Fri Jul 26, 2019 4:13 am

Re: ESP32 Long Range Mode 1 km

Post by bitrat » Tue Nov 05, 2019 5:18 am

Thanks! You're right!

I'm pretty sure I tried that earlier, but I had another error in my code, and lost the thread...

anyway...

Code: Select all

>>>
>>> import network as nw
>>> wlan = nw.WLAN(nw.STA_IF)
>>> wlan.active(True)
W (18387343) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (18387473) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 2
I (18387483) wifi: mode : sta (b4:e6:2d:d9:0f:ed)
True
I (18387483>)> >w ifi: STA_START

>>>
>>> nw.phy_mode(nw.STA_IF, nw.MODE_LR)
(True, I (18406273) network: event 3
0)
I (18406273) wifi: STA_START
>>>
>>>
>>> nw.phy_mode(nw.STA_IF)
(True, 8)
>>>
I have enough boards to do side by side testing (bgn vs lr) so, if everything's working, I'll likely post some range test results here.
I'll have to investigate the warning too.. W (18387343) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
Maybe after a tidy up I'll put in a pull request for changes to modnetwork.c
Are the ESP_ERR_* constants exposed in uP anywhere? What's the best strategy here for errors? Raise an exception?

Cheers!

Post Reply