نمایش نتایج: از 1 به 1 از 1
Like Tree2 لایک
  • 2 Post By hesam.time

موضوع: کلاینت توییتر وای فای

  1. #1
    Senior Member
    تاریخ عضویت
    Mar 2013
    محل سکونت
    Iran
    نوشته ها
    138

    Lightbulb کلاینت توییتر وای فای

    این مثال چگونگی پاسخ شما را به یک درخواست HTTP با استفاده از یک WiFi shield را نشان می دهد. آن برگشت XML را تجزیه می کند، و به دنبال <text>this is a tweet</text> می گردد. این مثال برای یک شبکه دارای رمزنگاری WPA نوشته شده است. برای WEP یا WPA
    وای فای را تغییر دهید.()begin را مطابق با آن فراخوانی کنید.
    سخت افزار مورد نیاز
    Arduino WiFi Shield
    شیلد سازگار با برد آردینو
    مدار
    شیلد WiFi از پین های 10 ، 11 ، 12، و 13 برای ارتباط SPI به ماژول HDG104 استفاده می کند. پین 4 دیجیتال ، برای کنترل پین انتخاب slave روی SD کارت استفاده می شود. برای این مثال شما باید به شبکه وایرلس 802.11b/g که به اینترنت متصل است؛ دسترسی داشته باشید.
    شما احتیاج خواهید داشت تنظیمات شبکه در طرح را مطابقSSID شبکه خاص خود تغییر دهید.
    برای شبکه های WPA/WPA2 که از رمزنگاری شخصی WPA/WPA2 استفاده می کنند، شما به SSID و پسورد نیاز دارید.شیلد قادر به اتصال به شبکه دارای رمزنگاری قوی WPA2 نیست.
    پسورد در شبکه WEP ، رشته های هگزادسیمال به عنوان کلید شناخته شده هستند. یک شبکه WEP می تواند 4 کلید متفاوت داشته باشد؛ به هر کلید
    یک مقدار”Key Index” اختصاص داده شده است. برای شبکه های رمزگذاری شده ی WEP ،شما به SSID ، کلید ، و شماره کلید احتیاج دارید.
    برای دیدن سایز بزرگ روی عکس کلیک کنید

نام: WiFiShield_bb.jpg
مشاهده: 60
حجم: 12.2 کیلو بایت
    در تصویر بالا ، آردینو باید در زیر شیلد WiFi قرار بگیرد.
    کد:
    #include <SPI.h> #include <WiFi.h> char ssid[] = "YourNetwork"; // your network SSID (name) char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; // status of the wifi connection // initialize the library instance: WiFiClient client; const unsigned long requestInterval = 30*1000; // delay between requests; 30 seconds // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(199,59,149,200); // numeric IP for api.twitter.com char server[] = "api.twitter.com"; // name address for twitter API boolean requested; // whether you've made a request since connecting unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds String currentLine = ""; // string to hold the text from server String tweet = ""; // string to hold the tweet boolean readingTweet = false; // if you're currently reading the tweet void setup() { // reserve space for the strings: currentLine.reserve(256); tweet.reserve(150); // start serial port: Serial.begin(9600); // attempt to connect to Wifi network: while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } // you're connected now, so print out the status: printWifiStatus(); connectToServer(); } void loop() { if (client.connected()) { if (client.available()) { // read incoming bytes: char inChar = client.read(); // add incoming byte to end of line: currentLine += inChar; // if you get a newline, clear the line: if (inChar == '\n') { currentLine = ""; } // if the current line ends with <text>, it will // be followed by the tweet: if ( currentLine.endsWith("<text>")) { // tweet is beginning. Clear the tweet string: readingTweet = true; tweet = ""; // break out of the loop so this character isn't added to the tweet: return; } // if you're currently reading the bytes of a tweet, // add them to the tweet String: if (readingTweet) { if (inChar != '<') { tweet += inChar; } else { // if you got a "<" character, // you've reached the end of the tweet: readingTweet = false; Serial.println(tweet); // close the connection to the server: client.stop(); } } } } else if (millis() - lastAttemptTime > requestInterval) { // if you're not connected, and two minutes have passed since // your last connection, then attempt to connect again: connectToServer(); } } void connectToServer() { // attempt to connect, and wait a millisecond: Serial.println("connecting to server..."); if (client.connect(server, 80)) { Serial.println("making HTTP request..."); // make HTTP GET request to twitter: client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino HTTP/1.1"); client.println("Host:api.twitter.com"); client.println("Connection:close"); client.println(); } // note the time of this connect attempt: lastAttemptTime = millis(); } 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"); }
    لینک سایت:Arduino - WiFiTwitterClient
    ویرایش توسط hesam.time : 03-28-2013 در ساعت 12:58 PM

کلمات کلیدی این موضوع

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •  

SEO by vBSEO