added wifi and time
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# 1 "/Users/nico/Documents/GitHub/blinds-controller/blinds-controller.ino"
|
||||
# 2 "/Users/nico/Documents/GitHub/blinds-controller/blinds-controller.ino" 2
|
||||
# 3 "/Users/nico/Documents/GitHub/blinds-controller/blinds-controller.ino" 2
|
||||
# 4 "/Users/nico/Documents/GitHub/blinds-controller/blinds-controller.ino" 2
|
||||
# 5 "/Users/nico/Documents/GitHub/blinds-controller/blinds-controller.ino" 2
|
||||
|
||||
const char ssid[] = "DasWifi";
|
||||
const char pass[] = "xsw2XSW@";
|
||||
WiFiClient wifiClient; // Used for the TCP socket connection
|
||||
|
||||
Servo blind;
|
||||
|
||||
@@ -15,7 +22,8 @@ void setup()
|
||||
|
||||
void openBlind()
|
||||
{
|
||||
for(position = 0; position <= 180; position += 1){
|
||||
for (position = 0; position <= 180; position += 1)
|
||||
{
|
||||
blind.write(position);
|
||||
delay(15);
|
||||
}
|
||||
@@ -24,8 +32,10 @@ void openBlind()
|
||||
SerialUSB.print("\n");
|
||||
}
|
||||
|
||||
void closeBlind(){
|
||||
for(position = 180; position >= 0; position -= 1){
|
||||
void closeBlind()
|
||||
{
|
||||
for (position = 180; position >= 0; position -= 1)
|
||||
{
|
||||
blind.write(position);
|
||||
delay(15);
|
||||
}
|
||||
@@ -36,14 +46,53 @@ void closeBlind(){
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
connectWiFi();
|
||||
}
|
||||
pdValue = analogRead(photoDiode);
|
||||
SerialUSB.println(String(pdValue/1024.0 * 100)+"%");
|
||||
SerialUSB.println(String(pdValue / 1024.0 * 100) + "%");
|
||||
delay(500);
|
||||
//if pdValue below 50% and inSchedule then open blind else close blind
|
||||
if(pdValue/1024.0 < 0.5){
|
||||
|
||||
SerialUSB.println("Now from TimeLib module: " + String(hour()) + ":" + String(minute()) + " " + String(day()) + "/" + String(month()) + "/" + String(year()));
|
||||
SerialUSB.println("Now from the WiFi module: " + String(getTime()));
|
||||
if(getTime() > 0){
|
||||
setTime(getTime());
|
||||
}
|
||||
// if pdValue below 50% and inSchedule then open blind else close blind
|
||||
if (pdValue / 1024.0 < 0.5)
|
||||
{
|
||||
openBlind();
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
closeBlind();
|
||||
}
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
unsigned long getTime()
|
||||
{
|
||||
// get the current time from the WiFi module
|
||||
return WiFi.getTime();
|
||||
}
|
||||
|
||||
void connectWiFi()
|
||||
{
|
||||
SerialUSB.print("Attempting to connect to SSID: ");
|
||||
SerialUSB.print(ssid);
|
||||
SerialUSB.print(" ");
|
||||
|
||||
while (WiFi.begin(ssid, pass) != WL_CONNECTED)
|
||||
{
|
||||
// failed, retry
|
||||
SerialUSB.print(".");
|
||||
delay(5000);
|
||||
}
|
||||
SerialUSB.println();
|
||||
|
||||
SerialUSB.println("You're connected to the network");
|
||||
getTime();
|
||||
//setTime(getTime());
|
||||
SerialUSB.println();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user