ESP32 Range extender / Antenna modification

Place your projects here
Post Reply
User avatar
PeterN
Posts: 642
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 297 times
Been thanked: 360 times
Contact:

ESP32 Range extender / Antenna modification

Post by PeterN »

When experimenting with ESP32 modules, especially the ESP32 CAMs, I wish I had a little more WIFI range reserve.
This could be achieved by adding an external antenna - but not all modules are prepared for the connection of an external antenna.
To keep it simple but effective, I added a half-wave antenna wire to the original onboard antenna of the ESP32 module.
0480BE99-94B4-408F-A7A5-3298D46F595C.jpeg

The original print antenna is a meander-shaped, inverted F antenna with 1/4 wavelength. It is a compromise between size, omnidirectional antenna pattern if possible, and power efficiency. I found a very helpful source of information about such kind of antennas at https://www.nxp.com/docs/en/application-note/AN2731.pdf

My thought now was to increase the WIFI range of the module by a strong coupling between the on-board antenna and a newly added external half-wave antenna wire (AWG24 switch wire 0.5mm with 62mm length).

EDIT: The experimentally determined optimum length for the entire half-wave antenna wire was finally 58mm. This is 4mm less than the old value and resulted in an additional signal boost of 1.5dB!


However, no irreversible changes or soldering should become necessary. So I hot glued the additional antenna wire directly on the board . Note that half of the isolated antenna wire is exactly following the meandering shape of the printed F-antenna, while the other half is mounted "free". This results in a good inductive and capacitive coupling.
I did some experiments where the free end of the antenna wire ran straight or was run up at a 90 degree angle. This changed the resulting antenna pattern, which could surely be investigated much more to optimize the result in a given mounting environment

My hopeful design was now to prove!
To show the effect of my design, I mounted a modified module next to an unmodified one so that both modules should have nearly the same receiving conditions.
4F5DE265-712E-44A3-9C22-9F7AD5685E21.jpeg

I have written ANNEX32 code that plots the WIFI field strength measured by both modules simultaneously on a single graph.
Module 1 (with additional antenna) logs its own WIFI RSSI and additionally requests a string with the logged RSSI from the second (unmodified) module.



I tested the effect of the additional antenna and recorded the WIFI strength under different conditions. Here I can show only an abstract of my experiments and results.
38EC685E-3EF7-41F7-975E-C005305A2E27.jpeg
0A81B065-AC62-45A3-8C5C-528CB197483E.jpeg


It turns out that the signal is improved by at least 3 dB overall on the modified modules with a elongated non-angled antenna wire. Under very reflective conditions, I had an improvement of almost 10 dB.
One of the reasons for the better gain is certainly the modified antenna pattern; another might be the strong coupling to a larger and somewhat more effective antenna.
Under given unfavorable conditions, this simple external antenna cannot work wonders, but it can increase the range of the ESP module or improve a less stable WIFI connection.

I modified an ESP32 CAM as described here and now have a much better signal and a very stable video connection in a place that was previously quite critical.
0CDB048A-D078-4856-BB65-91C738C8747D.jpeg

Code: [Local Link Removed for Guests]


'######## WIFI-GRAPH-LOGGER ####################################
'  Allows to compair the two ESP-Modules which have different antennas
'
' Displays  a graphical logging of two WIFI-signals in dB 
' -  the OWN WIFI-connection to the WIFI access point
' -  the WIFI-connection of a remote ESP32  to the same AP
'

' TX = 1  => this ESP-Module  returns the string with its 
'            WIFI-LOG-RESULT-STRING  on request at http://MY_IP/msg?x=1
TX         = 1   

' RX = 1 => This ESP-Module regularly requests the WIFI-LOG-RESULT-STRING 
'            from remote module with http://REMOTE_IP/msg?x=1
RX         = 0

REMOTE_IP$ = "192.168.0.141"

X_Num      = 100 'Number of WIFI-MESSURES to display  in the graph
WIFI_REMOTE$  = ""

onhtmlreload  WEBPAGE
gosub         WEBPAGE

if TX = 1 onurlmessage RETURN_WIFI_STRING
IF RX = 1 onwgetasync RECEIVE_REMOTE_STRING

timer0 500, LOG_MY_WIFI_CONNECTION

if RX = 1 timer1 1000, GET_REMOTE_WIFI_LOG_STRING
wait

'###############################################################

LOG_MY_WIFI_CONNECTION:
  w=0
  for i  = 1 to 50
  w = wifi.rssi + w
  next i
  w=W/(i-1)   ' Thanks for the hint Fernando !
  WIFI_LOCAL$= trim$(WIFI_LOCAL$ + " " +str$(wifi.rssi,"%2.1f")) 
  c = word.count(WIFI_LOCAL$," ")
  p = instr(1, WIFI_LOCAL$, " ")
  P = len(WIFI_LOCAL$) - p
  If c  > X_NUM then WIFI_LOCAL$ = right$(WIFI_LOCAL$, p )
  'wlog WIFI_LOCAL$ , c
  jscall |traceme(0,"| + WIFI_LOCAL$ + |");|
 if WIFI_REMOTE$ <> "" jscall |traceme(1,"| + WIFI_REMOTE$ + |");|
return


'###############################################################
RETURN_WIFI_STRING:
URLMSGRETURN WIFI_LOCAL$
return


'###############################################################
GET_REMOTE_WIFI_LOG_STRING:
wgetasync ("http://" + REMOTE_IP$+ "/msg?x=1")
return

'###############################################################
RECEIVE_REMOTE_STRING:
WIFI_REMOTE$ = WGETRESULT$
return


'###############################################################
WEBPAGE:
cls
' loads the library
jsexternal "/xy.min.js"
cnt = 0

a$ = ""
a$ = a$ + |<p>WIFI Graph for two ESP32-modules .. <br> |
a$ = a$ + |GREEN = WITH additional antenna <br> RED === with original antenna |
a$ = a$ + |</p><canvas id="canvas1" width="800" height="400"></canvas>|
html a$
pause 500

' define che datasets 
A$ = ""
A$ = A$ + |var datasets = [|
A$ = A$ + |  {|
A$ = A$ + |    lineColor : 'rgba(20,100,100,1)',|
A$ = A$ + |    pointColor : 'rgba(20,20,20,1)',|
A$ = A$ + |    pointStrokeColor : '#fff',|
A$ = A$ + |    data : []|
A$ = A$ + |  },|
A$ = A$ + |  {|
A$ = A$ + |    lineColor : 'rgba(151,30,0,1)',|
A$ = A$ + |    pointColor : 'rgba(151,80,0,1)',|
A$ = A$ + |    pointStrokeColor : '#fff',|
A$ = A$ + |    data : []|
A$ = A$ + |  }|
A$ = A$ + |];|

A$ = A$ + |var ctx2 = document.getElementById('canvas1').getContext('2d');|
A$ = A$ + ||
A$ = A$ + |var xy = new Xy(ctx2, {rangeX:[0,| + STR$(X_NUM)+ |], rangeY:[-80,-45], smooth:0.05, pointCircleRadius:2, pointStrokeWidth:1 });|
A$ = A$ + ||

A$ = A$ + |function traceme(set, data){|
A$ = A$ + |  var s = data.split(" ");|
A$ = A$ + |  for (var i=0; i<s.length; i++) {|
A$ = A$ + |    datasets[set].data[i] = [i, s[i]];|
A$ = A$ + |  }|
A$ = A$ + |  xy.draw(datasets);|
A$ = A$ + |}|

jscript a$
A$ = "" ' clean memory

return
You do not have the required permissions to view the files attached to this post.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 269 times

Re: ESP32 Range extender / Antenna modification

Post by Fernando Perez »

Peter, I don't think it matters much but at the end of your for next loop (line 41), w equals 51, not 50.
I understand that at no time do you solder the cable, you just glue it to the surface of the module.
In theory, it will work the same for ESP8266 modules, right?
Brilliant. I'm going to check that.
User avatar
PeterN
Posts: 642
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 297 times
Been thanked: 360 times
Contact:

Re: ESP32 Range extender / Antenna modification

Post by PeterN »

You are right about both statements, Fernando.

For .. next - variable after loop ... I am ashamed of this almost classic error. :oops:


And the Antenna of the ESP8266 is indeed the same kind of F-Antenna
User avatar
PeterN
Posts: 642
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 297 times
Been thanked: 360 times
Contact:

Re: ESP32 Range extender / Antenna modification

Post by PeterN »

I elaborated the matter a bit more and placed it at ...

- https://peterneufeld.wordpress.com/2021 ... ification/
- https://www.elektormagazine.com/labs/es ... dification

And of cause I did not forget to mention the world-famous ANNEX there!!!
User avatar
PeterN
Posts: 642
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 297 times
Been thanked: 360 times
Contact:

Re: ESP32 Range extender / Antenna modification

Post by PeterN »

This is the latest code … optimized for readability and for an article in the next September 2024 edition of ELEKTOR-Magazine about this project empathizing the advantages of Annex32

Code: [Local Link Removed for Guests]




'######## WIFI-GRAPH-LOGGER ####################################
'  Allows to compare the two ESP-Modules which have different antennas
'  (peter.neufeld@gmx.de 06/2024)
' Displays  a graphical logging of two WIFI-signals in dB on module_1 
' -  the OWN WIFI-connection to the WIFI access point
' -  the WIFI-connection of a remote ESP32 module_2  to the same AP
'
' RX = 1 => This ESP-Module regularly requests the WIFI-LOG-RESULT-STRING 
'            from a remote module with http://REMOTE_IP/msg?x=1
' TX = 1  => this ESP-Module  returns the string with its 
'            WIFI-LOG-RESULT-STRING  on request at http://MY_IP/msg?x=1

' uncomment this on the ESP32 module_1 as the main module 
RX        = 1   'This module_1 sends requests 
TX        = 0   'This module_1 is quiet

' uncomment this on the ESP32 module_2 as the 2nd module 
'RX         = 0   'This module_2 does not send  requests 
'TX         = 1   'This module_2 responds to requests

REMOTE_IP$ = "192.168.0.141" 'Set here YOUR IP-Address of module_2

X_Num      = 100 'Number of WIFI-MESSURES to display  in the graph
WIFI_REMOTE$  = ""
onhtmlreload  WEBPAGE
gosub         WEBPAGE
IF TX = 1 onurlmessage RETURN_WIFI_STRING
IF RX = 1 onwgetasync RECEIVE_REMOTE_STRING
timer0 500, LOG_MY_WIFI_CONNECTION
IF RX = 1 timer1 1000, GET_REMOTE_WIFI_LOG_STRING
wait

'###############################################################
LOG_MY_WIFI_CONNECTION:
w=0
for i  = 1 to 50
w = wifi.rssi + w
next i
w=W/(i-1)   ' Thanks for the hint Fernando !
WIFI_LOCAL$= trim$(WIFI_LOCAL$ + " " +str$(wifi.rssi,"%2.1f")) 
c = word.count(WIFI_LOCAL$," ")
p = instr(1, WIFI_LOCAL$, " ")
p = len(WIFI_LOCAL$) - p
If c > X_NUM then WIFI_LOCAL$ = right$(WIFI_LOCAL$, p )
'wlog WIFI_LOCAL$ , c
jscall |traceme(0,"| + WIFI_LOCAL$ + |");|
if WIFI_REMOTE$ <> "" jscall |traceme(1,"| + WIFI_REMOTE$ + |");|
return

'###############################################################
RETURN_WIFI_STRING:
URLMSGRETURN WIFI_LOCAL$
return

'###############################################################
GET_REMOTE_WIFI_LOG_STRING:
wgetasync ("http://" + REMOTE_IP$+ "/msg?x=1")
return

'###############################################################
RECEIVE_REMOTE_STRING:
WIFI_REMOTE$ = WGETRESULT$
return

'###############################################################
WEBPAGE:
cls
jsexternal "/xy.min.js"
cnt = 0
a$ = ""
a$ = a$ + |<p>WIFI Graph for two ESP32-modules .. <br> |
a$ = a$ + |GREEN = WITH additional antenna <br> RED === with original antenna |
a$ = a$ + |</p><canvas id="canvas1" width="800" height="400"></canvas>|
html a$
pause 500 
A$ = ""
A$ = A$ + |var datasets = [|
A$ = A$ + |  {|
A$ = A$ + |    lineColor : 'rgba(20,100,100,1)',|
A$ = A$ + |    pointColor : 'rgba(20,20,20,1)',|
A$ = A$ + |    pointStrokeColor : '#fff',|
A$ = A$ + |    data : []|
A$ = A$ + |  },|
A$ = A$ + |  {|
A$ = A$ + |    lineColor : 'rgba(151,30,0,1)',|
A$ = A$ + |    pointColor : 'rgba(151,80,0,1)',|
A$ = A$ + |    pointStrokeColor : '#fff',|
A$ = A$ + |    data : []|
A$ = A$ + |  }|
A$ = A$ + |];|
A$ = A$ + |var ctx2 = document.getElementById('canvas1').getContext('2d');|
A$ = A$ + ||
A$ = A$ + |var xy = new Xy(ctx2, {rangeX:[0,|+ STR$(X_NUM)+ |], rangeY:[-80,-45]|
A$ = A$ + |, smooth:0.05, pointCircleRadius:2, pointStrokeWidth:1 });|
A$ = A$ + ||
A$ = A$ + |function traceme(set, data){|
A$ = A$ + |  var s = data.split(" ");|
A$ = A$ + |  for (var i=0; i<s.length; i++) {|
A$ = A$ + |    datasets[set].data[i] = [i, s[i]];|
A$ = A$ + |  }|
A$ = A$ + |  xy.draw(datasets);|
A$ = A$ + |}|
jscript A$
A$ = "" ' clean memory
return

BeanieBots
Posts: 522
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 292 times
Been thanked: 163 times

Re: ESP32 Range extender / Antenna modification

Post by BeanieBots »

Thanks for updating this because it has reminded me that I have several (almost) out of range sensors which I keep meaning to upgrade with your useful insight!
Also, great to see somebody pushing out the word about Annex. Well done.
User avatar
PeterN
Posts: 642
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 297 times
Been thanked: 360 times
Contact:

Re: ESP32 Range extender / Antenna modification

Post by PeterN »

Thanks BeanieBots,
hope that this can extend the range of your devices. But keep in mind that the aditional antenna wire increases the directivity. Thus it is important to turn the antenna with its broad side towards the WIFI-AP

For the promotion of Annex32:
Over the years I posted some of my Annex projects on ELEKTOR labs. https://www.elektormagazine.com/labs?s ... cy&q=ANNEX Some of those then got published in the Print&online magazine. Elektor’s various channels have a very large readership focused on electronic topics. Everyone can post at ELEKTOR LABs after creating a free account.
I know that some of the projects in this forum here would certainly find a large interested readership there too.

And it could be helpful and even more effective if it wasn't just me praising and proving the advantages of Annex32 there ;-)

So dear fellow followers of the fabulous Annex32 cult ... in the best case scenario, it might just be a matter of copy and paste. :-)
Post Reply