我放了一个arduino mega和Arduino GSM Shield和Fyve(沃达丰) - 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 Web客户端。
连接gsm
连接gsm
连接gprs
gprs已连接
...连接
连接
找到HTTP / 1.1 302
日期:2017年2月23日星期四18:13:45 GMT
服务器:Apache
连接:关闭
内容长度:0
Vary:User-Agent
缓存控制:无变换
Content-Type:text / plain;字符集= ISO-8859-1
断开。
嗯,你有它。我希望有人可以帮助我,这些东西让我发疯。
关心Arne
答案 0 :(得分:1)
我感觉沃达丰检查了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();
}
答案 1 :(得分:0)