Connect to WiFi and draft of uptime testing

Co-authored-by: x <xbr@c3l.lu>
This commit is contained in:
Thijs Raymakers 2024-06-20 00:56:07 +02:00
parent e2862bc220
commit e6c28f8ed9
No known key found for this signature in database
3 changed files with 46 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.pio
compile_commands.json
.vscode

View file

@ -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

View file

@ -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
}