build for esp32 mask project
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#ifdef BOARD_ESP32
|
||||
#include <WiFi.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <time.h>
|
||||
#elif defined(BOARD_ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
@@ -11,16 +13,23 @@
|
||||
#include <ctime>
|
||||
|
||||
WiFiUDP wifiUdp;
|
||||
NTPClient timeClient(wifiUdp, "pool.ntp.org", 3600 * -7);
|
||||
//NTPClient timeClient(wifiUdp, "pool.ntp.org", 3600 * -7);
|
||||
NTPClient timeClient(wifiUdp, "10.0.0.1", 3600 * -7);
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_PHOTON
|
||||
STARTUP(BootOptions::initPins());
|
||||
#else
|
||||
#include "platform/arduino/MQTTTelemetry.h"
|
||||
void printNewline(Print* logOutput) {
|
||||
void printNewline(Print* logOutput)
|
||||
{
|
||||
logOutput->print("\r\n");
|
||||
}
|
||||
int printEspLog(const char* fmt, va_list args)
|
||||
{
|
||||
Log.notice(fmt, args);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int Platform::s_timezone = 0;
|
||||
@@ -30,6 +39,10 @@ Platform::name()
|
||||
{
|
||||
#ifdef PLATFORM_PHOTON
|
||||
return "Photon";
|
||||
#elif defined(BOARD_ESP8266)
|
||||
return "ESP8266";
|
||||
#elif defined(BOARD_ESP32)
|
||||
return "ESP32";
|
||||
#else
|
||||
return "Unknown!";
|
||||
#endif
|
||||
@@ -40,6 +53,8 @@ Platform::version()
|
||||
{
|
||||
#ifdef PLATFORM_PHOTON
|
||||
return System.version().c_str();
|
||||
#elif defined(BOARD_ESP32)
|
||||
return ESP.getSdkVersion();
|
||||
#else
|
||||
return "Unknown!";
|
||||
#endif
|
||||
@@ -49,6 +64,7 @@ void
|
||||
Platform::preSetup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(5000);
|
||||
#ifdef PLATFORM_PHOTON
|
||||
System.enableFeature(FEATURE_RETAINED_MEMORY);
|
||||
if (bootopts.isFlash) {
|
||||
@@ -65,6 +81,15 @@ Platform::preSetup()
|
||||
Log.begin(LOG_LEVEL_VERBOSE, Static<MQTTTelemetry>::instance()->logPrinter());
|
||||
Log.setSuffix(printNewline);
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_ESP32
|
||||
esp_task_wdt_init(10, true);
|
||||
esp_task_wdt_add(NULL);
|
||||
esp_log_set_vprintf(printEspLog);
|
||||
#endif
|
||||
#ifdef BOARD_ESP8266
|
||||
ESP.wdtEnable(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -95,7 +120,12 @@ void
|
||||
Platform::loop()
|
||||
{
|
||||
#ifdef BOARD_ESP8266
|
||||
timeClient.update();
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
timeClient.update();
|
||||
}
|
||||
ESP.wdtFeed();
|
||||
#elif defined(BOARD_ESP32)
|
||||
esp_task_wdt_reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -110,9 +140,12 @@ Platform::getLocalTime(struct tm* timedata)
|
||||
}
|
||||
return false;
|
||||
#elif defined(BOARD_ESP32)
|
||||
return getLocalTime(timedata);
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
(*timedata) = (*localtime(&rawtime));
|
||||
return (timedata->tm_year > (2016-1990));
|
||||
//return getLocalTime(timedata);
|
||||
#else
|
||||
timeClient.update();
|
||||
timedata->tm_hour = timeClient.getHours();
|
||||
timedata->tm_min = timeClient.getMinutes();
|
||||
return true;
|
||||
@@ -137,3 +170,5 @@ Platform::bootopts;
|
||||
|
||||
char
|
||||
Platform::s_deviceID[15];
|
||||
|
||||
STATIC_ALLOC(Platform);
|
||||
|
Reference in New Issue
Block a user