Skip to content

Particle function block does not properly pass strings to float values #7

@Glanetech

Description

@Glanetech

image
image
image

The issue im grappling with is the function block receiving the string input from the slider (Temperature setpoint block and deadband block) These are being converted from a number into a string and then passed in to the particle function block.

The function that is being called on the SOM tracker device is as follows:

` int setTempAlarm(String value) {

// Log the received value
Log.info("Received value: ---%s---", value.c_str());

if (value.trim().length() == 0) {
    Particle.publish("debug", "Received empty value for Temp Setpoint", PRIVATE);
    return -1;
}

// Validate if input is numeric
if (!isValidNumber(value)) {
    Particle.publish("debug", "Invalid numeric value for Temp Setpoint", PRIVATE);
    return -1;
}

tempAlarmSetpoint = value.toFloat();
Particle.publish("debug", String::format("Temp Setpoint Updated: %.2f", tempAlarmSetpoint), PRIVATE);
return 1;

}

// Helper function to validate numeric strings
bool isValidNumber(const String &str) {
for (int i = 0; i < str.length(); i++) {
if (!isdigit(str[i]) && str[i] != '.' && str[i] != '-') {
return false;
}
}
return true;
}
`

The fault is:

  1. the value is shown to be "an invalid numeric value for temp setpoint" in the particle console, im unsure if this is a device issue or a node red library issue
  2. The value passed into the particle function block resets to 0 continuously.
  3. the function on the device when called from the console works fine, when attempting to write the same value from node red, it sets it to 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions