You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
296 lines
6.9 KiB
296 lines
6.9 KiB
void internet()
|
|
{ //Serial2.setTimeout(5000);
|
|
char* name;
|
|
char* name1;
|
|
boolean bad = 0;
|
|
int i;
|
|
char c7 ;
|
|
char c8 ;
|
|
// esp8266();
|
|
//doo:
|
|
while(Serial2.available()) {
|
|
|
|
c8=Serial2.read();
|
|
//c7=Serial2.peek();
|
|
// Serial.print(String(c8));
|
|
delay(2);
|
|
|
|
}
|
|
myGLCD.setColor(VGA_WHITE);
|
|
myGLCD.setBackColor(0, 172, 238);
|
|
myGLCD.setFont(BigFont);
|
|
// myGLCD.fillScr(VGA_BLUE);
|
|
|
|
digitalWrite(18, LOW);
|
|
delay(3000);
|
|
digitalWrite(18, HIGH);//reset WIFI
|
|
myGLCD.print(" openweather " , 280, 457);
|
|
delay(3000);
|
|
// myGLCD.print(" connecting " , 280, 457);
|
|
//***************************
|
|
while(Serial2.available()) {
|
|
if (Serial2.find("hi"))
|
|
{
|
|
myGLCD.print("WiFi connected" ,280, 457);
|
|
}
|
|
}
|
|
//**************************************
|
|
Serial2.print("7");//проверка подключения к точке доступа если ответ больше 0 то подключились
|
|
delay(1000);
|
|
//myGLCD.print(" read server " ,280, 457);
|
|
//***************************
|
|
i=0;
|
|
while (i<900)
|
|
{
|
|
i++;
|
|
if(Serial2.available()) {
|
|
if (Serial2.find("IP"))
|
|
{Serial2.read();
|
|
// myGLCD.print(" NTP " ,280, 457);
|
|
int ip1 = Serial2.parseInt();
|
|
|
|
int ip2 = Serial2.parseInt();
|
|
|
|
int ip3 = Serial2.parseInt();
|
|
|
|
int ip4 = Serial2.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 += " "
|
|
myGLCD.print(data1 , 240, 457);
|
|
i=901;
|
|
}
|
|
// myGLCD.print("available" , 240, 457);
|
|
|
|
// myGLCD.print(String(c2) ,520, 457);
|
|
|
|
}
|
|
|
|
|
|
if(i>0)delay (10);
|
|
}
|
|
//**************************************
|
|
Serial2.print("1");//проверка подключения к точке доступа если ответ больше 0 то подключились
|
|
delay(1000);
|
|
//***************************
|
|
myGLCD.print(" read server " , 240, 457);
|
|
i = 0;
|
|
//while (i<900)
|
|
// {
|
|
// i++;
|
|
// if(Serial2.available()) {
|
|
// i=0;
|
|
// if (Serial2.find("1+"))
|
|
// {myGLCD.print(" read server " ,280, 457);
|
|
// i=1000;
|
|
// }
|
|
|
|
// }
|
|
// if(i>0)delay (10);
|
|
// }
|
|
//**************************************
|
|
//****************************SD**********************
|
|
sd.chdir("/");
|
|
delay (100);
|
|
|
|
sd.chdir("progn");
|
|
delay (100);
|
|
if (sd.exists("prognoz.txt"))
|
|
{ name = "prognoz1.txt";
|
|
name1 = "prognoz.txt";
|
|
}//установка раб директории
|
|
else
|
|
{ name = "prognoz.txt";
|
|
name1 = "prognoz1.txt";
|
|
}
|
|
|
|
// myFile.remove();
|
|
delay (50);
|
|
myFile.open(name, O_RDWR | O_CREAT | O_AT_END);
|
|
delay (50);
|
|
|
|
//******************************************************
|
|
|
|
i = 0; //счетчик времени
|
|
int n = 1; // счетчик символов
|
|
int st = 0;
|
|
char c ;
|
|
//Serial2.setTimeout(2000);
|
|
i = 0;
|
|
myGLCD.print(" read inform " , 280, 457);
|
|
while (i < 600) {
|
|
if (Serial2.available()) {
|
|
|
|
c = Serial2.read();
|
|
|
|
myFile.print(c);
|
|
|
|
i = 0;
|
|
}//gotov
|
|
if (i > 0)delay (10);
|
|
i++;
|
|
|
|
|
|
}//while
|
|
|
|
delay (500);
|
|
// myGLCD.print(" read inform 2 " , 280, 457);
|
|
i = 0;
|
|
while (i < 600) {
|
|
if (Serial2.available()) {
|
|
|
|
c = Serial2.read();
|
|
|
|
myFile.print(c);
|
|
|
|
i = 0;
|
|
}//gotov
|
|
if (i > 0)delay (10);
|
|
i++;
|
|
|
|
}//while
|
|
|
|
|
|
|
|
|
|
myGLCD.print(" ", 118, 457);
|
|
myGLCD.print(" end read inform " , 280, 457);
|
|
int cardSize = myFile.fileSize();
|
|
//myGLCD.printNumI(st ,150, 230);
|
|
// myGLCD.printNumI(i ,180, 230);
|
|
myFile.close();
|
|
delay (1000);
|
|
myGLCD.print(" ", 118, 457);
|
|
myGLCD.print(" verifying " , 280, 457);
|
|
delay (1000);
|
|
myGLCD.print(" ", 118, 457);
|
|
myGLCD.print("file size=" , 280, 457);
|
|
myGLCD.printNumI(cardSize, 280 + 160, 457);
|
|
//************proverka file **********************************************
|
|
|
|
sd.chdir("/");//установка раб директории
|
|
delay (1000);
|
|
sd.chdir("progn");
|
|
delay (100);
|
|
myFile.open(name, O_READ);
|
|
char symbol;
|
|
i = 0;
|
|
char token[] = "weatherdata";
|
|
n = 1;
|
|
while ( n < 8000) //размер считанного с сайта файла проверяем на наличае в конце </weatherdata>
|
|
{ symbol = myFile.read();
|
|
if (n > 1000)
|
|
{ if (symbol == token[i])
|
|
{ i = i + 1;
|
|
}
|
|
else
|
|
{
|
|
i = 0;
|
|
}
|
|
}
|
|
if (i > 9) {
|
|
break;
|
|
}
|
|
n = n + 1;
|
|
}
|
|
if (cardSize > 5000) //измерение размера файла если размер больше то считали все
|
|
{ if (i > 9) { // если есть в конце </weatherdata>
|
|
wifi = 0;
|
|
myGLCD.print(" good file W= " , 280, 457);
|
|
myGLCD.printNumI(i, 280 + 256, 457);
|
|
wifih = t.hour; // час обновления данных
|
|
wifim = t.min; // минуты
|
|
}
|
|
else// // если нет в конце </weatherdata> то error
|
|
{ myGLCD.print(" bad file W= " , 280, 457);
|
|
myGLCD.printNumI(i, 280 + 256, 457);
|
|
wifi = 9;
|
|
bad = 1;
|
|
}
|
|
|
|
}
|
|
else//размер меньше то считали не все error
|
|
{ myGLCD.print(" bad file " , 280, 457);
|
|
wifi = 9;
|
|
bad = 1;
|
|
}
|
|
myFile.close();
|
|
delay (1000);
|
|
sd.chdir("/");//установка раб директории
|
|
delay (1000);
|
|
sd.chdir("progn");
|
|
delay (100);
|
|
if (bad == 1)
|
|
{ if (sd.exists("Err.txt"))
|
|
{ myFile.open("Err.txt", O_RDWR | O_CREAT | O_AT_END);
|
|
delay (100);
|
|
myFile.remove();
|
|
}
|
|
delay (100);
|
|
sd.rename(name, "Err.txt");
|
|
delay (100);
|
|
|
|
}
|
|
else {
|
|
myFile.open(name1, O_RDWR | O_CREAT | O_AT_END);
|
|
delay (100);
|
|
myFile.remove();
|
|
}
|
|
|
|
|
|
sd.chdir("/");
|
|
delay (2000);
|
|
// myGLCD.print(" end read inform " ,260, 460);
|
|
myGLCD.print(" ", 250, 457);
|
|
clc();
|
|
digitalWrite(65, LOW);
|
|
/* return;
|
|
|
|
|
|
|
|
|
|
|
|
//****Для отладки***************************
|
|
|
|
|
|
|
|
while(1)
|
|
{
|
|
if (myTouch.dataAvailable())
|
|
|
|
{
|
|
myTouch.read();
|
|
int x=myTouch.getX();
|
|
int y=myTouch.getY();
|
|
|
|
if ((x>=0) && (x<=799)) // Upper row
|
|
{
|
|
|
|
if ((y>=10) && (y<=479)) // яркость
|
|
{
|
|
menu();
|
|
}
|
|
}
|
|
}//touch
|
|
sec=rtc_clock.get_seconds();
|
|
if (sec==0)
|
|
{
|
|
delay(800);
|
|
clc();
|
|
}
|
|
|
|
}//while
|
|
// dbgSerial.println(json);
|
|
//***********************************************************************************
|
|
*/
|
|
}
|
|
//***********************************************
|
|
|