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

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

@ -1,10 +1,10 @@
/*
* 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
* below. Or just customize this script to talk to other HTTP servers.
*
*/
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
below. Or just customize this script to talk to other HTTP servers.
*/
#include <ESP8266WiFi.h>
#include <NTPClient.h>
@ -14,22 +14,22 @@ const char* password = "vovak26102003";
WiFiUDP ntpUDP;
const char* host = "api.openweathermap.org";
String line ;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600+7200, 60000);
int a=0;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600 + 7200, 60000);
int a = 0;
//****************************************************************************
void setup() {
// delay(1000);
Serial.begin(9600);
// delay(1000);
Serial.begin(9600);
delay(1000);
//pinMode(2, OUTPUT);//gpio2//motor
// digitalWrite(2, 1);
// digitalWrite(2, 1);
// We start by connecting to a WiFi network
// Serial.println();
// Serial.println();7
// Serial.println();
// Serial.println();7
Serial.print("Connecting to ");
Serial.println(ssid);
@ -38,168 +38,168 @@ void setup() {
while (WiFi.status() != WL_CONNECTED) {
delay(500);
a++;
if(a>10)
{a=0;
if (a > 10)
{ a = 0;
goto q;
}
// Serial.print(".");
// Serial.print(".");
}
// Serial.println("");
// Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP");
Serial.println(WiFi.localIP());
q:
//Serial.println();
delay(2000);
Serial.println(WiFi.localIP());
q:
//Serial.println();
delay(2000);
}
int value = 0;
int n=0;
int n = 0;
void loop() {
Serial.println("hi");
a=0;
n=0;
while (a<10)
{
delay(2000);
if (Serial.available()>0){
n = Serial.read()-48;
if (n==7)
{Serial.print(n);
Serial.println("+");
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("hi");
a = 0;
n = 0;
while (a < 10)
{
delay(2000);
if (Serial.available() > 0) {
n = Serial.read() - 48;
if (n == 7)
{ Serial.print(n);
Serial.println("+");
a = 11;
}
}
Serial.println();
Serial.print(line.length());
delay(5000);
if(line.length()<10)
{ if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a=0;
return;
a++;
}
// 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);
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();
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();
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);
delay(1000);
ESP.deepSleep(9000000);
}
@ -209,12 +209,12 @@ void con()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
a=0;
a = 0;
delay(500);
a++;
if(a>10)
{a=0;
return;
if (a > 10)
{ a = 0;
return;
}
}

Loading…
Cancel
Save