MEGA + ESP01 + Blynk WiFi.RSSI() Issue

• Hardware model + communication type: Arduino MEGA2560 with ESP01
• Smartphone: iOS 13.5
• Blynk server
• Blynk Library: 0.6.1
• ESP01 is flashed to latest firmware AT v1.7.4.0 (May 11 2020)

HI Guys,

Strictly not a Blynk issue . . . yet . . . it will be when I get this solved as I intend to use this project as a WiFi/Blynk display to consolidate sensor info from a number of separate projects.

I have a number of MCUFriend TFT display shields, they work well on UNO/MEGA but need too many pins to work directly on ESP8266, so I’m using a MEGA2560 +ESP01 to connect to WiFi/Blynk, the MEGA has ample pins to accommodate the display. All good so far. I can connect to WiFi, connect to Blynk and display the uptime and other data on the display.

But . . . when I try to use any of these functions WiFi.localIP(), WiFi.SSID(), WiFi.macAddress() or WiFi.localIP() they freeze the code at the function. I have many other projects using these functions directly on ESP8266 and they are fine . . . but they compile on MEGA but don’t work.

Frustratingly I can see the MAC and IP details in the Serial Monitor during connection, but not read them in Arduino.

Any thoughts?

thnx
billd

// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <WiFi.h>
#include <SoftwareSerial.h>         // Software Serial on Uno, Nano...

SoftwareSerial EspSerial(50, 51);   // RX, TX
#define ESP8266_BAUD 9600           // Your ESP8266 baud rate:
ESP8266 wifi(&EspSerial);

char auth[] = "nnn";
char ssid[] = "GoTigers!_2GEXT_EX6100";
//char ssid[] = "GoTigers!_2GEXT";
char pass[] = "nnn";

int long testOTA = 393939;                                     // int to check that sketch has uploaded correctly
int status = WL_CONNECTED;
int count = 0;

BlynkTimer timer;                                         // define Blynk timer to determine when to do stuff
// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <SPI.h>              // f.k. for Arduino-1.5.2
#include <Adafruit_GFX.h>     // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#include <FreeDefaultFonts.h>

#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x8410
// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



void setup() {
  Serial.begin(9600);
// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  delay(10);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  
  Blynk.begin(auth, wifi, ssid, pass);

  Serial.println("");
  Serial.print("testOTA: ");
  Serial.println(testOTA);
  Serial.println("");
  Serial.println("void Setup() now complete . . .");
  Serial.println("");
// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  uint16_t ID = tft.readID();
  if (ID == 0xD3) ID = 0x9481;
  tft.begin(ID);
  tft.setRotation(0);  
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(2);
  tft.setCursor(10, 40);
  tft.print("WiFi Connected . .");
  tft.setCursor(10, 140);
  tft.print("IP: ");
  //tft.print(WiFi.localIP());
  tft.setCursor(10, 240);
  tft.print("SSID: ");
  //tft.print(WiFi.SSID());
  tft.setCursor(10, 340);
  tft.print("RSSI: ");
  //long rssi = WiFi.RSSI();
  //Serial.print("RSSI:");
  //Serial.println(rssi);
  //tft.print(rssi);
// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  
  timer.setInterval(1000, connectionUp);     // Do stuff when connected 
}


void loop() {
    Blynk.run();
    timer.run();
}


void connectionUp() {                        // Prints to Serial Monitor and TFT WiFi uptime every second
  if (status == WL_CONNECTED) {
    count++;
    Serial.print("WiFi Connected . . . ");
    Serial.println(count);
    Serial.println();
    
    tft.setTextSize(4);
    tft.setCursor(240, 25);
    tft.print(count);
  }
}

Hi Bill, the simple shield library acts as a wrapper that translates the WiFi commands into AT commands that the ESP-01 can use. Only some AT commands are passed through into useable methods in the library, so you have to hack the library to get more methods available.

This code will give you local IP and MAC…

And this will give you RSSI…

SSID is available with this RSSI hack, but as it’s needed as a variable to connect to your network anyway then it’s available in your code already…

Edited to add… I’m not condoning hacking the Blynk library in this way, and obviously you do so at your own risk and will need to take appropriate precautions when you do library updates in future :wink:

Pete.

HI Pete,

Thnx for the info, I suspected the Blynk library, guess I was hoping for a ‘magic bullet’ answer . . . I like that Blynk does a lot of the mundane WiFi connection stuff, very easy and convenient, but a little frustrating that there seem to have been arbitrary decisions on what is included and what is not . . .

I won’t be modifying the libraries . . . as pointed out this will need to be done after every update . . . my version control is not up to tracking that scenario :wink:

I’ll manually manage the WiFi connection, get the info I want then connect Blynk. A bit cumbersome but it will work.

thnx again

billd

HI @PeteKnight, after a few hours messing around with manual WiFi connection with the MEGA and ESP01 I came to realise how much tedium the Blynk libraries actually take care of! (I’ve become so used to working directly on ESP8266/32 where connectivity is simple, this step back in time has been an eye opener.)

I used your examples above, modified the BlynkSimpleShieldEsp8266.h, and will just need to remember when there is an update, although I can’t see to many more reasons for me to need it . . . famous last words :wink:

I don’t actually need this info for my project, I just took it as a personal affront when it wasn’t available . Now that I’ve wasted two days solving this non-problem I can get on with doing what I started out to do . . .

Thnx again

billd

1 Like

That sounds like the story of every project I ever start!

I think it ought to be possible to create a copy of BlynkSimpleShieldEsp8266.h and save it with another name, then include the new filename in your sketch. I’ve not tried it though.
The advantage of that would be that any updates wouldn’t overwrite your modified file, and if you try to compile the code on a different machine then t would tell you that the modified library was missing.

Anyway, glad its working, even though you don’t need it :smile:

Pete.

Final code for anyone interested, it’s a bit messy, but it works. Got there in the end.
IP, MAC & SSID at setup()
RSSI every 1 second in connectionUp()

cul
Billd

// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <WiFi.h>
#include <SoftwareSerial.h>         // Software Serial on Uno, Nano...

SoftwareSerial EspSerial(50, 51);   // RX, TX
#define ESP8266_BAUD 9600           // Your ESP8266 baud rate:
ESP8266 wifi(&EspSerial);

char auth[] = "nnn";
char ssid[] = "GoTigers!_2GEXT_EX6100";
//char ssid[] = "GoTigers!_2GEXT";
char pass[] = "nnn";

int long testOTA = 393939;                                     // int to check that sketch has uploaded correctly
int status = WL_CONNECTED;
int count = 0;

// @PeteKnight
String IP;                                                     // Global variable to hold the device IP address, assigned by DHCP
String MAC;                                                    // Global variable to hold the device MAC address


BlynkTimer timer;                                         // define Blynk timer to determine when to check sensors
// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <SPI.h>              // f.k. for Arduino-1.5.2
#include <Adafruit_GFX.h>     // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#include <FreeDefaultFonts.h>

#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x8410
// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



void setup() {
  Serial.begin(9600);
// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  delay(10);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  
  Blynk.begin(auth, wifi, ssid, pass);

  Serial.println("");
  Serial.print("testOTA: ");
  Serial.println(testOTA);
  Serial.println("");
  Serial.println("void Setup() now complete . . .");
  Serial.println("");
// MEGA + ESP01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// @PeteKnight +++++++++++++++++++++++++++++++++++++
  Parse_AT_Data();
  Serial.println(); 
  Serial.print("Local IP address = ");
  Serial.println(IP);
  Serial.print("MAC address = ");
  Serial.println(MAC);

  String ap_stats = wifi.getNowConecAp(); // rssi
  Serial.println(ap_stats);
  Serial.println(wifi_signal());    // https://community.blynk.cc/t/wemos-mega-wifi-r3-atmega2560-esp8266/44976/7
// @PeteKnight +++++++++++++++++++++++++++++++++++++

// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  uint16_t ID = tft.readID();
  if (ID == 0xD3) ID = 0x9481;
  tft.begin(ID);
  tft.setRotation(3);  
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(3);
  tft.setCursor(10, 40);
  tft.print("WiFi uptime: ");
  tft.setCursor(10, 90);
  tft.print("IP:   ");
  tft.print(IP);
  tft.setCursor(10, 140);
  tft.print("MAC:  ");
  tft.print(MAC);
  tft.setCursor(10, 190);
  tft.print("SSID: ");
  tft.setTextSize(2);
  tft.print(ssid);
  //tft.setCursor(10, 240);
  //tft.setTextSize(3);
  //tft.print("RSSI: ");
  //tft.print(wifi_signal());
  //tft.print(" dBm");
// MCUFriend TFT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  
  timer.setInterval(1000, connectionUp);     // Do stuff when connected 
}




void loop() {
    Blynk.run();
    timer.run();
}


// @Elfo_Del_Monte
//get wifi strength https://community.blynk.cc/t/wemos-mega-wifi-r3-atmega2560-esp8266/44976/7
  int wifi_signal() {
    String ap_string=wifi.getNowConecAp();
    char* ap_char=ap_string.c_str();
    ap_char=strtok(ap_char,",");
    ap_char=strtok(NULL,","); 
    ap_char=strtok(NULL,",");
    ap_char=strtok(NULL,"\n");
    return atoi(ap_char);
  }
// // @Elfo_Del_Monte

void connectionUp() {                        // Prints to Serial Monitor and TFT WiFi uptime every second
  if (status == WL_CONNECTED) {
    count++;
    Serial.print("WiFi Connected . . . ");
    Serial.println(count);
    Serial.println();
    
    tft.setTextSize(4);
    tft.setCursor(280, 33);
    tft.print(count);
    
    tft.setCursor(10, 240);
    tft.setTextSize(3);
    tft.print("RSSI: ");
    tft.print(wifi_signal());
    tft.print(" dBm");
  }
}