BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Combining two widgets

Hi, I’m new to programing and electronic things. I trying to figure are there any possibility that we can combine two widgets together since I’m trying to send my gps coordinate from my phone (using the gps widget) to the terminal widget on Blynk app. Thanks!. I’m using the Wemos d1 r1

Here is the code

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}
  BLYNK_WRITE(V3){
    if(String("1") == param.asStr()){
  BLYNK_WRITE(V0){
        GpsParam gps(param);
        float Lat = gps.getLat();
        if( param.asInt() == 1){
        Blynk.virtualWrite(V3, Lat);
      }
  }
    }
  }
void loop()
{
  Blynk.run();
}

Firstly, as per the welcome topic, you need to properly format any posted code in this forum, for proper viewability…

Blynk - FTFC

Your title is a bit misleading as you are not really combining widgets… just the usual “use sensor to get data and display to show data” routine.

As for your question… yes, it can be done… probably similar to how your code sorta looks (I have not looked at it that close in it’s unformatted format… I find reading the flow of others code a challenge when I can see it correctly, let alone when I can’t :stuck_out_tongue: …thats my story and I am sticking too it )

So anyhow… What are your results and what is the issue?

I’m basically trying to get my phone GPS coordinates to be send from virtual pin V0 to the terminal widget pin V3 when ever I enter 1, 2 or 3 in the terminal . Here is the code


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}
  BLYNK_WRITE(V3){
    terminal.clear();
    terminal.write(" Select the below options ");
    terminal.write('\n');
    terminal.write(" 1. Option 1 . 2. Option 2 . 3. Option 3");
    if(String("1") == param.asStr()){
  BLYNK_WRITE(V0){
        GpsParam gps(param);
        float Lat = gps.getLat();
        float Lon = gps.getLon();
        float Speed = gps.getSpeed();
        terminal.write(" Latitude: ");
        terminal.write(Lat, 8);
        terminal.write(" Longtitude: ");
        terminal.write(Lon, 8);
        terminal.write("Speed: ");
        terminal.write(Speed, 3);
        terminal.flush();
        
      }
  }
    }
void loop()
{
  Blynk.run();
}

Here is the error that I received:

Arduino_Blynk_system:14: error: 'terminal' was not declared in this scope
     terminal.clear();
     ^
Arduino_Blynk_system:19: error: a function-definition is not allowed here before '{' token
   BLYNK_WRITE(V0){
                  ^
exit status 1
'terminal' was not declared in this scope

Thank you!

Check out the Terminal’s example sketch… using the terminal.print() option requires you to setup/attach the terminal to it’s vPin in the sketch…

http://docs.blynk.cc/#widgets-displays-terminal

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

Although you can also just use the Blynk.virtualWrite(vPin, "stringdata") command to send data to the terminal… in some ways, it works even better.

This error is because you started a new Blynk function (V0) before closing } out the preceding Blynk function (V3)

But if I separate the two Blynk function I can’t use its own function. For example, the param.asStr in the terminal widget V3 or to get the data from the GPS widget to apply in the terminal widget.

It mean that whenever I enter 1 in the terminal widget. It will proceed the if statement in the BLYNK_WRITE(V3) function to get the coordinate from Virtual Pin 0

Virtual Pin 0 is the GPS widget on Blynk app

Use Global variables to carry data between functions.

https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/

Besides, the BLYNK_WRITE() function is for a widget sending data to the device… to send data back to another widget you just use the terminal.print() or Blynk.virtualWrite() commands from inside the receiving function.

1 Like

The GPS Streaming Widget even has a prepared wrapper that might work with the terminal.print()

This is UNTESTED… so you can be the guinea pig :stuck_out_tongue_winking_eye: terminal.print() may not need the decimal place marker… try with and without.

BLYNK_WRITE(vPin) {
  GpsParam gps(param);
  // Print 6 decimal places for Lat
  terminal.println(gps.getLat(), 7);
  terminal.println(gps.getLon(), 7);

  terminal.println(gps.getAltitude(), 2);
  terminal.println(gps.getSpeed(), 2);
}

How can you turn the GPS data obtained from the GPS widget to global variances? Since you can only get the gps data when you are in the BLYNK_WRITE function. If there are a way, can you show me a few lines of code. That would help much. Thanks!

This is already shown in the Docs… via the param.as___()

http://docs.blynk.cc/#blynk-main-operations-send-data-from-app-to-hardware

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control

http://docs.blynk.cc/#widgets-sensors-gps-streaming

And the GPS Streaming example (using the prepared wrapper method)… just modify as I mentioned above.

https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FGPS_Stream