Ylianst / MeshAgent

MeshAgent used along with MeshCentral to remotely manage computers. Many variations of the background management agent are included as binaries in the MeshCentral project.
https://meshcentral.com
234 stars 90 forks source link

How fast connect a raspberrypi to Meshcentral? #242

Open TommyA52 opened 6 months ago

TommyA52 commented 6 months ago

We are using a rpi zero W for connecting an industrial equipment to internet occasionally (for remote service). At power up the rpi starts a python script which open a local hotpot allowing the user to submit wifi ssid and password by a web interface. Then the script converts the rpi to a wifi client and tries to connect to Meshcentral. It works but take a long time (10-15 minutes or so) for the meshagent to connect. Understand that the reason may be that meshagent increases the time between the attempts when it doesn’t succeed. How solve this? Have tried using "sudo systemctl restart meshagent" when internet connection is established. Seems to get a bit better result, takes usually about 5-6 minutes to connect. Still to much for our need. May be it has something to do with the certificate? Very thankful for help with this!

si458 commented 6 months ago

you have to remember that when the agent connects to meshcentral, it then runs all its scripts, etc to get details of the pi. and the pi zero w isnt the most powerful device. i have an old Pi 2 with meshagent on and it can sometimes connect within 30 seconds, but then i cant actually open a terminal because its CPU is bottlenecked because meshagent is running all its scripts etc to get details about the device.

TommyA52 commented 6 months ago

I have tried to investigate your comment si458, but I don´t think thats the problem. I can open a terminal and use "top" but meshagent doesn't seem to be very busy. But I have also found that if the raspberrypi is powered on for 10 minutes even without internet access and then connected to internet it takes just a few seconds until its connects to Meshcentral. So something is going on at start, I still wonder if it has to do with certificate generation? I understand that it should be stored in the meshagent database or? I have tried to uninstall and reinstall the agent but the same result. I have also thought about if it is possible to increase the priority of meshagent at start. I'm a Linux novice so thankful for any suggestion what to do.

si458 commented 6 months ago

I will have a look over the weekend as I have a pi zero w and a zero 2 w I currently use meshagent on my zero 2 w as it runs my pikvm but it uses archlinux and not debian

TommyA52 commented 6 months ago

Thanks si458! I would really appreciate help on this subject. I have now tried to increase the priority of the meshagent but with no or little result. I have also investigated the certificate generation, it shouldn't be needed more than once and it also just take a minute or so. So there is something else that delay the meshagent after that the rpi is power up.

si458 commented 6 months ago

whats the OS running on your Pi Zero W ?

TommyA52 commented 6 months ago

Rasbian - Stretch23 maj 2024 kl. 16:31 skrev Simon Smith @.***>: whats the OS running on your Pi Zero W ?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

TommyA52 commented 6 months ago

Raspbian / Stretch

si458 commented 6 months ago

Raspbian / Stretch

is it the full desktop gui or just the lite version? and its defo a pi zero w and not a pi zero 2 ?

TommyA52 commented 6 months ago

Full desktop is installed but not used. Yes its a pi zero W.

si458 commented 6 months ago

@TommyA52 great no worries, I'm having an issue at the moment trying to get raspbian installed on my pi zero w at all! Just a black screen on the output! Do u have an image link at all for ur os? Or can share it?

si458 commented 6 months ago

ok got mine working, rapsberry pi imager wasnt working properly so had to use etcher haha

here is a quick 5 second capture using my meshcentral of my pi zero w desktop showing top running DesktopSession-pizerow-2024-05-26-22-13.mcrec.zip you can use https://meshcentral.mydomain.com/player.htm to view it

its literally using 100% cpu when doing remote desktop, my pi zero w does connect to my meshcentral without any issues quite quickly, but the cpu is crying when i do remote desktop

one thing you could try is IF your not using the desktop ui at all, use sudo raspi-config and switch to the terminal auto login or terminal login, this will disable the desktop which might help releave the cpu a little

also you could try running ps aux and pipe it to a file maybe 10 seconds after u restart the meshagent and see whats using all the CPU or memory?

TommyA52 commented 6 months ago

Thank you for trying to help me! Still I haven't succeded... Meshagent trys to connect but it seems that it had to wait for something that is started at power up. So if I wait to start meshagent for say 5 minutes after power up it works fine. This is independent of how long the internet connection had been running. I'm afraid I now have to leave this issue for a while. I have to work with another part of my code that has higher priority.

si458 commented 6 months ago

Just a random idea! Check the meshagent.service inside /etc/systemd/system Screenshot_20240527_132843_Firefox Mine looks like above (just customised) Try removing the network-online.service lines! The service won't start until network is online! So it might be that causing ur issue

TommyA52 commented 6 months ago

Yes, I have noticed it but also read an old post by Ylianst where an issue was cured by adding the lines about network-online.target! Hence I haven't tryed to delete it. But now when I think about I will try to disable the meshagent at boot and then start it when I know that there is a connection. I hope I will have time to test that tomorrow.

si458 commented 6 months ago

you should be able to disable it at startup using systemctl disable meshagent.service and then start/stop using systemctl (start/stop) meshagent.service