2016年5月4日 星期三

[Arduino] Wifi Shield Firmware Upgrade (Mac OS)


問題描述

最近借到一塊Wi-Fi Shield ,想測試一下連線功能。



順利連上家裡的AP後,卻一直無法連上google網頁。


範例程式從網路上COPY來修改的 ,如下所示

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using a WiFi shield.
 
 This example is written for a network using WPA encryption. For 
 WEP or WPA, change the Wifi.begin() call accordingly.
 
 This example is written for a network using WPA encryption. For 
 WEP or WPA, change the Wifi.begin() call accordingly.
 
 Circuit:
 * WiFi shield attached
 
 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 */


#include <SPI.h>
#include <WiFi.h>

char ssid[] = "qoo"; //  your network SSID (name) 
char pass[] = "12345678";    // 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;
// 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(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check firmware version
  Serial.print(F("Firmware version: "));
  Serial.println(WiFi.firmwareVersion());
  
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 
  
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
  
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
  
  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
     if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
    client.println("Connection: close");
    client.println();
    
  }
}

void loop() {
  // if there are incoming bytes available 
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}


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");
}

試了幾次總是



Firmware version: 1.0.0
Attempting to connect to SSID: qoo
Connected to wifi
SSID: qoo
IP Address: 192.168.0.101
signal strength (RSSI):-42 dBm

Starting connection to server...

disconnecting from server.


以telnet測試連上www.google.com 80 是OK的,爬文也有人遇到同樣問題。

需要將Firmware upgrade 一下。


系統環境

Mac OS : EI Capitan

Arduino IDE : 1.6.7

我的Arduino IDE是放在應用程式裡,

所以路徑是Applications/Arduino.app/Contents/...


更新Firmware

1.只要你有新版的Arduino IDE就不必再去Git Hub下載Firmware,IDE 口袋裡有。

2.安裝MacPorts (到這個網址下載後安裝即可)

https://www.macports.org/

3.安裝duf-Programmer ,輸入



sudo port install dfu-programmer










































4.將Wi-FI Shield上的Jumper 做個調整(2個針腳都套上)。

























5.Wi-Fi Shield必須接上USB線(連接電腦),注意,它並不是一般手機用的USB頭。

是這種梯形的 ,不要拿錯線硬插。



































6.開啟Command Line ,然候輸入


cd  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/firmwares/wifishield/scripts


7.接下來要開始燒錄了,輸入


sudo sh ./ArduinoWifiShield_upgrade_mac.sh  -a /Applications/Arduino.app/Contents/Java/ -f shield





















8.如果和上圖的訊息一樣,恭喜你己經成功了,接下來要做的是把Jumber 復原。

並拔除Wi-Fi Shield 的USB線,然候按一下板子上Reset 。


























接下來看到的訊息會如下所示,順利的把網頁給載回來了


Firmware version: 1.1.0
Attempting to connect to SSID: qoo
Connected to wifi
SSID: qoo
IP Address: 192.168.0.101
signal strength (RSSI):-44 dBm

Starting connection to server...
connected to server
HTTP/1.1 302 Found
Location: http://www.google.com.tw/search?q=arduino&gws_rd=cr&ei=uPApV82EBuaxmwWAh7P4Cw
Cache-Control: private
Content-Type: text/html; charset=UTF-8
P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
Date: Wed, 04 May 2016 12:53:12 GMT
Server: gws
Content-Length: 282
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=79=QJ8WpV2mdKUC7UqN6eGqKoRfVK8pRzDKVgAz7gTTmeb6eXnIpZvG5smDYJaDFwGvMLUdNTYDBGcHxvZOhAE0vyIDgnneFX1rDml3_zuSIuE2kuBWQsWCr3EPS1QQWDWE; expires=Thu, 03-Nov-2016 12:53:12 GMT; path=/; domain=.google.com; HttpOnly
Connection: close

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.tw/search?q=arduino&amp;gws_rd=cr&amp;ei=uPApV82EBuaxmwWAh7P4Cw">here</A>.
</BODY></HTML>

disconnecting from server.


歷經2個晚上的努力,總算讓Wi-Fi Shield正常了。




參考資料


如何upgrade Wi-Fi Shield Firmware

http://www.arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading

另一篇圖文說明upgrade firmware 的文

https://ohmyfarads.wordpress.com/2013/11/11/updating-firmware-on-arduino-wifi-shield-for-dummies/comment-page-1/

MAC 燒錄上遇到問題的帖子

http://forum.arduino.cc/index.php?topic=293142.0

相同問題的帖子

http://forum.arduino.cc/index.php?topic=177044.0


沒有留言:

張貼留言