65 行
1.0 KiB
C++
65 行
1.0 KiB
C++
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266HTTPClient.h>
|
|
#include <ESP8266Ping.h>
|
|
#include "credentials.h"
|
|
|
|
|
|
|
|
void wifi_connect (){
|
|
|
|
WiFi.begin(WLAN_ID, WLAN_PASSWORD);
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
while(WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(1000);
|
|
Serial.println("Connecting ...");
|
|
}
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setup (){
|
|
|
|
Serial.begin(115200);
|
|
wifi_connect();
|
|
}
|
|
|
|
void login (){
|
|
|
|
HTTPClient http;
|
|
|
|
http.begin("http://login.rz.ruhr-uni-bochum.de/cgi-bin/laklogin");
|
|
Serial.println("Attempt Login") ;
|
|
|
|
int httpCode = http.POST("code=1&loginid=" LOGIN_ID "&password=" LOGIN_PASSWORD "&action=Login");
|
|
|
|
|
|
http.end();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop (){
|
|
if(WiFi.status() != WL_CONNECTED){
|
|
wifi_connect();
|
|
}
|
|
IPAddress ip = (1, 1, 1, 1);
|
|
bool ret = Ping.ping(ip);
|
|
Serial.println(String("Connection state : ") + (ret ? "connected" : "not connected"));
|
|
if (ret == false){
|
|
Serial.println("Connection check failed");
|
|
login();
|
|
}
|
|
else Serial.println("Still connected");
|
|
delay(10000);
|
|
|
|
}
|