我有一些代碼,根據網站上的值(包含一個數字的空白頁開啓/關閉LED,頁面上的數字表示LED應該閃爍的次數)Arduino返回錯誤的整數值
的問題是,循環繼續運行。
我可以通過手動設置整數值(int c = 3
)解決問題。
不知道我的問題是什麼。
的,你是一個可以點我正確的方向
Ur L:http://b2b.as/lan.php?pid=8855
代碼:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 104 };
char server[] = "b2b.as";
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println(Ethernet.localIP());
Serial.println();
// Set digital pin as output
// 5V
pinMode(8, OUTPUT);
}
void loop()
{
//
Serial.print("\n-----\n");
// Connect to the server
Serial.print("connecting to URL ...");
// Start LAN connection
EthernetClient client;
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /lan.php?pid=8855");
client.println();
} else {
Serial.println("connection failed");
}
// Wait a moment for data to arrive
// Note: This is NOT a reliable way of doing this!
delay(1000);
if (client.available() > 0) {
char c = atoi(client.read());
Serial.print("page value (pick): ");
Serial.print(c, DEC);
Serial.print("\n");
for (int x = 1; x <= int(c); x++) {
Serial.print("picking: #");
Serial.println(x);
digitalWrite(8, HIGH);
Serial.println("8 HIGH ...");
delay(5000); // Add switch
digitalWrite(8, LOW);
Serial.println("8 LOW ...");
delay(1000);
}
Serial.print("end");
}
// Disconnect the client
if (client.connected()) {
//Serial.println();
Serial.print("disconnecting");
client.stop();
}
// Wait another 9s, which will give us a delay of roughly 10s
delay(9000);
}
這看起來並不像一個適當的HTTP請求。而一個HTTP服務器不只是返回一個字節。 https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Example_session –
這是一個php頁面,它返回的值是0-100 –
服務器還會發送一堆頭文件。 'client.read()'讀取一個字節。這隻會產生從0到9的數字。 –