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();
// 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,8 +14,8 @@ 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() {
@ -24,12 +24,12 @@ void setup() {
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,8 +38,8 @@ void setup() {
while (WiFi.status() != WL_CONNECTED) {
delay(500);
a++;
if(a>10)
{a=0;
if (a > 10)
{ a = 0;
goto q;
}
// Serial.print(".");
@ -49,46 +49,46 @@ void setup() {
Serial.println("WiFi connected");
Serial.println("IP");
Serial.println(WiFi.localIP());
q:
//Serial.println();
delay(2000);
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)
{
a = 0;
n = 0;
while (a < 10)
{
delay(2000);
if (Serial.available()>0){
n = Serial.read()-48;
if (Serial.available() > 0) {
n = Serial.read() - 48;
if (n==7)
{Serial.print(n);
if (n == 7)
{ Serial.print(n);
Serial.println("+");
a=11;
a = 11;
}
}
a++;
}
if(n>0)
{ a=0;
n=0;
while (a<10)
{delay(2000);
}
if (n > 0)
{ a = 0;
n = 0;
while (a < 10)
{ delay(2000);
a++;
if (Serial.available()>0){
n = Serial.read()-48;
if (Serial.available() > 0) {
n = Serial.read() - 48;
if (n==1)
if (n == 1)
{
Serial.print(n);
Serial.println("+");
@ -101,10 +101,10 @@ if(n>0)
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 +="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
@ -117,7 +117,7 @@ if(n>0)
// This will send the request to the server
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a=0;
a = 0;
return;
}
@ -131,17 +131,17 @@ if(n>0)
Serial.print( "host1");
Serial.println();
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
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)) {
if (line.length() < 10)
{ if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
a=0;
a = 0;
return;
}
// This will send the request to the server
@ -154,21 +154,21 @@ if(line.length()<10)
Serial.print( "host1");
Serial.println();
// 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');
Serial.print(line);
}
}
}
Serial.println();
Serial.println("closing connection");
delay(2000);
}
//******************************Time
if (n==2)
//******************************Time
if (n == 2)
{
Serial.print(n);
Serial.print(n);
Serial.println("+");
timeClient.update();
@ -177,29 +177,29 @@ Serial.print(n);
Serial.println(timeClient.getFormattedTime());
//Get a time structure
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
// Serial.print("Month day: ");
// Serial.println(monthDay);
// 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;
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(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,11 +209,11 @@ void con()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
a=0;
a = 0;
delay(500);
a++;
if(a>10)
{a=0;
if (a > 10)
{ a = 0;
return;
}
}

Loading…
Cancel
Save