More functions
This commit is contained in:
parent
4229c44678
commit
65439922b1
@ -92,16 +92,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set static ip
|
//Set static ip
|
||||||
IPAddress staticIpAddress;
|
setStaticIp(ipAddress, "192.168.0.1", "255.255.255.0")
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
WiFi.hostname(hostName); //Set HostName
|
WiFi.hostname(hostName); //Set HostName
|
||||||
|
|
||||||
http.end(); //Close connection
|
http.end(); //Close connection
|
||||||
@ -113,12 +104,7 @@ void loop() {
|
|||||||
ESP.restart()
|
ESP.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sleepTime > 0) { //if deep sleepTime > 0 use deep sleep
|
sleep();
|
||||||
Serial.println("GOING TO SLEEP FOR " + String(sleepTime));
|
|
||||||
ESP.deepSleep((sleepTime * 60) * 1000000, RF_DEFAULT);
|
|
||||||
} else {
|
|
||||||
delay(5000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//checking if connection is working
|
//checking if connection is working
|
||||||
@ -138,3 +124,27 @@ bool checkConnection() {
|
|||||||
Serial.println("Timed out.");
|
Serial.println("Timed out.");
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user