【问题标题】:Arduino GSM Shield WebClient 302Arduino GSM Shield WebClient 302
【发布时间】:2017-07-14 09:42:24
【问题描述】:

我将 arduino mega 和 Arduino GSM Shield 与 Fyve(vodafone)-Sim 放在一起。从长远来看,我想添加一个 GPS 以通过 GSM 模块将位置数据发送到 data.sparkfun.com。为了让我的代码运行,我从 arduino 的 GsmWebClient 示例开始。 问题是,我经常收到“HTTP/1.1 302 Found - Error”。所以显然我被重定向了。感觉必须有一个非常简单的解决方案,但我无法弄清楚。基本上通读整个互联网。我真的不知道这是怎么回事,现在感觉很愚蠢。

如果我将 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 网络客户端。

连接 gsm

gsm 已连接

连接 gprs

gprs 已连接

正在连接...

已连接

找到 HTTP/1.1 302

日期:格林威治标准时间 2017 年 2 月 23 日星期四 18:13:45

服务器:Apache

连接:关闭

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

内容长度:0

变化:用户代理

缓存控制:无转换

内容类型:文本/纯文本; charset=ISO-8859-1

断开连接。

嗯,你有它。我希望有人可以在这里帮助我,那东西让我发疯了。

问候阿恩

【问题讨论】:

    标签: arduino webclient gsm gprs


    【解决方案1】:

    我只是觉得 Vodafone 会检查 http-packet 标头,如果他们认为可疑的东西,他们会重定向它们。也许您可以尝试向 http-header 添加信息,例如 user-agent?

        // 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

    【讨论】:

      【解决方案2】:

      好吧,伙计们,我解决了这个奇迹。听起来很愚蠢:在 SIM 卡上选择的互联网没有关税。我从我的主管那里得到它,并确定它已经启用。不是。失败了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-21
        • 2018-05-09
        • 1970-01-01
        相关资源
        最近更新 更多