Ribbit-Network / ribbit-network-frog-hardware

The sensor for the world's largest crowdsourced network of open-source, low-cost, GHG Gas Detection Sensors.
https://www.ribbitnetwork.org/
MIT License
94 stars 26 forks source link

Setup issues with balena (WiFi Connect) and finding local wifi network #56

Closed spestana closed 1 year ago

spestana commented 2 years ago

I think a few folks (including myself) have had issues when connecting to the frog sensor over wifi, and connecting the sensor to their local wifi network. I wanted to capture some of that info here to see what might help solve these issues.

The current instructions for these steps are here: https://github.com/Ribbit-Network/ribbit-network-frog-sensor/blob/main/assembly-instructions/7-sensor-placement.md

spestana commented 2 years ago

My experience with these issues has been:

  1. plug in/power on frog sensor
  2. I see the WiFi Connect network start broadcasting and connect to it on my computer
  3. The balena login page (which is found at 192.168.42.1) has a drop-down menu with local wifi networks its found but my home wifi doesn't show up.
  4. Refreshing the page doesn't update the drop-down list
  5. Restarting the frog sensor and starting again at step 1 until my home wifi network shows up
  6. Pick my home wifi network in the drop-down menu, enter the network password
  7. WiFi Connect remains broadcasting and the frog sensor doesn't connect
  8. Restarting the frog sensor and starting again at step 1

Eventually I was able to connect the frog sensor to my local wifi network and data was visible on the ribbit network dashboard after going through the above steps several times.

Possible solutions?

keenanjohnson commented 2 years ago

From @Rabscuttler who experienced a similiar type of issue:

"I got the 'choose SSID' screen and the followup message, then the Wifi Connect network would disappear. At that point it seemed the device data didn't then appear on the web dashboard. I restarted several times, the Wifi Connect network didn't always reappear but eventually it did. I think I did a couple cycles of this. I also had trouble spotting the device on my routers network page. Do you know what the Device Name is?"

keenanjohnson commented 2 years ago

I think there are two primary things we've learned so far:

1) The wifi connect system is not exactly reliable. I'm currently using this Wifi Connect Repo.. Perhaps there is some sort of corner case with our specific wifi chipset or something. I'll continue to try and replicate the issue here and reach out to the Wifi Connect maintainers once I have something somewhat replicable. 2) It's obvious that the Frog sensor should provide some more status info maybe via an LED or some local webserver or something. I'll start brainstorming some ideas there.

keenanjohnson commented 2 years ago

I just created this issue to officially kick off the development of a local web UI which I think will go a long way to help any building or deploying a Frog Sensor diagnose and fix any issues! Let me know and get involved if you are interested in helping out in development! https://github.com/Ribbit-Network/ribbit-frog-micropython/issues/7

maggie44 commented 2 years ago

I think there are two primary things we've learned so far:

  1. The wifi connect system is not exactly reliable. I'm currently using this Wifi Connect Repo.. Perhaps there is some sort of corner case with our specific wifi chipset or something. I'll continue to try and replicate the issue here and reach out to the Wifi Connect maintainers once I have something somewhat replicable.
  2. It's obvious that the Frog sensor should provide some more status info maybe via an LED or some local webserver or something. I'll start brainstorming some ideas there.

I have been using wifi connect for a few years and it has always been a little problematic. It is fine for a basic use case of setting up a device with a connection when on site, maybe for a technician but for rolling out to a user base that needs ease it’s not ideal. It is now community supported and although has some Balena team input still it is a little sluggish among their other priorities and in Rust languages that has made community contributions difficult.

I also have a Python base to my project and some months ago moved to a Python based wifi connect (https://github.com/OpenAgricultureFoundation/python-wifi-connect).

Night and day difference, have been able to integrate more features and fix some annoyances. It’s always going to be a little unpredictable working with wifi but I’m pleased with the result.

43491198-DC43-41CE-A888-C0568DA9FE06

keenanjohnson commented 2 years ago

Thanks for that experience @maggie0002 ! Perhaps we should switch over to that python wifi connect! I'll give that a test soon!

maggie44 commented 2 years ago

Thanks for that experience @maggie0002 ! Perhaps we should switch over to that python wifi connect! I'll give that a test soon!

May be helpful: https://forums.balena.io/t/alternative-wi-fi-connect-looking-for-testers/349989

keenanjohnson commented 2 years ago

Thanks @maggie0002! That looks like a great repo! I'm not sure if it's super useful to use in the very short term since we need to present a UI to the Frog Sensor Owners, but perhaps in the future!

maggie44 commented 2 years ago

Hi @keenanjohnson,

Thanks for presenting last night.

I have been giving some more thought to your WiFi troubles. One of the key tricks up the sleeve of Python Wifi Connect is to use IW to do scans of the network instead of network manager, which seems to help resolve a lot of the issues of no wifi networks being visible on first boot. This could be a quick and easy addition to your current setup that is low risk for rolling out and doesn't require retooling any of your code (i.e. a shift to python wifi connect).

It would involve changing the Wi-Fi connect start.sh to something like this:

#!/usr/bin/env bash

export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

# Optional step - it takes couple of seconds (or longer) to establish a WiFi connection
# sometimes. In this case, following checks will fail and wifi-connect
# will be launched even if the device will be able to connect to a WiFi network.
# If this is your case, you can wait for a while and then check for the connection.
# sleep 15

# Choose a condition for running WiFi Connect according to your use case:

# 1. Is there a default gateway?
# ip route | grep default

# 2. Is there Internet connectivity?
# nmcli -t g | grep full

# 3. Is there Internet connectivity via a google ping?
# wget --spider http://google.com 2>&1

# 4. Is there an active WiFi connection?
iwgetid -r

if [ $? -eq 0 ]; then
    printf 'Skipping WiFi Connect\n'
else
+   iw dev wlan0 scan
    printf 'Starting WiFi Connect\n'
    ./wifi-connect
fi

# Start your application here.
sleep infinity

iw may already be in the container as part of wireless-tools, otherwise will need adding in addition, but it's very small in relation to the size of the container anyway.

If you have a lot of success with it do let me know and we can push it upstream to wifi-connect. I have avoided doing it just yet as it is a little hacky and wanted to validate that others have the same benefit I have had.

keenanjohnson commented 2 years ago

Thanks for the tips @maggie0002 ! I haven't had a lot of time to dig into this yet, but hopefully I or someone else in the community will soon!

keenanjohnson commented 1 year ago

We are moving away from wifi-connect in the v4 sensor as we transition to esp32, so closing this issue as won't fix for now.