| 
					 #include <SPI.h> 
#include <Adafruit_WS2801.h> 
#include <WizFi250.h> 
#include "Adafruit_WS2801.h" 
#ifdef __AVR_ATtiny85__ 
#include <avr/power.h> 
#endif 
#define VARID      "17ffc157ad6681462ea5060ea3d87582" 
uint8_t dataPin  = 2;    // Yellow wire on Adafruit Pixels 
uint8_t clockPin = 3;    // Green wire on Adafruit Pixels 
//LED strip객체 생성. LED의 개수에 따라 앞 인자값을 변경한다. 
Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin); 
char ssid[] = "Xiaomi(WIFI)";       // 와이파이SSID 
char pass[] = "1q2w3e4r";        // 와이파이 비밀번호 
int status = WL_IDLE_STATUS; 
char server[] = "api.openweathermap.org"; 
unsigned long lastConnectionTime = 0;         // 서버에 접속한 마지막 시간 (MilliSecond) 
const unsigned long postingInterval = 1000L; // 서버에 데이터를 요청할 Delay (MilliSecond) 
boolean readingVal; 
boolean getIsConnected = false; 
int val, temp; 
int tempVal; 
String rcvbuf; 
// WiFiClient 오브젝트 선언 
WiFiClient client; 
void httpRequest(); 
void printWifiStatus(); 
void setup() 
{ 
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L) 
  clock_prescale_set(clock_div_1); //clock을 16Mhz로 사용 
#endif 
  strip.begin(); 
  //LEDstrip loop를 실행시키기 위해 모든 LED를 off시키며 초기화 
  strip.show(); 
  Serial.begin(115200); 
  WiFi.init(); 
  if (WiFi.status() == WL_NO_SHIELD) {   // WiFi 보드에 문제가 있다면 
    Serial.println("WiFi board error"); // 시리얼 모니터에 WiFi board error  출력 
  } 
  while ( status != WL_CONNECTED) {  // WiFi보드에 문제가 없어서 Wifi연결 시도 
    Serial.print("Attempting to connect to WPA SSID: "); 
    Serial.println(ssid);          // 연결 할 WiFi의 SSID를 출력 
    status = WiFi.begin(ssid, pass);     // WPA/WPA2 WiFi에 연결 
  } 
  Serial.println("You're connected to the network"); 
  printWifiStatus(); 
} 
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.print("날씨코드 : "); 
        Serial.println(tempVal);  // 시리얼 모니터에 날씨 코드 출력 
      } 
    } 
  } 
  if (tempVal > 299 && tempVal < 532) {  //비 
    for (int i = 0; i < 25; i++) { 
      strip.setPixelColor(i, Color(255, 0, 0)); 
    } 
  } 
  else if (tempVal > 599 && tempVal < 623) { //눈 
    for (int i = 0; i < 25; i++) { 
      strip.setPixelColor(i, Color(0, 255, 0)); 
    } 
  } 
  else if (tempVal > 700 && tempVal < 782) { //안개(흐림) 
    for (int i = 0; i < 25; i++) { 
      strip.setPixelColor(i, Color(0, 0, 255)); 
    } 
  } 
  else if (tempVal > 799 && tempVal < 802) { //맑음 
    for (int i = 0; i < 25; i++) { 
      strip.setPixelColor(i, Color(255, 0, 0)); 
    } 
  } 
  else if (tempVal > 801 && tempVal < 805) { //구름많음 
    for (int i = 0; i < 25; i++) { 
      strip.setPixelColor(i, Color(0, 255, 0)); 
    } 
  } 
  //날씨 코드 초기화 
  tempVal = 0; 
  if (millis() - lastConnectionTime > postingInterval) { // interval 시간이 충족되었다면 
    httpRequest(); //데이터 호출 
  } 
  rcvbuf = ""; 
} 
// 서버에 날씨 데이터 호출 함수 
void httpRequest() { 
  Serial.println(); 
  // close any connection before send a new request 
  // this will free the socket on the WiFi shield 
  client.stop(); 
  // 제대로 서버에 연결되었을 경우 
  if (client.connect(server, 80)) { 
    Serial.println("Connecting..."); 
    // HTTP 요청을 보냄 
    client.print("GET /data/2.5/weather?q=Seoul,kr&appid="); 
    client.print(VARID); 
    client.println(" HTTP/1.1"); 
    client.println("Host: api.openweathermap.org"); 
    client.println("Connection: close"); 
    client.println(); 
    // note the time that the connection was made 
    lastConnectionTime = millis(); 
    getIsConnected = true; 
  } 
  // 제대로 서버에 연결이 되지 않았으면 Connection failed 메세지와 함께 neopixel LED에 적색불 점멸 
  else { 
    Serial.println("Connection failed"); 
    getIsConnected = false; 
  } 
} 
 
// WiFi 연결 상태 정보 출력 함수 
void printWifiStatus() { 
  // print the SSID of the network you're attached to 
  Serial.print("SSID: "); 
  Serial.println(WiFi.SSID()); 
  // print your WiFi shield's IP address 
  IPAddress ip = WiFi.localIP(); 
  Serial.print("IP Address: "); 
  Serial.println(ip); 
  // print the received signal strength 
  long rssi = WiFi.RSSI(); 
  Serial.print("Signal strength (RSSI):"); 
  Serial.print(rssi); 
  Serial.println(" dBm"); 
} 
uint32_t Color(byte r, byte g, byte b) 
{ 
  uint32_t cl; 
  cl = r; 
  cl <<= 8; 
  cl |= g; 
  cl <<= 8; 
  cl |= b; 
  return cl; 
} 
  
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ 
사진도 첨부하고 싶은데 첨부가 안되어서 아쉽습니다 ㅜㅜ 
열심히 혼자 여러 자료들을 보면서 만들 었는데 
시리얼모니터로 확인 했을 때 날씨코드를 와이파이로 연결되서 받아들여오는 것은 잘 됩니다. 
근데 무슨 이유에서 인지 모르겠는데 저가 생각하는 위에 소스 내용은 LED불이 비,눈,안개,맑음,구름(많음) 일 때 전체가 빨간색으로 들어오던 초록색으로 들어오던 파란색으로 들어오던 해야하는데 
LED에 불이 안들어 옵니다.. 연결은 잘 되어 있고 이 소스 말고 https://www.kocoafab.cc/tutorial/view/225 의 소스를 그대로 
가져와 쓰면 LED에 불이 안들어오는 것은 또 아니여서 고장은 아닌데 혹시 어떤 내용을 잘못하여 안나오는지 알 수 있을까요? 
					
										
									 |