Connect to WiFi and draft of uptime testing
Co-authored-by: x <xbr@c3l.lu>
This commit is contained in:
parent
e2862bc220
commit
e6c28f8ed9
3 changed files with 46 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
.pio
|
||||
compile_commands.json
|
||||
.vscode
|
|
@ -13,7 +13,6 @@ platform=espressif8266
|
|||
board=esp12e
|
||||
framework=arduino
|
||||
upload_speed=921600
|
||||
lib_deps = https://github.com/tzapu/WiFiManager.git
|
||||
|
||||
[env:esp12e]
|
||||
build_flags=-D RELEASE
|
||||
|
|
51
src/main.cpp
51
src/main.cpp
|
@ -1,18 +1,57 @@
|
|||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#define RELAY 4 // GPIO4
|
||||
#define WIFI_NAME "TechInc"
|
||||
#define WIFI_PASSWORD "itoldyoualready"
|
||||
#define ROOT_DNS_IP "193.0.14.129"
|
||||
|
||||
const IPAddress root_dns_ip(193, 0, 14, 129);
|
||||
|
||||
bool testDNS() {
|
||||
WiFiUDP udp;
|
||||
udp.beginPacket(root_dns_ip, 53);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool testHTTP() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true if Internet works
|
||||
bool uplinkWorks() {
|
||||
return testDNS() || testHTTP();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.print("Connecting to WiFi");
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Connected, IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
pinMode(RELAY, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
digitalWrite(RELAY, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
digitalWrite(RELAY, LOW);
|
||||
delay(1000);
|
||||
if(uplinkWorks()) {
|
||||
Serial.println("Network is up");
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
digitalWrite(RELAY, HIGH);
|
||||
} else {
|
||||
Serial.println("Network is down");
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
digitalWrite(RELAY, LOW);
|
||||
}
|
||||
delay(1000); // TODO: cleaner interval between tests
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue