├── .gitattributes ├── .github └── workflows │ └── tg-send.yml ├── LICENSE ├── README.md ├── README_EN.md ├── doc ├── zambretti.png └── zambretti.xlsx ├── examples └── test │ └── test.ino ├── keywords.txt ├── library.properties └── src └── Forecaster.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/tg-send.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Telegram Message 3 | on: 4 | release: 5 | types: [published] 6 | jobs: 7 | build: 8 | name: Send Message 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: send telegram message on push 12 | uses: appleboy/telegram-action@master 13 | with: 14 | to: ${{ secrets.TELEGRAM_TO }} 15 | token: ${{ secrets.TELEGRAM_TOKEN }} 16 | disable_web_page_preview: true 17 | message: | 18 | ${{ github.event.repository.name }} v${{ github.event.release.tag_name }} 19 | ${{ github.event.release.body }} 20 | https://github.com/${{ github.repository }} 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 AlexGyver 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![latest](https://img.shields.io/github/v/release/GyverLibs/Forecaster.svg?color=brightgreen)](https://github.com/GyverLibs/Forecaster/releases/latest/download/Forecaster.zip) 2 | [![PIO](https://badges.registry.platformio.org/packages/gyverlibs/library/Forecaster.svg)](https://registry.platformio.org/libraries/gyverlibs/Forecaster) 3 | [![Foo](https://img.shields.io/badge/Website-AlexGyver.ru-blue.svg?style=flat-square)](https://alexgyver.ru/) 4 | [![Foo](https://img.shields.io/badge/%E2%82%BD%24%E2%82%AC%20%D0%9F%D0%BE%D0%B4%D0%B4%D0%B5%D1%80%D0%B6%D0%B0%D1%82%D1%8C-%D0%B0%D0%B2%D1%82%D0%BE%D1%80%D0%B0-orange.svg?style=flat-square)](https://alexgyver.ru/support_alex/) 5 | [![Foo](https://img.shields.io/badge/README-ENGLISH-blueviolet.svg?style=flat-square)](https://github-com.translate.goog/GyverLibs/Forecaster?_x_tr_sl=ru&_x_tr_tl=en) 6 | 7 | [![Foo](https://img.shields.io/badge/ПОДПИСАТЬСЯ-НА%20ОБНОВЛЕНИЯ-brightgreen.svg?style=social&logo=telegram&color=blue)](https://t.me/GyverLibs) 8 | 9 | # Forecaster 10 | Библиотека для определения прогноза погоды по давлению для Arduino 11 | - Определение краткосрочного прогноза погоды по алгоритму Замбретти 12 | - Принимает давление, температуру, высоту над ур. моря и месяц года 13 | - Определение тренда давления при помощи линеаризации 14 | 15 | ### Совместимость 16 | Совместима со всеми Arduino платформами (используются Arduino-функции) 17 | 18 | ## Содержание 19 | - [Установка](#install) 20 | - [Инициализация](#init) 21 | - [Использование](#usage) 22 | - [Пример](#example) 23 | - [Версии](#versions) 24 | - [Баги и обратная связь](#feedback) 25 | 26 | 27 | ## Установка 28 | - Библиотеку можно найти по названию **Forecaster** и установить через менеджер библиотек в: 29 | - Arduino IDE 30 | - Arduino IDE v2 31 | - PlatformIO 32 | - [Скачать библиотеку](https://github.com/GyverLibs/Forecaster/archive/refs/heads/main.zip) .zip архивом для ручной установки: 33 | - Распаковать и положить в *C:\Program Files (x86)\Arduino\libraries* (Windows x64) 34 | - Распаковать и положить в *C:\Program Files\Arduino\libraries* (Windows x32) 35 | - Распаковать и положить в *Документы/Arduino/libraries/* 36 | - (Arduino IDE) автоматическая установка из .zip: *Скетч/Подключить библиотеку/Добавить .ZIP библиотеку…* и указать скачанный архив 37 | - Читай более подробную инструкцию по установке библиотек [здесь](https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA) 38 | ### Обновление 39 | - Рекомендую всегда обновлять библиотеку: в новых версиях исправляются ошибки и баги, а также проводится оптимизация и добавляются новые фичи 40 | - Через менеджер библиотек IDE: найти библиотеку как при установке и нажать "Обновить" 41 | - Вручную: **удалить папку со старой версией**, а затем положить на её место новую. "Замену" делать нельзя: иногда в новых версиях удаляются файлы, которые останутся при замене и могут привести к ошибкам! 42 | 43 | 44 | 45 | ## Инициализация 46 | ```cpp 47 | Forecaster cond; 48 | ``` 49 | 50 | 51 | ## Использование 52 | ```cpp 53 | void setH(int h); // установить высоту над уровнем моря (в метрах) 54 | void addP(long P, float t); // добавить текущее давление в Па и температуру в С (КАЖДЫЕ 30 МИНУТ), здесь же происходит расчёт 55 | void addPmm(float P, float t); // добавить текущее давление в мм.рт.ст и температуру в С (КАЖДЫЕ 30 МИНУТ) 56 | void setMonth(uint8_t month); // установить месяц (1-12), 0 чтобы отключить сезонность 57 | float getCast(); // получить прогноз (0 хорошая погода... 10 ливень-шторм) 58 | int getTrend(); // получить изменение давления в Па за 3 часа 59 | ``` 60 | 61 | 62 | ## Пример 63 | ```cpp 64 | #include "Forecaster.h" 65 | Forecaster cond; 66 | 67 | void setup() { 68 | Serial.begin(9600); 69 | // установить высоту над уровнем моря (Москва 255м) 70 | cond.setH(255); 71 | 72 | // если есть RTC - можно установить месяц 1-12 73 | //cond.setMonth(5); 74 | } 75 | void loop() { 76 | // таймер на 30 минут 77 | static uint32_t tmr; 78 | if (millis() - tmr >= 30*60*1000ul) { 79 | tmr = millis(); 80 | // каждые 30 минут передаём текущее давление (Па) и температуру (С) с датчика 81 | cond.addP(99218, 25.2); 82 | 83 | // getCast() возвращает текущий прогноз от 0 до 10 84 | // 0 - хорошая погода, 10 и выше - шторм/ливень 85 | Serial.println(cond.getCast()); 86 | } 87 | } 88 | ``` 89 | 90 | 91 | ## Версии 92 | - v1.0 93 | - v1.1 - добавил вывод тренда давления за 3 часа 94 | - v1.2 - совместимость esp8266/32 95 | 96 | 97 | ## Баги и обратная связь 98 | При нахождении багов создавайте **Issue**, а лучше сразу пишите на почту [alex@alexgyver.ru](mailto:alex@alexgyver.ru) 99 | Библиотека открыта для доработки и ваших **Pull Request**'ов! 100 | 101 | 102 | При сообщении о багах или некорректной работе библиотеки нужно обязательно указывать: 103 | - Версия библиотеки 104 | - Какой используется МК 105 | - Версия SDK (для ESP) 106 | - Версия Arduino IDE 107 | - Корректно ли работают ли встроенные примеры, в которых используются функции и конструкции, приводящие к багу в вашем коде 108 | - Какой код загружался, какая работа от него ожидалась и как он работает в реальности 109 | - В идеале приложить минимальный код, в котором наблюдается баг. Не полотно из тысячи строк, а минимальный код 110 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | This is an automatic translation, may be incorrect in some places. See sources and examples! 2 | 3 | # Forecaster 4 | Library for determining the forecast for pressure on arduino 5 | - Definition of a short -term weather forecast for the Zambretti algorithm 6 | - Takes pressure, temperature, height above the ur.Seas and month of the year 7 | - Determination of the pressure trend using linarization 8 | 9 | ## compatibility 10 | Compatible with all arduino platforms (used arduino functions) 11 | 12 | ## Content 13 | - [installation] (# Install) 14 | - [initialization] (#init) 15 | - [use] (#usage) 16 | - [Example] (# Example) 17 | - [versions] (#varsions) 18 | - [bugs and feedback] (#fedback) 19 | 20 | 21 | ## Installation 22 | - The library can be found by the name ** Forecaster ** and installed through the library manager in: 23 | - Arduino ide 24 | - Arduino ide v2 25 | - Platformio 26 | - [download the library] (https://github.com/gyverlibs/Forecaster/archive/refs/heads/main.zip) .Zip archive for manual installation: 27 | - unpack and put in * C: \ Program Files (X86) \ Arduino \ Libraries * (Windows X64) 28 | - unpack and put in * C: \ Program Files \ Arduino \ Libraries * (Windows X32) 29 | - unpack and put in *documents/arduino/libraries/ * 30 | - (Arduino id) Automatic installation from. Zip: * sketch/connect the library/add .Zip library ... * and specify downloaded archive 31 | - Read more detailed instructions for installing libraries [here] (https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%BD%D0%BE%BE%BE%BED0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA) 32 | ### Update 33 | - I recommend always updating the library: errors and bugs are corrected in the new versions, as well as optimization and new features are added 34 | - through the IDE library manager: find the library how to install and click "update" 35 | - Manually: ** remove the folder with the old version **, and then put a new one in its place.“Replacement” cannot be done: sometimes in new versions, files that remain when replacing are deleted and can lead to errors! 36 | 37 | 38 | 39 | ## initialization 40 | `` `CPP 41 | Forecaster Cond; 42 | `` ` 43 | 44 | 45 | ## Usage 46 | `` `CPP 47 | VOID Seth (inth);// set a height above sea level (in meters) 48 | Void Addp (Long P, Float T);// Add the current pressure in PA and temperature in C (every 30 minutes), there is also a calculation 49 | Void Addpm (Float P, Float T);// Add the current pressure in mm hg and temperature in C (every 30 minutes) 50 | VOID SetMonth (Uint8_t Month);// install a month (1-12), 0 to turn off seasonality 51 | Float getcast ();// Get a forecast (0 Good weather ... 10 rain-storm) 52 | Inttrend ();// get a change in pressure in Pa in 3 hours 53 | `` ` 54 | 55 | 56 | ## Example 57 | `` `CPP 58 | #include "Forecaster.h" 59 | Forecaster Cond; 60 | 61 | VOID setup () { 62 | Serial.Begin (9600); 63 | // set a height above sea level (Moscow 255m) 64 | Cond.Seth (255); 65 | 66 | // if there is RTC - you can install a month 1-12 67 | //cond.setmonth (5); 68 | } 69 | VOID loop () { 70 | // timer for 30 minutes 71 | Static uint32_t tmr; 72 | if (millis () - tmr> = 30*60*1000ul) { 73 | TMR = Millis (); 74 | // every 30 minutes we transmit the current pressure (PA) and temperature (c) from the sensor 75 | Cond.Addp (99218, 25.2); 76 | 77 | // getcast () returns the current forecast from 0 to 10 78 | // 0 - good weather, 10 and above - storm/rain 79 | Serial.println (cond.getcast ()); 80 | } 81 | } 82 | `` ` 83 | 84 | 85 | ## versions 86 | - V1.0 87 | - V1.1 - added the output of the pressure trend in 3 hours 88 | - V1.2 - Compatibility ESP8266/32 89 | 90 | 91 | ## bugs and feedback 92 | Create ** Issue ** when you find the bugs, and better immediately write to the mail [alex@alexgyver.ru] (mailto: alex@alexgyver.ru) 93 | The library is open for refinement and your ** pull Request ** 'ow! 94 | 95 | 96 | When reporting about bugs or incorrect work of the library, it is necessary to indicate: 97 | - The version of the library 98 | - What is MK used 99 | - SDK version (for ESP) 100 | - version of Arduino ide 101 | - whether the built -in examples work correctly, in which the functions and designs are used, leading to a bug in your code 102 | - what code has been loaded, what work was expected from it and how it works in reality 103 | - Ideally, attach the minimum code in which the bug is observed.Not a canvas of a thousand lines, but a minimum code -------------------------------------------------------------------------------- /doc/zambretti.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GyverLibs/Forecaster/c50c7a70b77c9b3491e59dbe4f7943699addf462/doc/zambretti.png -------------------------------------------------------------------------------- /doc/zambretti.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GyverLibs/Forecaster/c50c7a70b77c9b3491e59dbe4f7943699addf462/doc/zambretti.xlsx -------------------------------------------------------------------------------- /examples/test/test.ino: -------------------------------------------------------------------------------- 1 | #include "Forecaster.h" 2 | Forecaster cond; 3 | 4 | void setup() { 5 | Serial.begin(9600); 6 | // установить высоту над уровнем моря (Москва 255м) 7 | cond.setH(255); 8 | 9 | // если есть RTC - можно установить месяц 1-12 10 | //cond.setMonth(5); 11 | } 12 | void loop() { 13 | // таймер на 30 минут 14 | static uint32_t tmr; 15 | if (millis() - tmr >= 30*60*1000ul) { 16 | tmr = millis(); 17 | // каждые 30 минут передаём текущее давление (Па) и температуру (С) с датчика 18 | cond.addP(99218, 25.2); 19 | 20 | // getCast() возвращает текущий прогноз от 0 до 10 21 | // 0 - хорошая погода, 10 и выше - шторм/ливень 22 | Serial.println(cond.getCast()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Forecaster 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | Forecaster KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | 14 | setH KEYWORD2 15 | addP KEYWORD2 16 | addPmm KEYWORD2 17 | setMonth KEYWORD2 18 | getCast KEYWORD2 19 | getTrend KEYWORD2 20 | 21 | ####################################### 22 | # Constants (LITERAL1) 23 | ####################################### -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Forecaster 2 | version=1.2 3 | author=AlexGyver 4 | maintainer=AlexGyver 5 | sentence=Weather forecasting with Zambretti algorithm 6 | paragraph=Weather forecasting with Zambretti algorithm 7 | category=Data Processing 8 | url=https://github.com/GyverLibs/Forecaster 9 | architectures=* -------------------------------------------------------------------------------- /src/Forecaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | Библиотека для определения прогноза погоды по давлению для Arduino 3 | Документация: 4 | GitHub: https://github.com/GyverLibs/Forecaster 5 | Возможности: 6 | - Определение краткосрочного прогноза погоды по алгоритму Замбретти 7 | - Принимает давление, температуру, высоту над ур. моря и месяц года 8 | - Определение тренда давления при помощи линеаризации 9 | 10 | AlexGyver, alex@alexgyver.ru 11 | https://alexgyver.ru/ 12 | MIT License 13 | 14 | Основано на 15 | https://integritext.net/DrKFS/zambretti.htm 16 | 17 | Версии: 18 | v1.0 - релиз 19 | v1.1 - добавил вывод тренда давления за 3 часа 20 | v1.2 - совместимость esp8266/32 21 | */ 22 | 23 | #ifndef _Forecaster_h 24 | #define _Forecaster_h 25 | #include 26 | #define _FC_SIZE 6 // размер буфера. Усреднение за 3 часа, при размере 6 - каждые 30 минут 27 | 28 | class Forecaster { 29 | public: 30 | // установить высоту над уровнем моря (в метрах) 31 | void setH(int h) { 32 | H = h * 0.0065f; 33 | } 34 | 35 | // добавить текущее давление в Па и температуру в С (КАЖДЫЕ 30 МИНУТ) 36 | // здесь же происходит расчёт прогноза 37 | void addP(long P, float t) { 38 | P = (float)P * pow(1 - H / (t + H + 273.15), -5.257); // над уровнем моря 39 | if (!start) { 40 | start = true; 41 | for (uint8_t i = 0; i < _FC_SIZE; i++) Parr[i] = P; 42 | } else { 43 | for (uint8_t i = 0; i < (_FC_SIZE-1); i++) Parr[i] = Parr[i + 1]; 44 | Parr[_FC_SIZE - 1] = P; 45 | } 46 | 47 | // расчёт изменения по наименьшим квадратам 48 | long sumX = 0, sumY = 0, sumX2 = 0, sumXY = 0; 49 | for (int i = 0; i < _FC_SIZE; i++) { 50 | sumX += i; 51 | sumY += Parr[i]; 52 | sumX2 += i * i; 53 | sumXY += Parr[i] * i; 54 | } 55 | float a = _FC_SIZE * sumXY - sumX * sumY; 56 | a /= _FC_SIZE * sumX2 - sumX * sumX; 57 | delta = a * (_FC_SIZE - 1); 58 | 59 | // расчёт прогноза по Zambretti 60 | P /= 100; // -> ГПа 61 | if (delta > 150) cast = 160 - 0.155 * P - season; // rising 62 | else if (delta < -150) cast = 130 - 0.124 * P + season; // falling 63 | else cast = 138 - 0.133 * P; // steady 64 | if (cast < 0) cast = 0; 65 | } 66 | 67 | // добавить текущее давление в мм.рт.ст и температуру в С (КАЖДЫЕ 30 МИНУТ) 68 | void addPmm(float P, float t) { 69 | addP(P * 133.322f, t); 70 | } 71 | 72 | // установить месяц (1-12) 73 | // 0 чтобы отключить сезонность 74 | void setMonth(uint8_t month) { 75 | if (month == 0) season = 0; 76 | else season = (month >= 4 && month <= 9) ? 2 : 1; 77 | /* 78 | if (month == 12) month = 0; 79 | month /= 3; // 0 зима, 1 весна, 2 лето, 3 осень 80 | season = month * 0.5 + 1; // 1, 1.5, 2, 2.5 81 | if (season == 2.5) season = 1.5; // 1, 1.5, 2, 1.5 82 | */ 83 | } 84 | 85 | // получить прогноз (0 хорошая погода... 10 ливень-шторм) 86 | float getCast() { 87 | return cast; 88 | } 89 | 90 | // получить изменение давления в Па за 3 часа 91 | int getTrend() { 92 | return delta; 93 | } 94 | 95 | private: 96 | long Parr[_FC_SIZE]; 97 | float H = 0; 98 | bool start = false; 99 | float cast = 0; 100 | int delta = 0; 101 | uint8_t season = 0; 102 | }; 103 | #endif --------------------------------------------------------------------------------