RPi3 Wifi not connecting after a reboot from the API

Hi!

After issuing:
curl -X POST --header “Content-Type:application/json” \
"$RESIN_SUPERVISOR_ADDRESS/v1/reboot?apikey=$RESIN_SUPERVISOR_API_KEY"

To reboot from the app itself, the wifi does not reconnects.

If I reboot from the dashboard the wifi reconnects ok.

(I am talking about real physical device rebooting, not app restart)

I only noticed a difference between the two ways of rebooting, when I reboot with the API within the app, all process seems to be killed, since the screen returns to the splash logo, then it turns off, then start again.
When rebooting from the dashboard it turns off quick.

Edit2: I spent a couple of hours testing… every time I reboot the device from the dashboard, the wifi works after the reboot. Every time I do it with the API, it fails.
I still could not identify why it doesn’t reconnect.

Any ideas? Thank you!

Hi there,

I think this may be an issue with resin-wifi-connect or the supervisor. I have opened an issue here and will try my best to reproduce and fix ASAP.

Thanks for reporting

1 Like

Hey @diegosucaria

I have been unable to reproduce this behavior - here’s what I have been doing:

  1. Created a new app
  2. Downloaded the OS and confirmed HostOS = 1.24.1 and Supervisor = 2.8.3, set up WiFi credentials on the dashboard
  3. Burned the SD card, booted up Pi3 and waited for it to provision
  4. Pushed the master of resin-wifi-connect
  5. Waited for the hot spot to come up and configured the WiFi credentials
  6. Rebooted via the dashboard and checked it came back online (with the expected resin-wifi-connect and supervisor logs)
  7. Rebooted 3 times using the curl command you wrote above and checked it came back online (with the expected resin-wifi-connect and supervisor logs)

Can you try these exact steps please and let us know if you still see the issue.

Thanks

Hi @joe,

Yes, I did not provision a new SD card, but moved the device to a new test app.

  • pushed resin-wifi-connect master into it.
  • Connected ethernet so it downloads the image.
  • After it booted and the wifi hotspot came back online I un-plugged the ethernet cable.
  • Entered the wifi credentials.
  • The device is now online using wifi.
  • On the terminal, I run the curl command.

The device rebooted and did not came back online.

Edit: Tried several times using the curl command. 1st time failed, 2nd time worked, 3rd time worked, 4th time failed…
I found that every time I reboot it from the dashboard and then I reboot it with the curl command it fails.

The problem here is that I am not being able to see the logs, so I can’t tell what is failing.

Hey @diegosucaria

I managed to reproduce! The problem is that occasionally the connman service is not started when resin-wifi-connect asks it to connect to the configured connection so the connection times out.

I have a fix on branch 71-wait-until-service-ready which works for me. Please could you try this out and let me know if it solves the problem for you and then I will merge the PR.

Thanks for reporting this and your patience :slight_smile:

1 Like

I updated the resin-wifi-connect on our app, from your fix branch, but sorry, it didn’t work.

However the behaviour is a little bit different…

  1. Reseted the device from the dashboard. came back online.
  2. Reseted the device with the API, did not came back online.
  3. After that, I restarted the APP and it came back online.

I do not know if it helps, but can’t we just make it try to connect again after a while? I mean, if it could not connect at startup, can we try again after some minutes?

Hi @diegosucaria

I provisioned a new device without setting the WiFi credentials, connected the device to Ethernet, pulled the master branch of resin-wifi-connect (I merged the fix PR beforehand) and pushed it to the device. Once it had downloaded I disconnected the Ethernet and set up the WiFi credentials via the hot spot.

I then:
Rebooted from the dashboard 5 times
Rebooted from the API 5 times
Rebooted 6 times alternating between dashboard and API each time

It worked every time, which makes me think it could be your network causing issues? You could try increasing the timeout and see if that fixes things by setting an environment variable in the dashboard CONNECT_TIMEOUT to 30000 (the default setting is 15000 - 15 seconds)

You can also adapt the script below to make it attempt to re-connect as you wish

#!/bin/bash

# Look for the network for a while, good to check if Ethernet is available
GOTNET=0
for ((i=0; i<60; i++))
do
    if curl --output /dev/null --silent --head --fail http://www.google.com; then
        GOTNET=1
        break
    fi;
    sleep 1
done

# If no network, try four times, because it tries configured credentials for 15 seconds for each iteration
if [ "$GOTNET" -eq 0 ]; then
    export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
    sleep 1
    for ((i=0; i<4; i++))
    do
        node src/app.js --clear=false
        if curl --output /dev/null --silent --head --fail http://www.google.com; then
            GOTNET=1
            break
        fi;
    done

fi

# If we still can't find the network, clear credentials and try again
if [ "$GOTNET" -eq 0 ]; then
    until $(curl --output /dev/null --silent --head --fail http://www.google.com); do
        node src/app.js --clear=true
    done
fi

# Run our app
while true; do
    echo howdy
    sleep 1
done

Thank you @joe!!

With your script the device is connecting every time.

I was doing node src/app.js --clear=false directly, without checking for network first.

I do not know exactly what changes, but it works now!

No need to change the connect_timeout variable.

Thank you again!

1 Like

Great news @diegosucaria I am glad you got it working now!!

I have a quick question that may explain why it started working… what command did you use to push the 71-wait-until-service-ready branch to resin?

I manually copied the branch files over to my app project!