2. You've mentioned feelings of low self-worth. That's a classic sign of depression. The racing mind and jumbled thoughts overlaps with many different illnesses though. You definitely want to bring this up with your doctor (especially the last part) as it might be a sign of something more serious (not to scare you or anything.)
On a personal level: try to celebrate your own successes more rather than being overly interested in what other people are doing. There's always going to be someone doing better and if you're always looking at them you forget the progress you have made. For the 'lost the will to code' issue -- its hard to say what the cause is. Depression causes a loss of interest in previously enjoyed activities, but honestly you might just be burned out and fried from the repetition.
Practically, I can understand why you would feel stressed out over financials. If I were you I'd look into moving somewhere with a very low cost of living and find yourself a high paying remote gig (not sure how practical this is for you -- probably asking a lot if you have a family and/or mortgage, idk.) I wouldn't bother learning any new skills tho. It sounds like you already have years of experience. You just have to sell your existing engineering skills and how they translate to designing and implementing different systems with any tech.
Good luck, hope your situation improves.