mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Loop function added, generic timer added, message buffer increased (you never know)
This commit is contained in:
parent
bf37f655df
commit
957a91e55e
6 changed files with 41 additions and 4 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <freertos/FreeRTOS.h>
|
||||
#include "../../../USER_SETTINGS.h"
|
||||
#include "../../lib/knolleary-pubsubclient/PubSubClient.h"
|
||||
#include "../utils/timer.h"
|
||||
|
||||
const char* mqtt_subscriptions[] = MQTT_SUBSCRIPTIONS;
|
||||
const size_t mqtt_nof_subscriptions = sizeof(mqtt_subscriptions) / sizeof(mqtt_subscriptions[0]);
|
||||
|
@ -13,6 +14,7 @@ PubSubClient client(espClient);
|
|||
char msg[MSG_BUFFER_SIZE];
|
||||
int value = 0;
|
||||
static unsigned long previousMillisUpdateVal;
|
||||
MyTimer publish_global_timer(5000);
|
||||
|
||||
/** Publish global values and call callbacks for specific modules */
|
||||
static void publish_values(void) {
|
||||
|
@ -28,7 +30,7 @@ static void publish_values(void) {
|
|||
"}\n",
|
||||
((float)SOC) / 100.0, ((float)StateOfHealth) / 100.0, ((float)((int16_t)temperature_min)) / 10.0,
|
||||
((float)((int16_t)temperature_max)) / 10.0, cell_max_voltage, cell_min_voltage);
|
||||
bool result = client.publish("battery/info", msg, true);
|
||||
bool result = client.publish("battery_testing/info", msg, true);
|
||||
Serial.println(msg); // Uncomment to print the payload on serial
|
||||
}
|
||||
|
||||
|
@ -79,9 +81,8 @@ void init_mqtt(void) {
|
|||
void mqtt_loop(void) {
|
||||
if (client.connected()) {
|
||||
client.loop();
|
||||
if (millis() - previousMillisUpdateVal >= 5000) // Every 5s
|
||||
if (publish_global_timer.elapsed() == true) // Every 5s
|
||||
{
|
||||
previousMillisUpdateVal = millis();
|
||||
publish_values(); // Update values heading towards inverter. Prepare for sending on CAN, or write directly to Modbus.
|
||||
}
|
||||
} else {
|
||||
|
@ -92,3 +93,7 @@ void mqtt_loop(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool mqtt_publish(const String& topic, const String& payload) {
|
||||
return client.publish(topic.c_str(), payload.c_str());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue