Display TEXT from output number

Hello,

I have little program that will output number 7, 11 or 15 (depend on source).
Currently the Serial Monitor on my computer can display TEXT like FLOAT or BOOT or EQUALIZATION but not on my Blynk App.

How to display a TEXT on Blynk App?
If the output is 7 then I want Bylink app will show FLOAT
If the output is 11 then I want Bylink app will show BOOST
If the output is 15 then I want Bylink app will show EQUALIZATION

Here is the code:

#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <ModbusMaster.h>
#include <ESP8266WiFi.h>
#include "settings.h"
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

int CStatus, Boost, Float, Equalization;
float ChargingStatus;

// this is to check if we can write since rs485 is half duplex
bool rs485DataReceived = true;

// a list of the regisities to query in order
typedef void (*RegistryList[])();
RegistryList Registries = {
  AddressRegistry_3201,
};

// 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 updateBlynk() {
  Blynk.virtualWrite(vPIN_BATT_CHARGING_STATUS, ChargingStatus);
}

void doRegistryNumber() {
  Registries[currentRegistryNumber]();
}

// ========PROGRAM START HERE ==================
 void AddressRegistry_3201() {
 result = node.readInputRegisters(0x3201, 2);
 if (result == node.ku8MBSuccess)
 {
 ChargingStatus = node.getResponseBuffer(0x00) / 1.0f;

 if (ChargingStatus == 7) {
 Serial.print("Charging Status: ");
 Serial.println("Float");
 } else if (ChargingStatus == 11) {
 Serial.print("Charging Status: ");
 Serial.println("Boost");
 } else if (ChargingStatus == 15) {
 Serial.print("Charging Status: ");
 Serial.println("Equalization");
 }
 } else {
 rs485DataReceived = false;
 }
}

// ================================================
void loop()
{
  Blynk.run();
  ArduinoOTA.handle();
  timer.run();
}
// ========= END PROGRAM =============================

@key: Possibly vPIN_BATT_CHARGING_STATUS is not defined correctly?
Can’t tell from the code extract in your post.

Hi IBK,

I have update with full code and correct format.
Please help me to make the Blynk display the TEXT when out is number.

Regrads,
Key

@key: If this is the “full code”, then where is vPIN_BATT_CHARGING_STATUS defined/declared?
I only find it once:

#include <ArduinoOTA.h>
[...]
void updateBlynk() {
  Blynk.virtualWrite(vPIN_BATT_CHARGING_STATUS, ChargingStatus);
}
[...]
// ========= END PROGRAM =============================

Is it in the “settings.h” that you have not posted? :wink:
And where is updateBlynk() called?

Hi IBK,

Yes, that vPIN is in “Setting.h” file. (sorry about that)

FYI, the program is working fine as it can display the number like 7 or 11 or 15 (depend on source output). I don’t want it to display the number, I want the Blynk to display the TEXT.

Example:

  • Base on the source, Blynk app currently display: 11
  • I want it translate number 11 so Blynk can display BOOST

If the source output 7 then I want Blynk app to display FLOAT
or If the source output 15 then I want Blynk app to display EQUALIATION

Where does it do this? I do not see it in the code.

Also, check THIS. You can send strings to a virtual pin.

See below. You will need to change Vpin to whatever virtual pin you have the display assigned to.

if (ChargingStatus == 7) {
 Serial.print("Charging Status: ");
 Serial.println("Float");
  Blynk.virtualWrite(Vpin, "Float");
 } else if (ChargingStatus == 11) {
 Serial.print("Charging Status: ");
 Serial.println("Boost");
 Blynk.virtualWrite(Vpin, "Boost");
 } else if (ChargingStatus == 15) {
 Serial.print("Charging Status: ");
 Serial.println("Equalization");
 Blynk.virtualWrite(Vpin, "Equalization");
 }
1 Like

Hi Toro_Blanco,

Yes, it’s works :+1:
Thank you, thank you and thank you :pray: