kohacraft Lab
/
kc_tenkiyoho_LED2
tenkiyoho LED 2 (with ESP-WROOM-02)
Diff: main.cpp
- Revision:
- 2:65e5f82ea7b8
- Parent:
- 1:5f560645b4fb
--- a/main.cpp Sun Sep 06 09:58:41 2015 +0000 +++ b/main.cpp Wed May 04 03:13:17 2016 +0000 @@ -12,12 +12,12 @@ #define baudrate 115200 -static char rxbuff[1000]; //取得する文字列 +static char rxbuff[1500]; //取得する文字列 int buffAdr = 0; const char SSID[] = "your SSDI"; //アクセスポイントのSSID const char PASS[] = "password"; //アクセスポイントのパスワード -const char WOEID[] = "28413961"; //天気を調べる場所 http://woeid.rosselliot.co.nz/ で郵便番号で検索して得られる8桁 +const char WOEID[] = "28413961"; //天気を調べる場所 http://woeid.rosselliot.co.nz/ で郵便番号で検索して得られる番号 //データを受信する bool recvData() @@ -36,7 +36,7 @@ { rxbuff[buffAdr++] = wifi.getc(); //Serial.getc() headerCount++; - if( headerCount <= 2400 ) //最初の2400文字捨てる + if( headerCount <= 1500 ) //最初の2400文字捨てる buffAdr=0; if( buffAdr >= sizeof(rxbuff)-1 ) //バッファ溢れしたら終了 { @@ -67,46 +67,45 @@ return false; } - //最低気温を抽出 - char *lowStart,*lowEnd; - //int tempLow; - lowStart = strstr(forecast, "low"); - lowStart = strchr( lowStart , '\"' ); - lowStart++; //"の次の文字のポインタ - lowEnd = strchr( lowStart , '\"' ); - *lowEnd = '\0'; - *tempLow = atoi( lowStart ); //最低気温を数字に変換 + //天気コードを抽出 + char *codeStart,*codeEnd; + //int weatherCord; + codeStart = strstr(forecast, "code="); + codeStart = strchr( codeStart , '\"' ); + codeStart++; //"の次の文字のポインタ + codeEnd = strchr( codeStart , '\"' ); + *codeEnd = '\0'; + *weatherCord = atoi( codeStart ); //最高気温を数字に変換 //最高気温を抽出 char *hiStart,*hiEnd; //int tempHi; - hiStart = strstr(lowEnd+1, "high"); + hiStart = strstr(codeEnd+1, "high="); hiStart = strchr( hiStart , '\"' ); hiStart++; //"の次の文字のポインタ hiEnd = strchr( hiStart , '\"' ); *hiEnd = '\0'; *tempHi = atoi( hiStart ); //最高気温を数字に変換 - + + //最低気温を抽出 + char *lowStart,*lowEnd; + //int tempLow; + lowStart = strstr(hiEnd+1, "low="); + lowStart = strchr( lowStart , '\"' ); + lowStart++; //"の次の文字のポインタ + lowEnd = strchr( lowStart , '\"' ); + *lowEnd = '\0'; + *tempLow = atoi( lowStart ); //最低気温を数字に変換 //天気を抽出 char *textStart,*textEnd; char weatherText[32]; - textStart = strstr(hiEnd+1, "text"); + textStart = strstr(lowEnd+1, "text="); textStart = strchr( textStart , '\"' ); textStart++; //"の次の文字のポインタ textEnd = strchr( textStart , '\"' ); *textEnd = '\0'; strncpy( weatherText, textStart , 32); - - //天気コードを抽出 - char *codeStart,*codeEnd; - //int weatherCord; - codeStart = strstr(textEnd+1, "code"); - codeStart = strchr( codeStart , '\"' ); - codeStart++; //"の次の文字のポインタ - codeEnd = strchr( codeStart , '\"' ); - *codeEnd = '\0'; - *weatherCord = atoi( codeStart ); //最高気温を数字に変換 return true; } @@ -192,7 +191,7 @@ wifi.printf("AT\r\n"); ledIlluminationWait(); - wifi.printf("AT+CWMODE=3\r\n"); + wifi.printf("AT+CWMODE=1\r\n"); ledIlluminationWait(); //アクセスポイントに接続 @@ -204,27 +203,32 @@ while(1) { //サーバに接続 - wifi.printf("AT+CIPSTART=\"TCP\",\"weather.yahooapis.com\",80\r\n"); + wifi.printf("AT+CIPSTART=\"TCP\",\"query.yahooapis.com\",80\r\n"); ledIlluminationWait(); //サーバに要求 - wifi.printf("AT+CIPSEND=72\r\n"); + char str[200]; + sprintf(str , "GET http://query.yahooapis.com/v1/public/yql?q=SELECT%%20*%%20FROM%%20weather.forecast%%20WHERE%%20woeid%%3D%%22%s%%22%20and%%20u%%3D%%22c%%22\r\nHost: query.yahooapis.com\r\nConnection: close\r\n\r\n\r\n",WOEID); + wifi.printf("AT+CIPSEND=%d\r\n",strlen(str)); ledIlluminationWait(); //サーバに要求 - wifi.printf("GET http://weather.yahooapis.com/forecastrss?u=c&w=%s HTTP/1.1\r\n\r\n",WOEID); + wifi.printf("%s",str); recvData(); //データの受信 //切断 wifi.printf("AT+CIPCLOSE\r\n"); + wifi.printf("%s\r\n",rxbuff); //バッファの内容を出力 //文字列探索 int weatherCord , tempHi , tempLow; if( getWeather( rxbuff , &weatherCord , &tempLow , &tempHi ) == false ) //データの受信 { //予報の文字列がない + wifi.printf("Can not find strng:forecast\r\n"); break; //最初からやり直す } + wifi.printf("weatherCord:%d tempLow:%d tempHi:%d\r\n",weatherCord , tempLow , tempHi); //天気をLEDの色に変換する