Add files via upload
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
/********************** WiFi SSID Name and Password **************************/
|
||||
|
||||
String Host_name = "Vodafone-165DB9";
|
||||
String password = "8sWVvPY542";
|
||||
|
||||
void RESET();
|
||||
String Rain();
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial1.begin(9600);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
RESET();
|
||||
delay(1000);
|
||||
Serial.println(Rain());
|
||||
|
||||
}
|
||||
|
||||
void RESET()
|
||||
{
|
||||
//Disconnecting previous networks
|
||||
sendData("AT+RST\r\n", 2000, DEBUG);
|
||||
sendData("AT+CWQAP\r\n", 5000, DEBUG); // Disconnect WiFi if connected.
|
||||
|
||||
//Selecting Mode for WiFi
|
||||
sendData("AT+CWMODE=3\r\n", 1000, DEBUG); // configure as both access point and station mode.
|
||||
|
||||
//Searching for the wifi Connecrions.
|
||||
delay(3000);
|
||||
|
||||
sendData("AT+CWQAP\r\n", 4000, DEBUG); // again quit the connection if any.
|
||||
|
||||
String conn = "AT+CWJAP";
|
||||
char inv = '"';
|
||||
conn += "=";
|
||||
conn += inv;
|
||||
conn += Host_name; // Host name
|
||||
conn += inv;
|
||||
conn += ",";
|
||||
conn += inv;
|
||||
conn += password; // Password
|
||||
conn += inv;
|
||||
conn += "\r\n\r\n";
|
||||
sendData(conn, 7000, DEBUG); // Join the connection.( AT+CWJAP = "Host_name","password" )
|
||||
}
|
||||
|
||||
|
||||
String Rain()
|
||||
{
|
||||
char inv = '"';
|
||||
String add = "AT+CIPSTART";
|
||||
add += "=";
|
||||
add += inv;
|
||||
add += "TCP";
|
||||
add += inv;
|
||||
add += ",";
|
||||
add += inv;
|
||||
add += "api.thingspeak.com"; // Host_server_name
|
||||
add += inv;
|
||||
add += ",";
|
||||
add += "80";
|
||||
add += "\r\n";
|
||||
sendData(add, 3000, 0); // Establishing a TCP Connection. ( AT+CIPSTART = "TCP","Host_server_name",80 )
|
||||
|
||||
String rest = "AT+CIPSEND=90";
|
||||
rest += "\r\n";
|
||||
sendData(rest, 2000, 0); //Number of characters to send. ( "AT+CIPSEND=90" )
|
||||
|
||||
|
||||
String hostt = "GET /apps/thinghttp/send_request?api_key=XU89FNLMPBV4RI23";
|
||||
hostt += "\r\n";
|
||||
hostt += "Host:api.thingspeak.com";
|
||||
hostt += "\r\n\r\n\r\n\r\n\r\n";
|
||||
String Rain = sendData(hostt, 2000, 1); // GET request ( GET /apps/thinghttp/send_request?api_key=XXXXXXXXXXXXXXXX
|
||||
// Host: Host_server_name )
|
||||
return (Rain);
|
||||
}
|
||||
|
||||
String sendData(String command, const int Goldout, boolean debug)
|
||||
{
|
||||
String response = "";
|
||||
|
||||
Serial1.print(command); // send the read character to the Serial1
|
||||
|
||||
long int Gold = millis();
|
||||
|
||||
while ( (Gold + Goldout) > millis())
|
||||
{
|
||||
while (Serial1.available())
|
||||
{
|
||||
|
||||
// The esp has data so display its output to the serial window
|
||||
char c = Serial1.read(); // read the next character.
|
||||
response += c;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Serial.print(response);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#include <DS3231.h>
|
||||
|
||||
DS3231 rtc(SDA, SCL); // real time clock variable
|
||||
void rgLed(int redValue, int greenValue); // simple red and green led display funct
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
rtc.begin(); // rtc setup
|
||||
pinMode(5, OUTPUT); // red pin
|
||||
pinMode(6, OUTPUT); // green pin
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println(rtc.getTimeStr()); // show clock on monitor
|
||||
|
||||
Time t = rtc.getTime(); // gets struct from rtc
|
||||
int timewindow = t.hour; // gets hour from struct
|
||||
if (timewindow > 7 && timewindow < 14) {
|
||||
rgLed(150, 150);
|
||||
delay(1000);
|
||||
} else {
|
||||
rgLed(0, 0);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void rgLed(int redValue, int greenValue) {
|
||||
analogWrite(5, redValue);
|
||||
analogWrite(6, greenValue);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 286 KiB |
Binary file not shown.
Reference in New Issue
Block a user