chiefwigms / picobrew_pico

MIT License
148 stars 63 forks source link

502 Bad Gateway #163

Closed Rudder2 closed 3 years ago

Rudder2 commented 3 years ago

Everything was working fine I brewed yesterday and cleaned my Pico Z today until I decided to add my PicoFerms to my PI Server. Now all I get it a 502 Bad Gateway when ever I try to access the server. My Z gets a 502 of it's screen also when it tries to boot. I've been searching the form to figure out how to access the server logs and can't find any documentation on how to do that. The problem started when I added my PicoFerms to my config.yaml because I couldn't get them to connect to my PI Server and editing the config.yaml worked for getting my Pico Z and S connected. I reverted the config.yaml back to what it was before the edit with no dice. I've tried everything. Please help.

Rudder2 commented 3 years ago

Finally found the nginx error log. I get this over and over.

2020/12/17 01:35:29 [error] 316#316: 11 connect() failed (111: Connection refused) while connecting to upstream, client: LOCALIPADDRESS, server: www.picobrew.com, request: "GET / HTTP/1.1", upstream: "http://1$ 2020/12/17 01:35:29 [error] 316#316: 11 connect() failed (111: Connection refused) while connecting to upstream, client: IPADDRESS, server: www.picobrew.com, request: "GET / HTTP/1.1", upstream: "http://1$ 2020/12/17 01:35:30 [error] 316#316: *11 no live upstreams while connecting to upstream, client: IPADDRESS, server: www.picobrew.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://localhost/favic$

tmack8001 commented 3 years ago

@Rudder2 can you provide an example either here or PMed to me on FB of your config.yml (the product IDs don't leak any data from your PB account, but could in theory be used to get machine instructions for your "recipes" BTW).

I'm guessing the server is failing to start due to a startup error in processing that file.

Looks like you also get this same 502 when browsing to the index page http://raspberrypi?

Rudder2 commented 3 years ago

@tmack8001 I can't find you to PM on Facebook. I edited the file from my the PI using SSH and Nano the first time. The second I edited it from SMB from my Ubuntu computer. I'm thinking the permissions got messed up. It's owned by root. I have 2 versions of the config.yaml. The one that worked before I edited and the one after the edit. Neither one works. I tried copying the config.example.yaml yo config.yaml and it didn't boot either.

tmack8001 commented 3 years ago

The config.yaml file should have the following permissions:

-rw-r--r-- 1 pi pi <size> Jul 30 15:17 config.yaml

Likely yea the permissions from the SMB messed things up, I haven't actually used the Samba share to modify files so not sure if that was how you mounted the share or how the share is setup. Looking around at the samba configuration (at least in beta5, the most recent release) the share is setup with guest account = root. What might be happening is if you or your OS (ubuntu and windows do this I believe) send credentials that don't match the raspberrypi's userbase the root user is then associated with all actions your Bad User is making and thus changes ownership of files over to the root user?

Try changing the permissions back over to the pi user and pi group sudo chown pi:pi /picobrew_pico/config.yaml and see what happens when you force the server startup process to restart sudo systemctl restart rc.local.

Rudder2 commented 3 years ago

I chown the file and still didn't start. I notice every file on the pi server says root:root is the owner. When I edited it from my windows laptop I didn't have a problem but I left the power cord when I was on Thanksgiving vacation so had to do it from my Ubuntu computer. Is there more logs I can look at to narrow this down?

Rudder2 commented 3 years ago

My /PicoBrew_Pico permissions: drwxr-xr-x 9 root root 4096 Dec 17 01:11 app -rw-r--r-- 1 root root 2903 Nov 14 22:37 config.example.yaml -rw-r--r-- 1 root root 142 Dec 17 01:02 config.removed.yaml -rw-r--r-- 1 pi pi 3030 Dec 17 01:02 config.yaml -rw-r--r-- 1 root root 2894 Dec 17 01:02 config.yaml.bk -rw-r--r-- 1 root root 830 Nov 14 22:37 docker-compose.yml -rw-r--r-- 1 root root 510 Nov 14 22:37 Dockerfile -rw-r--r-- 1 root root 1061 Nov 14 22:37 LICENSE -rw-r--r-- 1 root root 41 Nov 14 22:37 Procfile -rw-r--r-- 1 root root 7372 Nov 14 22:37 README.md -rw-r--r-- 1 root root 110 Nov 14 22:39 requirements.txt drwxr-xr-x 4 root root 4096 Nov 14 22:37 scripts -rw-r--r-- 1 root root 465 Nov 14 22:37 server.py drwxr-xr-x 2 root root 4096 Nov 14 22:37 terraform -rw-r--r-- 1 root root 297 Nov 14 22:37 test_server.py

tmack8001 commented 3 years ago

Ah my bad @Rudder2 I sshed into my dev pi and not a image based one... I got 4 or 5 floating around these days all broadcasting and doing random crap.

If the files in /picobrew_pico are all root:root then ignore my mentions above to the contrary 🤣 . That is the way it should be.

tmack8001 commented 3 years ago

What do you see as logs from sudo systemctl status rc.local?

tmack8001 commented 3 years ago

Something is preventing the server from starting up successfully, my hunch is a malformed yaml file... yaml as a format is very picky about formatting / whitespace. That log should contain some exception that threw the server startup for a loop that it didn't recover from.

Rudder2 commented 3 years ago

Dec 17 11:34:30 raspberrypi rc.local[271]: ferm_session = load_ferm_session(file) Dec 17 11:34:30 raspberrypi rc.local[271]: File "/picobrew_pico/app/main/session_parser.py", line 134, in load_ferm_session Dec 17 11:34:30 raspberrypi rc.local[271]: json_data = json.loads(raw_data) Dec 17 11:34:30 raspberrypi rc.local[271]: File "/usr/lib/python3.7/json/init.py", line 348, in loads Dec 17 11:34:30 raspberrypi rc.local[271]: return _default_decoder.decode(s) Dec 17 11:34:30 raspberrypi rc.local[271]: File "/usr/lib/python3.7/json/decoder.py", line 337, in decode Dec 17 11:34:30 raspberrypi rc.local[271]: obj, end = self.raw_decode(s, idx=_w(s, 0).end()) Dec 17 11:34:30 raspberrypi rc.local[271]: File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode Dec 17 11:34:30 raspberrypi rc.local[271]: raise JSONDecodeError("Expecting value", s, err.value) from None Dec 17 11:34:30 raspberrypi rc.local[271]: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Rudder2 commented 3 years ago

I did notice when I connected my PicoFerm to the PI Server it created an empty json session file.

pi@raspberrypi:/picobrew_pico/app/sessions/ferm/active $ ls -l total 0 -rw-r--r-- 1 root root 0 Dec 17 01:06 20201216_230929#600194568fe6.json

chiefwigms commented 3 years ago

that looks like it's a malformed session, not config.yaml

Rudder2 commented 3 years ago

I will try to delete that 0 byte json and see what happens.

Rudder2 commented 3 years ago

@chiefwigms You hit the nail on the head...It was a malformed session. I deleted the 0 byte json file in the /picobrew_pico/app/sessions/ferm/active directory and the server came back up. So it was connecting my PicoFerm that was the problem not editing the config.yaml. Thank y'all for your help!

Rudder2 commented 3 years ago

I'm thinking of making some iSpindels. Do you think they are better that the PicoFerms?

tmack8001 commented 3 years ago

Wondering why that session file was created, but never written to. @Rudder2 did you have say a power disruption or similar that would have made the raspberrypi restart while the PicoFerm was communicating to it?

Rudder2 commented 3 years ago

@tmack8001 My WiFi on my Raspberry PI get's interrupted when more than one device connects to it. I had to connect my computer to my IOT network to monitor the PI with out interupting the communication with the ferm. I still notice that the ferm is still not showing up in sessions on the server even after adding all 3 ferms to the config.yaml.

tmack8001 commented 3 years ago

Which pi model do you have? Did you flash beta5 as a starting point (includes some wifi updates for stability)?

Rudder2 commented 3 years ago

@tmack8001 Pie Zero W...Wonder if a Pie 4 would of worked better. No, I have been updating from in the server starting with the Bata 4 image I first flashed when I started this project. I did update to Bata 5 and copy all my Data back when I was troubleshooting before I started this thread. Was going to ask if the in PI update actually updates the Pie side of the house or only server side.

tmack8001 commented 3 years ago

The images update the pi side whereas the restart script and exposed "update server" options in the UI just update the "server" side (python code).

tmack8001 commented 3 years ago

Regardless we should update the server start up code to log an error and continue if the active sessions are mucked up in anyway. Similar to what I've added for archived sessions. Maybe a UI component to display warnings to delete these mucked up files as well.

Rudder2 commented 3 years ago

@tmack8001 I agree with that. Just don't want to ask so much from y'all. I saw all the work you did over Thanksgiving and was really impressed. I'm not a programmer, just a hardware / OS person so programmers impress me. Y'all need a buy a beer button.

How long does it take to log a session after the ferm is turned on? I still don't see anything on the ferm sessions even after I added the ferms to the config.yaml. I just put the batteries back in to the ferm and connected it to my keg of beer I pinched lastnight.

Is the the error sessions at the top of the Brew Sessions page the malformed jsons that can be deleted that you mentioned? Brew Session History Screen Shot

tmack8001 commented 3 years ago

These sessions for some reason (still tracking down details for the Z) are caused somehow. Yeah they can be deleted or left there up to you 😜. They used to cause the page to fail rendering as does the corrupted/no expected ferm session at server startup.

Rudder2 commented 3 years ago

@tmack8001 The PicoFerm is working!!!!!

2020-12-17 PicoFerm is working!

tmack8001 commented 3 years ago

Takes several hours for the data points to start flowing it seems. Not sure what it's "hibernation" mode is as haven't jumped into the firmware yet... Doubt I will I don't really use mine and decompiling is a time consuming process.

Rudder2 commented 3 years ago

@tmack8001 What's your opinion on the iSpindel? I like fermentation monitoring. Would really like SG monitoring.

tmack8001 commented 3 years ago

iSpindel and Tilt are better fermentation monitoring systems than say Plaato (based on volumes of CO2) or PicoFerm (loosely based on time and pressure... Glorified 14d timer).

Really don't need any of this just let sit for 14d and you are good, but constant monitoring is nice for a data nerd like myself.

Rudder2 commented 3 years ago

Personally I like data my self. I bought a digital refracto %brix meter to get a good estimate of ABV and to tell if fermentation stalled but for the most part the 14 day method has been fine for me as well.

Just really like opening the browser and knowing exactly is going on. Will probably use both PicoFerm and iSpindel so I can get both pressure and SG. I don't open my keg after pinching for 14 days...More if I pull the pressure release and in an hour it hisses alot again. Most I've had to wait has been 17 days.

My local brew supplier, who are professional brewers also, had a heart attack when told them didn't have a system to measure the wart SG. They were like how do you know it's close to target...I said drink 1/2 a of the first glass in 5 mins and see how it feels...LOL

Thank you for your help and information. I'm staying 100% offline based on the state of Pico...

tmack8001 commented 3 years ago

@Rudder2 to make me feel a little better... this invalid session file thing has been "fixed" before, just only for brew sessions (guess they are more frequently used by the maintainers 😜 than ferm or iSpindle sessions)... I've attempted to fix that in refactoring code for reuse in https://github.com/chiefwigms/picobrew_pico/pull/164/files

Rudder2 commented 3 years ago

@tmack8001 Awesome! Thank you for the fix. I'm glad I could contribute in the making the offline server better.

I'm glad to report that Bata5 fix my WiFi stability problems with the PiZeroW! It no longer losses internet everyday and just seams more stable. I will continue to do more testing and report back. My PiZeroW is 40 feet from my router with line of sight, no walls in the way, and it seams to like that distance.

I've unboxed my PicoStill and plan on trying to get it going in the coming weeks. Any advice?

BuckoWA commented 3 years ago

Been planning to fix for iSpindel too in the near future. Life..,

On Dec 18, 2020, at 8:52 AM, Rudder2 notifications@github.com wrote:



@tmack8001https://github.com/tmack8001 Awesome! Thank you for the fix. I'm glad I could contribute in the making the offline server better.

I'm glad to report that Bata5 fix my WiFi stability problems with the PiZeroW! It no longer losses internet everyday and just seams more stable. I will continue to do more testing and report back. My PiZeroW is 40 feet from my router with line of sight, no walls in the way, and it seams to like that distance.

I've unboxed my PicoStill and plan on trying to get it going in the coming weeks. Any advice?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/chiefwigms/picobrew_pico/issues/163#issuecomment-748201357, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AP337JBWX76SV4R3S2IDFGLSVOCFHANCNFSM4U7DIUYQ.

tmack8001 commented 3 years ago

@BuckoWA my change did fix the invalid session file upon startup for the iSpindel as well just refactored for common code reuse forball 3 types of sessions together.

BuckoWA commented 3 years ago

Great! Hadn’t pulled the latest one down yet and have been working on some feature additions for naming spindel and Ferm sessions with brew names. Appreciate the heads up!

On Dec 18, 2020, at 11:51 AM, Trevor Mack notifications@github.com wrote:



@BuckoWAhttps://github.com/BuckoWA my change did fix the invalid session file upon startup for the iSpindel as well just refactored for common code reuse forball 3 types of sessions together.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/chiefwigms/picobrew_pico/issues/163#issuecomment-748288602, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AP337JENBXHE5CEFH4TNEM3SVOXEJANCNFSM4U7DIUYQ.