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

hello everyone!

today i’ve received the new pi zero wifi from pimoroni uk (i really reccommend this shop, received in 5 days)

what i would like to do, in short:
create a completely standalone, ultra portable / ultra light / low power consumption blynk server

for this, @Fettkeewl recommended me the pi zero w, with built in wifi and ble. it has everything on board, no extra hw needed just a battery and has a very small footprint.

to be completely self supported, the pi zero has to be the server and also the wifi hotspot in the same time. this is what i try to configure now. i have 0 experience with blynk local servers, so this is a trial and error for me.

what i achieved so far:

so far so good…
now the problems begin:

when i started my project, it says “not enough energy”.
ok. i learned that on local server i can have as much free energy as i want. and also learned, that i need to access some kind of admin panel in browser on the server to give myself energy :slight_smile:

i have tried this: “https://192.168.42.1:9443/admin”, but it can’t find that page…
what am i doing wrong, or missing some steps?

someone with experience on local servers, please help,
thank you!

4 Likes

Hi @wanek,
Did you create “server.properties” file?

See below:

After that, create “mail.properties” file:

Regards

2 Likes

To be more specific :

Comma separated list of administrator IPs. Allow access to admin UI only for those IPs. You may set it for 0.0.0.0/0 to allow access for all. You may use CIDR notation. For instance, 192.168.0.53/24.

allowed.administrator.ips=127.0.0.1

In other words you can’t access admin page if you try to access it from another PC unless you changed this property.

1 Like

thanks for the fast reply!

i was avare about that file (server.properties), but didn’t tought it is mandatory! for me this phrase was misleading:

"Advanced local server setup

For more flexibility you can extend server with more options by creating server.properties file in same folder as server.jar. Example could be found here. You could also specify any path to server.properties file via command line argument -serverConfig. You can do the same with mail.properties via -mailConfig and sms.properties via -smsConfig."

if it is not possible to access admin panel without creating this file - thus using my projects - i think this is mandatory, so:

“more flexibility” → “to access admin panel”
“you can” → “you have to”
“you could” → “you should”

ok, maybe i’m already too tired now (it is 01.00 here and it took several hours for me to chew through all this linux stuff :wink: )

i think i will visit http://www.go2bed.now, and will continue tomorrow…

oh, just some more questions:

  1. if i will use the pi as completely standalone ap, with no internet, it is mandatory to do this? because without internet it can not send email anyway…

  2. here it says: “IMPORTANT Server should be always updated before you update Blynk App.”

my phone has internet access, so it always uses the latest app version.
but after i set up the zero to be ap, i can’t connect to the internet anymore with the pi zero. so, how can i keep the blynk server jar file updated? any ideas?

@Dmitriy, thanks for clearing this up. at the moment i will be happy if i can access the admin panel from the zero itself. after that i will experiment with external access!

actually, i was pretty astonished how relatively easy was to set up all this stuff - so far, at least :slight_smile:

based on the forum discussions, i was prepared for something much harder. everyone said “this is advanced stuff, for experienced users, etc.”

Probably not required in your case. But you will not have automatic transfer of generated auth codes… You will need to copy/paste them from app and send them to your sketch via other means (email on phone or cloud sharing, etc).

No.

The simplest solution would be to turn off auto updates for app. And do manual updates when necessary.

We will also simplify admin access soon. However, no compromise here. Either secured env. or simplicity :slight_smile:.

1 Like

i didn’t say the current way to set up admin panel is complicated, because it seems ok.
the problem rather was the not very clear composition of the docs, about the importance of the server.properties file. that should be edited a little…

I agree… I had Local Server up and running almost at the very beginning… but it took much longer tying to figure out the admin page before even catching onto the server.properties file.

But as stated… soon to get even easier :smiley:

ok, now i need some sleep. tomorrow i will get back with details how it goes.
thanks again, for everyone!

I didn’t mean you, I mean many other users :slight_smile:.

1 Like

hello!

just continuing with my wandering in the realm of linux and rpi… maybe will be useful for others. today i managed to configure the rest of the necessary stuff:

  • downloaded blynk server files from here

  • copy server.properties file into home/pi folder and make your modifications if necessary. i’ve changed here:
    enable.raw.db.data.store=true
    allowed.administrator.ips=0.0.0.0/0 (only i will use this server, so no security concern)

  • reboot pi

  • start blynk admin panel in browser, give yourself lots of energy in users > yourAccount > energy > save changes

  • make the modifications in hw sketch and upload. for easy switching between cloud and local server, i made like this:

in header file:

// SERVER CONFIGURATION
//#define CLOUD
#define LOCAL

in main file:

#ifdef CLOUD
const char* ssid = "router ssid";       // CLOUD
const char* pass = "router wifi pass";  // CLOUD
char auth[] = "cloud token";
#endif

#ifdef LOCAL
char ssid[] = "zero ssid";             // LOCAL
char pass[] = "zero wifi pass";        // LOCAL
char auth[] = "local token";
#endif

and in void setup:

#ifdef CLOUD
    Blynk.begin(auth, ssid, pass);  // CLOUD
#endif

#ifdef LOCAL
    Blynk.begin(auth, ssid, pass, IPAddress(zero ip here));  // LOCAL
#endif

this way, when switching the same hw between local or cloud, i just have to comment / uncomment the 2 lines in the header file.

at this point all the pi / ap / server / app / hw configuration is done. now, i can connect to my local blynk server and have a fully standalone, working system. (when uploading new sketch ota, i just connect with my laptop to the pi zero wifi, and select the wemos ip address in arduino ide)

now, i could even stop here, because theoretically all is set up. but i’m too lazy person, and i wanted to have other “gadgets” like:

1) reduced boot time / power consumption on pi

2) access my pi zero from my windoze laptop (this way i can renounce to the pi’s keyboard, mouse and display)

3) have internet connection on the pi, while still in ap mode (this is important, because i have to keep the os and blynk server up to date, etc)

my linux knowledge is ultra basic, to say at least. probably i could never figure out how to achieve all these functions, if one of my friends didn’t help me out. (luckily, that guy is a unix / linux guru. these specimens are really strange kind of people, but could be quite handy sometimes ;))

1) ok, actually i could do this alone, with some google:
in terminal type: sudo raspi-config (this is kind of a “bios” menu for the pi)
here one can find various basic os setting. i just have selected the “no gui on startup, with command line auto login” option, that’s all. this way i have much shorter boot up time, lower current consumption, lighter on ram, etc.

2) access pi from windoze pc:

  • first enable ssh on the pi:
    one can do this in gui:
    start menu > preferences > pi configuration > interfaces
    or in sudo raspi-config

  • after ssh is enabled, install putty portable on the windoze machine. connect to the pi hotspot, open putty and type the pi zero ip address. leave the other settings as is (port 22, ssh). you can also save the session for future use. (on my pc the putty text size was too small to read, i could set the size in window > appearance > font settings.)

also, if you wish to set up auto log in with putty, you can do like this:

  • create a shortcut for putty exe
  • edit in shortcut > properties > target > putty.exe -load my_server -l your_user_name -pw your_password
    (‘my_server’ is the saved session name)

if all is set, just press open. a terminal window will open, here you have to enter user (default rpi user is “pi”), and password (default is “raspberry”).
there you have a working command line, to interact with the pi zero! no dedicated keyboard, mouse, display are needed, you can mount now the mini server out of sight!

3) internet connection:
for my project i set up the pi to work in access point mode (wifi hotspot). so, there is no internet connection on it. if you wish to check for server updates, or install new app, it is not possible.
here is how to share your laptop’s ethernet connection with the pi:

on the windoze pc:

  • connect to the pi zero wifi

  • start putty and connect to the pi (log in, etc)

  • set the gateway to use static ip:
    edit the interfaces file: sudo nano /etc/network/interfaces
    add after netmask line these 2 lines:

  • gateway xxx.xxx.xxx.200 (the pi ip address)

  • dns-nameservers 8.8.8.8 8.8.4.4

  • it should look like this:

    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

save the file and close editor: ctrl+x, y, enter

  • restart pi with: sudo reboot
  • after the pi has restarted connect to pi wifi, open network and sharing centre
  • click on the ethernet connection > properties > sharing tab > check the first tab, uncheck the second. click ok.
  • click on the pi zero wifi > properties > internet protocol version 4 > properties > confirm that use the following ip address is selected, then click advanced.
  • in ip settings tab at ip addresses click add. enter the pi zero ip address, except for the last value give 200 (like this: xxx.xxx.xxx.200). for subnet mask use 255.255.255.0
  • after you create the alias, click ok in each previous dialog box
  • reboot pi, after it has restarted connect to pi wifi
  • in putty terminal check the internet connection with:
    ping 8.8.8.8 (if you see some ms times it is ok)
    ping google.com (if you see some ms times it is ok)
  • now you can install mc file manager for example with sudo apt-get install mc
  • if you need to transfer files between you pc and pi zero, you can do it easily with winscp portable
  • !!! after you no longer need the internet on the pi, you should uncheck the box in: ethernet connection > properties > sharing tab > uncheck the first tab
4 Likes

After all said and done, disable the GUI on the Pi, saves power :wink:

if you mean this:

it is already done :slight_smile:
i’ve heard that it is also possible to turn off the hdmi port, it saves around 25ma, but it is a little risky…

Ow yes, missed that, awesome instructions, very complete!

thanks, i still learning linux, on very beginner level

Did you use the forever service for this or did you find a less bloated way?

initially we (one of my quite expert linux friend + me) tried to make it with init.d method, but after more than 1 hour unsuccessful trying, we gave up.

with the crontab it worked out of the box, and still work flawless since than.

1 Like

@wanek crontab seems fine, maybe it’s the client (in combination with the server) that requires the forever service.

i do not really understand. you mean if the client + server are on the same rpi?

Yes, the issue is the Blynk server takes quite a long time to start up so if you try to run the client from crontab and similar it will fail. “Forever service” is fine though.