OK here is the full sketch:
</>
#define Version "1.1"
/**************************************************************
* 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
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* Blynk using a LED widget on your phone!
*
* App dashboard setup:
* LED widget on V1
* LED widget on V2
*
*
* WARNING :
* For this example you'll need SimpleTimer library:
* https://github.com/jfturcot/SimpleTimer
* Visit this page for more information:
* http://playground.arduino.cc/Code/SimpleTimer
*
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleOak.h>
#include <SimpleTimer.h>
// Use Virtual pin 5 for uptime display
#define PIN_UPTIME V5
/// Use Virtual pin 3 for rebootToConfig() ///
#define REBOOT_TO_CONFIG V3
/// the bellow variables are for 3 sec push mode for V3 button in order to get in softAP mode ///
unsigned long previousMillis = 0; ///
const long interval = 3000; ///
unsigned long currentMillis = 0; ///
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth here";
WidgetLED led1(V1);
WidgetLED led2(V2); /// reports the actual logic of GP5 pin///
WidgetLCD lcd(V7);
SimpleTimer timer;
// This function sends Arduino's up time every 4 seconds to Virtual Pin (6).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendTemperature()
{
// Generate random temperature value 00.0 to 18.0 (for example)
float t = float(random(000, 180))/10;
// Format: 1 decimal place, add ℃
String str = String(t, 1) + "℃";
String strV6 = String(t, 1);
// Send it to the server
Blynk.virtualWrite(V6, strV6);
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(5, 1, str); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(1, 0, "The temp. is:");
}
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth);
/// initializing the GP5 that goes to the Relay, for output and set it to HIGH ("1") in order to have water heater Relay turned OFF ///
pinMode(5, OUTPUT); //LED on Oak
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
while (Blynk.connect() == false) {
// Wait until connected
}
timer.setInterval(1000L, blinkLedWidget);
/// timer.setInterval(200L, fadeLedWidget);
// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (5)
// Setup a function to be called every second
timer.setInterval(4000L, sendTemperature);
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(1, 0, "Not final yet!");
lcd.print(4, 1, "Ver=");
lcd.print(8, 1, Version); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
}
BLYNK_READ(PIN_UPTIME)
{
// This command writes Arduino's uptime in seconds to Virtual Pin (5)
Blynk.virtualWrite(PIN_UPTIME, millis() / 1000);
}
/// press V4 button in order to get the Software Version printed on app's screen ///
BLYNK_WRITE(V4)
{
if (param.asInt()) {
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(1, 0, "Not final yet!");
lcd.print(4, 1, "Ver=");
lcd.print(8, 1, Version); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
delay(400);
}
}
/// start of testing routine for correct driving using inverse logic, the external Relay. The Virtual Button SW V8 <==> GP5///
BLYNK_WRITE(V8)
{
if (param.asInt()) {
digitalWrite(5, LOW);
} else {
digitalWrite(5, HIGH);
}
}
/// end of testing routine for correct driving external inverse logic Relay using Virtual Button SW ///
/// start of rebootToConfig() routine for ISSUE reset to config to OAK if V3 button pressed for >= 3 seconds ///
BLYNK_WRITE(V3)
{
if (param.asInt()) {
/// button pressed ///
lcd.clear(); //Use it to clear the LCD Widget;
lcd.print(0, 0, "Rebooting.....");
lcd.print(0, 1, "in WiFi Config!");
delay(400);
Oak.rebootToConfig();
}
}
/* THIS DOES NOT WORK AS EXPECTED
BLYNK_WRITE(V3)
{
if (param.asInt()) {
/// button pressed ///
currentMillis = millis();
} else {
/// button released ///
if (millis() - currentMillis > interval) {
/// do something after long button press.
lcd.clear(); //Use it to clear the LCD Widget;
lcd.print(0, 0, "Rebooting.....");
lcd.print(0, 1, "in WiFi Config!");
delay(500);
Oak.rebootToConfig();
}
}
}
*/
void blinkLedWidget()
{
if (led1.getValue()) {
led1.off();
BLYNK_LOG("LED1: off");
} else {
led1.on();
BLYNK_LOG("LED1: on");
}
}
// Every time we connect to the cloud synchronize all the values from Widgets...
BLYNK_CONNECTED() {
/// if (isFirstConnect)
/// {
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
/// }
}
void loop()
{
Blynk.run();
if (digitalRead(5)== 1)
{
led2.on();
}
else
{
led2.off();
}
timer.run();
}
</>