Creating a loop I think!

Are the scales calibrated correctly? I’ve an HX711 based project and I’m still figuring out how to make sure the chip is calibrated correctly when starting. If the payload keeps at 0.00 that might be because of calibration, or lack thereof.

Or should we assume that if the weight is different the payload will be different as well? Because in that case a couple more examples of the payload would be appreciated :slight_smile:

The scales i am using are connected to a hx711 which have been calibrated using an Arduino board.
I have the Serial connected to a UI gauge and can see when the weight has been added to the scales.

Does the attached photo give you enough information? sorry for lack of info and appreciate everyone time to help me.

I see here that all values on the debug window are strings. In the screenshot in your earlier post there were mostly integer values, and 1 string. In your new screenshot the debug values are coming from a node with a different ID.

I just imported the flow to be sure, and I'm noticing a couple things. I'm not sure if they are related to your problem, but they explain the difference between the seen strings/numbers, which might help others to figure out the exact issue here (tagging @bakman2 and @ukmoose to further this).

First of all, as can be seen from the latest screenshot is that the values coming from the serial are all strings. The switch this get inputted in, has a check for msg.payload (which are string values). The first defined rule says >= (number) 10.00, the second defined rule says <= (string) 10.00.

In order to properly check the values, between the incoming serial and the switch a function node to parse the data to numbers should be placed. I think, without running the code myself that msg.payload = parseFloat(msg.payload); return msg should do the trick. With now a float value being passed to the switch, the second rule needs to be changed to a number value (note the difference between the 0/9 icon, and the a/z icon in front of the values). With that, a proper check should take place. However, the "checking all rules" option is selected, and the value 10.00 will trigger both rules. I am not familiar enough with the internals of the switch to figure out with this combination as to where the output will go.

Next up, the first output will go to "payload 0", which I will follow first. This function node sets the payload to integer value 0, then passes it on to the trigger node. After the time has passed, it will send forward a string value "1":


which in turn is forwarded to the side valve, which once again forwards string values to the GPIO nodes behind it when clicked.

The GPIO node explicitly mentions that for "digital output" (the selected option) the input must be 0 or 1, which corresponds to integer values as these are the common version of sending a true or false, or a high or low input.

The function node will also connect to the dashboard switch for the side fan. This integer value 0 is passed on, and the dashboard switch will forward an integer value when clicked, which matches the request of the GPIO pin behind it.

The second output of the switch is going to a couple different nodes. First there is a secondary change node, "set message reset" which does not have any outgoing wires, so the result is ignored. It also goes to a "payload 1" function node, which sets the payload to integer 1. This is then forwarded to the same fan dashboard switch, which correctly controls the GPIO pin with an integer output.
Also in the flow is a "set msg payload" switch, which sets the payload to a string "1". This output is being send to the debug node, as well as the side valve dashboard switch with the string values. However, this node doesn't have an input, and is never called as a result.

The debug node is, in the latest posted flow, only connected to nodes that have a string output. If in previous versions that weren't posted it was connected to the "payload 1" function node, or the fan dashboard switch, it might have been able to post integers as well as strings. In the latest flow it will only post strings.

My suggestion to start with would be to have the incoming serial data be parsed through the function node with the code I gave above to parse them to floats, then have that function node output to both the switch and the gauge (it will work better too with floats rather than strings as input :slightly_smiling_face:). Next, check all your nodes for strings, integers and floats and check for each node which you need. Based on this, I'd say that strings are not needed anywhere, but I might overlook something. If any of the others disagree with me here, feel free to improve this part. Make sure that the dashboard switches that enter into the GPIO output integer values, so the GPIO pin understands the low/high difference.

With these changes done, you should get at least a situation that is debuggable, and allows for a continued check on what is going correct/wrong.

Ok, it very clear that I'm so far out my depth here. @afelix Thank you so much for your response.
I might have dirty the water by making changes and sending a half arsed flow.
Ie not connecting the nodes and changing nodes string values.

i will carry on digging around to see what I can do. unless you kind people would put a flow together for me :slight_smile:

Thanks to you all

I have been called “the human debugger” on occasion by both friends and former coworkers, often taking a piece of paper and pen to write out everything a set of code does, noting variable values and type for each line, and changes that happen. If you make changes and would like another check like this for value and variable type, tag me (@afelix) on a post with the updated flow and I’ll take a look again :slight_smile:
(Basically, in terms of code, if a function is less than 150 ish lines without too many (nested) loops doing it on paper is still within my limits. Beyond that you may have to ask yourself if that function is still the most efficient at that length or if optimisation/readability has to be improved. And yes, I have done 170 lines with several nested loops and about a dozen of variables outside of the loops before. It wasn’t pretty.)

For other readers, we have continued this in direct message. After a bit of questioning and brainstorming a flow is being created based on blocking part of the output from happening if it’s already running, and unblocking (and reading weight again) when that part is finished, then check again and repeat if necessary. The repeat/loop takes place through the serial repeatedly giving values.

It’s not done being created yet, but it’s in progress and will at some point likely continue here again.

Hi
For what I understood about your problem (maybe not so much :slight_smile: ) My suggestion is the following

[{"id":"30d28a92.a59416","type":"function","z":"34a2e63d.af4712","name":"Payload 0","func":"var sr = context.get('sr')||0;\nif (msg.payload == \"set\")\n    {context.set('sr',1);\n    sr = 1;\n    return;\n    }\nif (msg.payload == \"reset\")\n    {context.set('sr',0);\n    sr = 0;\n    return;\n    }\nif (sr === 1)\n    {\n    return;\n    }\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":240,"wires":[["85c167df.a57368","3f0ccc3f.890604","562667.a8ca9998","51338a5e.337f04"]]},{"id":"ff65ae82.059468","type":"switch","z":"34a2e63d.af4712","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10.00","vt":"num"}],"checkall":"true","outputs":1,"x":390,"y":240,"wires":[["30d28a92.a59416"]]},{"id":"85c167df.a57368","type":"trigger","z":"34a2e63d.af4712","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","name":"wait to turn off","x":860,"y":240,"wires":[["36d23810.3e936","a5230720.4a76d"]]},{"id":"438b0d75.53d414","type":"inject","z":"34a2e63d.af4712","name":"debug input","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":110,"y":80,"wires":[["6832288c.61929"]]},{"id":"ce98cad2.70036","type":"function","z":"34a2e63d.af4712","name":"","func":"msg.payload = msg.payload * 1;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":240,"wires":[["ff65ae82.059468"]]},{"id":"e00f11aa.b991e","type":"debug","z":"34a2e63d.af4712","name":"turn on","active":true,"console":"false","complete":"payload","x":800,"y":380,"wires":[]},{"id":"c7fcc461.e6e318","type":"debug","z":"34a2e63d.af4712","name":"turn off","active":true,"console":"false","complete":"payload","x":1080,"y":400,"wires":[]},{"id":"36d23810.3e936","type":"trigger","z":"34a2e63d.af4712","op1":"","op2":"reset","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","name":"wait to reset (time close)","x":936.6666259765625,"y":48.33332061767578,"wires":[["30d28a92.a59416","c15961c5.a2fce8"]]},{"id":"3f0ccc3f.890604","type":"function","z":"34a2e63d.af4712","name":"set","func":"if (msg.payload != \"reset\") {\nmsg.payload = \"set\";\nreturn msg;}\nelse\n{return;}","outputs":1,"noerr":0,"x":676.6666259765625,"y":96.6666488647461,"wires":[["30d28a92.a59416"]]},{"id":"562667.a8ca9998","type":"function","z":"34a2e63d.af4712","name":"","func":"msg.payload = \"open valve\";\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":300,"wires":[["e00f11aa.b991e"]]},{"id":"a5230720.4a76d","type":"function","z":"34a2e63d.af4712","name":"","func":"msg.payload = \"close valve\";\nreturn msg;","outputs":1,"noerr":0,"x":963.3333740234375,"y":321.66668701171875,"wires":[["c7fcc461.e6e318"]]},{"id":"6832288c.61929","type":"random","z":"34a2e63d.af4712","name":"debug generator","low":"1","high":"20","inte":"false","x":210,"y":160,"wires":[["715b0fa3.c96608","ce98cad2.70036"]]},{"id":"715b0fa3.c96608","type":"debug","z":"34a2e63d.af4712","name":"","active":true,"console":"false","complete":"false","x":448.125,"y":85,"wires":[]},{"id":"51338a5e.337f04","type":"debug","z":"34a2e63d.af4712","name":"","active":true,"console":"false","complete":"false","x":818.1249389648438,"y":191.24996948242188,"wires":[]},{"id":"b242edff.6e298","type":"debug","z":"34a2e63d.af4712","name":"","active":true,"console":"false","complete":"payload","x":1162.291748046875,"y":261.2499694824219,"wires":[]},{"id":"c15961c5.a2fce8","type":"function","z":"34a2e63d.af4712","name":"","func":"msg.payload = \"reset\";\nreturn msg;","outputs":1,"noerr":0,"x":1100,"y":153.3333282470703,"wires":[["b242edff.6e298"]]}]

hoping it can helps

All best
M