如何使用ESP8266每小时将数据发送到数据库?

发布于 2025-01-27 03:10:16 字数 71 浏览 5 评论 0原文

我想用我的ESP8266将小时数据发送到数据库。但是,我不知道如何完全每小时发送数据。我不想使用delay()。有人可以帮我吗?

I would like to send hourly data to a database with my ESP8266. However, I don't know how to send the data exactly every hour. I don't want to use delay(). Can someone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅忆 2025-02-03 03:10:16

这是草图的骨骼,用于从Internet中带有ESP8266进入内部RTC的时间,将时间设置为Timelib,并使用Timelib的minute()函数在HH:00上执行某些内容。

#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <sntp.h>
#include <TZ.h>

#define TIME_ZONE TZ_Europe_London

bool doneSending = false; // flag to send only once in the first minute of the hour

void setup() {

  WiFi.begin(ssid, pass);

  configTime(TIME_ZONE, "pool.ntp.org");
  time_t now = time(nullptr);
  while (now < SECS_YR_2000) { // why until time is retrieve from Internet
    delay(100);
    now = time(nullptr);
  }
  setTime(now); // set the time into TimeLib
}

void loop() {
  if (minute() == 0) { // it is hh:00
    if (!doneSending) {
      sendData();
      doneSending= true;
    }
  } else if (doneSending) {
    doneSending = false; // reset after the :00 minute is over
  }
}

this is a skeleton of a sketch for retrieving time from Internet with the esp8266 into the internal RTC, set the time into the TimeLib and use TimeLib's minute() function to execute something at hh:00.

#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <sntp.h>
#include <TZ.h>

#define TIME_ZONE TZ_Europe_London

bool doneSending = false; // flag to send only once in the first minute of the hour

void setup() {

  WiFi.begin(ssid, pass);

  configTime(TIME_ZONE, "pool.ntp.org");
  time_t now = time(nullptr);
  while (now < SECS_YR_2000) { // why until time is retrieve from Internet
    delay(100);
    now = time(nullptr);
  }
  setTime(now); // set the time into TimeLib
}

void loop() {
  if (minute() == 0) { // it is hh:00
    if (!doneSending) {
      sendData();
      doneSending= true;
    }
  } else if (doneSending) {
    doneSending = false; // reset after the :00 minute is over
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文