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
#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);
}