GithubHelp home page GithubHelp logo

cfreshman / pico-fi Goto Github PK

View Code? Open in Web Editor NEW
26.0 1.0 1.0 667 KB

A MicroPython webserver framework for the Pico W with a captive portal for wireless network login

License: MIT License

HTML 50.53% Python 49.47%

pico-fi's Introduction

pico-fi

A MicroPython webserver framework for the Pico W with a captive portal for wireless network login

Quickstart Hold BOOTSEL & plug in Pico W

git clone https://github.com/cfreshman/pico-fi && cd pico-fi
python3 build -a --packs remote-repl

Then connect to w-pico (password: pico1234)
See packs/remote-repl for examples

Network Login Landing --packs remote-repl
For example, toggle the on-board LED:
from machine import Pin
import pico_fi

# Connect to the Pico W's network:
app = pico_fi.App(id='w-pico', password='pico1234')

# (on-board LED will be on if started successfully)
led = Pin('LED', Pin.OUT)
@app.started
def started(): led.on() 

# Wait for the login screen to appear
# Once logged in, you'll see a button to toggle the LED
@app.route('/led')
def toggle_led(req, res): led.toggle()
@app.route('/')
def index(req, res): res.html("""<button onclick="fetch(`/led`)" style="font-size:20vw">TOGGLE</button>""")

app.run()

Weighs 76K - 156K depending on configuration, supporting minified apps up to 774K
(2000K Pico W flash storage - MicroPython (1150K) - pico-fi (76K))

Features

  1. Connect the Pico to internet with your phone
  2. Serve HTML from the Pico
  3. Handle HTTP, WebSocket, and DNS requests
  4. Persist state on the Pico with provided get & set APIs
  5. Define new 'packs' for custom routes and behavior:
    Basic example - packs/hello-world
    Sync LED to endpoint - packs/led-indicator
    Web console for your Pico - packs/remote-repl
  6. Automatically build, minify, and sync changes to the Pico
    python3 build --packs hello-world,remote-repl --minify --sync --watch
    

Prerequisites

Hardware

  1. Pico W
  2. USB to Micro USB data cable
  3. LED (optional - defaults to on-board LED)

I've created a starter kit with these items

Software

  1. MicroPython
  2. rshell

Alternatively, make edits and upload to pico-repo.com/#how-to for a drag-n-drop .uf2
Then skip to Connect to the internet

Install

  1. Plug in your Pico W with MicroPython installed (if not, plug in while holding BOOTSEL)
  2. Download pico-fi & build
    git clone https://github.com/cfreshman/pico-fi
    cd pico-fi
    python3 build --auto
    
    This will automatically install MicroPython/rshell and start pico-fi on your Pico

See build for options or run python3 build -h

Connect to the internet

You should see a new w-pico wireless network appear (password: pico1234). Connect to this network with your computer or smartphone. If the portal doesn't open automatically, try opening http://192.128.4.1/portal. Expect this to take up to a minute - the Pico is doing its best.

Alternatively, specify the network credentials at build time: python3 build -a -n "network:password"

Post-install

Edit the network name/password or add functionality in main.py, HTML in public/index.html

If your main.py grows too complex, split into separate concerns under packs/ and include each in the build: python3 build -a pack-a,pack-b,pack-c. Or build without minifying for accurate stack trace line numbers: python3 build -ws pack-a,pack-b,pack-c

See packs/hello-world for a showcase of pico-fi features

Tip: prefix non-index.html files with the pack name, like cards-icon.png, since all the files get moved into the base directory when built

Looking for project ideas?

Potential upcoming features

  • WebSocket event handlers
    • remote-repl logs in real-time
  • Internet access through the Pico directly for connected devices (right now, devices have to reconnect to the base wifi network)
  • Minification step to support app sizes >750K
  • Create a new request

Third-party packs

  • (Send me any packs you make and I'll add them here)

pico-fi's People

Contributors

cfreshman avatar

Stargazers

 avatar Ian Schwartz avatar Cody Tolene avatar  avatar Davide Pirelli avatar Kamilkampfwagen-II avatar  avatar Colin Luoma avatar Erin Sparling avatar Filip avatar Will Dumm avatar  avatar  avatar Ferdinand Theil avatar  avatar Vzlom avatar  avatar  avatar  avatar  avatar Tony Jeffree avatar Rashid Khan avatar Jonas Müller avatar Fahmi Ahmad avatar  avatar Taylor Hokanson avatar

Watchers

 avatar

Forkers

emmatheclever

pico-fi's Issues

[ERROR] no matching stored network login

I ran the script several times with pico fi, everything flashed fine and booted, but all I get is:

[INFO] 2024/7/27 5:10:04 no stored network login
[INFO] 2024/7/27 5:10:04 defined packs: []
[INFO] 2024/7/27 5:10:04 configured routes: b'/portal' b'/' b'/get' b'/set' b'/api' b'/favicon.ico'
[INFO] 2024/7/27 5:10:04 configured events: 2 1 b'echo'
[INFO] 2024/7/27 5:10:04 start pico-fi
[INFO] 2024/7/27 5:10:04 register WebSocket to <handler WebSocket>
[INFO] 2024/7/27 5:10:04 register UDP to DNS
[INFO] 2024/7/27 5:10:04 register DNS to <handler DNS>
[INFO] 2024/7/27 5:10:04 register <connection UDP 537047088> to <handler DNS>
[INFO] 2024/7/27 5:10:04 DNS listening on :53 UDP DNS
[INFO] 2024/7/27 5:10:04 register TCP to HTTP
[INFO] 2024/7/27 5:10:04 register HTTP to <handler HTTP>
[INFO] 2024/7/27 5:10:04 register <connection TCP 537052800> to <handler HTTP>
[INFO] 2024/7/27 5:10:04 HTTP listening on :80 TCP HTTP
[INFO] 2024/7/27 5:10:04 found 8 networks
[INFO] 2024/7/27 5:10:04 26 XXX                   (XX:XX:XX:XX:XX:XX) chnl=1 sec=5 hid=4
[INFO] 2024/7/27 5:10:04 35 XXC                   (XX:XX:XX:XX:XX:XX) chnl=1 sec=5 hid=2
[INFO] 2024/7/27 5:10:04 53 XX1                    (XX:XX:XX:XX:XX:XX) chnl=5 sec=5 hid=4
[INFO] 2024/7/27 5:10:04 83 XX2                    (XX:XX:XX:XX:XX:XX) chnl=1 sec=5 hid=1
[INFO] 2024/7/27 5:10:04 84 XX3                    (XX:XX:XX:XX:XX:XX) chnl=11 sec=5 hid=2
[INFO] 2024/7/27 5:10:04 91 XX4                     (XX:XX:XX:XX:XX:XX) chnl=7 sec=5 hid=2
[INFO] 2024/7/27 5:10:04 access point: PicoFi ('192.168.4.1', '255.255.255.0', '192.168.4.1', '192.168.4.1')
[INFO] 2024/7/27 5:10:04 no matching stored network login
[INFO] 2024/7/27 5:10:04 network connect failed
[INFO] 2024/7/27 5:10:04 will retry connection to wifi every 5s
[INFO] 2024/7/27 5:10:04 no matching stored network login
[INFO] 2024/7/27 5:10:04 network connect failed
[INFO] 2024/7/27 5:10:04 retrying in 5s
[INFO] 2024/7/27 5:10:04 no matching stored network login
[INFO] 2024/7/27 5:10:04 network connect failed
[INFO] 2024/7/27 5:10:04 retrying in 5s

I go to the http://192.168.4.1/portal and while on the PicoFi network and I spins for about 60 secs and then fails, what might I be doing wrong, or is there something missing from this example, do I make the networks.json cause I don't see that in the code:

Screenshot 2024-07-27 at 10 14 41 AM

There is a store.json but its empty

Screenshot 2024-07-27 at 10 17 41 AM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.