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();
}