Setup PI ZERO W as ultra portable server and AP (tutorial) updated to 2022 :)

ah, ok i see. but i do not have the client on the same hw. the client is a wemos.

Hope you don’t mind me posting this here @wanek but hopefully this thread can become a go to resource for Zero W.

@Dmitriy I messed up a new Zero W installation with the new login details for the admin panel. I didn’t want to use a server.properties initially so I went with the default credentials and this was fine.

I then added server.properties and new admin panel credentials, but no certs, and restarted the server.
The credentials were for one of my email accounts that didn’t yet have an account on the server. At this point the default credentials still gave me access to the admin panel.

I then added the account for the email address in server.properties and started the server again.

Now I can’t get in with Chrome unless I use incognito mode, probably some weird caching issue. Can’t login with Internet Explorer and that doesn’t have an cache for the url. Incognito is still taking the default access details and not the credentials I provided.

How do I gain access with the real credentials?

Are certs required for the admin panel to work?

What will happen if I delete the admin@blynk.cc account from the server?

no problem, posts from @Costas quite rarely debase the level of a topic :wink:

1 Like

regarding the autostart, there was a bug in docs, this is why it not worked with the first method…

The better solution is to create a separate script in init.d folder, and run update-rc.d to include it at startup. There is an example startup script for Blynk I made somewhere around here. But for reference, here is another script:

#!/bin/sh

### BEGIN INIT INFO
# Provides:          mjpeg-stream
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpeg-stream
# Description:       webcam stream from local network
### END INIT INFO

BASE=/tmp
PID=$BASE/mjpeg-streamer.pid
LOG=$BASE/mjpeg-streamer.log
ERROR=$BASE/mjpeg-streamer-error.log

COMMAND="/home/bastiaan/mjpg-streamer/mjpg_streamer -b -i '/home/bastiaan/mjpeg-streamer/input_uvc.so' -o '/home/bastiaan/mpjeg-streamer/output_http.so -w ./www -c bastiaan:15Pir@@tjes'"

status() {
	echo
	echo "==== Status"

	if [ -f $PID ]
	then
		echo
		echo "Pid file: $( cat $PID ) [$PID]"
		echo
		ps -ef | grep -v grep | grep $( cat $PID )
	else
		echo
		echo "No Pid file"
	fi
}

start() {
	if [ -f $PID ]
	then
		echo
		echo "Already started. PID: [$( cat $PID )]"
	else
		echo "==== Starting"
		touch $PID
		if nohup $COMMAND >>$LOG 2>&1 &
		then
			echo $! >$PID
			echo "Done"
			echo "$(date '+%Y-%m-%d %X'): START" >>$LOG
		else
			echo "Error"
			/bin/rm $PID
		fi
	fi
}

kill_cmd() {
	SIGNAL=""; MSG="Killing "
	while true
	do
		LIST=`ps -ef | grep -v grep | grep server.jar | awk '{print$1}'`
		if [ "$LIST" ]
		then
			echo; echo " $MSG $LIST" ; echo
			echo $LIST | xargs kill $SIGNAL
			sleep 2
			SIGNAL="-9" ; MSG="Killing $SIGNAL"
			if [ -f $PID ]
			then
				/bin/rm $PID
			fi
		else
			echo; echo "All killed" ; echo
			break
		fi
	done
}

stop() {
    echo "==== Stop"

    if [ -f $PID ]
    then
        if kill $( cat $PID )
        then echo "Done."
             echo "$(date '+%Y-%m-%d %X'): STOP" >>$LOG
        fi
        /bin/rm $PID
        kill_cmd
    else
        echo "No pid file. Already stopped?"
    fi
}

case "$1" in
    'start')
            start
            ;;
    'stop')
            stop
            ;;
    'restart')
            stop ; echo "Sleeping..."; sleep 1 ;
            start
            ;;
    'status')
            status
            ;;
    *)
            echo
            echo "Usage: $0 { start | stop | restart | status }"
            echo
            exit 1
            ;;
esac

exit 0

The trick is to use the start/stop/restart states otherwise update-rc.d won’t work. More info here: https://www.debuntu.org/how-to-managing-services-with-update-rc-d/

thanks, i will look into this. what is the advantage of creating separate script?

That you can start/stop/restart the srvice/app from the same script. It will run at boot (add with: $ update-rc.d script.sh defaults) and you can manually start/stop them. Which comes in handy too.

My script even creates a PID file to see of a service is already started, granted, it can be a bit more sophisticated, but it does the job if you don’t have too many unexpected reboots.

And all in all, init.d is the place to put those scripts. It’s just good practice :slight_smile:

than maybe this is how it should be explained in the official docs? @Dmitriy?

@wanek I have my Zero W set up as a wireless AP and it’s fine but I had a few questions regarding internet access for the AP.

Many of the online tutorials refers to Pi’s with Ethernet ports but obviously the W doesn’t have one.

I know there are USB 2 Ethernet adaptors you can buy but I’m guessing this is not what you are using.

This is my interfaces file:

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
gateway 192.168.42.200
dns-nameservers 8.8.8.8 8.8.4.4
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

#allow-hotplug wlan1
#iface wlan1 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

And this is my hostapd.conf

interface=wlan0
#driver=nl80211
ssid=Pi_AP
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=xxxxxx
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

I have tried with the driver commented out and with the driver in place and it warns me of a driver issue when I run the AP but the AP seems to be fine.

Is your main network on a different subnet to 192.168.42.XXX or is it on the same?

Could you please compare my files with yours and see if there are any obvious differences and perhaps expand upon the internet sharing aspect to give internet access to the AP.

just for clarification:
i connected my zero wifi to my laptops shared internet connection via wifi (the laptop had ethernet cable plugged in), not directly to the router wifi. i didn’t needed internet all the time on my zero, so this temporarily solution worked fine, just while i updated the server and os.

how did you try exactly, and where it failed?

my /etc/network/interfaces:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback
iface eth0 inet manual

allow-hotplug wlan0

iface wlan0 inet static
    address 192.168.42.1
    netmask 255.255.255.0
    gateway 192.168.42.200
    dns-nameservers 8.8.8.8 8.8.4.4

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

and my /etc/hostapd/hostapd.conf file:

interface=wlan0
ssid=zero
country_code=US
hw_mode=g
channel=9
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

i didn’t spot any difference between your and my above 2 files (except the commented-out driver line).
my main network (router) is on 192.168.0.1, the 192.168.42.XXX is used exclusively on the zero.

regarding the internet connection, this is how i’ve done (i use windoze 10 on my pc):

i’m glad to help, if you elaborate exactly what you need to know.

@wanek yes it’s the Windows internet sharing that I’m struggling with. My router is using a subnet of 192.168.10.XXX.

I have tried with the gateway reference on the Pi and Windows as both 192.168.10.200 and 192.168.42.200.
10.200 is fine for the laptop but doesn’t give internet access to the Pi and 42.200 gives internet access to neither machine.

Just wondering how your subnet of 192.168.0.XXX ties up to the 192.168.42.200?

I think you need to use IP tables to setup NAT to the subnet from the Pi ethernet which wants Internet. Some more info here: http://www.revsys.com/writings/quicktips/nat.html

@Lichtsignaal the IP tables setup for NAT is covered in @wanek’s link of https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/overview

The IP of 192.168.42.200 is fine for the gateway.
Think I was getting confused over what I was sharing on my laptop and you must follow a precise procedure of connecting to the Pi’s AP before sharing etc.

I don’t normally use Ethernet on the laptop but the settings when I do are:

AFTER you have connected to the Pi’s AP you can then share the Ethernet VIA the WiFi connection:

Then set IP of WiFi connection as 192.168.42.200 as per the Gateway in interfaces on the Pi and checking Details for the connection should show:

And finally check the Pi with a ping to Blynk:

I have ordered a couple of these for the Zero W in any case:

ok, so you finally managed to share the internet?
what was the problem? do you think should i edit the steps in the tutorial, or something?

Your tutorial is fine, no edits required. I just wasn’t following the precise order.

Hi i tried to follow this and im running in to a problem, when i try to run the server and the hotspot at the same time i get “Server ports are busy”. Any suggestions ? thanks

Means you already have some process that uses port Blynk needs.

This is a fresh install so the router portion is probably using a port blynk needs ?

Nevermind, the code gods have blessed me, it works.Dunno why but it works.

2 Likes

:joy:

1 Like