MCU Temp Usermod
This commit is contained in:
122
usermods/mcu_temp/mcuTemp.h
Normal file
122
usermods/mcu_temp/mcuTemp.h
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "wled.h"
|
||||||
|
|
||||||
|
// class name. Use something descriptive and leave the ": public Usermod" part :)
|
||||||
|
class mcuTemp : public Usermod
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
float mcutemp = 0;
|
||||||
|
|
||||||
|
// any private methods should go here (non-inline methosd should be defined out of class)
|
||||||
|
void publishMqtt(const char *state, bool retain = false); // example for publishing MQTT message
|
||||||
|
|
||||||
|
public:
|
||||||
|
mcuTemp(const char *name, bool enabled) : Usermod(name, enabled) {} // WLEDMM
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void connected()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// if usermod is disabled or called during strip updating just exit
|
||||||
|
// NOTE: on very long strips strip.isUpdating() may always return true so update accordingly
|
||||||
|
if (!enabled || strip.isUpdating())
|
||||||
|
return;
|
||||||
|
|
||||||
|
#ifdef ESP8266 // ESP8266
|
||||||
|
// does not seem possible
|
||||||
|
mcutemp = -1;
|
||||||
|
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // ESP32S2
|
||||||
|
mcutemp = -1;
|
||||||
|
#else // ESP32 ESP32S3 and ESP32C3
|
||||||
|
mcutemp = roundf(temperatureRead() * 100) / 100;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (millis() - lastTime > 10000)
|
||||||
|
{
|
||||||
|
char array[10];
|
||||||
|
snprintf(array, sizeof(array), "%f", mcutemp);
|
||||||
|
publishMqtt(array);
|
||||||
|
lastTime = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
||||||
|
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
|
||||||
|
* Below it is shown how this could be used for e.g. a light sensor
|
||||||
|
*/
|
||||||
|
void addToJsonInfo(JsonObject &root)
|
||||||
|
{
|
||||||
|
// if "u" object does not exist yet wee need to create it
|
||||||
|
JsonObject user = root["u"];
|
||||||
|
if (user.isNull())
|
||||||
|
user = root.createNestedObject("u");
|
||||||
|
|
||||||
|
// this code adds "u":{"ExampleUsermod":[20," lux"]} to the info object
|
||||||
|
// int reading = 20;
|
||||||
|
JsonArray lightArr = user.createNestedArray(FPSTR(_name)); // name
|
||||||
|
lightArr.add(mcutemp); // value
|
||||||
|
lightArr.add(F(" °C")); // unit
|
||||||
|
|
||||||
|
// if you are implementing a sensor usermod, you may publish sensor data
|
||||||
|
// JsonObject sensor = root[F("sensor")];
|
||||||
|
// if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
|
||||||
|
// temp = sensor.createNestedArray(F("light"));
|
||||||
|
// temp.add(reading);
|
||||||
|
// temp.add(F("lux"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void addToJsonState(JsonObject &root)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void readFromJsonState(JsonObject &root)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void addToConfig(JsonObject &root)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readFromConfig(JsonObject &root)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendConfigData()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleOverlayDraw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).
|
||||||
|
* This could be used in the future for the system to determine whether your usermod is installed.
|
||||||
|
*/
|
||||||
|
uint16_t getId()
|
||||||
|
{
|
||||||
|
return USERMOD_ID_MCUTEMP;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void mcuTemp::publishMqtt(const char *state, bool retain)
|
||||||
|
{
|
||||||
|
#ifndef WLED_DISABLE_MQTT
|
||||||
|
// Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
|
if (WLED_MQTT_CONNECTED)
|
||||||
|
{
|
||||||
|
char subuf[64];
|
||||||
|
strcpy(subuf, mqttDeviceTopic);
|
||||||
|
strcat_P(subuf, PSTR("/mcutemp"));
|
||||||
|
mqtt->publish(subuf, 0, retain, state);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
11
usermods/mcu_temp/readme.md
Normal file
11
usermods/mcu_temp/readme.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# MCU Temp Usermod
|
||||||
|
This usermod adds the temperature readout to the Info tab and also publishes that over the topic `mcutemp` topic.
|
||||||
|
|
||||||
|
|
||||||
|
A shown temp of 53,33°C might indicate that the internal temp is not supported.
|
||||||
|
|
||||||
|
ESP8266 does not have a internal temp sensor
|
||||||
|
|
||||||
|
ESP32S2 seems to crash on reading the sensor -> disabled
|
||||||
|
|
||||||
|
Buildflag: `-D USERMOD_MCUTEMP`
|
||||||
@@ -133,6 +133,7 @@
|
|||||||
#define USERMOD_ID_SHT 39 //Usermod "usermod_sht.h
|
#define USERMOD_ID_SHT 39 //Usermod "usermod_sht.h
|
||||||
#define USERMOD_ID_KLIPPER 40 // Usermod Klipper percentage
|
#define USERMOD_ID_KLIPPER 40 // Usermod Klipper percentage
|
||||||
//WLEDMM
|
//WLEDMM
|
||||||
|
#define USERMOD_ID_MCUTEMP 89 //Usermod "usermod_v2_artifx.h"
|
||||||
#define USERMOD_ID_ARTIFX 90 //Usermod "usermod_v2_artifx.h"
|
#define USERMOD_ID_ARTIFX 90 //Usermod "usermod_v2_artifx.h"
|
||||||
#define USERMOD_ID_WEATHER 91 //Usermod "usermod_v2_weather.h"
|
#define USERMOD_ID_WEATHER 91 //Usermod "usermod_v2_weather.h"
|
||||||
#define USERMOD_ID_GAMES 92 //Usermod "usermod_v2_games.h"
|
#define USERMOD_ID_GAMES 92 //Usermod "usermod_v2_games.h"
|
||||||
|
|||||||
@@ -173,6 +173,10 @@
|
|||||||
#include "../usermods/boblight/boblight.h"
|
#include "../usermods/boblight/boblight.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USERMOD_MCUTEMP
|
||||||
|
#include "../usermods/mcu_temp/mcuTemp.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WLED_USE_SD_MMC) || defined(WLED_USE_SD_SPI)
|
#if defined(WLED_USE_SD_MMC) || defined(WLED_USE_SD_SPI)
|
||||||
// This include of SD.h and SD_MMC.h must happen here, else they won't be
|
// This include of SD.h and SD_MMC.h must happen here, else they won't be
|
||||||
// resolved correctly (when included in mod's header only)
|
// resolved correctly (when included in mod's header only)
|
||||||
@@ -377,6 +381,10 @@ void registerUsermods()
|
|||||||
usermods.add(new ShtUsermod("SHT-Sensor", false));
|
usermods.add(new ShtUsermod("SHT-Sensor", false));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USERMOD_MCUTEMP
|
||||||
|
usermods.add(new mcuTemp("MCUTemp", true));
|
||||||
|
#endif
|
||||||
|
|
||||||
// WLEDMM ARTIFX
|
// WLEDMM ARTIFX
|
||||||
#ifdef USERMOD_ARTIFX
|
#ifdef USERMOD_ARTIFX
|
||||||
usermods.add(new ARTIFXUserMod());
|
usermods.add(new ARTIFXUserMod());
|
||||||
|
|||||||
Reference in New Issue
Block a user