Add config.misc.temp_limit setting primed by setupVars.conf:TEMPERATURE_LIMIT (if available) used to signal beyond which temperature the frontend should consider the temperature "hot"

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-01-09 20:19:59 +01:00
parent 999a9735cb
commit 64441ed6d8
8 changed files with 74 additions and 12 deletions
+19 -7
View File
@@ -79,6 +79,8 @@ static cJSON *addJSONvalue(const enum conf_type conf_type, union conf_value *val
return cJSON_CreateNumber(val->l);
case CONF_ULONG:
return cJSON_CreateNumber(val->ul);
case CONF_DOUBLE:
return cJSON_CreateNumber(val->d);
case CONF_STRING:
case CONF_STRING_ALLOCATED:
return val->s ? cJSON_CreateStringReference(val->s) : cJSON_CreateNull();
@@ -130,7 +132,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem)
return "not of type bool";
// Set item
conf_item->v.b = elem->valueint;
log_debug(DEBUG_CONFIG, "Set %s to %s", conf_item->k, elem->valueint ? "true" : "false");
log_debug(DEBUG_CONFIG, "Set %s to %s", conf_item->k, conf_item->v.b ? "true" : "false");
break;
}
case CONF_INT:
@@ -142,7 +144,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem)
return "not of type integer";
// Set item
conf_item->v.i = elem->valueint;
log_debug(DEBUG_CONFIG, "Set %s to %i", conf_item->k, elem->valueint);
log_debug(DEBUG_CONFIG, "Set %s to %i", conf_item->k, conf_item->v.i);
break;
}
case CONF_UINT:
@@ -154,7 +156,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem)
return "not of type unsigned integer";
// Set item
conf_item->v.ui = elem->valuedouble;
log_debug(DEBUG_CONFIG, "Set %s to %u", conf_item->k, (unsigned int)elem->valuedouble);
log_debug(DEBUG_CONFIG, "Set %s to %u", conf_item->k, conf_item->v.ui);
break;
}
case CONF_LONG:
@@ -166,7 +168,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem)
return "not of type long";
// Set item
conf_item->v.l = elem->valuedouble;
log_debug(DEBUG_CONFIG, "Set %s to %li", conf_item->k, (long)elem->valuedouble);
log_debug(DEBUG_CONFIG, "Set %s to %li", conf_item->k, conf_item->v.l);
break;
}
case CONF_ULONG:
@@ -177,8 +179,18 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem)
elem->valuedouble < 0 || elem->valuedouble > ULONG_MAX)
return "not of type unsigned long";
// Set item
conf_item->v.l = elem->valuedouble;
log_debug(DEBUG_CONFIG, "Set %s to %lu", conf_item->k, (unsigned long)elem->valuedouble);
conf_item->v.ul = elem->valuedouble;
log_debug(DEBUG_CONFIG, "Set %s to %lu", conf_item->k, conf_item->v.ul);
break;
}
case CONF_DOUBLE:
{
// Check it is a number
if(!cJSON_IsNumber(elem))
return "not of type unsigned long";
// Set item
conf_item->v.d = elem->valuedouble;
log_debug(DEBUG_CONFIG, "Set %s to %f", conf_item->k, conf_item->v.d);
break;
}
case CONF_STRING:
@@ -257,7 +269,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem)
return "not within valid range";
// Set item
conf_item->v.i = elem->valueint;
log_debug(DEBUG_CONFIG, "Set %s to %d", conf_item->k, elem->valueint);
log_debug(DEBUG_CONFIG, "Set %s to %d", conf_item->k, conf_item->v.i);
break;
}
case CONF_STRUCT_IN_ADDR:
+3
View File
@@ -237,6 +237,8 @@ components:
type: boolean
privacylevel:
type: integer
temp_limit:
type: number
check:
type: object
properties:
@@ -376,6 +378,7 @@ components:
delay_startup: 10
addr2line: true
privacylevel: 0
temp_limit: 60.0
check:
load: true
shmem: 90
+9 -1
View File
@@ -285,10 +285,18 @@ components:
value:
type: number
description: Sensor value
hot_limit:
type: number
description: Limit defined in FTL's config beyond which the CPU should be considered hot
unit:
type: string
description: Sensor value unit
example:
- name: null
- name: "Composite"
path: "hwmon0/temp1"
value: 30.4
hot_limit: 60.0
unit: "C"
model:
type: string
description: Device model (if available, `null` otherwise)
+8 -3
View File
@@ -210,9 +210,9 @@ static int read_temp_sensor(struct ftl_conn *api,
FILE *f_value = fopen(value_path, "r");
if(f_value != NULL)
{
int temp = 0;
int raw_temp = 0;
char label[1024];
if(fscanf(f_value, "%d", &temp) == 1)
if(fscanf(f_value, "%d", &raw_temp) == 1)
{
cJSON *item = JSON_NEW_OBJECT();
if(f_label && fgets(label, sizeof(label)-1, f_label))
@@ -227,7 +227,12 @@ static int read_temp_sensor(struct ftl_conn *api,
JSON_ADD_NULL_TO_OBJECT(item, "name");
}
JSON_COPY_STR_TO_OBJECT(item, "path", short_path);
JSON_ADD_NUMBER_TO_OBJECT(item, "value", temp < 1000 ? temp : 1e-3*temp);
// Compute actual temperature
double temp = raw_temp < 1000 ? raw_temp : 1e-3*raw_temp;
JSON_ADD_NUMBER_TO_OBJECT(item, "value", temp);
JSON_ADD_NUMBER_TO_OBJECT(item, "hot_limit", config.misc.temp_limit.v.d);
JSON_REF_STR_IN_OBJECT(item, "unit", "C");
JSON_ADD_ITEM_TO_ARRAY(object, item);
}
}
+6
View File
@@ -478,6 +478,12 @@ void initConfig(void)
config.misc.delay_startup.t = CONF_UINT;
config.misc.delay_startup.d.ui = 0;
// sub-struct misc.temp
config.misc.temp_limit.k = "misc.temp_limit";
config.misc.temp_limit.h = "Which upper temperature limit should be used by Pi-hole [°C]? Temperatures above this limit will be shown as \"hot\"";
config.misc.temp_limit.t = CONF_DOUBLE;
config.misc.temp_limit.d.d = 60.0; // °C
// sub-struct misc.check
config.misc.check.load.k = "misc.check.load";
config.misc.check.load.h = "Should FTL check the 15 min average of CPU load and complain if the load is larger than the number of available CPU cores?";
+3
View File
@@ -51,6 +51,7 @@ union conf_value {
unsigned int ui; // unsigned int value
long l; // long value
unsigned long ul; // unsigned long value
double d; // double value
char *s; // char * value
enum ptr_type ptr_type; // enum ptr_type value
enum busy_reply busy_reply; // enum busy_reply value
@@ -69,6 +70,7 @@ enum conf_type {
CONF_UINT,
CONF_LONG,
CONF_ULONG,
CONF_DOUBLE,
CONF_STRING,
CONF_STRING_ALLOCATED,
CONF_ENUM_PTR_TYPE,
@@ -189,6 +191,7 @@ struct config {
struct conf_item delay_startup;
struct conf_item addr2line;
struct conf_item privacylevel;
struct conf_item temp_limit;
struct {
struct conf_item load;
struct conf_item shmem;
+13 -1
View File
@@ -69,7 +69,7 @@ static void printTOMLstring(FILE *fp, const char *s)
}
// If string is printable and does not contain any special characters, we can
// print it as is without furhter escaping
// print it as is without further escaping
if (ok)
{
fprintf(fp, "\"%s\"", s);
@@ -132,6 +132,9 @@ void writeTOMLvalue(FILE * fp, const enum conf_type t, union conf_value *v)
case CONF_ULONG:
fprintf(fp, "%lu", v->ul);
break;
case CONF_DOUBLE:
fprintf(fp, "%f", v->d);
break;
case CONF_STRING:
case CONF_STRING_ALLOCATED:
printTOMLstring(fp, v->s);
@@ -236,6 +239,15 @@ void readTOMLvalue(struct conf_item *conf_item, const char* key, toml_table_t *t
log_debug(DEBUG_CONFIG, "%s does not exist or is not of type unsigned long", conf_item->k);
break;
}
case CONF_DOUBLE:
{
const toml_datum_t val = toml_double_in(toml, key);
if(val.ok)
conf_item->v.d = val.u.d;
else
log_debug(DEBUG_CONFIG, "%s does not exist or is not of type double", conf_item->k);
break;
}
case CONF_STRING:
case CONF_STRING_ALLOCATED:
{
+13
View File
@@ -85,6 +85,19 @@ void importsetupVarsConf(void)
// Free memory, harmless to call if read_setupVarsconf() didn't return a result
clearSetupVarsArray();
// Try to obtain blocking active boolean
const char* temp_limit = read_setupVarsconf("TEMPERATURE_LIMIT");
if(temp_limit != NULL)
{
double lim;
if(sscanf(temp_limit, "%lf", &lim) == 1)
config.misc.temp_limit.v.d = lim;
}
// Free memory, harmless to call if read_setupVarsconf() didn't return a result
clearSetupVarsArray();
}
char* __attribute__((pure)) find_equals(const char* s)