Bad gateway and no browser stream incoming after upgrading

S.L.P. image questions, stereoscopic video livestream and recording, stereoscopic photo capture etc.
Post Reply
fmassa80
Posts: 2
Joined: Wed Mar 10, 2021 11:53 am
Location: Genoa, Italy

Bad gateway and no browser stream incoming after upgrading

Post by fmassa80 »

Dear all

I upgraded via sudo apt-get update && sudo apt-get upgrade the stereopi (v0.23) img but I have some issues. Probably I shouldn't have done this... :(

After the upgrading process I had some issues with the package php7.0-fpm: via browser stereopi.local aswered Bad gateway. So I solved with sudo apt-get purge php7.0-fpm && sudo apt-get install php7.0-fpm.
Now stereopi.local page work fine again: I can see the StereoPi logo and click the different bottons but no stream video incoming as if browser stream option had disabled (instead it is enable); connectng the StereoPi via HDMI both camera images are freezed to the first image arrived to the system.

I post below some Debug test made I don't know if there are correlation between the php7.0-fpm issue and this:

via browse (web developer console F12)

WebSocket connection to 'ws://stereopi.local:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED



via console

/usr/bin/nodejs ./wsstream/index.js 1280 720 30


module.js:549
throw err;
^

Error: Cannot find module '/wsstream/index.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3


So does anyone have any idea or suggestions about it?

Thanks in advance

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

hi!
i`d the same problem after update to php 7.3.

I coudn`t start up cameras, but i started up the server. I work on Raspbian Stretch.
Here are my steps:
1.

Code: Select all

sudo mount -o remount,rw /
2.Then i followed the tutorial- https://onedev.net/post/942

Code: Select all

sudo nano /etc/apt/sources.list.d/10-buster.list
deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
sudo apt update
sudo apt install -y -t buster php7.3 php-apcu php7.3-curl php7.3-gd php7.3-fpm php7.3-cli php7.3-opcache php7.3-mbstring php7.3-xml php7.3-zip php7.3-intl php7.3-mysql php7.3-sqlite3 php7.3-xmlrpc
sudo  systemctl stop apache2
sudo apt-get remove -y apache2
sudo apt install -t buster nginx-full
sudo systemctl start nginx.service
3.Then we need to set up server configs. I followed this way with some changes - https://sprut.ai/client/article/1064

Code: Select all

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 777 /var/www/html

Code: Select all

sudo nano /etc/nginx/sites-available/default
Dont change
root /var/www/html;
Only need to change to:

Code: Select all

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        }        
Save changes.
4.Restart ngnix:

Code: Select all

sudo systemctl reload nginx
and check it working:

Code: Select all

sudo systemctl check nginx
5.Give rights to www-data:

Code: Select all

sudo chown -R www-data:www-data /var/www/html
sudo chown -R www-data:www-data /media/DCIM
sudo chown -R www-data:www-data /opt/StereoPi
sudo chmod 777 /dev/vchiq
sudo chmod 777 /media/DCIM
usermod -a -G video www-data
After steps completed error "Bad gateway" will pass, but still no video from cameras and hold on with photo making.
Perhaps, .php scripts should be corrected or something else should be done cause of

Code: Select all

raspistill -v -o test.jpg
doesnt work either.

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Bad gateway and no browser stream incoming after upgrading

Post by Realizator »

Hi guys,
As I mentioned a few times, SLP update is not a good idea. We are having a lot of stuff onboard, and did a lot of configuration to fit each part with the other. The update usually breaks all dependencies (and overwrite settings).
But I see you are well ahead, so let me try to help you with other setting.

Zoldaten, could you please test, if your system sees any cameras?
1. What is the output of this command:

Code: Select all

vcgencmd get_camera
2. I see you're not set the camera to use in your raspistill command. Please add -cs 0 or cs-1, like this:

raspistill -cs 0 -o test.jpg

3. Are you sure your fs is not read-only? The mentioned command try to record a file 'test.jpg'. to the Linux partition

Let's figure out this part first, and then go to PHP and the admin panel.
Eugene a.k.a. Realizator

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

1.

Code: Select all

vcgencmd get_camera
gives nothing with two cameras connected:
2021-03-13_00h29_42.jpg
2021-03-13_00h29_42.jpg (20.37 KiB) Viewed 14205 times
And freezes SSH-session.
2.

Code: Select all

raspistill -cs 0 -o test.jpg
gives the same result.
*Ofcause, i remember of rw protection on partition.

But!
If i disconnect one of cameras and reboot. Everything works - i mean commands above gives something like supported=2 detected=1 and raspistill
makes photo when call it.

So. I suppose the problem is in the scripts started on boot that linked somehow with cameras.
I tried also with no result:
1.
- put more GPU memory on boot - sudo nano boot/config.txt:
GPU_MEM_512=448
- put less GPU memory on boot - sudo nano boot/config.txt:
GPU_MEM=128
2.
manually stop scripts in /opt/Stereopi:
./stop.sh
But camera led was still light.
3.
change camera(cameras) and cable(cables).

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Bad gateway and no browser stream incoming after upgrading

Post by Realizator »

Wow. I never faced the stuck of 'vcgencmd get_camera'.
More than a year ago, there was a bug in Raspbian. They updated AWB algo, and this broken stereoscopic support (our post about this, and the GitHub discussion with the Raspberry engineer). Right now, this bug is fixed in the latest kernels, but on your screenshot, I see 4.19.66 - it is the affected version.
Please try to run "sudo vcdbg set awb_mode 0" BEFORE accessing the camera. For SLP, it is better to add this row to autostart (or to our run.sh).
Eugene a.k.a. Realizator

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

Ok. Got it worked! (but web-interface buttons still dont(( )

Firstly, i think just to

Code: Select all

rpi-update
, but remembered my wi-fi dongle was build in current configuration.
So. I put

Code: Select all

sudo vcdbg set awb_mode 0
to /opt/Stereopi/run.sh as 2d string.
After that

Code: Select all

raspistill -3d sbs -o 1.jpg
become possible.
But still werent no video streams.

So i found out if use /opt/Stereopi/stop.sh - makung photo on browser is possible also u can move on directory to see them. But it comes
imposible again if manually start again run.sh.
Secondly, searching around i learned that if just correct manually /boot/sterepi.conf (not /opt/Stereopi/config.conf) everything works like
a charm! (exept making photo on page).
At last i just correct /boot/sterepi.conf (previosly remounted boot -

Code: Select all

sudo mount -o remount,rw /boot
):

Code: Select all

udp_clients=192.168.1.108:3000 #my pc address i stream udp to 
udp_enabled=1
ws_enabled=1 #to start up browser video
So. The last steps are - find out how to start working buttons of photo and change options as that still not working. I think the reason of rights.
Could you share what rights dirs have, mine:
2021-03-13_19h41_35.jpg
2021-03-13_19h41_35.jpg (161.28 KiB) Viewed 14193 times

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Bad gateway and no browser stream incoming after upgrading

Post by Realizator »

Hey Zoldaten,
A few comments on your investigations:

1. When our scripts are running (run.sh), they are using raspivid. So when you try to run "raspistill", it shows you an error. For the manual console run of "raspistill" or "raspivid" please stop our scripts first by stop.sh. Note: if you try to kill the raspivid process, but not run "stop.sh", our scripts will run it again. We have a self-check logic to run this again if something goes wrong.

2. /opt/Stereopi/config.conf is a local, system-used configuration. While booting, our system copies /boot/sterepi.conf to /opt/Stereopi/config.conf and work with it. So if you change anything in /opt/Stereopi/config.conf, your changes will be overwritten by the next boot. So please use /boot/sterepi.conf to change settings

3. As for the shot and record buttons in the admin panel after the update - could you please try to catch JS errors in your browser console after clicking those buttons? This will help a lot.
Eugene a.k.a. Realizator

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

Realizator wrote:
Mon Mar 15, 2021 9:40 am
Hey Zoldaten,
A few comments on your investigations:

1. When our scripts are running (run.sh), they are using raspivid. So when you try to run "raspistill", it shows you an error. For the manual console run of "raspistill" or "raspivid" please stop our scripts first by stop.sh. Note: if you try to kill the raspivid process, but not run "stop.sh", our scripts will run it again. We have a self-check logic to run this again if something goes wrong.
So, as i understand, it`s impossible to make a photo (from the web page) while scripts are running? So each time to make a photo i should go SSH to stop them.
Realizator wrote:
Mon Mar 15, 2021 9:40 am
3. As for the shot and record buttons in the admin panel after the update - could you please try to catch JS errors in your browser console after clicking those buttons? This will help a lot.
Nothing special there.
Admin panel looks well, i see cameras restart after push button "save", but it doesnt change options:
2021-03-15_22h14_09.jpg
2021-03-15_22h14_09.jpg (39.42 KiB) Viewed 14144 times
Cant catch why client try to get 8080 port after saveconfig.php...

fmassa80
Posts: 2
Joined: Wed Mar 10, 2021 11:53 am
Location: Genoa, Italy

Re: Bad gateway and no browser stream incoming after upgrading

Post by fmassa80 »

EUREKA!!!


Now all things seem to work fine again... I try to summarize a solution (it's work for me and it's my best work but surely I accept other tips to improve it!)

The last issue is that the initial start logo didn't start... I donn't know why...

This is my rc.local file: I added four rows to restart the php7.0-fpm service to prevent Bad Gateway issue. Maybe could I add them otherwhere to make this solution a bit more elegant?

----- rc.local -----
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

##### FM ADDED #####

sudo mount -o rw,remount /
sudo mount -o rw,remount /boot

#Bad Gateway PREVENTING
systemctl daemon-reload
systemctl restart php7.0-fpm

##### ######## ######

# clear HDMI console
setterm -clear all -foreground black -background black > /dev/tty0
setterm -clear all -foreground black -background black > /dev/tty3


# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi


echo "\n\n"
printf "\033[1;34mRaspberry Pi serial number\n"
printf "\033[1;37m"
cat /proc/cpuinfo | tail -n 1
printf "\033[0m\n"
echo "\n\n"



cd /opt/StereoPi
./run.sh > /dev/null 2>&1 &

exit 0


---------------

I added in run.sh the row below at the top of the script (as it suggested by you)
----- run.sh -----

sudo vcdbg set awb_mode 0 # added by FM





My2Cents

Francesco

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Bad gateway and no browser stream incoming after upgrading

Post by Realizator »

Francesco, thank you for sharing your solution! :-)

Zoldaten, our "shot" button has a special logic controlled by our scripts. No need to manually stop/start them. When you take a photo, scripts automatically stops raspivid, takes a photo, and run all live streams again.
Here is the way we are taking the photo:
/var/www/html/make_photo.php
Eugene a.k.a. Realizator

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

##### FM ADDED #####
sudo mount -o rw,remount /
sudo mount -o rw,remount /boot

#Bad Gateway PREVENTING
systemctl daemon-reload
systemctl restart php7.0-fpm
do not know how those could fix everything as it just restart php7.0-fpm...nevermind.
Not for me as i updated to php7.3-fm and adding that do not help me.

Ok. After all i found the last solution which doesnt let to take photo and change settings in web-admin panel.
1. For making photo as was mentioned above responsible make_photo.php. So to start it working again i`ve change 1 string in it adding sudo:

Code: Select all

sudo killall -q raspivid
As i investigate it just coundnt kill raspivid to start raspistill...
2.The second thing that didnt work - i cannot make changes from web-page as all settings keep the same.
A start, i thought js is responsible for crash but later land to php.
To sum up 2 scripts should be changed:
in getconfig.php:
from

Code: Select all

 
$content = file('/boot/stereopi.conf');
to

Code: Select all

$content = file('/opt/StereoPi/config.conf');
in saveconfig.php
from

Code: Select all

$CONFIG_FILE = '/boot/stereopi.conf';
to

Code: Select all

$CONFIG_FILE = '/opt/StereoPi/config.conf';
and from

Code: Select all

system("sudo mount -o rw,remount /boot");
to:

Code: Select all

system("sudo mount -o rw,remount /");
And the last step here - change rights to config.conf:

Code: Select all

sudo chmod 777 config.conf
(or 755 if u scared)

That`s it.

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

But after reboot /opt/Stereopi/config.conf again with 644 rights (
How to fix that to 777 to make it automatic ?

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Bad gateway and no browser stream incoming after upgrading

Post by stereomaton »

You are working against the way SLP works (which is not a reproach, you do what you want with your board) so you have to find which mechanism you did not brake that is doing that. The mode is classically changed by a chmod or a copy, or sometimes if a file is removed and rewritten. I let you investigate.

By the way, using 777 mode is usually a good alert signal that something is done wrong.
For example here, one could wonder why you need execution rights on a configuration file.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

Re: Bad gateway and no browser stream incoming after upgrading

Post by zoldaten »

My SLP updated image works well exept config.conf which needs 755 or 777 rights.
I`m trying to find how to change rights on boot or what change it back to 644. All other files in the same dir have 755.

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Bad gateway and no browser stream incoming after upgrading

Post by stereomaton »

You can probably use the command chmod to override the rights, but it is probably better to understand how the rights are set in the first place.

But again, the difference between 755 and 644 are execution rights, and then it is strange that you need them on a configuration (thus not executable) file.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

Post Reply