UnixTime не работает с компилятором ESP32

mrcheat

✩✩✩✩✩✩✩
7 Июн 2023
2
0
Russia
dupix.art
Приветствую, пытаюсь сделать преобразование даты/времени из Unix Timestamp в какой-то читабельный обьект.
Собираю прошивку под ESP32. Установил библиотеку - сделал все по примеру - не собирается.

Код:
In file included from E:\Document\Arduino\BasicHttpClient\BasicHttpClient.ino:1:
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:22:21: error: expected ')' before 'gmt'
     UnixTime (int8_t gmt) {
              ~      ^~~~
                     )
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:27:5: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
     uint32_t getUnix() {
     ^~~~~~~~
     char32_t
In file included from E:\Document\Arduino\BasicHttpClient\BasicHttpClient.ino:1:
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:40:22: error: 'uint32_t' has not been declared
     void getDateTime(uint32_t t) {
                      ^~~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:83:22: error: 'uint16_t' has not been declared
     void setDateTime(uint16_t nyear, uint8_t nmonth, uint8_t nday, uint8_t nhour, uint8_t nminute, uint8_t nsecond) {
                      ^~~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:83:38: error: 'uint8_t' has not been declared
     void setDateTime(uint16_t nyear, uint8_t nmonth, uint8_t nday, uint8_t nhour, uint8_t nminute, uint8_t nsecond) {
                                      ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:83:54: error: 'uint8_t' has not been declared
     void setDateTime(uint16_t nyear, uint8_t nmonth, uint8_t nday, uint8_t nhour, uint8_t nminute, uint8_t nsecond) {
                                                      ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:83:68: error: 'uint8_t' has not been declared
     void setDateTime(uint16_t nyear, uint8_t nmonth, uint8_t nday, uint8_t nhour, uint8_t nminute, uint8_t nsecond) {
                                                                    ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:83:83: error: 'uint8_t' has not been declared
     void setDateTime(uint16_t nyear, uint8_t nmonth, uint8_t nday, uint8_t nhour, uint8_t nminute, uint8_t nsecond) {
                                                                                   ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:83:100: error: 'uint8_t' has not been declared
     void setDateTime(uint16_t nyear, uint8_t nmonth, uint8_t nday, uint8_t nhour, uint8_t nminute, uint8_t nsecond) {
                                                                                                    ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:93:5: error: 'uint16_t' does not name a type; did you mean 'char16_t'?
     uint16_t year;
     ^~~~~~~~
     char16_t
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:94:5: error: 'uint8_t' does not name a type
     uint8_t month;
     ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:95:5: error: 'uint8_t' does not name a type
     uint8_t day;
     ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:96:5: error: 'uint8_t' does not name a type
     uint8_t hour;
     ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:97:5: error: 'uint8_t' does not name a type
     uint8_t minute;
     ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:98:5: error: 'uint8_t' does not name a type
     uint8_t second;
     ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:99:5: error: 'uint8_t' does not name a type
     uint8_t dayOfWeek;
     ^~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:102:5: error: 'int8_t' does not name a type; did you mean 'int'?
     int8_t _gmt = 0;
     ^~~~~~
     int
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h: In member function 'void UnixTime::getDateTime(int)':
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:41:9: error: 'uint32_t' was not declared in this scope
         uint32_t a, b, c, d, e, f;
         ^~~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:41:9: note: suggested alternative: 'char32_t'
         uint32_t a, b, c, d, e, f;
         ^~~~~~~~
         char32_t
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:44:14: error: '_gmt' was not declared in this scope
         t += _gmt * 3600;
              ^~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:45:9: error: 'second' was not declared in this scope
         second = t % 60ul;
         ^~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:47:9: error: 'minute' was not declared in this scope
         minute = t % 60ul;
         ^~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:47:9: note: suggested alternative: 'int'
         minute = t % 60ul;
         ^~~~~~
         int
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:49:9: error: 'hour' was not declared in this scope
         hour = t % 24ul;
         ^~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:52:9: error: 'a' was not declared in this scope
         a = (uint32_t)((4ul * t + 102032) / 146097 + 15);
         ^
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:53:9: error: 'b' was not declared in this scope
         b = (uint32_t)(t + 2442113 + a - (a / 4));
         ^
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:54:9: error: 'c' was not declared in this scope
         c = (20 * b - 2442) / 7305;
         ^
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:55:9: error: 'd' was not declared in this scope
         d = b - 365 * c - (c / 4);
         ^
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:56:9: error: 'e' was not declared in this scope
         e = d * 1000 / 30601;
         ^
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:57:9: error: 'f' was not declared in this scope
         f = d - e * 30 - e * 601 / 1000;
         ^
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:68:9: error: 'year' was not declared in this scope
         year = c;
         ^~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:68:9: note: suggested alternative: 'char'
         year = c;
         ^~~~
         char
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:69:9: error: 'month' was not declared in this scope
         month = e;
         ^~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:70:9: error: 'day' was not declared in this scope
         day = f;
         ^~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:79:9: error: 'dayOfWeek' was not declared in this scope
         dayOfWeek = ((h + 5) % 7) + 1;
         ^~~~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h: In member function 'void UnixTime::setDateTime(int, int, int, int, int, int)':
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:84:9: error: 'year' was not declared in this scope
         year = nyear;
         ^~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:84:9: note: suggested alternative: 'nyear'
         year = nyear;
         ^~~~
         nyear
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:85:9: error: 'month' was not declared in this scope
         month = nmonth;
         ^~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:85:9: note: suggested alternative: 'nmonth'
         month = nmonth;
         ^~~~~
         nmonth
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:86:9: error: 'day' was not declared in this scope
         day = nday;
         ^~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:86:9: note: suggested alternative: 'nday'
         day = nday;
         ^~~
         nday
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:87:9: error: 'hour' was not declared in this scope
         hour = nhour;
         ^~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:87:9: note: suggested alternative: 'nhour'
         hour = nhour;
         ^~~~
         nhour
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:88:9: error: 'minute' was not declared in this scope
         minute = nminute;
         ^~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:88:9: note: suggested alternative: 'nminute'
         minute = nminute;
         ^~~~~~
         nminute
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:89:9: error: 'second' was not declared in this scope
         second = nsecond;
         ^~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:89:9: note: suggested alternative: 'nsecond'
         second = nsecond;
         ^~~~~~
         nsecond
E:\Document\Arduino\BasicHttpClient\BasicHttpClient.ino: At global scope:
BasicHttpClient:9:17: error: no matching function for call to 'UnixTime::UnixTime(int)'
UnixTime stamp(3);  // указать GMT (3 для Москвы)
                 ^
In file included from E:\Document\Arduino\BasicHttpClient\BasicHttpClient.ino:1:
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:19:7: note: candidate: 'constexpr UnixTime::UnixTime()'
class UnixTime {
       ^~~~~~~~
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:19:7: note:   candidate expects 0 arguments, 1 provided
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:19:7: note: candidate: 'constexpr UnixTime::UnixTime(const UnixTime&)'
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:19:7: note:   no known conversion for argument 1 from 'int' to 'const UnixTime&'
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:19:7: note: candidate: 'constexpr UnixTime::UnixTime(UnixTime&&)'
E:\Document\Arduino\libraries\UnixTime\src/UnixTime.h:19:7: note:   no known conversion for argument 1 from 'int' to 'UnixTime&&'
E:\Document\Arduino\BasicHttpClient\BasicHttpClient.ino: In function 'void loop()':
BasicHttpClient:46:30: error: 'class UnixTime' has no member named 'hour'
     USE_SERIAL.println(stamp.hour);
                              ^~~~
BasicHttpClient:47:30: error: 'class UnixTime' has no member named 'minute'
     USE_SERIAL.println(stamp.minute);
                              ^~~~~~
BasicHttpClient:48:30: error: 'class UnixTime' has no member named 'second'
     USE_SERIAL.println(stamp.second);
                              ^~~~~~
Несколько библиотек найдено для "UnixTime.h"
Используется: E:\Document\Arduino\libraries\UnixTime
Не используется: E:\Document\Arduino\libraries\UnixTime-main
Несколько библиотек найдено для "WiFi.h"
Используется: C:\Users\admin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\libraries\WiFi
Не используется: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
no matching function for call to 'UnixTime::UnixTime(int)'

Если кратко - no matching function for call to 'UnixTime::UnixTime(int)'
и.. на этом все.

Я так и не понял - проблема в моем коде, или в самой библиотеке?

Код:
Код:
#include <UnixTime.h>
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
#define USE_SERIAL Serial
WiFiMulti wifiMulti;
UnixTime stamp(3);  // указать GMT (3 для Москвы)

String prevtime = "";
int globaltime = 0;

void setup() {
    USE_SERIAL.begin(115200);
    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }
    wifiMulti.addAP("wifi", "password");
}

String gettime(){
  HTTPClient http;
  http.begin("http://worldtimeapi.org/api/timezone/Europe/Moscow");
  int httpCode = http.GET();
  if(httpCode == HTTP_CODE_OK) {
    String payload = http.getString();
    try{
      JSONVar date = JSON.parse(payload);
      prevtime = JSON.stringify(date["unixtime"]);
      return prevtime;
    }catch(int e){ return prevtime; }
  }
  http.end();
  return prevtime;
}

void loop() {
  if((wifiMulti.run() == WL_CONNECTED)) {
    if (globaltime == 0){
      globaltime = gettime().toInt();
    }
    stamp.getDateTime(globaltime);
    USE_SERIAL.println(stamp.hour);
    USE_SERIAL.println(stamp.minute);
    USE_SERIAL.println(stamp.second);
    globaltime+=1;
    delay(1000);
  }
}
Как можно решить эту проблему? Заранее спасибо.
 

bort707

★★★★★★✩
21 Сен 2020
3,075
915
Читайте сообщение об ошибке, в библиотеке Unixtime нет конструктора с 1 параметром. Что делать - либо заглянуть в исходник либы и посмотреть, какой должен быть синтаксис, либо, если для вас это темный лес - искать именно ту либу, что использовал автор кода
 

mrcheat

✩✩✩✩✩✩✩
7 Июн 2023
2
0
Russia
dupix.art
@bort707, я и читаю, сурсы библиотеки я почитал.. там всё есть. и этот конструктор - пример от библиотеки,я не думаю что ошибка в примерах есть
 

vortigont

★★★★★★✩
24 Апр 2020
1,022
543
Saint-Petersburg, Russia
отдельные библиотеки не нужны

C++:
time_t _now;    // unixtime
time(&_now);

const tm* t = localtime(&_now);

Serial.printf("HH:%d mm:%s ss:%d", t->tm_hour,t->tm_min,t->tm_sec);