We not begin the client every loop or better, we begin every loop while the client hasn't connected to the socket. When the client is connected it join the while and so not repeat again the begin
PS: When we use connected with Serial Monitor, it ensures us that not try again the begin because not print "Starting websocket client"
Regarding the schematic:
A schematic that does not reflect true components and wiring as as good as useless. Draw a true one with pen and paper, take a photo and attached it.
I can not find if anybody mentioned this but Serial.print on the MKR prints over the USB connection, not the Tx/Rx pins. Use Serial1 instead.
This is interestaring, so the pin TX and RX use Serial1 and not Serial right? Now we try something, but I have a question. Arduino Uno doesn't have Serial 1 so the Serial1 of MKR can communicate with Serial of Arduino Uno?
Note that I specifically mentioned the MKR, not the Uno. So on the Uno you use Serial for communication over USB and over Tx/Rx and on the MKR you can use Serial1 for the communication over Tx/Rx and Serial for communication of USB.
Notes:
Connecting something to the Tx and Rx pins on the Uno will interfere with the upload to the Uno. So you have to disconnect before uploading and reconnect afterwards. Alternatively you can use SoftwareSerial on two other pins for communication with the MKR during development and later use Serial. Advantage is that you maintain the ability to debug your Uno code using Serial.
The Uno has one UART that is used for both USB and Tx/Rx. The MKR has several UARTs (one is connected to Tx/Rx) and uses native USB for communication with the PC.
We've just tried with Serial1, in both circuit so with the resistence and then connecting directly RX - TX between Uno and MKR. But in both case Uno not receive nothing from MKR.
Bro read and next do the affermation. You say that the problem is that two places in my code are consuming byte. But when I use Serial Monitor it all works, so can you understand too that it can't be the problem? Because if it was the problem when we use the Serial Monitor it should not work, but it works with serial monitor
Bro I listen what you say, but I want that you tell me why with Serial Monitor work.
Because if I understand well that you say, the problem of "lost bytes" tecnically it should show up in Serial Monitor too, and not only when we use TX & RX