Pi keyboard node with internet connection looses characters

Hi, I'm a new Node-RED user from Japan.

Could you give me some information and advice on Pi Keyboard node,
node-red-node-pi-gpio? My problem is with internet connection Pi Keyboard
node looses characters. But without internet connection it works fine.

I tried to capture characters from bar code scanner by using Pi Keyboard node.
The flow is defined and stored on Raspberry Pi 3B locally. Almost of all the flow
is done in local. Once all the red characters are convined and entire code is
created, it is sent to Google Spreadsheet by using G Sheet node.

During development in my office for about 1 month, The flow and Pi Keyboard
node worked fine. Last January I delivered my devices and barcode scanners.
My customer said about 4 days after delivery suddenly my devices started
behaving incorrectly. Incorrectly means LEDs on my devices did not flush after
reading the barcode.

I analysed the incorrect bahavior and realized :

  1. Pi keyboard node looses characters.
  2. The problem happens 1 minute after reading previous code.
  3. During such term, 1minute, it keeps working fine if I keep reading code
    continuously.
  4. If I finish reading code and wait for 1 minute and try to read again, it fails.
  5. If I use the device and barcode scanner stand-alone, without internet
    connection, it works OK.
  6. If I use the device and barcode scanner with internet connection, it fails.

My flow forwards the code to a Google Spreadsheet. So I definetly need
internet connection.

Does anybody have an idea to solve the problem?

Thank you,

Here is the information on my Pi Keyboard node information.

  • node-red-node-pi-gpio, 2.0.6

One more question.

Does the Node-RED flow tries to access (send/receive) anything to/from Internet when the flow is activated?

I'm wondering such access process performed at the first stage of an entire flow prevents Pi Keyboard node receiving characters.

Does every flow try to access somewhere on the Internet when executed?

What do you think?
Does anyone have similar problem?

Raspberry pi 3B seems to use USB hub for communicating USB devices, NOT directly connected. Does it cause the problem?

I have no idea about your flow but no, Node-red does not require internet access to work correctly.

Have you checked the power demands of all devices connected to the Pi?
There is a limit to the amount available for USB devices.
Also check vcgencmd get_throttled. If the response is non-zero it may indicate an inadequate power supply.

Thanks, jbudd!

I tried the command and checked the response.

pi@raspberrypi:~ $ vcgencmd get_throttled
throttled=0x50000

Does this mean the power supply to the barcode scanner is inadequate?

I also tried the command on my Ras Pi 4B. The response is below.

pi@raspberrypi:~ $ vcgencmd get_throttled
throttled=0x0

Not necessarily.
It means that the CPU clock has been throttled at some time since the last boot.

One reason could be that the voltage supplied to the Pi dropped below the minimum, even for a tiny part of a second.

This can be caused by voltage drop in too thin USB cables or by a poor quality power supply which fails to maintain 5V when under load.

Thanks, jbudd!

Could you tell me why the 2 responses are different? The response from Ras Pi 4B seems to be OK. But the response from Ras Pi 3B seems to be NOT OK. I use the same power supplys and the same barcode scanners.

And as I told above, I had spent for more than 1 month during development. But I did not have the problem. Suddenly it appeared in my customer site. Why? Any idea?

I would check the quality of the USB cables.
Maybe the power is noisy at the customer's site, from welding or such like. A total guess.
But you might get better advice about tracking this down on the Raspberry Pi forum.

Let me check the meaning of "USB cables".
Do you mean USB cables for power supply or for barcode scanner? Or both?

One critical point that might be worth keeping in mind.

The RPI 3b uses the same bus to drive the Ethernet and USB ports.
So if the USB ports are being hammered, it has the potential to knock out the Ethernet.

RPI 4 The USB and Ethernet are on separate buses.
I'm not a mechanical / electrical engineer - but something to maybe consider

If the CPU was throttled because of low voltage, it's the power supply and it's cable that you need to check.

Thank you guys!

I'll check mechanical/electrical structures, USB ports/USB hub/LAN port, on Ras Pi 3B.

Do you have any idea on the useful website which describes USB hub or etc about Ras Pi 3B?

Hello, guys.

I tried several combinations of power supplys and USB cables, but I could not make it.

Strange things are :

  1. If I try to keep reading frequently, for example every 30s, RasPi 3B can read entire code.
  2. If I wait for more than 30s and try reading, it fails.
  3. When it fails, try reading the code again it's OK.

It seems "30s timer?" is running, it stops accepting a new code once te timer has been expired.

What's the timer?
Can I stop the timer?

And let me tell you 1 thing. It was working correctly for more than 1 month.
It start failing suddnely? Why?

Please give me any advice.

Maybe at this point - an export of your flow will help (removing any sensitive info you feel is necessary).
Presently, this is guess work, but maybe your flow will reveal something that someone else can spot

Thanks, marcus-j-davies.

Here is the flow. Original contains more nodes. I just give you key areas.

----------------------------------------------------------------------------------------------------- [{"id":"e2f1907f.6527c","type":"comment","z":"be764ee2.db6f7","name":"①コード情報作成","info":"","x":710,"y":340,"wires":[]},{"id":"80131045.beb17","type":"comment","z":"be764ee2.db6f7","name":"Test version : 1.00 (23/3/19)","info":"","x":160,"y":40,"wires":[]},{"id":"3332f094.5001d","type":"join","z":"be764ee2.db6f7","name":"make_entire_code","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":730,"y":380,"wires":[["ce1d7674.a4dbf8","cc2b30af.a2469"]]},{"id":"ebaec867.a32708","type":"function","z":"be764ee2.db6f7","name":"msg : 0","func":"msg.payload = \"0\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":180,"wires":[["3332f094.5001d"]]},{"id":"4b614c08.4dd4e4","type":"function","z":"be764ee2.db6f7","name":"msg : 1","func":"msg.payload = \"1\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":220,"wires":[["3332f094.5001d"]]},{"id":"36f3c92d.4146a6","type":"function","z":"be764ee2.db6f7","name":"msg : 2","func":"msg.payload = \"2\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":260,"wires":[["3332f094.5001d"]]},{"id":"ea4f3f2f.d0ba4","type":"function","z":"be764ee2.db6f7","name":"msg : 3","func":"msg.payload = \"3\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":300,"wires":[["3332f094.5001d"]]},{"id":"2a3ffbd.3c2bb04","type":"function","z":"be764ee2.db6f7","name":"msg : 4","func":"msg.payload = \"4\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":340,"wires":[["3332f094.5001d"]]},{"id":"42b11155.789a5","type":"function","z":"be764ee2.db6f7","name":"msg : 5","func":"msg.payload = \"5\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":380,"wires":[["3332f094.5001d"]]},{"id":"315e12e3.685a0e","type":"function","z":"be764ee2.db6f7","name":"msg : 6","func":"msg.payload = \"6\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":420,"wires":[["3332f094.5001d"]]},{"id":"173512ca.9d1bed","type":"function","z":"be764ee2.db6f7","name":"msg : 7","func":"msg.payload = \"7\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":460,"wires":[["3332f094.5001d"]]},{"id":"a1a5430f.fafae","type":"function","z":"be764ee2.db6f7","name":"msg : 8","func":"msg.payload = \"8\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":500,"wires":[["3332f094.5001d"]]},{"id":"558133c6.ccf18c","type":"function","z":"be764ee2.db6f7","name":"msg : 9","func":"msg.payload = \"9\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":540,"wires":[["3332f094.5001d"]]},{"id":"ce1d7674.a4dbf8","type":"debug","z":"be764ee2.db6f7","name":"output code","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":180,"wires":[]},{"id":"cc2b30af.a2469","type":"debug","z":"be764ee2.db6f7","name":"output length","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.length","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":220,"wires":[]},{"id":"ad75e947.18c048","type":"switch","z":"be764ee2.db6f7","name":"change_code","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1111","vt":"str"},{"t":"eq","v":"22","vt":"str"},{"t":"eq","v":"33","vt":"str"},{"t":"eq","v":"44","vt":"str"},{"t":"eq","v":"55","vt":"str"},{"t":"eq","v":"66","vt":"str"},{"t":"eq","v":"77","vt":"str"},{"t":"eq","v":"88","vt":"str"},{"t":"eq","v":"99","vt":"str"},{"t":"eq","v":"1010","vt":"str"},{"t":"eq","v":"2828","vt":"str"}],"checkall":"true","repair":false,"outputs":11,"x":240,"y":380,"wires":[["ebaec867.a32708"],["4b614c08.4dd4e4"],["36f3c92d.4146a6"],["ea4f3f2f.d0ba4"],["2a3ffbd.3c2bb04"],["42b11155.789a5"],["315e12e3.685a0e"],["173512ca.9d1bed"],["a1a5430f.fafae"],["558133c6.ccf18c"],["94db94d4.16c3b8"]]},{"id":"5b6ca905.69bf18","type":"join","z":"be764ee2.db6f7","name":"2 to 1_code","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"0.5","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":170,"y":160,"wires":[["ad75e947.18c048"]]},{"id":"94db94d4.16c3b8","type":"function","z":"be764ee2.db6f7","name":"msg : enter","func":"msg.payload = \"\\n\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":580,"wires":[[]]},{"id":"2b96d463.eb535c","type":"function","z":"be764ee2.db6f7","name":"Initialize","func":"var wait_flg = flow.get('wait_flg') || 0;\nflow.set('wait_flg', wait_flg);","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":100,"wires":[[]]},{"id":"710563a9.3ab66c","type":"debug","z":"be764ee2.db6f7","name":"debug 1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":400,"y":40,"wires":[]},{"id":"11d6f7fc.0b2f58","type":"debug","z":"be764ee2.db6f7","name":"debug 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":120,"wires":[]},{"id":"bf1eca5f.02a078","type":"rpi-keyboard","z":"be764ee2.db6f7","name":"","x":130,"y":100,"wires":[["710563a9.3ab66c","2b96d463.eb535c","5b6ca905.69bf18"]]}]

Ok,

I have failed to witness the keyboard not sending characters (Evan after waiting 1:30 after the last)

BUT
if the length of your barcodes are 16, would it make more sense to trigger make_entire_code
after the 16th?


Screenshot 2023-03-22 at 15.07.36

Also, reading the keyboard is achieved via a python process that opens up a file read operation of the "keyboard" device - could the barcode scanner going into standby be killing this process perhaps, and it needing to start up again, before reading continues (only after the scanner wakes up again) - given the file could become an invalid resource.

Note: I used a keyboard, that might skew my investigation

:man_shrugging:

Thanks, marcus-j-davies!

Today I tried another approach, USB port power control.

I got to know a command, uhubctl, which control and monitor USB port power status.
It makes a slight progress.

I added an independent flow in my Node-RED flow. It injects a trigger at every 30s
and execute a command below.

sudo uhubctl -l 1-1 -p 2 -a off

By the way my USB port status is this.

pi@raspberrypi:~ $ sudo uhubctl
Current status for hub 1-1 [0424:9514, USB 2.00, 5 ports, ppps]
Port 1: 0503 power highspeed enable connect [0424:ec00]
Port 2: 0103 power enable connect [28e9:03da NETUM USB Keyboard]
Port 3: 0100 power
Port 4: 0100 power
Port 5: 0100 power
Current status for hub 1 [1d6b:0002 Linux 5.10.17-v7+ dwc_otg_hcd DWC OTG Controller 3f980000.usb, USB 2.00, 1 ports, ppps]
Port 1: 0503 power highspeed enable connect [0424:9514, USB 2.00, 5 ports, ppps]

As I said above, it makes a slight progress. It means I could read a barcode anytime.
But it seemed reading process might take long, it is too slow. I have to wait, no immediate
response. Not good for barcode reading system.

So I'm wondering any other way, command to control USB hub/port.

I would be appreciated, if you have any idea.

2 more things.

  1. It's clear and strange if Ras Pi is not connected to internet wireless, WiFi, or wired,
    It never fails.
  2. If I reset, means turn off and on the power, my wifi router, Ras Pi can read the
    barcode correctly for a while, maybe about 5 to 7 minutes. After that it fails. Strange ...

Internal USB hub causes these problems?