Arduino GSM Shield WebClient 302 [英] Arduino GSM Shield WebClient 302
问题描述
我将 arduino mega 和带有 Fyve(vodafone)-Sim 的 Arduino GSM Shield 放在一起.长期来看,我想添加一个 GPS 以通过 GSM 模块将位置数据发送到 data.sparkfun.com.为了让我的代码运行,我从 arduino 的 GsmWebClient 示例开始.问题是,我不断收到HTTP/1.1 302 Found - Error".所以显然我被重定向了.感觉必须有一个非常简单的解决方案,但我无法弄清楚.基本上通读整个互联网.我真的不知道这是怎么回事,现在感觉很愚蠢.
如果我将 APN 更改为 web.vodafone.de GSM 和 GPRS 连接,但客户端没有.
下面是代码和序列的响应:
//库#include <GSM.h>//密码#define PINNUMBER "****"//APN数据#define GPRS_APN "event.vodafone.de"//替换你的GPRS APN#define GPRS_LOGIN ""//替换为您的 GPRS 登录名#define GPRS_PASSWORD ""//替换为你的GPRS密码//初始化库实例GSMClient客户端;GPRS GPRS;GSM GSM接入;//URL,路径 &端口(例如:arduino.cc)char server[] = "arduino.cc";char path[] = "/asciilogo.txt";int 端口 = 80;//端口 80 是 HTTP 的默认端口无效设置(){//初始化串行通信并等待端口打开:Serial.begin(9600);而(!串行){;//等待串口连接.仅本地 USB 端口需要}Serial.println("启动Arduino web客户端.");//连接状态布尔值 notConnected = true;//用 GSM.begin() 启动调制解调器后//使用APN、登录名和密码将屏蔽连接到GPRS网络而(未连接){Serial.println("连接GSM");如果 (gsmAccess.begin(PINNUMBER) == GSM_READY) {Serial.println("gsm 已连接");延迟(1000);Serial.println("连接gprs");if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY) {Serial.println("gprs 已连接");notConnected = 假;}别的 {Serial.println("gprs 未连接");延迟(1000);}}别的 {Serial.println("gsm 未连接");延迟(1000);}}Serial.println("正在连接...");//如果获得连接,则通过串行报告:如果(客户端.连接(服务器,端口)){Serial.println("已连接");//发出 HTTP 请求:client.println("GET/asciilogo.txt HTTP/1.1");client.print("主机:");client.println("www.arduino.cc");client.println("连接:关闭");客户端打印();}}无效循环(){//如果有可用的传入字节//从服务器读取它们并打印它们:如果(客户端可用()){char c = client.read();Serial.print(c);}//如果服务器断开连接,停止客户端:如果 (!client.available() && !client.connected()) {Serial.println();Serial.println("断开连接.");客户端停止();//永远什么都不做:为了 (;;);}}
<块引用>
启动 Arduino 网络客户端.
连接GSM
GSM 已连接
连接gprs
gprs 已连接
正在连接...
已连接
发现 HTTP/1.1 302
日期:2017 年 2 月 23 日星期四 18:13:45 GMT
服务器:Apache
连接:关闭
内容长度:0
变化:用户代理
缓存控制:无转换
内容类型:文本/纯文本;字符集=ISO-8859-1
断开连接.
好吧,你有它.我希望有人能在这里帮助我,那些东西让我发疯.
问候阿恩
我只是觉得 Vodafone 会检查 http-packet 标头,如果有他们认为可疑的东西,他们会重定向它们.也许您可以尝试向 http-header 添加信息,例如 user-agent?
//如果获得连接,则通过串行报告:如果(客户端.连接(服务器,端口)){Serial.println("已连接");//发出 HTTP 请求:client.println("GET/asciilogo.txt HTTP/1.1");client.print("主机:");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("连接:关闭");客户端打印();}
I put an arduino mega and the Arduino GSM Shield with a Fyve(vodafone)- Sim together. Long term I want to add a GPS to send position-data via the GSM module to data.sparkfun.com. In order to get my code running, I started with the GsmWebClient example from arduino. The problem is, that I constantly get the "HTTP/1.1 302 Found - Error". So apparently I get redirected. Got the feeling that there has to be a pretty much easy solution, but I cant figure it out. Basically read through the whole internet. I really dont know wth is going on and feel rather stupid now.
If i change the APN to web.vodafone.de GSM and GPRS connect, but the client doesnt.
Here comes the code and the response from the serial:
// 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 (;;)
;
}
}
Starting Arduino web client.
connecting gsm
gsm connected
connecting gprs
gprs connected
connecting...
connected
HTTP/1.1 302 Found
Date: Thu, 23 Feb 2017 18:13:45 GMT
Server: Apache
Connection: close
Content-Length: 0
Vary: User-Agent
Cache-Control: no-transform
Content-Type: text/plain; charset=ISO-8859-1
disconnecting.
Well, there you have it. I hope someone can help me here, that stuff is driving me crazy.
Regards Arne
I just got feeling that Vodafone checks http-packet headers and if there is something that they think suspicious, they redirect them. Maybe you could try to add information to http-header, like 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
这篇关于Arduino GSM Shield WebClient 302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!