commit ad7c3bb80c8af9a6779be073373dc6c081fe9e0f Author: Sebastian Wendel Date: Tue Sep 10 01:39:52 2024 +0200 latest changes diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c710523 --- /dev/null +++ b/.envrc @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +# https://github.com/direnv/direnv/wiki + +use flake + +watch_file ./nix/shell.nix + +eval "$shellHook" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8decebc --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.direnv +.pre-commit-config.yaml +.esphome +secrets.yaml \ No newline at end of file diff --git a/.reuse/dep5 b/.reuse/dep5 new file mode 100644 index 0000000..bb3233c --- /dev/null +++ b/.reuse/dep5 @@ -0,0 +1,21 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: mushlab-iot +Upstream-Contact: Sebastian Wendel +Source: https://code.curious.bio/curious.bio/mushlab-iot + +Files: hardware/* +Copyright: (C) 2023 Sebastian Wendel +License: CERN-OHL-S-2.0 + +Files: + .gitea + .vscode + .editorconfig + .envrc + .gitignore + flake.* + nix/* + software/* +Copyright: (C) 2023 Sebastian Wendel +License: GPL-3.0-or-later + diff --git a/README.md b/README.md new file mode 100644 index 0000000..c11d99a --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# ESP-BMC + +## Links + +- https://github.com/jeelabs/esp-link +- https://github.com/esphome/aioesphomeapi +- https://openwrt.org/docs/guide-user/hardware/esp8266-serial-bridge \ No newline at end of file diff --git a/esphome.yaml b/esphome.yaml new file mode 100644 index 0000000..b6c897f --- /dev/null +++ b/esphome.yaml @@ -0,0 +1,86 @@ +esphome: + name: esp-bmc + +esp32: + board: nodemcu-32s + +time: + - platform: sntp + timezone: Europe/Berlin + +logger: + level: VERBOSE + +web_server: + port: 80 + version: 3 + local: true + +api: + password: !secret api_password + +ota: + - platform: esphome + password: !secret ota_password + +wifi: + ssid: !secret wifi_ssid + password: !secret wifi_password + ap: + ssid: !secret ap_ssid + password: !secret ap_password + +# ethernet: +# type: W5500 +# clk_pin: GPIOXX +# mosi_pin: GPIOXX +# miso_pin: GPIOXX +# cs_pin: GPIOXX +# interrupt_pin: GPIOXX +# reset_pin: GPIOXX +# manual_ip: +# static_ip: 10.0.0.42 +# gateway: 10.0.0.1 +# subnet: 255.255.255.0 + +uart: + - id: uart_1 + tx_pin: 1 + rx_pin: 2 + baud_rate: 115200 + debug: + direction: BOTH + after: + delimiter: "\n" + # dummy_receiver: false + # sequence: + # - lambda: UARTDebug::log_string(direction, bytes); + +select: + - id: change_baud_rate + name: Baud rate + platform: template + options: + - "2400" + - "9600" + - "38400" + - "57600" + - "115200" + - "256000" + - "512000" + - "921600" + initial_option: "115200" + optimistic: true + restore_value: True + internal: false + entity_category: config + icon: mdi:swap-horizontal + set_action: + - lambda: |- + id(uart_1).flush(); + uint32_t new_baud_rate = stoi(x); + ESP_LOGD("change_baud_rate", "Changing baud rate from %i to %i",id(uart_1).get_baud_rate(), new_baud_rate); + if (id(uart_1).get_baud_rate() != new_baud_rate) { + id(uart_1).set_baud_rate(new_baud_rate); + id(uart_1).load_settings(); + } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cb82cfe --- /dev/null +++ b/flake.lock @@ -0,0 +1,155 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725634671, + "narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1725513492, + "narHash": "sha256-tyMUA6NgJSvvQuzB7A1Sf8+0XCHyfSPRx/b00o6K0uo=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "7570de7b9b504cfe92025dd1be797bf546f66528", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ac541d8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = "esp-bmc"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + }; + + outputs = { + nixpkgs, + flake-utils, + ... + } @ inputs: + flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: { + devShells.default = import ./nix/shell.nix inputs system; + checks = import ./nix/checks.nix inputs system; + + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + config.allowAliases = true; + }; + }); +} diff --git a/nix/checks.nix b/nix/checks.nix new file mode 100644 index 0000000..25b701a --- /dev/null +++ b/nix/checks.nix @@ -0,0 +1,16 @@ +{ + self, + pre-commit-hooks, + ... +}: system: +with self.pkgs.${system}; { + pre-commit-check = + pre-commit-hooks.lib.${system}.run + { + src = lib.cleanSource ../.; + hooks = { + alejandra.enable = true; + }; + settings = {}; + }; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..693dc20 --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,22 @@ +{self, ...}: system: +with self.pkgs.${system}; + mkShell { + name = "esp-bmc"; + + nativeBuildInputs = [ + alejandra + esphome + git + mosquitto + nil + nixVersions.git + pre-commit + reuse + yaml-language-server + yamllint + ]; + + shellHook = '' + ${self.checks.${system}.pre-commit-check.shellHook} + ''; + }