I can't use the terminal in an external file

@Nera I’ve merged your two topics, as they are about the same issue.
Please don’t keep creating new topics in this way.

Pete.

Thanks Pete, I’m still trying to find a solution.

TBH, I don’t understand your problem, what it is that you are trying to achieve, and what the function of your Terminal.h header file.

If you wish to send data to the Blynk terminal widget then there are two main ways in C++

  1. Write the data direct to the virtual pin that the terminal widget is connected to…
    Blynk.virtualWrite(V1,"Hello World)

  2. Use the functionality provided by the WidgetTerminal.h" wrapper (which doesn't need to be specified in any #includestatement). To use this wrapper you create a terminal object usingWidgetTerminal terminal(V1)then print data to that object usingterminal.println(“Hello World”)`

The two methods give very similar results. The wrapper makes print/println operations simpler, but I think there are occasional use cases where it doesn’t always produce the expected result. The command to clear the screen has a different syntax, but works equally well with both methods.

Pete.

My case is option 2. I did as you said, but the following message appears:

Compiling 'Indka ILV1000' for 'ESP32 Dev Module'
 
Indka ILV1000.ino: 198:10: error: conflicting declaration 'Terminal terminal
   Terminal terminal
Indka ILV1000.ino:56: note  previous declaration as WidgetTerminal terminal
   WidgetTerminal terminal(V5)
 
Indka ILV1000.ino: In function void doTerminal()
 
Indka ILV1000.ino: 200:14: error: 'class WidgetTerminal' has no member named 'interpretador
   terminal.interpretador()
 
Terminal.cpp: 21:1: error: 'WidgetTerminal' does not name a type
   WidgetTerminal terminal(V5)
Terminal.cpp: In member function void Terminal::empresa()
 
Terminal.cpp: 46:6: error: 'terminal' was not declared in this scope
   ")
Error compiling project sources
Build failed for project 'Indka ILV1000'

Wait, there is a conflict, I will resolve it.

I resolved the conflict, but the error messages continue. I can’t run terminal.println (“text”) on an external file.

What error messages?

I still can’t work-out what you’re doing with your header file.

Pete.

Pete, I made a program to demonstrate what my difficulty is. The program is 100% compilable.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You can send/receive any data using WidgetTerminal object.

  App project setup:
    Terminal widget attached to Virtual Pin V1
 *************************************************************/

 /* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/*
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
*/

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "Prompt.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "JDtGDB5JXCCZyD8VdqpxRZJRlJHj63pZ";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Nera";
char pass[] = "iub950962";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);


Prompt shell;

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
bool flag_rx;
String bufferBlynk;
BLYNK_WRITE(V1)
{
    bufferBlynk = param.asString();
    flag_rx = true;
}

void setup()
{
    // Debug console
    Serial.begin(115200);

    Blynk.begin(auth, ssid, pass);

    // Clear the terminal content
    terminal.clear();

    // This will print Blynk Software version to the Terminal Widget when
    // your hardware gets connected to Blynk Server
    terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
    terminal.println(F("-------------"));
    terminal.println(F("Type 'Marco' and get a reply, or type"));
    terminal.println(F("anything else and get it printed back."));
    terminal.flush();
}

void loop()
{
    Blynk.run();
    shell.command();
}

#include "Arduino.h"
#include "Prompt.h"




Prompt::Prompt(){
   //constructor
}




String buffer;
extern String bufferBlynk;
extern bool flag_rx;
char c;
uint8_t indice;
void Prompt::command(){
    //+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
    if ((Serial.available())||(flag_rx))
    {

        c = Serial.read();

        if (c >= 0x20)
        {
            Serial.write(c);
            buffer += c;
            indice++;
        }
        else
        {
            if (c == 8) //backspace
            {
                if (index > 0)
                {
                    // 5 - retorna o nome do terminal
                    indice--;
                    Serial.write(127);
                    buffer.remove(buffer.length() - 1, 1);
                }
                else
                {
                    Serial.write(7);//bell
                }
            }
            else if (c == '\r') //enter
            {
                Serial.println();
                buffer += '\0';
                indice = 0;
            }
            else //--
            {
                Serial.println("? Nao foi possivel interpretar");
            }
        } //Caracteres especiais 

    }
    //+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 

    if (flag_rx) {
        flag_rx = false;
        buffer = bufferBlynk;
        c = 13;
    }
    
    //+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 

    if (c == 13) //ENTER
    {
        if (buffer.startsWith("help"))
        {
            Serial.println("This is a help!");
        }


        c = 0;
    }
    //+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
}
#ifndef PROMPT_H
#define PROMPT_H

class Prompt {
public:
      Prompt();  //Constructor
	  void command(); //
private:
};


#endif

I´m using an ESP32.

Your approach of dumping lots of code, which I personally find incomprehensible, into this forum topic doesn’t seem to be generating the desired results.

I think it would be more helpful if you simpy explained, in words, what exactly it is that you are trying to achieve, and why the existing Blynk terminal widget functionality isn’t working for you.

Pete.

Now I have made the code as simple as possible using examples from Blynk. I’m trying to print the text “This is a help!” On the terminal, but I don’t know how to do that because I’m trying to make it from an external file, where there is no Blynk declaration.

Good morning Pete. Please take a look at the last 3 codes I sent you, you will notice that it is very easy to understand because it was based on a blynk firmware.

I’m afraid that your programming methods are beyond the scope of my current C++ coding skills, so as I’ve said before, I don’t understand your code.

Neither do I understand what it is that you are trying to achieve and why, or why you expect a serial.printing statement to appear in the Blynk terminal without some additional functionality- which I don’t see.

Normally, I’d take my lack of knowledge as a challenge to learn more, but in this case I don’t feel that learning more would actually help, as I still don’t know what the ‘big picture’ goal of this exercise is, and why you need to approach the issue from this perspective.

Pete.

Pete, normally when we have a variable / object that we want to use in another file, we redeclar it as ‘extern’, but I can’t do that with blynk because it gives an error, please take the last three codes and compile for you to see the generated errors and thus be able to help me and others who are having the same problem.

I don’t see how me compiling the code to confirm that it generates an error will help.

Pete.

If you install the IDE from arduino and use these 3 simple files and compile it will not give an error. It will only give an error if you try to print to the external CPP file.

So are you after taking the terminal input and sending it to a file in the Arduino file system? If so a wild guess would be save your terminal input to a temporary file, write or append the existing file in littleFS then it should be possible to send that to a server. (Also beyond my scope of programming)