How to show the Blynk Serial Monitor on My Android app?

Hello, I have a project to control a relay with a Blynk app switch. I’m using Blynk IOT. The code is below and it works well.

However, I want to have the serial monitor output shown in the app, instead of just on the Serial Monitor for Arduino IDE, because that only works when the ESP8266 is connected via USB to the PC. (I think by using the Sim800L module to write it to blynk IOT server, and then retrieve from the Blynk app.) I want to use a separate power source and view the output remotely.

How can this be done? I searched the forum and there was a suggestion to use Terminal.print instead of Serial.print, but that gives an error. I can make a Terminal on the app, but can’t understand how to send all serial prints to the terminal, so that I can view them from the app.

Any help is appreciated.

• ESP8266 + Sim800L
• Sony Xperia XZ3, Android 10.
• Blynk server
• Blynk Library version : 1.0.0

#define BLYNK_TEMPLATE_ID "TMPLGsnMChWq"
#define BLYNK_DEVICE_NAME "MyESP"
#define BLYNK_AUTH_TOKEN "EkwgjmAuIysjIgCbHewkhjCZy1CzHR5C"

//------------------------------------------------------------------
#define BLYNK_PRINT Serial

#define TINY_GSM_MODEM_SIM800
//------------------------------------------------------------------

#include "Adafruit_FONA.h"
#include <SoftwareSerial.h>
//GPS Module RX pin to NodeMCU D3
//GPS Module TX pin to NodeMCU D4
#define rxPin 0
#define txPin 2
#define FONA_RST 13

SoftwareSerial Sim800L(rxPin,txPin);
SoftwareSerial *fonaSerial = &Sim800L;
//Hardware serial is also possible! for ESP32
//HardwareSerial *fonaSerial = &Serial2;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

//------------------------------------------------------------------

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
//------------------------------------------------------------------
char auth[] = BLYNK_AUTH_TOKEN;

char apn[]  = "hutch3g";
char user[] = "";
char pass[] = "";
//------------------------------------------------------------------
TinyGsm modem(fona);
BlynkTimer timer;
//------------------------------------------------------------------
//NOTE: Enter the phone number that you want to register with the project
//You can only control the project, with the phone number you entered here
//Must enter your personal phone number with country code.
//Make Sure: never enter the gsm module's phone number here.

const String PHONE = "+94777984078";
//------------------------------------------------------------------
#define pin_relay1 14
//------------------------------------------------------------------
int state_relay1 = 0;
//------------------------------------------------------------------
//Change the virtual pins, as you have set in the blynk account.
#define virtual_pin1    V1
//------------------------------------------------------------------
String gsm_buff ="";
char sendsms[15];
char caller_id[32];
char sms_buffer[160];
int len=0;


//------------------------------------------------------------------
BLYNK_WRITE(virtual_pin1) {
  state_relay1 = param.asInt();
  digitalWrite(pin_relay1, state_relay1);
   Serial.print("Relay 1 is ");
   if(state_relay1==0)
   Serial.println("OFF");
   else
   Serial.println("ON");
}

//------------------------------------------------------------------

void handle_sms(){
  while(Serial.available())  {
    fona.println(Serial.readString());
  }
  //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  gsm_buff ="";
  //+CMTI: "SM",1 (here! 1 is slot)
  int slot = 0;
  uint16_t smslen;
  //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  //any data available from the fona?
  gsm_buff= fona.readString();
  //if(gsm_buff.length() > 0)
    //{Serial.println();Serial.println(gsm_buff);}
  len = gsm_buff.length();
  //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  //if(gsm_buff.indexOf("+CMTI:")) {
  if (len >10) {
    gsm_buff =gsm_buff.substring(14,len);
    slot = gsm_buff.toInt();
    Serial.print("Slot: ");
    Serial.println(slot);
    if (slot == 0) {
      return;
    }
    //------------------------------------------------------------
    if (!fona.readSMS(slot, sms_buffer, 250, &smslen)) {  // pass in buffer and max len!
      Serial.println(F("Failed!"));
      return;
    }
    //------------------------------------------------------------
    if (! fona.getSMSSender(slot, caller_id, 31)) {
      Serial.println("Didn't find SMS message in slot!");
      return;
    }
    //------------------------------------------------------------
    if(PHONE != String(caller_id)){
      Serial.println("The phone number is not Registered.");
      Serial.println("Please use the Registered Phone Number.");
    }
    else 
    {
      //_________________________________________
      String sms_temp = sms_buffer;
      sms_temp.toLowerCase();
      String caller_temp = caller_id;
      Serial.println("SMS: "+sms_temp);
      Serial.println("From: "+caller_temp);
      //_________________________________________
      if(sms_temp == "1on"){
        state_relay1 =1;
        digitalWrite(pin_relay1, HIGH);
        Blynk.virtualWrite(virtual_pin1, state_relay1);
        fona.sendSMS(caller_id, "Relay 1 is ON");
        Serial.println("Response: Relay 1 is ON");
      }
      //_________________________________________
      if(sms_temp == "1off"){
        state_relay1 =0;
        digitalWrite(pin_relay1, LOW);
        Blynk.virtualWrite(virtual_pin1, state_relay1);
        fona.sendSMS(caller_id, "Relay 1 is OFF");
        Serial.println("Response: Relay 1 is OFF");
      }
      
      //_________________________________________
      else
        {
          fona.sendSMS(caller_id, "ERROR: Send SMS with valid command");
        }
      //_________________________________________
    }
    //------------------------------------------------------------
    fona.deleteSMS(slot);
    fona.print(F("AT+CMGD=1,4\n\r"));
    fona.print(F("AT+CMGDA= \"DEL ALL\""));
    //------------------------------------------------------------
  }
  //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}
 
 

void setup()
{
  Serial.begin(115200);
    //--------------------------------------------------------------------
  pinMode(pin_relay1, OUTPUT);
 
  //--------------------------------------------------------------------
  //During Starting all Relays should TURN OFF
  digitalWrite(pin_relay1, LOW);
 
  //--------------------------------------------------------------------
  delay(2000);
   fonaSerial->begin(9600);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while(1);
  }
  //--------------------------------------------------------------------
  Serial.println(F("FONA is OK"));
  fona.println("AT+CMGF=1"); // Configuring TEXT mode
  delay(1000);
  fona.print ("AT+CSMP=17,167,0,0\r");// Configuring TEXT mode
  delay(1000);
  fona.print("AT+CNMI=2,1\r\n");  //set up the fona to send a +CMTI notification when an SMS is received
 
  fona.println(F("AT+CMGDA=\"DEL ALL\""));
  //delay(5000);
  delay(1000);
  Serial.println("FONA Ready");
  //--------------------------------------------------------------------
  modem.restart();
  //Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

  Blynk.begin(auth, modem, apn, user, pass);
  Blynk.virtualWrite(virtual_pin1, state_relay1);
  //--------------------------------------------------------------------
  timer.setInterval(2000, handle_sms);
}

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

Serial Monitor output is something like this. I want to view this on the app itself.

Attempting to open comm with ATs
	---> AT
	<--- OK
	---> ATE0
	<--- OK
	---> ATE0
	<--- OK
	---> AT+CVHU=0
	<--- OK
	---> ATI
	<--- SIM800 R14.18

OK

	---> AT+CPMS="SM","SM","SM"
	<--- +CPMS: 10,10,10,10,10,10
FONA is OK
FONA Ready
[16943] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.0 on ESP8266

[16945] Modem init...
[17137] Connecting to network...
[24198] Network: Hutchison Lanka (Pvt)
[24198] Connecting to hutch3g ...
[33039] Connected to GPRS
[33105] Connecting to blynk-cloud.com:80
[34946] Ready (ping: 532ms).

Slot: 2
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=2
+CMGR: "REC UNREAD","+94777984078","","22/06/20,17:59:33+22",145,32,0,0,"+9477000003",145,3
1on
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=2
+CMGR: "REC READ","+94777984078","","22/06/20,17:59:33+22",145,32,0,0,"+9477000003",145,3
SMS: 1on
From: +94777984078
	---> AT+CMGF=1
	<--- OK
	---> AT+CMGS="+94777984078"
	<--- > 
> Relay 1 is ON
^Z
Response: Relay 1 is ON
	---> AT+CMGF=1
	<--- +CMTI: "SM",4
	---> AT+CMGF=1
	<--- +CIEV: 10,"41308","Hutch","", 0, 0
Slot: 5
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=5
+CMGR: "REC UNREAD","+94777984078","","22/06/20,18:12:36+22",145,36,0,0,"+9477000003",145,4
1off
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=5
+CMGR: "REC READ","+94777984078","","22/06/20,18:12:36+22",145,36,0,0,"+9477000003",145,4
SMS: 1off
From: +94777984078
	---> AT+CMGF=1
	<--- OK
	---> AT+CMGS="+94777984078"
	<--- > 
> Relay 1 is OFF
^Z
Response: Relay 1 is OFF
	---> AT+CMGF=1
	<--- 
Slot: 0
Slot: 7
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=7
+CMGR: "REC UNREAD","+94777984078","","22/06/20,18:13:31+22",145,36,0,0,"+9477000003",145,3
1on
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=7
+CMGR: "REC READ","+94777984078","","22/06/20,18:13:31+22",145,36,0,0,"+9477000003",145,3
SMS: 1on
From: +94777984078
	---> AT+CMGF=1
	<--- OK
	---> AT+CMGS="+94777984078"
	<--- > 
> Relay 1 is ON
^Z
Response: Relay 1 is ON
	---> AT+CMGF=1
	<--- 
	---> AT+CMGF=1
	<--- 
Slot: 8
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=8
+CMGR: "REC UNREAD","+94777984078","","22/06/20,18:13:46+22",145,36,0,0,"+9477000003",145,4
1off
	---> AT+CMGF=1
	<--- OK
	---> AT+CSDH=1
	<--- OK
AT+CMGR=8
+CMGR: "REC READ","+94777984078","","22/06/20,18:13:46+22",145,36,0,0,"+9477000003",145,4
SMS: 1off
From: +94777984078
	---> AT+CMGF=1
	<--- OK
	---> AT+CMGS="+94777984078"
	<--- > 
> Relay 1 is OFF
^Z
Response: Relay 1 is OFF
	---> AT+CMGF=1
	<--- 
Slot: 0
Relay 1 is ON
Slot: 0
Relay 1 is OFF
Slot: 0
Relay 1 is ON
Relay 1 is OFF

Here you go…

The Terminal widget in Blynk IoT doesn’t currently retain the data that was previously sent to it before the app was closed and re-opened, but that is due to be fixed at some point in (I think) the fairly near future.

Pete.

I’d suggest that you start with a very basic sketch first. this is a good example
Blynk Example Browser