More functions

This commit is contained in:
JonatanRek 2019-11-28 08:45:51 +01:00
parent 4229c44678
commit 65439922b1

View File

@ -92,16 +92,7 @@ void loop() {
}
//Set static ip
IPAddress staticIpAddress;
IPAddress subnetIpAddress(192,168,0,1);
IPAddress gatewayIpAddress(255, 255, 255, 0);
if (staticIpAddress.fromString(ipAddress)) {
WiFi.config(staticIpAddress, subnetIpAddress, gatewayIpAddress);
Serial.print("STATIC IP address:\t");
Serial.println(WiFi.localIP());
}
setStaticIp(ipAddress, "192.168.0.1", "255.255.255.0")
WiFi.hostname(hostName); //Set HostName
http.end(); //Close connection
@ -113,12 +104,7 @@ void loop() {
ESP.restart()
}
if (sleepTime > 0) { //if deep sleepTime > 0 use deep sleep
Serial.println("GOING TO SLEEP FOR " + String(sleepTime));
ESP.deepSleep((sleepTime * 60) * 1000000, RF_DEFAULT);
} else {
delay(5000);
}
sleep();
}
//checking if connection is working
@ -138,3 +124,27 @@ bool checkConnection() {
Serial.println("Timed out.");
return false;
}
void setStaticIp(String IpAddress, String subnet, String gateway){
//Set static ip
IPAddress staticIpAddress;
IPAddress subnetIpAddress;
IPAddress gatewayIpAddress;
if (
staticIpAddress.fromString(ipAddress) &&
subnetIpAddress.fromString(subnet) &&
gatewayIpAddress.fromString(gateway)
) {
WiFi.config(staticIpAddress, subnetIpAddress, gatewayIpAddress);
Serial.print("STATIC IP address:\t");
Serial.println(WiFi.localIP());
}
}
void sleep(int sleepTime) {
if (sleepTime > 0) { //if deep sleepTime > 0 use deep sleep
Serial.println("GOING TO SLEEP FOR " + String(sleepTime));
ESP.deepSleep((sleepTime * 60) * 1000000, RF_DEFAULT);
} else {
delay(5000);
}
}