4#include <Arduino_JSON.h> 
   67    Doctor(String name = 
"doctor") : name(name) {
 
   81        tID = pSched->
add([
this]() { this->loop(); }, name, 100000);  
 
   83        pSched->
subscribe(tID, name + 
"/#", [
this](String topic, String msg, String originator) {
 
   84            this->subsMsg(topic, msg, originator);
 
   91    void publishDiagnostics() {
 
   93#if defined(USTD_FEATURE_FREE_MEMORY) 
   94        diaginfo[
"free_memory"] = freeMemory();
 
   97        diaginfo[
"sdk_version"] = (
const char *)ESP.getSdkVersion();
 
   98        diaginfo[
"cpu_frequency"] = (int)ESP.getCpuFreqMHz();
 
   99        diaginfo[
"free_sketch_space"] = (int)ESP.getFreeSketchSpace();
 
  100        diaginfo[
"flash_size"] = (int)ESP.getFlashChipSize();
 
  101        diaginfo[
"flash_speed_mhz"] = (float)((
float)ESP.getFlashChipSpeed() / 1000000.0f);
 
  102        diaginfo[
"program_size"] = (int)ESP.getSketchSize();
 
  104        diaginfo[
"hardware"] = (
const char *)
"ESP32";
 
  105        diaginfo[
"chip_revision"] = (int)ESP.getChipRevision();
 
  107        diaginfo[
"hardware"] = (
const char *)
"ESP8266";
 
  108        diaginfo[
"chip_id"] = (int)ESP.getChipId();
 
  109        diaginfo[
"core_version"] = (
const char *)(ESP.getCoreVersion().c_str());
 
  110        diaginfo[
"flash_chip_id"] = (int)ESP.getFlashChipId();
 
  111        diaginfo[
"real_flash_size"] = (int)ESP.getFlashChipRealSize();
 
  112        diaginfo[
"last_reset_reason"] = (
const char *)(ESP.getResetReason().c_str());
 
  116#if defined(__ARDUINO__) 
  118        diaginfo[
"hardware"] = (
const char *)
"Arduino MEGA";
 
  119#elif defined(__UNO__) 
  120        diaginfo[
"hardware"] = (
const char *)
"Arduino UNO";
 
  122        diaginfo[
"hardware"] = (
const char *)
"Arduino unknown";
 
  126#if defined(__RISC_V__) 
  127        diaginfo[
"hardware"] = (
const char *)
"RISC-V";
 
  131        diaginfo[
"hardware"] = (
const char *)
"ARM";
 
  134        pSched->
publish(name + 
"/diagnostics", JSON.stringify(diaginfo));
 
  137#if defined(USTD_FEATURE_FREE_MEMORY) 
  138    void publishMemory() {
 
  139        int mem = freeMemory();
 
  140        pSched->
publish(name + 
"/memory", String(mem));
 
  144    void publishTimeinfo() {
 
  146#ifdef USTD_FEATURE_CLK_READ 
  147        time_t now = time(
nullptr);
 
  149        struct tm *plt = localtime(&now);
 
  150        strftime(szTime, 9, 
"%T", plt);
 
  151        timeinfo[
"time"] = (
const char *)szTime;
 
  152        strftime(szTime, 20, 
"%Y.%m.%d %H:%M:%S", plt);
 
  153        timeinfo[
"date"] = (
const char *)szTime;
 
  154        timeinfo[
"time_t"] = (long)time(
nullptr);
 
  156        timeinfo[
"uptime"] = (long)pSched->
getUptime();
 
  157        timeinfo[
"millis"] = millis();
 
  158        pSched->
publish(name + 
"/timeinfo", JSON.stringify(timeinfo));
 
  163#if defined(USTD_FEATURE_FREE_MEMORY) 
  164            if (memoryInterval.
beat()) {
 
  171    void subsMsg(String topic, String msg, String originator) {
 
  172#if defined(USTD_FEATURE_FREE_MEMORY) 
  173        if (topic == name + 
"/memory/get") {
 
  175                int period = msg.toInt();
 
  176                memoryInterval = period * 1000;
 
  183        if (topic == name + 
"/diagnostics/get") {
 
  184            publishDiagnostics();
 
  186        if (topic == name + 
"/timeinfo/get") {
 
  190        if (topic == name + 
"/restart") {
 
muwerk Doctor Class
Definition doctor.h:53
 
Doctor(String name="doctor")
Definition doctor.h:67
 
void begin(Scheduler *_pSched)
Definition doctor.h:74
 
muwerk Scheduler Class
Definition scheduler.h:199
 
int add(T_TASK task, String name, unsigned long minMicroSecs=100000L, T_PRIO prio=PRIO_NORMAL)
Definition scheduler.h:475
 
unsigned long getUptime()
Definition scheduler.h:554
 
bool publish(String topic, String msg="", String originator="")
Definition scheduler.h:367
 
int subscribe(int taskID, String topic, T_SUBS subs, String originator="")
Definition scheduler.h:395
 
muwerk HeartBeat Class
Definition heartbeat.h:47
 
unsigned long beat()
Definition heartbeat.h:75
 
The muwerk namespace.
Definition console.h:15