首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >10秒后,Arduino互联网数据消失。

10秒后,Arduino互联网数据消失。
EN

Stack Overflow用户
提问于 2021-12-11 23:33:01
回答 1查看 30关注 0票数 0

我是Arduino的新手,今天我尝试用我的TTGO板连接到WiFi,并从URL获取数据。它正确地连接到WiFi,从URL获取数据,但10秒后所有数据消失。

我理解这是由于tft.fillScreen(TFT_GREY);命令而发生的,但我不明白为什么函数不能继续,在该命令之后还有其他命令来获取数据和打印数据的命令。

我的计划是每10秒刷新一次URL中的数据。

我的代码:

代码语言:javascript
复制
#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); 
}

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-12-12 00:53:29

我没有意识到的问题是,所有新的数据都会从显示中消失,所以每次需要通过tft.setCursor();设置光标时

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70319824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档