Git Product home page Git Product logo

esp32-pico-wifi's Introduction

A Rust-based Pico driver for the ESP32 wireless feather board from Pimoroni

This is a proof-of-concept project that translates enough of Pimoroni's C++ code into a Rust implementation to POST to an Ambi web backend instance with live temperature, pressure and humidity values via a BME280 sensor.

This project will eventually turn into a full open source library that implements most or all of the WiFi functionality for use in any embedded Rust application.

Getting started

For more details see the following article on getting started for getting your environment set up on Mac/Linux: https://reltech.substack.com/p/getting-started-with-rust-on-a-raspberry

At the time of writing, this code is heavily influenced by the Pimoroni C++ Wifi driver: https://github.com/pimoroni/pimoroni-pico/blob/main/drivers/esp32spi/

Hardware

In order to run this code you need to purchase some hardware. This section provides a list of required hardware needed at minimum, and some suggested items to make your life even easier.

Required Hardware

  1. Raspberry Pi Pico with pre-soldered headers (2x)

  2. Pimoroni Pico Wireless Pack (1x)

  3. BME280 temperature/pressure/humidity sensor (1x)

  4. Breadboard (1x)

    • Note: If you already have a medium/large breadboard, then don't worry about purchasing this specific one

Optional but Helpful Hardware

  1. Break Away Headers (1x)

    • If you want to solder headers to the non-pre-soldered BME280 sensor board from #2 above
  2. Multi-length Jumper Wire Kit 140pcs (1x)

  3. Straight 7" Jumper Wires M/M (1x)

    • Helpful to have some of these on hand
  4. Straight 6" Jumper Wires M/F (1x)

    • Helpful to have some of these on hand
  5. Saleae Logic 8 (1x)

    • Note: Only needed if you'd like to participate in developing/debugging parts of this project that communicate on the SPI/I2C buses

Wiring Details

Start with the section Pico to Pico Wiring in this article to set up using two Picos together, one as a Picoprobe (flash/debug) and the other as your embedded target.

Once properly wired, it should look similar to the following:

IMG_3747

IMG_3746

Pico to ESP32 WiFi

The following table lists the pin name and pin number to properly wire between a Pico board and an ESP32 WiFi. This can be done on a breadboard such as the one listed above. Note that V+/- rail means the +/- columns on the breadboard for use as +5 VDC and GND respectively.

Pico ESP32 WiFi Adafuit Airlift Breadboard
GND (Pin 3) GND (Pin 3) V- rail
GP2 (Pin 4) GPIO0 (Pin 4) GP0 (Pin 10)
GP7 (Pin 10) ESP_CSn (Pin 10) CS (Pin 7)
GP8 (Pin 11)
GP9 (Pin 12)
GP10 (Pin 14) ACK (Pin 14) Busy (Pin 8)
GP11 (Pin 15) RESETn (Pin 15) RSTn (Pin 9)
GP12 (Pin 16) SW_A (Pin 16) N/A
GND (Pin 18) V- rail
VBUS (Pin 40) VBUS (Pin 40)
VSYS (Pin 39) VSYS (Pin 39) VIN (Pin 1) V+ rail
GND (Pin 38) GND (Pin 38) V- rail
3V3(OUT) (Pin 36) 3V3 (Pin 36) 3Vo (Pin 2)
GP19 (Pin 25) MOSI (Pin 25) MOSI (Pin 5)
GP18 (Pin 24) SCLK (Pin 24) SCK (Pin 4)
GND (Pin 23) V- rail
GP16 (Pin 21) MISO (Pin 21) MISO (Pin 5)

BME280 to Pico

BME280 Pico Breadboard
GND V- rail
3.3V 3V3(OUT) (Pin 36)
SDA I2C1 SDA (Pin 31)
SCL I2C1 SCL (Pin 32)

Software Requirements

  • The standard Rust tooling (cargo, rustup) which you can install from https://rustup.rs/

  • Toolchain support for the cortex-m0+ processors in the rp2040 (thumbv6m-none-eabi)

  • flip-link - this allows you to detect stack-overflows on the first core, which is the only supported target for now.

Installation of development dependencies

rustup target install thumbv6m-none-eabi
cargo install flip-link
cargo install probe-run

Set Up Git Hooks

The esp32-pico-wifi repository makes use of several Git hooks to ensure that code quality standards are met and consistent. To automatically configure these hooks for your local workspace, you can run the following:

./scripts/create-git-hooks

This will create symlinks to the Git hooks, preserving any hooks that you may have already configured.

Running

For a debug build

cargo run

For a release build

cargo run --release

To see debug output on the serial console on macOS:

minicom -D /dev/tty.usbmodem14201 -b 115200

or on Linux:

minicom -D /dev/ttyUSB0 -b 115200

Note that you'll most likely need to find the current /dev link assigned to the Pico UART for your particular machine.

Debugging with VSCode

Note: these instructions originate from the rp-hal project's rp2040_project_template README

To start a probe-rs debug session:

Step 1 - Download probe-rs-debugger VSCode plugin 0.4.0

Step 2 - Install probe-rs-debugger VSCode plugin

$ code --install-extension probe-rs-debugger-0.4.0.vsix

Step 3 - Install probe-rs-debugger

$ cargo install --git https://github.com/probe-rs/probe-rs probe-rs-debugger

Step 4 - Open this project in VSCode

Step 5 - Launch a debug session by choosing Run>Start Debugging (or press F5)

License

This project is licensed under the BSD + Patent license.

Any submissions to this project (e.g. as Pull Requests) must be made available under these terms.

esp32-pico-wifi's People

Contributors

bortyr avatar calebbourg avatar jhodapp avatar serneum avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

esp32-pico-wifi's Issues

Can't connect to WiFi of certain SSIDs

The name of WiFi's SSID will have an impact whenever the connection will be successful or not.
I performed a set of tests with different kinds of names just to see what what works and not:

OK - WiFi connection successful, LED is green and a POST request is sent to Ambi correctly
FAILED - WiFi connection failed, LED is red

# SSID
TP-Link_4AD4 - FAILED
borys2g - OK
1234567 - FAILED
1 - FAILED
a - FAILED
aaaaa - FAILED
aaaaa2g - OK
aaaaaa - OK
aaaaaaa - OK
aaaaaaaa - FAILED
aaaa_2g - OK
aaaaa_2g - FAILED

# PASSWORD
75884345 - OK

Notes from this:

  • It seems to be a recurring pattern that string with over 7 chars will fail (but so did 1 char "1" or "a")
  • The "aaaa_2g" showed that "_" character went through correctly
  • Password being 8 chars long wasn't an issue

Add ability to send an HTTP POST request to Ambi backend endpoint

Summary

To wrap up our ESP32 WiFi proof-of-concept, the final piece is to add the ability to make an HTTP POST request with a JSON payload to an Ambi backend instance.

Feature specifics

Add a function to send an HTTP POST request to Ambi backend endpoint:

  1. Function should take the following parameters and send off a POST request to host
    • Client socket
    • Host IP address
    • HTTP port of host
    • HTTP request path (the Ambi API endpoint path minus host IP/port)
  2. It should send a JSON payload as part of the HTTP body
  3. It should handle basic server responses (HTTP 200 + 201 success status codes + 400 errors) by outputting error debug statements on the serial console
    • Note: the Ambi backend may not yes implement success response 201 after successfully responding to a POST request

Note: don't worry about implementing DNS lookups and using full on hostnames. For the PoC, we can just focus on using straight IP addresses.

Example ambi_mock_client output

Sending POST request to http://localhost:4000/api/readings/add as JSON: 
{"temperature":"16.7","humidity":"43.1","pressure":"1086","dust_concentration":"13","air_purity":"Dangerous Pollution"}
Response: Ok(
    Response {
        url: Url {
            scheme: "http",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "localhost",
                ),
            ),
            port: Some(
                4000,
            ),
            path: "/api/readings/add",
            query: None,
            fragment: None,
        },
        status: 200,
        headers: {
            "cache-control": "max-age=0, private, must-revalidate",
            "content-length": "60",
            "content-type": "application/json; charset=utf-8",
            "date": "Wed, 23 Feb 2022 17:50:37 GMT",
            "server": "Cowboy",
            "x-request-id": "FtZ7n0Eot7jp2Q0AAV8n",
        },
    },
)

Tests

At this time, don't worry about writing unit/integration tests unless it will aid you in completing this work. We'll more intentionally focus on test writing in our next phase when we work to implement a mature ESP32 WiFi Rust crate.

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.