main
parent 56a320b922
commit 991a09d3b5
  1. 20
      play5/ntp.ino
  2. 338
      wifi/wifi.ino

@ -32,16 +32,16 @@ void ntp()
int ip4 = Serial1.parseInt(); int ip4 = Serial1.parseInt();
// Serial1.read(); // Serial1.read();
String data1 = "IP:" + String(ip1) + "." + String(ip2) + "." + String(ip3) + "." + String(ip4) + " "; // String data1 = "IP:" + String(ip1) + "." + String(ip2) + "." + String(ip3) + "." + String(ip4) + " ";
// String data1; String data1;
// data1 += ip1; data1 += ip1;
// data1 += "."; data1 += ".";
// data1 += ip2; data1 += ip2;
// data1 += "."; data1 += ".";
// data1 += ip3; data1 += ip3;
// data1 += "."; data1 += ".";
// data1 += ip4; data1 += ip4;
// data1 += " "; data1 += " ";
myGLCD.print(data1 , 240, 457); myGLCD.print(data1 , 240, 457);
} }
// myGLCD.print(String(c1) ,500, 457); // myGLCD.print(String(c1) ,500, 457);

@ -1,10 +1,10 @@
/* /*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service. This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers. below. Or just customize this script to talk to other HTTP servers.
*
*/ */
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <NTPClient.h> #include <NTPClient.h>
@ -14,194 +14,194 @@ const char* password = "vovak26102003";
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
const char* host = "api.openweathermap.org"; const char* host = "api.openweathermap.org";
String line ; String line ;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600+7200, 60000); NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600 + 7200, 60000);
int a=0; int a = 0;
//**************************************************************************** //****************************************************************************
void setup() { void setup() {
// delay(1000); // delay(1000);
Serial.begin(9600); Serial.begin(9600);
delay(1000); delay(1000);
//pinMode(2, OUTPUT);//gpio2//motor //pinMode(2, OUTPUT);//gpio2//motor
// digitalWrite(2, 1); // digitalWrite(2, 1);
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
// Serial.println();
// Serial.println();7 // Serial.println();
// Serial.println();7
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(500);
a++; a++;
if(a>10) if (a > 10)
{a=0; { a = 0;
goto q; goto q;
} }
// Serial.print("."); // Serial.print(".");
} }
// Serial.println(""); // Serial.println("");
Serial.println("WiFi connected"); Serial.println("WiFi connected");
Serial.println("IP"); Serial.println("IP");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
q: q:
//Serial.println(); //Serial.println();
delay(2000); delay(2000);
} }
int value = 0; int value = 0;
int n=0; int n = 0;
void loop() { void loop() {
Serial.println("hi"); Serial.println("hi");
a=0; a = 0;
n=0; n = 0;
while (a<10) while (a < 10)
{ {
delay(2000); delay(2000);
if (Serial.available()>0){ if (Serial.available() > 0) {
n = Serial.read()-48; n = Serial.read() - 48;
if (n==7) if (n == 7)
{Serial.print(n); { Serial.print(n);
Serial.println("+"); Serial.println("+");
a=11; a = 11;
} }
}
a++;
}
if(n>0)
{ a=0;
n=0;
while (a<10)
{delay(2000);
a++;
if (Serial.available()>0){
n = Serial.read()-48;
if (n==1)
{
Serial.print(n);
Serial.println("+");
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
// We now create a URI for the request
String url = "/data/2.5/forecast/daily?q=";
// url +="yevpatoriya&mode=xml&units=metric&cnt=7";
url +="Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=xml&cnt=7";
//http://api.openweathermap.org/data/2.5/forecast/daily?q=
// Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=metric&cnt=7
// url=data/2.5/forecast/daily?q=yevpatoriya&mode=xml&units=metric&cnt=7
// This will send the request to the server
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a=0;
return;
}
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.print("Requesting URL: ");
Serial.println(url);
delay(1000);
Serial.print( "host1");
Serial.println();
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
line = client.readStringUntil('\r');
Serial.print(line);
} }
Serial.println(); a++;
Serial.print(line.length());
delay(5000);
if(line.length()<10)
{ if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a=0;
return;
} }
// This will send the request to the server if (n > 0)
client.print(String("GET ") + url + " HTTP/1.1\r\n" + { a = 0;
"Host: " + host + "\r\n" + n = 0;
"Connection: close\r\n\r\n"); while (a < 10)
Serial.print("Requesting URL: "); { delay(2000);
Serial.println(url); a++;
delay(500); if (Serial.available() > 0) {
Serial.print( "host1"); n = Serial.read() - 48;
Serial.println();
// Read all the lines of the reply from server and print them to Serial if (n == 1)
while(client.available()){ {
String line = client.readStringUntil('\r'); Serial.print(n);
Serial.print(line); Serial.println("+");
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
// We now create a URI for the request
String url = "/data/2.5/forecast/daily?q=";
// url +="yevpatoriya&mode=xml&units=metric&cnt=7";
url += "Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=xml&cnt=7";
//http://api.openweathermap.org/data/2.5/forecast/daily?q=
// Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=metric&cnt=7
// url=data/2.5/forecast/daily?q=yevpatoriya&mode=xml&units=metric&cnt=7
// This will send the request to the server
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a = 0;
return;
}
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.print("Requesting URL: ");
Serial.println(url);
delay(1000);
Serial.print( "host1");
Serial.println();
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.print(line.length());
delay(5000);
if (line.length() < 10)
{ if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a = 0;
return;
}
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.print("Requesting URL: ");
Serial.println(url);
delay(500);
Serial.print( "host1");
Serial.println();
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
}
Serial.println();
Serial.println("closing connection");
delay(2000);
}
//******************************Time
if (n == 2)
{
Serial.print(n);
Serial.println("+");
timeClient.update();
time_t epochTime = timeClient.getEpochTime();
Serial.println(timeClient.getFormattedTime());
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
// Serial.print("Month day: ");
// Serial.println(monthDay);
int currentMonth = ptm->tm_mon + 1;
// Serial.print("Month: ");
// Serial.println(currentMonth);
int currentYear = ptm->tm_year + 1900;
//Serial.print("Year: ");
// Serial.println(currentYear);
String currentDate = String(monthDay) + "-" + String(currentMonth) + "-" + String(currentYear) ;
Serial.println(currentDate);
}
} //serial available
}
} }
} Serial.println("sleep");
delay(1000);
ESP.deepSleep(9000000);
Serial.println();
Serial.println("closing connection");
delay(2000);
}
//******************************Time
if (n==2)
{
Serial.print(n);
Serial.println("+");
timeClient.update();
time_t epochTime = timeClient.getEpochTime();
Serial.println(timeClient.getFormattedTime());
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
// Serial.print("Month day: ");
// Serial.println(monthDay);
int currentMonth = ptm->tm_mon+1;
// Serial.print("Month: ");
// Serial.println(currentMonth);
int currentYear = ptm->tm_year+1900;
//Serial.print("Year: ");
// Serial.println(currentYear);
String currentDate = String(monthDay) + "-" + String(currentMonth)+ "-" + String(currentYear) ;
Serial.println(currentDate);
}
} //serial available
}
}
Serial.println("sleep");
delay(1000);
ESP.deepSleep(9000000);
} }
@ -209,14 +209,14 @@ void con()
{ {
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
a=0; a = 0;
delay(500); delay(500);
a++; a++;
if(a>10) if (a > 10)
{a=0; { a = 0;
return; return;
} }
} }
} }

Loading…
Cancel
Save