Reading Digital Pin using Bridge

My idea is creating a Wifi Remote Device (ESP8266) to control other ESP8266 (remote), I have succeed to push (write) one value to Digital Pin on remote ESP, unfortunately I can not find a way to read the remote Digital Pin … This (remote digital pin) value is needed since I want to create a toggle mechanism …
Further more on the remote device to preserve the batt I will shutdown the device in any given time …

Any suggestion for work around?

/************************************************************************
 * 
 *     BLYNK with RaspBerry Local Server
 *     192.160.0.XX - My_IoT
 * 
 *     Rev 1
 * 
 *************************************************************************/
#define BLYNK_MAX_SENDBYTES 1200
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define BLYNK_PROPERTY // Comment this out to disable Blynk.setProperty

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <TimeLord.h>
// ************** OTA *****************
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
// ************** OTA *****************

// ---------------- CRENDENTIAL and Other Param -------------------------------------------------------------
const char ssid[] = "wifi";
const char pass[] = "passwd";
const char blynk_server[40] = "ip";
const char auth[] = "auth1"; // Wifi Remote 
const char auth_bridge[] = "auth2"; // Lt.2 
const char OTA_Hostname[] = "myesp-WifiRemote";

#define DigitalPinButton D1 // GPIO_5
#define DigitalPinInternalLED D4
#define DigitalPinLED D3 // GPIO_0
#define DigitalPinBridgeLED D5 // GPIO_14
#define VirtualPinBridgeLED V5 // GPIO_14


ADC_MODE(ADC_VCC);
WidgetRTC rtc;
SimpleTimer timer;
WidgetBridge bridge_lt2(V0);

const int DebounceCounterMAX = 5;

// boolean FirstConnection = true;
boolean LastNetworkConnectionState = false;
boolean LampStateHIGH = false;
int DebounceCounter = 0;


/* ========================================================================
                            STARING BLYNK FUNCTiON
  ======================================================================== */



BLYNK_CONNECTED() { // -- Executed every Blynk connected to internet
 bridge_lt2.setAuthToken(auth_bridge);

 if (FirstConnection) {
   ToggleSwitchLamp();
   FirstConnection = false;
 }
 
}


BLYNK_WRITE(V2) { //-- Button Widget for Lamp 1 
  int i =  param.asInt();
}

void ToggleSwitchLamp() {
  LampStateHIGH = !LampStateHIGH;  // flip LampState
  if (LampStateHIGH) {
    bridge_lt2.virtualWrite(VirtualPinBridgeLED, HIGH);
  }
  else {
    bridge_lt2.virtualWrite(VirtualPinBridgeLED, LOW);      
  }
}

void Timer_ReadButtonDebounce ()
{
  int ButtonValue = digitalRead(DigitalPinButton); // Touch Sensor Switch
  if (ButtonValue == 1) {
    DebounceCounter++;
    if (DebounceCounter == DebounceCounterMAX) ToggleSwitchLamp();  // == non repeatable; >= reapetable
  }
  else DebounceCounter = 0;
  
}

void TimerCheckNetworkConnection()
{
  boolean CurrentNetworkConnectionState = Blynk.connected();
  if (CurrentNetworkConnectionState) {
    if (CurrentNetworkConnectionState != LastNetworkConnectionState) digitalWrite(DigitalPinInternalLED, HIGH);
  }
  else {
    if (CurrentNetworkConnectionState != LastNetworkConnectionState) digitalWrite(DigitalPinInternalLED, LOW);
  }
  LastNetworkConnectionState = CurrentNetworkConnectionState;
}


/* ========================================================================
                            STARING SETUP & LOOP FUNCTiON
  ======================================================================== */

void setup() {

  Serial.begin(115200);  
  pinMode(DigitalPinButton, INPUT);
  pinMode(DigitalPinInternalLED, OUTPUT); // Internal LED (Blink network)
  digitalWrite(DigitalPinInternalLED, LOW); // initial Set internal LED Off

  ConnectWifi();
  Blynk.config(auth,blynk_server,8080);
  timer.setInterval(10L, Timer_ReadButtonDebounce); // Read phisical button every 100 milisecond
  timer.setInterval(250L, TimerCheckNetworkConnection); // Blink while not connected to WiFi
  Init_ArduinoOTA(); 
}



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


Did you try to read the Digital Pin firstly from its board and transfer the data into Virtual Pin to be sent to the Remote device? Give it a try…

1 Like

Sure … Nice suggestion, I can create a trigger for the remote control device (master) to ask the slave device to copy the digital pin state to the master virtual pin… but yet I have no clue how to read the virtual pin?

Ummmhh … maybe I can use BLYNK_WRITE(VirtualPin)
Ok let me try … thanks for the suggestion @psoro

its not possible to read a pin directly, the only method is blynk.sync(pin) in combination with blynk_write(pin) the sync will force the write to run.
Note that if you update a pin remotely it will trigger blynk_write for that pin locally, just keep in mind that you use a bridge to update the remote pin.

1 Like

You know about Espressif Systems’ ESP.now communication? (they must be near around one of the other to work but no internet is needed)

1 Like

The other device I want to controlled is running Blynk apps… I don’t think Bynk is supporting ESP.now yet… :slight_smile:

I know, but i was talking that «if the devices are near» you can use ESP.now to make a “local communication protocol” to use when the internet connection is down.

1 Like