From 0807c15de4f4cbb5dee8805d57f12a195d618849 Mon Sep 17 00:00:00 2001 From: Felix Wittwer Date: Sun, 7 Aug 2022 21:29:03 +0200 Subject: [PATCH] Implement weather API call --- .gitignore | 1 + Cargo.lock | 790 +++++++++++++++++++++++++++++++++- Cargo.toml | 3 + README.md | 2 + src/weather/data.rs | 112 +++-- src/weather/mod.rs | 97 +++-- src/weather/secret.rs.example | 2 + 7 files changed, 935 insertions(+), 72 deletions(-) create mode 100644 src/weather/secret.rs.example diff --git a/.gitignore b/.gitignore index 6d2cde5..6b7088e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +secret.rs /target # /Cargo.lock diff --git a/Cargo.lock b/Cargo.lock index b9013c1..f579180 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" + [[package]] name = "bytemuck" version = "1.11.0" @@ -104,6 +110,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + [[package]] name = "cast" version = "0.3.0" @@ -143,6 +155,22 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "cortex-m" version = "0.7.5" @@ -293,6 +321,24 @@ dependencies = [ "itertools", ] +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + [[package]] name = "float-cmp" version = "0.8.0" @@ -302,12 +348,91 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "futures-channel" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[package]] +name = "futures-io" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" + +[[package]] +name = "futures-sink" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" + +[[package]] +name = "futures-task" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" + +[[package]] +name = "futures-util" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "gif" version = "0.11.4" @@ -329,6 +454,25 @@ dependencies = [ "nix", ] +[[package]] +name = "h2" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hash32" version = "0.2.1" @@ -338,6 +482,12 @@ dependencies = [ "byteorder", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "heapless" version = "0.7.15" @@ -360,6 +510,77 @@ dependencies = [ "libc", ] +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "i2cdev" version = "0.5.1" @@ -372,6 +593,17 @@ dependencies = [ "nix", ] +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "image" version = "0.23.14" @@ -391,6 +623,16 @@ dependencies = [ "tiff", ] +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg 1.1.0", + "hashbrown", +] + [[package]] name = "inky-ticker" version = "0.1.0" @@ -400,12 +642,22 @@ dependencies = [ "embedded-plots", "linux-embedded-hal", "profont", + "reqwest", "serde", "serde_json", "ssd1675", "tinybmp", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "ioctl-rs" version = "0.1.6" @@ -415,6 +667,12 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" + [[package]] name = "itertools" version = "0.9.0" @@ -439,6 +697,15 @@ dependencies = [ "rayon", ] +[[package]] +name = "js-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -447,9 +714,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" [[package]] name = "libm" @@ -485,6 +752,21 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + [[package]] name = "memchr" version = "2.3.4" @@ -506,6 +788,12 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc4010833aea396656c2f91ee704d51a6f1329ec2ab56ffd00bfd56f7481ea94" +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + [[package]] name = "miniz_oxide" version = "0.3.7" @@ -525,6 +813,36 @@ dependencies = [ "autocfg 1.1.0", ] +[[package]] +name = "mio" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nb" version = "0.1.3" @@ -631,6 +949,75 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +[[package]] +name = "openssl" +version = "0.10.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +dependencies = [ + "autocfg 1.1.0", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + [[package]] name = "png" version = "0.16.8" @@ -809,6 +1196,15 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.4.6" @@ -826,6 +1222,52 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "riscv" version = "0.7.0" @@ -871,6 +1313,16 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + [[package]] name = "scoped_threadpool" version = "0.1.9" @@ -907,6 +1359,29 @@ dependencies = [ "libc", ] +[[package]] +name = "security-framework" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -959,6 +1434,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "serial-core" version = "0.4.0" @@ -980,6 +1467,25 @@ dependencies = [ "termios", ] +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg 1.1.0", +] + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spidev" version = "0.5.1" @@ -1036,6 +1542,20 @@ dependencies = [ "nix", ] +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if 1.0.0", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "termios" version = "0.2.2" @@ -1066,18 +1586,140 @@ dependencies = [ "nom", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +dependencies = [ + "autocfg 1.1.0", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "once_cell", + "pin-project-lite", + "socket2", + "winapi", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + [[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[package]] +name = "unicode-normalization" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + [[package]] name = "vcell" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -1099,6 +1741,98 @@ dependencies = [ "vcell", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" + +[[package]] +name = "web-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "weezl" version = "0.1.7" @@ -1126,3 +1860,55 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml index 8a19611..8d96dab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,9 @@ ssd1675 = { git = "https://github.com/Feliix42/ssd1675" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +# for retrieving weather data from the API +reqwest = { version = "0.11", features = ["blocking", "json"] } + linux-embedded-hal = { version = "0.3.2", optional = true } embedded-graphics-simulator = { version = "0.3.0", optional = true } diff --git a/README.md b/README.md index 3d5d346..955d98b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ I selected this particular data provider because it has a One-Call API which yie The use of the API is free so long as one stays below 1,000 requests/day (as of the time writing this). You'll need your own API key to use this project. +Copy the file `src/weather/secret.rs.example` to `src/weather/secret.rs` and replace the placeholder API key inside with yours. + ## Hardware Required diff --git a/src/weather/data.rs b/src/weather/data.rs index 10b89fd..170a0d8 100644 --- a/src/weather/data.rs +++ b/src/weather/data.rs @@ -5,9 +5,9 @@ //! [here](https://openweathermap.org/api/one-call-3#parameter). #![allow(dead_code)] +use embedded_plots::curve::PlotPoint; use serde::Deserialize; - /// Response from the OpenWeather API with both current and forecast data for a given location. #[derive(Deserialize)] pub struct WeatherData { @@ -31,27 +31,61 @@ pub struct WeatherData { daily: Vec<()>, /// Currently active wheather alerts #[serde(default)] - alerts: Vec + alerts: Vec, +} + +impl WeatherData { + pub fn current_temp(&self) -> f32 { + self.current.data.temp + } + + pub fn perceived_temp(&self) -> f32 { + self.current.data.feels_like + } + + pub fn rain_probability(&self) -> u8 { + (self.hourly[0].pop * 100_f32).round() as u8 + } + + pub fn humidity(&self) -> u8 { + self.current.data.humidity + } + + pub fn uv_idx(&self) -> u8 { + self.current.data.uvi.round() as u8 + } + + pub fn forecast_plot_data(&self) -> Vec { + let data: Vec = self.hourly.iter().take(24).map(|h| h.data.temp).collect(); + + data.into_iter() + .enumerate() + .map(|(x, y)| PlotPoint { + x: x as i32, + y: y.round() as i32, + }) + .collect() + } } /// Current weather data. #[derive(Deserialize)] pub struct CurrentWeather { #[serde(flatten)] - data: CommonWeatherInfo, + pub(self) data: CommonWeatherInfo, /// Sunrise time (Unix Timestamp, UTC) - sunrise: u64, + pub(self) sunrise: u64, /// Sunset time (Unix Timestamp, UTC) - sunset: u64, + pub(self) sunset: u64, } /// Weather Forecast for a specific hour in the future. #[derive(Deserialize)] pub struct HourlyWeather { #[serde(flatten)] - data: CommonWeatherInfo, + pub(self) data: CommonWeatherInfo, /// Probability of precipitation (values range from 0 to 1). - pop: f32 + pub(self) pop: f32, } /// Common weather information shared among different forecast types. @@ -60,67 +94,71 @@ pub struct HourlyWeather { #[derive(Deserialize)] pub struct CommonWeatherInfo { /// Current time (Unix Timestamp, UTC) - dt: u64, + pub(self) dt: u64, /// Current temperature - temp: f32, + pub(self) temp: f32, /// Temperature according to human perception - feels_like: f32, + pub(self) feels_like: f32, /// Atmospheric Pressure at sea level (hPa) - pressure: u32, + pub(self) pressure: u32, /// Air Humidity in % - humidity: u8, + pub(self) humidity: u8, /// Dew Point (temperature below which water droplets begin to form) - dew_point: f32, + pub(self) dew_point: f32, /// Cloudiness in % - clouds: u8, + pub(self) clouds: u8, /// Current UV Index - uvi: f32, + pub(self) uvi: f32, /// Average Visibility in metres (max: 10.000m) - visibility: u16, + pub(self) visibility: u16, /// Wind Speed - wind_speed: f32, + pub(self) wind_speed: f32, /// Wind Gust (optional) - wind_gust: f32, + pub(self) wind_gust: Option, /// Wind direction in degrees - wind_deg: u16, + pub(self) wind_deg: u16, /// Rain - rain: Option, + pub(self) rain: Option, /// Snow - snow: Option, + pub(self) snow: Option, /// Weather - weather: Vec, + pub(self) weather: Vec, } #[derive(Deserialize)] pub struct WeatherAlert { /// Name of the alert source. - sender_name: String, + pub(self) sender_name: String, /// Name of the Event - event: String, + pub(self) event: String, /// Date and time of the start of the alert (Unix Timestamp, UTC) - start: u64, + pub(self) start: u64, /// Date and time of the end of the alert (Unix Timestamp, UTC) - end: u64, + pub(self) end: u64, /// Description of the alert (localized). - description: String, + pub(self) description: String, /// Type(s) of severe weather. - tags: Vec, + pub(self) tags: Vec, } #[derive(Deserialize)] pub struct Precipitation { /// Precipitation volume in the last hour in mm #[serde(rename = "1h")] - hour: u16, + pub(self) hour: u16, } #[derive(Deserialize)] pub struct WeatherDetails { + /// Identifier of the current weather condition, mapped to an enum for better matching #[serde(rename = "id")] - condition: WeatherCondition, - main: String, - description: String, - icon: String + pub(self) condition: WeatherCondition, + /// Main weather event + pub(self) main: String, + /// Description of the current weather + pub(self) description: String, + /// OpenWeather Icon associated to the current weather + pub(self) icon: String, } /// Weather Condition @@ -154,10 +192,10 @@ pub enum WeatherCondition { impl From for WeatherCondition { fn from(value: u16) -> Self { match value { - 200 ..= 299 => Self::Thunderstorm, - 300 ..= 399 => Self::Drizzle, - 500 ..= 599 => Self::Rain, - 600 ..= 699 => Self::Snow, + 200..=299 => Self::Thunderstorm, + 300..=399 => Self::Drizzle, + 500..=599 => Self::Rain, + 600..=699 => Self::Snow, 701 => Self::Mist, 711 => Self::Smoke, 721 => Self::Haze, diff --git a/src/weather/mod.rs b/src/weather/mod.rs index f89d37a..ac1c447 100644 --- a/src/weather/mod.rs +++ b/src/weather/mod.rs @@ -1,25 +1,36 @@ use embedded_graphics::{ - draw_target::DrawTarget, image::Image, mono_font::MonoTextStyle, prelude::*, text::Text, -}; -use embedded_plots::{ - axis::Scale, - curve::{Curve, PlotPoint}, - single_plot::SinglePlot, + draw_target::DrawTarget, + image::Image, + mono_font::MonoTextStyle, + prelude::*, + text::{Alignment, Baseline, Text}, }; +use embedded_plots::{axis::Scale, curve::Curve, single_plot::SinglePlot}; use profont::{ PROFONT_12_POINT, PROFONT_14_POINT, PROFONT_24_POINT, PROFONT_7_POINT, PROFONT_9_POINT, }; use ssd1675::Color; +use std::error::Error; use std::fmt::Debug; use tinybmp::Bmp; +mod api; mod data; +mod secret; pub fn get_weather(display: &mut D) where D: DrawTarget, D::Error: Debug, { + let weather_data = match api::get_weather_data() { + Ok(d) => d, + Err(e) => { + display_no_data(display, e); + return; + } + }; + // draw image let bmp_data = include_bytes!("../../rain2.bmp"); let bmp = Bmp::::from_slice(bmp_data).unwrap(); @@ -28,15 +39,15 @@ where .expect("Failed to draw image"); Text::new( - &format!("{:.1}°C", -28.1), + &format!("{:.1}°C", weather_data.current_temp()), Point::new(75, 28), - MonoTextStyle::new(&PROFONT_24_POINT, Color::Black), + MonoTextStyle::new(&PROFONT_24_POINT, Color::Red), ) .draw(display) .expect("error drawing text"); Text::new( - "gefühlt: 12°C", + &format!("gefühlt: {:.1}°C", weather_data.perceived_temp()), Point::new(75, 39), MonoTextStyle::new(&PROFONT_9_POINT, Color::Black), ) @@ -44,7 +55,7 @@ where .expect("error drawing text"); Text::new( - &format!("{:2.0}%", 32), + &format!("{:2.0}%", weather_data.rain_probability()), Point::new(10, 62), MonoTextStyle::new(&PROFONT_14_POINT, Color::Black), ) @@ -60,7 +71,7 @@ where .expect("error drawing text"); Text::new( - &format!("{:2.0}%", 2.0), + &format!("{:2.0}%", weather_data.humidity()), Point::new(10, 81), MonoTextStyle::new(&PROFONT_14_POINT, Color::Black), ) @@ -75,12 +86,15 @@ where .draw(display) .expect("error drawing text"); - // TODO(feliix42): Color based on the value. // https://de.wikipedia.org/wiki/UV-Index + let uvi = weather_data.uv_idx(); Text::new( - &format!("{:2.0}", 3), + &format!("{:2.0}", uvi), Point::new(20, 100), - MonoTextStyle::new(&PROFONT_14_POINT, Color::Black), + MonoTextStyle::new( + &PROFONT_14_POINT, + if uvi < 6 { Color::Black } else { Color::Red }, + ), ) .draw(display) .expect("error drawing text"); @@ -93,26 +107,43 @@ where .draw(display) .expect("error drawing text"); - // TODO(feliix42): use test data to draw a forecast using - // https://crates.io/crates/embedded-plots - let data: [f32; 24] = [ - 19.65, 19.32, 18.95, 18.55, 17.84, 16.44, 15.25, 14.29, 14.43, 15.07, 16.34, 18.06, 19.8, - 21.39, 22.81, 23.8, 24.4, 24.78, 24.76, 24.43, 23.74, 21.67, 18.88, 17.43, - ]; - - let data_points: Vec = data - .into_iter() - .enumerate() - .map(|(x, y)| PlotPoint { - x: x as i32, - y: y.round() as i32, - }) - .collect(); + // Plot the forecast + // TODO(feliix42): Annotate the plot better?? + let data_points = weather_data.forecast_plot_data(); let curve = Curve::from_data(&data_points); - let plot = SinglePlot::new(&curve, Scale::RangeFraction(4), Scale::RangeFraction(3)) - .into_drawable(Point::new(100, 54), Point::new(206, 94)) - .set_color(Color::Black); + let plot = SinglePlot::new(&curve, Scale::RangeFraction(4), Scale::RangeFraction(2)) + .into_drawable(Point::new(100, 54), Point::new(206, 94)) + .set_color(Color::Black); - plot.draw(display).expect("Failed to draw the temperature plot"); + plot.draw(display) + .expect("Failed to draw the temperature plot"); +} + +fn display_no_data(display: &mut D, err: E) +where + D: DrawTarget, + D::Error: Debug, + E: Error, +{ + Text::with_alignment( + "KEINE DATEN", + Point::new(106, 28), + MonoTextStyle::new(&PROFONT_24_POINT, Color::Red), + Alignment::Center, + ) + .draw(display) + .expect("error drawing text"); + + eprintln!("[error] Failed to get/parse JSON:\n{}", err); + + // TODO(feliix42): As soon as there is a custom text renderer for full texts, use it here! + Text::with_baseline( + &err.to_string(), + Point::new(5, 32), + MonoTextStyle::new(&PROFONT_12_POINT, Color::Black), + Baseline::Top, + ) + .draw(display) + .expect("error drawing text"); } diff --git a/src/weather/secret.rs.example b/src/weather/secret.rs.example new file mode 100644 index 0000000..5fb59ba --- /dev/null +++ b/src/weather/secret.rs.example @@ -0,0 +1,2 @@ +/// Your API token for the OpenWeather API. +pub static API_TOKEN: &'static str = "1234";