RN8209 energy sensor support with watt, voltage and current. (#1337)
Co-authored-by: h2zero <powellperalta@gmail.com>
This commit is contained in:
1 parent
145896516d
commit
8ee1c4e524
7 files changed
+173
-9
No files matched your search
@@ -328,8 +328,6 @@ void emptyBTQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ProcessLock = false; // Process lock when we want to use a critical function like OTA for example
|
||||
|
||||
void createOrUpdateDevice(const char* mac, uint8_t flags, int model, int mac_type = 0);
|
||||
|
||||
BLEdevice* getDeviceByMac(const char* mac); // Declared here to avoid pre-compilation issue (misplaced auto declaration by pio)
|
||||
|
||||
@@ -758,6 +758,29 @@ void pubMqttDiscovery() {
|
||||
);
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorRN8209
|
||||
# define RN8209parametersCount 3
|
||||
Log.trace(F("RN8209Discovery" CR));
|
||||
char* RN8209sensor[RN8209parametersCount][8] = {
|
||||
{"sensor", "volt", "RN8209", "", jsonVolt, "", "", "V"},
|
||||
{"sensor", "current", "RN8209", "", jsonCurrent, "", "", "A"},
|
||||
{"sensor", "power", "RN8209", "", jsonPower, "", "", "W"}
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
};
|
||||
|
||||
for (int i = 0; i < RN8209parametersCount; i++) {
|
||||
String name = String(RN8209sensor[i][2]) + "PWR: " + String(RN8209sensor[i][1]);
|
||||
createDiscovery(RN8209sensor[i][0],
|
||||
subjectRN8209toMQTT, (char*)name.c_str(), (char*)getUniqueId(RN8209sensor[i][1], RN8209sensor[i][2]).c_str(),
|
||||
will_Topic, RN8209sensor[i][3], RN8209sensor[i][4],
|
||||
RN8209sensor[i][5], RN8209sensor[i][6], RN8209sensor[i][7],
|
||||
0, "", "", true, "",
|
||||
"", "", "", "", false, // device name, device manufacturer, device model, device MAC, retain
|
||||
stateClassNone //State Class
|
||||
);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayRF
|
||||
// Sensor to display RF received value
|
||||
Log.trace(F("gatewayRFDiscovery" CR));
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
OpenMQTTGateway Addon - ESP8266, ESP32 or Arduino program for home automation
|
||||
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
RN8209 reading Addon
|
||||
|
||||
Contributors:
|
||||
- 1technophile
|
||||
|
||||
This file is part of OpenMQTTGateway.
|
||||
|
||||
OpenMQTTGateway is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef ZsensorRN8209
|
||||
|
||||
# include "ArduinoJson.h"
|
||||
# include "driver/uart.h"
|
||||
# include "rn8209_flash.h"
|
||||
# include "rn8209c_user.h"
|
||||
|
||||
extern "C" bool init_8209c_interface();
|
||||
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> doc;
|
||||
|
||||
void rn8209_loop(void* mode) {
|
||||
if (!ProcessLock) {
|
||||
uint32_t voltage;
|
||||
int32_t current;
|
||||
int32_t power;
|
||||
|
||||
while (1) {
|
||||
rn8209c_read_voltage(&voltage);
|
||||
uint8_t ret = rn8209c_read_emu_status();
|
||||
if (ret) {
|
||||
uint32_t temp_current = 0;
|
||||
uint32_t temp_power = 0;
|
||||
rn8209c_read_current(phase_A, &temp_current);
|
||||
rn8209c_read_power(phase_A, &temp_power);
|
||||
if (ret == 1) {
|
||||
current = temp_current;
|
||||
power = temp_power;
|
||||
} else {
|
||||
current = (int32_t)temp_current * (-1);
|
||||
power = (int32_t)temp_power * (-1);
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject data = doc.to<JsonObject>();
|
||||
data["volt"] = (float)voltage / 1000.0;
|
||||
data["current"] = (float)current / 10000.0;
|
||||
data["power"] = (float)power / 10000.0;
|
||||
pub(subjectRN8209toMQTT, data);
|
||||
delay(TimeBetweenReadingRN8209);
|
||||
}
|
||||
} else {
|
||||
Log.trace(F("RN8209 reading canceled by processLock" CR));
|
||||
}
|
||||
}
|
||||
|
||||
void setupRN8209() {
|
||||
STU_8209C cal = {0};
|
||||
cal.Ku = RN8209_KU;
|
||||
cal.Kia = RN8209_KIA;
|
||||
cal.EC = RN8209_EC;
|
||||
set_user_param(cal);
|
||||
init_8209c_interface();
|
||||
xTaskCreate(rn8209_loop, "rn8209_loop", RN8209_TASK_STACK_SIZE, NULL, RN8209_TASK_PRIO, NULL);
|
||||
}
|
||||
|
||||
#endif // ZsensorRN8209
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
OpenMQTTGateway - ESP8266 or Arduino program for home automation
|
||||
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
This files enables to set your parameter for the RN8209 sensor
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
This file is part of OpenMQTTGateway.
|
||||
|
||||
OpenMQTTGateway is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef config_RN8209_h
|
||||
#define config_RN8209_h
|
||||
|
||||
extern void setupRN8209();
|
||||
extern void RN8209toMQTT();
|
||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectRN8209toMQTT "/RN8209toMQTT"
|
||||
|
||||
/*-------------CALIBRATION PARAMETERS----------------*/
|
||||
#ifndef RN8209_KU
|
||||
# define RN8209_KU 18570
|
||||
#endif
|
||||
#ifndef RN8209_KIA
|
||||
# define RN8209_KIA 272433
|
||||
#endif
|
||||
#ifndef RN8209_EC
|
||||
# define RN8209_EC 28250
|
||||
#endif
|
||||
|
||||
#ifndef TimeBetweenReadingRN8209
|
||||
# define TimeBetweenReadingRN8209 10000 // time between 2 RN8209 readings in ms
|
||||
#endif
|
||||
#endif
|
||||
@@ -120,6 +120,9 @@ struct GfSun2000Data {};
|
||||
#ifdef ZsensorAHTx0
|
||||
# include "config_AHTx0.h"
|
||||
#endif
|
||||
#ifdef ZsensorRN8209
|
||||
# include "config_RN8209.h"
|
||||
#endif
|
||||
#ifdef ZsensorHCSR04
|
||||
# include "config_HCSR04.h"
|
||||
#endif
|
||||
@@ -210,6 +213,8 @@ static String ota_server_cert = "";
|
||||
# include <nvs.h>
|
||||
# include <nvs_flash.h>
|
||||
|
||||
bool ProcessLock = false; // Process lock when we want to use a critical function like OTA for example
|
||||
|
||||
# ifdef ESP32_ETHERNET
|
||||
# include <ETH.h>
|
||||
void WiFiEvent(WiFiEvent_t event);
|
||||
@@ -863,6 +868,10 @@ void setup() {
|
||||
# endif
|
||||
# define ACTIVE_RECEIVER ACTIVE_RTL
|
||||
#endif
|
||||
#ifdef ZsensorRN8209
|
||||
setupRN8209();
|
||||
modules.add(ZsensorRN8209);
|
||||
#endif
|
||||
#if defined(ZgatewayRTL_433) || defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRF2)
|
||||
# ifdef DEFAULT_RECEIVER // Allow defining of default receiver as a compiler directive
|
||||
activeReceiver = DEFAULT_RECEIVER;
|
||||
|
||||
Reference in new issue
Block a user