Reading VirtualPin value from another hardware board

Hi, I’m trying to work out if the following is possible (in a simple fashion): [Essentially reading a virtual pin value from one h/w board from another with different AUTH tokens] -e.g.

Board 1 : Ardunio Mega running with its own AUTH token , Virtual PIN 1 holds the current temperature reading from a sensor, being read evey 10 seconds
Board 2 : Wemos D1 mini running with its own AUTH token, and I wish to read the value of V1 from Board 1 every 30 mins

1 Like

Yes, no problem for Blynk.

how :slight_smile: I can’t seem to figure out a simple solution.Any hints ? :wink:

Do both auth tokens belong to the same user?

If so then the Bridge widget should be fine.

There are new ways too with the latest libraries.

hi @Costas was looking at Bridge widget (btw: yes in this case using same userid), but I’m failing to understand how I read the actual virtual pin value of another auth token board. I can see that using bridge with a syncvirtual pin could envoke a Blynk write in the other board but that doesn’t help as I need the value read from the bridged board if that makes sense. Only way I can think of reading the value of a virtual pin from another board with a different auth token is by using Http API getvalue command.

There is an example for bridge
May be this helps to understand

This will set the V5 to the given value.:
bridge1.virtualWrite(V5, 1); // Sends 1 value to BLYNK_WRITE(V5) handler on receiving side.

But you must handle V5 at the second board also:

 /////////////////////////////////////////////////////////////////////////////////////////
// Keep in mind that when performing virtualWrite with Bridge,
// second board will need to process the incoming command.
// It can be done by using this handler on the second board:
//
//    BLYNK_WRITE(V5){
//    int pinData = param.asInt(); // pinData variable will store value that came via Bridge
//    }
//
/////////////////////////////////////////////////////////////////////////////////////////
1 Like

thanks Brummer - I’ve seen this example but as you said it does not allow you to read the virtual pin value from another board. The solution I’ve come up with involves using the http api - (optionally using webhook) using bridge as far as I can see will not deliver the solution. @costas seem to have a solution perhaps.

1 Like

@mars

Why not set up the bridge on the BoardA to read the virtual pin (Temp sensor) every 30 min, then send (via bridge) to the other BoardB; Essentially instead of “reading from A” it is getting the data “pushed from A”… gets the same job done right?

While I haven’t tried yet, I don’t see why we can’t set up the bridge on both boards, then either can push data to the other.

hi Gunner - yes I see your thinking; basically the board which is the source of virtual pin (calling it Board A), does a BLYNK_WRITE(V1) and within the blynk write function it does a bridge.virtualwrite(V1) (every 30 mins) to Board B which is the board I want to save/receive the data every 30 mins. I’ll give it a try

Well I managed to succeed with the following sketch in reading virtual pin from effectively any another board using http api (which can be very useful) - however I cannot succeed in using webhook Widget to do the same - if anybody out there can successfully read a value of a virtual pin via an SSL https request from webhook widget then I would be grateful to known how they did it :wink: - I can’t make it work for me.

The code below works for those interested in using this capability for their projects:

/*
 *  HTTP over TLS (HTTPS) example sketch
 *
 *  This example demonstrates how to use
 *  WiFiClientSecure class to access HTTPS API.
 *  We fetch and display the status of
 *  esp8266/Arduino project continuous integration
 *  build.
 *
 *  Created by Ivan Grokhotkov, 2015.
 *  This example is in public domain.
 */

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "------";
const char* password = "-------";

const char* host = "<my local blynk server domain>";
const int httpsPort = <my local blynk server ssl port>-;  //

// Use web browser to view and copy
// SHA1 fingerprint of the certificate

const char* fingerprint = "-- -- f4 db -- -- -- 5a -- -- -- -- -- -- c8 -- a1 -- 59 --";


void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Use WiFiClientSecure class to create TLS connection
  WiFiClientSecure client;
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }

  String url = "/<my auth token >/get/V2";   // reads Virtual Pin 2 from the specified <my auth token>
  Serial.print("requesting URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\r\n" +
               "Connection: close\r\n\r\n");

  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client.readStringUntil('\n');
  if (line.startsWith("{\"state\":\"success\"")) {
    Serial.println("esp8266/Arduino CI successfull!");
  } else {
    Serial.println("esp8266/Arduino CI has failed");
  }
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
}

void loop() {
}

I see some errors from your webhook. So it could be our issue. I’ll check. But in next year :wink:.

awesome, thanks Dmitriy