void loop() {
String valString;
while (client.available()) {
// {"id": 뒤에 오는 문자열을 날씨 코드로 저장
if ( rcvbuf.endsWith("{\"id\":")) {
readingVal = true;
valString = "";
}
char c = client.read();
if ( c != NULL ) {
if (rcvbuf.length() > 30)
rcvbuf = "";
rcvbuf += c;
//Serial.write(c);
}
if (readingVal) {
if (c != ',' ) {
valString += c;
//Serial.write(c);
}
else {
readingVal = false;
tempVal = valString.toInt(); // 날씨 코드를 String에서 Integer로 변환
Serial.println(tempVal); // 시리얼 모니터에 날씨 코드 출력
}
}
}
//전송 받은 날씨 데이터에 따라 네오픽셀 온오프 변경
if (tempVal > 299 && tempVal < 532) { //rainny
colorWipe2(strip2.Color(0, 216, 255), 50); //하늘색 출력
}
else if (tempVal > 599 && tempVal < 623) { //snow
colorWipe3(strip3.Color(255, 255, 255), 50); //흰색 출력
}
else if (tempVal > 799 && tempVal < 802) { //clear and sunny
colorWipe(strip.Color(255, 187, 0), 50); //진노랑색 출력
}
else if ((tempVal > 801 && tempVal < 805) || (tempVal > 700 && tempVal < 782)) { //cloudy & mist
colorWipe1(strip1.Color(1, 0, 255), 50); //진파랑색 출력
}
안녕하세요
klant님의 웨더클락 코드를 약간 변형 시켜서 if문으로 tempVal값을 조건을 걸어서 코딩을 했습니다.
그런데 OpenWeatherMap 사이트에서는 Rain 값으로 나오는데
네오픽셀에 출력이 안되거나 cloudy & mist값으로 출력이 나올 때가 있어서
왜 tempVal값이 저 조건(숫자)로 되야하는지 궁금합니다.
위에 코드는 일부만 발췌한 것이고 Rain으로 잘 출력되는 경우도 있습니다.
|