1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
#include <ESP8266WiFi.h> #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> // Required for 16 MHz Adafruit Trinket #endif #define PIN D3 #define NUMPIXELS 7 Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); // 와이파이 ssid을 입력해주세요. const char* ssid = "harmono"; //const char* ssid = "Decoder4f"; //와이파이 비밀번호를 입력해주세요. const char* password = "decoder@@@"; //const char* password = "decoder4f!!"; //const char* host = "www.kma.go.kr"; const char* host = "www.jaker.zc.bz"; int bLight = 150; void setup() { pixels.begin(); for (int k = 0; k < NUMPIXELS; k++) { pixels.setPixelColor(k, pixels.Color(0,255,0)); } pixels.setBrightness(bLight); pixels.show(); delay(1000); Serial.begin(115200); delay(10); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } unsigned long previousMillis = 0; const long delayTime = 60000; //1초(1000) 대기시간 bool firstChk = false; String seq_str = ""; String data_seq = ""; int weatherState = 0;//0 sunny 1 rain 2 snow int prevWState=-1; int wColor[4][3] = { {0,210,210},{0,0,255},{0,0,255},{255,100,30} }; void loop() { unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= delayTime || firstChk==false) { firstChk = true; previousMillis = currentMillis; Serial.print("connecting to "); Serial.println(host); // Use WiFiClient class to create TCP connections WiFiClient client; const int httpPort = 80; //http://www.kma.go.kr/wid/queryDFSRSS.jsp?zone=1144066000 if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } long randNumber = random(300000); // String url = "/wid/queryDFSRSS.jsp?zone=1144066000&rNum="+String(randNumber); String url = "/test/weather.xml"; Serial.print("Requesting URL: "); Serial.println(url); // 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"); delay(3000); Serial.print("client.available(): "); Serial.println(client.available()); while(client.available()){ //라인을 기준으로 문자열을 저장한다. String line = client.readStringUntil('\n'); delay(100); int seq = line.indexOf("<data seq=\""); // Serial.print("seq000: "); // Serial.println(seq); if (seq >= 0) { seq_str = "<data seq=\""; int seq_end = line.indexOf("\">"); data_seq = line.substring(seq + seq_str.length(), seq_end); if(data_seq.toInt()>9)break; } // Serial.print("data_seq.toInt(): "); // Serial.println(data_seq.toInt()); // if(data_seq.toInt()>0) // { int pty= line.indexOf("</pty>"); // Serial.print("pty11111: "); // Serial.println(pty); if(pty>0) { String pty_str="<pty>"; String wt_pty = line.substring(line.indexOf(pty_str)+pty_str.length(),pty); Serial.print("data_seq: "); Serial.println(data_seq.toInt()); Serial.print("wt_pty: "); Serial.println(wt_pty); int num = wt_pty.toInt(); weatherState = num; if(num>0){ break; } } // } } Serial.print("weatherState: "); Serial.println(weatherState); client.stop(); Serial.println("closing connection"); if(prevWState!=weatherState){ Serial.println("lightSetting"); lightSetting(); prevWState = weatherState; } } } int FadeSpeed = 10; void lightSetting() { for (int j = bLight; j > 0; j=j-1) { pixels.setBrightness(j); pixels.show(); delay(FadeSpeed); } pixels.clear(); for (int k = 0; k < NUMPIXELS; k++) { pixels.setPixelColor(k, pixels.Color(wColor[weatherState][0], wColor[weatherState][1], wColor[weatherState][2])); } for (int m = 1; m < bLight; m=m+1) { pixels.setBrightness(m); pixels.show(); delay(FadeSpeed); } } |