Hey I haven’t used the terminal widget before… Not sure if there is an error in my code or if my hardware can’t handle it. (NodeMCU 0.9)
I looked at the sketch link to GitHub
-defined BLYNK_PRINT Serial
-debug
-Defined a WidgetTerminal “name” and Vpin
-Is Serial.begin used or was it on the GitHub sketch because it was connected to the serial port?
-Called some terminal.prints and they don’t work.
See attached code…
#define BLYNK_DEBUG
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#ifndef STASSID
#define STASSID "**"
#define STAPSK "**"
#define LED D4
long S = 300;
long O = 1200;
long off = 600;
int flagS=0;
int flagO=0;
int loopFlag=0;
int loopFlagO=0;
int loopFlagS=0;
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
WidgetLCD lcd (V0);
WidgetTerminal terminal1(V5);
char auth[] = "@@@";
BlynkTimer timer;
void setup() {
Serial.begin(9600); //115200
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
delay(5000);
ESP.restart();
}
Blynk.begin(auth,STASSID,STAPSK);
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else {
type = "filesystem";
}
});
ArduinoOTA.onEnd([]() {
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
});
ArduinoOTA.onError([](ota_error_t error) {
if (error == OTA_AUTH_ERROR) {
} else if (error == OTA_BEGIN_ERROR) {
} else if (error == OTA_CONNECT_ERROR) {
} else if (error == OTA_RECEIVE_ERROR) {
} else if (error == OTA_END_ERROR) {
}
});
ArduinoOTA.begin();
pinMode(LED,OUTPUT);
digitalWrite(LED, HIGH);
timer.setInterval(1000L,upTime);
Blynk.notify("Up again!");
lcd.clear();
terminal1.println("started");
}
void loop() {
ArduinoOTA.handle();
Blynk.run();
timer.run();
}
BLYNK_WRITE(V10)
{
int buttonStatus = param.asInt();
//lcd.print(0,0, "1");
if ((buttonStatus == 1))
{
Blynk.setProperty(V10, "offLabel", "Start");
lcd.clear();
lcd.print(0,0, loopFlagO);
lcd.print(1,0, loopFlagS);
S1();
terminal1.print("wow");
}
}
void S1()
{
if(loopFlagS <= 2){
digitalWrite(LED,LOW);
timer.setTimeout(S,Off2);
lcd.print(0,0, loopFlagO);
lcd.print(1,0, loopFlagS);
Blynk.setProperty(V10, "offLabel",(loopFlagO+loopFlagS));
}
else if((loopFlagS >= 2)&&(loopFlagO <= 2))
{
digitalWrite(LED,LOW);
timer.setTimeout(O,Off3);
lcd.print(0,0, loopFlagO);
lcd.print(1,0, loopFlagS);
Blynk.setProperty(V10, "offLabel", (loopFlagO+loopFlagS));
}
else if((loopFlagS <= 5)&&(loopFlagO == 3))
{
digitalWrite(LED,LOW);
timer.setTimeout(S,Off2);
lcd.print(0,0, loopFlagO);
lcd.print(1,0, loopFlagS);
Blynk.setProperty(V10, "offLabel", (loopFlagO+loopFlagS));
}
else{
loopFlagS=0;
loopFlagO=0;
S3();
}
}
void Off2()
{
digitalWrite(LED,HIGH);
loopFlagS++;
timer.setTimeout(off,S1);
Blynk.setProperty(V10, "offLabel", (loopFlagO+loopFlagS));
}
void Off3()
{
digitalWrite(LED,HIGH);
timer.setTimeout(off,S1);
loopFlagO++;
}
void S3()
{
lcd.print(0,0, "bucka");
timer.setTimeout(3000L,clearLCD);
}
void clearLCD()
{
lcd.clear();
Blynk.notify("Done");
Blynk.setProperty(V10, "offLabel", "Done");
}
void upTime()
{
unsigned long runMillis = millis();
unsigned long allSeconds = millis()/1000;
int daysRemain = allSeconds/86400;
int runDays = daysRemain%86400;
int runHours = allSeconds/3600;
int secsRemaining = allSeconds%3600;
int runMinutes = secsRemaining/60;
int runSeconds = secsRemaining%60;
char buf[25];
sprintf(buf,"Runtime %02d:%02d:%02d:%02d",runDays,runHours,runMinutes,runSeconds);
Blynk.virtualWrite(V4,buf);
}