위즈네트 아카데미

OPEN PROJECT

오픈 프로젝트

쉴드체험단 (1기) [체험단 wizfi-shield 08] 코드

자랑쟁이 2014.12.01 09:24 조회 수 : 28


[체험단 wizfi-shield 08] 코드


저번글에 이어 8번째 글입니다.




최종 코드는 다음과 같습니다.






/******************************************************************
* WizFiShield Web Client Test Example
*
* This sketch connect to a website(http://www.google.com) using WizFi Shield
*
* Circuit:
* WizFiShield connected to Arduino via SPI
*
* RST: pin 2  // Output
* DRDY: pin 3  // Input
* CSB: pin 4  // output
*
* MOSI: pin 11  // output
* MISO: pin 12  // input
* SCK: pin 13  // out
*
* Created 18 Sep. 2012
* by James YS Kim  (jameskim@wiznet.co.kr, javakys@gmail.com)
*
* Modified 27 May. 2013
* by Jinbuhm Kim  (jbkim@wiznet.co.kr, jinbuhm.kim@gmail.com)
*
*****************************************************************/




// WizFiShield communicates using SPI, so include the SPI library:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SPI.h>
#include <TimerOne.h>
#include <WizFi2x0.h>
#include <WizFiClient.h>






#define SSID    "scod"        // SSID of your AP
#define Key     "rlawhdahr7"  // Key or Passphrase
// Wi-Fi security option (NO_SECURITY, WEP_SECURITY, WPA_SECURITY, WPA2PSK_SECURITY)
#define Security        WPA2PSK_SECURITY




WizFi2x0Class myWizFi;
WizFiClient myClient;
TimeoutClass ConnectInterval;




boolean Wifi_setup = false;




///////////////////////////////
// 1msec Timer
void Timer1_ISR()
{
myWizFi.ReplyCheckTimer.CheckIsTimeout();
}
//
//////////////////////////////




int transCode [] = {
3,3,3,3,3,2,2,2,2,2,2,3,3,2,2,2,2,3,2,4,4,4,4,3,3,2,4,4,4,4,4,1,1,1,1,2,1,3,3,3,3,2,2,2,4,3,2,3};




const int stepsPerRevolution = 200;
int switchPin = 5;
int rCounter=-1;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Stepper myStepper(stepsPerRevolution, 6,7,8,9);




void setup() {




pinMode(switchPin, INPUT);
while( rCounter < 0) {
if (digitalRead(6) == HIGH){
rCounter = 0;
}
else {
myStepper.step(-1);
rCounter--;
Serial.println(rCounter);
}
}
myStepper.setSpeed(80);




byte retval;




Serial.begin(9600);
Serial.println("rnSerial Init");




// initalize WizFi2x0 module:
myWizFi.begin();




ConnectInterval.init();




// Socket Creation with Server IP address and Server Port num
myClient =  WizFiClient("xml.weather.yahoo.com", 80);




// Timer1 Initialize
Timer1.initialize(1000); // 1msec
Timer1.attachInterrupt(Timer1_ISR);




myWizFi.SendSync();
myWizFi.ReplyCheckTimer.TimerStart(3000);




Serial.println("Send Sync data");




while(1)
{
if(myWizFi.CheckSyncReply())
{
myWizFi.ReplyCheckTimer.TimerStop();
Serial.println("Rcvd Sync data");
break;
}
if(myWizFi.ReplyCheckTimer.GetIsTimeout())
{
Serial.println("Rcving Sync Timeout!!");
// Nothing to do forever;
for(;;)
;
}
}
////////////////////////////////////////////////////////////////////////////
// AP association
while(1)
{
retval = myWizFi.associate(SSID, Key, Security, true);




if(retval == 1){
Serial.println("AP association Success");
Wifi_setup = true;
break;
}
else{
Serial.println("AP association Failed");
}
}




}




void loop()
{
uint8_t retval;
byte rcvdBuf[129];




memset(rcvdBuf, 0, 129);




if(Wifi_setup)
{
myWizFi.RcvPacket();




if(myClient.available()){
if(myClient.read(rcvdBuf))
{
Serial.print((char *)rcvdBuf);
}
}
else{
retval = myClient.connect();
if(retval == 1)
{
Serial.println("Connected! ");
myClient.write((byte *)"GET /forecastrss?w=1132599&u=c HTTP/1.0rnrn");
if(myClient.find("code=") )
{
int code = myClient.parseInt();
Serial.print("code is ");
Serial.println(code);
myStepper.step((-stepsPerRevolution*3)+(-stepsPerRevolution/4)*transCode

[code][/code]

);
delay(500);
}
else {
Serial.println("can't access the data");
delay(500);
}
}
else
Serial.println("Connection Failed");
}
}
}



이제 조립해서 작동만 시키면 되네요. 근데 출력이 자꾸 이상하게 나오는 문제가 ㅎㅎㅎ.