【发布时间】: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
连接:关闭
内容长度:0
变化:用户代理
缓存控制:无转换
内容类型:文本/纯文本; charset=ISO-8859-1
断开连接。
嗯,你有它。我希望有人可以在这里帮助我,那东西让我发疯了。
问候阿恩
【问题讨论】:
标签: arduino webclient gsm gprs