Im having an issue where im trying to update a value from node red using sliders or any input and triggering a function on the device to push the current value of the slider into a float.
its to set a temperature alarm setpoint on a slider.
For some reason when the function runs it does not properly format the incoming string into a double/float and instead sets it to 0 no matter how i format the data. Node red shows that the data is correctly being passed to the function. The function shows up properly and executes properly in the particle console when i execute it manually. It just does not execute properly when called from node red.
I appreciate you taking the time to look into this. I tried your sample code and the debugging log info to no avail. No matter what gets passed into the function on the device side it always gets forced back to 0, not just once but continuously.
I decided to try and play with the strings and numbers being passed into the function and it didnt seem to make a difference. This is the function im using to convert the raw number from the slider on the dashboard to a string before passing it to the particle function:
The code you provided did answer two things however, it is receiving a number of some sort, however it is constantly receiving the "invalid number" in the log.
This is the actual debug output to the particle function block in node red, seems like a well made string to me.
I cannot get it to parse the string into a double or float value properly, there must be something im missing. Do i need to add the decimal point? Is a string[2] an issue potentially? Should it be a string length of [1]?
@Glanetech, just a reminder that if you do a Particle.publish() within a Particle.function(), you should store the value of String value since the function and publish share a buffer. You can do that with: String val = value; and using val in the rest of the function.
Initially i didnt have the serial monitor checking the raw value coming in like you had previously suggested, i thought the event logs would catch it.
Below is what the serial monitor Log caught
[app] INFO: Received value: ---msg.payload---
It seems apparent that the message being sent is "msg.payload" rather than the actual value. So im assuming that the value needs to be published to a variable and then the function triggered?
ok, so the issue seems to be on the node red side, some how it is sending msg.payload instead of the value you intended.
This is what needs fixing, and you'll be on your way to success.
i fixed the issue, the node red function block (official library) does not pull the parameter being passed into the argument field properly. it only passes whatever is in the field as a literal, making it somewhat useless.
The user contributed SSE block worked fine, its a library issue on node red.