-
Notifications
You must be signed in to change notification settings - Fork 10
/
_blynk.h
82 lines (66 loc) · 1.69 KB
/
_blynk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _BLYNK_H
#define _BLYNK_H
WidgetTerminal terminal(TEXT_SENDER_WIDGET);
#include <ESP8266WiFi.h>
#include "_blynkWidgets.h"
#include "AsyncPing.h"
AsyncPing ping;
//Check if internet is up an running.
bool pingCheck = false;
//Forward declaration of the function.
void blynkSync();
void blynkInit()
{
matrix->fillScreen(0);
matrix->show();
Blynk.config(auth);
if ( Blynk.connect())
{
blynkConnected = true;
}
Serial.println("Blynk Config End");
blynkSync();
ping.on(false, [](const AsyncPingResponse & response) {
if (response.total_recv > 0)
{
Serial.println("Ping Sucessfull");
pingCheck = true;
}
else
{
pingCheck = false;
Serial.println("Ping UnSucessfull");
}
return true; //doesn't matter
});
}
//Check if Blynk needs to be connected or not, only if internet is up and running, not only wifi.
void blynkCheckEvent()
{
if (blynkConnected == false && pingCheck == false)
{
ping.begin("8.8.8.8");
}
if (blynkConnected == false && pingCheck == true)
{
Blynk.connect();
}
}
//Initial Blynk Widget state
void blynkSync()
{
Blynk.virtualWrite(BRIGHTNESS_WIDGET, brightness);
Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, LOW);
Blynk.virtualWrite(FX_BUTTON_WIDGET, LOW);
Blynk.virtualWrite(EFFECTS_WIDGET, 1);
Blynk.virtualWrite(MSG_SPEED_WIDGET, textSpeed);
Blynk.virtualWrite(FX_SPEED_WIDGET, fxSpeed);
Blynk.virtualWrite(OTA_BUTTON_WIDGET, LOW);
Blynk.virtualWrite(WIFI_CONFIG_BUTTON_WIDGET, LOW);
Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, LOW);
Blynk.virtualWrite(ALARM_BUTTON_WIDGET, LOW);
terminal.println(F(" "));
terminal.flush();
Serial.println("Terminal Flush");
}
#endif