LucidEye
Posts: 84
Joined: Sun Aug 04, 2013 2:20 pm

How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sat Aug 01, 2020 11:12 pm

I have a time-lapse camera I've built with an R-Pi Zero W.
I need to use this camera out in the field where there is no normal WiFi connection via a router.
The entire setup is enclosed in a waterproof case and thus I need to connect to this R-Pi via my Android phone using WiFi direct ONLY (I can NOT use Bluetooth either as the BT on the Pi is being redirected to the mini-UART for a HAT board)
I need the R-Pi to be setup as a stand-alone WiFi access point broadcasting an SSID so that I can see it from my phone and connect to it using a password login (NOT WPS or PIN login).
I then would connect to the R-Pi with my phone using SSH or the RaspController app to make changes to the time-lapse settings in my Python code (https://play.google.com/store/apps/deta ... r&hl=en_US)
This used to be a really easy thing to setup a couple of years ago, but apparently it's become overly complicated lately for reasons I don't understand... I've seen many "instructions" on how to do it, but they are all different, all seem outdated, and none of them work according to the most recent comments on those instructions.
Why doesn't this page -
(https://www.raspberrypi.org/documentati ... /wireless/ )
have instructions for that scenario?
Before I started wasting my time with a bunch of "instructions" that seem dubious or outdated at best, I thought I'd ask here for the most recent, up-to-date-method of achieving this configuration.... but there doesn't seem to be one in the official documentation, which seems odd to me considering that these days it would be a pretty common scenario :-(
Can someone please tell me what the simplest way to accomplish this would be?
I am running the 2020-05-27 build of RaspiOS Buster
Thank you very much :-)

drgeoff
Posts: 10950
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sun Aug 02, 2020 7:54 am

https://www.raspberrypi.org/documentati ... -routed.md should work. The LAN port (which a ZeroW does not have) is superfluous in your situation.
Quis custodiet ipsos custodes?

LucidEye
Posts: 84
Joined: Sun Aug 04, 2013 2:20 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sun Aug 02, 2020 9:45 am

Yes, I've tried that setup, skipping the "Enable routing and IP masquerading" to create a standalone AP on the Pi.
I keep running into these problems...
1. I can not connect with DHCP from my phone, it never automatically acquires an IP address from the Pi. I have to set my phone to static IP and then it will connect to the Pi (even though the Pi is set to use DHCP)? The Pi's IP address is 10.0.0.1. I have the IP range set to 10.0.0.2 to 10.0.0.10. I've set the phone's IP to 10.0.0.10
2. Even though my phone appears to be connected to the Pi and has an IP address, I can not SSH into the Pi from my phone. I keep getting "Connection error. Timeout. Socket is not established." I have tried setting the timeout on my phone from the default 10 seconds to 20 seconds and it still will not connect. I have placed the file "ssh" in the boot directory on the Pi and I am using the default port (22)... but it will not connect. I know I am using the correct SSH password. So I don't understand why it is not connecting via SSH.

So at this point I no longer have any WiFi access to the Pi to edit any configuration files, I need to dismantle the whole setup to get to the SD card and plug it into another computer to edit the config files. I don't have an HDMI cable to plug the Pi into a monitor to try to see what is happening on the Pi side of things, so I can't do any troubleshooting while the Pi is running.

Any suggestions would be appreciated.

Thanks

drgeoff
Posts: 10950
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sun Aug 02, 2020 1:30 pm

Are you getting the login password prompt when you try to ssh in?
Quis custodiet ipsos custodes?

LucidEye
Posts: 84
Joined: Sun Aug 04, 2013 2:20 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sun Aug 02, 2020 8:36 pm

I'm trying to login to the Pi with my Android phone, so no, there is no login prompt from the Pi. I've tried using 2 different apps on my phone, JuiceSSH and RaspController. In apps like these you setup a "profile" for each computer you want to login to with all the login information and then you just tap an icon and the app logs you into that machine. I've never had a problem logging into any of my machines from these apps before, the only thing that is different in this situation is that this time I'm trying to login to a stand-alone AP, which shouldn't matter being that all the protocols are the same, there's just no internet available on the stand-alone AP. I have no way of knowing why the socket isn't available on the Pi and it keeps timing out the SSH connection from the phone.

I did try connecting to the Pi from my laptop. I had the same problem with the DHCP not working, the Pi is set to use DHCP but again when connecting via WiFi to the Pi from the laptop it never acquired an IP address and I had to force the laptop to use a static IP and then it connected fine. Once connected, I was able to SSH into the Pi from a terminal, so I know it is working, I just can't get it to work from my phone :-(

There is obviously some setting, either on the Pi or on the phone, that isn't allowing the socket to connect before timing out. But I don't even know where to begin looking.

My best guess at the moment is that for some reason the port forwarding on the Pi isn't working when trying to SSH in from the phone. I'm wondering if completely removing the firewall from the Pi will solve this? It's a stand-alone AP, why does it even need a firewall?

drgeoff
Posts: 10950
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sun Aug 02, 2020 11:01 pm

Your desired topology does not use routeing so port forwarding should not be invoked. And I would dump any firewall stuff too. At least initially.

Looks like you don't have a DHCP server running on the RPi.
Quis custodiet ipsos custodes?

LucidEye
Posts: 84
Joined: Sun Aug 04, 2013 2:20 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Sun Aug 02, 2020 11:25 pm

I followed this documentation...
https://www.raspberrypi.org/documentati ... -routed.md
which supposedly sets up the DHCP server. I have mine configured like this...

interface=wlan0 # Listening interface
dhcp-range=10.0.0.2,10.0.0.10,255.255.255.0,24h
# Pool of IP addresses served via DHCP
domain=wlan # Local wireless DNS domain
address=/gw.wlan/10.0.0.1
# Alias for this router

Regardless of whether the DHCP is working, I still can not SSH into the Pi from my phone even with a static IP.

This is why I asked for other instructions specifically for connecting to the Pi from a smartphone in my original post, because the documentation here on the Raspberry Pi site does not work for smartphones trying to connect to a stand alone AP on a Raspberry Pi. There really needs to be a separate document specifically for this type of connection (WiFi direct with Andriod phone as client).

LucidEye
Posts: 84
Joined: Sun Aug 04, 2013 2:20 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Tue Aug 04, 2020 12:46 pm

OK... so after much more digging around in this and other various forums, it seems like I'm not the only one having this same problem. And it seems like this is an issue specific to the Pi Zero W and Android phones (SSH timeout).

There's this one...
viewtopic.php?t=182952
Nothing useful there as it seems that issue is still unresolved after 3 years :roll:

And this one...
viewtopic.php?t=178025
Nothing useful here as it is a slightly different issue from the one I am having. Although I did try the edits to the sshd_config and it did not fix my problem :roll:

And this one...
viewtopic.php?t=256770
Setting a different SSH port didn't work either :cry:

I am able to connect to the Pi from my laptop via the WiFi using a static IP and I can SSH into the Pi.
I can ping the Pi to itself (10.0.0.1) and it works ok.
I can ping my phone from the Pi (10.0.0.10) and that works ok.
I can ping my laptop from the Pi (10.0.0.5) and that works ok.
I can NOT ping the Pi from my phone even though my phone says it is connected to the Pi with IP address 10.0.0.10, and I can not SSH into the Pi from my phone no matter what app I am using... I get the same error: Connection error. Timeout. Socket is not established.

I am still hoping someone can give me an answer as to why this isn't working... at least someplace I should be looking for where the problem might be... some configuration file on the Pi... SSH config? Networking config? Anything? Bueller.... Bueller? I've been working on this project for 2 months now, trying to get it working before our monsoon season here in Arizona so I can shoot some nice time lapse movies of the rain storms, clouds, and awesome sunsets... and I thought I finally had everything working, only to be stopped dead by this problem. I really need to find a fix for this, the whole point of building this camera was to be able to use it out in the field and connect to it via my Android phone so I can adjust the settings on the time lapse and stepper motor scripts via SSH. Hiking my laptop into the wilderness in my backpack is not an option, the camera and my phone are small, light, and weather proof... my laptop is not :(

Would really appreciate some help getting this to work like it's supposed to.
Thanks.

LucidEye
Posts: 84
Joined: Sun Aug 04, 2013 2:20 pm

Re: How to connect to R-Pi with phone wifi-direct NO ROUTER????

Fri Aug 07, 2020 8:41 am

SOLVED! :D

After 2 more days of digging around more forums and trying several configurations, I came across this wonderful setup! :)

It allows you to setup any R-Pi as either a regular WiFi client on your home router, OR it will automatically set itself up as a Hotspot if it doesn't detect your router WiFi network, allowing you to connect via WiFi Direct (p2p) with your phone, tablet, laptop, etc.! :o

It also mentions a bug in Android that prevents you from connecting via SSH when using WiFi Direct... You need to TURN OFF MOBILE DATA on the phone to make SSH work in WiFi Direct mode!

MODERATORS: PLEASE consider posting this setup to the https://www.raspberrypi.org/documentati ... /wireless/ page... I can think of so many scenarios where people would need this kind of functionality... as well as the fix for Android when connecting via SSH to an R-Pi Hotspot (p2p).

This setup worked perfectly on the first try... it does take slightly longer for the Pi to boot and connect to your router, or for the Hotspot to show up when it can't find your router, so be patient after the Pi boots. ;)

I hope this helps other people :D

Here's the link... ENJOY! :mrgreen:
https://www.raspberryconnect.com/projec ... connection

Return to “Networking and servers”