HASwitchPlate / openHASP

HomeAutomation Switchplate based on lvgl for ESP32
https://www.openhasp.com
MIT License
695 stars 179 forks source link

Why ‘openHASP\src\my_custom.cpp’ not work #735

Closed XiaoTuXing closed 4 months ago

XiaoTuXing commented 4 months ago
openHASP\include\user_config_override.h
`#define HASP_USE_CUSTOM 1                           // Enable compilation of custom code from /src/custom`

openHASP\src\my_custom.cpp’
`/* MIT License - Copyright (c) 2019-2024 Francis Van Roie
   For full license information read the LICENSE file in the project folder */

// USAGE: - Copy this file and rename it to my_custom.cpp
//        - Change false to true on line 9

#include "hasplib.h"

#if defined(HASP_USE_CUSTOM) && true // <-- set this to true in your code

#include "hasp_debug.h"
#include "my_custom.h"
void custom_setup()
{
    // Initialization code here
    randomSeed(millis());
}

void custom_loop()
{
    // Non-blocking code here, this should execute very fast!
    Serial.print("temp_custom_loop");
}

void custom_every_second()
{
    Serial.print("#");
}

void custom_every_5seconds()
{
    LOG_VERBOSE(TAG_CUSTOM, "5 seconds have passsed...");
    dispatch_state_subtopic("my_sensor","{\"test\":123}");
}

bool custom_pin_in_use(uint8_t pin)
{
    if(pin == 1024) return true; // fictuous used pin

    // otherwise the pin is not used
    return false;
}

void custom_get_sensors(JsonDocument& doc)
{
    /* Sensor Name */
    JsonObject sensor = doc.createNestedObject(F("Custom"));

    /* Key-Value pair of the sensor value */
    sensor[F("Random")] = HASP_RANDOM(256);
}

void custom_topic_payload(const char* topic, const char* payload, uint8_t source){
    // Not used
}

#endif // HASP_USE_CUSTOM`
marsman7 commented 4 months ago

What does not work?

my_custom_template.cpp is in openHASP/src/custom/. Is your my_custom.cpp and my_custom.h in openHASP/src/custom/?

Have you read the comment in 'custom_loop()'? Serial.print is not good for "Non-blocking code here, this should execute very fast!".