제목이 잘못되었거나 오도 된 사람은 누구나 언제든지 업데이트하십시오.Arduino - WiFi 클라이언트가 작동하지 않는 지연 루프 없음
내가 가지고있는 문제는 내 Uno R3 및 WiFi Shield입니다. 난 정말 지금 정확한 소스를 공유 할 수 있지만, 이것은 꽤 잘 문제를 설명합니다 :
#include <WiFi.h>
#include <SPI.h>
#include <Ethernet.h>
char httpHost[] = "my.local.site.com";
IPAddress server(192,168,1,10);
int serverPort = 80;
char ssid[] = "myssid";
char password[] = "abcd123456";
int thingy = 0;
float lastTick = 0;
float tickInterval = 30000;
WiFiClient client;
boolean lastConnected = false;
void setup()
{
Serial.begin(9600);
connectWifi();
pinMode(2, INPUT);
}
void loop()
{
float currentMillis = millis();
if (currentMillis >= (lastTick + tickInterval) || currentMillis < lastTick) {
pollThingy();
logUpdate();
lastTick = currentMillis;
}
while (client.available()) {
char c = client.read();
Serial.print(c);
}
if (client.connected() == false && lastConnected == true) {
Serial.println("-- Disconnected.");
client.stop();
}
lastConnected = client.connected();
if (lastConnected == true) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}
void connectWifi()
{
int status = WL_IDLE_STATUS;
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("No WiFi Shield Found! Aborting!");
while(true) { }
}
int i = 0;
while(true) {
Serial.print("Attempting to connect to network: ");
Serial.print(ssid);
Serial.print(" Attempt #");
Serial.println(++i);
status = WiFi.begin(ssid, password);
if (status == WL_CONNECTED) break;
delay(10000);
}
if (status == WL_CONNECTED) {
Serial.println("Connected!");
} else {
Serial.println("Failed connecting! Aborting!");
while(true) { }
}
}
void pollThingy()
{
thingy = digitalRead(2);
}
void logUpdate()
{
Serial.println("Logging update: ");
if (client.connected() == false) {
Serial.print("-- Connecting to ");
Serial.print(server);
Serial.print(":");
Serial.println(serverPort);
if (client.connect(server, serverPort)) {
Serial.println(" Connected!");
client.print("GET /some/Uri/with/arguments?output=json HTTP/1.1");
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(httpHost);
client.println("Connection: close");
client.println();
} else {
Serial.println(" Connection failed!");
}
} else {
Serial.println("-- Already connected... Skipping, this time...");
}
}
지금 내가 데 문제가 좀 미친 것 같다. 이것은 정상적으로 작동하고 예상 된대로 매 30 초마다 주어진 엔드 포인트에 대한 갱신 사항을 기록합니다. 그러나, 약 2 시간 후에 그것은 단지 실속하고 다시는 아무것도하지 못합니다. 마지막으로 예상 한
Serial.println()
문 이외의 것을 반환하는 직렬 모니터를 보았지만 표시 할 오류가 없거나 아무것도 없습니다.
나는 그것을 얻은 이후로 WiFi 방패의 펌웨어를 업데이트하지 않았으며 솔직하게 어떤 개정판이 실행 중인지 말할 수 없었습니다. 그러나, 나는 이것이 완전히 다른 무엇인가라고 느낀다. 그리고 나는 단지 그것에 나의 손가락을 댈 수 없다.
누구든지 조언을 해줄 수 있습니까?
제 코드 스타일에 대해 너무 많이 괴롭히지 마십시오. 이것은 단지 초안 일뿐입니다.
2 시간 장애 지점이 의심 스럽습니다. 2 시간 30 초마다 240x로 256에 가깝습니다. 8 비트 변수가 넘칠 수 있습니까? BTW, 무슨 와이파이 라이브러리와 방패를 사용하고 계십니까? – HM1