2017-02-23 69 views
3

我把arduino mega和Arduino GSM Shield與Fyve(vodafone) - Sim結合在一起。長期來說,我想添加一個GPS,通過GSM模塊發送位置數據到data.sparkfun.com。爲了讓我的代碼正常運行,我開始使用來自arduino的GsmWebClient示例。 問題是,我經常得到「HTTP/1.1 302 Found - Error」。所以顯然我會重定向。有這樣的感覺,必須有一個非常簡單的解決方案,但我無法弄清楚。基本上通讀整個互聯網。我真的不知道現在是否正在發生,感覺非常愚蠢。Arduino GSM Shield WebClient 302

如果我將APN更改爲web.vodafone.de GSM和GPRS連接,但客戶端沒有。

這裏談到的代碼,並從串行響應:

// libraries 
#include <GSM.h> 


// PIN Number 
#define PINNUMBER "****" 

// APN data 
#define GPRS_APN  "event.vodafone.de" // replace your GPRS APN 
#define GPRS_LOGIN  "" // replace with your GPRS login 
#define GPRS_PASSWORD "" // replace with your GPRS password 

// initialize the library instance 
GSMClient client; 
GPRS gprs; 
GSM gsmAccess; 

// URL, path & port (for example: arduino.cc) 
char server[] = "arduino.cc"; 
char path[] = "/asciilogo.txt"; 
int port = 80; // port 80 is the default for HTTP 

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

    Serial.println("Starting Arduino web client."); 
    // connection state 
    boolean notConnected = true; 

    // After starting the modem with GSM.begin() 
    // attach the shield to the GPRS network with the APN, login and password 
    while (notConnected) { 
    Serial.println("connecting gsm"); 
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) { 
      Serial.println("gsm connected"); 
      delay(1000); 
      Serial.println("connecting gprs"); 
      if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY) { 
       Serial.println("gprs connected"); 
       notConnected = false; 
     } 
     else { 
      Serial.println("gprs Not connected"); 
      delay(1000); 
    } 
     } 
    else { 
     Serial.println("gsm Not connected"); 
     delay(1000); 
    } 
    } 

    Serial.println("connecting..."); 

    // if you get a connection, report back via serial: 
    if (client.connect(server, port)) { 
    Serial.println("connected"); 
    // Make a HTTP request: 
    client.println("GET /asciilogo.txt HTTP/1.1"); 
    client.print("Host: "); 
    client.println("www.arduino.cc"); 
    client.println("Connection: close"); 
    client.println(); 


    } 
} 

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

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

    // do nothing forevermore: 
    for (;;) 
     ; 
    } 
} 

開始Arduino的Web客戶端。

連接GSM

GSM連接

連接GPRS

GPRS連接

連接...

連接

HTTP/1.1 302實測值

日期:週四,2017年2月23日十八時13分45秒GMT

服務器:Apache

連接:關閉

地點: https://web.vodafone.de/sbb/redirectToLandingPage?lyt=vodafone&SESSION_TARGET_URL=http%3A%2F%2Fwww.arduino.cc%2Fasciilogo.txt

的Content-Length:0

不同點:用戶代理

緩存控制: no-transform

Content-Type:text/plain; charset = ISO-8859-1

斷開連接。

那麼,你有它。我希望有人能幫助我,這東西讓我瘋狂。

問候阿恩

回答

1

我只是有感情,沃達豐檢查HTTP數據包報頭,如果有,他們認爲可疑的東西,它們會重定向他們。也許你可以嘗試添加信息到http-header,像用戶代理?

// if you get a connection, report back via serial: 
    if (client.connect(server, port)) { 
      Serial.println("connected"); 
      // Make a HTTP request: 
      client.println("GET /asciilogo.txt HTTP/1.1"); 
      client.print("Host: "); 
      client.println("www.arduino.cc"); 
      client.println("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"); 
      client.println("Connection: close"); 
      client.println(); 
    } 

Example and info about http-headers

Discussion about Vodafone proxy detection and redirection

0

好球員,我解決了這個奇蹟。聽起來很愚蠢:SIM卡上沒有選擇互聯網的資費。我從我的主管那裏得到了它,並且確定它已經啓用了。事實並非如此。在那個上失敗了。

相關問題