main
parent 56a320b922
commit 991a09d3b5
  1. 20
      play5/ntp.ino
  2. 128
      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,8 +14,8 @@ 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() {
@ -24,12 +24,12 @@ void setup() {
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();
// Serial.println();7 // Serial.println();7
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
@ -38,8 +38,8 @@ void setup() {
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(".");
@ -49,46 +49,46 @@ void setup() {
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++; a++;
} }
if(n>0) if (n > 0)
{ a=0; { a = 0;
n=0; n = 0;
while (a<10) while (a < 10)
{delay(2000); { delay(2000);
a++; a++;
if (Serial.available()>0){ if (Serial.available() > 0) {
n = Serial.read()-48; n = Serial.read() - 48;
if (n==1) if (n == 1)
{ {
Serial.print(n); Serial.print(n);
Serial.println("+"); Serial.println("+");
@ -101,10 +101,10 @@ if(n>0)
const int httpPort = 80; const int httpPort = 80;
// We now create a URI for the request // We now create a URI for the request
String url = "/data/2.5/forecast/daily?q="; String url = "/data/2.5/forecast/daily?q=";
// url +="yevpatoriya&mode=xml&units=metric&cnt=7"; // url +="yevpatoriya&mode=xml&units=metric&cnt=7";
url +="Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=xml&cnt=7"; url += "Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=xml&cnt=7";
//http://api.openweathermap.org/data/2.5/forecast/daily?q= //http://api.openweathermap.org/data/2.5/forecast/daily?q=
// Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=metric&cnt=7 // Yevpatoriya,UA&APPID=a0b9f94d153cbcbfeb00ea5632db24ac&mode=metric&cnt=7
@ -117,7 +117,7 @@ if(n>0)
// This will send the request to the server // This will send the request to the server
if (!client.connect(host, httpPort)) { if (!client.connect(host, httpPort)) {
Serial.println("connection failed"); Serial.println("connection failed");
a=0; a = 0;
return; return;
} }
@ -131,17 +131,17 @@ if(n>0)
Serial.print( "host1"); Serial.print( "host1");
Serial.println(); Serial.println();
// Read all the lines of the reply from server and print them to Serial // Read all the lines of the reply from server and print them to Serial
while(client.available()){ while (client.available()) {
line = client.readStringUntil('\r'); line = client.readStringUntil('\r');
Serial.print(line); Serial.print(line);
} }
Serial.println(); Serial.println();
Serial.print(line.length()); Serial.print(line.length());
delay(5000); delay(5000);
if(line.length()<10) if (line.length() < 10)
{ if (!client.connect(host, httpPort)) { { if (!client.connect(host, httpPort)) {
Serial.println("connection failed"); Serial.println("connection failed");
a=0; a = 0;
return; return;
} }
// This will send the request to the server // This will send the request to the server
@ -154,21 +154,21 @@ if(line.length()<10)
Serial.print( "host1"); Serial.print( "host1");
Serial.println(); Serial.println();
// Read all the lines of the reply from server and print them to Serial // Read all the lines of the reply from server and print them to Serial
while(client.available()){ while (client.available()) {
String line = client.readStringUntil('\r'); String line = client.readStringUntil('\r');
Serial.print(line); Serial.print(line);
} }
} }
Serial.println(); Serial.println();
Serial.println("closing connection"); Serial.println("closing connection");
delay(2000); delay(2000);
} }
//******************************Time //******************************Time
if (n==2) if (n == 2)
{ {
Serial.print(n); Serial.print(n);
Serial.println("+"); Serial.println("+");
timeClient.update(); timeClient.update();
@ -177,29 +177,29 @@ Serial.print(n);
Serial.println(timeClient.getFormattedTime()); Serial.println(timeClient.getFormattedTime());
//Get a time structure //Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime); struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday; int monthDay = ptm->tm_mday;
// Serial.print("Month day: "); // Serial.print("Month day: ");
// Serial.println(monthDay); // Serial.println(monthDay);
int currentMonth = ptm->tm_mon+1; int currentMonth = ptm->tm_mon + 1;
// Serial.print("Month: "); // Serial.print("Month: ");
// Serial.println(currentMonth); // Serial.println(currentMonth);
int currentYear = ptm->tm_year+1900; int currentYear = ptm->tm_year + 1900;
//Serial.print("Year: "); //Serial.print("Year: ");
// Serial.println(currentYear); // Serial.println(currentYear);
String currentDate = String(monthDay) + "-" + String(currentMonth)+ "-" + String(currentYear) ; String currentDate = String(monthDay) + "-" + String(currentMonth) + "-" + String(currentYear) ;
Serial.println(currentDate); Serial.println(currentDate);
} }
} //serial available } //serial available
} }
} }
Serial.println("sleep"); Serial.println("sleep");
delay(1000); delay(1000);
ESP.deepSleep(9000000); ESP.deepSleep(9000000);
} }
@ -209,11 +209,11 @@ 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