From e95e326baa78366213c39400ed966f1e50ff686d Mon Sep 17 00:00:00 2001 From: pivotsengineer Date: Fri, 9 Aug 2024 16:48:40 +0200 Subject: [PATCH 01/21] Update setup.py --- setup.py | 78 +++++--------------------------------------------------- 1 file changed, 7 insertions(+), 71 deletions(-) diff --git a/setup.py b/setup.py index a80e672..5c2bfb8 100755 --- a/setup.py +++ b/setup.py @@ -33,97 +33,33 @@ def replace_num(file,initial,new_num): break for x in range(1,4): - if os.system("sudo pip3 install -U pip") == 0: + if os.system("sudo apt-get install -y python3-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") == 0: break for x in range(1,4): - if os.system("sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") == 0: + if os.system("sudo apt-get install -y python3-flask python3-flask-cors python3-websockets") == 0: break for x in range(1,4): - if os.system("sudo -H pip3 install --upgrade luma.oled") == 0: + if os.system("sudo apt-get install -y python3-opencv python3-numpy python3-imutils python3-zmq python3-psutil") == 0: break for x in range(1,4): - if os.system("sudo apt-get install -y i2c-tools") == 0: + if os.system("sudo apt-get install -y python3-smbus i2c-tools") == 0: break for x in range(1,4): - if os.system("sudo apt-get install -y python3-smbus") == 0: + if os.system("sudo apt-get install -y libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") == 0: break for x in range(1,4): - if os.system("sudo pip3 install icm20948") == 0: - break - -for x in range(1,4): - if os.system("sudo pip3 install flask") == 0: - break - -for x in range(1,4): - if os.system("sudo pip3 install flask_cors") == 0: - break - -for x in range(1,4): - if os.system("sudo pip3 install websockets") == 0: - break - -try: - replace_num("/boot/config.txt",'#dtparam=i2c_arm=on','dtparam=i2c_arm=on') -except: - print('try again') - -try: - replace_num("/boot/config.txt",'[all]','[all]\ngpu_mem=128') -except: - print('try again') - -try: - replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1\nstart_x=1') -except: - print('try again') - -try: - replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1') -except: - print('try again') - - -for x in range(1,4): - if os.system("sudo pip3 install opencv-contrib-python==3.4.11.45") == 0: - break - elif os.system("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45") == 0: - break - -for x in range(1,4): - if os.system("sudo pip3 uninstall -y numpy") == 0: - break - -for x in range(1,4): - if os.system("sudo pip3 install numpy==1.21") == 0: - break - elif os.system("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple numpy==1.21") == 0: - break - -for x in range(1,4): - if os.system("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") == 0: - break - -for x in range(1,4): - if os.system("sudo pip3 install imutils zmq pybase64 psutil") == 0: - break - elif os.system("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil") == 0: + if os.system("sudo apt-get install -y python3-pi-ina219") == 0: break for x in range(1,4): if os.system("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") == 0: break -for x in range(1,4): - if os.system("sudo pip3 install pi-ina219") == 0: - break - - for x in range(1,4): if os.system("cd " + thisPath + " && cd .. && sudo git clone https://github.com/oblique/create_ap") == 0: break @@ -137,4 +73,4 @@ def replace_num(file,initial,new_num): print('Completed!') -os.system("sudo reboot") \ No newline at end of file +os.system("sudo reboot") From 49969147b45c39619f169b7c1fbeafecd7321b3b Mon Sep 17 00:00:00 2001 From: pivotsengineer Date: Fri, 9 Aug 2024 17:05:55 +0200 Subject: [PATCH 02/21] Refactoring setup.py --- setup.py | 90 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/setup.py b/setup.py index 5c2bfb8..1b93546 100755 --- a/setup.py +++ b/setup.py @@ -20,57 +20,65 @@ def replace_num(file,initial,new_num): with open(file,"w") as f: f.writelines(newline) -for x in range(1,4): - if os.system("sudo apt update") == 0: - break +def run_command(command, retries=3): + for _ in range(retries): + if os.system(command) == 0: + return True + return False + +if run_command("sudo apt update"): + run_command("sudo apt -y dist-upgrade") + run_command("sudo apt clean") + run_command("sudo pip3 install -U pip") + run_command("sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") + run_command("sudo -H pip3 install --upgrade luma.oled") + run_command("sudo apt-get install -y i2c-tools") + run_command("sudo apt-get install -y python3-smbus") + run_command("sudo pip3 install icm20948") + run_command("sudo pip3 install flask") + run_command("sudo pip3 install flask_cors") + run_command("sudo pip3 install websockets") -for x in range(1,4): - if os.system("sudo apt -y dist-upgrade") == 0: - break - -for x in range(1,4): - if os.system("sudo apt clean") == 0: - break - -for x in range(1,4): - if os.system("sudo apt-get install -y python3-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") == 0: - break +try: + replace_num("/boot/config.txt",'#dtparam=i2c_arm=on','dtparam=i2c_arm=on') +except: + print('Failed to update /boot/config.txt for i2c_arm=on') -for x in range(1,4): - if os.system("sudo apt-get install -y python3-flask python3-flask-cors python3-websockets") == 0: - break +try: + replace_num("/boot/config.txt",'[all]','[all]\ngpu_mem=128') +except: + print('Failed to update /boot/config.txt for gpu_mem=128') -for x in range(1,4): - if os.system("sudo apt-get install -y python3-opencv python3-numpy python3-imutils python3-zmq python3-psutil") == 0: - break +try: + replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1\nstart_x=1') +except: + print('Failed to update /boot/config.txt for camera_auto_detect=1') -for x in range(1,4): - if os.system("sudo apt-get install -y python3-smbus i2c-tools") == 0: - break +try: + replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1') +except: + print('Failed to update /boot/config.txt for camera_auto_detect=1') -for x in range(1,4): - if os.system("sudo apt-get install -y libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") == 0: - break +# Install OpenCV +if not run_command("sudo pip3 install opencv-contrib-python==3.4.11.45"): + run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45") -for x in range(1,4): - if os.system("sudo apt-get install -y python3-pi-ina219") == 0: - break +# Uninstall and reinstall numpy +if run_command("sudo pip3 uninstall -y numpy"): + if not run_command("sudo pip3 install numpy==1.21"): + run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple numpy==1.21") -for x in range(1,4): - if os.system("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") == 0: - break +run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") +if not run_command("sudo pip3 install imutils zmq pybase64 psutil"): + run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil") -for x in range(1,4): - if os.system("cd " + thisPath + " && cd .. && sudo git clone https://github.com/oblique/create_ap") == 0: - break +run_command("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") +run_command("sudo pip3 install pi-ina219") -try: - os.system("cd " + thisPath + " && cd .. && cd create_ap && sudo make install") -except: - pass +if run_command(f"cd {thisPath} && cd .. && sudo git clone https://github.com/oblique/create_ap"): + run_command(f"cd {thisPath} && cd .. && cd create_ap && sudo make install") -replace_num('/etc/rc.local','exit 0','cd '+thisPath+' && sudo python3 webServer.py &\nexit 0') +replace_num('/etc/rc.local','exit 0',f'cd {thisPath} && sudo python3 webServer.py &\nexit 0') print('Completed!') - os.system("sudo reboot") From 3af3c44b496e36164abd4f6c89e478f8bed1bc42 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Fri, 9 Aug 2024 17:58:54 +0200 Subject: [PATCH 03/21] add gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acd5a2e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +waveshare_OLED/__pycache__/ \ No newline at end of file From b15e029af70c3c67cdbef7378091ae1e511ba32f Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Fri, 9 Aug 2024 18:17:42 +0200 Subject: [PATCH 04/21] --break-system-packages --- setup.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 1b93546..dd5aa86 100755 --- a/setup.py +++ b/setup.py @@ -29,15 +29,15 @@ def run_command(command, retries=3): if run_command("sudo apt update"): run_command("sudo apt -y dist-upgrade") run_command("sudo apt clean") - run_command("sudo pip3 install -U pip") + run_command("sudo pip3 install --break-system-packages -U pip") run_command("sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") - run_command("sudo -H pip3 install --upgrade luma.oled") + run_command("sudo -H pip3 install --break-system-packages --upgrade luma.oled") run_command("sudo apt-get install -y i2c-tools") run_command("sudo apt-get install -y python3-smbus") - run_command("sudo pip3 install icm20948") - run_command("sudo pip3 install flask") - run_command("sudo pip3 install flask_cors") - run_command("sudo pip3 install websockets") + run_command("sudo pip3 install --break-system-packages icm20948") + run_command("sudo pip3 install --break-system-packages flask") + run_command("sudo pip3 install --break-system-packages flask_cors") + run_command("sudo pip3 install --break-system-packages websockets") try: replace_num("/boot/config.txt",'#dtparam=i2c_arm=on','dtparam=i2c_arm=on') @@ -60,23 +60,24 @@ def run_command(command, retries=3): print('Failed to update /boot/config.txt for camera_auto_detect=1') # Install OpenCV -if not run_command("sudo pip3 install opencv-contrib-python==3.4.11.45"): - run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45") +if not run_command("sudo pip3 install --break-system-packages opencv-contrib-python==3.4.11.45"): + run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45") # Uninstall and reinstall numpy if run_command("sudo pip3 uninstall -y numpy"): - if not run_command("sudo pip3 install numpy==1.21"): - run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple numpy==1.21") + if not run_command("sudo pip3 install --break-system-packages numpy==1.21"): + run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple numpy==1.21") run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") -if not run_command("sudo pip3 install imutils zmq pybase64 psutil"): - run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil") +if not run_command("sudo pip3 install --break-system-packages imutils zmq pybase64 psutil"): + run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil") run_command("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") -run_command("sudo pip3 install pi-ina219") +run_command("sudo pip3 install --break-system-packages pi-ina219") -if run_command(f"cd {thisPath} && cd .. && sudo git clone https://github.com/oblique/create_ap"): - run_command(f"cd {thisPath} && cd .. && cd create_ap && sudo make install") +if not os.path.exists(os.path.join(thisPath, '..', 'create_ap')): + if run_command(f"cd {thisPath} && cd .. && sudo git clone https://github.com/oblique/create_ap"): + run_command(f"cd {thisPath} && cd .. && cd create_ap && sudo make install") replace_num('/etc/rc.local','exit 0',f'cd {thisPath} && sudo python3 webServer.py &\nexit 0') From 3f9f56542467180e3f097fe29ad6f135817581d5 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Fri, 9 Aug 2024 18:46:31 +0200 Subject: [PATCH 05/21] numpy installation update --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index dd5aa86..9fa67ce 100755 --- a/setup.py +++ b/setup.py @@ -63,9 +63,12 @@ def run_command(command, retries=3): if not run_command("sudo pip3 install --break-system-packages opencv-contrib-python==3.4.11.45"): run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45") +# Install required dependencies for numpy +run_command("sudo apt-get install -y gfortran libopenblas-dev liblapack-dev") + # Uninstall and reinstall numpy if run_command("sudo pip3 uninstall -y numpy"): - if not run_command("sudo pip3 install --break-system-packages numpy==1.21"): + if not run_command("sudo pip3 install --break-system-packages numpy==1.21 --only-binary=:all:"): run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple numpy==1.21") run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") From 829fe80bb1d66be1d204ade746a369fc7d329f58 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Fri, 9 Aug 2024 23:15:58 +0200 Subject: [PATCH 06/21] add logs --- setup.py | 80 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/setup.py b/setup.py index 9fa67ce..5b4b715 100755 --- a/setup.py +++ b/setup.py @@ -26,63 +26,71 @@ def run_command(command, retries=3): return True return False -if run_command("sudo apt update"): - run_command("sudo apt -y dist-upgrade") - run_command("sudo apt clean") - run_command("sudo pip3 install --break-system-packages -U pip") - run_command("sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") - run_command("sudo -H pip3 install --break-system-packages --upgrade luma.oled") - run_command("sudo apt-get install -y i2c-tools") - run_command("sudo apt-get install -y python3-smbus") - run_command("sudo pip3 install --break-system-packages icm20948") - run_command("sudo pip3 install --break-system-packages flask") - run_command("sudo pip3 install --break-system-packages flask_cors") - run_command("sudo pip3 install --break-system-packages websockets") - +# Update and upgrade system packages +run_command("sudo apt update") +run_command("sudo apt -y dist-upgrade") +run_command("sudo apt clean") + +# Upgrade pip +run_command("sudo pip3 install -U pip --break-system-packages") + +# Install necessary packages +run_command("sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") +run_command("sudo -H pip3 install --upgrade luma.oled --break-system-packages") +run_command("sudo apt-get install -y i2c-tools") +run_command("sudo apt-get install -y python3-smbus") +run_command("sudo pip3 install icm20948 --break-system-packages") +run_command("sudo pip3 install flask --break-system-packages") +run_command("sudo pip3 install flask_cors --break-system-packages") +run_command("sudo pip3 install websockets --break-system-packages") + +# Configure system settings try: replace_num("/boot/config.txt",'#dtparam=i2c_arm=on','dtparam=i2c_arm=on') except: - print('Failed to update /boot/config.txt for i2c_arm=on') + print('Failed to modify /boot/config.txt for I2C') try: replace_num("/boot/config.txt",'[all]','[all]\ngpu_mem=128') except: - print('Failed to update /boot/config.txt for gpu_mem=128') + print('Failed to modify /boot/config.txt for GPU memory') try: replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1\nstart_x=1') except: - print('Failed to update /boot/config.txt for camera_auto_detect=1') + print('Failed to modify /boot/config.txt for camera settings') -try: - replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1') -except: - print('Failed to update /boot/config.txt for camera_auto_detect=1') +# Install OpenCV with retries +if not run_command("sudo pip3 install opencv-contrib-python==3.4.11.45 --break-system-packages"): + run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45 --break-system-packages") -# Install OpenCV -if not run_command("sudo pip3 install --break-system-packages opencv-contrib-python==3.4.11.45"): - run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45") - -# Install required dependencies for numpy +# Install numpy dependencies run_command("sudo apt-get install -y gfortran libopenblas-dev liblapack-dev") -# Uninstall and reinstall numpy -if run_command("sudo pip3 uninstall -y numpy"): - if not run_command("sudo pip3 install --break-system-packages numpy==1.21 --only-binary=:all:"): - run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple numpy==1.21") +# Uninstall and reinstall numpy with retries +run_command("sudo pip3 uninstall -y numpy --break-system-packages") +if not run_command("sudo pip3 install numpy==1.21 --only-binary=:all: --break-system-packages"): + # Fallback to source installation if binary fails + if not run_command("sudo pip3 install numpy==1.21 --break-system-packages"): + run_command("sudo apt-get install -y python3-numpy") +# Install additional libraries run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") -if not run_command("sudo pip3 install --break-system-packages imutils zmq pybase64 psutil"): - run_command("sudo pip3 install --break-system-packages -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil") +if not run_command("sudo pip3 install imutils zmq pybase64 psutil --break-system-packages"): + run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil --break-system-packages") run_command("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") -run_command("sudo pip3 install --break-system-packages pi-ina219") +run_command("sudo pip3 install pi-ina219 --break-system-packages") -if not os.path.exists(os.path.join(thisPath, '..', 'create_ap')): - if run_command(f"cd {thisPath} && cd .. && sudo git clone https://github.com/oblique/create_ap"): - run_command(f"cd {thisPath} && cd .. && cd create_ap && sudo make install") +# Clone and install create_ap if not already present +if not os.path.exists(os.path.join(thisPath, "../create_ap")): + run_command("cd " + thisPath + " && cd .. && sudo git clone https://github.com/oblique/create_ap") + run_command("cd " + thisPath + " && cd .. && cd create_ap && sudo make install") -replace_num('/etc/rc.local','exit 0',f'cd {thisPath} && sudo python3 webServer.py &\nexit 0') +# Modify rc.local to start the web server on boot +replace_num('/etc/rc.local','exit 0','cd '+thisPath+' && sudo python3 webServer.py &\nexit 0') print('Completed!') + +# Reboot the system os.system("sudo reboot") From 38145f09f7d1d7424b1084ae6d0350890b562481 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Fri, 9 Aug 2024 23:17:51 +0200 Subject: [PATCH 07/21] comment reboot --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5b4b715..a6be561 100755 --- a/setup.py +++ b/setup.py @@ -93,4 +93,4 @@ def run_command(command, retries=3): print('Completed!') # Reboot the system -os.system("sudo reboot") +# os.system("sudo reboot") From 709396131da6c4693b2627e2adad8db4557cd446 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 00:07:26 +0200 Subject: [PATCH 08/21] numpy --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index a6be561..f6afa2e 100755 --- a/setup.py +++ b/setup.py @@ -74,8 +74,8 @@ def run_command(command, retries=3): if not run_command("sudo pip3 install numpy==1.21 --break-system-packages"): run_command("sudo apt-get install -y python3-numpy") -# Install additional libraries -run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev") +# Install additional libraries (excluding libjasper-dev) +run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev") if not run_command("sudo pip3 install imutils zmq pybase64 psutil --break-system-packages"): run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil --break-system-packages") @@ -93,4 +93,4 @@ def run_command(command, retries=3): print('Completed!') # Reboot the system -# os.system("sudo reboot") +os.system("sudo reboot") From 3651e5011ba0eb63fc0105960587128564f148a7 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 10:12:46 +0200 Subject: [PATCH 09/21] fallback options for the numpy --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f6afa2e..0b0b6f3 100755 --- a/setup.py +++ b/setup.py @@ -93,4 +93,4 @@ def run_command(command, retries=3): print('Completed!') # Reboot the system -os.system("sudo reboot") +os.system("sudo reboot") \ No newline at end of file From a1aed25f0d064a6b2ba3c58a0d8e6ed603efe3b8 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 10:35:35 +0200 Subject: [PATCH 10/21] numpy upgrade --- setup.py | 94 +++++++++++++------------------------------------------- 1 file changed, 21 insertions(+), 73 deletions(-) diff --git a/setup.py b/setup.py index 0b0b6f3..691d928 100755 --- a/setup.py +++ b/setup.py @@ -1,23 +1,16 @@ #!/usr/bin/python3 -# File name : setup.py for PIPPY -# Date : 2020/11/24 import os -import time -import re -curpath = os.path.realpath(__file__) -thisPath = os.path.dirname(curpath) - -def replace_num(file,initial,new_num): - newline="" - str_num=str(new_num) - with open(file,"r") as f: +def replace_num(file, initial, new_num): + newline = "" + str_num = str(new_num) + with open(file, "r") as f: for line in f.readlines(): - if(line.find(initial) == 0): - line = (str_num+'\n') + if line.find(initial) == 0: + line = (str_num + '\n') newline += line - with open(file,"w") as f: + with open(file, "w") as f: f.writelines(newline) def run_command(command, retries=3): @@ -26,71 +19,26 @@ def run_command(command, retries=3): return True return False -# Update and upgrade system packages run_command("sudo apt update") run_command("sudo apt -y dist-upgrade") run_command("sudo apt clean") - -# Upgrade pip run_command("sudo pip3 install -U pip --break-system-packages") +run_command("sudo apt-get install -y python3-dev python3-pip build-essential libfreetype6-dev libjpeg-dev gfortran libatlas-base-dev libopenblas-dev liblapack-dev") +run_command("sudo apt-get install -y i2c-tools python3-smbus") +run_command("sudo -H pip3 install --upgrade luma.oled flask flask_cors websockets icm20948 --break-system-packages") -# Install necessary packages -run_command("sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential") -run_command("sudo -H pip3 install --upgrade luma.oled --break-system-packages") -run_command("sudo apt-get install -y i2c-tools") -run_command("sudo apt-get install -y python3-smbus") -run_command("sudo pip3 install icm20948 --break-system-packages") -run_command("sudo pip3 install flask --break-system-packages") -run_command("sudo pip3 install flask_cors --break-system-packages") -run_command("sudo pip3 install websockets --break-system-packages") - -# Configure system settings -try: - replace_num("/boot/config.txt",'#dtparam=i2c_arm=on','dtparam=i2c_arm=on') -except: - print('Failed to modify /boot/config.txt for I2C') - -try: - replace_num("/boot/config.txt",'[all]','[all]\ngpu_mem=128') -except: - print('Failed to modify /boot/config.txt for GPU memory') - -try: - replace_num("/boot/config.txt",'camera_auto_detect=1','#camera_auto_detect=1\nstart_x=1') -except: - print('Failed to modify /boot/config.txt for camera settings') - -# Install OpenCV with retries -if not run_command("sudo pip3 install opencv-contrib-python==3.4.11.45 --break-system-packages"): - run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple opencv-contrib-python==3.4.11.45 --break-system-packages") - -# Install numpy dependencies -run_command("sudo apt-get install -y gfortran libopenblas-dev liblapack-dev") - -# Uninstall and reinstall numpy with retries -run_command("sudo pip3 uninstall -y numpy --break-system-packages") -if not run_command("sudo pip3 install numpy==1.21 --only-binary=:all: --break-system-packages"): - # Fallback to source installation if binary fails - if not run_command("sudo pip3 install numpy==1.21 --break-system-packages"): - run_command("sudo apt-get install -y python3-numpy") - -# Install additional libraries (excluding libjasper-dev) -run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev") -if not run_command("sudo pip3 install imutils zmq pybase64 psutil --break-system-packages"): - run_command("sudo pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple imutils zmq pybase64 psutil --break-system-packages") - -run_command("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") -run_command("sudo pip3 install pi-ina219 --break-system-packages") +# Installing numpy with a version more compatible with Python 3.11 +if not run_command("sudo pip3 install numpy==1.22.4 --only-binary=:all: --break-system-packages"): + run_command("sudo pip3 install numpy==1.21.5 --break-system-packages") -# Clone and install create_ap if not already present -if not os.path.exists(os.path.join(thisPath, "../create_ap")): - run_command("cd " + thisPath + " && cd .. && sudo git clone https://github.com/oblique/create_ap") - run_command("cd " + thisPath + " && cd .. && cd create_ap && sudo make install") +# Further package installations +run_command("sudo pip3 install opencv-contrib-python==3.4.11.45 --break-system-packages") +run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev util-linux procps hostapd iproute2 iw haveged dnsmasq") +run_command("sudo pip3 install pi-ina219 imutils zmq pybase64 psutil --break-system-packages") -# Modify rc.local to start the web server on boot -replace_num('/etc/rc.local','exit 0','cd '+thisPath+' && sudo python3 webServer.py &\nexit 0') +if not os.path.exists(os.path.join(os.path.dirname(__file__), "../create_ap")): + run_command("cd .. && sudo git clone https://github.com/oblique/create_ap && cd create_ap && sudo make install") -print('Completed!') +replace_num('/etc/rc.local', 'exit 0', 'cd ' + os.path.dirname(__file__) + ' && sudo python3 webServer.py &\nexit 0') -# Reboot the system -os.system("sudo reboot") \ No newline at end of file +os.system("sudo reboot") From ca6d338777ae5a2226bc1328364a81c7fb1d759a Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 10:56:47 +0200 Subject: [PATCH 11/21] fix --- setup.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 691d928..92083ed 100755 --- a/setup.py +++ b/setup.py @@ -23,22 +23,25 @@ def run_command(command, retries=3): run_command("sudo apt -y dist-upgrade") run_command("sudo apt clean") run_command("sudo pip3 install -U pip --break-system-packages") -run_command("sudo apt-get install -y python3-dev python3-pip build-essential libfreetype6-dev libjpeg-dev gfortran libatlas-base-dev libopenblas-dev liblapack-dev") -run_command("sudo apt-get install -y i2c-tools python3-smbus") -run_command("sudo -H pip3 install --upgrade luma.oled flask flask_cors websockets icm20948 --break-system-packages") -# Installing numpy with a version more compatible with Python 3.11 -if not run_command("sudo pip3 install numpy==1.22.4 --only-binary=:all: --break-system-packages"): - run_command("sudo pip3 install numpy==1.21.5 --break-system-packages") +# Install dependencies required for building numpy +run_command("sudo apt-get install -y python3-dev python3-pip build-essential gfortran libopenblas-dev liblapack-dev libatlas-base-dev") -# Further package installations +# Install numpy using pre-built binary wheels, avoiding source builds +run_command("sudo pip3 install numpy==1.22.4 --only-binary=:all: --break-system-packages") + +# Install additional dependencies +run_command("sudo apt-get install -y i2c-tools python3-smbus libfreetype6-dev libjpeg-dev") run_command("sudo pip3 install opencv-contrib-python==3.4.11.45 --break-system-packages") -run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev util-linux procps hostapd iproute2 iw haveged dnsmasq") +run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev util-linux procps hostapd iproute2 iw haveged dnsmasq") run_command("sudo pip3 install pi-ina219 imutils zmq pybase64 psutil --break-system-packages") +# Clone and install create_ap if not already installed if not os.path.exists(os.path.join(os.path.dirname(__file__), "../create_ap")): run_command("cd .. && sudo git clone https://github.com/oblique/create_ap && cd create_ap && sudo make install") +# Modify rc.local to start the server at boot replace_num('/etc/rc.local', 'exit 0', 'cd ' + os.path.dirname(__file__) + ' && sudo python3 webServer.py &\nexit 0') +# Reboot the system after installation os.system("sudo reboot") From f2e991aab17a9c59d2da3e60a9e5a5a2edf40a40 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 11:08:21 +0200 Subject: [PATCH 12/21] fix 1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92083ed..53b311a 100755 --- a/setup.py +++ b/setup.py @@ -44,4 +44,4 @@ def run_command(command, retries=3): replace_num('/etc/rc.local', 'exit 0', 'cd ' + os.path.dirname(__file__) + ' && sudo python3 webServer.py &\nexit 0') # Reboot the system after installation -os.system("sudo reboot") +# os.system("sudo reboot") From a557500caf5b3b3fd3f6feb53904fb55902cf409 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 11:23:50 +0200 Subject: [PATCH 13/21] fix for setup --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 53b311a..2c19198 100755 --- a/setup.py +++ b/setup.py @@ -28,11 +28,11 @@ def run_command(command, retries=3): run_command("sudo apt-get install -y python3-dev python3-pip build-essential gfortran libopenblas-dev liblapack-dev libatlas-base-dev") # Install numpy using pre-built binary wheels, avoiding source builds -run_command("sudo pip3 install numpy==1.22.4 --only-binary=:all: --break-system-packages") +# run_command("sudo pip3 install numpy==1.22.4 --only-binary=:all: --break-system-packages") # Install additional dependencies run_command("sudo apt-get install -y i2c-tools python3-smbus libfreetype6-dev libjpeg-dev") -run_command("sudo pip3 install opencv-contrib-python==3.4.11.45 --break-system-packages") +run_command("sudo pip3 install opencv-python --break-system-packages") #opencv-contrib-python==3.4.11.45 run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev util-linux procps hostapd iproute2 iw haveged dnsmasq") run_command("sudo pip3 install pi-ina219 imutils zmq pybase64 psutil --break-system-packages") From 64b36ef12e92b0adf5e14e60229050edfc9ac0e8 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 11:32:19 +0200 Subject: [PATCH 14/21] cv2.imencode error hahdelling --- camera_opencv.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/camera_opencv.py b/camera_opencv.py index 8cf2d58..3c9425d 100755 --- a/camera_opencv.py +++ b/camera_opencv.py @@ -425,24 +425,19 @@ def frames(): cvt.start() while True: - # read current frame - _, img = camera.read() + success, img = cvt.read() # Capture frame-by-frame + if not success or img is None: + # If the frame was not captured successfully, skip encoding + print("Failed to capture image") + continue - if Camera.modeSelect == 'none': - cvt.pause() - else: - if cvt.CVThreading: - pass - else: - cvt.mode(Camera.modeSelect, img) - cvt.resume() - try: - img = cvt.elementDraw(img) - except: - pass - - # encode as a jpeg image and return it - yield cv2.imencode('.jpg', img)[1].tobytes() + # Proceed with encoding only if the image is valid + try: + encoded_img = cv2.imencode('.jpg', img)[1].tobytes() + yield encoded_img + except cv2.error as e: + print(f"Error encoding image: {e}") + continue class Functions(threading.Thread): From 0fadbe8d1a56d6fcb913efc00f3dd412f072d1ef Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 11:35:41 +0200 Subject: [PATCH 15/21] camera --- camera_opencv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera_opencv.py b/camera_opencv.py index 3c9425d..4f3d706 100755 --- a/camera_opencv.py +++ b/camera_opencv.py @@ -425,7 +425,7 @@ def frames(): cvt.start() while True: - success, img = cvt.read() # Capture frame-by-frame + success, img = camera.read() # Capture frame-by-frame if not success or img is None: # If the frame was not captured successfully, skip encoding print("Failed to capture image") From 8995e2b73a271b4f0e5b40ab0121dd397b80168d Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 11:39:10 +0200 Subject: [PATCH 16/21] timeout --- camera_opencv.py | 1 + 1 file changed, 1 insertion(+) diff --git a/camera_opencv.py b/camera_opencv.py index 4f3d706..356578b 100755 --- a/camera_opencv.py +++ b/camera_opencv.py @@ -429,6 +429,7 @@ def frames(): if not success or img is None: # If the frame was not captured successfully, skip encoding print("Failed to capture image") + time.sleep(0.1) # Add a short delay before trying again continue # Proceed with encoding only if the image is valid From c6418e1eaf3ab783b05fe17d012ba74b2d4d7007 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 11:43:18 +0200 Subject: [PATCH 17/21] frames update --- camera_opencv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera_opencv.py b/camera_opencv.py index 356578b..0cd7c48 100755 --- a/camera_opencv.py +++ b/camera_opencv.py @@ -428,7 +428,7 @@ def frames(): success, img = camera.read() # Capture frame-by-frame if not success or img is None: # If the frame was not captured successfully, skip encoding - print("Failed to capture image") + print("Failed to capture image. Retrying...") time.sleep(0.1) # Add a short delay before trying again continue From 0a01c86b0e3df11c83d50f8f734fe423c03bd548 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 14:26:51 +0200 Subject: [PATCH 18/21] setup --- setup.py | 92 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 2c19198..4bba386 100755 --- a/setup.py +++ b/setup.py @@ -1,47 +1,89 @@ #!/usr/bin/python3 +# File name : setup.py for PIPPY +# Date : 2020/11/24 import os def replace_num(file, initial, new_num): + """Replace a specific line in a file with a new line.""" newline = "" - str_num = str(new_num) with open(file, "r") as f: for line in f.readlines(): - if line.find(initial) == 0: - line = (str_num + '\n') + if line.startswith(initial): + line = f"{new_num}\n" newline += line with open(file, "w") as f: - f.writelines(newline) + f.write(newline) -def run_command(command, retries=3): - for _ in range(retries): +def run_command(command, max_retries=3): + """Run a shell command with retry mechanism.""" + for _ in range(max_retries): if os.system(command) == 0: return True return False -run_command("sudo apt update") -run_command("sudo apt -y dist-upgrade") -run_command("sudo apt clean") -run_command("sudo pip3 install -U pip --break-system-packages") +# Paths +curpath = os.path.realpath(__file__) +thisPath = os.path.dirname(curpath) -# Install dependencies required for building numpy -run_command("sudo apt-get install -y python3-dev python3-pip build-essential gfortran libopenblas-dev liblapack-dev libatlas-base-dev") +# Update system and install packages +commands = [ + "sudo apt update", + "sudo apt -y dist-upgrade", + "sudo apt clean", + "sudo pip3 install -U pip", + "sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential", + "sudo -H pip3 install --break-system-packages --upgrade luma.oled", + "sudo apt-get install -y i2c-tools", + "sudo apt-get install -y python3-smbus", + "sudo pip3 install --break-system-packages icm20948", + "sudo pip3 install --break-system-packages flask", + "sudo pip3 install --break-system-packages flask_cors", + "sudo pip3 install --break-system-packages websockets", +] -# Install numpy using pre-built binary wheels, avoiding source builds -# run_command("sudo pip3 install numpy==1.22.4 --only-binary=:all: --break-system-packages") +for cmd in commands: + run_command(cmd) -# Install additional dependencies -run_command("sudo apt-get install -y i2c-tools python3-smbus libfreetype6-dev libjpeg-dev") -run_command("sudo pip3 install opencv-python --break-system-packages") #opencv-contrib-python==3.4.11.45 -run_command("sudo apt-get -y install libhdf5-dev libhdf5-serial-dev util-linux procps hostapd iproute2 iw haveged dnsmasq") -run_command("sudo pip3 install pi-ina219 imutils zmq pybase64 psutil --break-system-packages") +# Modify /boot/config.txt +config_modifications = [ + ('/boot/config.txt', '#dtparam=i2c_arm=on', 'dtparam=i2c_arm=on'), + ('/boot/config.txt', '[all]', '[all]\ngpu_mem=128'), + ('/boot/config.txt', 'camera_auto_detect=1', '#camera_auto_detect=1\nstart_x=1'), + ('/boot/config.txt', 'camera_auto_detect=1', '#camera_auto_detect=1') +] -# Clone and install create_ap if not already installed -if not os.path.exists(os.path.join(os.path.dirname(__file__), "../create_ap")): - run_command("cd .. && sudo git clone https://github.com/oblique/create_ap && cd create_ap && sudo make install") +for file, initial, new_num in config_modifications: + try: + replace_num(file, initial, new_num) + except Exception as e: + print(f"Error modifying {file}: {e}") -# Modify rc.local to start the server at boot -replace_num('/etc/rc.local', 'exit 0', 'cd ' + os.path.dirname(__file__) + ' && sudo python3 webServer.py &\nexit 0') +# Install specific packages +package_commands = [ + "sudo pip3 install --break-system-packages opencv-contrib-python==3.4.11.45", + "sudo pip3 uninstall -y numpy", + "sudo pip3 install --break-system-packages numpy==1.21", + "sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev", + "sudo pip3 install --break-system-packages imutils zmq pybase64 psutil", + "sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq", + "sudo pip3 install --break-system-packages pi-ina219" +] -# Reboot the system after installation +for cmd in package_commands: + run_command(cmd) + +# Clone and install create_ap +if run_command(f"cd {thisPath} && cd .. && sudo git clone https://github.com/oblique/create_ap"): + try: + os.system(f"cd {thisPath} && cd .. && cd create_ap && sudo make install") + except Exception as e: + print(f"Error installing create_ap: {e}") + +# Update rc.local +# replace_num('/etc/rc.local', 'exit 0', f'cd {thisPath} && sudo python3 webServer.py &\nexit 0') + +print('Completed!') + +# Reboot system # os.system("sudo reboot") From 1909cf4ae094e80080af509facf0a5f21c714b30 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 14:29:26 +0200 Subject: [PATCH 19/21] --break-system-packages --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4bba386..4d357a4 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def run_command(command, max_retries=3): "sudo apt update", "sudo apt -y dist-upgrade", "sudo apt clean", - "sudo pip3 install -U pip", + "sudo pip3 install --break-system-packages -U pip", "sudo apt-get install -y python-dev python3-pip libfreetype6-dev libjpeg-dev build-essential", "sudo -H pip3 install --break-system-packages --upgrade luma.oled", "sudo apt-get install -y i2c-tools", @@ -62,7 +62,7 @@ def run_command(command, max_retries=3): # Install specific packages package_commands = [ "sudo pip3 install --break-system-packages opencv-contrib-python==3.4.11.45", - "sudo pip3 uninstall -y numpy", + "sudo pip3 uninstall --break-system-packages -y numpy", "sudo pip3 install --break-system-packages numpy==1.21", "sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev", "sudo pip3 install --break-system-packages imutils zmq pybase64 psutil", From f8f36b9c7e639ba98fbd7beadd12f5326a4200d6 Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Sat, 10 Aug 2024 14:32:35 +0200 Subject: [PATCH 20/21] 4.5.3.56 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4d357a4..8235d8b 100755 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ def run_command(command, max_retries=3): # Install specific packages package_commands = [ - "sudo pip3 install --break-system-packages opencv-contrib-python==3.4.11.45", + "sudo pip3 install --break-system-packages opencv-contrib-python==4.5.3.56", "sudo pip3 uninstall --break-system-packages -y numpy", "sudo pip3 install --break-system-packages numpy==1.21", "sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev", From 7788d7d430da3aa609e8d864291ab383f9e6b9ae Mon Sep 17 00:00:00 2001 From: Sergei Sergienko Date: Mon, 10 Feb 2025 09:44:10 +0100 Subject: [PATCH 21/21] test comment --- test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..e69de29