Fresh Install of Pi Gateway - nginx problem

Started by Stereodude, June 20, 2024, 11:38:22 PM

Stereodude

I dusted off my MightyHat r3 and RPi3b and wanted to get Pi Gateway and the MightyHat r3 working again. I did a clean install of the latest Raspberry Pi OS Lite 2024-03-15-raspios-bookworm-armhf-lite.img (not sure if I should have used ARM64).  I ran the install script and it seemed to complete successfully. After rebooting it told me that NGINX failed to start

[FAILED] Failed to start nginx.service ...

I used the suggested command to see what the issue is using systemctl status nginx.service. These are the two relevant lines.

nginx[1210]: 2024/06/20 23:46:01 [warn] 1210#1210: low address bits of 192.168.1.1/24 are meaningless in /etc/nginx/sites-enabled/gateway:18
nginx[1210]: 2024/06/20 23:46:01 [emerg] 1210#1210: unknown directive "pm.status_listen" in /etc/nginx/sites-enabled/gateway:70

Edit: The forum keeps auto editing my post and removing large parts of my post... Continued below

Stereodude

#1
I resolved that issue by editing the gateway config and commenting out this line
pm.status_listen = 127.0.0.1:9001;

I'm not sure if that was the correct thing to do, but it allowed nginx to start.

Then it was hanging at Waiting for Connection as the attachment in the first post shows when I tried to load the webpage from another PC.  However, I now see from another thread that I need to use the default username of Pi which I didn't, which is probably why it wasn't loading. I will have to try a clean install tomorrow also using the latest HEAD not the latest release.

I am unsure if I should use the 64-bit version or Raspberry Pi OS or the 32-bit. I also noticed that the MightyHat was not able to shut down the RPi3b.

Stereodude

I did a clean install of 2024-03-15-raspios-bookworm-armhf-lite and set my username to pi. Also used the HEAD version when prompted in the script.

I had the same issue as before with pm.status_listen = 127.0.0.1:9001; blocking nginx from starting. I commented that out

The next issue was that nginx didn't have access to the gateway folder
sudo -u www-data namei /home/pi/gateway/
f: /home/pi/gateway/www/index.html
 d /
 d home
 d pi
   gateway - Permission denied

I had to change the permissions of the pi folder with chmod og+x /home/pi so that it could traverse the folder and get into the gateway directory. Now I can get to the web interface.

Not sure if it's working as my Motetinos are not here with me. I know the power/reboot button on the MightHat is not working. It looks like GPIO.wait_for_edge is not supported in the latest python included with the OS (3.11.2).

Stereodude

Quote from: Stereodude on June 21, 2024, 11:15:22 AM
Not sure if it's working as my Motetinos are not here with me. I know the power/reboot button on the MightyHat is not working. It looks like GPIO.wait_for_edge is not supported in the latest python included with the OS (3.11.2).
I resolved the issue with the power/reboot button on the MightyHat as detailed here: https://lowpowerlab.com/forum/mightyhat/fixing-mightyhat-shutdownreboot-functionality-on-rpi-os-lite-2024-03-(bookworm)/

Maybe I should have posted it here instead since it was a Pi Gateway software change not something that needed changing in the MightyHat, but it was specific to the MH.

Also, I got out my Motetino M0 w/ radio and confirmed that everything is working.

Felix

Thanks for documenting all this.
P.S. And we thought computers make our lives easy :-)

Felix

As a follow up - I fixed the script and it should now install PHP correctly as well as grant the necessary access to the /home/pi/gateway directory.

brasskey4u

I'm about to pull my hair out (what little I have left) and I am stuck with the same "Waiting on socket connection"  I changed the default user and rebuilt with "pi", that did not work.  I tried a pi2 and pi3, no joy.  I tried the Head version instead of the recommended version, same result, I also notice that I can not get the gateway to start and doing a ps ux | grep gateway just shows one line (the command itself).  I have the mighty hat installed and I see data from the 2 weather nodes I have just fine.  I also see data coming in by using the terminal program, so it appears that the pi serial port is getting data from the hat.  I think I have rebuilt my SD cards no less that 10 times with different combinations and still stuck with the waiting on socket connection.  Oh I also tried the chmod of the /home/pi directory like stereodude did, no luck with that.  Any ideas welcome.

Felix

Thanks for reporting it, please avoid pulling hairs, we will solve this somehow :-)
I have installed recently on a few Pi's including Pi5, I think there were minor bumps but nothing major that would prevent a good outcome.
I would need a bit more detail from the error logs to be able to advise on this. I am also checking the details of my installs to try to see what I did and if that might be a cause.
Having said that, unless you just need to use an older pi for economical reasons, I would advise using at least a RaspberryPi 3B+ or Pi 4 would be better.

brasskey4u

Hey Felix, thanks for the reply, I believe my pi3 is b+.  This actually ran on a pi2 for years and had zero problems until I moved and I think something happened to the SD card, so that prompted a new install.  So frustrating.  I have also started with a clean build did a sudo apt update && sudo apt upgrade -y , and that makes no difference.  Odd that the gateway won't start.  At this point it might just be a go unplug everything and comeback in a few days.  Sleeping on it had me trying new things this morning and I definitely had to rebuild with the user "pi".  I knew I screwed up when there was nothing in the home directory of the user I created.  Odd thing is that the default password for pi didn't work either.  But rebuilding everything with just pi user did not fix anything either.

Felix

I have some commercial installs that have a lot of changes and haven't really caught up. I will merge what is relevant as I have time.
For now I submitted a commit to the HEAD which includes some installation changes, updated packages etc, which will become a new patch release, also when I can have time to check that.
So right now get the HEAD and try again. It's important to make sure the settings.json5 contains the matching serial port (GPIO UART serial usually /dev/ttyAMA0 or USB serial usually /dev/ttyACM0) and the baud (this matters especially for GPIO UART, as opposed to the USB serial which can not matter when the port is emulated - in any case match it).
Note any install errors, look in the logs for reasons why the gateway.js service cannot start, or nodejs or socket.io are not running.
I will be building a brand new gateway for myself soon with a Pi5 and bring a lot of new features over from my custom commercial installs. At that point I will iron our all issues and merge everything and make a new major release. My big problem is time and other things that are high priority.

brasskey4u

Steps
new image via pi imager
64bit pi os lite for pi 3 b
user name pi
no updates or upgrades
selected HEAD version
installed Fail2Ban
ATXRaspi shutdown script
Installed interrupt script
answered no to login shell
answered yes to serial interface enabled
no to proftp
no to raspiconfig
reboot
Still getting "Waiting for socket connection"

Here is my setting in settings.json5

  serial: {
      editable: true,
      exposed: true,
      port: {
        value: '/dev/ttyAMA0',
        description: 'replace this with whatever serial port you have on your Pi/gateway (ttyAMA0 is the default GPIO serial port). If you use a MoteinoUSB then your Pi will emulate a serial port >
      },
      baud: {
        value: 19200,
        type: 'number',
        description: 'needs to match the Serial baud speed in the sketch running on the Moteino or MightyHat that is attached to this Pi',
      },



As you can see , I have no tty directory or device call ttyAMA0

pi@pigate:/dev $ ls ttyAMA0
ls: cannot access 'ttyAMA0': No such file or directory
pi@pigate:/dev $ cd tty
-bash: cd: tty: Not a directory
pi@pigate:/dev $


In the logs for gateway.sys.log, this just keeps repeating:

pi@pigate:~/gateway/logs $ more gateway.sys.log
/home/pi/gateway/gateway.js:1303



SyntaxError: Unexpected end of input
    at wrapSafe (node:internal/modules/cjs/loader:1740:18)
    at Module._compile (node:internal/modules/cjs/loader:1783:20)
    at Object..js (node:internal/modules/cjs/loader:1940:10)
    at Module.load (node:internal/modules/cjs/loader:1530:32)
    at Module._load (node:internal/modules/cjs/loader:1332:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
    at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
    at node:internal/main/run_main_module:33:47


webserver log:

pi@pigate:~/gateway/logs $ more webserver.error.log
2026/02/04 14:35:44 [error] 1051#1051: *7 user "pi": password mismatch, client: 192.168.0.108, server: gateway, request: "GET / HTTP/1.1", host: "192.168.0.162"
2026/02/04 14:35:55 [error] 1051#1051: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.108, server: gateway, request: "GET /socket.io/socket.io.js HTTP
/1.1", upstream: "http://[::1]:8080/socket.io/socket.io.js", host: "192.168.0.162", referrer: "https://192.168.0.162/"
2026/02/04 14:35:55 [error] 1051#1051: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.108, server: gateway, request: "GET /socket.io/socket.io.js HTTP
/1.1", upstream: "http://127.0.0.1:8080/socket.io/socket.io.js", host: "192.168.0.162", referrer: "https://192.168.0.162/"
2026/02/04 14:35:55 [error] 1051#1051: *7 open() "/usr/share/nginx/html/50x.html" failed (2: No such file or directory), client: 192.168.0.108, server: gateway, request: "GET /socket.io/socket.io.j
s HTTP/1.1", upstream: "http://127.0.0.1:8080/socket.io/socket.io.js", host: "192.168.0.162", referrer: "https://192.168.0.162/"


webserver.error.log:


pi@pigate:~/gateway/logs $ more webserver.access.log
192.168.0.108 - pi [04/Feb/2026:14:35:44 -0500] "GET / HTTP/1.1" 401 574 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143
.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET / HTTP/1.1" 200 32667 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/1
43.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /socket.io/socket.io.js HTTP/1.1" 404 181 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Ge
cko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /css/jquery.mobile-1.4.5.min.css HTTP/1.1" 200 207465 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KH
TML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /css/jqm-font-awesome-usvg-upng.min.css HTTP/1.1" 200 115121 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537
.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /css/listview-grid.css HTTP/1.1" 200 4853 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Ge
cko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /css/jquery.mobile.datepicker.css HTTP/1.1" 200 4936 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHT
ML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /js/jquery-1.12.1.min.js HTTP/1.1" 200 97403 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /js/jquery.flot.time-0.8.3.min.js HTTP/1.1" 200 4658 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHT
ML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:55 -0500] "GET /js/jquery.mobile-1.4.5.min.js HTTP/1.1" 200 200143 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTM
L, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
.
.
.
parsed info in the middle, here is the last several lines:

192.168.0.108 - pi [04/Feb/2026:14:35:56 -0500] "GET /css/images/ajax-loader.gif HTTP/1.1" 200 6242 "https://192.168.0.162/css/jquery.mobile-1.4.5.min.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64
) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:56 -0500] "GET /css/svg/terminal-16.svg HTTP/1.1" 200 861 "https://192.168.0.162/css/jqm-font-awesome-usvg-upng.min.css" "Mozilla/5.0 (Windows NT 10.0; Win64;
x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:56 -0500] "GET /css/svg/gear-16.svg HTTP/1.1" 200 1680 "https://192.168.0.162/css/jqm-font-awesome-usvg-upng.min.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64
) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:56 -0500] "GET /css/svg/database-16.svg HTTP/1.1" 200 1340 "https://192.168.0.162/css/jqm-font-awesome-usvg-upng.min.css" "Mozilla/5.0 (Windows NT 10.0; Win64;
x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:56 -0500] "GET /css/svg/flash-16.svg HTTP/1.1" 200 810 "https://192.168.0.162/css/jqm-font-awesome-usvg-upng.min.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64
) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"
192.168.0.108 - pi [04/Feb/2026:14:35:56 -0500] "GET /images/favicon.ico HTTP/1.1" 200 6727 "https://192.168.0.162/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko
) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0"






brasskey4u

Thank you for taking the time to help me.  This certainly isn't a high priority as its just supposed to be a fun project. :)


Felix

go to /dev then ls tty* - you should get a ton of tty devices. At the very least you should have ttyAMA0 which is the GPIO UART serial.

Anyway it's a mess looks like. I think I have a Pi3B+ somewhere and I'll try this when I have a few hours to burn.

brasskey4u

Here are my ttys:

pi@pigate:/dev $ ls tty*
tty   tty10  tty13  tty16  tty19  tty21  tty24  tty27  tty3   tty32  tty35  tty38  tty40  tty43  tty46  tty49  tty51  tty54  tty57  tty6   tty62  tty8       ttyS0
tty0  tty11  tty14  tty17  tty2   tty22  tty25  tty28  tty30  tty33  tty36  tty39  tty41  tty44  tty47  tty5   tty52  tty55  tty58  tty60  tty63  tty9
tty1  tty12  tty15  tty18  tty20  tty23  tty26  tty29  tty31  tty34  tty37  tty4   tty42  tty45  tty48  tty50  tty53  tty56  tty59  tty61  tty7   ttyprintk
pi@pigate:/dev $


I notice that there is a symbolic link for serial0:

pi@pigate:/dev $ ls -l ser*
lrwxrwxrwx 1 root root 5 Feb  4 14:34 serial0 -> ttyS0
pi@pigate:/dev $


Could that be an issue ? 

Felix

It could mean the serial is not enabled. What serial port are you connected to (from your Moteino/radio board)?