forked from blynkkk/blynk-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlynkSimpleLinkItONE.h
92 lines (77 loc) · 2.27 KB
/
BlynkSimpleLinkItONE.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
83
84
85
86
87
88
89
90
91
92
/**
* @file BlynkSimpleLinkItONE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jul 2015
* @brief
*
*/
#ifndef BlynkSimpleLinkItONE_h
#define BlynkSimpleLinkItONE_h
#ifndef BLYNK_INFO_DEVICE
#define BLYNK_INFO_DEVICE "LinkIt ONE"
#endif
// cause this causes crashes...
#define BLYNK_NO_YIELD
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
class BlynkLinkItOneWifi
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkLinkItOneWifi(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass, int wifi_auth)
{
BLYNK_LOG("Connecting to %s ...", ssid);
LWiFi.begin();
while(!LWiFi.connect(ssid, LWiFiLoginInfo((LWiFiEncryption)wifi_auth, pass))){
::delay(1000);
}
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
int wifi_auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, wifi_auth);
config(auth, domain, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
int wifi_auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, wifi_auth);
config(auth, ip, port);
}
};
static LWiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkLinkItOneWifi Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif