{"id":23261305,"url":"https://github.com/mossmaurice/cosyfir","last_synced_at":"2025-04-06T05:44:52.039Z","repository":{"id":90923871,"uuid":"266346039","full_name":"mossmaurice/cosyfir","owner":"mossmaurice","description":"Control system for irrigation based on LoRa and TTN","archived":false,"fork":false,"pushed_at":"2020-07-24T20:40:31.000Z","size":179,"stargazers_count":2,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T11:27:23.400Z","etag":null,"topics":["gardening","iot","irrigation","lora","lorawan","stm32","thethingsnetwork","ttn","watering"],"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/mossmaurice.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-23T13:50:14.000Z","updated_at":"2024-10-29T06:47:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"24daf380-8c1f-4e69-b942-c2ead05b8eb9","html_url":"https://github.com/mossmaurice/cosyfir","commit_stats":{"total_commits":96,"total_committers":1,"mean_commits":96.0,"dds":0.0,"last_synced_commit":"32a42fe8c17fef61be94fa2b270648abe0072c6c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mossmaurice%2Fcosyfir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mossmaurice%2Fcosyfir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mossmaurice%2Fcosyfir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mossmaurice%2Fcosyfir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mossmaurice","download_url":"https://codeload.github.com/mossmaurice/cosyfir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441005,"owners_count":20939235,"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":["gardening","iot","irrigation","lora","lorawan","stm32","thethingsnetwork","ttn","watering"],"created_at":"2024-12-19T13:31:31.473Z","updated_at":"2025-04-06T05:44:52.019Z","avatar_url":"https://github.com/mossmaurice.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![cosyfir logo](/doc/cosyfir-logo-small.jpg) **CO**ntrol **SY**stem **F**or **IR**rigation\n\n\u003e **_Disclaimer:_** This is a personal project and not affiliated with my employer\n\nCosyfir shall help you watering your plants.\n\nThe node software runs on an STM32 ARM Cortex microcontroller. The server software runs on UNIX-based systems like Debian. The following picture depicts an example setup:\n\n     []         \\ /       +--+         \\  /        \\o/\n     []  \u003c-\u003e     |   \u003c-\u003e  |  |  \u003c-\u003e   ( )( )  \u003c-\u003e   |\n     \\/  LoRa    |        +--+  MQTT   (  )   SSH  / \\\n\n    Sensor    LoRaWAN     TTN          RPi        User\n     Node     Gateway    Server       @home\n\n    ./node/* (Not part of cosyfir)  ./server/*\n\nThis readme describes both the server (e.g. Raspberry Pi) and the sensor node software in the following sections.\n\n## Server\n\nThe cosyfird application is a daemon, which receives messages from sensor nodes via TTN server and displays the last\nmessage.\n\n### Required hard- and software\n\n* Computer running UNIX-like OS e.g. Raspberry Pi with Raspbian\n\nInstall the following software packages e.g. for Debian do:\n\n    sudo apt install libncurses6 libmosquittopp1 libssl1.1 libyaml-cpp0.6 gcc cmake libjsoncpp1 libb64-0d\n\nC++17 compiler is required. GCC 8.3.0 is recommended.\n\n## Sensor node\n\nThis section describes the sensor node software which communicates based on [LoRa](https://en.wikipedia.org/wiki/LoRa) and [TTN](https://www.thethingsnetwork.org/).\n\n### Required hard- and software\n\n* [LSN50 v1.2](http://www.dragino.com/products/lora-lorawan-end-node/item/128-lsn50.html) from Dragino (I bought it [here](https://www.exp-tech.de/plattformen/internet-of-things-iot/8377/dragino-lsn50-868-12-waterproof-long-range-wireless-lora-sensor-node))\n  * STM32L072CZT6\n  * SX1276\n  * Battery\n  * IP66 case\n* DS18B20 temperature sensor\n* Watermark soil moistore sensor (Model 200SS) (I bought it [here](https://www.mmm-tech.de/de/watermark/wms))\n* FTDI UART cable\n* UNIX machine\n  * [stm32flash](https://sourceforge.net/p/stm32flash/wiki/Home/) version  \u003e=0.5\n\n[LSN50-V2](http://www.dragino.com/products/lora-lorawan-end-node/item/155-lsn50-v2.html) should most likely work as well.\n\nInstall the following packages:\n\n    sudo apt install stm32flash arm-none-eabi-gcc\n\n## Build and setup\n\nBefore building the binaries, register your cosyfir application on the TTN website.\n\n### Setup cosyfird and cosyfir-node with TTN\n\nThe following is a YAML configuration file template for cosyfird:\n\n```yaml\nMqttConfig:\n    HostAddress: region.thethings.network\n    Port: 8883\n    ClientId: application-id\n    Password: secret\n```\n\nTTN uses port `8883` with SSL and the host address `region.thethings.network` where `region` can be e.g. `eu`.\n\nFirst of all, create a client identifier on the TTN site by clicking \"Add application\" on your personal\n[network console](https://console.thethingsnetwork.org/). The application access key can be found at the bottom after\nyou have created an application. It acts as the password for the MQTT connection.\n\nHere's an overview of the LoRa terminology:\n\n| LoRa              | Explanation                           | From where?                          | Where to put?                   |\n| ------------------|---------------------------------------|--------------------------------------|:-------------------------------:|\n| DevEUI            | 64-bit end-device identifier (unique) | On device box                        | TTN console (\"Register device\") |\n| AppEUI or JoinEUI | 64-bit application identifier         | Issued by TTN (\"Add application\")    | Commissioning.h                 |\n| NwkKey or AppKey  | Data encryption key (TTN \u003c-\u003e server)  | Generated by TTN (\"Add application\") | Commissioning.h                 |\n| DevAddr           | 32-bit address (non-unique)           | Assigned when node joins TTN         | -                               |\n\nThe activation method will always be over-the-air-activation (OTAA). The file is preconfigured to run in Europe.\n\nFill the preprocessor defines into `node/Commissioning_template.h` as described in the table. Then rename the file:\n\n    mv node/common/Commissioning_template.h node/common/Commissioning.h\n\n### Start the build\n\nRun the build script in root to build both server and node binary.\n\n    ./build_all.sh\n\nAvailable parameters to the script are:\n\n* `clean`: Perform a clean build\n* `debug`: Build with debug symbols\n\n### How to flash the sensor node\n\nFlashing LSN50 can be done with a simple FTDI UART cable using the ISP boot mode.\n\nConnect the UART as described below:\n\n    GND (black):  JP4 Pin11 GND\n    TXD (orange): JP3 Pin9  PA3 (USART1)\n    RXD (yellow): JP3 Pin10 PA2 (USART1)\n\nFind out where your USB serial device is mounted:\n\n    journalctl -k -n 100\n\nSet the switch from FLASH mode to ISP mode and then do:\n\n    sudo stm32flash -w node/build/sensor-node.hex /dev/ttyUSBx\n\n## Get cosyfir running\n\nConnect the sensors:\n\n    # DS18B20\n    GND (blue):   JP3 Pin2 GND\n    DQ  (yellow): JP3 Pin4 PA9 (Half-duplex single-wire using only TX)\n    VDD (red):    JP3 Pin1 VDD\n\n    # Watermark 200SS (tbd)\n    JP3 Pin12 PA0\n    JP3 Pin5  PA4\n    # 10k resistor between PA4 and PA1\n\n[More information](https://www.irrometer.com/200ss.html) about the Watermark sensor.\n\nCheck your local [TTN coverage](https://ttnmapper.org/) and make sure a gateway is nearby. Start\n`./cosyfird --config-file /path/to/cosyfird.yaml` and power on the LSN50 with the boot switch set to FLASH.\nAfter a few moments you should see messages arrive. In debug mode, messages are sent every 30 seconds.\nIn release mode every half an hour.\n\nExample message payload in hex:\n\n    | 42 | BE | EF | CA | FE |\n      ^\n      Battery level\n           ^\n           Temperature (resolution 0.0625 °C)\n                     ^\n                     Soil water tension\n                     (tbd)\n\n## Development\n\nFor development the following packages might be necessary:\n\n    sudo apt install clang-format libmosquittopp-dev libssl-dev libyaml-cpp-dev libjsoncpp-dev libb64-dev libncurses-dev\n\n### Debugging with STM32\n\nGet an ST-LINK V2 debugger and install these packages:\n\n    sudo apt install stmlink-tools gdb-multiarch\n\nThree applications are available after installation:\n\n* **st-flash**, for flashing binaries\n* **st-info**, get infos about the microcontroller\n* **st-utils**, attach GDB to the microcontroller\n\nConnect as described below:\n\n    GND:   JP4 Pin11 GND\n    SWCLK: JP4 Pin4  PA14\n    SWDIO: JP4 Pin9  PA13\n    RST:   JP4 Pin1  NRST\n\nSet the boot switch to ISP and try:\n\n    st-info --probe\n\nIf everything is running correctly, you should see the serial and other infos about the microcontroller.\nIn case you don't see the infos, try swapping SWDIO and SWCLK. Some ST-LINK V2 debugger are wrongly labeled.\n\nYou can flash and debug your code with:\n\n    st-util -p 1234\n    (gdb-multiarch) set arch arm\n    (gdb-multiarch) target extended-remote localhost:1234\n    (gdb-multiarch) load sensor-node\n\nTo be able to jump back to user code, set the boot switch back to FLASH. Then you can set breakpoints and run the code\nas usual:\n\n    (gdb-multiarch) break foo.c:42\n    (gdb-multiarch) run\n\nJust loading the symbols without flashing is possible:\n\n    (gdb-multiarch) file sensor-node\n\nTo do a warm restart, jump to the start of the flash:\n\n    (gdb-multiarch) jump *0x08000000\n\nTo be able to see the printf's connect an FTDI on the same PINs as for flashing via bootloader/ISP boot mode and run:\n\n    screen /dev/ttyUSB3 38400\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmossmaurice%2Fcosyfir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmossmaurice%2Fcosyfir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmossmaurice%2Fcosyfir/lists"}