
-
UID:2821603
-
- 注册时间2017-12-27
- 最后登录2025-09-26
- 在线时间141小时
-
-
访问TA的空间加好友用道具
|
, , , 模块直连上网获取网络时间,并且数码管显示,加网页显示,手机可WEB重置WIFI,也可以按键呼出快连程序,扫描二维码即可连接WIFI , , 程序 - #include <Arduino.h>
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <FS.h>
- #include <ESP8266WiFiMulti.h>
- #include <ESP8266HTTPClient.h>
- #include <string.h>
- #include <ESP8266mDNS.h>
- #include <WiFiUdp.h>
- ESP8266WebServer server(80);
- //=========== 按键及输出IO定义 =====================
- //TM1620模块引脚定义
- #define DIO 15
- #define CLK 4
- #define STB 5 //这里定义了那三个脚
- #define KEY1 0 //GPIO 0
- #define LED 2 //esp模块板载LED蓝色
- #define bi 12 //
- //==========================================
- int CWD=0;
- unsigned long new_time;
- //=========== 全局数据,定义 ========
- int nowificici=0;
- int SJ_NIAN , SJ_YUE , SJ_RI , SJ_XQ ;
-
-
- int KEY_TIME=0;
-
-
-
- bool duan_flag=0;
- // #define new_time 40 //===== 每50S更新一次网络时间,
- #define dao_time 10 //===== 倒计时 时间,
- #define newgp_time 5 //===== 股票更新时间 S
- const char* wifi_gp_data = "/wifi_gp_data.txt";
-
-
-
- int GP_DAT; // 股票100%比 股票 正 负
- unsigned char ZFU;
- unsigned char GP_ZFU; // 股票 正 负
-
-
- String gpmingzi = "未更新";
-
-
-
-
- unsigned int ksj=0;
- unsigned char onkey=1;
-
-
- unsigned char LED_SMG[] = {0,0,0,0 };
-
- bool SPIFFSOK=0; // 无 FLASH 内存标志
- unsigned char wh;
-
- int k;
- int m;
- int dpp;
- unsigned char ledd;
- unsigned char autoo=0x80;
- const byte tab[] = {0x5F, 0x06, 0x3B, 0x2F, 0x66, 0x6D, 0x7D, 0x47,
- 0x7F, 0x6F
- };// 0-9 共阴数码管
- //---- WEB时间需要的数据 ------
- unsigned char HHH=0;
- unsigned char MMM=0;
- unsigned char SSS=0;
- int S1=0;
- int M1=0;
- unsigned char liangdu=141;
- unsigned char HTTP_KOFF=1;
- int diann;
- int m1;
- int m10;
- int h1;
- int h10;
- int bibi;
- unsigned char dsb =0x80;
- unsigned char sjh;
- unsigned char sjm;
- unsigned char sjs;
- unsigned long sj0=0;
- // int k;
- //int m;
- //int dpp;
- //unsigned char ledd;
- //unsigned char autoo;
- #define APIKEY "60a806f68cc9bffe" //设置apikey 60a806f68cc9bffe
- //------时间 数据 NED ------
- const char* ssid = "";
- const char* password = "";
- // 北京时间网站 http://time.beijing-time.org/time.asp 直接浏览器打开输出时间信息,
- //这粒模拟了浏览器,抓取需要的数据,
- const char* host = "time.beijing-time.org"; // 获取 HTTP网站,的IP地址用
- String url = "/time.asp"; // 获取 HTTP网站主页下的连接
-
-
-
-
- //===========================
-
-
- // 股票网站 http://hq.sinajs.cn/list=sh601360
- const char* host2 = "hq.sinajs.cn"; // 获取 HTTP网站,的IP地址用
- String url2 = "/list=sz300104"; // 获取 HTTP网站主页下的连接
-
- //===========================
- //-----------------
- const char* hostt = "led4"; // esp8266,local/
-
- String ssid2 = "";
- String pass2 = "";
- String nofwifi ="未连接";
-
- int kofff=0;
-
- int bih1;
- void(* resetFunc) (void) = 0; // 需要复位时这样调用: resetFunc();
- int KEY_NUM = 0; //按键键值存放变量,不等于1说明有按键按下
- int KEYSJ;
- int g = 0;
- int ke = 1;
- //==========================================
- //函数声明
- void init_TM1620(void);
- void TM1620_Write( unsigned char DATA);
- void Write_COM(unsigned char cmd);
- void SPIFFS_666(void); //==FS文件夹系统,小程序
- //================================
- //================================
- //======= 小程序 ===================
- /** IP to String? */
- String toStringIp(IPAddress ip) {
- String res = "";
- for (int i = 0; i < 3; i++) {
- res += String((ip >> (8 * i)) & 0xFF) + ".";
- }
- res += String(((ip >> 8 * 3)) & 0xFF);
- return res;
- }
- //=============================================================
- bool autoConfig() //自动连接WIFI程序, ===用上一次的WIFI密码连接
- {
- WiFi.begin(); //======注入WIFI
- for (int i = 9; i >0; i--) // 超时 2S X 5 = 10S
- {
- if ( WiFi.status() == WL_CONNECTED) // 如果相等 说明连接成功 == 就退出
- {
- Serial.println("===================");
- WiFi.printDiag(Serial);
- Serial.println("===================");
-
- digitalWrite(LED, 1); // LED
-
- autoo = 0x80;
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc8); //位5 === 4
- TM1620_Write( autoo | 0x40 ); //段码
- digitalWrite(STB, HIGH);
-
-
-
-
- delay(100);
- Serial.println("==== wifi AUTO ok =====");
-
- Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str());
- Serial.printf("PSW:%s\r\n", WiFi.psk().c_str());
-
- Serial.print("WIFI IP = : ");
- Serial.println(WiFi.localIP());
-
- WiFi.setAutoConnect(true); // 设置自动连接===================================
- return true; //连接成功了跳过循环,退出连接程序
- break;
- }
- else // 连接不成功 == 一直等待连接
- {
-
- Serial.println("==== wifi NO =====");
- digitalWrite(LED, 0); // LED
-
-
- autoo = 0x00;
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc8); //位5 === 4
- TM1620_Write( autoo | 0x40 ); //段码
- digitalWrite(STB, HIGH);
-
- delay(500);
-
-
-
-
- autoo = 0x80;
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc8); //位5 === 4
- TM1620_Write( autoo | 0x40 ); //段码
- digitalWrite(STB, HIGH);
-
-
- delay(500);
-
-
-
-
-
- }
- }
- digitalWrite(2, 0);
- Serial.println("== wifi MIMA NO NO ===");
- Serial.println("==== wifi smartConfig OPEN 99S -- =====");
- return false;
- }
- void smartConfig() //快连程序
- {
- delay(10);
- WiFi.mode(WIFI_STA);
-
- WiFi.beginSmartConfig();
-
- delay(10);
- int i=99;
- while (i>0) // 99S超时
- {
-
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xC8); // 位1 === 1
- TM1620_Write( autoo | 0x3E ); // 段码 W
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xC6); // 位2 === 2
- TM1620_Write( 0x71 ); // 段码 F
- digitalWrite(STB, HIGH);
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xC2); //位3 === dian
- TM1620_Write( tab[i/10%10] ); //段码 ledd
- digitalWrite(STB, HIGH);
- digitalWrite(STB, LOW);
- TM1620_Write(0xC0); //位4 === 3
- TM1620_Write( tab[i%10] ); //段码
- digitalWrite(STB, HIGH);
-
-
-
-
-
-
-
-
-
-
-
-
-
- Serial.print("==== wifi smartConfig SOS SOS ");
- Serial.print(i);
- Serial.println(" S ======= ");
-
- digitalWrite(2,0);
- delay(500);
-
-
- if (WiFi.smartConfigDone())
- {
- Serial.println("=== SmartConfig OK =========================");
-
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc0); // 位1 === 1
- TM1620_Write( 0x76 ); // 段码 H
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc2); // 位2 === 2
- TM1620_Write( 0x76 ); // 段码 H
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc4); //位3 === dian
- TM1620_Write( 0xFF ); //段码 ledd
- digitalWrite(STB, HIGH);
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc6); //位4 === 3
- TM1620_Write( 0x76 ); //段码 H
- digitalWrite(STB, HIGH);
- digitalWrite(STB, LOW);
- TM1620_Write(0xc8); //位5 === 4
- TM1620_Write( autoo | 0x76 ); //段码 H
- digitalWrite(STB, HIGH);
-
-
-
-
-
-
-
-
-
-
-
-
-
- Serial.printf("==========SSID:%s\r\n", WiFi.SSID().c_str());
- Serial.printf("==========PSW:%s\r\n", WiFi.psk().c_str());
-
- WiFi.mode(WIFI_AP_STA );
-
- Serial.println("======= WiFi.mode 显示模式,信道,密码 ======");
- WiFi.printDiag(Serial);
- Serial.println("===================");
-
- WiFi.setAutoConnect(true); // 设置自动连接
- break;
- }
-
-
-
-
- i--;
- digitalWrite(2,1);
- delay(500); // 这个地方一定要加延时,否则极易崩溃重启
-
-
-
- // WiFi.beginSmartConfig();
- }
- Serial.println("==== wifi NO NO smartConfig 30S END =====");
- }
- //=============================================================
- //=============== WEB网页送显 =================================
- void handleRootGet() {
-
- String gpsz ="/list=sz"; //深圳及创业板
- String gpsh ="/list=sh"; //上证
- String web_ssid = server.arg("web_ssid"); // 取回Post数据
- String web_pass = server.arg("web_pass"); // 取回Post数据
- String web_GP_DATA = server.arg("web_GP_DATA"); // 取回Post数据
- if( web_GP_DATA.length() ==6 ) // 取回Post数据==6位 = 股票的数字
- {
- if( (web_GP_DATA.toInt() /100000%10 )==0) url2 = gpsz + web_GP_DATA;
- if( (web_GP_DATA.toInt() /100000%10 )==3) url2 = gpsz + web_GP_DATA;
- if( (web_GP_DATA.toInt() /100000%10 )==6) url2 = gpsh + web_GP_DATA; //判断是上证
-
- if( SPIFFSOK==1) // 有FLASH 内存标志
- {
- File x = SPIFFS.open(wifi_gp_data, "w"); // 打开SPIFFS文件系统内指定的文件
- x.println(url2); // 写入文件,
- x.close(); // 上锁 SPIFFS
- }
-
- }
- if( web_ssid.length() >=4 ) // 取回Post数据 = WIFI,AP名字大于2位数,
- {
- WiFi.begin(web_ssid.c_str(), web_pass.c_str()); //重新注入WIFI,修改WIFI
-
- }
- //====== WEB HTTP 网页输出 代码 =============
- String html = "";
- html += "<head> ";
- html += "<meta name='viewport' content='width=device-width,initial-scale=1' charset='utf-8' /> ";
- html += "<title>ESP8266_LED4设置页面</title> ";
- html += "</head>";
- html += "<body align='center' style='background-color:#d3d388'>";
- html += "<h2>设置</h2>";
-
-
- html +=" <p style='color:#ff04fe'>";
- html +="联网状态=: ";
- html +=String() + nofwifi +"<br>";
-
-
- // Serial.println(WiFi.localIP()); //获取本地IP
-
-
- html += String() + toStringIp(WiFi.localIP()) + "<br>";
-
-
-
- html +="<br>";
-
- html +="北京时间: ";
-
- html += String()+ SJ_NIAN ;
- html +="年";
-
-
- html += String()+ SJ_YUE ;
- html +="月";
- html += String()+ SJ_RI ;
- html +="日";
- html +="/星期";
- html += String()+ SJ_XQ ;
-
- html += "<br>";
-
- html += String()+ HHH ;
- html +="点";
- html +="/";
- html += String()+ MMM ;
- html +="分";
- html +="/--";
- html += String()+ SSS ;
- html +="秒";
-
-
- html += "<br>";
-
-
-
-
-
- html +="</p>";
-
-
- html +=" <p>重新连接WIFI网络..</p>";
- html += "<form method='post' action='wifisave' >";
- html += " <p>WIFI名称<input type='text' name='web_ssid' placeholder='ssid'></p>";
- html += " <p>WIFI密码<input type='text' name='web_pass' placeholder='pass'></p>";
- html += " <input type='submit' value='保存'>";
- html += "</form>";
- /***
- html +="<h1>输入股票代码<br>";
- html += "<form method='post' action='wifisave'>";
- html += "<input type='text' maxlength='6' name='web_GP_DATA'><input type='submit' value='确定' />";
- html += "</form>";
- html +="</h1>";
-
- html +=" <p>六位股票数字<br></p>";
- html +="<br>";
-
-
- ****/
-
- html +="<br>";
- html +=" <a href='/'target='_top'>刷新主页</a> ";
-
- html +=" <p>输入正确的WIFI密码,保存后</p>";
- html +=" <p>重启终端,即可更新使用</p>";
-
-
-
-
- html +=" <p>BY:WANGYU-TEL:15858013830</p>";
- html +="</body>";
- server.send(200, "text/html", html);
-
- }
- //======================================
-
-
-
- void TM1620_Write( unsigned char DATA) //写数据函数
- {
- unsigned char i;
-
-
-
- for (i = 0; i < 8; i++)
- {
- digitalWrite(CLK, LOW);
- if(DATA & 0X01)
- {
- digitalWrite(DIO, HIGH);
- }
- else
- {
- digitalWrite(DIO, LOW);
- }
- digitalWrite(CLK, HIGH);
- DATA>>=1;
- }
- }
- void Write_COM(unsigned char cmd) //发送命令字
- {
- digitalWrite(STB, LOW);
- TM1620_Write(cmd);
- digitalWrite(STB, HIGH);
- }
- //TM1620初始化函数
- void init_TM1620(void)
- {
-
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0x02);
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0x44);
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(liangdu); // 亮度 (0x88-0x8f)8级亮度可调 137-143
- digitalWrite(STB, HIGH);
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xC0); // 位1 === 1
- TM1620_Write( 0x20); // 段码
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc2); // 位2 === 2
- TM1620_Write( 0x20 ); // 段码
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc4); //位3 === dian
- TM1620_Write( 0xFF ); //段码 ledd
- digitalWrite(STB, HIGH);
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc6); //位4 === 3
- TM1620_Write( 0x20 ); //段码
- digitalWrite(STB, HIGH);
- digitalWrite(STB, LOW);
- TM1620_Write(0xc8); //位5 === 4
- TM1620_Write( autoo | 0x20 ); //段码
- digitalWrite(STB, HIGH);
-
- }
- //================================
- //================================
- //===== setup() //初始化 =====
- //================================
- //================================
- void setup() //初始化函数
- {
- pinMode( bi, OUTPUT);
-
- pinMode(LED, OUTPUT);
-
- pinMode(5,INPUT_PULLUP); //定义GPIO 5 为带上拉输入引脚
-
- // pinMode(3,INPUT_PULLUP); //定义GPIO 3为带上拉输入引脚
- digitalWrite(LED, 0);
-
-
- delay(100);
- digitalWrite(bi, 0);
- unsigned long koff=100000;
- while(koff>1) //RXD没有低电平后延时0.3S退出
- {
- if(digitalRead(5) == 0) //串口有低电平信号,
- koff=100000;
- delayMicroseconds(7); //9us
- koff--;
- }
- digitalWrite(LED, 1);
-
-
-
-
-
-
-
-
-
-
-
-
- delay(100); //
- Serial.begin(115200);
- delay(100); //
- Serial.println("");
- Serial.println("");
-
- Serial.println("==== ESP8266 OK =====");
- SPIFFS.begin();
-
-
-
- pinMode(KEY1,INPUT_PULLUP); //定义KEY1为带上拉输入引脚
-
-
- pinMode(LED, OUTPUT);
-
-
- pinMode(STB, OUTPUT);
- pinMode(CLK, OUTPUT);
- pinMode(DIO, OUTPUT); //让三个脚都是输出状态
-
-
-
- digitalWrite(LED, 0);
-
-
- digitalWrite(CLK, HIGH);
- digitalWrite(STB, HIGH);
- digitalWrite(DIO, HIGH);
-
- init_TM1620(); //初始化TM1638
-
- digitalWrite(bi, 0);
- delay(10);
- //================
-
- // WiFi.mode(WIFI_STA);
- WiFi.mode(WIFI_AP_STA ); // 必须采用 AP 与 Station 兼容模式
- delay(100); // 等待配网
-
- WiFi.begin(); //======注入WIFI
-
- delay(100);
-
-
- // autoConfig();
-
- WiFi.setAutoConnect(true); // 设置自动连接
- // if ( !autoConfig() ) //如自动连接不成功超时20次,就进入手动配网
- // {
-
- // smartConfig(); //手动快连程序
- // }
-
- delay(10);
- // WiFi.mode(WIFI_AP_STA ); // 必须采用 AP 与 Station 兼容模式
- delay(10);
- Serial.println("======= WiFi.mode ALL=: ");
- WiFi.printDiag(Serial);
- Serial.println("===================");
- delay(1000);
-
- // ===============设置内网ap
- // ===============设置内网ap
- IPAddress softLocal(192,168,4,1); // DNS
- IPAddress softGateway(192,168,4,2); //AP
- IPAddress softSubnet(255,255,255,0);
- WiFi.softAPConfig(softLocal, softLocal, softSubnet);
- //String apName = ("AP168_4_1_"+(String)ESP.getChipId()); // 2 设置WIFI名称
- String apName = "LED4_192_168_4_1";
- const char *softAPName = apName.c_str();
- WiFi.softAP(softAPName); // 3创建wifi 名称 +密码 adminadmin
- IPAddress myIP = WiFi.softAPIP(); // 4输出创建的WIFI IP地址
-
-
-
-
-
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.println("=== wifi no no ===========");
- }
- Serial.println("=== wifi ok ok ===========");
- Serial.println("IP address: "); //打印下行
- Serial.println(WiFi.localIP()); //获取本地IP
-
-
- Serial.print("== WIFI IP =: ");
- Serial.println(WiFi.localIP());
-
- IPAddress ip = WiFi.localIP();
-
- if (!MDNS.begin(hostt, myIP)) {
- Serial.println("Error setting up MDNS responder!");
- while(1) {
- delay(1000);
-
- }
- }
- Serial.println("mDNS responder started");
-
-
- Serial.println("");
- Serial.print("Connected! IP address: ");
- Serial.println(WiFi.localIP());
- MDNS.begin(hostt);
-
- delay(500);
-
-
- server.on("/", HTTP_GET, handleRootGet);
- server.on("/wifisave", HTTP_POST, handleRootGet);
-
-
- server.begin();
-
-
- MDNS.setInstanceName("Cubie's ESP8266");
- MDNS.addService("http", "tcp", 80);
-
-
-
-
- // WiFi.begin(ssid, password);
- Serial.println();
- Serial.println(" ============ SPIFFS_666 ================== ");
-
-
- delay(500);
-
-
-
- SPIFFS_666();
-
-
-
-
- digitalWrite(LED, 1);
- delay(500);
- //= =============
- dpp= 0x80;
-
- m= 1;
- k=0;
-
- HTTP_KOFF=1;
- autoo=0x80; //auto字符
-
- digitalWrite(bi, 0);
- S1=0;
-
- HHH=23;
- MMM=58;
- SSS=55;
-
- new_time=10;
-
- }
- //================================
- //================================
- //===== loop() //主函数 =====
- //================================
- //================================
- void loop() //主函数
- {
-
- // ==== 路由器连接状态判断
- if (WiFi.status() == WL_CONNECTED ) nofwifi ="连接OK";
-
- else nofwifi ="未连接";
-
-
-
- server.handleClient();
-
-
-
-
-
-
-
-
-
-
- if(digitalRead(KEY1) == LOW) //有按键按下
- {
- delay(1);
- KEY_TIME++;
- digitalWrite(LED, 0);
- if( KEY_TIME <5000 ) duan_flag=1;
-
-
- if( KEY_TIME >5000 )
- {
- digitalWrite(LED,1);
- duan_flag=0;
- smartConfig(); //快连程序
- digitalWrite(LED, 1);
- }
-
-
- }
-
- else
- {
- KEY_TIME=0;
- if( duan_flag==1)
- {
- digitalWrite(LED, 1);
- new_time=0;
- duan_flag=0;
- digitalWrite(LED, 1);
- }
-
- }
-
-
- // while(digitalRead(KEY1) == LOW)
-
- // digitalWrite(LED, 1);
-
-
-
-
-
-
-
- unsigned long sj1=millis(); // 取得当前时间数
- if( sj1 - sj0 > 400) ledd=0x00; //双点
- if( sj1 - sj0 > 1000) // 1s 当前时间数大于前一个时间1S间隔
- {
- sj0 = sj1;
- ledd=0x06; //双点
- S1++;
-
- if(S1==1) digitalWrite(bi, 0);
-
-
- if(S1>= new_time ) //===== 每10S更新一次
- {
- S1=0;
-
- digitalWrite(LED, 1);
-
- Serial.println("======= GET OPEN ===========");
-
- // digitalWrite(bi, 1);
-
-
-
-
-
- int code_now = getWeatherCode();
-
- if (code_now == -1)
- {
- nowificici++;
-
- Serial.print("==== nowificici =; ");
- Serial.println(nowificici);
-
-
-
- if(nowificici>=50)
- {
-
- Serial.println("========== NO WIFI 50CI ==========");
-
-
- new_time = 8280 ; // 23 h
-
- nowificici=0;
- HTTP_KOFF=0;
-
- S1=0;
- }
- delay(10);
-
- }
-
- else // OK WIFI
-
- {
- HHH = sjh;
- MMM = sjm;
- SSS = sjs;
-
- new_time = 3000 ; // 50 M
- S1=0;
-
- }
-
-
-
-
-
-
-
-
-
- // getWeatherCode99();
- // getWeatherCodepm25();
-
-
-
- // getWeatherCode99();
- // getWeatherCode9922();
- // getWeatherCodeled3();
-
-
- }
-
-
- SSS++;
- if(SSS>=60) { SSS=0; MMM++; }
- if(MMM>=60) { MMM=0; HHH++; }
- if(HHH>=24) { HHH=0; }
-
-
-
- LED_SMG[0]= tab[MMM%10 ];
- LED_SMG[1]= tab[MMM/10%10 ];
-
- LED_SMG[2]= tab[HHH%10 ];
- LED_SMG[3]= tab[HHH/10%10 ];
-
-
- }
-
-
-
-
-
-
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc0); // 位1 === 1
- TM1620_Write( LED_SMG[0] ); // 段码
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc2); // 位2 === 2
- TM1620_Write( LED_SMG[1] ); // 段码
- digitalWrite(STB, HIGH);
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc4); //位3 === dian
- TM1620_Write( ledd | 0x88 ); //段码 ledd
- digitalWrite(STB, HIGH);
-
-
- digitalWrite(STB, LOW);
- TM1620_Write(0xc6); //位4 === 3
- TM1620_Write( LED_SMG[2] ); //段码
- digitalWrite(STB, HIGH);
- digitalWrite(STB, LOW);
- TM1620_Write(0xc8); //位5 === 4
- TM1620_Write( autoo | LED_SMG[3] ); //段码
- digitalWrite(STB, HIGH);
-
-
-
-
-
-
-
-
-
- delay(1);
-
- }
- //====================================================================================
- //================= end =================================
-
-
-
-
- void SPIFFS_666(void) //==FS文件夹系统,小程序
-
- {
- bool ok = SPIFFS.begin(); //检查 FS文件夹系统,如果失败,返回0
-
- if (ok) //检查到 有内存的模块,可以执行读出 数据
- {
-
- SPIFFSOK=1; // 有FLASH 内存标志
- File f = SPIFFS.open(wifi_gp_data, "r");
- url2 = f.readStringUntil('\n');
- f.close();
- url2.trim();
- }
- else SPIFFSOK=0; // 无 FLASH 内存标志
-
- }
-
-
- // ============HTTP 小程序=====================================================================
- int getWeatherCode(){
-
-
- // 北京时间网站 http://time.beijing-time.org/time.asp 直接浏览器打开输出时间信息,
- //这粒模拟了浏览器,抓取需要的数据,
- const char* host1 = "time.beijing-time.org"; // 获取 HTTP网站,的IP地址用
- String url1 = "/time.asp"; // 获取 HTTP网站主页下的连接
- WiFiClient client;
-
- //----------------- http to tcp
- //
- const int httpPort = 80;
- if (!client.connect(host1, httpPort)) {
- return -1;
- }
- client.print(String("GET ") + url1 + " HTTP/1.1\r\n" +
- "Host: " + host1 + "\r\n" +
- "Connection: close\r\n\r\n");
- delay(150);
-
- String str = "";
- while(client.available()){
- String line = client.readStringUntil('\r');
- str += line;
-
- }
-
- // Serial.println(str); OK
-
- String sjall_data ="";
-
- String new_data ="";
- String STSJS ="";
- String STSJM ="";
- String STSJH ="";
-
- // new_data = str.substring( str.indexOf("nyear")+1 , str.length() ) ;
- // ========================分割字符, "nyear"开始-到结束,只需要这段字符
-
- // t0=new Date().getTime(); nyear= 2019; nmonth=1; nday=1; nwday=2; nhrs=14; nmin=15; nsec=54;
-
-
-
- sjall_data = str.substring( str.indexOf("getTime")+10 , str.length() ) ;
-
- if( sjall_data.length() <5 ) return -1; //
- new_data = str.substring( str.indexOf("nyear")+6 , str.length() ) ; // "nyear" 0 -- end,
-
- SJ_NIAN = ( new_data.substring( 0, new_data.indexOf(":") ) ) .toInt(); // 年获取
-
- new_data = str.substring( str.indexOf("nmonth")+7 , str.length() ) ;
- SJ_YUE = ( new_data.substring( 0, new_data.indexOf(":") ) ) .toInt(); // 月
-
- new_data = str.substring( str.indexOf("nday")+5 , str.length() ) ;
- SJ_RI = ( new_data.substring( 0, new_data.indexOf(":") ) ) .toInt(); // 日
-
- new_data = str.substring( str.indexOf("nwday")+6 , str.length() ) ;
- SJ_XQ = ( new_data.substring( 0, new_data.indexOf(":") ) ) .toInt(); // 星期
- // 时
- //分
- // 秒
-
-
-
-
- new_data = new_data.substring( new_data.indexOf("nhrs")+5 , new_data.length() ) ;
-
-
-
-
-
- STSJH = new_data.substring( 0, new_data.indexOf(":") ) ; // hhhhhhhhhhhhhhhhhhhhhhhhhhh
-
-
-
- new_data = new_data.substring( new_data.indexOf("nmin")+5 , new_data.length() ) ;
-
- STSJM = new_data.substring( 0, new_data.indexOf(":") ) ; //mmmmmmmmmmmmmmmmmmmmmmmmm
-
-
- new_data = new_data.substring( new_data.indexOf("nsec")+5 , new_data.length() ) ;
-
- STSJS = new_data.substring( 0, new_data.indexOf(":") ) ; // sssssmmmmmmmmmmmmsssssss
-
-
-
- // ===================字符转INT,如果字符是纯数字,转换后的INT值就可以赋值给数码管使用, sjm sjh
-
- sjm = STSJM.toInt();
- sjh = STSJH.toInt();
- sjs = STSJS.toInt()+6;
-
- Serial.println("==== SJ=; ");
- Serial.println(sjm);
-
- return sjm;
- }
|