Go Down

Topic: wifi.rssi is not affected by esp_wifi_set_max_tx_power() (Read 440 times) previous topic - next topic

belisar

Hello,

In my current project I use two Esp32. I would like to measure the signal attenuation between them. Default is the transmission power 1mW (0dBm). If I increase the transmission power using esp_wifi_set_max_tx_power(78), which corresponds to 20 dBm, this does not affect the measurement of the WiFi.RSSI() method, regardless where I set the transmission power to 20dBm. Maybe, one of you probably knows what to do and could help :)


Code: [Select]

#include "painlessMesh.h"
#include <esp_wifi.h>
#define   MESH_PREFIX     "CvOSAO"
#define   MESH_PASSWORD   "1234"
#define   MESH_PORT       5555
 
Scheduler userScheduler; // to control your personal task
 
painlessMesh  mesh;
 
// User stub
void sendMessage() ; // Prototype so PlatformIO doesn't complain
 
Task taskSendMessage( TASK_MILLISECOND * 4000 , TASK_FOREVER, &sendMessage );
 
void sendMessage() {
  String msg = "RSSI:  ";
  wifi_ap_record_t wifidata;
   esp_wifi_set_max_tx_power(72);
  if(esp_wifi_sta_get_ap_info(&wifidata) == 0){
    Serial.println(wifidata.rssi);
  }
  int dBm = WiFi.RSSI();
 
  msg.concat(dBm);
  //mesh.sendBroadcast( msg );
 
  String rssiMessage = "{\"EventType\" : \"";
            rssiMessage.concat("RSSI_EVENT");
            rssiMessage.concat("\", \"nodeId\" :\"");
            rssiMessage.concat(mesh.getNodeId());
            rssiMessage.concat("\", object : { \"dBm\" : \"");
            rssiMessage.concat(dBm);
            rssiMessage.concat("\"}}");
   while(rssiMessage.length() <= 1500){
         
         rssiMessage.concat(" ");
       
     }       
            Serial.println(rssiMessage);
}
 
// Needed for painless library
void receivedCallback( uint32_t from, String &msg ) {
  Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
}
 
void newConnectionCallback(uint32_t nodeId) {
    Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
 
void changedConnectionCallback() {
  Serial.printf("Changed connections\n");
}
 
void nodeTimeAdjustedCallback(int32_t offset) {
    Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
 
void setup() {
  Serial.begin(115200);
esp_wifi_set_max_tx_power(72);
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
  mesh.setDebugMsgTypes( ERROR | STARTUP );  // set before init() so that you can see startup messages
 
  mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
  mesh.setRoot(true);
  mesh.setContainsRoot(true);
  mesh.onReceive(&receivedCallback);
  mesh.onNewConnection(&newConnectionCallback);
  mesh.onChangedConnections(&changedConnectionCallback);
  mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
 
  //userScheduler.addTask( taskSendMessage );
  //taskSendMessage.enable();
}
 
void loop() {
  // it will run the user scheduler as well
 esp_wifi_set_max_tx_power(72);
  mesh.update();
  esp_wifi_set_max_tx_power(72);
}
#include "painlessMesh.h"
#include <esp_wifi.h>
#define   MESH_PREFIX     "CvOSAO"
#define   MESH_PASSWORD   "1234"
#define   MESH_PORT       5555
 
Scheduler userScheduler; // to control your personal task
 
painlessMesh  mesh;
 
// User stub
void sendMessage() ; // Prototype so PlatformIO doesn't complain
 
Task taskSendMessage( TASK_MILLISECOND * 4000 , TASK_FOREVER, &sendMessage );
 
void sendMessage() {
  String msg = "RSSI:  ";
  wifi_ap_record_t wifidata;
   esp_wifi_set_max_tx_power(72);
  if(esp_wifi_sta_get_ap_info(&wifidata) == 0){
    Serial.println(wifidata.rssi);
  }
  int dBm = WiFi.RSSI();
 
  msg.concat(dBm);
  //mesh.sendBroadcast( msg );
 
  String rssiMessage = "{\"EventType\" : \"";
            rssiMessage.concat("RSSI_EVENT");
            rssiMessage.concat("\", \"nodeId\" :\"");
            rssiMessage.concat(mesh.getNodeId());
            rssiMessage.concat("\", object : { \"dBm\" : \"");
            rssiMessage.concat(dBm);
            rssiMessage.concat("\"}}");
   while(rssiMessage.length() <= 1500){
         
         rssiMessage.concat(" ");
       
     }       
            Serial.println(rssiMessage);
}
 
// Needed for painless library
void receivedCallback( uint32_t from, String &msg ) {
  Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
}
 
void newConnectionCallback(uint32_t nodeId) {
    Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
 
void changedConnectionCallback() {
  Serial.printf("Changed connections\n");
}
 
void nodeTimeAdjustedCallback(int32_t offset) {
    Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
 
void setup() {
  Serial.begin(115200);
esp_wifi_set_max_tx_power(72);
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
  mesh.setDebugMsgTypes( ERROR | STARTUP );  // set before init() so that you can see startup messages
 
  mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
  mesh.setRoot(true);
  mesh.setContainsRoot(true);
  mesh.onReceive(&receivedCallback);
  mesh.onNewConnection(&newConnectionCallback);
  mesh.onChangedConnections(&changedConnectionCallback);
  mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
 
  //userScheduler.addTask( taskSendMessage );
  //taskSendMessage.enable();
}
 
void loop() {
  // it will run the user scheduler as well
 esp_wifi_set_max_tx_power(72);
  mesh.update();
  esp_wifi_set_max_tx_power(72);
}

Idahowalker

#1
Jul 13, 2020, 01:54 pm Last Edit: Jul 13, 2020, 01:55 pm by Idahowalker
I found the best way to increase the WiFi signal on an individual ESP32 is to use the ESP32's that can take an external antenna.

By using another task scheduler on top of the ESP32's built in OS, freeRTOS, an excellent task scheduler you are duplicating process and slowing up processing.

Already built into a ESP32 is freeRTOS https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html and https://www.freertos.org/a00106.html.

PaulRB

Maybe the clue is in the name "esp_wifi_set_max_tx_power"? You are not specifying the actual tx power, only the maximum allowed. If that max is not needed, a lower power will be used.

Maybe try your tests at longer range, or through several walls, to see if it makes a difference then.

LMI1

RSSI refers to deceiver signal level. Are you measuring RSSi at the other ESP32?

PaulRB


LMI1


DrAzzy

Why would you expect changing the power it transmits at would increase the strength of the signal it receives?
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Juraj

Why would you expect changing the power it transmits at would increase the strength of the signal it receives?
as I understand it, the sketch runs in two esp32

PaulRB

That's what I understood or assumed. The OP is setting the max transmit power on the first esp32 and measuring the RSSI on the second esp32.

But the OP has not responded for many days, so may have lost interest in the matter.

Go Up