{"id":13343836,"url":"https://github.com/lucasdietrich/zephyr-caniot-controller","last_synced_at":"2025-03-12T06:30:33.650Z","repository":{"id":44340610,"uuid":"420730771","full_name":"lucasdietrich/zephyr-caniot-controller","owner":"lucasdietrich","description":"Personal gateway/controller for CAN/BLE devices supporting CANIOT custom application protocol. Based on nucleo_f429zi and Zephyr RTOS.","archived":false,"fork":false,"pushed_at":"2024-11-18T20:29:04.000Z","size":2843,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-18T21:39:16.250Z","etag":null,"topics":["aws","bluetooth","can-bus","ethernet","nucleo-f429zi","qemu","zephyr-rtos"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucasdietrich.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-24T16:06:01.000Z","updated_at":"2024-11-18T20:29:08.000Z","dependencies_parsed_at":"2024-08-13T20:15:08.892Z","dependency_job_id":"f7995393-a552-45b2-9276-5af3be46d3be","html_url":"https://github.com/lucasdietrich/zephyr-caniot-controller","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasdietrich%2Fzephyr-caniot-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasdietrich%2Fzephyr-caniot-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasdietrich%2Fzephyr-caniot-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasdietrich%2Fzephyr-caniot-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasdietrich","download_url":"https://codeload.github.com/lucasdietrich/zephyr-caniot-controller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243171384,"owners_count":20247876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","bluetooth","can-bus","ethernet","nucleo-f429zi","qemu","zephyr-rtos"],"created_at":"2024-07-29T19:32:01.493Z","updated_at":"2025-03-12T06:30:33.632Z","avatar_url":"https://github.com/lucasdietrich.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Home Automation Controller for CAN/BLE devices - with ZephyrRTOS and stm32f4\n\n## Introduction\n\nThis **personnal** project is an attempt to create a home automation controller \nfor CAN/BLE devices I have at home.\n\n**This project is not longer maintained**, I'm only making periodic updates to keep \nit up to date with Zephyr RTOS, but this is more a training task (to not get rusty) \nthan actual maintenance. Particularily, I recently found *memory* issues when \nhandling devices events.\n\nComments, questions, suggestions are welcome.\n\nCurrently supporting **ZephyrRTOS v4.0.0** with following targets:\n- `nucleo_f429zi`\n- `mps2_an385`\n- `qemu_x86`\n\nI also aim to build a custom board dedicated to this project.\n\n## Synoptic\n\nGoal is to have a controller able to handle several IoT protocols like CAN, \nBLE (or Thread), Ethernet protocols, etc.. Goal is to gather all the data from\nthe different devices and send them to a cloud platform (AWS IoT Core for now) or\nto a local server (REST, prometheus ..) for monitoring and/or control \n(like heating, lights, alarm etc..).\n\n![docs/pics/caniot-controller-synoptic-components.png](./docs/pics/caniot-controller-synoptic-components.png)\n\n## AWS - Grafana Dashboard\n\n![docs/pics/aws_grafana_3.png](./docs/pics/aws_grafana_3.png)\n\n## Expected console output\n\n```\n*** Booting Zephyr OS build zephyr-v3.0.0  ***\nI: Starting bootloader\nI: Primary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x1\nI: Scratch: magic=bad, swap_type=0x1, copy_done=0x2, image_ok=0x2\nI: Boot source: primary slot\nI: Swap type: none\nI: Bootloader chainload address offset: 0x20000\nI: Jumping to the first image slot\n[00:00:00.011,000] \u003cdbg\u003e disk: disk_access_register: disk interface(SD) registered\n*** Booting Zephyr OS build v3.7.0-1-gbdddc83484ad ***\nStarting Zephyr application...\n[00:00:00.011,000] \u003cinf\u003e dfu: MCUBOOT version=1 IMAGE size=0x72a00 version=0.0.0+0 confirmed=1\n[00:00:00.011,000] \u003cwrn\u003e dfu: Development image (version=0.0.0+0)\n[00:00:00.031,000] \u003cinf\u003e sd: Maximum SD clock is under 25MHz, using clock of 24000000Hz\n[00:00:00.036,000] \u003cinf\u003e app_fs: FS mounted /SD:\n[00:00:00.037,000] \u003cinf\u003e creds_manager: Found 11 credentials in FLASH\n[00:00:00.037,000] \u003cdbg\u003e netif: net_interface_init: [1] mac: 00:80:E1:77:77:77 iface: 0x20003910 up: 1\n[00:00:00.037,000] \u003cdbg\u003e netif: net_interface_init: [2] mac: 00:00:5E:00:53:00 iface: 0x20003a30 up: 1\n[00:00:00.330,000] \u003cinf\u003e bt_hci_core: Identity: F2:DF:DA:8E:AB:50 (random)\n[00:00:00.330,000] \u003cinf\u003e bt_hci_core: HCI: version 5.4 (0x0d) revision 0x0000, manufacturer 0x05f1\n[00:00:00.330,000] \u003cinf\u003e bt_hci_core: LMP: version 5.4 (0x0d) subver 0xffff\n[00:00:00.330,000] \u003cinf\u003e ble: Bluetooth initialized 0\n[00:00:01.511,000] \u003cdbg\u003e netif: net_event_handler: [face: 0x20003910] event: NET_EVENT_IF_UP (d0010002)\n[00:00:01.511,000] \u003cdbg\u003e netif: net_event_handler: [face: 0x20003910] event: NET_EVENT_IPV4_DHCP_START (e0040007)\n[00:00:01.513,000] \u003cdbg\u003e netif: net_event_handler: [face: 0x20003910] event: \u003cunknown net event\u003e (f1140007)\n[00:00:01.517,000] \u003cinf\u003e net_dhcpv4: Received: 192.168.10.226\n[00:00:01.517,000] \u003cdbg\u003e netif: net_event_handler: [face: 0x20003910] event: NET_EVENT_IPV4_ADDR_ADD (e0040001)\n[00:00:01.517,000] \u003cinf\u003e netif: === NET interface 0x20003910 ===\n[00:00:01.517,000] \u003cinf\u003e netif: Address: 192.168.10.226 [addr type NET_ADDR_DHCP]\n[00:00:01.517,000] \u003cinf\u003e netif: Subnet:  255.255.255.0\n[00:00:01.517,000] \u003cinf\u003e netif: Router:  192.168.10.1\n[00:00:01.517,000] \u003cinf\u003e netif: DHCPv4 Lease time: 43000 seconds [state: bound]\n[00:00:01.517,000] \u003cdbg\u003e netif: net_event_handler: [face: 0x20003910] event: NET_EVENT_IPV4_DHCP_BOUND (e0040008)\n[00:00:01.631,000] \u003cinf\u003e net_time: SNTP time from fr.pool.ntp.org:123 = 1723568041, 1 thread(s) signaled\n[00:00:01.634,000] \u003cinf\u003e cloud: State changed: STATE_INIT (0) -\u003e STATE_RESOLVE_HOST (1)\n[00:00:01.635,000] \u003cinf\u003e cloud_utils: Resolved a31gokdeokxhl8-ats.iot.eu-west-1.amazonaws.com -\u003e 52.16.249.75\n[00:00:01.635,000] \u003cinf\u003e cloud: State changed: STATE_RESOLVE_HOST (1) -\u003e STATE_CONNECTING (3)\n[00:00:03.265,000] \u003cinf\u003e net_mqtt: Connect completed\n[00:00:03.366,000] \u003cinf\u003e cloud: State changed: STATE_CONNECTING (3) -\u003e STATE_CONNECTED (4)\n[00:00:05.209,000] \u003cinf\u003e ble_obv: [XIAOMI] mac: A4:C1:38:3C:D3:21 rssi: -71 bat: 2466 mV temp: 27 °C hum: 61 %\nLocal (Europe/Paris) Date and time : 2024/08/13 16:54:05\n[00:00:09.431,000] \u003cinf\u003e caniot: [ 60d ] 01 C1-D0 Telemetry Response ep : ep-c ff ff 07 2b fe ff\n[00:00:09.436,000] \u003cinf\u003e caniot: [ 64d ] 09 C1-D1 Telemetry Response ep : ep-c ff ff 07 2b fe ff\n[00:00:09.446,000] \u003cinf\u003e caniot: [ 68d ] 17 C1-D2 Telemetry Response ep : ep-c ff ff 07 2b fe ff\n[00:00:09.451,000] \u003cinf\u003e caniot: [ 6cd ] 25 C1-D3 Telemetry Response ep : ep-c ff ff 07 2b fe ff\n[00:00:09.461,000] \u003cinf\u003e caniot: [ 70d ] 33 C1-D4 Telemetry Response ep : ep-c ff ff 07 26 fe ff\n[00:00:09.511,000] \u003cinf\u003e caniot: [ 74d ] 41 C1-D5 Telemetry Response ep : ep-c ff ff 07 2b fe ff\n[00:00:10.205,000] \u003cinf\u003e ble_obv: [XIAOMI] mac: A4:C1:38:3C:D3:21 rssi: -74 bat: 2468 mV temp: 27 °C hum: 61 %\n[00:00:12.700,000] \u003cinf\u003e ble_obv: [XIAOMI] mac: A4:C1:38:3C:D3:21 rssi: -74 bat: 2468 mV temp: 27 °C hum: 61 %\n[00:00:17.698,000] \u003cinf\u003e ble_obv: [XIAOMI] mac: A4:C1:38:3C:D3:21 rssi: -63 bat: 2467 mV temp: 27 °C hum: 61 %\n```\n\n## Documentation\n\nDocumentation is available in the `docs` folder for following topics:\n\n- [Bluetooth (HCI host/controller)](./docs/bluetooth-hci.md)\n- [HTTP server (REST, Prometheus, file server, webserver)](./docs/http-server.md)\n  - [Swagger API for the REST server](./docs/swagger-local-api.yaml)\n- [Credentials (AWS IoT, HTTPS server, etc.)](./docs/credentials.md)\n- [UDP Discovery Server](./docs/discovery-server.md)\n- [User IO (LEDs, buttons, etc.)](./docs/userio.md)\n- [Cloud AWS](./docs/cloud-aws.md)\n- [Home Automation (HA) - Devices and events model](./docs/devices.md)\n- [USB CDC ACM / ECM (networking)](./docs/usb.md)\n- [Controller Schematic/PCB wiring draft](./docs/board.md)\n- [Configuration](./docs/configuration.md)\n- [CANIOT](./docs/caniot.md)\n- Enabling/disabling features\n  - CAN configuration (CANIOT)\n  - BLE configuration\n  - AWS client\n  - LUA\n  - ...\n\n## Getting started\n\n### Prerequisites\n\nIn order to build this project you need the Zephyr RTOS toolchain. Please refer \nto the [Zephyr RTOS Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html).\n\nI advice to use a Linux machine for this project, Zephyr SDK should now be\navailable for Windows but I didn't try it yet. I personally use a Fedora 36\nvirtual machine.\n\nThis project is entirely compliant with the Zephyr RTOS tooling like `west`, \nthe `Zephyr SDK`, `Zephyr net-tools` (`twister` in the future).\n\n### Get the project\n\nLet's suppose you are in your home directory : `cd ~`\n\nThe project contains a [west.yml](./west.yml) file, you can clone the project using `west`:\n\n    west init -m git@github.com:lucasdietrich/zephyr-caniot-controller.git zephyr-caniot-workspace\n    cd zephyr-caniot-workspace\n    west update\n\nFinally initialize application submodules (should be enhanced in the future):\n\n    cd zephyr-caniot-controller\n    git submodule update --init --recursive\n\nOnce you have created the workspace you should have the following file structure:\n\n```\n[lucas@fedora zephyr-caniot-workspace]$ tree -L 1\n.\n├── bootloader\n├── modules\n├── zephyr-caniot-controller\n├── tools\n└── zephyr\n```\n\nI also advice to create a python virtual environment in your workspace:\n\n    cd ~/zephyr-caniot-workspace\n    python3 -m venv .venv\n    source .venv/bin/activate\n\nThen install Zephyr RTOS and application requirements:\n    pip install -r zephyr/scripts/requirements.txt\n    pip install -r zephyr-caniot-controller/requirements.txt\n\n## Quick build steps for `nucleo_f429zi` for debug\n\n1. Flash debug version of mcuboot with `flash_bootloader`\n2. Prepare credentials (if not already done)\n- Generate HTTP key and certificate with `creds/https_server/gen_rsa_ca.sh`\n- Convert AWS device key and certificate with `creds/AWS/aws-to-der.sh`\n- Update `creds/creds.json` consequently\n3. Build the project with `west build -b nucleo_f429zi`\n4. Flash the project with `west flash --runner=openocd`\n\n## Configure the project\n\nOnce you have cloned the project, go to the application directory `cd zephyr-caniot-controller` :\n\nConfiguration is the result of several files:\n- Root [prj.conf](./prj.conf) file contains the configuration common to all boards:\nFollowing files contain the configuration specific to each board.\n  - [boards/nucleo_f429zi.conf](./boards/nucleo_f429zi.conf)\n  - [boards/mps2_an385.conf](./boards/mps2_an385.conf)\n  - [boards/qemu_x86.conf](./boards/qemu_x86.conf)\n- Finally [overlays/](./overlays/) contains specific configuration to enable features.\n\nIf you want to enable a feature, you need to add the corresponding overlay file \nto the `OVERLAY_CONFIG` cmake variable, as follows, for further details please refer \nto [this Makefile](./Makefile).\n\n    west build -b nucleo_f429zi -- -DOVERLAY_CONFIG=\"overlays/nucleo_f429zi_shell.conf\"\n\nYou may want to enable a specific feature, to do so, set `-DOVERLAY_CONFIG` \n\nIf you're using features that requires credentials (like HTTPS server of AWS IoT),\nplease refer to the [docs/credentials.md](./docs/credentials.md) documentation.\n\n### Configure for QEMU targets\n\nIf you want to build for QEMU targets, take a look to `CONFIG_QEMU_ICOUNT` and\nrelated configuration options.\n\n### Flash the bootloader\n\nYou will need to flash the MCUBoot bootloader to be able to run the application \non a real board. You can find the bootloader in the `bins` directory:\n- [bins/bootloader_debug.bin](./bins/bootloader_debug.bin)\n\nYou can flash it using `make flash_bootloader`, from the project root directory.\n\nCaution: The command erases the whole flash memory.\n\nNote: In case you want to sign and encrypt your own applications, you will need\nto build and flash a custom bootloader.\n\nMore details are available here: [docs/mcuboot.md](./docs/mcuboot.md).\n\n### Build the project\n\nTo build the project, make sure you have activated the Python virtual environment \nwith `source ../.venv/bin/activate`, then run the following command (for `nucleo_f429zi`):\n\n    west build -b nucleo_f429zi\n\nFor `mps2_an385`:\n\n    west build -b mps2_an385\n\nFor `qemu_x86`:\n\n    west build -b qemu_x86\n\nIf compilation is successful, you should get following output, for `nucleo_f429zi`:\n```\nMemory region         Used Size  Region Size  %age Used\n           FLASH:      502356 B         1 MB     47.91%\n            SRAM:      125878 B       192 KB     64.02%\n             CCM:         64 KB        64 KB    100.00%\n        IDT_LIST:          0 GB         2 KB      0.00%\n```    \n\nIn case of error, please refer to the troubleshooting section below.\n\n### Flash and run (Nucleo F429ZI)\n\nWith west simply flash with `west flash`\n\n### QEMU Networking\n\nIf you want to run the application on QEMU with networking, more configuration is required.\n- Clone `git clone zephyrproject-rtos/net-tools` in your zephyr workspace (`zedpyr-caniot-workspace`).\n- Build the tools with `cd net-tools \u0026\u0026 make`\n\nThe tools are now available to the scripts located in [scripts/](./scripts/)\n\n## `qemu_x86` target\n\n`qemu_x86` uses SLIP TAP networking.\n\nThe script [scripts/prepareqemunet.sh](./scripts/prepareqemunet.sh) prepare\nthe networking configuration for QEMU. But please refer to the official documentation\nfor further details : [Networking with QEMU](https://docs.zephyrproject.org/3.0.0/guides/networking/qemu_setup.html)\n\nSo open a terminal and launch the script (not as sudo):\n\n    ./scripts/prepareqemunet.sh\n\nYou should see the created `tap0` interface\n```\n[lucas@fedora zephyr-caniot-controller]$ ifconfig\ntap0: flags=4163\u003cUP,BROADCAST,RUNNING,MULTICAST\u003e  mtu 1500\n        inet 192.0.2.2  netmask 255.255.255.0  broadcast 0.0.0.0\n        inet6 2001:db8::2  prefixlen 64  scopeid 0x0\u003cglobal\u003e\n        inet6 fe80::c894:12ff:fefa:2cdf  prefixlen 64  scopeid 0x20\u003clink\u003e\n        ether ca:94:12:fa:2c:df  txqueuelen 1000  (Ethernet)\n        RX packets 159  bytes 15931 (15.5 KiB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 143  bytes 29149 (28.4 KiB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n```\n\nIn this guide we are using the TAP interface but there are other options available\nas described here [Networking with the host system](https://docs.zephyrproject.org/3.0.0/guides/networking/networking_with_host.html).\n\nThen you can run the application (built for `qemu_x86`) :\n\n    west build -t run\n\nFinally if you want to expose your QEMU HTTP server, you may\nconfigure and run the script [scripts/forward_webserver_ports.sh](./scripts/forward_webserver_ports.sh) :\n\n    ./scripts/forward_webserver_ports.sh\n\n## `mps2_an385` target\n\n`mps2_an385` supports both `slip` and real `lan9220` hardware.\n- If using `lan9220` hardware, run the script `sudo ../net-tools/net-setup.sh` (`sudo`) to start the interface.\n- If using `slip` interface, as for `qemu_x86`, run `./scripts/prepareqemunet.sh`\n\nThen run your application with `west build -t run`\n    west build -t run\n\n\n\n## Debug (VS Code)\n\nDebug can be launch on QEMU targets using `ninja debugserver -C build` command\n\n### Nucleo F429ZI\n\nDebug of the nucleo_f429zi board is done using the ST-Link V2 debugger with OpenOCD.\n\nUse one of the the configurations `Launch cortex-debug nucleo_429zi` and `Attach cortex-debug nucleo_429zi` \navailable in the [launch.json](./.vscode/launch.json) file.\n\nIf OpenOCD configuration doesn't work try the configuration `BACKUP cortex-debug STutil`, but \nI discourage using it and you will need to install ST-Link utilities.\n\n- Select the configuration\n- Then press `F5`\n\n![./docspics/caniot-controller-nucleo-f429zi-debug.png](./docs/pics/caniot-controller-nucleo-f429zi-debug.png)\n\n### mps2_an385\nDebug of the mps2_an385 board is done using the gdbserver provided by QEMU.\n\n- Run `ninja debugserver -C build` \n- Then use configuration `(gdb) mps2_an385`.\n- Then press `F5`\n\n### QEMU x86\nDebug of the qemu_x86 board is done using the gdbserver provided by QEMU.\n\n- Run `ninja debugserver -C build` \n- Then use configuration `(gdb) qemu_x86`.\n- Then press `F5`\n![./docs/pics/caniot-controller-qemux86-debug.png](./docs/pics/caniot-controller-qemux86-debug.png)\n\n### QEMU ARM (TODO)\n\nWith `EXPERIMENTAL (gdb) QEMU ARM` and `LEGACY (gdb) QEMU ARM`\n\n**TODO**\n\n### Agnostic (deprecated)\n\nYou can launch debug on any target using the `ninja debugserver -C build` command\nwith `BACKUP (gdb) Agnostic` configuration. But I advice to use the configuration\nspecific to the target.\n\n### Wireshark (QEMU)\n\nTo see network traffic generated by the application in QEMU, use one of the following commands:\n\n- If you are on a windows host, with your QEMU instance running on a Linux guest, \nrun the following command in a git bash terminal:\n\nInterface to monitor is `zeth` (with `lan9220` for example):\n\n    ssh lucas@fedora sudo tcpdump -U -s0 'not port 22' -i zeth -w - | \"C:\\Program Files\\Wireshark\\Wireshark.exe\" -k -i -\n\nInterface to monitor is `tap0` :\n\n    ssh lucas@fedora sudo tcpdump -U -s0 'not port 22' -i tap0 -w - | \"C:\\Program Files\\Wireshark\\Wireshark.exe\" -k -i -\n\nIf you are on a Linux host, with your QEMU instance running on a Linux guest, use the following command :\n\n    ssh lucas@fedora sudo tcpdump -U -s0 'not port 22' -i tap0 -w - | wireshark -k -i -\n\nIf your wireshark and QEMU are on the same machine (`zeth` instead of `tap0` if not using slip):\n\n    sudo tcpdump -U -s0 'not port 22' -i tap0 -w - | wireshark -k -i -\n\n## Features\n\nProgress if not percentage :\n- `P` for planned\n- `E` for evaluated (soon to be implemented)\n- `T` for testing\n- `D` for done\n- `A` for abandoned\n\nPriority: grade from 1 to 10.\n\n| Module           | Feature                                 | Progress | Priority | Issues |\n| ---------------- | --------------------------------------- | -------- | -------- | ------ |\n| HTTP Server      |                                         |          |          |        |\n|                  | Concurrent connections                  | D        |          |        |\n|                  | Keep-alive support                      | D        |          |        |\n|                  | Static files                            | 15%      |          |        |\n|                  | HTTPS                                   | D        |          |        |\n|                  | HTTPS Client Authentication             | 0%       |          |        |\n|                  | Chunked encoding (request)              | D        |          |        |\n|                  | Chunked encoding (response)             | D        |          |        |\n|                  | Webserver                               | 0%       | 5        |        |\n|                  | REST server                             | D        |          |        |\n|                  | Prometheus metrics client               | D        |          |        |\n|                  | File download                           | 50%      |          |        |\n|                  | Multipart parser (for files)            | 0%       | 5        |        |\n| BLE              |                                         |          |          |        |\n|                  | HCI Interface                           | E        |          |        |\n|                  | GATT Server (phone application)         | P        | 10       |        |\n|                  | GATT Client                             | P        |          |        |\n|                  | Xiaomi data collector                   | E        |          |        |\n| CAN              |                                         |          |          |        |\n|                  | CAN Interface                           | D        |          |        |\n|                  | CANIOT (class0)                         | T        |          |        |\n|                  | CANIOT (class1)                         | 25%      | 10       |        |\n|                  | CANIOT (telemetry)                      | T        | 10       |        |\n|                  | CANIOT (command)                        | 0%       | 10       |        |\n| LUA              |                                         | A        |          |        |\n|                  | Lua interpreter                         | DA       |          |        |\n|                  | Lua orchestrator                        | 10% A    |          |        |\n|                  | OS Module for LUA                       | 0% A     |          |        |\n|                  | Devices module for LUA                  | 0% A     |          |        |\n|                  | REST API                                | 25% A    |          |        |\n| HA               |                                         | P        |          |        |\n| CLOUD            |                                         |          |          |        |\n|                  | AWS IoT (publish)                       | T        |          |        |\n|                  | AWS IoT (remote control)                | 0% P     |          |        |\n|                  | AWS Iot (remote config - device shadow) | 0%       |          |        |\n| FS               |                                         |          |          |\n|                  | SD SPI FAT32                            | D        |          |        |\n|                  | SD MCC FAT32                            | 0% P     |          |        |\n|                  | SD card FAT32 formatting                | 0% P     |          |        |\n|                  | NVS FLASH                               | D        |          |        |\n| Discovery server |                                         |          |          |        |\n|                  | UDP Discovery server                    | 80% P    |          |        |\n| User IO          |                                         |          |          |        |\n|                  | LEDs                                    | E        |          |        |\n|                  | Buttons                                 | E        |          |        |\n| Stats            |                                         |          |          |        |\n|                  | Heap memory usage                       | P        |          |        |\n|                  | Mbedtls memory usage                    | P        |          |        |\n|                  | HA stats                                | P        |          |        |\n|                  | CAN stats                               | P        |          |        |\n|                  | NET stats                               | P        |          |        |\n|                  | BLE stats                               | P        |          |        |\n| Thread/matter    |                                         | P        |          |        |\n\n\n## Footprint\n\nCurrent footprint `nucleo_f429zi` build (debug):\n```\nMemory region         Used Size  Region Size  %age Used\n           FLASH:      498428 B         1 MB     47.53%\n            SRAM:      119286 B       192 KB     60.67%\n             CCM:         64 KB        64 KB    100.00%\n        IDT_LIST:          0 GB         2 KB      0.00%\n```\n\n## Demo\n\n HTTP upload of a LUA script to SD card then execute.\n```\nsomecalc1.lua\n1661031779\n0.505708\n[00:01:32.512,000] \u003cinf\u003e http_server: (4) Connection accepted from 192.168.10.216:54476, cli sock = 7\n[00:01:32.514,000] \u003cinf\u003e files_server: Filepath: /SD:/lua/somecalc1.lua\n[00:01:32.527,000] \u003cinf\u003e files_server: File /SD:/lua/somecalc1.lua upload succeeded [size = 389]\n[00:01:32.528,000] \u003cinf\u003e http_server: (7) Req /files [payload 389 B] returned B resp status 200 [payload 16 B] (keep-alive=0)\n[00:01:32.544,000] \u003cinf\u003e http_server: (7) Connection closed by peer\n[00:01:32.544,000] \u003cinf\u003e http_server: (7) Closing sock conn 0x20003e54\n[00:01:32.545,000] \u003cinf\u003e http_server: (4) Connection accepted from 192.168.10.216:54486, cli sock = 7\n[00:01:32.557,000] \u003cdbg\u003e lua: lua_orch_script_handler: (0x20010bb4) Executing script ...\n[00:01:32.595,000] \u003cdbg\u003e lua: lua_orch_script_handler: (0x20010bb4) Script returned res=0...\n[00:01:32.595,000] \u003cinf\u003e lua: (0x20010bb4) Script returned 0 (LUA_OK)\n[00:01:32.596,000] \u003cinf\u003e http_server: (7) Req /lua/execute [payload 0 B] returned B resp status 200 [payload 45 B] (keep-alive=0)\n[00:01:32.598,000] \u003cinf\u003e http_server: (7) Connection closed by peer\n[00:01:32.598,000] \u003cinf\u003e http_server: (7) Closing sock conn 0x20003e98\n```\n\n## clang-format\n\n- Install clang-format, and run `make format` to format all files\n- Or install `xaver.clang-format` extension for VS Code, and format on save or\nformat using `Ctrl + K, Ctrl + F`\n\n\n## Known issues\n\n- MAJOR: SD FAT FS internal state gets corrupted when doing many requests in a short time.\n- minor: Fix `-Waddress-of-packed-member` during `xiaomi_dataframe_t` handling\n- CANIOT send command with small timeout (100ms) always fails\n  - ISR seems to be called very late\n  - Set `CONFIG_CAN_LOG_LEVEL_DBG=y` \n- FS Access  (upload/download) -\u003e do a stress test\n\n## TODO\n\n### Immediate\n- Reduce MBEDTLS memory usage by 1/3\n- Remove dependencies on CANIOT_LIB, CANIOT_CONTROLLER, HA, so that the code\ncan be compiled without them.\n- Add general diagnostic messages\n- Look at zephyr Settings Subsystem and this sample: samples/subsys/settings/src/main.c\n- **Fix use of lan9220 ethernet driver with mps2_an385**\n- Investigate crash for emulated devices in QEMU:\n```\nASSERTION FAIL [atomic_get(\u0026ev-\u003eref_count) == (atomic_val_t)0] @ WEST_TOPDIR/zephyr-caniot-controller/src/ha/devices.c:867\n[00:07:59.400,000] \u003cerr\u003e ha_dev: k_fifo_alloc_put() error -12\n[00:07:59.400,000] \u003cerr\u003e ha_dev: Failed to notify event 0x20093868 to 0x20093988, err=-12\n```\n\n### Long term\n\n- Move several buffers to CCM to keep space in SRAM for Newlib heap (for LUA)\n- ~~Allow to embed LUA script when building for `nucleo_f429zi`~~\n- Cannot uses 2 sockets chrome with keepalive\n- Use [docs/ram_report.txt](./docs/ram_report.txt) to optimize memory usage\n  - DNS buffers\n- Bit of C++ ?\n- HTTP:\n  - Make requests processing completely assynchronous (with concurrent requests)\n    - Using workqueue to process requests ?\n  - Allow to stream response -\u003e helps to decrease http buffer size\n- ~~Draft LUA scripts orchestrator~~\n- REST: list files in filesystem\n- HTTP: allow to download files from the filesystem\n- Allow to store few scripts in the SoC ROM\n- Test keepalive feature\n- Allow authentication using \"username:password\" and x509 certificates\n- Find a way to be able to print numbers from LUA with CONFIG_NEWLIB_LIBC_NANO enabled (for ARM)\n- Find a way to redirect stdout and stderr to a file or to logging system\n  - Check `zephyr/lib/libc/newlib/libc-hooks.c`\n- `CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE` seems to have no effect\n- Create a totally agnostic API for devices, allowing to add many kind of MAC \naddr abstraction layers.\n\n## Troubleshooting\n- For an unkown reason yet, make sure to have docker disabled when using QEMU with networking. To disable it run:\n\n    sudo systemctl disable --now docker.service\n    sudo reboot\n\n## Ressources:\n- [Zephyr Documentation - West Manifests](https://docs.zephyrproject.org/3.0.0/guides/west/manifest.html)\n- TODO Add all the ressources !","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasdietrich%2Fzephyr-caniot-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasdietrich%2Fzephyr-caniot-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasdietrich%2Fzephyr-caniot-controller/lists"}