Initial Commit

This commit is contained in:
Iain (Bill) Wiseman 2025-04-16 12:17:28 +12:00
parent 36980750ab
commit b1eeeaeea2
8 changed files with 403 additions and 234 deletions

View File

@ -1,16 +1,20 @@
[target.xtensa-esp32-none-elf] [target.xtensa-esp32-none-elf]
runner = "espflash flash --monitor" runner = "espflash flash --monitor"
[env] [env]
ESP_LOG="info" ESP_LOG="info"
ESP_WIFI_CONFIG_RX_QUEUE_SIZE = "16"
ESP_WIFI_CONFIG_STATIC_RX_BUF_NUM = "32"
ESP_WIFI_CONFIG_DYNAMIC_RX_BUF_NUM = "16"
[build] [build]
rustflags = [ rustflags = [
"-C", "link-arg=-nostartfiles", "-C", "link-arg=-nostartfiles"
] ]
target = "xtensa-esp32-none-elf" target = "xtensa-esp32-none-elf"
[unstable] [unstable]
build-std = ["core"] build-std = ["core", "alloc"]

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ target/
# MSVC Windows builds of rustc generate these, which store debugging information # MSVC Windows builds of rustc generate these, which store debugging information
*.pdb *.pdb
.env*

324
Cargo.lock generated
View File

@ -14,12 +14,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]] [[package]]
name = "basic-toml" name = "basic-toml"
version = "0.1.10" version = "0.1.10"
@ -35,6 +29,12 @@ version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f798d2d157e547aa99aab0967df39edd0b70307312b6f8bd2848e6abe40896e0" checksum = "f798d2d157e547aa99aab0967df39edd0b70307312b6f8bd2848e6abe40896e0"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.9.0" version = "2.9.0"
@ -42,10 +42,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]] [[package]]
name = "byte-slice-cast" name = "blocking-network-stack"
version = "1.2.3" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/bjoernQ/blocking-network-stack.git?rev=b3ecefc222d8806edd221f266999ca339c52d34e#b3ecefc222d8806edd221f266999ca339c52d34e"
checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d" dependencies = [
"embedded-io",
"heapless",
"log",
"smoltcp",
]
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
@ -101,7 +106,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim", "strsim",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -112,7 +117,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -123,36 +128,7 @@ checksum = "b9b6483c2bbed26f97861cf57651d4f2b731964a28cd2257f934a4b452480d21"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
]
[[package]]
name = "display-interface"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ba2aab1ef3793e6f7804162debb5ac5edb93b3d650fbcc5aeb72fcd0e6c03a0"
[[package]]
name = "display-interface-i2c"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d964fa85bbbb5a6ecd06e58699407ac5dc3e3ad72dac0ab7e6b0d00a1cd262d"
dependencies = [
"display-interface",
"embedded-hal 1.0.0",
"embedded-hal-async",
]
[[package]]
name = "display-interface-spi"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f86b9ec30048b1955da2038fcc3c017f419ab21bb0001879d16c0a3749dc6b7a"
dependencies = [
"byte-slice-cast",
"display-interface",
"embedded-hal 1.0.0",
"embedded-hal-async",
] ]
[[package]] [[package]]
@ -187,6 +163,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067"
[[package]]
name = "embassy-net-driver"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524eb3c489760508f71360112bca70f6e53173e6fe48fc5f0efd0f5ab217751d"
[[package]] [[package]]
name = "embassy-sync" name = "embassy-sync"
version = "0.6.2" version = "0.6.2"
@ -235,29 +217,6 @@ dependencies = [
"nb 1.1.0", "nb 1.1.0",
] ]
[[package]]
name = "embedded-graphics"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0"
dependencies = [
"az",
"byteorder",
"embedded-graphics-core",
"float-cmp",
"micromath",
]
[[package]]
name = "embedded-graphics-core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044"
dependencies = [
"az",
"byteorder",
]
[[package]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "0.2.7" version = "0.2.7"
@ -332,7 +291,7 @@ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -353,7 +312,7 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -362,6 +321,19 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "esp-alloc"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "408c0d4c7f51efb256af18641047b0d83b58a485be9edf5a559da796abef0b63"
dependencies = [
"cfg-if",
"critical-section",
"document-features",
"enumset",
"linked_list_allocator",
]
[[package]] [[package]]
name = "esp-backtrace" name = "esp-backtrace"
version = "0.15.1" version = "0.15.1"
@ -380,7 +352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8aa1c8f9954c9506699cf1ca10a2adcc226ff10b6ae3cb9e875cf2c6a0b9a372" checksum = "8aa1c8f9954c9506699cf1ca10a2adcc226ff10b6ae3cb9e875cf2c6a0b9a372"
dependencies = [ dependencies = [
"quote", "quote",
"syn 2.0.100", "syn",
"termcolor", "termcolor",
] ]
@ -401,7 +373,7 @@ checksum = "a573175c540fd1d21a9cf07b0dee286b5a8f4cfde4b35da0f4f4657de7942c45"
dependencies = [ dependencies = [
"basic-toml", "basic-toml",
"bitfield", "bitfield",
"bitflags", "bitflags 2.9.0",
"bytemuck", "bytemuck",
"cfg-if", "cfg-if",
"chrono", "chrono",
@ -452,7 +424,7 @@ dependencies = [
"proc-macro-error2", "proc-macro-error2",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -490,6 +462,47 @@ dependencies = [
"riscv-rt-macros", "riscv-rt-macros",
] ]
[[package]]
name = "esp-wifi"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "321b112db6629693fae49644b1ba28e8b917b58829533e9cdd0400183af1877d"
dependencies = [
"cfg-if",
"critical-section",
"document-features",
"embassy-net-driver",
"embassy-sync",
"embedded-io",
"embedded-io-async",
"enumset",
"esp-alloc",
"esp-build",
"esp-config",
"esp-hal",
"esp-metadata",
"esp-wifi-sys",
"fugit",
"heapless",
"libm",
"num-derive",
"num-traits",
"portable-atomic",
"portable_atomic_enum",
"rand_core",
"smoltcp",
"xtensa-lx-rt",
]
[[package]]
name = "esp-wifi-sys"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6b5438361891c431970194a733415006fb3d00b6eb70b3dcb66fd58f04d9b39"
dependencies = [
"anyhow",
]
[[package]] [[package]]
name = "esp32" name = "esp32"
version = "0.35.0" version = "0.35.0"
@ -500,15 +513,6 @@ dependencies = [
"vcell", "vcell",
] ]
[[package]]
name = "float-cmp"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -582,6 +586,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
dependencies = [ dependencies = [
"hash32", "hash32",
"portable-atomic",
"stable_deref_trait", "stable_deref_trait",
] ]
@ -595,12 +600,16 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
name = "helloworld" name = "helloworld"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"embedded-graphics", "blocking-network-stack",
"embedded-io",
"esp-alloc",
"esp-backtrace", "esp-backtrace",
"esp-hal", "esp-hal",
"esp-println", "esp-println",
"esp-wifi",
"heapless",
"log", "log",
"ssd1306", "smoltcp",
] ]
[[package]] [[package]]
@ -635,9 +644,21 @@ dependencies = [
"indoc", "indoc",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]]
name = "libm"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
[[package]]
name = "linked_list_allocator"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286"
[[package]] [[package]]
name = "litrs" name = "litrs"
version = "0.4.1" version = "0.4.1"
@ -654,17 +675,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]] [[package]]
name = "maybe-async-cfg" name = "managed"
version = "0.2.4" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e083394889336bc66a4eaf1011ffbfa74893e910f902a9f271fa624c61e1b2" checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
dependencies = [
"proc-macro-error",
"proc-macro2",
"pulldown-cmark",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
@ -672,12 +686,6 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "micromath"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
[[package]] [[package]]
name = "minijinja" name = "minijinja"
version = "2.9.0" version = "2.9.0"
@ -702,6 +710,17 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
[[package]]
name = "num-derive"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.19" version = "0.2.19"
@ -735,6 +754,27 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "portable_atomic_enum"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d48f60c43e0120bb2bb48589a16d4bed2f4b911be41e299f2d0fc0e0e20885"
dependencies = [
"portable-atomic",
"portable_atomic_enum_macros",
]
[[package]]
name = "portable_atomic_enum_macros"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33fa6ec7f2047f572d49317cca19c87195de99c6e5b6ee492da701cfe02b053"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "3.3.0" version = "3.3.0"
@ -744,30 +784,6 @@ dependencies = [
"toml_edit", "toml_edit",
] ]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]] [[package]]
name = "proc-macro-error-attr2" name = "proc-macro-error-attr2"
version = "2.0.0" version = "2.0.0"
@ -787,7 +803,7 @@ dependencies = [
"proc-macro-error-attr2", "proc-macro-error-attr2",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -799,17 +815,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "pulldown-cmark"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
dependencies = [
"bitflags",
"memchr",
"unicase",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.40" version = "1.0.40"
@ -852,7 +857,7 @@ checksum = "f265be5d634272320a7de94cea15c22a3bfdd4eb42eb43edc528415f066a1f25"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -869,7 +874,7 @@ checksum = "30f19a85fe107b65031e0ba8ec60c34c2494069fe910d6c297f5e7cb5a6f76d0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -901,7 +906,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]
[[package]] [[package]]
@ -914,17 +919,17 @@ dependencies = [
] ]
[[package]] [[package]]
name = "ssd1306" name = "smoltcp"
version = "0.10.0" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ea6aac2d078bbc71d9b8ac3f657335311f3b6625e9a1a96ccc29f5abfa77c56" checksum = "dad095989c1533c1c266d9b1e8d70a1329dd3723c3edac6d03bbd67e7bf6f4bb"
dependencies = [ dependencies = [
"display-interface", "bitflags 1.3.2",
"display-interface-i2c", "byteorder",
"display-interface-spi", "cfg-if",
"embedded-graphics-core", "heapless",
"embedded-hal 1.0.0", "log",
"maybe-async-cfg", "managed",
] ]
[[package]] [[package]]
@ -958,18 +963,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustversion", "rustversion",
"syn 2.0.100", "syn",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
] ]
[[package]] [[package]]
@ -1032,12 +1026,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
[[package]]
name = "unicase"
version = "2.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.18" version = "1.0.18"
@ -1050,12 +1038,6 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]] [[package]]
name = "void" name = "void"
version = "1.0.2" version = "1.0.2"
@ -1190,5 +1172,5 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn",
] ]

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
embedded-graphics = "0.8.1" esp-alloc = "0.6.0"
esp-backtrace = { version = "0.15.1", features = [ esp-backtrace = { version = "0.15.1", features = [
"esp32", "esp32",
"exception-handler", "exception-handler",
@ -15,12 +15,13 @@ esp-backtrace = { version = "0.15.1", features = [
] } ] }
esp-hal = { version = "0.23.1", features = [ "esp32" ] } esp-hal = { version = "0.23.1", features = [ "esp32" ] }
esp-println = { version = "0.13.1", features = ["esp32", "log"] } esp-println = { version = "0.13.1", features = ["esp32", "log"] }
esp-wifi = { version = "0.12.0", features = ["esp32","wifi", "utils"] }
log = { version = "0.4.22" } log = { version = "0.4.22" }
ssd1306 = "0.10.0" smoltcp = { version = "0.12.0", features = ["proto-ipv4", "socket-tcp", "socket-icmp", "socket-udp", "medium-ethernet", "proto-dhcpv4", "socket-raw", "socket-dhcpv4"], default-features = false }
[profile.dev] heapless = { version = "0.8.0"}
# Rust debug is too slow.
# For debug builds always builds with some optimization blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack.git", rev = "b3ecefc222d8806edd221f266999ca339c52d34e" }
opt-level = "s" embedded-io = "0.6.1"
[profile.release] [profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread codegen-units = 1 # LLVM can perform better optimizations using a single thread
@ -29,4 +30,4 @@ debug-assertions = false
incremental = false incremental = false
lto = 'fat' lto = 'fat'
opt-level = 's' opt-level = 's'
overflow-checks = false overflow-checks = false

View File

@ -1,30 +1,40 @@
# LoRa HelloWorld Project # ESP32 Static IP Project
Welcome to the **LoRa HelloWorld** project! This is a simple project designed to demonstrate basic usage of the i2C interface using a ssd1306 display. The Lora model used was a Lora32 T3 v1.6.1 Welcome to the **ESP32 Static IP** project! This is a working example of how to configure a static IP using `non_std`.
## Features ## Features
- Prints "Hello, World!" on a ssd1306 display. - Connect to your static IP and serve an image.
- Tested on a Lora32 T3 v1.6.1.
## Requirements ## Requirements
- espup installed - [espup](https://github.com/esp-rs/espup) installed
- rust installed - [Rust](https://www.rust-lang.org/) installed
## Installation ## Installation
1. Clone the repository: 1. Clone the repository:
```bash ```bash
git clone https://github.com/bibble235/lora-helloworld.git git clone https://github.com/bibble235/esp32-static-ip.git
``` ```
2. Navigate to the project directory: 2. Navigate to the project directory:
```bash ```bash
cd lora-helloworld cd esp32-static-ip
```
3. Set the environment variables for your static IP and Wi-Fi credentials. Remember to escape special characters like `@` and `$`:
```bash
export SSID="MyWifi"
export PASSWORD="MyPassword"
export STATIC_IP="10.1.2.3"
export GATEWAY_IP="10.1.1.99"
``` ```
## Usage ## Usage
Run the application with the following command: Build and run the application with the following commands:
```bash ```bash
cargo build cargo build
cargo run cargo run
@ -32,14 +42,19 @@ cargo run
## License ## License
This project is licensed under the [License Name] - see the [LICENSE](LICENSE) file for details. This project is licensed under the [License Name]. See the [LICENSE](LICENSE) file for details.
## Demonstration ## Demonstration
![Screenshot of a Lora32 T3 v1.6.1 running this app.](./assets/images/Lora_ssd1306_hello.png)
Below is a screenshot of a Lora32 T3 v1.6.1 running this application:
![Screenshot of a Lora32 T3 v1.6.1 running this app.](./assets/images/esp32-static-ip.png)
## Contact ## Contact
For questions or feedback, please contact iwiseman@bibble.co.nz. For questions or feedback, please contact [iwiseman@bibble.co.nz](mailto:iwiseman@bibble.co.nz).
---
![Rust](https://img.shields.io/badge/Rust-Language-black?logo=rust&logoColor=white) ![Rust](https://img.shields.io/badge/Rust-Language-black?logo=rust&logoColor=white)
![ESP32](https://img.shields.io/badge/ESP32-Microcontroller-blue) ![ESP32](https://img.shields.io/badge/ESP32-Microcontroller-blue)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 599 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

View File

@ -1,49 +1,214 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate alloc;
use blocking_network_stack::Stack;
use embedded_io::*;
use embedded_graphics::{mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder}, pixelcolor::BinaryColor, prelude::Point, text::{Baseline, Text}, Drawable};
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal::{delay::Delay, i2c::master::{Config, I2c}, time::Duration, xtensa_lx_rt::entry}; use esp_hal::{
use ssd1306::{mode::DisplayConfig, prelude::DisplayRotation, size::DisplaySize128x64, I2CDisplayInterface, Ssd1306}; clock::CpuClock, delay::Delay, rng::Rng, time::{self, Duration}, timer::timg::TimerGroup, xtensa_lx_rt::entry
};
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new();
// let system = SystemControl::new(peripherals.SYSTEM); use esp_wifi::wifi::{utils::create_network_interface, AccessPointInfo, AuthMethod, ClientConfiguration, Configuration, WifiError, WifiStaDevice};
// let delay = Delay::new(); use smoltcp::iface::{SocketSet, SocketStorage};
esp_println::logger::init_logger_from_env(); fn parse_ip(ip: &str) -> [u8; 4] {
let mut result = [0u8; 4];
for (idx, octet) in ip.split(".").into_iter().enumerate() {
result[idx] = u8::from_str_radix(octet, 10).unwrap();
}
result
}
// Create a new peripheral object with the described wiring #[entry]
// and standard I2C clock speed fn main() -> ! {
let i2c = I2c::new(
peripherals.I2C0,
Config::default()
).unwrap().with_scl(peripherals.GPIO22).with_sda(peripherals.GPIO21);
let interface = I2CDisplayInterface::new(i2c); // Initialize the ESP-IDF logging system
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) esp_println::logger::init_logger(log::LevelFilter::Info);
.into_buffered_graphics_mode();
display.init().unwrap();
let text_style = MonoTextStyleBuilder::new() // Setup the cpu clock config and initialize
.font(&FONT_6X10) let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
.text_color(BinaryColor::On) let peripherals = esp_hal::init(config);
.build();
Text::with_baseline("Hello world!", Point::zero(), text_style, Baseline::Top) // Create a delay object
.draw(&mut display) let delay = Delay::new();
.unwrap();
Text::with_baseline("Hello Rust!", Point::new(0, 16), text_style, Baseline::Top) // You need to allocate here and you must use the same version as esp-wifi
.draw(&mut display) esp_alloc::heap_allocator!(72 * 1024);
.unwrap();
display.flush().unwrap(); // Initialize the timer group
loop { let timg0 = TimerGroup::new(peripherals.TIMG0);
log::info!("Hello world!");
delay.delay(Duration::millis(500)); // Initialize the random number generator
let mut rng = Rng::new(peripherals.RNG);
// Initialize the wifi controller
let esp_wifi_ctrl = esp_wifi::init(
timg0.timer0,
rng.clone(),
peripherals.RADIO_CLK,
)
.unwrap();
// Set credentials from environment variables
const SSID: &str = env!("SSID");
const PASSWORD: &str = env!("PASSWORD");
const GATEWAY_IP: &str = env!("GATEWAY_IP");
const STATIC_IP: &str = env!("STATIC_IP");
// Get the wifi Peripheral
let mut wifi = peripherals.WIFI;
// Initialize the iface and device and the controller
let (iface, device, mut controller) =
create_network_interface(&esp_wifi_ctrl, &mut wifi, WifiStaDevice).unwrap();
// Create the socket set which is like the c struct sockaddr
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let socket_set = SocketSet::new(&mut socket_set_entries[..]);
// Create the stack
let now = || time::now().duration_since_epoch().to_millis();
let mut wifi_stack = Stack::new(iface, device, socket_set, now, rng.random());
// Configure Authentication
let mut auth_method = AuthMethod::WPA2Personal;
if PASSWORD.is_empty() {
auth_method = AuthMethod::None;
}
// Configure the Wi-Fi client
let client_config = Configuration::Client(ClientConfiguration {
ssid: SSID.try_into().unwrap(),
password: PASSWORD.try_into().unwrap(),
auth_method,
..Default::default()
});
let res = controller.set_configuration(&client_config);
log::info!("Wi-Fi set_configuration returned {:?}", res);
controller.start().unwrap();
log::info!("Is wifi started: {:?}", controller.is_started());
log::info!("Starting Wifi Scan");
// Scan for APs
let res: Result<(heapless::Vec<AccessPointInfo, 10>, usize), WifiError> = controller.scan_n();
if let Ok((res, _count)) = res {
for ap in res {
log::info!("{:?}", ap);
}
}
log::info!("{:?}", controller.capabilities());
log::info!("Wi-Fi connect: {:?}", controller.connect());
// wait to get connected
log::info!("Waiting to get connected");
loop {
let res = controller.is_connected();
match res {
Ok(connected) => {
if connected {
break;
}
}
Err(err) => {
log::info!("{:?}", err);
loop {}
} }
} }
}
log::info!("{:?}", controller.is_connected());
log::info!("Setting static IP {}", STATIC_IP);
wifi_stack
.set_iface_configuration(&blocking_network_stack::ipv4::Configuration::Client(
blocking_network_stack::ipv4::ClientConfiguration::Fixed(
blocking_network_stack::ipv4::ClientSettings {
ip: blocking_network_stack::ipv4::Ipv4Addr::from(parse_ip(STATIC_IP)),
subnet: blocking_network_stack::ipv4::Subnet {
gateway: blocking_network_stack::ipv4::Ipv4Addr::from(parse_ip(GATEWAY_IP)),
mask: blocking_network_stack::ipv4::Mask(24),
},
dns: None,
secondary_dns: None,
},
),
))
.unwrap();
log::info!(
"Start busy loop on main. Point your browser to http://{}:8080/",
STATIC_IP
);
let mut rx_buffer = [0u8; 1536];
let mut tx_buffer = [0u8; 1536];
let mut socket = wifi_stack.get_socket(&mut rx_buffer, &mut tx_buffer);
socket.listen(8080).unwrap();
loop {
socket.work();
if !socket.is_open() {
socket.listen(8080).unwrap();
}
if socket.is_connected() {
log::info!("Connected");
let mut time_out = false;
let deadline = time::now() + Duration::secs(20);
let mut buffer = [0u8; 1024];
let mut pos = 0;
while let Ok(len) = socket.read(&mut buffer[pos..]) {
let to_print = unsafe { core::str::from_utf8_unchecked(&buffer[..(pos + len)]) };
if to_print.contains("\r\n\r\n") {
log::info!("{}", to_print);
break;
}
pos += len;
if time::now() > deadline {
log::info!("Timeout");
time_out = true;
break;
}
}
if !time_out {
socket.write_all(
b"HTTP/1.0 200 OK\r\n\r\n\
<html>\
<body>\
<h1>Hello Rust! Hello esp-wifi!</h1>\
<img src=\"https://rustacean.net/more-crabby-things/dancing-ferris.gif\"/>
</body>\
</html>\r\n\
"
).unwrap();
socket.flush().unwrap();
}
socket.close();
log::info!("Done");
}
let deadline = time::now() + Duration::secs(5);
while time::now() < deadline {
socket.work();
}
}
}