Please help me to identify the cause of why “Load Current” (V4) and “Load Power” (V5) labeled value display are not working? (all other buttons are working fine)
Please treat me as beginner as I’m new to Blynk network.
Here is the code for settings.h file:
/*
Auth Codes & Wifi info go in the following file.
Create a new folder in your library dir called 'wifi_credentials'
and create a new file called 'wifi_credentials.h' and copy the
example in the repo. You can use this for all your wifi projects.
*/
#include <wifi_credentials.h>
/*
Blynk Auth Codes
*/
#define AUTH "put your author code here"
/*
Local Server Settings
Comment out to use Cloud Server
/*
Over The Air Hostname
*/
/*
Virtual Pins - Base
*/
#define vPIN_PV_POWER V1
#define vPIN_PV_CURRENT V2
#define vPIN_PV_VOLTAGE V3
#define vPIN_LOAD_CURRENT V4
#define vPIN_LOAD_POWER V5
#define vPIN_BATT_TEMP V6
#define vPIN_BATT_VOLTAGE V7
/*
Debug. Change to 0 when you are finished debugging.
*/
const int debug = 1;
/*
*/
And here is the main code.ino file:
// CONNECT THE RS485 MODULE RX->RX, TX->TX.
// Disconnect when uploading code.
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
int timerTask1, timerTask2, timerTask3;
float battBhargeCurrent, bvoltage, ctemp, btemp, bremaining, lpower, lcurrent, pvvoltage, pvcurrent, pvpower;
uint8_t result;
// To add later
//uint8_t result, time1, time2, time3, date1, date2, date3, dateDay, dateMonth, dateYear, timeHour, timeMinute, timeSecond;
//char buf[10];
//String dtString;
// this is to check if we can write since rs485 is half duplex
bool rs485DataReceived = true;
ModbusMaster node;
SimpleTimer timer;
// tracer requires no handshaking
void preTransmission() {}
void postTransmission() {}
// a list of the regisities to query in order
typedef void (*RegistryList[])();
RegistryList Registries = {
AddressRegistry_3100,
AddressRegistry_311A,
AddressRegistry_3300,
};
// keep log of where we are
uint8_t currentRegistryNumber = 0;
// function to switch to next registry
void nextRegistryNumber() {
currentRegistryNumber = (currentRegistryNumber + 1) % ARRAY_SIZE( Registries);
}
void setup()
{
Serial.begin(115200);
// Modbus slave ID 1
node.begin(1, Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
WiFi.mode(WIFI_STA);
#if defined(USE_LOCAL_SERVER)
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS, SERVER);
#else
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS);
#endif
while (Blynk.connect() == false) {}
ArduinoOTA.setHostname(OTA_HOSTNAME);
ArduinoOTA.begin();
timerTask1 = timer.setInterval(1000, updateBlynk);
timerTask2 = timer.setInterval(1000, doRegistryNumber);
timerTask3 = timer.setInterval(1000, nextRegistryNumber);
}
// --------------------------------------------------------------------------------
void updateBlynk() {
Blynk.virtualWrite(vPIN_PV_POWER, pvpower);
Blynk.virtualWrite(vPIN_PV_CURRENT, pvcurrent);
Blynk.virtualWrite(vPIN_PV_VOLTAGE, pvvoltage);
Blynk.virtualWrite(vPIN_LOAD_CURRENT, lcurrent);
Blynk.virtualWrite(vPIN_LOAD_POWER, lpower);
Blynk.virtualWrite(vPIN_BATT_TEMP, btemp);
Blynk.virtualWrite(vPIN_BATT_VOLTAGE, bvoltage);
}
void doRegistryNumber() {
Registries[currentRegistryNumber]();
}
void AddressRegistry_3100() {
result = node.readInputRegisters(0x3100, 7);
if (result == node.ku8MBSuccess)
{
ctemp = node.getResponseBuffer(0x11) / 100.0f;
if (debug == 1) {
Serial.println(ctemp);
Serial.print("Battery Voltage: ");
}
bvoltage = node.getResponseBuffer(0x04) / 100.0f;
if (debug == 1) {
Serial.println(bvoltage);
}
pvvoltage = (long)node.getResponseBuffer(0x00) / 100.0f;
if (debug == 1) {
Serial.print("PV Voltage: ");
Serial.println(pvvoltage);
}
pvcurrent = (long)node.getResponseBuffer(0x01) / 100.0f;
if (debug == 1) {
Serial.print("PV Current: ");
Serial.println(pvcurrent);
}
pvpower = ((long)node.getResponseBuffer(0x03) << 16 | node.getResponseBuffer(0x02)) / 100.0f;
if (debug == 1) {
Serial.print("PV Power: ");
Serial.println(pvpower);
}
battBhargeCurrent = (long)node.getResponseBuffer(0x05) / 100.0f;
if (debug == 1) {
Serial.print("Battery Charge Current: ");
Serial.println(battBhargeCurrent);
Serial.println();
}
} else {
rs485DataReceived = false;
}
}
void AddressRegistry_311A() {
result = node.readInputRegisters(0x311A, 2);
if (result == node.ku8MBSuccess)
{
bremaining = node.getResponseBuffer(0x00) / 1.0f;
if (debug == 1) {
Serial.print("Battery Remaining %: ");
Serial.println(bremaining);
}
btemp = node.getResponseBuffer(0x01) / 100.0f;
if (debug == 1) {
Serial.print("Battery Temperature: ");
Serial.println(btemp);
Serial.println();
}
} else {
rs485DataReceived = false;
}
}
void AddressRegistry_3300() {
result = node.readInputRegisters(0x3300, 2);
if (result == node.ku8MBSuccess)
{
stats_today_pv_volt_max = node.getResponseBuffer(0x00) / 100.0f;
if (debug == 1) {
Serial.print("Stats Today PV Voltage MAX: ");
Serial.println(stats_today_pv_volt_max);
}
stats_today_pv_volt_min = node.getResponseBuffer(0x01) / 100.0f;
if (debug == 1) {
Serial.print("Stats Today PV Voltage MIN: ");
Serial.println(stats_today_pv_volt_min);
}
} else {
rs485DataReceived = false;
}
}
void loop()
{
Blynk.run();
ArduinoOTA.handle();
timer.run();
}