-
Notifications
You must be signed in to change notification settings - Fork 2
/
a20_wifi.ino
74 lines (63 loc) · 3.31 KB
/
a20_wifi.ino
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
/*******************************************************************************
# #
# LYT-SCRIPTED, an alternative firmware for LYT8266 RGBW LED lamps #
# #
# #
# Copyright (C) 2017 Tom Stöveken #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
*******************************************************************************/
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <WiFiUdp.h>
WiFiUDP Udp;
uint8_t buffer[10] = {1};
/******************************************************************************
Description.: prepare the WiFi settings, uses WiFi Manager Library
Input Value.: -
Return Value: -
******************************************************************************/
void setup_wifi() {
WiFiManager wifiManager;
//reset settings - for testing
//wifiManager.resetSettings();
wifiManager.setConfigPortalTimeout(600);
wifiManager.autoConnect("LYT8266");
Log("WiFi connected, RSSI: "+ String(WiFi.RSSI()));
}
/******************************************************************************
Description.: no permanent task necessary
Input Value.: -
Return Value: -
******************************************************************************/
void loop_wifi() {
//because of having issues with an unresposive connection
//just meaningless data traffic will hopefully fix it
//a single UDP packet is send to the gateway IP
static unsigned long then = 0;
// for using millis be aware of overflow every ~50 days
// but using substraction is "overflow-safe"
if( g_send_WLAN_keep_alive_packet && (millis()-then >= 30000) ) {
then = millis();
//UDP port 9 is supposed to discard packets or it will simply not return
//anything because no service is running at the gateway-IP,port9
Udp.beginPacket(WiFi.gatewayIP(), 9);
Udp.write(buffer, LENGTH_OF(buffer));
Udp.endPacket();
Log("WiFi kept busy, RSSI: "+ String(WiFi.RSSI()) +", Connected: "+ String(WiFi.isConnected()));
}
}