Display TEXT format

Hello,

I have little program that will output number 7, 11 or 15 (depend on source).

Currently the Serial print can only display 7, 11, or 15.

How to translate or have Serial print to display Text like:
Number 7 is for Test1
Number 11 is for Test2
Number 15 is for Test3

Here is the code:

void AddressRegistry_3201() {
result = node.readInputRegisters(0x3201, 2);
if (result == node.ku8MBSuccess)
{
ChargingStatus = node.getResponseBuffer(0x00) / 1.0f;
if (debug == 1) {
Serial.print("Charging Status %: ");
Serial.println(ChargingStatus);
} else {
rs485DataReceived = false;
}
}
}

Google the Switch Case Function.

Pete.

switch (Number ) {

case 7 : 
Serial.println("Number 7 is for Test1");
break;

case 11 : 
Serial.println("Number 11 is for Test2");
break;

case 15 : 
Serial.println("Number 15 is for Test3");
break;
}

that's all :smile:

Hi Pete,
Thank you for the hint.

Hi Alexis,
I’m using IF and ELSE IF statement, I was able to display it on my computer but on the BLYNK app it shown 0.

What did I do wrong? please help.

Here is what it looks like on my Serial Monitor:
2 ⸮Charging Status: Boost0.00

And here is the code:


 Blynk.virtualWrite(vPIN_BATT_CHARGING_STATUS,     CStatus);
void AddressRegistry_3201() {
  result = node.readInputRegisters(0x3201, 2);
  if (result == node.ku8MBSuccess)
  {
    ChargingStatus = node.getResponseBuffer(0x00) / 1.0f;

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

Note: I’m using “Labeled Value” on Blynk App

Blynk.virtualWrite(vPIN_BATT_CHARGING_STATUS,     CStatus); // THIS IS WHERE YOU WRITE THE VALUE OF ‘CStatus’ TO BLYNK
void AddressRegistry_3201() {
  result = node.readInputRegisters(0x3201, 2);
  if (result == node.ku8MBSuccess)
  {
    ChargingStatus = node.getResponseBuffer(0x00) / 1.0f;

int CStatus = ChargingStatus; // THIS IS WHERE YOU ASSIGN A VALUE TO THE VARIABLE ‘CStatus’
if (CStatus == 7) {
Serial.print("Charging Status: Float");
Serial.println(Float);
  }  else if (CStatus == 11) {
    Serial.print("Charging Status: Boost");
    Serial.println(Boost);
  }  else if (CStatus == 15) {
    Serial.print("Charging Status: Equalization");
    Serial.println(Equalization);
  }
  } else {
    rs485DataReceived = false;
  }
}

Read my comments (in capitals) in the code above and you should realise your problem.
You need to move the Blynk Virtualwrite further down, so that the CStatus variable actually contains a value.

Pete.

Hi Pete,

Thank you for your response, unfortunately, I’m still having problem with it
(sorry, I’m still learning on how to code)

No matter where I move the Blynk Virutal to, the Blynk app either display 0 or 11 (11 is actual output from source)

Please help.

void AddressRegistry_3201() {
Blynk.virtualWrite(vPIN_BATT_CHARGING_STATUS,     CStatus);
  result = node.readInputRegisters(0x3201, 2);
// blynk app display: 0
  if (result == node.ku8MBSuccess)
  {        
// When I move Blynk Virutal to here, the blynk app display: 0
    ChargingStatus = node.getResponseBuffer(0x00) / 1.0f;
// When I move Blynk Virutal to here, the blynk app display: 0

  int CStatus = ChargingStatus;
//When I move Blynk Virutal to here, the blynk app display: 11
  if (CStatus == 7) {
    Serial.print("Charging Status: Float");
    Serial.println(Float);
  }  else if (CStatus == 11) {
//When I move Blynk Virutal to here, the blynk app display: 11
    Serial.print("Charging Status: Boost");          
//When I move Blynk Virutal to here, the blynk app display: 11
    Serial.println(Boost);
//When I move Blynk Virutal to here, the blynk app display: 11
  }  else if (CStatus == 15) {
    Serial.print("Charging Status: Equalization");
    Serial.println(Equalization);
  }
  } else {
    rs485DataReceived = false;
  }
}

Hi Leonette,

What kind of hint do you have?
How to correct it?

I thought that’s what you wanted, as you are sending the value of CStatus to Blynk. If you want something g different to appear in Blynk then that’s what you should send. For example:

Blynk.virtualWrite(vPIN_BATT_CHARGING_STATUS, ”Text to display in Blynk here”);

This forum isn’t really the place to learn simple coding. The problems you’re having aren’t related to Blynk, they stem from a lack of knowledge of C+ coding.

Pete.

Scratched my head for the last 5 hours but still can’t figure it out :tired_face::tired_face::tired_face:

The code below can display the TEXT fine on my computer Serial Monitor but I still can’t have it display the TEXT to my Blynk app :cry::cry::cry:

My Blynk app still display 11, please help to make it display “BOOST” as it does on my computer

image

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

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

Post your full code.

Pete.

Hi Pete,

Here is full code, spent another 90 minutes today but still can’t make it display the TEXT, please HELP

#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 =============================

I don’t think this can be your full code.
There’s no Blynk connection process or connection credentials, no void setup, no timers defined etc.

Does this code REALLY produce an output in the serial monitor?

Pete.

Problems solved. Thank you for all your help