gpt4 book ai didi

无法使用 Arduino Wifi-Shield 连接到本地服务器

转载 作者:行者123 更新时间:2023-11-30 17:13:06 24 4
gpt4 key购买 nike

我正在尝试使用Arduino wifi shied将数据从arduino上传到本地服务器。但是代码永远不会到达“已连接”线。我正在使用WAMP服务器。arduino wifishield的IP地址ping是好的。 wifishield连接网络。代码如下:

 #include <TinkerKit.h>
#include <WiFi.h>
#include <SPI.h>

char ssid[] = "Connectify-moloi"; // your network SSID (name)
char pass[] = "1234567890"; // your network password
int status = WL_IDLE_STATUS;

//WiFiServer server(80);
long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 250000; // READING INTERVAL
int sensor;
int analog_val;

String data;
String Hall;
String Temp;
WiFiClient client;
IPAddress server(192,168,164,101);
void setup() {
Serial.begin(9600);

while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}

// you're connected now, so print out the status:
printWifiStatus();


Hall = "50";
Temp = "50";

data = "";
}

void loop(){

currentMillis = millis();
if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
previousMillis = currentMillis;
Hall ="50"; //String(analog_val);
Temp ="50"; //String(sensor);

}

data = "temp1=" + Hall + "&hum1=" + Temp;
client.flush();
if (client.connect(server,80)) { // REPLACE WITH YOUR SERVER ADDRESS
Serial.println("Connected");
client.println("POST project/add.php HTTP/1.1");
client.println("Host: 192.168.164.101"); // SERVER ADDRESS HERE TOO
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
}

if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
client.flush();
}

delay(7000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}

void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

最佳答案

尝试使用 GET 请求,而不是 POST 命令。

POST project/add.php 更改为 GET/project/add.php?

关于无法使用 Arduino Wifi-Shield 连接到本地服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31051904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com