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
+6
-7
@@ -12,9 +12,6 @@ You will receive every TimeBetweenReadingDHT (set into config_DHT.h) the DHT mea
|
||||
|
||||
`home/OpenMQTTGateway/DHTtoMQTT {"tempc":21,"tempf":69.8,"hum":51}`
|
||||
|
||||
Legacy (removed after release 0.9.5)
|
||||
`home/OpenMQTTGateway/DHTtoMQTT {"temp":21,"hum":51}`
|
||||
|
||||
If you want to don't resend value when it is the same you can set dht_always = false in config_DHT.h
|
||||
|
||||
### HTU21
|
||||
@@ -37,9 +34,6 @@ Each sensor will be published under the following topic using each sensors' addr
|
||||
|
||||
`home/OpenMQTTGateway/CLIMAtoMQTT/ds1820/0x0000000000000000 {"tempc":27.8, "tempf":82.04, "type":"DS18B20","res":"12bit\n","addr":"0x28616411907650bc"}`
|
||||
|
||||
Legacy (removed after release 0.9.5)
|
||||
`home/OpenMQTTGateway/CLIMAtoMQTT/ds1820/0x0000000000000000 {"temp":27.8,"unit":"C","type":"DS18B20","res":"12bit\n","addr":"0x28616411907650bc"}`
|
||||
|
||||
The units for temperature readings are sent in Celsius by default can be changed to Fahrenheit by setting DS1820_FAHRENHEIT = true in in config_DS1820.h
|
||||
|
||||
If you don't want to resend values that haven't changed you can set DS1820_ALWAYS = false in config_DS1820.h
|
||||
@@ -55,4 +49,9 @@ This can be useful if you would like to connect an LED to turn on when motion is
|
||||
`#define HCSR501_LED_NOTIFY_GPIO 4`
|
||||
|
||||
This notification pin can be inverted if driving directly or through a transistor/mosfet.
|
||||
`#define INVERT_LED_NOTIFY true`
|
||||
`#define INVERT_LED_NOTIFY true`
|
||||
|
||||
### RN8209
|
||||
You will receive every TimeBetweenReadingRN8209 (set into config_RN8209.h) the RN8209 measurements (10s per default).
|
||||
|
||||
`home/OpenMQTTGateway/RN8209toMQTT {"volt":120.345,"current":7.9264,"power":954.6132}`
|
||||
@@ -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;
|
||||
|
||||
@@ -141,6 +141,7 @@ gfSunInverter = https://github.com/BlackSmith/GFSunInverter.git#v1.0.1
|
||||
decoder = https://github.com/theengs/decoder.git#v0.9.7
|
||||
ssd1306 = thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0
|
||||
lm75 = jeremycole/I2C Temperature Sensors derived from the LM75@^1.0.3
|
||||
rn8209 = https://github.com/theengs/RN8209C-SDK.git#arduino
|
||||
|
||||
[env]
|
||||
framework = arduino
|
||||
@@ -265,6 +266,7 @@ lib_deps =
|
||||
${libraries.dallastemperature}
|
||||
${libraries.rfWeatherStation}
|
||||
${libraries.shtc3}
|
||||
${libraries.rn8209}
|
||||
build_flags =
|
||||
${com-esp.build_flags}
|
||||
'-DZgatewayRF="RF"'
|
||||
@@ -289,6 +291,7 @@ build_flags =
|
||||
'-DZgatewayRFM69="RFM69"'
|
||||
'-DZsensorGPIOInput="GPIOInput"'
|
||||
'-DZsensorGPIOKeyCode="GPIOKeyCode"'
|
||||
'-DZsensorRN8209="RN8209"'
|
||||
'-DZgatewayWeatherStation="WeatherStation"'
|
||||
'-DsimplePublishing=true'
|
||||
'-DWM_PWD_FROM_MAC=true'
|
||||
|
||||
Reference in new issue
Block a user