mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-09 20:06:31 +00:00
Berry tasmota.read_sensors()
This commit is contained in:
parent
efb77a6547
commit
cb0ad2c75b
@ -32,6 +32,8 @@ extern int l_scaleuint(bvm *vm);
|
||||
extern int l_logInfo(bvm *vm);
|
||||
extern int l_save(bvm *vm);
|
||||
|
||||
extern int l_read_sensors(bvm *vm);
|
||||
|
||||
extern int l_respCmnd(bvm *vm);
|
||||
extern int l_respCmndStr(bvm *vm);
|
||||
extern int l_respCmndDone(bvm *vm);
|
||||
@ -2010,6 +2012,8 @@ class be_class_tasmota (scope: global, name: Tasmota) {
|
||||
log, func(l_logInfo)
|
||||
save, func(l_save)
|
||||
|
||||
read_sensors, func(l_read_sensors)
|
||||
|
||||
resp_cmnd, func(l_respCmnd)
|
||||
resp_cmnd_str, func(l_respCmndStr)
|
||||
resp_cmnd_done, func(l_respCmndDone)
|
||||
|
@ -307,6 +307,7 @@ extern const bcstring be_const_str_SERIAL_8N1;
|
||||
extern const bcstring be_const_str_pi;
|
||||
extern const bcstring be_const_str_add_header;
|
||||
extern const bcstring be_const_str_list;
|
||||
extern const bcstring be_const_str_read_sensors;
|
||||
extern const bcstring be_const_str_super;
|
||||
extern const bcstring be_const_str_has;
|
||||
extern const bcstring be_const_str___upper__;
|
||||
|
@ -306,7 +306,8 @@ be_define_const_str(AudioFileSource, "AudioFileSource", 2959980058u, 0, 15, &be_
|
||||
be_define_const_str(SERIAL_8N1, "SERIAL_8N1", 2369297235u, 0, 10, &be_const_str_pi);
|
||||
be_define_const_str(pi, "pi", 1213090802u, 0, 2, NULL);
|
||||
be_define_const_str(add_header, "add_header", 927130612u, 0, 10, &be_const_str_list);
|
||||
be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_super);
|
||||
be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_read_sensors);
|
||||
be_define_const_str(read_sensors, "read_sensors", 892689201u, 0, 12, &be_const_str_super);
|
||||
be_define_const_str(super, "super", 4152230356u, 0, 5, NULL);
|
||||
be_define_const_str(has, "has", 3988721635u, 0, 3, NULL);
|
||||
be_define_const_str(__upper__, "__upper__", 3612202883u, 0, 9, &be_const_str_exp);
|
||||
@ -515,6 +516,6 @@ static const bstring* const m_string_table[] = {
|
||||
|
||||
static const struct bconststrtab m_const_string_table = {
|
||||
.size = 163,
|
||||
.count = 326,
|
||||
.count = 327,
|
||||
.table = m_string_table
|
||||
};
|
||||
|
@ -1,88 +1,89 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_tasmota_map) {
|
||||
{ be_const_key(chars_in_string, 62), be_const_closure(chars_in_string_closure) },
|
||||
{ be_const_key(publish, -1), be_const_func(l_publish) },
|
||||
{ be_const_key(try_rule, 5), be_const_closure(try_rule_closure) },
|
||||
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
|
||||
{ be_const_key(get_free_heap, 43), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(eth, 55), be_const_func(l_eth) },
|
||||
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
|
||||
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
|
||||
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(event, -1), be_const_closure(event_closure) },
|
||||
{ be_const_key(hs2rgb, -1), be_const_closure(hs2rgb_closure) },
|
||||
{ be_const_key(time_str, 56), be_const_closure(time_str_closure) },
|
||||
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
|
||||
{ be_const_key(response_append, 1), be_const_func(l_respAppend) },
|
||||
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
|
||||
{ be_const_key(remove_driver, 47), be_const_closure(remove_driver_closure) },
|
||||
{ be_const_key(yield, 37), be_const_func(l_yield) },
|
||||
{ be_const_key(exec_cmd, 2), be_const_closure(exec_cmd_closure) },
|
||||
{ be_const_key(rtc, 14), be_const_func(l_rtc) },
|
||||
{ be_const_key(cmd_res, -1), be_const_var(0) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(exec_tele, -1), be_const_closure(exec_tele_closure) },
|
||||
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
|
||||
{ be_const_key(global, 51), be_const_var(1) },
|
||||
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
|
||||
{ be_const_key(add_driver, 12), be_const_closure(add_driver_closure) },
|
||||
{ be_const_key(_timers, 53), be_const_var(2) },
|
||||
{ be_const_key(_cb, 71), be_const_var(3) },
|
||||
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(remove_rule, 0), be_const_closure(remove_rule_closure) },
|
||||
{ be_const_key(web_send, 9), be_const_func(l_webSend) },
|
||||
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(remove_timer, 10), be_const_closure(remove_timer_closure) },
|
||||
{ be_const_key(memory, -1), be_const_func(l_memory) },
|
||||
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
|
||||
{ be_const_key(wire2, -1), be_const_var(4) },
|
||||
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
|
||||
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(kv, 65), be_const_closure(kv_closure) },
|
||||
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
|
||||
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
|
||||
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
|
||||
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
|
||||
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
|
||||
{ be_const_key(cmd, 60), be_const_closure(cmd_closure) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(settings, -1), be_const_var(5) },
|
||||
{ be_const_key(load, -1), be_const_closure(load_closure) },
|
||||
{ be_const_key(arch, -1), be_const_func(l_arch) },
|
||||
{ be_const_key(_ccmd, -1), be_const_var(6) },
|
||||
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
|
||||
{ be_const_key(find_key_i, 19), be_const_closure(find_key_i_closure) },
|
||||
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
|
||||
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
|
||||
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
|
||||
{ be_const_key(save, 25), be_const_func(l_save) },
|
||||
{ be_const_key(millis, -1), be_const_func(l_millis) },
|
||||
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(wire1, 72), be_const_var(7) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(scale_uint, 50), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(get_switch, -1), be_const_func(l_getswitch) },
|
||||
{ be_const_key(wifi, 38), be_const_func(l_wifi) },
|
||||
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
|
||||
{ be_const_key(_drivers, -1), be_const_var(8) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
|
||||
{ be_const_key(log, -1), be_const_func(l_logInfo) },
|
||||
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
|
||||
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
|
||||
{ be_const_key(_timers, -1), be_const_var(1) },
|
||||
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(_rules, 73), be_const_var(2) },
|
||||
{ be_const_key(get_switch, 21), be_const_func(l_getswitch) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(find_op, 4), be_const_closure(find_op_closure) },
|
||||
{ be_const_key(wire1, -1), be_const_var(3) },
|
||||
{ be_const_key(resp_cmnd_failed, 29), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
|
||||
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
|
||||
{ be_const_key(_cb, 57), be_const_var(4) },
|
||||
{ be_const_key(hs2rgb, 71), be_const_closure(hs2rgb_closure) },
|
||||
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
|
||||
{ be_const_key(kv, -1), be_const_closure(kv_closure) },
|
||||
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
|
||||
{ be_const_key(resp_cmnd_done, 74), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(_rules, 16), be_const_var(9) },
|
||||
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
|
||||
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(global, -1), be_const_var(5) },
|
||||
{ be_const_key(rtc, 0), be_const_func(l_rtc) },
|
||||
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
|
||||
{ be_const_key(wd, -1), be_const_var(6) },
|
||||
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(read_sensors, 56), be_const_func(l_read_sensors) },
|
||||
{ be_const_key(settings, -1), be_const_var(7) },
|
||||
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
|
||||
{ be_const_key(save, -1), be_const_func(l_save) },
|
||||
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
|
||||
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) },
|
||||
{ be_const_key(response_append, 14), be_const_func(l_respAppend) },
|
||||
{ be_const_key(remove_driver, -1), be_const_closure(remove_driver_closure) },
|
||||
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(load, -1), be_const_closure(load_closure) },
|
||||
{ be_const_key(_settings_ptr, 55), be_const_comptr(&Settings) },
|
||||
{ be_const_key(millis, 23), be_const_func(l_millis) },
|
||||
{ be_const_key(event, 67), be_const_closure(event_closure) },
|
||||
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
|
||||
{ be_const_key(publish_result, 60), be_const_func(l_publish_result) },
|
||||
{ be_const_key(_drivers, -1), be_const_var(8) },
|
||||
{ be_const_key(get_light, 1), be_const_closure(get_light_closure) },
|
||||
{ be_const_key(init, -1), be_const_closure(init_closure) },
|
||||
{ be_const_key(wd, 52), be_const_var(10) },
|
||||
{ be_const_key(remove_cmd, 24), be_const_closure(remove_cmd_closure) },
|
||||
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
|
||||
{ be_const_key(_cmd, 68), be_const_func(l_cmd) },
|
||||
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
|
||||
{ be_const_key(remove_rule, 70), be_const_closure(remove_rule_closure) },
|
||||
{ be_const_key(resolvecmnd, 41), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(web_send, 38), be_const_func(l_webSend) },
|
||||
{ be_const_key(cb_dispatch, 6), be_const_closure(cb_dispatch_closure) },
|
||||
{ be_const_key(memory, -1), be_const_func(l_memory) },
|
||||
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
|
||||
{ be_const_key(strftime, 16), be_const_func(l_strftime) },
|
||||
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
|
||||
{ be_const_key(add_driver, -1), be_const_closure(add_driver_closure) },
|
||||
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
|
||||
{ be_const_key(log, 40), be_const_func(l_logInfo) },
|
||||
{ be_const_key(wire2, -1), be_const_var(9) },
|
||||
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
|
||||
{ be_const_key(yield, -1), be_const_func(l_yield) },
|
||||
{ be_const_key(arch, -1), be_const_func(l_arch) },
|
||||
{ be_const_key(resp_cmnd, 69), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(_global_addr, 26), be_const_comptr(&TasmotaGlobal) },
|
||||
{ be_const_key(publish, -1), be_const_func(l_publish) },
|
||||
{ be_const_key(_ccmd, -1), be_const_var(10) },
|
||||
{ be_const_key(eth, -1), be_const_func(l_eth) },
|
||||
{ be_const_key(exec_tele, -1), be_const_closure(exec_tele_closure) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_tasmota_map,
|
||||
77
|
||||
78
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
@ -621,7 +621,7 @@ void CmndStatus(void)
|
||||
|
||||
if ((0 == payload) || (8 == payload) || (10 == payload)) {
|
||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS10_SENSOR "\":"));
|
||||
MqttShowSensor();
|
||||
MqttShowSensor(true);
|
||||
ResponseJsonEnd();
|
||||
CmndStatusResponse((8 == payload) ? 8 : 10);
|
||||
}
|
||||
|
@ -835,7 +835,7 @@ String GetSwitchText(uint32_t i) {
|
||||
return switch_text;
|
||||
}
|
||||
|
||||
bool MqttShowSensor(void)
|
||||
bool MqttShowSensor(bool call_show_sensor)
|
||||
{
|
||||
ResponseAppendTime();
|
||||
|
||||
@ -894,20 +894,20 @@ bool MqttShowSensor(void)
|
||||
}
|
||||
ResponseJsonEnd();
|
||||
|
||||
if (json_data_available) { XdrvCall(FUNC_SHOW_SENSOR); }
|
||||
if (call_show_sensor && json_data_available) { XdrvCall(FUNC_SHOW_SENSOR); }
|
||||
return json_data_available;
|
||||
}
|
||||
|
||||
void MqttPublishSensor(void) {
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
if (MqttShowSensor(true)) {
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
}
|
||||
|
||||
void MqttPublishTeleperiodSensor(void) {
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
if (MqttShowSensor(true)) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings->flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
XdrvRulesProcess(1);
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ void TasDiscovery(void) {
|
||||
|
||||
if (!Settings->flag.hass_discovery) { // SetOption19 - Clear retained message
|
||||
Response_P(PSTR("{\"sn\":"));
|
||||
MqttShowSensor();
|
||||
MqttShowSensor(true);
|
||||
ResponseAppend_P(PSTR(",\"ver\":1}"));
|
||||
}
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR("tasmota/discovery/%s/sensors"), NetworkUniqueId().c_str());
|
||||
|
@ -382,7 +382,7 @@ void NewHAssDiscovery(void) {
|
||||
|
||||
if (!Settings->flag.hass_discovery) { // SetOption19 - Clear retained message
|
||||
Response_P(PSTR("{\"sn\":"));
|
||||
MqttShowSensor();
|
||||
MqttShowSensor(true);
|
||||
ResponseAppend_P(PSTR(",\"ver\":1}"));
|
||||
}
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR("tasmota/discovery/%s/sensors"), NetworkUniqueId().c_str());
|
||||
|
@ -541,6 +541,35 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Native functions mapped to Berry functions
|
||||
*
|
||||
* read_sensors(show_sensor:bool) -> string
|
||||
*
|
||||
\*********************************************************************************************/
|
||||
extern "C" {
|
||||
int32_t l_read_sensors(struct bvm *vm);
|
||||
int32_t l_read_sensors(struct bvm *vm) {
|
||||
int32_t top = be_top(vm); // Get the number of arguments
|
||||
bool sensor_display = false; // don't trigger a display by default
|
||||
if (top >= 2) {
|
||||
sensor_display = be_tobool(vm, 2);
|
||||
}
|
||||
ResponseClear();
|
||||
if (MqttShowSensor(sensor_display)) {
|
||||
// return string
|
||||
be_pushstring(vm, ResponseData());
|
||||
be_return(vm);
|
||||
} else {
|
||||
be_return_nil(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Logging functions
|
||||
*
|
||||
\*********************************************************************************************/
|
||||
// called as a replacement to Berry `print()`
|
||||
void berry_log(const char * berry_buf);
|
||||
void berry_log(const char * berry_buf) {
|
||||
|
@ -385,7 +385,7 @@ void InfluxDbLoop(void) {
|
||||
|
||||
// {"Time":"2021-08-14T17:19:33","Switch1":"ON","Switch2":"OFF","ANALOG":{"Temperature":184.72},"DS18B20":{"Id":"01144A0CB2AA","Temperature":27.50},"HTU21":{"Temperature":28.23,"Humidity":39.7,"DewPoint":13.20},"Global":{"Temperature":27.50,"Humidity":39.7,"DewPoint":12.55},"TempUnit":"C"}
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) { // Pull sensor data
|
||||
if (MqttShowSensor(true)) { // Pull sensor data
|
||||
InfluxDbProcessJson();
|
||||
};
|
||||
|
||||
|
@ -282,7 +282,7 @@ void HandleMetrics(void) {
|
||||
}
|
||||
|
||||
ResponseClear();
|
||||
MqttShowSensor(); //Pull sensor data
|
||||
MqttShowSensor(true); //Pull sensor data
|
||||
String jsonStr = ResponseData();
|
||||
JsonParser parser((char *)jsonStr.c_str());
|
||||
JsonParserObject root = parser.getRootObject();
|
||||
|
Loading…
x
Reference in New Issue
Block a user