我是Arduino的新手,今天我尝试用我的TTGO板连接到WiFi,并从URL获取数据。它正确地连接到WiFi,从URL获取数据,但10秒后所有数据消失。
我理解这是由于tft.fillScreen(TFT_GREY);命令而发生的,但我不明白为什么函数不能继续,在该命令之后还有其他命令来获取数据和打印数据的命令。
我的计划是每10秒刷新一次URL中的数据。
我的代码:
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
#define TFT_GREY 0x5AEB // New colour
const char* ssid = "MyNetwork";
const char* password = "password";
int number = 10;
void setup(void) {
tft.init();
tft.setRotation(1);
delay(4000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
tft.println("Connecting to WiFi..");
}
tft.println("Connected to the WiFi network");
}
void loop() {
refreshData();
}
void refreshData ()
{
// Fill screen with grey so we can see the effect of printing with and without
// a background colour defined
tft.fillScreen(TFT_GREY);
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin("http://example.com"); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
//tft.println(httpCode);
tft.print(payload);
}
else {
tft.println("Error on HTTP request");
}
http.end(); //Free the resources
}
number ++;
delay(10000);
}谢谢!
发布于 2021-12-12 00:53:29
我没有意识到的问题是,所有新的数据都会从显示中消失,所以每次需要通过tft.setCursor();设置光标时
https://stackoverflow.com/questions/70319824
复制相似问题