Firstly I am totally new to all of this so please be gentle with me, however, I am really struggling with splitting data to be able to display in to two Gauges. It is presented from a single API value and the range is from -3300 to +3300. Ideally what I would like is one Gauge displaying data from 0 to -3300 and one displaying +1 to +3300.
So far I have written a function with two outputs as follows:
var x = msg.payload.Pac_total_W;
if (x >=1){
var msg_0 = {payload : msg.payload.Pac_total_W}
return [msg_0]}
else if (x <=0){
var msg_1 = {payload : msg.payload.Pac_total_W}
return [msg_1]}
The very first example there shows you an array with two things in it... (one for each output)... how many things do you have in the arrays that you are returning? (hint: not 2)
Did you mean it to do nothing if x is, for example, 0.5? Perhaps you think that can never happen, but it is better not to allow such holes in your s/w even if you think it will never happen. This would probably be a better way to code it
if ( x > 0 ) {
...
} else {
// must be less than or equal to 0
...
}
Well, it's an interesting question. However the API I am reading from doesn't display say 0.1 or 0.2 hence the 1 figures as that would be the 1st plus figure I am pulling. But technically i am guessing that greater than >0 would be correct as if a change was made to the API that allowed this it would be presented correctly in the application.
Its working great though screenshot of the output below:
The history of s/w is strewn with debris from crashes caused by spec writers saying "this can't possibly happen".
In addition the suggested code is slightly more efficient as only one test is required, and there does not appear to be a down side.
Weird so if I do a conversion in the function it works fine, so I take it the system has a bug with minus figures not that it matters to me as I convert it to a plus figure.
Not a bug, a misunderstanding. The gauge itself (not the text display) shows the value in the payload. You have scaled the gauge 0 to 3300 and then given it a -ve value, so it is off the bottom. By changing it in the function you are now giving the gauge a value in range.
It is always best to initially assume that some malfunction is of ones own making. Occasionally it will be a bug, but my experience is that usually it is myself that is missing something.