-
Notifications
You must be signed in to change notification settings - Fork 0
/
victron_ve_toMqtt.ino
160 lines (130 loc) · 3.3 KB
/
victron_ve_toMqtt.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Created by MeisterQ 13.01.2023
// V00.01.01
// Victron MPPT 150 / 35
// Smart Solar charge controller
// Message format <Newline><Field-Label><Tab><Field-Value>
// V (mV) Main Battery Voltage
// VPV (mV) Panel voltage
// PPV (W) Panel power
// I (mA) Battery current
// RELAY Relay state
// H19 (0.01 kWh) Yield total
// H20 (0.01 kWh) Yield today
// H21 (W) Maximum power today
// H22 (0.01 kWh) Yield yesterday
// H23 (W) Maximum power yesterday
// ERR Error code
// CS State of operation
// FW Firmware version
// PID Product ID
// Ser# Serial number
// HSDS Day sequence number (0...364)
// State of operations
// 0 OFF
// 2 FAULT
// 3 BULK
// 4 Absorption
// 5 Float
// Errorlist
// 0 No error
// 2 Battery voltage too high
// 17 Charger temperature too high
// 18 Charger over current
// 19 Charger current reversed
// 20 Bulk time limit exceeded
// 21 Current sensor issue
// 26 Terminals overheated
// 33 Input voltage too high (solar panel)
// 34 Input current too high (solar panel)
// 38 Input shutdown (due to excessive battery voltage)
// 116 Factory calibration data lost
// 117 Invalid / incompatible firmware
// 119 User settings invalid
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <SoftwareSerial.h>
#include <credentials.h>
#include <ArduinoJson.h>
SoftwareSerial swSer(D6, D7);
/*
------------------------ Mosquitto --------------------------
*/
//#define mqttSecure
const char* mqtt_server = mqttServer;
WiFiClient espClient;
PubSubClient client(espClient);
/* topics */
#define ACT_DATA_TOPIC "Solar/Victron/act/data"
#define STATE_DEBUG_TOPIC "Solar/Victron/debug/debug"
#define STATE_WATCHDOG_TOPIC "Solar/Victron/state/watchdog"
#define MQTTPort 1883
#define ClientID "Victron"
#define MQTTUser "User"
#define MQTTPass "Password"
/*
---------------------- Wifi settings ------------------
*/
//#define fixedIP // Uncomment to use fixed IP
const char* ssid = wifiName;
const char* password = wifiPass;
#ifdef fixedIP
IPAddress ip(192, 168, 1, 1); // Change IP if you use fixed IP!!
IPAddress gateway(192, 168, 1, 1); // Change IP if you use fixed IP!!
IPAddress subnet(192, 168, 1, 1); // Change IP if you use fixed IP!!
IPAddress dns(192, 168, 1, 1); // Change IP if you use fixed IP!!
#endif
/*
---------------------- Variables ----------------------
*/
byte cs;
int vpv;
int batteryV;
int current;
int ppv;
int H19;
int H20;
int H21;
int H22;
int H23;
int ERR;
int RELAY;
String data;
String valueVPV;
String valuePID;
String valueV;
String valueI;
String valuePPV;
String valueCS;
String valueH19;
String valueH20;
String valueH21;
String valueH22;
String valueH23;
String valueERR;
String valueRELAY;
String mqttUser = "mqttUser"; // Enter MQTT User
String mqttPass = "mqttPass"; // Enter MQTT Password
unsigned long previousMillisWatchdog = 0;
long watchdogTime = 0;
unsigned long previousMillis = 0;
const long interval = 5000;
void setup()
{
Serial.begin(115200);
swSer.begin(19200);
wifiSettings();
mqttSettings();
OTAsettings();
mqttconnect();
client.publish(STATE_DEBUG_TOPIC, "Setup Done");
}
void loop()
{
ArduinoOTA.handle();
mqttHandle();
getData();
sendMQTT();
watchdog(5000);
}