Closed imoldovavan closed 4 years ago
Please post your source code.
I used the code from DynamicPage example and insert it into may code. Lines 13-20;76-144;436-450;456 I am using an esp32 from TTGO with display https://github.com/Xinyuan-LilyGO/TTGO-T-Display
`
TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library
Button2 btn1(BUTTON_1); Button2 btn2(BUTTON_2); Button2 lidswitch(LIDSWITCH);
char buff[512]; int vref = 1100; int btnCick = false; int btn2Click = false; int lidclosed = false; int runcyclefirststart = true; int runcyclestart = false; int stopcyclefirstrun = true; float cooktemp = 150;
static uint64_t runtimeStamp = 0;
// GPIO where the DS18B20 is connected to const int oneWireBus = 17;
// Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire);
//Motor relay setup int motorRelay = 33; volatile byte relayState = LOW;
//////////
// Modify according to your Wi-Fi environment.
ESP8266WebServer server;
WebServer server;
PageElement elm; PageBuilder page; String currentUri;
// The root page content builder String rootPage(PageArgument& args) { return String(F("This is root page.")); }
// The hello page content builder String helloPage(PageArgument& args) { return String(F("This is hello page.")); }
// This function creates dynamic web page by each request. // It is called twice at one time URI request that caused by the structure // of ESP8266WebServer class. bool handleAcs(HTTPMethod method, String uri) { if (uri == currentUri) { // Page is already prepared. return true; } else { currentUri = uri; page.clearElement(); // Discards the remains of PageElement. page.addElement(elm); // Register PageElement for current access.
Serial.println("Request:" + uri);
if (uri == "/") { // for the / page
page.setUri(uri.c_str());
elm.setMold(PSTR(
"<html>"
"<body>"
"<h2>{{ROOT}}</h2>"
"</body>"
"</html>"));
elm.addToken("ROOT", rootPage);
return true;
}
else if (uri == "/hello") { // for the /hello page
page.setUri(uri.c_str());
elm.setMold(PSTR(
"<html>"
"<body>"
"<p style=\"color:Tomato;\">{{HELLO}}</p>"
"</body>"
"</html>"));
elm.addToken("HELLO", helloPage);
return true;
}
else {
return false; // Not found to accessing exception URI.
}
} }
/////////
//! Long time delay, it is recommended to use shallow sleep, which can effectively reduce the current consumption
void espDelay(int ms)
{
esp_sleep_enable_timer_wakeup(ms * 1000);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH,ESP_PD_OPTION_ON);
esp_light_sleep_start();
}
void showVoltage() { static uint64_t timeStamp = 0; if (millis() - timeStamp > 1000) { timeStamp = millis(); uint16_t v = analogRead(ADC_PIN); float battery_voltage = ((float)v / 4095.0) 2.0 3.3 * (vref / 1000.0); String voltage = String(battery_voltage) + "V"; //Serial.println(voltage); tft.setTextColor(TFT_GREEN, TFT_BLACK); tft.drawString("Voltage", tft.width() / 2, tft.height() / 4 ); tft.setTextFont(7); tft.setTextSize(1); tft.drawString(voltage, tft.width() / 2, tft.height() / 1.5 ); tft.setTextFont(4); tft.setTextSize(2); } }
void showTemperature() { static uint64_t timeStamp = 0;
if (millis() - timeStamp > 1000) {
timeStamp = millis();
sensors.requestTemperatures();
//float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
//Serial.print(temperatureF);
//Serial.println("ºC");
if(temperatureF > DEVICE_DISCONNECTED_F) {
//Serial.print(temperatureF);
//Serial.println("ºF");
String tempF = String(temperatureF) + "F";
tft.setTextFont(7);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setTextSize(1);
tft.drawString(tempF, tft.width() / 2, tft.height() / 1.5 );
tft.setTextSize(2);
}else{
//tft.drawString("Temp", tft.width() / 2, tft.height() / 4 );
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setTextFont(4);
tft.setTextSize(2);
tft.drawString("Discon", tft.width() / 2, tft.height() / 1.5 );
tft.setTextColor(TFT_GREEN, TFT_BLACK);
}
}
}
void runcycle(){ if (runcyclefirststart){ runtimeStamp = millis(); runcyclefirststart = false; stopcyclefirstrun = true; tft.setTextFont(4); tft.setTextSize(2); tft.drawString(" -Running- ", tft.width() / 2, tft.height() / 4 ); }
//tft.drawString(" Run ", tft.width() / 2, tft.height() / 4 );
//static uint64_t timeStamp = millis() - runtimeStamp;
if (millis() - runtimeStamp < 10000) { //turn motor on for 10 seconds digitalWrite(motorRelay, LOW); //tft.drawString(" Mtr On ", tft.width() / 2, tft.height() / 4 ); } else if ((millis() - runtimeStamp >= 10000) && (millis() - runtimeStamp < 20000)) { digitalWrite(motorRelay, HIGH); //tft.drawString(" Mtr Off ", tft.width() / 2, tft.height() / 4 ); } else if ((millis() - runtimeStamp >= 20000) && (millis() - runtimeStamp < 25000)) { sensors.requestTemperatures(); //float temperatureC = sensors.getTempCByIndex(0); float temperatureF = sensors.getTempFByIndex(0); if (temperatureF < cooktemp) { runcyclestart = true; runcyclefirststart = true; }else{ runcyclefirststart = true; runcyclestart = false; } } }
void stopcycle(){ if(!lidclosed && stopcyclefirstrun){ tft.setTextColor(TFT_RED, TFT_BLACK); tft.setTextFont(4); tft.setTextSize(2); tft.drawString("Lid Open", tft.width() / 2, tft.height() / 4 ); //tft.setTextColor(TFT_GREEN, TFT_BLACK); }
digitalWrite(motorRelay, HIGH); runtimeStamp = 0; runcyclefirststart = true; runcyclestart = false; stopcyclefirstrun = false;
}
void button_init() { btn1.setLongClickHandler([](Button2 & b) { Serial.println("Detect Voltage..."); btnCick = true; btn2Click = false; tft.fillScreen(TFT_BLACK); tft.setRotation(1); tft.setTextDatum(MC_DATUM); tft.setTextColor(TFT_GREEN, TFT_BLACK); //tft.setTextSize(5); // btnCick = false; // btn2Click = false; // int r = digitalRead(TFT_BL); // tft.fillScreen(TFT_BLACK); // tft.setTextColor(TFT_GREEN, TFT_BLACK); // tft.setTextDatum(MC_DATUM); // tft.setTextSize(3); // tft.drawString("Press again", tft.width() / 2, tft.height() / 4 ); // tft.drawString("to wake up", tft.width() / 2, tft.height() / 1.5 ); // espDelay(3000); // digitalWrite(TFT_BL, !r);
// tft.writecommand(TFT_DISPOFF);
// tft.writecommand(TFT_SLPIN);
// esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
// esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
// esp_deep_sleep_start();
});
btn1.setPressedHandler([](Button2 & b) {
if(lidclosed){
runcyclestart = true;
}else{
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setTextFont(4);
tft.setTextSize(2);
tft.drawString("-error Lid-", tft.width() / 2, tft.height() / 4 );
}
// Serial.println("Detect Voltage...");
// btnCick = true;
// btn2Click = false;
// tft.fillScreen(TFT_BLACK);
// tft.setRotation(1);
// tft.setTextDatum(MC_DATUM);
// tft.setTextColor(TFT_GREEN, TFT_BLACK);
// tft.setTextSize(5);
});
btn2.setPressedHandler([](Button2 & b) {
Serial.println("Detect Temp...");
btnCick = false;
btn2Click = true;
//tft.fillScreen(TFT_BLACK);
//tft.setRotation(1);
//tft.setTextDatum(MC_DATUM);
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setTextFont(4);
tft.setTextSize(2);
tft.drawString(" --Stoped-- ", tft.width() / 2, tft.height() / 4 );
//relayState = !relayState;
//digitalWrite(motorRelay, relayState);
runcyclestart = false;
// sensors.requestTemperatures();
// float temperatureC = sensors.getTempCByIndex(0);
// float temperatureF = sensors.getTempFByIndex(0);
// Serial.print(temperatureC);
// Serial.println("ºC");
// Serial.print(temperatureF);
// Serial.println("ºF");
// delay(5000);
});
lidswitch.setPressedHandler([](Button2 & b) {
Serial.println("Lid Closed...");
tft.setTextColor(TFT_GREEN,TFT_BLACK);
tft.setTextFont(4);
tft.setTextSize(2);
tft.drawString("Lid Closed", tft.width() / 2, tft.height() / 4 );
lidclosed = true;
});
lidswitch.setReleasedHandler([](Button2 & b) {
Serial.println("Lid Open");
tft.setTextColor(TFT_RED,TFT_BLACK);
tft.setTextFont(4);
tft.setTextSize(2);
tft.drawString("-Lid Open-", tft.width() / 2, tft.height() / 4 );
lidclosed = false;
});
}
void button_loop() { btn1.loop(); btn2.loop(); lidswitch.loop(); }
void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println("Start");
/ ADC_EN is the ADC detection enable port If the USB port is used for power supply, it is turned on by default. If it is powered by battery, it needs to be set to high level / pinMode(ADC_EN, OUTPUT); digitalWrite(ADC_EN, HIGH);
tft.init(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); tft.setTextSize(2); tft.setTextColor(TFT_GREEN); tft.setCursor(0, 0); tft.setTextDatum(MC_DATUM); tft.setTextSize(1);
//tft.loadFont(7); tft.setTextFont(7); //tft.setTextSize(1); if (TFT_BL > 0) { // TFT_BL has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); // Turn backlight on. TFT_BACKLIGHT_ON has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h }
tft.setSwapBytes(true); tft.pushImage(0, 0, 240, 135, mlogo); espDelay(2500);
tft.setRotation(0); //int i = 1; // while (i--) { // tft.fillScreen(TFT_RED); // espDelay(100); // tft.fillScreen(TFT_BLUE); // espDelay(100); // tft.fillScreen(TFT_GREEN); // espDelay(100); // }
button_init();
esp_adc_cal_characteristics_t adc_chars; esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC1_CHANNEL_6, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars); //Check type of calibration value used to characterize ADC if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) { Serial.printf("eFuse Vref:%u mV", adc_chars.vref); vref = adc_chars.vref; } else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) { Serial.printf("Two Point --> coeff_a:%umV coeff_b:%umV\n", adc_chars.coeff_a, adc_chars.coeff_b); } else { Serial.println("Default Vref: 1100mV"); }
// Start the DS18B20 sensor sensors.begin(); espDelay(500); tft.fillScreen(TFT_BLACK); tft.setRotation(1); tft.setTextDatum(MC_DATUM); tft.setTextColor(TFT_GREEN, TFT_BLACK); //tft.setTextSize(5); //tft.setTextFont(4); //tft.drawString("Temp", tft.width() / 2, tft.height() / 4 ); //showVoltage(); btn2Click = true;
// Pin for motor relay set as output pinMode(motorRelay, OUTPUT); digitalWrite(motorRelay, HIGH);
Serial.println("WiFi Starting up...");
WiFi.mode(WIFI_STA); delay(100); WiFi.begin(SSID, PSK); while (WiFi.waitForConnectResult() != WL_CONNECTED) { delay(100); }
// Prepare dynamic web page page.exitCanHandle(handleAcs); // Handles for all requests. page.insert(server);
// Start web server server.begin(); Serial.print("http server:"); Serial.println(WiFi.localIP()); }
void loop() {
server.handleClient();
if (btnCick) { showVoltage(); }
if (btn2Click) { showTemperature(); }
if (lidclosed && runcyclestart) { runcycle(); } else { stopcycle(); }
button_loop(); } `
My platformio.ini is this.
` ; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html
[env:ttgo-t1] platform = espressif32 board = esp32dev framework = arduino upload_protocol = esptool monitor_speed = 115200
lib_deps =
Button2
TFT_eSPI SPI
OneWire DallasTemperature
PageBuilder `
I started a blank project with only Pagebuilder library and the DynamicPage example and it compiled without errors. I will try to add the other libraries one at a time to see if I can replicate the error.
Here is a capture of the terminal. Maybe it helps.
Compiling .pio\build\ttgo-t1\src\main.cpp.o In file included from src\main.cpp:20:0: .pio/libdeps/ttgo-t1/PageBuilder_ID2010/src/PageBuilder.h: In constructor 'PageArgument::PageArgument()': .pio/libdeps/ttgo-t1/PageBuilder_ID2010/src/PageBuilder.h:68:38: error: call of overloaded 'unique_ptr(NULL)' is ambiguous PageArgument() : _arguments(nullptr) {} ^ In file included from c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\memory:81:0, from C:/Users/moljoh/.platformio/packages/framework-arduinoespressif32/libraries/FS/src/FS.h:24, from .pio/libdeps/ttgo-t1/TFT_eSPI_ID1559/Processors/TFT_eSPI_ESP32.h:52, from .pio/libdeps/ttgo-t1/TFT_eSPI_ID1559/TFT_eSPI.h:48, from src\main.cpp:2: c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:356:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>] <deleted> unique_ptr(const unique_ptr&) = delete; ^ c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:205:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>&&) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>] unique_ptr(unique_ptr&& __u) noexcept ^ c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:200:17: note: candidate: constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr(std::nullptr_t) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>; std::nullptr_t = std::nullptr_t] constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } ^ c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:169:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>; std::unique_ptr<_Tp, _Dp>::pointer = PageArgument::_RequestArgumentSL*] unique_ptr(pointer __p) noexcept ^ In file included from src\main.cpp:20:0: .pio/libdeps/ttgo-t1/PageBuilder_ID2010/src/PageBuilder.h: In constructor 'PageArgument::PageArgument(const String&, const String&)': .pio/libdeps/ttgo-t1/PageBuilder_ID2010/src/PageBuilder.h:69:76: error: call of overloaded 'unique_ptr(NULL)' is ambiguous PageArgument(const String& key, const String& value) : _arguments(nullptr) { push(key, value); } ^ In file included from c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\memory:81:0, from C:/Users/moljoh/.platformio/packages/framework-arduinoespressif32/libraries/FS/src/FS.h:24, from .pio/libdeps/ttgo-t1/TFT_eSPI_ID1559/Processors/TFT_eSPI_ESP32.h:52, from .pio/libdeps/ttgo-t1/TFT_eSPI_ID1559/TFT_eSPI.h:48, from src\main.cpp:2: c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:356:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>] <deleted> unique_ptr(const unique_ptr&) = delete; ^ c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:205:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>&&) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>] unique_ptr(unique_ptr&& __u) noexcept ^ c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:200:17: note: candidate: constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr(std::nullptr_t) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>; std::nullptr_t = std::nullptr_t] constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } ^ c:\users\moljoh\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits\unique_ptr.h:169:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = PageArgument::_RequestArgumentSL; _Dp = std::default_delete<PageArgument::_RequestArgumentSL>; std::unique_ptr<_Tp, _Dp>::pointer = PageArgument::_RequestArgumentSL*] unique_ptr(pointer __p) noexcept ^
@imoldovavan Thank you post. In the first place, an error is strange:
call of overloaded 'unique_ptr(NULL)' is ambiguous
^^^^
As you can see from the PageBuilder.h code, the PageBuilder constructor does not quote NULL
. It's nullptr
.
https://github.com/Hieromon/PageBuilder/blob/7da92afd67593b541d5efc700489567b82959b43/src/PageBuilder.h#L68
In the C ++ language standard, there is a clear definitional difference between NULL
and nullptr
. Refs: https://oopscenities.net/2011/06/17/c0x-nullptr/
However, some libraries importing unexamined legacy C code force nullptr
to be redefined to NULL
using like #define nullptr NULL
, which is a mistake. I suspect some library header files preceding the #include <PageBuilder.h>
directive defines nullptr as NULL.
To find the causes, you can try moving #include <WiFi.h>
, #include <WebServer.h>
and #include <PageBuilder.h>
to the beginning part of main.cpp. (but they should place after #include <Arduio.h>
)
I moved the Wifi, Webserver and PageBuilder includes after the Arduino and it compiled with no problems. `
`
Thank you for the suggestion. I have to remember this next time I run into these kind of problems
Close due to resolved.
I get an error compiling on Platformio in VSCode. Line 68 and 69 in Pagebuilder.h
PageArgument() : _arguments(nullptr) {} PageArgument(const String& key, const String& value) : _arguments(nullptr) { push(key, value); }
.pio/libdeps/ttgo-t1/PageBuilder_ID2010/src/PageBuilder.h:69:73: error: call of overloaded 'unique_ptr(NULL)' is ambiguous