├── .DS_Store
├── .gitignore
├── .piolibdeps
├── Bleeper_ID1966
│ ├── .gitignore
│ ├── .library.json
│ ├── .travis.yml
│ ├── .vscode
│ │ ├── extensions.json
│ │ └── settings.json
│ ├── LICENSE
│ ├── README.md
│ ├── docs
│ │ └── VARIABLES.md
│ ├── examples
│ │ └── Simple
│ │ │ └── Simple.ino
│ ├── img
│ │ ├── Bleeper.png
│ │ ├── Bleeper.svg
│ │ ├── diagram.ai
│ │ ├── diagram.png
│ │ ├── smartphone.png
│ │ └── web.png
│ ├── keywords.txt
│ ├── lib
│ │ └── readme.txt
│ ├── library.json
│ ├── library.properties
│ ├── platformio.ini
│ └── src
│ │ ├── Bleeper.h
│ │ ├── Bleeper
│ │ ├── Bleeper+Configuration.cpp
│ │ ├── Bleeper+ConfigurationInterface.cpp
│ │ ├── Bleeper+Connection.cpp
│ │ ├── Bleeper+Storage.cpp
│ │ ├── BleeperClass.cpp
│ │ ├── BleeperClass.h
│ │ └── Initable.h
│ │ ├── Configuration
│ │ ├── BaseConfiguration.h
│ │ ├── ConfigMap.cpp
│ │ ├── ConfigMap.h
│ │ ├── Configuration.h
│ │ ├── ConfigurationDictionary.cpp
│ │ ├── ConfigurationDictionary.h
│ │ ├── ConfigurationMacros.h
│ │ ├── RootConfiguration.h
│ │ ├── StringConvertibleVariable.cpp
│ │ ├── StringConvertibleVariable.h
│ │ └── Variable.h
│ │ ├── ConfigurationInterface
│ │ ├── ConfigurationInterface.h
│ │ └── WebServer
│ │ │ ├── ESP32
│ │ │ ├── ESP32DefaultWebServer.cpp
│ │ │ ├── ESP32DefaultWebServer.h
│ │ │ ├── HTTPRequest.cpp
│ │ │ └── HTTPRequest.h
│ │ │ ├── ESP8266
│ │ │ ├── ESP8266DefaultWebServer.cpp
│ │ │ └── ESP8266DefaultWebServer.h
│ │ │ ├── WebPage.h
│ │ │ ├── WebServer.cpp
│ │ │ └── WebServer.h
│ │ ├── Connectivity
│ │ ├── AP.cpp
│ │ ├── AP.h
│ │ ├── Connection.cpp
│ │ ├── Connection.h
│ │ ├── Wifi.cpp
│ │ └── Wifi.h
│ │ ├── Helpers
│ │ ├── Logger.cpp
│ │ ├── Logger.h
│ │ ├── macros.h
│ │ ├── utils.cpp
│ │ └── utils.h
│ │ ├── Observers
│ │ ├── ConfigurationObserver.cpp
│ │ ├── ConfigurationObserver.h
│ │ └── Observable.h
│ │ ├── Storage
│ │ ├── EEPROMHelper.h
│ │ ├── SPIFFSStorage.h
│ │ ├── Storage.h
│ │ └── VariablesMapStorage.h
│ │ └── keywords.txt
├── PubSubClient_ID89
│ ├── .gitignore
│ ├── .library.json
│ ├── .travis.yml
│ ├── CHANGES.txt
│ ├── LICENSE.txt
│ ├── README.md
│ ├── examples
│ │ ├── mqtt_auth
│ │ │ └── mqtt_auth.ino
│ │ ├── mqtt_basic
│ │ │ └── mqtt_basic.ino
│ │ ├── mqtt_esp8266
│ │ │ └── mqtt_esp8266.ino
│ │ ├── mqtt_publish_in_callback
│ │ │ └── mqtt_publish_in_callback.ino
│ │ ├── mqtt_reconnect_nonblocking
│ │ │ └── mqtt_reconnect_nonblocking.ino
│ │ └── mqtt_stream
│ │ │ └── mqtt_stream.ino
│ ├── keywords.txt
│ ├── library.json
│ ├── library.properties
│ └── src
│ │ ├── PubSubClient.cpp
│ │ └── PubSubClient.h
└── SimpleDHT_ID849
│ ├── .gitignore
│ ├── .library.json
│ ├── LICENSE
│ ├── README.md
│ ├── SimpleDHT.cpp
│ ├── SimpleDHT.h
│ ├── examples
│ ├── DHT11Default
│ │ └── DHT11Default.ino
│ ├── DHT11ErrCount
│ │ └── DHT11ErrCount.ino
│ ├── DHT11WithRawBits
│ │ └── DHT11WithRawBits.ino
│ ├── DHT22Default
│ │ └── DHT22Default.ino
│ ├── DHT22ErrCount
│ │ └── DHT22ErrCount.ino
│ ├── DHT22Integer
│ │ └── DHT22Integer.ino
│ ├── DHT22WithRawBits
│ │ └── DHT22WithRawBits.ino
│ └── TwoSensorsDefault
│ │ └── TwoSensorsDefault.ino
│ ├── keywords.txt
│ └── library.properties
├── .travis.yml
├── .vscode
├── extensions.json
└── settings.json
├── README.md
├── firmware
└── firmware.bin
├── images
├── 1.png
├── 2.jpg
├── 3.png
└── 4.png
├── lib
├── .DS_Store
├── ir
│ ├── include
│ │ ├── ir_ac_apply.h
│ │ ├── ir_ac_binary_parse.h
│ │ ├── ir_ac_build_frame.h
│ │ ├── ir_ac_control.h
│ │ ├── ir_ac_parse_forbidden_info.h
│ │ ├── ir_ac_parse_frame_info.h
│ │ ├── ir_ac_parse_parameter.h
│ │ ├── ir_decode.h
│ │ ├── ir_defs.h
│ │ ├── ir_tv_control.h
│ │ └── ir_utils.h
│ └── src
│ │ ├── ir_ac_apply.cpp
│ │ ├── ir_ac_binary_parse.cpp
│ │ ├── ir_ac_build_frame.cpp
│ │ ├── ir_ac_control.cpp
│ │ ├── ir_ac_parse_forbidden_info.cpp
│ │ ├── ir_ac_parse_frame_info.cpp
│ │ ├── ir_ac_parse_parameter.cpp
│ │ ├── ir_decode.cpp
│ │ ├── ir_tv_control.cpp
│ │ └── ir_utils.cpp
└── readme.txt
├── platformio.ini
└── src
├── Untitled-1.txt
└── main.cpp
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .pioenvs
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .piolibdeps
6 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 | .pioenvs
34 | .piolibdeps
35 | .clang_complete
36 | .gcc-flags.json
37 | .vscode/.browse.c_cpp.db*
38 | .vscode/c_cpp_properties.json
39 | .vscode/launch.json
40 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/.library.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Bleeper",
3 | "repository": {
4 | "url": "https://github.com/neman-io/Bleeper.git",
5 | "type": "git"
6 | },
7 | "platforms": [
8 | "espressif32",
9 | "espressif8266"
10 | ],
11 | "frameworks": [
12 | "arduino"
13 | ],
14 | "version": "1.0.3",
15 | "authors": [
16 | {
17 | "maintainer": false,
18 | "name": "neman.io",
19 | "url": "https://github.com/neman-io",
20 | "email": null
21 | }
22 | ],
23 | "keywords": [
24 | "web panel",
25 | "connection",
26 | "configuration",
27 | "storage",
28 | "wifi"
29 | ],
30 | "id": 1966,
31 | "description": "A library to store generic configurations"
32 | }
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/.travis.yml:
--------------------------------------------------------------------------------
1 | # Continuous Integration (CI) is the practice, in software
2 | # engineering, of merging all developer working copies with a shared mainline
3 | # several times a day < http://docs.platformio.org/page/ci/index.html >
4 | #
5 | # Documentation:
6 | #
7 | # * Travis CI Embedded Builds with PlatformIO
8 | # < https://docs.travis-ci.com/user/integration/platformio/ >
9 | #
10 | # * PlatformIO integration with Travis CI
11 | # < http://docs.platformio.org/page/ci/travis.html >
12 | #
13 | # * User Guide for `platformio ci` command
14 | # < http://docs.platformio.org/page/userguide/cmd_ci.html >
15 | #
16 | #
17 | # Please choice one of the following templates (proposed below) and uncomment
18 | # it (remove "# " before each line) or use own configuration according to the
19 | # Travis CI documentation (see above).
20 | #
21 |
22 |
23 | #
24 | # Template #1: General project. Test it using existing `platformio.ini`.
25 | #
26 |
27 | # language: python
28 | # python:
29 | # - "2.7"
30 | #
31 | # sudo: false
32 | # cache:
33 | # directories:
34 | # - "~/.platformio"
35 | #
36 | # install:
37 | # - pip install -U platformio
38 | #
39 | # script:
40 | # - platformio run
41 |
42 |
43 | #
44 | # Template #2: The project is intended to by used as a library with examples
45 | #
46 |
47 | # language: python
48 | # python:
49 | # - "2.7"
50 | #
51 | # sudo: false
52 | # cache:
53 | # directories:
54 | # - "~/.platformio"
55 | #
56 | # env:
57 | # - PLATFORMIO_CI_SRC=path/to/test/file.c
58 | # - PLATFORMIO_CI_SRC=examples/file.ino
59 | # - PLATFORMIO_CI_SRC=path/to/test/directory
60 | #
61 | # install:
62 | # - pip install -U platformio
63 | #
64 | # script:
65 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
66 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // See http://go.microsoft.com/fwlink/?LinkId=827846
3 | // for the documentation about the extensions.json format
4 | "recommendations": [
5 | "platformio.platformio-ide"
6 | ]
7 | }
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "terminal.integrated.env.windows": {
3 | "PATH": "C:\\Users\\ucmed\\.platformio\\penv\\Scripts;C:\\Users\\ucmed\\.platformio\\penv;C:\\Program Files\\ImageMagick-7.0.7-Q16;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;D:\\Program Files\\nodejs\\;C:\\Program Files\\SourceGear\\Common\\DiffMerge\\;C:\\Program Files\\Mu\\bin;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files (x86)\\Microsoft VS Code\\bin;D:\\android-sdk\\platform-tools;D:\\android-sdk\\build-tools\\25.0.1;C:\\Program Files\\Java\\jdk1.8.0_131\\bin;C:\\Program Files\\MongoDB\\Server\\3.4\\bin;D:\\Program Files\\Python27;D:\\Program Files\\Python27\\Scripts;C:\\Users\\ucmed\\AppData\\Local\\Programs\\Fiddler;D:\\apache-maven-3.5.2\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files\\nodejs;D:\\ffmpeg\\bin;C:\\Users\\ucmed\\AppData\\Roaming\\npm;C:\\Program Files (x86)\\Microsoft VS Code\\bin;;C:\\Program Files\\ImageMagick-7.0.7-Q16;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;D:\\Program Files\\nodejs\\;C:\\Program Files\\SourceGear\\Common\\DiffMerge\\;C:\\Program Files\\Mu\\bin;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files (x86)\\Microsoft VS Code\\bin;D:\\android-sdk\\platform-tools;D:\\android-sdk\\build-tools\\25.0.1;C:\\Program Files\\Java\\jdk1.8.0_131\\bin;C:\\Program Files\\MongoDB\\Server\\3.4\\bin;D:\\Program Files\\Python27;D:\\Program Files\\Python27\\Scripts;C:\\Users\\ucmed\\AppData\\Local\\Programs\\Fiddler;D:\\apache-maven-3.5.2\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files\\nodejs;D:\\ffmpeg\\bin;C:\\Users\\ucmed\\AppData\\Roaming\\npm;C:\\Program Files (x86)\\Microsoft VS Code\\bin;",
4 | "PLATFORMIO_CALLER": "vscode"
5 | }
6 | }
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Diego Ernst
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 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Bleeper is a library to manage your firmware configurations written in C++ for [ESP8266](https://github.com/esp8266/Arduino) and [ESP32](https://github.com/espressif/arduino-esp32) Arduino Platforms.
6 |
7 | - [Features](#features)
8 | - [Why Bleeper](#why-bleeper)
9 | - [Usage](#usage)
10 | - [Installation](#installation)
11 | - [Arduino IDE](#arduino-ide)
12 | - [PlatformIO IDE for Atom](#platformio-ide)
13 | - [Future Work](#future-work)
14 |
15 | ## Features
16 |
17 | - [x] Fully customizable hierarchical configuration structure
18 | - [x] Generic property types
19 | - [x] Automatic storage with property granularity (EEPROM & SPIFFS)
20 | - [x] Wifi & AP connections
21 | - [x] Configuration interfaces (web panel by default)
22 | - [x] Observe any configuration property change through the observer API
23 |
24 | ## Why Bleeper
25 |
26 | In the scenario of prototyping with hardware devices you will likely end up with a bunch of configuration settings like pin numbers, sensor thresholds, device ids, connection credentials, port numbers, and so many others.
27 | As a good programmer you decide to define these configurations in a "configuration file" with a lot of `#define` macros or constants.
28 |
29 | But... what if you want to change those values? Downloading the firmware each time is tedious. Think about the cases where you have multiple devices to configure or even worst you don't have close physical access to them.
30 |
31 | At the end you realize that you actually need some sort of "Configuration Manager" with high level features like exposing those variables on a web panel (or another type of interface), persisting some of them (usually your Wifi credentials) and so on.
32 |
33 | ## Usage
34 |
35 | Suppose that you have this configuration:
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | The above tree structure speaks by its own, what's worth to mention here is that we want `wifi.ssid` and `wifi.passwrod` to be persistent using the Bleeper storage.
48 |
49 | The C++ code will look like this:
50 |
51 | ```cpp
52 | #include "Bleeper.h"
53 |
54 | class Config: public RootConfiguration {
55 | public:
56 | stringVar(name, "Default Device Name");
57 | subconfig(WifiConfig, wifi);
58 | subconfig(LedsConfig, leds);
59 | };
60 |
61 | class WifiConfig: public Configuration {
62 | public:
63 | persistentStringVar(ssid, "MySSID");
64 | persistentStringVar(password, "MyPassword");
65 | };
66 |
67 | class LedsConfig: public Configuration {
68 | public:
69 | floatVar(calibration, 1.5);
70 | subconfig(SPIConfig, spi);
71 | };
72 |
73 | class SPIConfig: public Configuration {
74 | public:
75 | intVar(speed, 1000000);
76 | };
77 | ```
78 |
79 | Basically, per each configuration node you have to implement a subclass of `Configuration` and a `RootConfiguration` subclass for the especial root node (i.e the top level entry).
80 |
81 | > For a full documentation on how properties are defined read [here](docs/VARIABLES.md).
82 |
83 | Once we completed our configuration structure we can use it like this:
84 |
85 | ```cpp
86 | // Your Config instance
87 | Config C;
88 |
89 | void loop() {
90 | // access to your spi speed config
91 | int speed = C.leds.spi.speed
92 | }
93 |
94 | ```
95 |
96 | > Note that all variables are type-safe. You are not accessing to a generic wrapper and casting its type.
97 |
98 | The final step is to setup the Bleeper singleton instance with your `RootConfiguration` instance and specify your connections, interfaces, storage and observers.
99 |
100 | ```cpp
101 | #include "Bleeper.h"
102 |
103 | class CalibrationObserver: public ConfigurationObserver {
104 | public:
105 | void onConfigurationChanged(const ConfigurationPropertyChange value) {
106 | Serial.println("Configuration " + value.key + " changed from " + value.oldValue + " to " + value.newValue);
107 | }
108 | };
109 |
110 | Config C;
111 |
112 | void setup() {
113 |
114 | Bleeper
115 | .verbose()
116 | .configuration
117 | .set(&C)
118 | .addObserver(new CalibrationObserver(), {&C.leds.calibration})
119 | .done()
120 | .configurationInterface
121 | .addDefaultWebServer()
122 | .done()
123 | .connection
124 | .setSingleConnectionFromPriorityList({
125 | new Wifi(&C.wifi.ssid, &C.wifi.password),
126 | new AP() // fallback
127 | })
128 | .done()
129 | .storage
130 | .setDefault() // EEPROM
131 | // .set(new SPIFFSStorage()) // SPIFFS
132 | .done()
133 | .init();
134 | }
135 |
136 | void loop() {
137 |
138 | Bleeper.handle();
139 |
140 | }
141 | ```
142 |
143 | Basically Bleeper exposes four entry points:
144 |
145 | 1. **Bleeper.configuration**
146 |
147 | Lets you set your `RootConfiguration` instance and add observers to changes on it. In this example we are setting the `CalibrationObserver` instance that will be only notified about changes on the `C.leds.calibration` property.
148 |
149 | 2. **Bleeper.configurationInterface**
150 |
151 | Here you can add as many `ConfigurationInterface` instances as you want. Bleeper provides a default web panel when calling `addDefaultWebServer`.
152 |
153 | 2. **Bleeper.connection**
154 |
155 | Under connection we can call `setMultipleConnections` or `setSingleConnectionFromPriorityList` (in which only one connection will be active) and provide a list of `Connection` instances. By default the `Wifi` class will observe changes on the provided credentials and retry the connection accordingly.
156 |
157 | 2. **Bleeper.storage**
158 |
159 | Lets you specify the `Storage` instance to use when saving your persistent variables. Calling `setDefault` will use the default EEPROM storage automatically. You can also use `SPIFFSStorage` or create your own instead.
160 |
161 | ## Installation
162 |
163 | ### Arduino IDE
164 |
165 | Go to Sketch > Include Library > Manage Libraries...
166 | Search for `Bleeper` and click on `Install`
167 |
168 | ### PlatformIO IDE
169 |
170 | Go to your `platformio.ini` file and add the following lines:
171 | ```
172 | lib_deps = Bleeper
173 | lib_ldf_mode = deep
174 | ```
175 |
176 | ## Future Work
177 |
178 | - Add support for other boards.
179 | - Improve documentation & examples.
180 | - Add CI server & tests.
181 |
182 | ## Author
183 |
184 | * [Diego Ernst](https://github.com/dernster)
185 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/docs/VARIABLES.md:
--------------------------------------------------------------------------------
1 | # Variables
2 |
3 | Variables within a `Configuration` class or `RootConfiguration` class will be tracked by `Bleeper` only if they are declared using specific macros.
4 |
5 | ## Common types
6 |
7 | - `intVar`, `floatVar` & `stringVar`
8 | They all receive two parameters, the first one is the name of the variable and the second one its default value. Default values must be of types `int`, `float` and `String` respectively.
9 |
10 | - `persistentIntVar`, `persistentFloatVar` & `persistentStringVar`
11 | The same as before but they will be persisted on the configured `Bleeper` storage.
12 |
13 | ```Cpp
14 | class ExampleConfig: public Configuration {
15 | public:
16 | persistentStringVar(boardName, "Board 1");
17 | floatVar(threshold, 0.7);
18 | };
19 | ```
20 |
21 | ## Custom types
22 |
23 | `Bleeper` allows you to store any type of variable. You only need to be able to serialize & deserialize it to & from a string.
24 |
25 | - `var(type, name, default, setBody, getBody)`
26 | - `type`: your custom type.
27 | - `name`: name of your variable.
28 | - `default`: default value.
29 | - `setBody`: scope enclosed by curly brackets in which you will have exposed a variable called `name` (your actual variable) and a constant called `nameString` which you will have to make your conversion from.
30 | - `getBody`: similar to `setBody` but you need to write the variable called `nameString` from your variable `name`.
31 |
32 |
33 | - `persistentVar(type, name, default, setBody, getBody)`
34 | The same as before but persistent.
35 |
36 | ```Cpp
37 | #include "Bleeper.h"
38 |
39 | class Point {
40 | public:
41 | int x, y;
42 |
43 | Point(int x, int y) {
44 | this->x = x;
45 | this->y = y;
46 | }
47 |
48 | Point(String string) {
49 | auto strings = splitString(string, ",");
50 | x = strings[0].toInt();
51 | y = strings[1].toInt();
52 | }
53 |
54 | String toString() {
55 | return String(x) + "," + String(y)
56 | }
57 | }
58 |
59 | class ExampleConfig: public Configuration {
60 | public:
61 | var(Point, point, Point(0, 0),
62 | {
63 | point = Point(pointString);
64 | },
65 | {
66 | pointString = point.toString();
67 | });
68 | };
69 | ```
70 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/examples/Simple/Simple.ino:
--------------------------------------------------------------------------------
1 | #include "Bleeper.h"
2 |
3 | class Network: public Configuration {
4 | public:
5 | stringVar(ip, "localhost");
6 | intVar(port, 506);
7 | };
8 |
9 | class WifiConfig: public Configuration {
10 | public:
11 | persistentStringVar(ssid, "ssid");
12 | persistentStringVar(password, "pass");
13 | subconfig(Network, network);
14 | };
15 |
16 | class Config: public RootConfiguration {
17 | public:
18 | floatVar(floatValue, 0);
19 |
20 | var(unsigned int, time, 25,
21 | {
22 | time = timeString.toInt();
23 | },
24 | {
25 | timeString = String(time);
26 | });
27 |
28 | subconfig(WifiConfig, wifi);
29 | } C;
30 |
31 | class MyObserver: public ConfigurationObserver {
32 | public:
33 | void onConfigurationChanged(const ConfigurationPropertyChange value) {
34 | Serial.println("Configuration " + value.key + " changed from " + value.oldValue + " to " + value.newValue);
35 | }
36 | };
37 |
38 | void setup() {
39 |
40 | Bleeper
41 | .verbose()
42 | .configuration
43 | .set(&C)
44 | .addObserver(new MyObserver(), {&C.wifi.network.port})
45 | .done()
46 | .configurationInterface
47 | .addDefaultWebServer()
48 | .done()
49 | .connection
50 | .setSingleConnectionFromPriorityList({
51 | new Wifi(&C.wifi.ssid, &C.wifi.password),
52 | new AP()
53 | })
54 | .done()
55 | .storage
56 | .setDefault() // EEPROM
57 | // .set(new SPIFFSStorage()) // SPIFFS
58 | .done()
59 | .init();
60 | }
61 |
62 | void loop() {
63 |
64 | Bleeper.handle();
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/img/Bleeper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.piolibdeps/Bleeper_ID1966/img/Bleeper.png
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/img/Bleeper.svg:
--------------------------------------------------------------------------------
1 | BleeperAsset 3 Bleeper
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/img/diagram.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.piolibdeps/Bleeper_ID1966/img/diagram.ai
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/img/diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.piolibdeps/Bleeper_ID1966/img/diagram.png
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/img/smartphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.piolibdeps/Bleeper_ID1966/img/smartphone.png
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/img/web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.piolibdeps/Bleeper_ID1966/img/web.png
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/keywords.txt:
--------------------------------------------------------------------------------
1 | #############################
2 | # Automatically generated
3 | #############################
4 |
5 | BleeperClass::ConfigurationInterfaceFunctions KEYWORD1
6 | add KEYWORD2
7 | addDefaultWebServer KEYWORD2
8 | BleeperClass::StorageFunctions KEYWORD1
9 | persist KEYWORD2
10 | set KEYWORD2
11 | setDefault KEYWORD2
12 | BleeperClass::UserProperties KEYWORD1
13 | BleeperClass::ConfigurationFunctions KEYWORD1
14 | addObserver KEYWORD2
15 | enableObservers KEYWORD2
16 | get KEYWORD2
17 | getAsDictionary KEYWORD2
18 | getVariables KEYWORD2
19 | set KEYWORD2
20 | setFromDictionary KEYWORD2
21 | BleeperClass::Chainable KEYWORD1
22 | done KEYWORD2
23 | BleeperClass KEYWORD1
24 | handle KEYWORD2
25 | init KEYWORD2
26 | shared KEYWORD2
27 | verbose KEYWORD2
28 | BleeperClass::ConnectionFunctions KEYWORD1
29 | set KEYWORD2
30 | setMultipleConnections KEYWORD2
31 | setSingleConnectionFromPriorityList KEYWORD2
32 | Initable KEYWORD1
33 | init KEYWORD2
34 | BaseConfiguration KEYWORD1
35 | addTo KEYWORD2
36 | fillConfigMap KEYWORD2
37 | getPrefix KEYWORD2
38 | withPrefix KEYWORD2
39 | ConfigMap KEYWORD1
40 | add KEYWORD2
41 | Configuration KEYWORD1
42 | ConfigurationDictionary KEYWORD1
43 | append KEYWORD2
44 | toStrings KEYWORD2
45 | RootConfiguration KEYWORD1
46 | getAsDictionary KEYWORD2
47 | getVariableForAddress KEYWORD2
48 | getVariables KEYWORD2
49 | init KEYWORD2
50 | isAddressValid KEYWORD2
51 | setFromDictionary KEYWORD2
52 | StringConvertibleVariable KEYWORD1
53 | getAsString KEYWORD2
54 | getFullKey KEYWORD2
55 | getKey KEYWORD2
56 | getMemoryAddress KEYWORD2
57 | isPersistentVariable KEYWORD2
58 | setFromString KEYWORD2
59 | setFullKey KEYWORD2
60 | Variable KEYWORD1
61 | addTo KEYWORD2
62 | getAsString KEYWORD2
63 | isPersistentVariable KEYWORD2
64 | setFromString KEYWORD2
65 | IntVariable KEYWORD1
66 | getAsString KEYWORD2
67 | setFromString KEYWORD2
68 | GenericVariable KEYWORD1
69 | SetterOfType KEYWORD2
70 | getAsString KEYWORD2
71 | setFromString KEYWORD2
72 | StringVariable KEYWORD1
73 | getAsString KEYWORD2
74 | setFromString KEYWORD2
75 | FloatVariable KEYWORD1
76 | getAsString KEYWORD2
77 | setFromString KEYWORD2
78 | ConfigurationInterface KEYWORD1
79 | handle KEYWORD2
80 | init KEYWORD2
81 | AP KEYWORD1
82 | connect KEYWORD2
83 | disconnect KEYWORD2
84 | handle KEYWORD2
85 | init KEYWORD2
86 | Connections KEYWORD1
87 | add KEYWORD2
88 | handle KEYWORD2
89 | init KEYWORD2
90 | OneOfMultipleConnection KEYWORD1
91 | connect KEYWORD2
92 | disconnect KEYWORD2
93 | disconnectFromAllExepct KEYWORD2
94 | handle KEYWORD2
95 | retry KEYWORD2
96 | Connection KEYWORD1
97 | connect KEYWORD2
98 | connectionDidComplete KEYWORD2
99 | connectionDidFail KEYWORD2
100 | disconnect KEYWORD2
101 | handle KEYWORD2
102 | init KEYWORD2
103 | retry KEYWORD2
104 | setIsExclusiveConnection KEYWORD2
105 | wantsToRetryConnection KEYWORD2
106 | MultipleConnection KEYWORD1
107 | connect KEYWORD2
108 | disconnect KEYWORD2
109 | handle KEYWORD2
110 | Wifi KEYWORD1
111 | connect KEYWORD2
112 | disconnect KEYWORD2
113 | handle KEYWORD2
114 | init KEYWORD2
115 | onConfigurationChanged KEYWORD2
116 | retry KEYWORD2
117 | wantsToRetryConnection KEYWORD2
118 | Logger KEYWORD1
119 | print KEYWORD2
120 | ConfigurationObserver KEYWORD1
121 | isInterestedIn KEYWORD2
122 | onConfigurationChanged KEYWORD2
123 | setFilter KEYWORD2
124 | ConfigurationPropertyChange KEYWORD1
125 | Observable KEYWORD1
126 | addObserver KEYWORD2
127 | EEPROMHelper KEYWORD1
128 | readStrings KEYWORD2
129 | writeStrings KEYWORD2
130 | Storage KEYWORD1
131 | load KEYWORD2
132 | persist KEYWORD2
133 | VariablesMapStorage KEYWORD1
134 | init KEYWORD2
135 | load KEYWORD2
136 | persist KEYWORD2
137 | DefaultWebServer KEYWORD1
138 | handle KEYWORD2
139 | init KEYWORD2
140 | WebServer KEYWORD1
141 | handle KEYWORD2
142 | init KEYWORD2
143 |
144 | #############################
145 | # Manual settings
146 | #############################
147 |
148 | Bleeper KEYWORD1
149 | var KEYWORD2
150 | floatVar KEYWORD2
151 | stringVar KEYWORD2
152 | intVar KEYWORD2
153 | persistentVar KEYWORD2
154 | persistentFloatVar KEYWORD2
155 | persistentStringVar KEYWORD2
156 | persistentIntVar KEYWORD2
157 | subconfig KEYWORD2
158 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/lib/readme.txt:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for the project specific (private) libraries.
3 | PlatformIO will compile them to static libraries and link to executable file.
4 |
5 | The source code of each library should be placed in separate directory, like
6 | "lib/private_lib/[here are source files]".
7 |
8 | For example, see how can be organized `Foo` and `Bar` libraries:
9 |
10 | |--lib
11 | | |--Bar
12 | | | |--docs
13 | | | |--examples
14 | | | |--src
15 | | | |- Bar.c
16 | | | |- Bar.h
17 | | |--Foo
18 | | | |- Foo.c
19 | | | |- Foo.h
20 | | |- readme.txt --> THIS FILE
21 | |- platformio.ini
22 | |--src
23 | |- main.c
24 |
25 | Then in `src/main.c` you should use:
26 |
27 | #include
28 | #include
29 |
30 | // rest H/C/CPP code
31 |
32 | PlatformIO will find your libraries automatically, configure preprocessor's
33 | include paths and build them.
34 |
35 | More information about PlatformIO Library Dependency Finder
36 | - http://docs.platformio.org/page/librarymanager/ldf.html
37 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/library.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Bleeper",
3 | "keywords": "Configuration, Storage, Web Panel, Connection, WiFi",
4 | "description": "A library to store generic configurations",
5 | "repository":
6 | {
7 | "type": "git",
8 | "url": "https://github.com/neman-io/Bleeper.git"
9 | },
10 | "frameworks": "arduino",
11 | "platforms": ["espressif8266", "espressif32"],
12 | "version": "1.0.3"
13 | }
14 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/library.properties:
--------------------------------------------------------------------------------
1 | name=Bleeper
2 | version=1.0.3
3 | author=Diego Ernst
4 | maintainer=Diego Ernst
5 | sentence=A library to store generic configurations.
6 | paragraph=Easily define your configuration hierarchy, the type of each property and weather or not it should be persisted.
7 | category=Other
8 | url=https://github.com/neman-io/Bleeper.git
9 | architectures=esp8266,esp32
10 | includes=Bleeper.h
11 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/platformio.ini:
--------------------------------------------------------------------------------
1 | #
2 | # Project Configuration File
3 | #
4 | # A detailed documentation with the EXAMPLES is located here:
5 | # http://docs.platformio.org/en/latest/projectconf.html
6 | #
7 |
8 | # A sign `#` at the beginning of the line indicates a comment
9 | # Comment lines are ignored.
10 |
11 | # Simple and base environment
12 | # [env:mybaseenv]
13 | # platform = %INSTALLED_PLATFORM_NAME_HERE%
14 | # framework =
15 | # board =
16 | #
17 | # Automatic targets - enable auto-uploading
18 | # targets = upload
19 |
20 | [env:esp8266dev]
21 | platform = espressif
22 | framework = arduino
23 | board = nodemcuv2
24 |
25 | [env:esp32dev]
26 | platform = espressif32
27 | framework = arduino
28 | board = esp32dev
29 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Helpers/utils.h"
4 | #include "Bleeper/BleeperClass.h"
5 | #include "Connectivity/Wifi.h"
6 | #include "Connectivity/AP.h"
7 | #include "Observers/ConfigurationObserver.h"
8 | #include "Configuration/ConfigurationMacros.h"
9 | #include "Configuration/Configuration.h"
10 | #include "Configuration/RootConfiguration.h"
11 | #include "Storage/SPIFFSStorage.h"
12 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/Bleeper+Configuration.cpp:
--------------------------------------------------------------------------------
1 | #include "Bleeper/BleeperClass.h"
2 | #include "Observers/ConfigurationObserver.h"
3 | #include "Helpers/macros.h"
4 |
5 | #define FunctionsContainer BleeperClass::ConfigurationFunctions
6 |
7 | FunctionsContainer& FunctionsContainer::addObserver(ConfigurationObserver* observer, std::set filter) {
8 | guard(Bleeper.userProperties.rootConfig != NULL, return *this);
9 | observer->setFilter(filter);
10 | Bleeper.userProperties.rootConfig->addObserver(observer);
11 | return *this;
12 | }
13 |
14 | FunctionsContainer& FunctionsContainer::set(RootConfiguration* config) {
15 | Bleeper.userProperties.rootConfig = config;
16 | return *this;
17 | }
18 |
19 | void FunctionsContainer::setFromDictionary(const ConfigurationDictionary& dict) {
20 | Bleeper.userProperties.rootConfig->setFromDictionary(dict);
21 | }
22 |
23 | ConfigurationDictionary FunctionsContainer::getAsDictionary(bool onlyPersistent) {
24 | guard(Bleeper.userProperties.rootConfig, return ConfigurationDictionary());
25 | return Bleeper.userProperties.rootConfig->getAsDictionary(onlyPersistent);
26 | }
27 |
28 | RootConfiguration* FunctionsContainer::get() {
29 | return Bleeper.userProperties.rootConfig;
30 | }
31 |
32 | void FunctionsContainer::enableObservers(bool enable) {
33 | ConfigurationObserver::isEnabled = enable;
34 | }
35 |
36 | const std::vector& FunctionsContainer::getVariables() {
37 | return Bleeper.userProperties.rootConfig->getVariables();
38 | }
39 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/Bleeper+ConfigurationInterface.cpp:
--------------------------------------------------------------------------------
1 | #ifdef ESP8266
2 | #include "ConfigurationInterface/WebServer/ESP8266/ESP8266DefaultWebServer.h"
3 | #elif ESP32
4 | #include "ConfigurationInterface/WebServer/ESP32/ESP32DefaultWebServer.h"
5 | #endif
6 |
7 | #include "Bleeper/BleeperClass.h"
8 | #include "Helpers/macros.h"
9 |
10 | #define FunctionsContainer BleeperClass::ConfigurationInterfaceFunctions
11 |
12 | FunctionsContainer& FunctionsContainer::add(ConfigurationInterface* i) {
13 | Bleeper.userProperties.interfaces.push_back(i);
14 | return *this;
15 | }
16 |
17 | FunctionsContainer& FunctionsContainer::addDefaultWebServer() {
18 | #ifdef ESP8266
19 | Bleeper.userProperties.interfaces.push_back(new ESP8266DefaultWebServer(80));
20 | #elif ESP32
21 | Bleeper.userProperties.interfaces.push_back(new ESP32DefaultWebServer(80));
22 | #endif
23 | return *this;
24 | }
25 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/Bleeper+Connection.cpp:
--------------------------------------------------------------------------------
1 | #include "Bleeper/BleeperClass.h"
2 | #include "Helpers/macros.h"
3 |
4 | #define FunctionsContainer BleeperClass::ConnectionFunctions
5 |
6 | FunctionsContainer& FunctionsContainer::set(Connection* c) {
7 | Bleeper.userProperties.connection = c;
8 | return *this;
9 | }
10 |
11 | FunctionsContainer& FunctionsContainer::setMultipleConnections(std::vector connections) {
12 | Bleeper.userProperties.connection = new MultipleConnection(connections);
13 | return *this;
14 | }
15 |
16 | FunctionsContainer& FunctionsContainer::setSingleConnectionFromPriorityList(std::vector connections) {
17 | Bleeper.userProperties.connection = new OneOfMultipleConnection(connections);
18 | return *this;
19 | }
20 |
21 | Connection* FunctionsContainer::get() {
22 | return Bleeper.userProperties.connection;
23 | }
24 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/Bleeper+Storage.cpp:
--------------------------------------------------------------------------------
1 | #include "Bleeper/BleeperClass.h"
2 | #include "Storage/VariablesMapStorage.h"
3 | #include "Helpers/macros.h"
4 |
5 | #define FunctionsContainer BleeperClass::StorageFunctions
6 |
7 | FunctionsContainer& FunctionsContainer::set(Storage* s) {
8 | Bleeper.userProperties.storage = s;
9 | return *this;
10 | }
11 |
12 | FunctionsContainer& FunctionsContainer::setDefault() {
13 | Bleeper.userProperties.storage = new VariablesMapStorage();
14 | return *this;
15 | }
16 |
17 | FunctionsContainer& FunctionsContainer::persist() {
18 | guard(Bleeper.userProperties.storage, return *this);
19 | Bleeper.userProperties.storage->persist();
20 | return *this;
21 | }
22 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/BleeperClass.cpp:
--------------------------------------------------------------------------------
1 | #include "Bleeper/BleeperClass.h"
2 | #include "Helpers/Logger.h"
3 | #include "Helpers/macros.h"
4 |
5 | #ifdef ESP8266
6 | #include
7 | #elif ESP32
8 | #include
9 | #endif
10 |
11 | BleeperClass* BleeperClass::sharedInstance = NULL;
12 |
13 | BleeperClass::BleeperClass() {
14 | userProperties.storage = NULL;
15 | userProperties.rootConfig = NULL;
16 | userProperties.connection = NULL;
17 | }
18 |
19 | BleeperClass* BleeperClass::shared() {
20 | if (!sharedInstance)
21 | sharedInstance = new BleeperClass();
22 | return sharedInstance;
23 | }
24 |
25 | void BleeperClass::handle() {
26 | for(auto interface: userProperties.interfaces) {
27 | interface->handle();
28 | }
29 |
30 | if (userProperties.connection) {
31 | userProperties.connection->handle();
32 | }
33 |
34 | }
35 |
36 | BleeperClass& BleeperClass::verbose() {
37 | Logger::verbose = true;
38 | return *this;
39 | }
40 |
41 | void BleeperClass::init() {
42 | init(true);
43 | }
44 |
45 | void BleeperClass::init(bool loadFromStorage) {
46 | guard(userProperties.rootConfig, return);
47 |
48 | configuration.enableObservers(false);
49 |
50 | userProperties.rootConfig->init();
51 |
52 | if (userProperties.storage) {
53 | userProperties.storage->init();
54 | if (loadFromStorage)
55 | userProperties.storage->load();
56 | }
57 |
58 | for(auto interface: userProperties.interfaces) {
59 | interface->init();
60 | }
61 |
62 | if (userProperties.connection) {
63 | WiFi.mode(WIFI_OFF);
64 | userProperties.connection->init();
65 | userProperties.connection->connect();
66 | }
67 | configuration.enableObservers(true);
68 | }
69 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/BleeperClass.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Storage/Storage.h"
3 | #include "Configuration/RootConfiguration.h"
4 | #include "Connectivity/Connection.h"
5 | #include "Configuration/ConfigurationDictionary.h"
6 | #include "ConfigurationInterface/ConfigurationInterface.h"
7 | #include "Bleeper/Initable.h"
8 |
9 | #define Bleeper (*BleeperClass::shared())
10 |
11 | class BleeperClass: public Initable {
12 | private:
13 | static BleeperClass* sharedInstance;
14 | BleeperClass();
15 |
16 | struct UserProperties {
17 | Storage* storage;
18 | RootConfiguration* rootConfig;
19 | std::vector interfaces;
20 | Connection* connection;
21 | } userProperties;
22 |
23 | public:
24 | static BleeperClass* shared();
25 | void handle();
26 | void init();
27 | void init(bool loadFromStorage);
28 | BleeperClass& verbose();
29 |
30 | class Chainable {
31 | public:
32 | BleeperClass& done() {
33 | return Bleeper;
34 | }
35 | };
36 |
37 | class ConfigurationFunctions: public Chainable {
38 | public:
39 | ConfigurationFunctions& set(RootConfiguration*);
40 | ConfigurationFunctions& addObserver(ConfigurationObserver* observer, std::set filter = std::set());
41 | RootConfiguration* get();
42 | ConfigurationDictionary getAsDictionary(bool onlyPersistent = false);
43 | const std::vector& getVariables();
44 | void enableObservers(bool);
45 | void setFromDictionary(const ConfigurationDictionary&);
46 | } configuration;
47 |
48 | class ConnectionFunctions: public Chainable {
49 | public:
50 | ConnectionFunctions& set(Connection*);
51 | Connection* get();
52 | ConnectionFunctions& setMultipleConnections(std::vector connections);
53 | ConnectionFunctions& setSingleConnectionFromPriorityList(std::vector connections);
54 | } connection;
55 |
56 | class StorageFunctions: public Chainable {
57 | public:
58 | StorageFunctions& set(Storage*);
59 | StorageFunctions& setDefault();
60 | StorageFunctions& persist();
61 | } storage;
62 |
63 | class ConfigurationInterfaceFunctions: public Chainable {
64 | public:
65 | ConfigurationInterfaceFunctions& add(ConfigurationInterface*);
66 | ConfigurationInterfaceFunctions& addDefaultWebServer();
67 | } configurationInterface;
68 |
69 | };
70 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Bleeper/Initable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class Initable {
4 | public:
5 | virtual void init() = 0;
6 | };
7 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/BaseConfiguration.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Configuration/ConfigurationDictionary.h"
3 | #include "Variable.h"
4 | #include "StringConvertibleVariable.h"
5 | #include "Configuration/ConfigMap.h"
6 |
7 | class BaseConfiguration {
8 | protected:
9 | String prefix;
10 | std::vector vars;
11 | std::vector subConfigs;
12 |
13 | template void add(Variable& var) {
14 | vars.push_back(&var);
15 | }
16 |
17 | void fillConfigMap(String cumulativePrefix, ConfigMap* map) {
18 | for(StringConvertibleVariable* variable: vars) {
19 | auto prefix = cumulativePrefix;
20 | auto varFullKey = (prefix != "") ? prefix + "." + variable->getKey() : variable->getKey();
21 | variable->setFullKey(varFullKey);
22 | map->add(variable->getMemoryAddress(), variable);
23 | }
24 | for(BaseConfiguration* subConfig: subConfigs) {
25 | auto cumulative = (cumulativePrefix != "") ? cumulativePrefix + "." + subConfig->prefix: subConfig->prefix;
26 | subConfig->fillConfigMap(cumulative, map);
27 | }
28 | }
29 |
30 | public:
31 | BaseConfiguration() {}
32 |
33 | String getPrefix() {
34 | return prefix;
35 | }
36 |
37 | void fillConfigMap(ConfigMap* map) {
38 | fillConfigMap("", map);
39 | }
40 |
41 | template
42 | T* addTo(std::vector& subConfigs) {
43 | subConfigs.push_back(this);
44 | return (T*)this;
45 | }
46 |
47 | template
48 | T* withPrefix(String prefix) {
49 | this->prefix = prefix;
50 | return (T*)this;
51 | }
52 |
53 | };
54 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/ConfigMap.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigMap.h"
2 |
3 | ConfigMap::ConfigMap() {}
4 |
5 | void ConfigMap::add(VariableAddress address, StringConvertibleVariable* variable) {
6 | addressMap[address] = variable;
7 | keyMap[variable->getFullKey()] = variable;
8 | variables.push_back(variable);
9 | }
10 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/ConfigMap.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "StringConvertibleVariable.h"
3 | #include "Configuration/ConfigurationDictionary.h"
4 | #include
5 | #include
6 |
7 | typedef const void* VariableAddress;
8 |
9 | class ConfigMap {
10 | protected:
11 | std::map addressMap;
12 | std::map keyMap;
13 | std::vector variables;
14 | public:
15 | ConfigMap();
16 | void add(VariableAddress address, StringConvertibleVariable* variable);
17 | };
18 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/Configuration.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "BaseConfiguration.h"
3 |
4 | class Configuration: public BaseConfiguration {};
5 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/ConfigurationDictionary.cpp:
--------------------------------------------------------------------------------
1 | #include "Configuration/ConfigurationDictionary.h"
2 | #include "Helpers/utils.h"
3 | #include "Helpers/macros.h"
4 |
5 | ConfigurationDictionary::ConfigurationDictionary() {};
6 |
7 | ConfigurationDictionary::ConfigurationDictionary(const std::vector & strings) {
8 | guard(strings.size() > 0, return);
9 | for(auto p = 0; p < strings.size() - 1; p += 2) {
10 | (*this)[strings[p]] = strings[p + 1];
11 | }
12 | }
13 |
14 | void ConfigurationDictionary::append(ConfigurationDictionary dict) {
15 | insert(dict.begin(), dict.end());
16 | }
17 |
18 | std::vector ConfigurationDictionary::toStrings() {
19 | std::vector result;
20 | for(auto const& pair: *this) {
21 | result.push_back(pair.first);
22 | result.push_back(pair.second);
23 | }
24 | return result;
25 | }
26 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/ConfigurationDictionary.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 |
6 | class ConfigurationDictionary: public std::map {
7 | public:
8 | ConfigurationDictionary();
9 | ConfigurationDictionary(const std::vector & strings);
10 | void append(ConfigurationDictionary);
11 | std::vector toStrings();
12 | };
13 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/ConfigurationMacros.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define UNIQUE_NAME(x) zbleeper ## _ ## x
4 |
5 | /******************* MOST COMMON VARS ******************/
6 |
7 | #define floatVar(name, initial) __floatVar__(name, initial, false)
8 | #define stringVar(name, initial) __stringVar__(name, initial, false)
9 | #define intVar(name, initial) __intVar__(name, initial, false)
10 |
11 | #define persistentFloatVar(name, initial) __floatVar__(name, initial, true)
12 | #define persistentStringVar(name, initial) __stringVar__(name, initial, true)
13 | #define persistentIntVar(name, initial) __intVar__(name, initial, true)
14 |
15 | #define var(type, name, initial, setBody, getBody) __var__(type, name, initial, false, setBody, getBody)
16 | #define persistentVar(type, name, initial, setBody, getBody) __var__(type, name, initial, true, setBody, getBody)
17 |
18 | /******************* MOST COMMON VARS ******************/
19 |
20 | #define __floatVar__(name, initial, isPersistent)\
21 | float name = initial;\
22 | FloatVariable* UNIQUE_NAME(var_ ## name) = (new FloatVariable(#name, &name, isPersistent))->addTo(vars);
23 |
24 | #define __stringVar__(name, initial, isPersistent)\
25 | StringVariable* UNIQUE_NAME(var_ ## name) = (new StringVariable(#name, &name, isPersistent))->addTo(vars);\
26 | String name = initial;
27 |
28 | #define __intVar__(name, initial, isPersistent)\
29 | IntVariable* UNIQUE_NAME(var_ ## name) = (new IntVariable(#name, &name, isPersistent))->addTo(vars);\
30 | int name = initial;
31 |
32 | #define subconfig(type, name)\
33 | type * UNIQUE_NAME(name) = (new type())->withPrefix(#name)->addTo(subConfigs);\
34 | type & name = *UNIQUE_NAME(name);\
35 |
36 | /*************** GENERIC TYPE VARIABLES ****************/
37 |
38 | #define __var__(type, name, initial, isPersistent, setBody, getBody)\
39 | GenericVariable* UNIQUE_NAME(var_ ## name) = (new GenericVariable(#name, &name, isPersistent, &setterFuncName(name), &getterFuncName(name)))->addTo>(vars);\
40 | type name = initial;\
41 | setterFunc(type, name, setBody);\
42 | getterFunc(type, name, getBody);\
43 |
44 | #define setterFuncName(name) UNIQUE_NAME(set_ ## name)
45 | #define getterFuncName(name) UNIQUE_NAME(get_ ## name)
46 |
47 | #define setterFunc(type, name,body)\
48 | static void setterFuncName(name)(type* UNIQUE_NAME(instance), const String& name ## String){\
49 | auto & name = *UNIQUE_NAME(instance);\
50 | body;\
51 | }
52 |
53 | #define getterFunc(type, name, body)\
54 | static String getterFuncName(name)(type* UNIQUE_NAME(instance)){\
55 | const auto & name = *UNIQUE_NAME(instance);\
56 | String name ## String = "STRING_CONVERTER_NOT_IMPLEMENTED";\
57 | body;\
58 | return name ## String;\
59 | }
60 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/RootConfiguration.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "BaseConfiguration.h"
3 | #include "Observers/Observable.h"
4 | #include "Observers/ConfigurationObserver.h"
5 | #include "Bleeper/Initable.h"
6 |
7 | class RootConfiguration:
8 | public BaseConfiguration,
9 | public Observable,
10 | public ConfigMap,
11 | public Initable {
12 | protected:
13 |
14 | virtual void notifyObserversOfChange(VariableAddress address, const String & key, const String oldValue, const String newValue) {
15 | if (oldValue == newValue)
16 | return;
17 | for(ConfigurationObserver* o: observers) {
18 | if (o->isInterestedIn(address))
19 | o->onConfigurationChanged({.key = key, .oldValue = oldValue, .newValue = newValue});
20 | }
21 | }
22 |
23 | public:
24 |
25 | virtual void init() {
26 | fillConfigMap(this);
27 | }
28 |
29 | bool isAddressValid(VariableAddress address) {
30 | return addressMap.find(address) != addressMap.end();
31 | }
32 |
33 | StringConvertibleVariable* getVariableForAddress(VariableAddress address) {
34 | return addressMap[address];
35 | }
36 |
37 | ConfigurationDictionary getAsDictionary(bool onlyPersistent) {
38 | ConfigurationDictionary result;
39 | for(auto const &value : addressMap) {
40 | if (!onlyPersistent || value.second->isPersistentVariable()) {
41 | result[value.second->getFullKey()] = value.second->getAsString();
42 | }
43 | }
44 | return result;
45 | }
46 |
47 | void setFromDictionary(const ConfigurationDictionary& dict) {
48 | for(auto const &pair : dict) {
49 | std::map::iterator it = keyMap.find(pair.first);
50 | if (it != keyMap.end()) {
51 | auto oldValue = it->second->getAsString();
52 | it->second->setFromString(pair.second);
53 | notifyObserversOfChange(it->second->getMemoryAddress(), pair.first, oldValue, it->second->getAsString());
54 | }
55 | }
56 | }
57 |
58 | const std::vector& getVariables() {
59 | return variables;
60 | }
61 |
62 | };
63 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/StringConvertibleVariable.cpp:
--------------------------------------------------------------------------------
1 | #include "Configuration/StringConvertibleVariable.h"
2 |
3 | StringConvertibleVariable::StringConvertibleVariable(void* value, String key, bool isPersistent){
4 | this->key = key;
5 | this->value = value;
6 | this->isPersistent = isPersistent;
7 | }
8 |
9 | bool StringConvertibleVariable::isPersistentVariable() {
10 | return isPersistent;
11 | }
12 |
13 | String StringConvertibleVariable::getKey() {
14 | return key;
15 | }
16 |
17 | void* StringConvertibleVariable::getMemoryAddress() {
18 | return value;
19 | }
20 |
21 | void StringConvertibleVariable::setFullKey(const String fullKey) {
22 | this->fullKey = fullKey;
23 | }
24 |
25 | String StringConvertibleVariable::getFullKey() {
26 | return fullKey;
27 | }
28 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/StringConvertibleVariable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Arduino.h"
3 | class BaseConfiguration;
4 |
5 | class StringConvertibleVariable {
6 | protected:
7 | String key;
8 | String fullKey;
9 | void* value;
10 | bool isPersistent;
11 | public:
12 | StringConvertibleVariable(void* value, String key, bool isPersistent);
13 | bool isPersistentVariable();
14 | virtual String getAsString() = 0;
15 | virtual void setFromString(const String &value) = 0;
16 | String getKey();
17 | void* getMemoryAddress();
18 | void setFullKey(const String fullKey);
19 | String getFullKey();
20 |
21 | };
22 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Configuration/Variable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Helpers/utils.h"
3 | #include "StringConvertibleVariable.h"
4 |
5 | template
6 | class Variable: public StringConvertibleVariable {
7 | public:
8 | ValueT* value;
9 |
10 | Variable(String key, ValueT* value, bool isPersistent): StringConvertibleVariable(value, key, isPersistent) {
11 | this->value = value;
12 | }
13 |
14 | template
15 | T* addTo(std::vector& bag) {
16 | bag.push_back(this);
17 | return (T*) this;
18 | }
19 |
20 | virtual bool isPersistentVariable() {
21 | return false;
22 | }
23 |
24 | virtual String getAsString() = 0;
25 | virtual void setFromString(const String &value) = 0;
26 |
27 | };
28 |
29 | class IntVariable: public Variable {
30 | public:
31 | IntVariable(String key, int* value, bool isPersistent): Variable(key, value, isPersistent) {}
32 |
33 | virtual String getAsString() {
34 | return String(*value);
35 | }
36 |
37 | virtual void setFromString(const String &stringValue) {
38 | *value = stringValue.toInt();
39 | }
40 |
41 | };
42 |
43 | class FloatVariable: public Variable {
44 | public:
45 | FloatVariable(String key, float* value, bool isPersistent): Variable(key, value, isPersistent) {}
46 |
47 | virtual String getAsString() {
48 | return String(*value);
49 | }
50 |
51 | virtual void setFromString(const String &stringValue) {
52 | *value = stringValue.toFloat();
53 | }
54 |
55 | };
56 |
57 | class StringVariable: public Variable {
58 | public:
59 | StringVariable(String key, String* value, bool isPersistent): Variable(key, value, isPersistent) {}
60 |
61 | virtual String getAsString() {
62 | return *value;
63 | }
64 |
65 | virtual void setFromString(const String &stringValue) {
66 | *value = stringValue;
67 | }
68 |
69 | };
70 |
71 | #define SetterOfType(T) void (*SetterPtr)(T* intance, const String& value);
72 | #define GetterOfType(T) String (*GetterPtr)(T* intance);
73 |
74 | template
75 | class GenericVariable: public Variable {
76 | public:
77 | typedef SetterOfType(T);
78 | typedef GetterOfType(T);
79 | SetterPtr setter;
80 | GetterPtr getter;
81 |
82 | GenericVariable(String key, T* value, bool isPersistent, SetterPtr setter, GetterPtr getter): Variable(key, value, isPersistent) {
83 | this->setter = setter;
84 | this->getter = getter;
85 | }
86 |
87 | virtual String getAsString() {
88 | return getter(this->value);
89 | }
90 |
91 | virtual void setFromString(const String &stringValue) {
92 | setter(this->value, stringValue);
93 | }
94 |
95 | };
96 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/ConfigurationInterface.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Bleeper/Initable.h"
4 |
5 | class ConfigurationInterface: public Initable {
6 | public:
7 | virtual void init() = 0;
8 | virtual void handle() = 0;
9 | };
10 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/ESP32/ESP32DefaultWebServer.cpp:
--------------------------------------------------------------------------------
1 | #ifdef ESP32
2 |
3 | #include "ConfigurationInterface/WebServer/ESP32/ESP32DefaultWebServer.h"
4 | #include "Bleeper/BleeperClass.h"
5 | #include "Helpers/Logger.h"
6 | #include
7 |
8 | ESP32DefaultWebServer::ESP32DefaultWebServer(int port): WebServer(port) {
9 | server = NULL;
10 | }
11 |
12 | void ESP32DefaultWebServer::init() {
13 | server = new WiFiServer(port);
14 | using std::placeholders::_1;
15 | using std::placeholders::_2;
16 | registerRoute(
17 | GET,
18 | "/",
19 | std::bind(&ESP32DefaultWebServer::handleRoot, this, _1, _2)
20 | );
21 | registerRoute(
22 | GET,
23 | "/script",
24 | std::bind(&ESP32DefaultWebServer::handleScript, this, _1, _2)
25 | );
26 | registerRoute(
27 | GET,
28 | "/style",
29 | std::bind(&ESP32DefaultWebServer::handleStyle, this, _1, _2)
30 | );
31 | registerRoute(
32 | POST,
33 | "/save",
34 | std::bind(&ESP32DefaultWebServer::handleSave, this, _1, _2)
35 | );
36 | }
37 |
38 | void ESP32DefaultWebServer::handle(){
39 | // This server only starts working when
40 | // some connection is active.
41 | // It's safe to call it multiple times.
42 | server->begin();
43 |
44 | WiFiClient client = server->available();
45 | if (!client) return;
46 | Log("New client");
47 | HTTPRequest request;
48 | while (client.connected()) {
49 | if (request.isFinished()) {
50 | handleRequest(request, client);
51 | break;
52 | }
53 | if (client.available()) {
54 | char c = client.read();
55 | request.add(c);
56 | }
57 | }
58 | client.stop();
59 | Log("Client disconnected");
60 | }
61 |
62 | void ESP32DefaultWebServer::handleRequest(HTTPRequest & request, WiFiClient & client) {
63 | RouteHandler* handler = getRequestHandler(request);
64 | if (!handler)
65 | handleError(client);
66 |
67 | (*handler)(request, client);
68 | }
69 |
70 | void ESP32DefaultWebServer::handleRoot(HTTPRequest &, WiFiClient & client){
71 | send(client, true, CONTENT_TYPE_HTML, buildPage(Bleeper.configuration.getVariables()).c_str());
72 | }
73 |
74 | void ESP32DefaultWebServer::handleScript(HTTPRequest &, WiFiClient & client){
75 | send(client, true, CONTENT_TYPE_JS, getJS());
76 | }
77 |
78 | void ESP32DefaultWebServer::handleStyle(HTTPRequest &, WiFiClient & client){
79 | send(client, true, CONTENT_TYPE_CSS, getStyle());
80 | }
81 |
82 | void ESP32DefaultWebServer::handleSave(HTTPRequest & request, WiFiClient & client){
83 | send(client, true, "", NULL);
84 | saveValues(request.getArgs());
85 | }
86 |
87 | void ESP32DefaultWebServer::handleError(WiFiClient & client) {
88 | send(client, false, "", NULL);
89 | }
90 |
91 | void ESP32DefaultWebServer::send(WiFiClient & client, bool ok, String contentType, const char* data) {
92 | client.println(ok ? "HTTP/1.1 200 OK" : "HTTP/1.1 500 Internal Server Error");
93 | if (contentType != "") client.println("Content-type:" + contentType);
94 | client.println();
95 | if (data != NULL) client.print(data);
96 | client.println();
97 | }
98 |
99 | void ESP32DefaultWebServer::registerRoute(HTTPMethod method, String route, RouteHandler handler) {
100 | router[String(method) + route] = handler;
101 | }
102 |
103 | RouteHandler* ESP32DefaultWebServer::getRequestHandler(HTTPRequest & request) {
104 | auto key = request.getMethod() + request.getRoute();
105 | if (router.find(key) == router.end())
106 | return NULL;
107 | return &router[key];
108 | }
109 |
110 | #endif // ESP32
111 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/ESP32/ESP32DefaultWebServer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef ESP32
4 |
5 | #include "Arduino.h"
6 | #include
7 | #include "ConfigurationInterface/WebServer/WebServer.h"
8 | #include "ConfigurationInterface/WebServer/ESP32/HTTPRequest.h"
9 | #include
10 | #include
11 |
12 | typedef std::function RouteHandler;
13 |
14 | class ESP32DefaultWebServer: public WebServer {
15 | protected:
16 | WiFiServer* server;
17 | std::map router;
18 | void handleRequest(HTTPRequest &, WiFiClient &);
19 | void handleRoot(HTTPRequest &, WiFiClient &);
20 | void handleScript(HTTPRequest &, WiFiClient &);
21 | void handleStyle(HTTPRequest &, WiFiClient &);
22 | void handleSave(HTTPRequest &, WiFiClient &);
23 | void handleError(WiFiClient &);
24 | void send(WiFiClient & client, bool ok, String contentType, const char* data);
25 | void registerRoute(HTTPMethod method, String route, RouteHandler handler);
26 | RouteHandler* getRequestHandler(HTTPRequest &);
27 | public:
28 | ESP32DefaultWebServer(int port);
29 | virtual void init();
30 | virtual void handle();
31 | };
32 |
33 | #endif // ESP32
34 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/ESP32/HTTPRequest.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigurationInterface/WebServer/ESP32/HTTPRequest.h"
2 | #include "Helpers/Logger.h"
3 | #include "Helpers/utils.h"
4 |
5 | void HTTPRequest::add(const char c) {
6 | if (readingData) {
7 | if ((c == '\n') || (c == '\r')) return;
8 | data += c;
9 | dataLength--;
10 | if (!dataLength) {
11 | auto pairs = splitString(data, '&');
12 | for(auto p: pairs) {
13 | auto split = splitString(p, '=');
14 | if (split.size() == 2) {
15 | args[split[0]] = split[1];
16 | }
17 | }
18 | _isFinished = true;
19 | return;
20 | }
21 | return;
22 | }
23 |
24 | if (c == '\n') {
25 | if ((line.length() == 0) && (!hasData())) {
26 | _isFinished = true;
27 | } else if (hasData()) {
28 | readingData = true;
29 | } else {
30 | if (firstLine) {
31 | if (line.startsWith("GET")) {
32 | method = GET;
33 | } else if (line.startsWith("POST")) {
34 | method = POST;
35 | } else {
36 | method = UNKNOWN;
37 | }
38 | firstLine = false;
39 | auto strings = splitString(line, ' ');
40 | if (strings.size() > 1)
41 | route = strings[1];
42 | }
43 | if (line.startsWith("Content-Length:")) {
44 | dataLength = line.substring(15).toInt();
45 | }
46 | line = "";
47 | }
48 | } else if (c != '\r') {
49 | line += c;
50 | }
51 | }
52 |
53 | bool HTTPRequest::hasData() {
54 | return (dataLength > 0);
55 | }
56 |
57 | bool HTTPRequest::isFinished() {
58 | return _isFinished;
59 | }
60 |
61 | HTTPMethod HTTPRequest::getMethod() {
62 | return method;
63 | }
64 |
65 | String HTTPRequest::getRoute() {
66 | return route;
67 | }
68 |
69 | std::map HTTPRequest::getArgs() {
70 | return args;
71 | }
72 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/ESP32/HTTPRequest.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Arduino.h"
3 | #include
4 |
5 | enum HTTPMethod {
6 | GET,
7 | POST,
8 | UNKNOWN,
9 | };
10 |
11 | class HTTPRequest {
12 | private:
13 | bool readingData = false;
14 | bool firstLine = true;
15 | int dataLength = 0;
16 | String line;
17 | HTTPMethod method;
18 | String route;
19 | String data;
20 | std::map args;
21 | bool _isFinished = false;
22 | bool hasData();
23 | public:
24 | void add(const char c);
25 | bool isFinished();
26 | HTTPMethod getMethod();
27 | String getRoute();
28 | std::map getArgs();
29 | };
30 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/ESP8266/ESP8266DefaultWebServer.cpp:
--------------------------------------------------------------------------------
1 | #ifdef ESP8266
2 |
3 | #include "Bleeper/BleeperClass.h"
4 | #include "ConfigurationInterface/WebServer/ESP8266/ESP8266DefaultWebServer.h"
5 | #include
6 | #include
7 | #include
8 | #include "Helpers/Logger.h"
9 |
10 | ESP8266DefaultWebServer::ESP8266DefaultWebServer(int port): WebServer(port) {
11 | server = NULL;
12 | }
13 |
14 | void ESP8266DefaultWebServer::init() {
15 | server = new ESP8266WebServer(port);
16 | server->on(
17 | "/", std::bind(&ESP8266DefaultWebServer::handleRoot, this)
18 | );
19 | server->on(
20 | "/save", HTTP_POST,
21 | std::bind(&ESP8266DefaultWebServer::handleSave, this)
22 | );
23 | server->on(
24 | "/script", std::bind(&ESP8266DefaultWebServer::handleScript, this)
25 | );
26 | server->on(
27 | "/style", std::bind(&ESP8266DefaultWebServer::handleStyle, this)
28 | );
29 | server->begin();
30 | }
31 |
32 | void ESP8266DefaultWebServer::handle(){
33 | server->handleClient();
34 | }
35 |
36 | void ESP8266DefaultWebServer::handleRoot(){
37 | server->send(HTTP_STATUS_OK, CONTENT_TYPE_HTML, buildPage(Bleeper.configuration.getVariables()));
38 | }
39 |
40 | void ESP8266DefaultWebServer::handleScript(){
41 | server->send_P(HTTP_STATUS_OK, CONTENT_TYPE_JS, getJS());
42 | }
43 |
44 | void ESP8266DefaultWebServer::handleStyle(){
45 | server->send_P(HTTP_STATUS_OK, CONTENT_TYPE_CSS, getStyle());
46 | }
47 |
48 | void ESP8266DefaultWebServer::handleSave(){
49 | server->send(HTTP_STATUS_OK, CONTENT_TYPE_HTML, "");
50 | std::map values;
51 | for(auto i = 0; i < server->args(); i++) {
52 | values[server->argName(i)] = server->arg(i);
53 | }
54 | saveValues(values);
55 | }
56 |
57 | #endif // ESP8266
58 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/ESP8266/ESP8266DefaultWebServer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef ESP8266
4 |
5 | #include "Arduino.h"
6 | #include
7 | #include "ConfigurationInterface/WebServer/WebServer.h"
8 |
9 | class ESP8266DefaultWebServer: public WebServer {
10 | protected:
11 | ESP8266WebServer* server;
12 | void handleRoot();
13 | void handleScript();
14 | void handleStyle();
15 | void handleSave();
16 | public:
17 | ESP8266DefaultWebServer(int port);
18 | virtual void init();
19 | virtual void handle();
20 | };
21 |
22 | #endif // ESP8366
23 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/WebPage.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | const char JS[] PROGMEM = "function onLoad(){for(var e=document.getElementById(\"cf\"),n=e.getElementsByTagName(\"input\"),t=0,a=n.length;a>t;++t)configs[t]=n[t].value;e.addEventListener(\"animationend\",function(){e.className=\"\"});var o=document.getElementsByTagName(\"h1\")[0];o.addEventListener(\"animationend\",function(){o.className=\"\"})}function animate(){document.getElementById(\"cf\").className=\"animate\",document.getElementsByTagName(\"h1\")[0].className=\"animate\"}function save(){for(var e=new XMLHttpRequest,n=document.getElementById(\"cf\").getElementsByTagName(\"input\"),t=\"\",a=configs,o=0,m=n.length;m>o;++o){var s=n[o];s.value!=configs[o]&&(t+=s.name+\"=\"+s.value+\"&\",a[o]=s.value)}t.length>0&&(e.onreadystatechange=function(){4==e.readyState&&200==e.status&&(configs=a,animate())},e.open(\"POST\",document.URL+\"save\",!0),e.setRequestHeader(\"Content-type\",\"application/x-www-form-urlencoded\"),e.send(t))}var configs=new Array;window.onload=onLoad;"
4 | ;
5 |
6 | const char CSS[] PROGMEM = "#cf label{color:#FFF;font-size:90%;font-family:'Courier New'}#cf label.p{color:#2ECC9F}h1{color:#fff;font-weight:300}h1.animate{animation:bounce 1s}body{padding-top:30px;background:#25333c;font-family:'Righteous','Titillium Web',sans-serif;font-size:18px}#cf{padding:5px 15px;margin:0 auto;max-width:400px;background:#25333c;font-weight:80}input[type=text]{font-size:80%;width:100%;padding:10px 15px;margin:12px 0;margin-bottom:20px;display:inline-block;border:1px solid #92999d;box-sizing:border-box;color:#92999d;background-color:#25333c}input:focus{outline:none!important;border:1px solid #28b089;box-shadow:0 0 3px #28b089;color:#fff}input[type=submit]{background-color:#292F33;color:#fff;padding:14px 20px;margin:8px 0;border:none;border-radius:4px;cursor:pointer}button{margin-top:20px;border:none;padding:12px 30px;font-size:90%;background:#28b089;color:#FFF;float:right;outline:none}#cf.animate input{animation:flash 1.5s cubic-bezier(0.095,0.905,0.225,0.915)}@keyframes flash{50%{outline:none!important;border:1px solid #28b089;box-shadow:0 0 3px #28b089;color:#fff;transform:scale(1.03,1.03);background-color:#30434f}}@keyframes bounce{0%,20%,60%,100%{transform:translateY(0)}40%{transform:translateY(-4px)}80%{transform:translateY(-2px)}}button:hover{background:#219E7A}button:active{background:#1D8064}div{border-radius:5px;overflow:hidden}"
7 | ;
8 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/WebServer.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigurationInterface/WebServer/WebServer.h"
2 | #include "Configuration/ConfigurationDictionary.h"
3 | #include "Bleeper/BleeperClass.h"
4 | #include "Helpers/Logger.h"
5 | #include "ConfigurationInterface/WebServer/WebPage.h"
6 |
7 | WebServer::WebServer(int port) {
8 | this->port = port;
9 | }
10 |
11 | String WebServer::buildPage(const std::vector & vars) {
12 | Log("Page requested");
13 | String first = "AP WIFI CONFIG
AP Wifi ";
14 | String middle = "";
15 | for(auto const& v: vars) {
16 | yield();
17 | String key = v->getFullKey();
18 | String value = v->getAsString();
19 | String classs = v->isPersistentVariable() ? "p" : "";
20 | middle += "" + key + " \n";
21 | middle += " \n";
22 | }
23 |
24 | yield();
25 | String last = "Save ";
26 | return first + middle + last;
27 | }
28 |
29 | void WebServer::saveValues(const std::map & args) {
30 | if (args.size() == 0) return;
31 | ConfigurationDictionary params;
32 | for(const auto & arg: args) {
33 | params[arg.first] = arg.second;
34 | }
35 | Bleeper.configuration.setFromDictionary(params);
36 | Bleeper.storage.persist();
37 | Log("Configs saved!");
38 | }
39 |
40 | const char* WebServer::getJS() {
41 | return JS;
42 | }
43 |
44 | const char* WebServer::getStyle() {
45 | return CSS;
46 | }
47 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/ConfigurationInterface/WebServer/WebServer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ConfigurationInterface/ConfigurationInterface.h"
4 | #include "Configuration/StringConvertibleVariable.h"
5 | #include
6 | #include
7 |
8 | #define HTTP_STATUS_OK 200
9 | #define HTTP_STATUS_SERVER_ERROR 500
10 | #define CONTENT_TYPE_HTML "text/html"
11 | #define CONTENT_TYPE_JS "application/javascript"
12 | #define CONTENT_TYPE_CSS "text/css"
13 |
14 | class WebServer: public ConfigurationInterface {
15 | protected:
16 | int port;
17 | public:
18 | WebServer(int port);
19 | virtual void init() = 0;
20 | virtual void handle() = 0;
21 | virtual String buildPage(const std::vector &);
22 | virtual const char* getJS();
23 | virtual const char* getStyle();
24 | virtual void saveValues(const std::map &);
25 | };
26 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Connectivity/AP.cpp:
--------------------------------------------------------------------------------
1 | #include "Connectivity/AP.h"
2 |
3 | #ifdef ESP8266
4 | #include
5 | #elif ESP32
6 | #include
7 | #endif
8 |
9 | #include "Helpers/Logger.h"
10 |
11 | void AP::connect() {
12 | Connection::connect();
13 |
14 | if (!isExclusiveConnection) {
15 | #ifdef ESP8266
16 | WiFi.mode((WiFiMode)(WiFi.getMode() | WIFI_AP));
17 | #elif ESP32
18 | WiFi.mode((WiFiMode_t)(WiFi.getMode() | WIFI_AP));
19 | #endif
20 | }
21 |
22 | WiFi.softAP("AP_HOME_NODE");
23 | Log("AP IP address: " + WiFi.softAPIP().toString());
24 | };
25 |
26 | void AP::disconnect() {
27 | Connection::disconnect();
28 | WiFi.softAPdisconnect(true);
29 | };
30 |
31 | void AP::init() {
32 | }
33 |
34 | void AP::handle() {
35 | isConnected = true;
36 | isConnecting = false;
37 | };
38 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Connectivity/AP.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Connection.h"
3 |
4 | class AP: public Connection {
5 | public:
6 | virtual void connect();
7 | virtual void disconnect();
8 | virtual void init();
9 | virtual void handle();
10 | };
11 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Connectivity/Connection.cpp:
--------------------------------------------------------------------------------
1 | #include "Connectivity/Connection.h"
2 | #include "Helpers/Logger.h"
3 |
4 | Connection::Connection() {
5 | triedToConnect = false;
6 | isExclusiveConnection = false;
7 | }
8 |
9 | void Connection::setIsExclusiveConnection(bool is) {
10 | isExclusiveConnection = is;
11 | }
12 |
13 | void Connection::connect() {
14 | triedToConnect = true;
15 | isConnecting = true;
16 | }
17 |
18 | void Connection::disconnect() {
19 | triedToConnect = false;
20 | isConnecting = false;
21 | isConnected = false;
22 | }
23 |
24 | bool Connection::connectionDidFail() {
25 | return triedToConnect && !isConnected && !isConnecting;
26 | }
27 |
28 | bool Connection::connectionDidComplete() {
29 | return triedToConnect && isConnected && !isConnecting;
30 | }
31 |
32 | void Connection::retry() {
33 | disconnect();
34 | connect();
35 | }
36 |
37 | bool Connection::wantsToRetryConnection() {
38 | return false;
39 | }
40 |
41 | Connections::Connections() {
42 |
43 | }
44 |
45 | Connections::Connections(std::vector connections) {
46 | this->connections = connections;
47 | }
48 |
49 | void Connections::handle() {};
50 |
51 | void Connections::init() {
52 | for(auto c: connections) {
53 | c->init();
54 | }
55 | };
56 |
57 | void Connections::add(Connection* c) {
58 | connections.push_back(c);
59 | }
60 |
61 | MultipleConnection::MultipleConnection(std::vector connections) : Connections(connections) {
62 | }
63 |
64 | void MultipleConnection::connect() {
65 | Connections::connect();
66 | for(Connection* c: connections) {
67 | c->setIsExclusiveConnection(false);
68 | c->connect();
69 | }
70 | }
71 |
72 | void MultipleConnection::disconnect() {
73 | Connections::disconnect();
74 | for(Connection* c: connections) {
75 | c->disconnect();
76 | }
77 | }
78 |
79 | void MultipleConnection::handle() {
80 | bool allConnectionsConnected = true;
81 | for(Connection* c: connections) {
82 | if (c->wantsToRetryConnection()) {
83 | Log("retrying connection");
84 | c->connect();
85 | }
86 | c->handle();
87 | isConnecting = isConnecting || c->isConnecting;
88 | allConnectionsConnected = allConnectionsConnected && c->isConnected;
89 | }
90 | isConnected = allConnectionsConnected;
91 | }
92 |
93 | OneOfMultipleConnection::OneOfMultipleConnection(std::vector connections) : Connections(connections) {
94 | connectionIndex = 0;
95 | betterConnectionIndex = -1;
96 | }
97 |
98 | OneOfMultipleConnection::OneOfMultipleConnection() {
99 | connectionIndex = 0;
100 | betterConnectionIndex = -1;
101 | }
102 |
103 | void OneOfMultipleConnection::connect() {
104 | Connections::connect();
105 | connections[connectionIndex]->connect();
106 | }
107 |
108 | void OneOfMultipleConnection::disconnect() {
109 | Connections::disconnect();
110 | for(Connection* c: connections) {
111 | c->disconnect();
112 | }
113 | }
114 |
115 | void OneOfMultipleConnection::disconnectFromAllExepct(int c) {
116 | for(auto i = 0; i < connections.size(); i++) {
117 | if (i != c)
118 | connections[i]->disconnect();
119 | }
120 | }
121 |
122 | void OneOfMultipleConnection::handle() {
123 | if (connections[connectionIndex]->wantsToRetryConnection()) {
124 | connections[connectionIndex]->retry();
125 | }
126 | connections[connectionIndex]->handle();
127 | isConnected = connections[connectionIndex]->isConnected;
128 | if (isConnected) {
129 | isConnecting = false;
130 | }
131 |
132 | if (connectionIndex < connections.size() - 1) {
133 | if (connections[connectionIndex]->connectionDidFail()) {
134 | Log("Connection did fail for index " + String(connectionIndex));
135 | connections[connectionIndex]->disconnect();
136 | connectionIndex = (connectionIndex + 1) % connections.size();
137 | connections[connectionIndex]->connect();
138 | return;
139 | }
140 | }
141 |
142 | if (isConnected && (connectionIndex == 0)) {
143 | return;
144 | }
145 |
146 | if (betterConnectionIndex != -1) {
147 | connections[betterConnectionIndex]->handle();
148 | if (connections[betterConnectionIndex]->connectionDidComplete()) {
149 | connections[connectionIndex]->disconnect();
150 | connectionIndex = betterConnectionIndex;
151 | betterConnectionIndex = -1;
152 | } else if (connections[betterConnectionIndex]->connectionDidFail()) {
153 | connections[betterConnectionIndex]->disconnect();
154 | betterConnectionIndex = -1;
155 | }
156 | }
157 |
158 | if (betterConnectionIndex == -1) {
159 | for(int b = 0; b < connectionIndex; b++) {
160 | if (connections[b]->wantsToRetryConnection()) {
161 | betterConnectionIndex = b;
162 | connections[b]->retry();
163 | Log("Retrying connection " + String(b));
164 | break;
165 | }
166 | }
167 | }
168 |
169 | }
170 |
171 | void OneOfMultipleConnection::retry() {
172 | Log("Retrying... " + String(connectionIndex));
173 | connectionIndex = 0;
174 | Connections::retry();
175 | }
176 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Connectivity/Connection.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include "Bleeper/Initable.h"
4 |
5 | class Connection: public Initable {
6 | protected:
7 | bool triedToConnect;
8 | bool isExclusiveConnection;
9 | public:
10 | bool isConnected;
11 | bool isConnecting;
12 |
13 | Connection();
14 | virtual void setIsExclusiveConnection(bool is);
15 | virtual void connect();
16 | virtual void disconnect();
17 | virtual void handle() = 0;
18 | virtual void init() = 0;
19 | virtual bool connectionDidFail();
20 | virtual bool connectionDidComplete();
21 | virtual void retry();
22 | virtual bool wantsToRetryConnection();
23 | };
24 |
25 | class Connections: public Connection {
26 | protected:
27 | std::vector connections;
28 | public:
29 | Connections();
30 | Connections(std::vector connections);
31 | virtual void handle();
32 | virtual void init();
33 | void add(Connection* c);
34 | };
35 |
36 | class MultipleConnection: public Connections {
37 | public:
38 | MultipleConnection(std::vector connections);
39 | virtual void connect();
40 | virtual void disconnect();
41 | virtual void handle();
42 | };
43 |
44 | class OneOfMultipleConnection: public Connections {
45 | private:
46 | int connectionIndex;
47 | int betterConnectionIndex;
48 | public:
49 | OneOfMultipleConnection(std::vector connections);
50 | OneOfMultipleConnection();
51 | virtual void connect();
52 | virtual void disconnect();
53 | void disconnectFromAllExepct(int c);
54 | virtual void handle();
55 | virtual void retry();
56 | };
57 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Connectivity/Wifi.cpp:
--------------------------------------------------------------------------------
1 | #include "Connectivity/Wifi.h"
2 |
3 | #ifdef ESP8266
4 | #include
5 | #elif ESP32
6 | #include
7 | #endif
8 |
9 | #include "Bleeper/BleeperClass.h"
10 | #include "Helpers/Logger.h"
11 | #include "Helpers/macros.h"
12 |
13 | void Wifi::printWifiStatus() {
14 | Log("SSID: " + WiFi.SSID());
15 | IPAddress ip = WiFi.localIP();
16 | Log("IP Address: " + ip.toString());
17 | }
18 |
19 | Wifi::Wifi(VariableAddress ssidAddress, VariableAddress passwordAddress) {
20 | this->ssidAddress = ssidAddress;
21 | this->passwordAddress = passwordAddress;
22 | }
23 |
24 | void Wifi::init() {
25 | auto c = Bleeper.configuration.get();
26 | guard(c, return);
27 | guard(c->isAddressValid(ssidAddress), return);
28 | guard(c->isAddressValid(passwordAddress), return);
29 |
30 | StringConvertibleVariable* ssid = c->getVariableForAddress(ssidAddress);
31 | StringConvertibleVariable* password = c->getVariableForAddress(passwordAddress);
32 | this->ssid = ssid->getAsString();
33 | ssidKey = ssid->getFullKey();
34 | this->password = password->getAsString();
35 | _wantsToRetryConnection = false;
36 | Bleeper.configuration.addObserver(this, {ssidAddress, passwordAddress});
37 | }
38 |
39 | void Wifi::onConfigurationChanged(const ConfigurationPropertyChange value) {
40 | Log("wifi settings changed...");
41 | Log("Wifi -> " + value.key + " changed from " + value.oldValue + " to " + value.newValue);
42 | if (value.key == ssidKey) {
43 | ssid = value.newValue;
44 | } else {
45 | password = value.newValue;
46 | }
47 | _wantsToRetryConnection = true;
48 | }
49 |
50 | void Wifi::connect() {
51 | Connection::connect();
52 | _wantsToRetryConnection = false;
53 | if (!isExclusiveConnection) {
54 | #ifdef ESP8266
55 | WiFi.mode((WiFiMode)(WiFi.getMode() | WIFI_STA));
56 | #elif ESP32
57 | WiFi.mode((WiFiMode_t)(WiFi.getMode() | WIFI_STA));
58 | #endif
59 | }
60 | WiFi.begin(ssid.c_str(), password.c_str());
61 | };
62 |
63 | void Wifi::disconnect() {
64 | Connection::disconnect();
65 | WiFi.disconnect(true);
66 | };
67 |
68 | void Wifi::handle() {
69 | auto status = WiFi.status();
70 | isConnected = (status == WL_CONNECTED);
71 | isConnecting = !isConnected && (status != WL_CONNECT_FAILED) && (status != WL_NO_SSID_AVAIL);
72 | if (isConnected && firstTime) {
73 | printWifiStatus();
74 | firstTime = false;
75 | }
76 | };
77 |
78 | bool Wifi::wantsToRetryConnection() {
79 | return _wantsToRetryConnection;
80 | }
81 |
82 | void Wifi::retry() {
83 | firstTime = true;
84 | WiFi.disconnect();
85 | connect();
86 | }
87 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Connectivity/Wifi.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Connection.h"
4 | #include "Observers/ConfigurationObserver.h"
5 |
6 | class Wifi: public Connection, public ConfigurationObserver {
7 | private:
8 | String ssid, password;
9 | String ssidKey;
10 | bool _wantsToRetryConnection;
11 | bool firstTime = true;
12 |
13 | VariableAddress ssidAddress;
14 | VariableAddress passwordAddress;
15 |
16 | void printWifiStatus();
17 | public:
18 | Wifi(VariableAddress ssidAddress, VariableAddress passwordAddress);
19 | virtual void init();
20 | virtual void onConfigurationChanged(const ConfigurationPropertyChange value);
21 | virtual void connect();
22 | virtual void disconnect();
23 | virtual void handle();
24 | virtual bool wantsToRetryConnection();
25 | virtual void retry();
26 | };
27 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Helpers/Logger.cpp:
--------------------------------------------------------------------------------
1 | #include "Logger.h"
2 |
3 | bool Logger::verbose = false;
4 | bool Logger::serialInitialized = false;
5 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Helpers/Logger.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Arduino.h"
3 |
4 | #define Log(msg) Logger::print(msg)
5 |
6 | class Logger {
7 | public:
8 | static bool verbose;
9 | static bool serialInitialized;
10 | static void print(String msg) {
11 | if (!serialInitialized) {
12 | Serial.begin(115200);
13 | while (!Serial) yield();
14 | serialInitialized = true;
15 | }
16 | if (verbose) {
17 | Serial.println("[Bleeper]: " + msg);
18 | }
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Helpers/macros.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define guard(condition, returnStatement) if (!(condition)) { returnStatement; }
4 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Helpers/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | std::vector splitString(String string, char delimiter){
4 | std::vector result;
5 | int lastStart = 0;
6 | for(int i = 0; i < string.length(); i++){
7 | if (string.charAt(i) == delimiter){
8 | result.push_back(string.substring(lastStart,i));
9 | lastStart = i+1;
10 | }
11 | }
12 | if (lastStart < string.length()){
13 | result.push_back(string.substring(lastStart,string.length()));
14 | }
15 | return result;
16 | }
17 |
18 | void flashLed(int led, int onMs, int offMs, int times){
19 | for(int i = 0; i < times; i++){
20 | digitalWrite(led,LOW);
21 | delay(onMs);
22 | digitalWrite(led,HIGH);
23 | delay(offMs);
24 | }
25 | }
26 |
27 | void configureLed(int led) {
28 | pinMode(led,OUTPUT);
29 | digitalWrite(led,HIGH);
30 | flashLed(led, 300,250,3);
31 | }
32 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Helpers/utils.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Arduino.h"
3 |
4 | void configureLed(int led);
5 | void flashLed(int led, int onMs, int offMs, int times);
6 | std::vector splitString(String string, char delimiter);
7 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Observers/ConfigurationObserver.cpp:
--------------------------------------------------------------------------------
1 | #include "Observers/ConfigurationObserver.h"
2 |
3 | bool ConfigurationObserver::isEnabled = true;
4 |
5 | ConfigurationObserver::ConfigurationObserver() {}
6 |
7 | void ConfigurationObserver::setFilter(std::set addressFilter) {
8 | this->addressFilter = addressFilter;
9 | }
10 |
11 | bool ConfigurationObserver::isInterestedIn(VariableAddress address) {
12 | return ConfigurationObserver::isEnabled && (addressFilter.empty() || (addressFilter.find(address) != addressFilter.end()));
13 | }
14 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Observers/ConfigurationObserver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Configuration/ConfigMap.h"
3 | #include
4 |
5 | struct ConfigurationPropertyChange {
6 | String key;
7 | String oldValue;
8 | String newValue;
9 | };
10 |
11 | class ConfigurationObserver {
12 | protected:
13 | std::set addressFilter;
14 | public:
15 | static bool isEnabled;
16 | ConfigurationObserver();
17 | void setFilter(std::set addressFilter);
18 | virtual bool isInterestedIn(VariableAddress address);
19 | virtual void onConfigurationChanged(const ConfigurationPropertyChange value) = 0;
20 | };
21 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Observers/Observable.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | template
5 | class Observable {
6 | protected:
7 | std::vector observers;
8 | public:
9 | Observer& addObserver(Observer* observer) {
10 | observers.push_back(observer);
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Storage/EEPROMHelper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include "Arduino.h"
4 | #include "Helpers/Logger.h"
5 |
6 | #define MAX_EEPROM_SIZE 4096
7 | #define FORMAT_VALUE 0x55
8 |
9 | class EEPROMHelper {
10 | public:
11 |
12 | EEPROMHelper(){
13 | EEPROM.begin(MAX_EEPROM_SIZE);
14 | byte v;
15 | EEPROM.get(0,v);
16 | if (v != FORMAT_VALUE){
17 | Log("Initializing EEPROM...");
18 | EEPROM.write(0,FORMAT_VALUE);
19 | unsigned short stringsCount = 0;
20 | EEPROM.put(1, 0);
21 | for(int i = 3; i < MAX_EEPROM_SIZE; i++)
22 | EEPROM.write(i, 0);
23 | Log("Initializing EEPROM...Done!");
24 | }
25 | EEPROM.end();
26 | delay(500);
27 | };
28 |
29 | public:
30 | std::vector readStrings() {
31 | EEPROM.begin(MAX_EEPROM_SIZE);
32 | std::vector result;
33 | unsigned short stringsCount;
34 | EEPROM.get(1, stringsCount);
35 | int addr = 3;
36 | for(auto s = 0; s < stringsCount; s++) {
37 | String res = "";
38 | for(; addr < MAX_EEPROM_SIZE; addr++){
39 | char r = char(EEPROM.read(addr));
40 | if (r == '\0')
41 | break;
42 | res += String(r);
43 | }
44 | addr++;
45 | result.push_back(res);
46 | }
47 | EEPROM.end();
48 | return result;
49 | }
50 |
51 | void writeStrings(const std::vector & strings) {
52 | EEPROM.begin(MAX_EEPROM_SIZE);
53 |
54 | unsigned short stringsCount = strings.size();
55 | EEPROM.put(1, stringsCount);
56 |
57 | int addr = 3;
58 | for(auto s: strings) {
59 | for(int i = 0; addr < MAX_EEPROM_SIZE && i < s.length(); i++, addr++){
60 | EEPROM.write(addr, s.charAt(i));
61 | }
62 | EEPROM.write(addr,'\0');
63 | addr++;
64 | }
65 |
66 | EEPROM.end();
67 | delay(500);
68 | }
69 |
70 | };
71 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Storage/SPIFFSStorage.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Bleeper/BleeperClass.h"
3 | #include "Helpers/Logger.h"
4 | #include "Helpers/utils.h"
5 |
6 | #define CONFIGS_FILE "/bleeperVars.bpr1"
7 |
8 | #ifdef ESP8266
9 | #include "FS.h"
10 | #elif ESP32
11 | #include "SPIFFS.h"
12 | #endif
13 |
14 | class SPIFFSStorage: public Storage {
15 | public:
16 | void init() {
17 | SPIFFS.begin();
18 | if (!SPIFFS.exists(CONFIGS_FILE)) {
19 | SPIFFS.format();
20 | }
21 | }
22 |
23 | void persist() {
24 | File f = SPIFFS.open(CONFIGS_FILE, "w");
25 | if (!f) {
26 | f.close();
27 | return;
28 | }
29 | std::vector persistentVars = Bleeper.configuration.getAsDictionary(true).toStrings();
30 | for(auto const & s: persistentVars) {
31 | f.print(s);
32 | f.write(0);
33 | }
34 | f.close();
35 | }
36 |
37 | void load() {
38 | File f = SPIFFS.open(CONFIGS_FILE, "r");
39 | if (!f) {
40 | f.close();
41 | persist();
42 | return;
43 | }
44 | std::vector storedVars;
45 | while (f.available()) {
46 | auto readString = f.readStringUntil('\0');
47 | storedVars.push_back(readString);
48 | }
49 | Bleeper.configuration.setFromDictionary(ConfigurationDictionary(storedVars));
50 | f.close();
51 | }
52 |
53 | };
54 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Storage/Storage.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Bleeper/Initable.h"
4 |
5 | class Storage: public Initable {
6 | public:
7 | virtual void persist() = 0;
8 | virtual void load() = 0;
9 | };
10 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/Storage/VariablesMapStorage.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Bleeper/BleeperClass.h"
3 | #include "Storage/EEPROMHelper.h"
4 |
5 | class VariablesMapStorage: public Storage {
6 | private:
7 | EEPROMHelper eeprom;
8 | public:
9 | void init() {
10 |
11 | }
12 |
13 | void persist() {
14 | std::vector persistentVars = Bleeper.configuration.getAsDictionary(true).toStrings();
15 | eeprom.writeStrings(persistentVars);
16 | }
17 |
18 | void load() {
19 | std::vector storedVars = eeprom.readStrings();
20 | if (storedVars.size() == 0) {
21 | persist();
22 | } else {
23 | Bleeper.configuration.setFromDictionary(ConfigurationDictionary(storedVars));
24 | }
25 | }
26 |
27 | };
28 |
--------------------------------------------------------------------------------
/.piolibdeps/Bleeper_ID1966/src/keywords.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/.piolibdeps/Bleeper_ID1966/src/keywords.txt
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/.gitignore:
--------------------------------------------------------------------------------
1 | tests/bin
2 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/.library.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "PubSubClient",
3 | "repository": {
4 | "url": "https://github.com/knolleary/pubsubclient.git",
5 | "type": "git"
6 | },
7 | "platforms": [
8 | "atmelavr",
9 | "atmelsam",
10 | "espressif8266",
11 | "intel_arc32",
12 | "microchippic32",
13 | "nordicnrf51",
14 | "teensy",
15 | "timsp430"
16 | ],
17 | "frameworks": [
18 | "arduino"
19 | ],
20 | "version": "2.6",
21 | "export": {
22 | "exclude": "tests"
23 | },
24 | "examples": "examples/*/*.ino",
25 | "authors": [
26 | {
27 | "maintainer": false,
28 | "name": "Nick O'Leary",
29 | "url": "https://github.com/knolleary",
30 | "email": null
31 | }
32 | ],
33 | "keywords": [
34 | "ethernet",
35 | "mqtt",
36 | "iot",
37 | "m2m"
38 | ],
39 | "homepage": "http://pubsubclient.knolleary.net",
40 | "id": 89,
41 | "description": "A client library for MQTT messaging. MQTT is a lightweight messaging protocol ideal for small devices. This library allows you to send and receive MQTT messages. It supports the latest MQTT 3.1.1 protocol and can be configured to use the older MQTT 3.1 if needed. It supports all Arduino Ethernet Client compatible hardware, including the Intel Galileo/Edison, ESP8266 and TI CC3000."
42 | }
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: cpp
3 | compiler:
4 | - g++
5 | script: cd tests && make && make test
6 | os:
7 | - linux
8 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/CHANGES.txt:
--------------------------------------------------------------------------------
1 | 2.4
2 | * Add MQTT_SOCKET_TIMEOUT to prevent it blocking indefinitely
3 | whilst waiting for inbound data
4 | * Fixed return code when publishing >256 bytes
5 |
6 | 2.3
7 | * Add publish(topic,payload,retained) function
8 |
9 | 2.2
10 | * Change code layout to match Arduino Library reqs
11 |
12 | 2.1
13 | * Add MAX_TRANSFER_SIZE def to chunk messages if needed
14 | * Reject topic/payloads that exceed MQTT_MAX_PACKET_SIZE
15 |
16 | 2.0
17 | * Add (and default to) MQTT 3.1.1 support
18 | * Fix PROGMEM handling for Intel Galileo/ESP8266
19 | * Add overloaded constructors for convenience
20 | * Add chainable setters for server/callback/client/stream
21 | * Add state function to return connack return code
22 |
23 | 1.9
24 | * Do not split MQTT packets over multiple calls to _client->write()
25 | * API change: All constructors now require an instance of Client
26 | to be passed in.
27 | * Fixed example to match 1.8 api changes - dpslwk
28 | * Added username/password support - WilHall
29 | * Added publish_P - publishes messages from PROGMEM - jobytaffey
30 |
31 | 1.8
32 | * KeepAlive interval is configurable in PubSubClient.h
33 | * Maximum packet size is configurable in PubSubClient.h
34 | * API change: Return boolean rather than int from various functions
35 | * API change: Length parameter in message callback changed
36 | from int to unsigned int
37 | * Various internal tidy-ups around types
38 | 1.7
39 | * Improved keepalive handling
40 | * Updated to the Arduino-1.0 API
41 | 1.6
42 | * Added the ability to publish a retained message
43 |
44 | 1.5
45 | * Added default constructor
46 | * Fixed compile error when used with arduino-0021 or later
47 |
48 | 1.4
49 | * Fixed connection lost handling
50 |
51 | 1.3
52 | * Fixed packet reading bug in PubSubClient.readPacket
53 |
54 | 1.2
55 | * Fixed compile error when used with arduino-0016 or later
56 |
57 |
58 | 1.1
59 | * Reduced size of library
60 | * Added support for Will messages
61 | * Clarified licensing - see LICENSE.txt
62 |
63 |
64 | 1.0
65 | * Only Quality of Service (QOS) 0 messaging is supported
66 | * The maximum message size, including header, is 128 bytes
67 | * The keepalive interval is set to 30 seconds
68 | * No support for Will messages
69 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2008-2015 Nicholas O'Leary
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/README.md:
--------------------------------------------------------------------------------
1 | # Arduino Client for MQTT
2 |
3 | This library provides a client for doing simple publish/subscribe messaging with
4 | a server that supports MQTT.
5 |
6 | ## Examples
7 |
8 | The library comes with a number of example sketches. See File > Examples > PubSubClient
9 | within the Arduino application.
10 |
11 | Full API documentation is available here: http://pubsubclient.knolleary.net
12 |
13 | ## Limitations
14 |
15 | - It can only publish QoS 0 messages. It can subscribe at QoS 0 or QoS 1.
16 | - The maximum message size, including header, is **128 bytes** by default. This
17 | is configurable via `MQTT_MAX_PACKET_SIZE` in `PubSubClient.h`.
18 | - The keepalive interval is set to 15 seconds by default. This is configurable
19 | via `MQTT_KEEPALIVE` in `PubSubClient.h`.
20 | - The client uses MQTT 3.1.1 by default. It can be changed to use MQTT 3.1 by
21 | changing value of `MQTT_VERSION` in `PubSubClient.h`.
22 |
23 |
24 | ## Compatible Hardware
25 |
26 | The library uses the Arduino Ethernet Client api for interacting with the
27 | underlying network hardware. This means it Just Works with a growing number of
28 | boards and shields, including:
29 |
30 | - Arduino Ethernet
31 | - Arduino Ethernet Shield
32 | - Arduino YUN – use the included `YunClient` in place of `EthernetClient`, and
33 | be sure to do a `Bridge.begin()` first
34 | - Arduino WiFi Shield - if you want to send packets > 90 bytes with this shield,
35 | enable the `MQTT_MAX_TRANSFER_SIZE` define in `PubSubClient.h`.
36 | - Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
37 | - TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
38 | - Intel Galileo/Edison
39 | - ESP8266
40 |
41 | The library cannot currently be used with hardware based on the ENC28J60 chip –
42 | such as the Nanode or the Nuelectronics Ethernet Shield. For those, there is an
43 | [alternative library](https://github.com/njh/NanodeMQTT) available.
44 |
45 | ## License
46 |
47 | This code is released under the MIT License.
48 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/examples/mqtt_auth/mqtt_auth.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Basic MQTT example with Authentication
3 |
4 | - connects to an MQTT server, providing username
5 | and password
6 | - publishes "hello world" to the topic "outTopic"
7 | - subscribes to the topic "inTopic"
8 | */
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | // Update these with values suitable for your network.
15 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
16 | IPAddress ip(172, 16, 0, 100);
17 | IPAddress server(172, 16, 0, 2);
18 |
19 | void callback(char* topic, byte* payload, unsigned int length) {
20 | // handle message arrived
21 | }
22 |
23 | EthernetClient ethClient;
24 | PubSubClient client(server, 1883, callback, ethClient);
25 |
26 | void setup()
27 | {
28 | Ethernet.begin(mac, ip);
29 | // Note - the default maximum packet size is 128 bytes. If the
30 | // combined length of clientId, username and password exceed this,
31 | // you will need to increase the value of MQTT_MAX_PACKET_SIZE in
32 | // PubSubClient.h
33 |
34 | if (client.connect("arduinoClient", "testuser", "testpass")) {
35 | client.publish("outTopic","hello world");
36 | client.subscribe("inTopic");
37 | }
38 | }
39 |
40 | void loop()
41 | {
42 | client.loop();
43 | }
44 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/examples/mqtt_basic/mqtt_basic.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Basic MQTT example
3 |
4 | This sketch demonstrates the basic capabilities of the library.
5 | It connects to an MQTT server then:
6 | - publishes "hello world" to the topic "outTopic"
7 | - subscribes to the topic "inTopic", printing out any messages
8 | it receives. NB - it assumes the received payloads are strings not binary
9 |
10 | It will reconnect to the server if the connection is lost using a blocking
11 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
12 | achieve the same result without blocking the main loop.
13 |
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | // Update these with values suitable for your network.
21 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
22 | IPAddress ip(172, 16, 0, 100);
23 | IPAddress server(172, 16, 0, 2);
24 |
25 | void callback(char* topic, byte* payload, unsigned int length) {
26 | Serial.print("Message arrived [");
27 | Serial.print(topic);
28 | Serial.print("] ");
29 | for (int i=0;i Preferences -> Additional Boards Manager URLs":
20 | http://arduino.esp8266.com/stable/package_esp8266com_index.json
21 | - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
22 | - Select your ESP8266 in "Tools -> Board"
23 |
24 | */
25 |
26 | #include
27 | #include
28 |
29 | // Update these with values suitable for your network.
30 |
31 | const char* ssid = "........";
32 | const char* password = "........";
33 | const char* mqtt_server = "broker.mqtt-dashboard.com";
34 |
35 | WiFiClient espClient;
36 | PubSubClient client(espClient);
37 | long lastMsg = 0;
38 | char msg[50];
39 | int value = 0;
40 |
41 | void setup() {
42 | pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
43 | Serial.begin(115200);
44 | setup_wifi();
45 | client.setServer(mqtt_server, 1883);
46 | client.setCallback(callback);
47 | }
48 |
49 | void setup_wifi() {
50 |
51 | delay(10);
52 | // We start by connecting to a WiFi network
53 | Serial.println();
54 | Serial.print("Connecting to ");
55 | Serial.println(ssid);
56 |
57 | WiFi.begin(ssid, password);
58 |
59 | while (WiFi.status() != WL_CONNECTED) {
60 | delay(500);
61 | Serial.print(".");
62 | }
63 |
64 | Serial.println("");
65 | Serial.println("WiFi connected");
66 | Serial.println("IP address: ");
67 | Serial.println(WiFi.localIP());
68 | }
69 |
70 | void callback(char* topic, byte* payload, unsigned int length) {
71 | Serial.print("Message arrived [");
72 | Serial.print(topic);
73 | Serial.print("] ");
74 | for (int i = 0; i < length; i++) {
75 | Serial.print((char)payload[i]);
76 | }
77 | Serial.println();
78 |
79 | // Switch on the LED if an 1 was received as first character
80 | if ((char)payload[0] == '1') {
81 | digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
82 | // but actually the LED is on; this is because
83 | // it is acive low on the ESP-01)
84 | } else {
85 | digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
86 | }
87 |
88 | }
89 |
90 | void reconnect() {
91 | // Loop until we're reconnected
92 | while (!client.connected()) {
93 | Serial.print("Attempting MQTT connection...");
94 | // Attempt to connect
95 | if (client.connect("ESP8266Client")) {
96 | Serial.println("connected");
97 | // Once connected, publish an announcement...
98 | client.publish("outTopic", "hello world");
99 | // ... and resubscribe
100 | client.subscribe("inTopic");
101 | } else {
102 | Serial.print("failed, rc=");
103 | Serial.print(client.state());
104 | Serial.println(" try again in 5 seconds");
105 | // Wait 5 seconds before retrying
106 | delay(5000);
107 | }
108 | }
109 | }
110 | void loop() {
111 |
112 | if (!client.connected()) {
113 | reconnect();
114 | }
115 | client.loop();
116 |
117 | long now = millis();
118 | if (now - lastMsg > 2000) {
119 | lastMsg = now;
120 | ++value;
121 | snprintf (msg, 75, "hello world #%ld", value);
122 | Serial.print("Publish message: ");
123 | Serial.println(msg);
124 | client.publish("outTopic", msg);
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/examples/mqtt_publish_in_callback/mqtt_publish_in_callback.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Publishing in the callback
3 |
4 | - connects to an MQTT server
5 | - subscribes to the topic "inTopic"
6 | - when a message is received, republishes it to "outTopic"
7 |
8 | This example shows how to publish messages within the
9 | callback function. The callback function header needs to
10 | be declared before the PubSubClient constructor and the
11 | actual callback defined afterwards.
12 | This ensures the client reference in the callback function
13 | is valid.
14 |
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | // Update these with values suitable for your network.
22 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
23 | IPAddress ip(172, 16, 0, 100);
24 | IPAddress server(172, 16, 0, 2);
25 |
26 | // Callback function header
27 | void callback(char* topic, byte* payload, unsigned int length);
28 |
29 | EthernetClient ethClient;
30 | PubSubClient client(server, 1883, callback, ethClient);
31 |
32 | // Callback function
33 | void callback(char* topic, byte* payload, unsigned int length) {
34 | // In order to republish this payload, a copy must be made
35 | // as the orignal payload buffer will be overwritten whilst
36 | // constructing the PUBLISH packet.
37 |
38 | // Allocate the correct amount of memory for the payload copy
39 | byte* p = (byte*)malloc(length);
40 | // Copy the payload to the new buffer
41 | memcpy(p,payload,length);
42 | client.publish("outTopic", p, length);
43 | // Free the memory
44 | free(p);
45 | }
46 |
47 | void setup()
48 | {
49 |
50 | Ethernet.begin(mac, ip);
51 | if (client.connect("arduinoClient")) {
52 | client.publish("outTopic","hello world");
53 | client.subscribe("inTopic");
54 | }
55 | }
56 |
57 | void loop()
58 | {
59 | client.loop();
60 | }
61 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/examples/mqtt_reconnect_nonblocking/mqtt_reconnect_nonblocking.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Reconnecting MQTT example - non-blocking
3 |
4 | This sketch demonstrates how to keep the client connected
5 | using a non-blocking reconnect function. If the client loses
6 | its connection, it attempts to reconnect every 5 seconds
7 | without blocking the main loop.
8 |
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | // Update these with values suitable for your hardware/network.
16 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
17 | IPAddress ip(172, 16, 0, 100);
18 | IPAddress server(172, 16, 0, 2);
19 |
20 | void callback(char* topic, byte* payload, unsigned int length) {
21 | // handle message arrived
22 | }
23 |
24 | EthernetClient ethClient;
25 | PubSubClient client(ethClient);
26 |
27 | long lastReconnectAttempt = 0;
28 |
29 | boolean reconnect() {
30 | if (client.connect("arduinoClient")) {
31 | // Once connected, publish an announcement...
32 | client.publish("outTopic","hello world");
33 | // ... and resubscribe
34 | client.subscribe("inTopic");
35 | }
36 | return client.connected();
37 | }
38 |
39 | void setup()
40 | {
41 | client.setServer(server, 1883);
42 | client.setCallback(callback);
43 |
44 | Ethernet.begin(mac, ip);
45 | delay(1500);
46 | lastReconnectAttempt = 0;
47 | }
48 |
49 |
50 | void loop()
51 | {
52 | if (!client.connected()) {
53 | long now = millis();
54 | if (now - lastReconnectAttempt > 5000) {
55 | lastReconnectAttempt = now;
56 | // Attempt to reconnect
57 | if (reconnect()) {
58 | lastReconnectAttempt = 0;
59 | }
60 | }
61 | } else {
62 | // Client connected
63 |
64 | client.loop();
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/examples/mqtt_stream/mqtt_stream.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Example of using a Stream object to store the message payload
3 |
4 | Uses SRAM library: https://github.com/ennui2342/arduino-sram
5 | but could use any Stream based class such as SD
6 |
7 | - connects to an MQTT server
8 | - publishes "hello world" to the topic "outTopic"
9 | - subscribes to the topic "inTopic"
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | // Update these with values suitable for your network.
18 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
19 | IPAddress ip(172, 16, 0, 100);
20 | IPAddress server(172, 16, 0, 2);
21 |
22 | SRAM sram(4, SRAM_1024);
23 |
24 | void callback(char* topic, byte* payload, unsigned int length) {
25 | sram.seek(1);
26 |
27 | // do something with the message
28 | for(uint8_t i=0; i
4 | maintainer=Nick O'Leary
5 | sentence=A client library for MQTT messaging.
6 | paragraph=MQTT is a lightweight messaging protocol ideal for small devices. This library allows you to send and receive MQTT messages. It supports the latest MQTT 3.1.1 protocol and can be configured to use the older MQTT 3.1 if needed. It supports all Arduino Ethernet Client compatible hardware, including the Intel Galileo/Edison, ESP8266 and TI CC3000.
7 | category=Communication
8 | url=http://pubsubclient.knolleary.net
9 | architectures=*
10 |
--------------------------------------------------------------------------------
/.piolibdeps/PubSubClient_ID89/src/PubSubClient.h:
--------------------------------------------------------------------------------
1 | /*
2 | PubSubClient.h - A simple client for MQTT.
3 | Nick O'Leary
4 | http://knolleary.net
5 | */
6 |
7 | #ifndef PubSubClient_h
8 | #define PubSubClient_h
9 |
10 | #include
11 | #include "IPAddress.h"
12 | #include "Client.h"
13 | #include "Stream.h"
14 |
15 | #define MQTT_VERSION_3_1 3
16 | #define MQTT_VERSION_3_1_1 4
17 |
18 | // MQTT_VERSION : Pick the version
19 | //#define MQTT_VERSION MQTT_VERSION_3_1
20 | #ifndef MQTT_VERSION
21 | #define MQTT_VERSION MQTT_VERSION_3_1_1
22 | #endif
23 |
24 | // MQTT_MAX_PACKET_SIZE : Maximum packet size
25 | #ifndef MQTT_MAX_PACKET_SIZE
26 | #define MQTT_MAX_PACKET_SIZE 128
27 | #endif
28 |
29 | // MQTT_KEEPALIVE : keepAlive interval in Seconds
30 | #ifndef MQTT_KEEPALIVE
31 | #define MQTT_KEEPALIVE 15
32 | #endif
33 |
34 | // MQTT_SOCKET_TIMEOUT: socket timeout interval in Seconds
35 | #ifndef MQTT_SOCKET_TIMEOUT
36 | #define MQTT_SOCKET_TIMEOUT 15
37 | #endif
38 |
39 | // MQTT_MAX_TRANSFER_SIZE : limit how much data is passed to the network client
40 | // in each write call. Needed for the Arduino Wifi Shield. Leave undefined to
41 | // pass the entire MQTT packet in each write call.
42 | //#define MQTT_MAX_TRANSFER_SIZE 80
43 |
44 | // Possible values for client.state()
45 | #define MQTT_CONNECTION_TIMEOUT -4
46 | #define MQTT_CONNECTION_LOST -3
47 | #define MQTT_CONNECT_FAILED -2
48 | #define MQTT_DISCONNECTED -1
49 | #define MQTT_CONNECTED 0
50 | #define MQTT_CONNECT_BAD_PROTOCOL 1
51 | #define MQTT_CONNECT_BAD_CLIENT_ID 2
52 | #define MQTT_CONNECT_UNAVAILABLE 3
53 | #define MQTT_CONNECT_BAD_CREDENTIALS 4
54 | #define MQTT_CONNECT_UNAUTHORIZED 5
55 |
56 | #define MQTTCONNECT 1 << 4 // Client request to connect to Server
57 | #define MQTTCONNACK 2 << 4 // Connect Acknowledgment
58 | #define MQTTPUBLISH 3 << 4 // Publish message
59 | #define MQTTPUBACK 4 << 4 // Publish Acknowledgment
60 | #define MQTTPUBREC 5 << 4 // Publish Received (assured delivery part 1)
61 | #define MQTTPUBREL 6 << 4 // Publish Release (assured delivery part 2)
62 | #define MQTTPUBCOMP 7 << 4 // Publish Complete (assured delivery part 3)
63 | #define MQTTSUBSCRIBE 8 << 4 // Client Subscribe request
64 | #define MQTTSUBACK 9 << 4 // Subscribe Acknowledgment
65 | #define MQTTUNSUBSCRIBE 10 << 4 // Client Unsubscribe request
66 | #define MQTTUNSUBACK 11 << 4 // Unsubscribe Acknowledgment
67 | #define MQTTPINGREQ 12 << 4 // PING Request
68 | #define MQTTPINGRESP 13 << 4 // PING Response
69 | #define MQTTDISCONNECT 14 << 4 // Client is Disconnecting
70 | #define MQTTReserved 15 << 4 // Reserved
71 |
72 | #define MQTTQOS0 (0 << 1)
73 | #define MQTTQOS1 (1 << 1)
74 | #define MQTTQOS2 (2 << 1)
75 |
76 | #ifdef ESP8266
77 | #include
78 | #define MQTT_CALLBACK_SIGNATURE std::function callback
79 | #else
80 | #define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int)
81 | #endif
82 |
83 | class PubSubClient {
84 | private:
85 | Client* _client;
86 | uint8_t buffer[MQTT_MAX_PACKET_SIZE];
87 | uint16_t nextMsgId;
88 | unsigned long lastOutActivity;
89 | unsigned long lastInActivity;
90 | bool pingOutstanding;
91 | MQTT_CALLBACK_SIGNATURE;
92 | uint16_t readPacket(uint8_t*);
93 | boolean readByte(uint8_t * result);
94 | boolean readByte(uint8_t * result, uint16_t * index);
95 | boolean write(uint8_t header, uint8_t* buf, uint16_t length);
96 | uint16_t writeString(const char* string, uint8_t* buf, uint16_t pos);
97 | IPAddress ip;
98 | const char* domain;
99 | uint16_t port;
100 | Stream* stream;
101 | int _state;
102 | public:
103 | PubSubClient();
104 | PubSubClient(Client& client);
105 | PubSubClient(IPAddress, uint16_t, Client& client);
106 | PubSubClient(IPAddress, uint16_t, Client& client, Stream&);
107 | PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
108 | PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
109 | PubSubClient(uint8_t *, uint16_t, Client& client);
110 | PubSubClient(uint8_t *, uint16_t, Client& client, Stream&);
111 | PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
112 | PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
113 | PubSubClient(const char*, uint16_t, Client& client);
114 | PubSubClient(const char*, uint16_t, Client& client, Stream&);
115 | PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
116 | PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
117 |
118 | PubSubClient& setServer(IPAddress ip, uint16_t port);
119 | PubSubClient& setServer(uint8_t * ip, uint16_t port);
120 | PubSubClient& setServer(const char * domain, uint16_t port);
121 | PubSubClient& setCallback(MQTT_CALLBACK_SIGNATURE);
122 | PubSubClient& setClient(Client& client);
123 | PubSubClient& setStream(Stream& stream);
124 |
125 | boolean connect(const char* id);
126 | boolean connect(const char* id, const char* user, const char* pass);
127 | boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
128 | boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
129 | void disconnect();
130 | boolean publish(const char* topic, const char* payload);
131 | boolean publish(const char* topic, const char* payload, boolean retained);
132 | boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
133 | boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
134 | boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
135 | boolean subscribe(const char* topic);
136 | boolean subscribe(const char* topic, uint8_t qos);
137 | boolean unsubscribe(const char* topic);
138 | boolean loop();
139 | boolean connected();
140 | int state();
141 | };
142 |
143 |
144 | #endif
145 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/.gitignore:
--------------------------------------------------------------------------------
1 | # Object files
2 | *.o
3 | *.ko
4 | *.obj
5 | *.elf
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Libraries
12 | *.lib
13 | *.a
14 | *.la
15 | *.lo
16 |
17 | # Shared objects (inc. Windows DLLs)
18 | *.dll
19 | *.so
20 | *.so.*
21 | *.dylib
22 |
23 | # Executables
24 | *.exe
25 | *.out
26 | *.app
27 | *.i*86
28 | *.x86_64
29 | *.hex
30 |
31 | # Debug files
32 | *.dSYM/
33 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/.library.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "Arduino Temp & Humidity Sensors for DHT11 and DHT22.",
3 | "repository": {
4 | "url": "https://github.com/winlinvip/SimpleDHT",
5 | "type": "git"
6 | },
7 | "platforms": [
8 | "atmelavr",
9 | "atmelsam",
10 | "espressif32",
11 | "espressif8266",
12 | "intel_arc32",
13 | "microchippic32",
14 | "nordicnrf51",
15 | "nordicnrf52",
16 | "ststm32",
17 | "teensy",
18 | "timsp430"
19 | ],
20 | "export": {
21 | "exclude": [
22 | "extras",
23 | "docs",
24 | "tests",
25 | "test",
26 | "*.doxyfile",
27 | "*.pdf"
28 | ],
29 | "include": null
30 | },
31 | "authors": [
32 | {
33 | "maintainer": true,
34 | "name": "Winlin",
35 | "url": null,
36 | "email": "winlin@vip.126.com"
37 | }
38 | ],
39 | "keywords": [
40 | "sensors"
41 | ],
42 | "id": 849,
43 | "name": "SimpleDHT",
44 | "frameworks": [
45 | "arduino"
46 | ],
47 | "version": "1.0.8",
48 | "homepage": null
49 | }
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016-2017 winlin
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 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/README.md:
--------------------------------------------------------------------------------
1 | # SimpleDHT
2 |
3 | Simple, Stable and Fast Arduino Temp & Humidity Sensors for
4 | [DHT11 and DHT22](http://learn.adafruit.com/dht).
5 |
6 | 1. Simple: Simple C++ code with lots of comments.
7 | 1. Stable: Strictly follow the standard DHT protocol.
8 | 1. Fast: Support 0.5HZ(DHT22) or 1HZ(DHT11) sampling rate.
9 |
10 | ## Usage
11 |
12 | To use this library:
13 |
14 | 1. Download the zip from specified version: https://github.com/winlinvip/SimpleDHT/releases
15 | 2. Import to Arduino: Arduino => Sketch => Include Library => Add .ZIP Library...
16 | 3. Open example: Arduino => File => Examples => SimpleDHT => DHT11Default
17 | 4. Connect the DHT11 and Upload program to Arduino.
18 | 5. Open the Serial Window of Arduino IDE, we got the result as following.
19 |
20 | ```
21 | =================================
22 | Sample DHT11...
23 | Sample OK: 19 *C, 31 H
24 | =================================
25 | Sample DHT11...
26 | Sample OK: 19 *C, 31 H
27 | =================================
28 | ```
29 |
30 | > Remark: For DHT11, no more than 1 Hz sampling rate (once every second).
31 |
32 | > Remark: For DHT22, no more than 0.5 Hz sampling rate (once every 2 seconds).
33 |
34 | ## Sensors
35 |
36 | - [x] DHT11, The [product](https://www.adafruit.com/product/386), [datasheet](https://akizukidenshi.com/download/ds/aosong/DHT11.pdf) and [example](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT11Default), 1HZ sampling rate.
37 | - [x] DHT22, The [product](https://www.adafruit.com/product/385), [datasheet](http://akizukidenshi.com/download/ds/aosong/AM2302.pdf) and [example](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT22Default), 0.5Hz sampling rate.
38 |
39 | ## Examples
40 |
41 | This library including the following examples:
42 |
43 | 1. [DHT11Default](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT11Default): Use DHT11 to sample.
44 | 1. [DHT11WithRawBits](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT11WithRawBits): Use DHT11 to sample and get the 40bits RAW data.
45 | 1. [DHT11ErrCount](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT11ErrCount): Use DHT11 to sample and stat the success rate.
46 | 1. [DHT22Default](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT22Default): Use DHT22 to sample.
47 | 1. [DHT22WithRawBits](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT22WithRawBits): Use DHT22 to sample and get the 40bits RAW data.
48 | 1. [DHT22Integer](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT22Integer): Use DHT22 to sample and ignore the fractional data.
49 | 1. [DHT22ErrCount](https://github.com/winlinvip/SimpleDHT/tree/master/examples/DHT22ErrCount): Use DHT22 to sample and stat the success rate.
50 | 1. [TwoSensorsDefault](https://github.com/winlinvip/SimpleDHT/tree/master/examples/TwoSensorsDefault): Use two DHT11 to sample.
51 |
52 | ## Links
53 |
54 | 1. [adafruit/DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library)
55 | 1. [Arduino #4469: Add SimpleDHT library.](https://github.com/arduino/Arduino/issues/4469)
56 | 1. [DHT11 datasheet and protocol.](https://akizukidenshi.com/download/ds/aosong/DHT11.pdf)
57 | 1. [DHT22 datasheet and protoocl.](http://akizukidenshi.com/download/ds/aosong/AM2302.pdf)
58 |
59 | Winlin 2016.1
60 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/SimpleDHT.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2016-2017 winlin
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #include "SimpleDHT.h"
26 |
27 | int SimpleDHT::read(int pin, byte* ptemperature, byte* phumidity, byte pdata[40]) {
28 | int ret = SimpleDHTErrSuccess;
29 |
30 | float temperature = 0;
31 | float humidity = 0;
32 | if ((ret = read2(pin, &temperature, &humidity, pdata)) != SimpleDHTErrSuccess) {
33 | return ret;
34 | }
35 |
36 | if (ptemperature) {
37 | *ptemperature = (byte)(int)temperature;
38 | }
39 |
40 | if (phumidity) {
41 | *phumidity = (byte)(int)humidity;
42 | }
43 |
44 | return ret;
45 | }
46 |
47 | int SimpleDHT::confirm(int pin, int us, byte level) {
48 | int cnt = us / 10;
49 | if ((us % 10) > 0) {
50 | cnt++;
51 | }
52 |
53 | bool ok = false;
54 | for (int i = 0; i < cnt; i++) {
55 | delayMicroseconds(10);
56 |
57 | if (digitalRead(pin) != level) {
58 | ok = true;
59 | break;
60 | }
61 | }
62 |
63 | if (!ok) {
64 | return -1;
65 | }
66 | return SimpleDHTErrSuccess;
67 | }
68 |
69 | byte SimpleDHT::bits2byte(byte data[8]) {
70 | byte v = 0;
71 | for (int i = 0; i < 8; i++) {
72 | v += data[i] << (7 - i);
73 | }
74 | return v;
75 | }
76 |
77 | int SimpleDHT::parse(byte data[40], short* ptemperature, short* phumidity) {
78 | short humidity = bits2byte(data);
79 | short humidity2 = bits2byte(data + 8);
80 | short temperature = bits2byte(data + 16);
81 | short temperature2 = bits2byte(data + 24);
82 | byte check = bits2byte(data + 32);
83 | byte expect = (byte)humidity + (byte)humidity2 + (byte)temperature + (byte)temperature2;
84 | if (check != expect) {
85 | return SimpleDHTErrDataChecksum;
86 | }
87 |
88 | *ptemperature = temperature<<8 | temperature2;
89 | *phumidity = humidity<<8 | humidity2;
90 |
91 | return SimpleDHTErrSuccess;
92 | }
93 |
94 | int SimpleDHT11::read2(int pin, float* ptemperature, float* phumidity, byte pdata[40]) {
95 | int ret = SimpleDHTErrSuccess;
96 |
97 | byte data[40] = {0};
98 | if ((ret = sample(pin, data)) != SimpleDHTErrSuccess) {
99 | return ret;
100 | }
101 |
102 | short temperature = 0;
103 | short humidity = 0;
104 | if ((ret = parse(data, &temperature, &humidity)) != SimpleDHTErrSuccess) {
105 | return ret;
106 | }
107 |
108 | if (pdata) {
109 | memcpy(pdata, data, 40);
110 | }
111 | if (ptemperature) {
112 | *ptemperature = (int)(temperature>>8);
113 | }
114 | if (phumidity) {
115 | *phumidity = (int)(humidity>>8);
116 | }
117 |
118 | // For example, when remove the data line, it will be success with zero data.
119 | if (temperature == 0 && humidity == 0) {
120 | return SimpleDHTErrZeroSamples;
121 | }
122 |
123 | return ret;
124 | }
125 |
126 | int SimpleDHT11::sample(int pin, byte data[40]) {
127 | // empty output data.
128 | memset(data, 0, 40);
129 |
130 | // According to protocol: https://akizukidenshi.com/download/ds/aosong/DHT11.pdf
131 | // notify DHT11 to start:
132 | // 1. PULL LOW 20ms.
133 | // 2. PULL HIGH 20-40us.
134 | // 3. SET TO INPUT.
135 | pinMode(pin, OUTPUT);
136 | digitalWrite(pin, LOW);
137 | delay(20);
138 | digitalWrite(pin, HIGH);
139 | pinMode(pin, INPUT);
140 | delayMicroseconds(30);
141 | // DHT11 starting:
142 | // 1. PULL LOW 80us
143 | // 2. PULL HIGH 80us
144 | if (confirm(pin, 80, LOW)) {
145 | return SimpleDHTErrStartLow;
146 | }
147 | if (confirm(pin, 80, HIGH)) {
148 | return SimpleDHTErrStartHigh;
149 | }
150 |
151 | // DHT11 data transmite:
152 | // 1. 1bit start, PULL LOW 50us
153 | // 2. PULL HIGH 26-28us, bit(0)
154 | // 3. PULL HIGH 70us, bit(1)
155 | for (int j = 0; j < 40; j++) {
156 | if (confirm(pin, 50, LOW)) {
157 | return SimpleDHTErrDataLow;
158 | }
159 |
160 | // read a bit, should never call method,
161 | // for the method call use more than 20us,
162 | // so it maybe failed to detect the bit0.
163 | bool ok = false;
164 | int tick = 0;
165 | for (int i = 0; i < 8; i++, tick++) {
166 | if (digitalRead(pin) != HIGH) {
167 | ok = true;
168 | break;
169 | }
170 | delayMicroseconds(10);
171 | }
172 | if (!ok) {
173 | return SimpleDHTErrDataRead;
174 | }
175 | data[j] = (tick > 3? 1:0);
176 | }
177 |
178 | // DHT11 EOF:
179 | // 1. PULL LOW 50us.
180 | if (confirm(pin, 50, LOW)) {
181 | return SimpleDHTErrDataEOF;
182 | }
183 |
184 | return SimpleDHTErrSuccess;
185 | }
186 |
187 | int SimpleDHT22::read2(int pin, float* ptemperature, float* phumidity, byte pdata[40]) {
188 | int ret = SimpleDHTErrSuccess;
189 |
190 | byte data[40] = {0};
191 | if ((ret = sample(pin, data)) != SimpleDHTErrSuccess) {
192 | return ret;
193 | }
194 |
195 | short temperature = 0;
196 | short humidity = 0;
197 | if ((ret = parse(data, &temperature, &humidity)) != SimpleDHTErrSuccess) {
198 | return ret;
199 | }
200 |
201 | if (pdata) {
202 | memcpy(pdata, data, 40);
203 | }
204 | if (ptemperature) {
205 | *ptemperature = (float)((temperature & 0x8000 ? -1 : 1) * (temperature & 0x7FFF)) / 10.0;
206 | }
207 | if (phumidity) {
208 | *phumidity = (float)humidity / 10.0;
209 | }
210 |
211 | return ret;
212 | }
213 |
214 | int SimpleDHT22::sample(int pin, byte data[40]) {
215 | // empty output data.
216 | memset(data, 0, 40);
217 |
218 | // According to protocol: http://akizukidenshi.com/download/ds/aosong/AM2302.pdf
219 | // notify DHT11 to start:
220 | // 1. T(be), PULL LOW 1ms(0.8-20ms).
221 | // 2. T(go), PULL HIGH 30us(20-200us), use 40us.
222 | // 3. SET TO INPUT.
223 | pinMode(pin, OUTPUT);
224 | digitalWrite(pin, LOW);
225 | delayMicroseconds(1000);
226 | digitalWrite(pin, HIGH);
227 | pinMode(pin, INPUT);
228 | delayMicroseconds(40);
229 |
230 | // DHT11 starting:
231 | // 1. T(rel), PULL LOW 80us(75-85us), use 90us.
232 | // 2. T(reh), PULL HIGH 80us(75-85us), use 90us.
233 | if (confirm(pin, 90, LOW)) {
234 | return SimpleDHTErrStartLow;
235 | }
236 | if (confirm(pin, 90, HIGH)) {
237 | return SimpleDHTErrStartHigh;
238 | }
239 |
240 | // DHT11 data transmite:
241 | // 1. T(LOW), 1bit start, PULL LOW 50us(48-55us), use 60us.
242 | // 2. T(H0), PULL HIGH 26us(22-30us), bit(0)
243 | // 3. T(H1), PULL HIGH 70us(68-75us), bit(1)
244 | for (int j = 0; j < 40; j++) {
245 | if (confirm(pin, 60, LOW)) {
246 | return SimpleDHTErrDataLow;
247 | }
248 |
249 | // read a bit, should never call method,
250 | // for the method call use more than 20us,
251 | // so it maybe failed to detect the bit0.
252 | bool ok = false;
253 | int tick = 0;
254 | for (int i = 0; i < 8; i++, tick++) {
255 | if (digitalRead(pin) != HIGH) {
256 | ok = true;
257 | break;
258 | }
259 | delayMicroseconds(10);
260 | }
261 | if (!ok) {
262 | return SimpleDHTErrDataRead;
263 | }
264 | data[j] = (tick > 3? 1:0);
265 | }
266 |
267 | // DHT11 EOF:
268 | // 1. T(en), PULL LOW 50us(45-55us), use 60us.
269 | if (confirm(pin, 60, LOW)) {
270 | return SimpleDHTErrDataEOF;
271 | }
272 |
273 | return SimpleDHTErrSuccess;
274 | }
275 |
276 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/SimpleDHT.h:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2016-2017 winlin
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #ifndef __SIMPLE_DHT_H
26 | #define __SIMPLE_DHT_H
27 |
28 | #include
29 |
30 | // Success.
31 | #define SimpleDHTErrSuccess 0
32 | // Error to wait for start low signal.
33 | #define SimpleDHTErrStartLow 100
34 | // Error to wait for start high signal.
35 | #define SimpleDHTErrStartHigh 101
36 | // Error to wait for data start low signal.
37 | #define SimpleDHTErrDataLow 102
38 | // Error to wait for data read signal.
39 | #define SimpleDHTErrDataRead 103
40 | // Error to wait for data EOF signal.
41 | #define SimpleDHTErrDataEOF 104
42 | // Error to validate the checksum.
43 | #define SimpleDHTErrDataChecksum 105
44 | // Error when temperature and humidity are zero, it shouldn't happen.
45 | #define SimpleDHTErrZeroSamples 106
46 |
47 | class SimpleDHT {
48 | public:
49 | // to read from dht11 or dht22.
50 | // @param pin the DHT11 pin.
51 | // @param ptemperature output, NULL to igore. In Celsius.
52 | // @param phumidity output, NULL to ignore.
53 | // For DHT11, in H, such as 35H.
54 | // For DHT22, in RH%, such as 53%RH.
55 | // @param pdata output 40bits sample, NULL to ignore.
56 | // @remark the min delay for this method is 1s(DHT11) or 2s(DHT22).
57 | // @return SimpleDHTErrSuccess is success; otherwise, failed.
58 | virtual int read(int pin, byte* ptemperature, byte* phumidity, byte pdata[40]);
59 | // to get a more accurate data.
60 | // @remark it's available for dht22. for dht11, it's the same of read().
61 | virtual int read2(int pin, float* ptemperature, float* phumidity, byte pdata[40]) = 0;
62 | protected:
63 | // confirm the OUTPUT is level in us,
64 | // for example, when DHT11 start sample, it will
65 | // 1. PULL LOW 80us, call confirm(pin, 80, LOW)
66 | // 2. PULL HIGH 80us, call confirm(pin, 80, HIGH)
67 | // @return 0 success; oterwise, error.
68 | // @remark should never used to read bits,
69 | // for function call use more time, maybe never got bit0.
70 | // @remark please use simple_dht11_read().
71 | virtual int confirm(int pin, int us, byte level);
72 | // @data the bits of a byte.
73 | // @remark please use simple_dht11_read().
74 | virtual byte bits2byte(byte data[8]);
75 | // read temperature and humidity from dht11.
76 | // @param pin the pin for DHT11, for example, 2.
77 | // @param data a byte[40] to read bits to 5bytes.
78 | // @return 0 success; otherwise, error.
79 | // @remark please use simple_dht11_read().
80 | virtual int sample(int pin, byte data[40]) = 0;
81 | // parse the 40bits data to temperature and humidity.
82 | // @remark please use simple_dht11_read().
83 | virtual int parse(byte data[40], short* ptemperature, short* phumidity);
84 | };
85 |
86 | /*
87 | Simple DHT11
88 |
89 | Simple, Stable and Fast DHT11 library.
90 |
91 | The circuit:
92 | * VCC: 5V or 3V
93 | * GND: GND
94 | * DATA: Digital ping, for instance 2.
95 |
96 | 23 Jan 2016 By winlin
97 |
98 | https://github.com/winlinvip/SimpleDHT#usage
99 | https://akizukidenshi.com/download/ds/aosong/DHT11.pdf
100 | https://cdn-shop.adafruit.com/datasheets/DHT11-chinese.pdf
101 |
102 | */
103 | class SimpleDHT11 : public SimpleDHT {
104 | public:
105 | virtual int read2(int pin, float* ptemperature, float* phumidity, byte pdata[40]);
106 | protected:
107 | virtual int sample(int pin, byte data[40]);
108 | };
109 |
110 | /*
111 | Simple DHT11
112 |
113 | Simple, Stable and Fast DHT11 library.
114 |
115 | The circuit:
116 | * VCC: 5V or 3V
117 | * GND: GND
118 | * DATA: Digital ping, for instance 2.
119 |
120 | 3 Jun 2017 By winlin
121 |
122 | https://github.com/winlinvip/SimpleDHT#usage
123 | http://akizukidenshi.com/download/ds/aosong/AM2302.pdf
124 | https://cdn-shop.adafruit.com/datasheets/DHT22.pdf
125 |
126 | */
127 | class SimpleDHT22 : public SimpleDHT {
128 | public:
129 | virtual int read2(int pin, float* ptemperature, float* phumidity, byte pdata[40]);
130 | protected:
131 | virtual int sample(int pin, byte data[40]);
132 | };
133 |
134 | #endif
135 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT11Default/DHT11Default.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT11,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT11 = 2;
8 | SimpleDHT11 dht11;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT11...");
18 |
19 | // read without samples.
20 | byte temperature = 0;
21 | byte humidity = 0;
22 | int err = SimpleDHTErrSuccess;
23 | if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
24 | Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
25 | return;
26 | }
27 |
28 | Serial.print("Sample OK: ");
29 | Serial.print((int)temperature); Serial.print(" *C, ");
30 | Serial.print((int)humidity); Serial.println(" H");
31 |
32 | // DHT11 sampling rate is 1HZ.
33 | delay(1500);
34 | }
35 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT11ErrCount/DHT11ErrCount.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT11,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT11 = 2;
8 | SimpleDHT11 dht11;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT11 with error count");
18 |
19 | int cnt = 0;
20 | int err_cnt = 0;
21 | for (;;) {
22 | cnt++;
23 |
24 | byte temperature = 0;
25 | byte humidity = 0;
26 | int err = SimpleDHTErrSuccess;
27 | if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
28 | Serial.print("Read DHT11 failed, err="); Serial.println(err);err_cnt++;
29 | }
30 |
31 | Serial.print("DHT11, ");
32 | Serial.print((int)temperature); Serial.print(" *C, ");
33 | Serial.print((int)humidity); Serial.print(" H");
34 | Serial.print(", total: "); Serial.print(cnt);
35 | Serial.print(", err: "); Serial.print(err_cnt);
36 | Serial.print(", success rate: "); Serial.print((cnt - err_cnt) * 100.0 / (float)cnt); Serial.println("%");
37 |
38 | delay(1500);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT11WithRawBits/DHT11WithRawBits.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT11,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT11 = 2;
8 | SimpleDHT11 dht11;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT11 with RAW bits...");
18 |
19 | // read with raw sample data.
20 | byte temperature = 0;
21 | byte humidity = 0;
22 | byte data[40] = {0};
23 | int err = SimpleDHTErrSuccess;
24 | if ((err = dht11.read(pinDHT11, &temperature, &humidity, data)) != SimpleDHTErrSuccess) {
25 | Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
26 | return;
27 | }
28 |
29 | Serial.print("Sample RAW Bits: ");
30 | for (int i = 0; i < 40; i++) {
31 | Serial.print((int)data[i]);
32 | if (i > 0 && ((i + 1) % 4) == 0) {
33 | Serial.print(' ');
34 | }
35 | }
36 | Serial.println("");
37 |
38 | Serial.print("Sample OK: ");
39 | Serial.print((int)temperature); Serial.print(" *C, ");
40 | Serial.print((int)humidity); Serial.println(" H");
41 |
42 | // DHT11 sampling rate is 1HZ.
43 | delay(1500);
44 | }
45 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT22Default/DHT22Default.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT22,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT22 = 2;
8 | SimpleDHT22 dht22;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT22...");
18 |
19 | // read without samples.
20 | // @remark We use read2 to get a float data, such as 10.1*C
21 | // if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
22 | float temperature = 0;
23 | float humidity = 0;
24 | int err = SimpleDHTErrSuccess;
25 | if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
26 | Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
27 | return;
28 | }
29 |
30 | Serial.print("Sample OK: ");
31 | Serial.print((float)temperature); Serial.print(" *C, ");
32 | Serial.print((float)humidity); Serial.println(" RH%");
33 |
34 | // DHT22 sampling rate is 0.5HZ.
35 | delay(2500);
36 | }
37 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT22ErrCount/DHT22ErrCount.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT22,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT22 = 2;
8 | SimpleDHT22 dht22;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT22 with error count");
18 |
19 | int cnt = 0;
20 | int err_cnt = 0;
21 | for (;;) {
22 | cnt++;
23 |
24 | float temperature = 0;
25 | float humidity = 0;
26 | int err = SimpleDHTErrSuccess;
27 | if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
28 | Serial.print("Read DHT22 failed, err="); Serial.println(err);err_cnt++;
29 | }
30 |
31 | Serial.print((float)temperature); Serial.print(" *C, ");
32 | Serial.print((float)humidity); Serial.print(" RH%");
33 | Serial.print(", total: "); Serial.print(cnt);
34 | Serial.print(", err: "); Serial.print(err_cnt);
35 | Serial.print(", success rate: "); Serial.print((cnt - err_cnt) * 100.0 / (float)cnt); Serial.println("%");
36 |
37 | delay(2500);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT22Integer/DHT22Integer.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT22,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT22 = 2;
8 | SimpleDHT22 dht22;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT22...");
18 |
19 | // read without samples.
20 | byte temperature = 0;
21 | byte humidity = 0;
22 | int err = SimpleDHTErrSuccess;
23 | if ((err = dht22.read(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
24 | Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
25 | return;
26 | }
27 |
28 | Serial.print("Sample OK: ");
29 | Serial.print((int)temperature); Serial.print(" *C, ");
30 | Serial.print((int)humidity); Serial.println(" RH%");
31 |
32 | // DHT22 sampling rate is 0.5HZ.
33 | delay(2500);
34 | }
35 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/DHT22WithRawBits/DHT22WithRawBits.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // for DHT22,
4 | // VCC: 5V or 3V
5 | // GND: GND
6 | // DATA: 2
7 | int pinDHT22 = 2;
8 | SimpleDHT22 dht22;
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | }
13 |
14 | void loop() {
15 | // start working...
16 | Serial.println("=================================");
17 | Serial.println("Sample DHT22 with RAW bits...");
18 |
19 | // read with raw sample data.
20 | // @remark We use read2 to get a float data, such as 10.1*C
21 | // if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
22 | float temperature = 0;
23 | float humidity = 0;
24 | byte data[40] = {0};
25 | int err = SimpleDHTErrSuccess;
26 | if ((err = dht22.read2(pinDHT22, &temperature, &humidity, data)) != SimpleDHTErrSuccess) {
27 | Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
28 | return;
29 | }
30 |
31 | Serial.print("Sample RAW Bits: ");
32 | for (int i = 0; i < 40; i++) {
33 | Serial.print((int)data[i]);
34 | if (i > 0 && ((i + 1) % 4) == 0) {
35 | Serial.print(' ');
36 | }
37 | }
38 | Serial.println("");
39 |
40 | Serial.print("Sample OK: ");
41 | Serial.print((float)temperature); Serial.print(" *C, ");
42 | Serial.print((float)humidity); Serial.println(" RH%");
43 |
44 | // DHT22 sampling rate is 0.5HZ.
45 | delay(2500);
46 | }
47 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/examples/TwoSensorsDefault/TwoSensorsDefault.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // Created by santosomar Ωr using SimpleDHT library to read data from two DHT11 sensors
4 | // for DHT11,
5 | // VCC: 5V or 3V
6 | // GND: GND
7 | // SENSOR 1 is in Digital Data pin: 2
8 | // SENSOR 1 is in Digital Data pin: 2
9 |
10 | int dataPinSensor1 = 2;
11 | int dataPinSensor2 = 4;
12 | SimpleDHT11 dht11;
13 |
14 | void setup() {
15 | Serial.begin(115200);
16 | }
17 |
18 | void loop() {
19 | // Reading data from sensor 1...
20 | Serial.println("=================================");
21 |
22 | // Reading data from sensor 1...
23 | Serial.println("Getting data from sensor 1...");
24 |
25 | // read without samples.
26 | byte temperature = 0;
27 | byte humidity = 0;
28 | int err = SimpleDHTErrSuccess;
29 | if ((err = dht11.read(dataPinSensor1, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
30 | Serial.print("Communication error with Sensor 1, err="); Serial.println(err);delay(1000);
31 | return;
32 | }
33 |
34 | // converting Celsius to Fahrenheit
35 |
36 | byte f = temperature * 1.8 + 32;
37 | Serial.print("Sample OK: ");
38 | Serial.print((int)temperature); Serial.print(" *C, ");
39 | Serial.print((int)f); Serial.print(" *F, ");
40 | Serial.print((int)humidity); Serial.println(" H humidity");
41 |
42 |
43 | // Reading data from sensor 2...
44 | // ============================
45 |
46 | Serial.println("Getting data from sensor 2...");
47 |
48 | byte temperature2 = 0;
49 | byte humidity2 = 0;
50 | if ((err = dht11.read(dataPinSensor2, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
51 | Serial.print("Communication error with Sensor 2, err="); Serial.println(err);delay(1000);
52 | return;
53 | }
54 |
55 | // converting Celsius to Fahrenheit
56 |
57 | byte fb = temperature2 * 1.8 + 32;
58 |
59 | Serial.print("Sample OK: ");
60 | Serial.print((int)temperature); Serial.print(" *C, ");
61 | Serial.print((int)fb); Serial.print(" *F, ");
62 | Serial.print((int)humidity2); Serial.println(" H humidity");
63 |
64 |
65 |
66 | // DHT11 sampling rate is 1HZ.
67 | delay(1500);
68 | }
69 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/keywords.txt:
--------------------------------------------------------------------------------
1 | ###########################################
2 | # Syntax Coloring Map For SimpleDHT
3 | ###########################################
4 |
5 | ###########################################
6 | # Datatypes (KEYWORD1)
7 | ###########################################
8 | SimpleDHT11 KEYWORD1
9 | SimpleDHT22 KEYWORD1
10 |
11 | ###########################################
12 | # Methods and Functions (KEYWORD2)
13 | ###########################################
14 | read KEYWORD2
15 |
16 | ###########################################
17 | # Constants (LITERAL1)
18 | ###########################################
19 |
--------------------------------------------------------------------------------
/.piolibdeps/SimpleDHT_ID849/library.properties:
--------------------------------------------------------------------------------
1 | name=SimpleDHT
2 | version=1.0.8
3 | author=Winlin
4 | maintainer=Winlin
5 | sentence=Arduino Temp & Humidity Sensors for DHT11 and DHT22.
6 | paragraph=Simple C++ code with lots of comments, strictly follow the standard DHT protocol, supports 0.5HZ(DHT22) or 1HZ(DHT11) sampling rate.
7 | category=Sensors
8 | url=https://github.com/winlinvip/SimpleDHT
9 | architectures=*
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Continuous Integration (CI) is the practice, in software
2 | # engineering, of merging all developer working copies with a shared mainline
3 | # several times a day < http://docs.platformio.org/page/ci/index.html >
4 | #
5 | # Documentation:
6 | #
7 | # * Travis CI Embedded Builds with PlatformIO
8 | # < https://docs.travis-ci.com/user/integration/platformio/ >
9 | #
10 | # * PlatformIO integration with Travis CI
11 | # < http://docs.platformio.org/page/ci/travis.html >
12 | #
13 | # * User Guide for `platformio ci` command
14 | # < http://docs.platformio.org/page/userguide/cmd_ci.html >
15 | #
16 | #
17 | # Please choice one of the following templates (proposed below) and uncomment
18 | # it (remove "# " before each line) or use own configuration according to the
19 | # Travis CI documentation (see above).
20 | #
21 |
22 |
23 | #
24 | # Template #1: General project. Test it using existing `platformio.ini`.
25 | #
26 |
27 | # language: python
28 | # python:
29 | # - "2.7"
30 | #
31 | # sudo: false
32 | # cache:
33 | # directories:
34 | # - "~/.platformio"
35 | #
36 | # install:
37 | # - pip install -U platformio
38 | # - platformio update
39 | #
40 | # script:
41 | # - platformio run
42 |
43 |
44 | #
45 | # Template #2: The project is intended to by used as a library with examples
46 | #
47 |
48 | # language: python
49 | # python:
50 | # - "2.7"
51 | #
52 | # sudo: false
53 | # cache:
54 | # directories:
55 | # - "~/.platformio"
56 | #
57 | # env:
58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c
59 | # - PLATFORMIO_CI_SRC=examples/file.ino
60 | # - PLATFORMIO_CI_SRC=path/to/test/directory
61 | #
62 | # install:
63 | # - pip install -U platformio
64 | # - platformio update
65 | #
66 | # script:
67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
68 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // See http://go.microsoft.com/fwlink/?LinkId=827846
3 | // for the documentation about the extensions.json format
4 | "recommendations": [
5 | "platformio.platformio-ide"
6 | ]
7 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "terminal.integrated.env.osx": {
3 | "PATH": "/Users/jiangyucan/.platformio/penv/bin:/Users/jiangyucan/.platformio/penv:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Tomcat/bin",
4 | "PLATFORMIO_CALLER": "vscode"
5 | },
6 | "files.associations": {
7 | "*.vue": "vue",
8 | "*.wpy": "vue",
9 | "*.wxml": "html",
10 | "*.wxss": "css",
11 | "sstream": "cpp",
12 | "array": "cpp",
13 | "deque": "cpp",
14 | "list": "cpp",
15 | "unordered_map": "cpp",
16 | "vector": "cpp",
17 | "initializer_list": "cpp",
18 | "typeinfo": "cpp",
19 | "*.tcc": "cpp",
20 | "iosfwd": "cpp",
21 | "bitset": "cpp",
22 | "fstream": "cpp",
23 | "ostream": "cpp",
24 | "string": "cpp"
25 | },
26 | "terminal.integrated.env.windows": {
27 | "PATH": "C:\\Users\\ucmed\\.platformio\\penv\\Scripts;C:\\Users\\ucmed\\.platformio\\penv;C:\\Program Files\\ImageMagick-7.0.7-Q16;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;D:\\Program Files\\nodejs\\;C:\\Program Files\\SourceGear\\Common\\DiffMerge\\;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files (x86)\\Microsoft VS Code\\bin;D:\\android-sdk\\platform-tools;D:\\android-sdk\\build-tools\\25.0.1;C:\\Program Files\\Java\\jdk1.8.0_131\\bin;C:\\Program Files\\MongoDB\\Server\\3.4\\bin;D:\\Program Files\\Python27;D:\\Program Files\\Python27\\Scripts;C:\\Users\\ucmed\\AppData\\Local\\Programs\\Fiddler;D:\\apache-maven-3.5.2\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files\\nodejs;D:\\ffmpeg\\bin;C:\\Users\\ucmed\\AppData\\Roaming\\npm;C:\\Program Files (x86)\\Microsoft VS Code\\bin;;C:\\Program Files\\ImageMagick-7.0.7-Q16;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;D:\\Program Files\\nodejs\\;C:\\Program Files\\SourceGear\\Common\\DiffMerge\\;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files (x86)\\Microsoft VS Code\\bin;D:\\android-sdk\\platform-tools;D:\\android-sdk\\build-tools\\25.0.1;C:\\Program Files\\Java\\jdk1.8.0_131\\bin;C:\\Program Files\\MongoDB\\Server\\3.4\\bin;D:\\Program Files\\Python27;D:\\Program Files\\Python27\\Scripts;C:\\Users\\ucmed\\AppData\\Local\\Programs\\Fiddler;D:\\apache-maven-3.5.2\\bin;C:\\Users\\ucmed\\AppData\\Local\\Microsoft\\WindowsApps;D:\\Program Files\\nodejs;D:\\ffmpeg\\bin;C:\\Users\\ucmed\\AppData\\Roaming\\npm;C:\\Program Files (x86)\\Microsoft VS Code\\bin;",
28 | "PLATFORMIO_CALLER": "vscode"
29 | }
30 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MqttIrext
2 | =====
3 |
4 | ---
5 | ## 什么是MqttIrext?
6 | MqttIrext [Irext](https://github.com/irext/irext-core)的一个衍生项目。
7 | MqttIrext的作用是帮助你只需要一个ESP8266系列的模块和一个红外二级管就可以控制家里红外设备。
8 | 它的优势在于:
9 | > * 成本低廉只需要一个ESP8266模块或开发板如NodeMcu)和一个红外二级管
10 | > * 不需要人为学习红外码快速匹配到电器
11 | > * 有mqtt接口可以方便接入homeassistant
12 |
13 | ## 开发状态
14 |
15 | MqttIrext 仍然处于前期开发阶段,未经充分测试与验证,不推荐用于生产环境。
16 |
17 | **目前的交互协议可能随时改变,不保证向后兼容,升级新版本时需要注意公告说明同时升级服务端和客户端。**
18 |
19 | ## 说明
20 | 现已完成,当前版本只支持空调
21 |
22 | ## 使用方式
23 | * 首先你需要刷好固件
24 | * 打开 http://esp.shanming.top/#/, 配置mqtt信息,完成会提示是否连接
25 | 
26 | * 开启esp设备,查找`AP_HOME_NODE`或`Bleeper`热点,手机或电脑都可以连接,访问地址`192.168.4.1` 配置如下信息:
27 | 
28 | * 网页端会接收到这样一个消息
29 | 
30 | * 配置topic和针脚,默认是14也就是d5,8266型号就是`00AED134`
31 | * 选择好空调固件,点击`使用固件`,会看到右上角有`download is ok`消息,证明固件下载完成
32 | 
33 | * 点击测试,会发送改变温度,从 `18度到30,制冷`,或在HomeAssistant中测试
34 |
35 | ## 发射管连接图
36 | 
37 |
38 | 也可以尝试不用三级管,直接连接。红外二级管长引脚接gpio,短脚接地。
39 |
40 | ## HomeAssistant配置文件
41 | 记得修改mqtt型号
42 | ```yaml
43 | climate:
44 | - platform: mqtt
45 | name: study
46 | friendly_name: 客厅空调
47 | modes:
48 | - cool
49 | - heat
50 | - auto
51 | - fan
52 | - dry
53 | - off
54 | swing_modes:
55 | - on
56 | - off
57 | fan_modes:
58 | - high
59 | - medium
60 | - low
61 | - auto
62 | power_command_topic: "esp/00AECB90/mode/set"
63 | mode_command_topic: "esp/00AECB90/mode/set"
64 | temperature_command_topic: "esp/00AECB90/temperature/set"
65 | fan_mode_command_topic: "esp/00AECB90/fan/set"
66 | swing_mode_command_topic: "esp/00AECB90/swing/set"
67 | min_temp: 16
68 | max_temp: 30
69 | ```
70 |
71 | ## 特别感谢
72 | * [Strawmanbobi](https://github.com/strawmanbobi) Irext开源库的作者,给予我技术和精神上的支持
73 | * [Caffreyfans](https://github.com/Caffreyfans) IRmqtt 开源库作者,我这这个基础上做了一些修改
74 |
75 |
--------------------------------------------------------------------------------
/firmware/firmware.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/firmware/firmware.bin
--------------------------------------------------------------------------------
/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/images/1.png
--------------------------------------------------------------------------------
/images/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/images/2.jpg
--------------------------------------------------------------------------------
/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/images/3.png
--------------------------------------------------------------------------------
/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/images/4.png
--------------------------------------------------------------------------------
/lib/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaming116/MqttIrext/b38731f4ed3dd6e21f21e569a5fc88d5f9596d51/lib/.DS_Store
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_apply.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_ac_apply.h
3 | Revised: Date: 2016-10-12
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides methods for AC IR applying functionalities
7 |
8 | Revision log:
9 | * 2016-10-12: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_APPLY_H_
13 | #define _IRDA_APPLY_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_decode.h"
21 |
22 | #define MIN_TAG_LENGTH_TYPE_1 4
23 | #define MIN_TAG_LENGTH_TYPE_2 6
24 |
25 | INT8 apply_power(t_remote_ac_status ac_status, UINT8 function_code);
26 |
27 | INT8 apply_mode(t_remote_ac_status ac_status, UINT8 function_code);
28 |
29 | INT8 apply_wind_speed(t_remote_ac_status ac_status, UINT8 function_code);
30 |
31 | INT8 apply_swing(t_remote_ac_status ac_status, UINT8 function_code);
32 |
33 | INT8 apply_temperature(t_remote_ac_status ac_status, UINT8 function_code);
34 |
35 | INT8 apply_function(struct ac_protocol *protocol, UINT8 function);
36 |
37 | INT8 apply_checksum(struct ac_protocol *protocol);
38 |
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 |
43 | #if defined(ARDUINO) && ARDUINO >= 100
44 | #include "arduino.h"
45 | #else
46 | #include "WProgram.h"
47 | #endif
48 |
49 | #endif //_IRDA_APPLY_H_
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_binary_parse.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_ac_binary_parse.h
3 | Revised: Date: 2017-01-03
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides methods for AC binary parse
7 |
8 | Revision log:
9 | * 2017-01-03: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef IRDA_DECODER_IR_AC_BINARY_PARSE_H
13 | #define IRDA_DECODER_IR_AC_BINARY_PARSE_H
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_defs.h"
21 |
22 | extern INT8 binary_parse_offset();
23 |
24 | extern INT8 binary_parse_len();
25 |
26 | extern void binary_tags_info();
27 |
28 | extern INT8 binary_parse_data();
29 |
30 | #ifdef __cplusplus
31 | }
32 | #endif
33 |
34 | #if defined(ARDUINO) && ARDUINO >= 100
35 | #include "arduino.h"
36 | #else
37 | #include "WProgram.h"
38 | #endif
39 |
40 | #endif //IRDA_DECODER_IR_AC_BINARY_PARSE_H
41 |
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_build_frame.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_utils.c
3 | Revised: Date: 2016-10-26
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides generic utils for IR frame build
7 |
8 | Revision log:
9 | * 2016-10-01: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_IRFRAME_H_
13 | #define _IRDA_IRFRAME_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_defs.h"
21 |
22 | extern UINT16 create_ir_frame();
23 |
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 |
28 | #if defined(ARDUINO) && ARDUINO >= 100
29 | #include "arduino.h"
30 | #else
31 | #include "WProgram.h"
32 | #endif
33 |
34 | #endif // _IRDA_IRFRAME_H_
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_control.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_ac_control.h
3 | Revised: Date: 2016-12-31
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides methods for AC IR control
7 |
8 | Revision log:
9 | * 2016-10-12: created by strawmanbobi
10 | **************************************************************************************/
11 | #ifndef IRDA_DECODER_IR_AC_CONTROL_H
12 | #define IRDA_DECODER_IR_AC_CONTROL_H
13 |
14 | #ifdef __cplusplus
15 | extern "C"
16 | {
17 | #endif
18 |
19 | #include "ir_defs.h"
20 |
21 |
22 | #define TAG_COUNT_FOR_PROTOCOL 29
23 |
24 | #define TAG_INVALID 0xffff
25 |
26 | #define MAX_DELAYCODE_NUM 16
27 | #define MAX_BITNUM 16
28 |
29 | #define AC_PARAMETER_TYPE_1 0
30 | #define AC_PARAMETER_TYPE_2 1
31 |
32 | typedef enum
33 | {
34 | AC_POWER_ON = 0,
35 | AC_POWER_OFF,
36 | AC_POWER_MAX
37 | } t_ac_power;
38 |
39 | typedef enum
40 | {
41 | AC_TEMP_16 = 0,
42 | AC_TEMP_17,
43 | AC_TEMP_18,
44 | AC_TEMP_19,
45 | AC_TEMP_20,
46 | AC_TEMP_21,
47 | AC_TEMP_22,
48 | AC_TEMP_23,
49 | AC_TEMP_24,
50 | AC_TEMP_25,
51 | AC_TEMP_26,
52 | AC_TEMP_27,
53 | AC_TEMP_28,
54 | AC_TEMP_29,
55 | AC_TEMP_30,
56 | AC_TEMP_MAX
57 | } t_ac_temperature;
58 |
59 | typedef enum
60 | {
61 | AC_MODE_COOL = 0,
62 | AC_MODE_HEAT,
63 | AC_MODE_AUTO,
64 | AC_MODE_FAN,
65 | AC_MODE_DRY,
66 | AC_MODE_MAX
67 | } t_ac_mode;
68 |
69 | typedef enum
70 | {
71 | AC_FUNCTION_POWER = 1,
72 | AC_FUNCTION_MODE,
73 | AC_FUNCTION_TEMPERATURE_UP,
74 | AC_FUNCTION_TEMPERATURE_DOWN,
75 | AC_FUNCTION_WIND_SPEED,
76 | AC_FUNCTION_WIND_SWING,
77 | AC_FUNCTION_WIND_FIX,
78 | AC_FUNCTION_MAX,
79 | } t_ac_function;
80 |
81 | typedef enum
82 | {
83 | AC_WS_AUTO = 0,
84 | AC_WS_LOW,
85 | AC_WS_MEDIUM,
86 | AC_WS_HIGH,
87 | AC_WS_MAX
88 | } t_ac_wind_speed;
89 |
90 | typedef enum
91 | {
92 | AC_SWING_ON = 0,
93 | AC_SWING_OFF,
94 | AC_SWING_MAX
95 | } t_ac_swing;
96 |
97 | typedef enum
98 | {
99 | SWING_TYPE_SWING_ONLY = 0,
100 | SWING_TYPE_NORMAL,
101 | SWING_TYPE_NOT_SPECIFIED,
102 | SWING_TYPE_MAX
103 | } swing_type;
104 |
105 | typedef enum
106 | {
107 | TEMP_TYPE_DYNAMIC = 0,
108 | TEMP_TYPE_STATIC,
109 | TEMP_TYPE_MAX,
110 | } t_temp_type;
111 |
112 | // enumeration for application polymorphism
113 | typedef enum
114 | {
115 | AC_APPLY_POWER = 0,
116 | AC_APPLY_MODE,
117 | AC_APPLY_TEMPERATURE_UP,
118 | AC_APPLY_TEMPERATURE_DOWN,
119 | AC_APPLY_WIND_SPEED,
120 | AC_APPLY_WIND_SWING,
121 | AC_APPLY_WIND_FIX,
122 | AC_APPLY_MAX
123 | } t_ac_apply;
124 |
125 | typedef struct _ac_hex
126 | {
127 | UINT8 len;
128 | UINT8 *data;
129 | } t_ac_hex;
130 |
131 | typedef struct _ac_level
132 | {
133 | UINT16 low;
134 | UINT16 high;
135 | } t_ac_level;
136 |
137 | typedef struct _ac_bootcode
138 | {
139 | UINT16 len;
140 | UINT16 data[16];
141 | } t_ac_bootcode;
142 |
143 | typedef struct _ac_delaycode
144 | {
145 | INT16 pos;
146 | UINT16 time[8];
147 | UINT16 time_cnt;
148 | } t_ac_delaycode;
149 |
150 | /*
151 | * the array of tag_100X application data
152 | * seg_len : length for each segment
153 | * byte_pos : the position of update byte
154 | * byte_value : the value to be updated to position
155 | */
156 | typedef struct _tag_comp_type_1
157 | {
158 | UINT8 seg_len;
159 | UINT8 *segment;
160 | } t_tag_comp;
161 |
162 | typedef struct _tag_swing_info
163 | {
164 | swing_type type;
165 | UINT8 mode_count;
166 | UINT8 dir_index;
167 | } t_swing_info;
168 |
169 | typedef struct _tag_power_1
170 | {
171 | UINT8 len;
172 | t_tag_comp comp_data[AC_POWER_MAX];
173 | } t_power_1;
174 |
175 | typedef struct _tag_temp_1
176 | {
177 | UINT8 len;
178 | UINT8 type;
179 | t_tag_comp comp_data[AC_TEMP_MAX];
180 | } t_temp_1;
181 |
182 | typedef struct tag_mode_1
183 | {
184 | UINT8 len;
185 | t_tag_comp comp_data[AC_MODE_MAX];
186 | } t_mode_1;
187 |
188 | typedef struct tag_speed_1
189 | {
190 | UINT8 len;
191 | t_tag_comp comp_data[AC_WS_MAX];
192 | } t_speed_1;
193 |
194 | typedef struct tag_swing_1
195 | {
196 | UINT8 len;
197 | UINT16 count;
198 | t_tag_comp *comp_data;
199 | } t_swing_1;
200 |
201 | typedef struct tag_temp_2
202 | {
203 | UINT8 len;
204 | UINT8 type;
205 | t_tag_comp comp_data[AC_TEMP_MAX];
206 | } t_temp_2;
207 |
208 | typedef struct tag_mode_2
209 | {
210 | UINT8 len;
211 | t_tag_comp comp_data[AC_MODE_MAX];
212 | } t_mode_2;
213 |
214 | typedef struct tag_speed_2
215 | {
216 | UINT8 len;
217 | t_tag_comp comp_data[AC_WS_MAX];
218 | } t_speed_2;
219 |
220 | typedef struct tag_swing_2
221 | {
222 | UINT8 len;
223 | UINT16 count;
224 | t_tag_comp *comp_data;
225 | } t_swing_2;
226 |
227 | #if defined SUPPORT_HORIZONTAL_SWING
228 | typedef struct tag_horiswing_1
229 | {
230 | UINT16 len;
231 | t_tag_comp comp_data[AC_HORI_SWING_MAX];
232 | } hori_swing_1;
233 | #endif
234 |
235 | typedef struct _tag_checksum_data
236 | {
237 | UINT8 len;
238 | UINT8 type;
239 | UINT8 start_byte_pos;
240 | UINT8 end_byte_pos;
241 | UINT8 checksum_byte_pos;
242 | UINT8 checksum_plus;
243 | UINT8 *spec_pos;
244 | } t_tag_checksum_data;
245 |
246 | typedef struct tag_checksum
247 | {
248 | UINT8 len;
249 | UINT16 count;
250 | t_tag_checksum_data *checksum_data;
251 | } t_checksum;
252 |
253 | typedef struct tag_function_1
254 | {
255 | UINT8 len;
256 | t_tag_comp comp_data[AC_FUNCTION_MAX - 1];
257 | } t_function_1;
258 |
259 | typedef struct tag_function_2
260 | {
261 | UINT8 len;
262 | t_tag_comp comp_data[AC_FUNCTION_MAX - 1];
263 | } t_function_2;
264 |
265 | typedef struct tag_solo_code
266 | {
267 | UINT8 len;
268 | UINT8 solo_func_count;
269 | UINT8 solo_function_codes[AC_FUNCTION_MAX - 1];
270 | } t_solo_code;
271 |
272 | typedef struct _ac_bitnum
273 | {
274 | INT16 pos;
275 | UINT16 bits;
276 | } t_ac_bit_num;
277 |
278 | typedef enum
279 | {
280 | N_COOL = 0,
281 | N_HEAT,
282 | N_AUTO,
283 | N_FAN,
284 | N_DRY,
285 | N_MODE_MAX,
286 | } t_ac_n_mode;
287 |
288 | typedef enum
289 | {
290 | CHECKSUM_TYPE_BYTE = 1,
291 | CHECKSUM_TYPE_BYTE_INVERSE,
292 | CHECKSUM_TYPE_HALF_BYTE,
293 | CHECKSUM_TYPE_HALF_BYTE_INVERSE,
294 | CHECKSUM_TYPE_SPEC_HALF_BYTE,
295 | CHECKSUM_TYPE_SPEC_HALF_BYTE_INVERSE,
296 | CHECKSUM_TYPE_SPEC_HALF_BYTE_ONE_BYTE,
297 | CHECKSUM_TYPE_SPEC_HALF_BYTE_INVERSE_ONE_BYTE,
298 | CHECKSUM_TYPE_MAX,
299 | } t_checksum_type;
300 |
301 | typedef struct _ac_n_mode_info
302 | {
303 | UINT8 enable;
304 | UINT8 all_speed;
305 | UINT8 all_temp;
306 | UINT8 temp[AC_TEMP_MAX];
307 | UINT8 temp_cnt;
308 | UINT8 speed[AC_WS_MAX];
309 | UINT8 speed_cnt;
310 | } t_ac_n_mode_info;
311 |
312 | typedef struct ac_protocol
313 | {
314 | UINT8 endian;
315 | // t_ac_hex default_code;
316 | t_ac_hex default_code;
317 | t_ac_level zero;
318 | t_ac_level one;
319 | t_ac_bootcode boot_code;
320 | t_ac_delaycode dc[MAX_DELAYCODE_NUM];
321 | t_power_1 power1;
322 | t_temp_1 temp1;
323 | t_mode_1 mode1;
324 | t_speed_1 speed1;
325 | t_swing_1 swing1;
326 | t_checksum checksum;
327 |
328 | t_function_1 function1;
329 | t_function_2 function2;
330 |
331 | t_temp_2 temp2;
332 | t_mode_2 mode2;
333 | t_speed_2 speed2;
334 | t_swing_2 swing2;
335 |
336 | t_swing_info si;
337 | t_solo_code sc;
338 |
339 | UINT8 swing_status;
340 |
341 | BOOL change_wind_direction;
342 |
343 | UINT16 dc_cnt;
344 | t_ac_bit_num bit_num[MAX_BITNUM];
345 | UINT16 bit_num_cnt;
346 | UINT16 repeat_times;
347 | t_ac_n_mode_info n_mode[N_MODE_MAX];
348 | UINT16 code_cnt;
349 | UINT8 last_bit;
350 | UINT16 *time;
351 | UINT8 solo_function_mark;
352 |
353 | UINT16 frame_length;
354 | } t_ac_protocol;
355 |
356 | typedef struct tag_head
357 | {
358 | UINT16 tag;
359 | UINT16 len;
360 | UINT16 offset;
361 | UINT8 *p_data;
362 | } t_tag_head;
363 |
364 | struct ir_bin_buffer
365 | {
366 | UINT8 *data;
367 | UINT16 len;
368 | UINT16 offset;
369 | };
370 |
371 | typedef struct REMOTE_AC_STATUS
372 | {
373 | t_ac_power ac_power;
374 | t_ac_temperature ac_temp;
375 | t_ac_mode ac_mode;
376 | t_ac_swing ac_wind_dir;
377 | t_ac_wind_speed ac_wind_speed;
378 | UINT8 ac_display;
379 | UINT8 ac_sleep;
380 | UINT8 ac_timer;
381 | } t_remote_ac_status;
382 |
383 | // function polymorphism
384 | typedef INT8 (*lp_apply_ac_parameter)(t_remote_ac_status ac_status, UINT8 function_code);
385 |
386 | #define TAG_AC_BOOT_CODE 1
387 | #define TAG_AC_ZERO 2
388 | #define TAG_AC_ONE 3
389 | #define TAG_AC_DELAY_CODE 4
390 | #define TAG_AC_FRAME_LENGTH 5
391 | #define TAG_AC_ENDIAN 6
392 | #define TAG_AC_LAST_BIT 7
393 |
394 | #define TAG_AC_POWER_1 21
395 | #define TAG_AC_DEFAULT_CODE 22
396 | #define TAG_AC_TEMP_1 23
397 | #define TAG_AC_MODE_1 24
398 | #define TAG_AC_SPEED_1 25
399 | #define TAG_AC_SWING_1 26
400 | #define TAG_AC_CHECKSUM_TYPE 27
401 | #define TAG_AC_SOLO_FUNCTION 28
402 | #define TAG_AC_FUNCTION_1 29
403 | #define TAG_AC_TEMP_2 30
404 | #define TAG_AC_MODE_2 31
405 | #define TAG_AC_SPEED_2 32
406 | #define TAG_AC_SWING_2 33
407 | #define TAG_AC_FUNCTION_2 34
408 |
409 | #define TAG_AC_BAN_FUNCTION_IN_COOL_MODE 41
410 | #define TAG_AC_BAN_FUNCTION_IN_HEAT_MODE 42
411 | #define TAG_AC_BAN_FUNCTION_IN_AUTO_MODE 43
412 | #define TAG_AC_BAN_FUNCTION_IN_FAN_MODE 44
413 | #define TAG_AC_BAN_FUNCTION_IN_DRY_MODE 45
414 | #define TAG_AC_SWING_INFO 46
415 | #define TAG_AC_REPEAT_TIMES 47
416 | #define TAG_AC_BIT_NUM 48
417 |
418 |
419 | // definition about size
420 |
421 | #define PROTOCOL_SIZE (sizeof(t_ac_protocol))
422 |
423 | /* exported variables */
424 | extern UINT8 *ir_hex_code;
425 | extern UINT8 ir_hex_len;
426 | extern t_ac_protocol *context;
427 |
428 |
429 | extern INT8 ir_ac_lib_parse();
430 |
431 | extern INT8 free_ac_context();
432 |
433 | extern BOOL is_solo_function(UINT8 function_code);
434 |
435 | #ifdef __cplusplus
436 | }
437 | #endif
438 |
439 |
440 | #endif //IRDA_DECODER_IR_AC_CONTROL_H
441 |
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_parse_forbidden_info.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_parse_forbidden_info.h
3 | Revised: Date: 2016-10-05
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for forbidden area of AC code
7 |
8 | Revision log:
9 | * 2016-10-05: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_PARSE_PARSE_H_
13 | #define _IRDA_PARSE_PARSE_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_decode.h"
21 |
22 | extern INT8 parse_nmode(struct tag_head *tag, t_ac_n_mode index);
23 |
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 |
28 | #if defined(ARDUINO) && ARDUINO >= 100
29 | #include "arduino.h"
30 | #else
31 | #include "WProgram.h"
32 | #endif
33 |
34 | #endif // _IRDA_PARSE_PARSE_H_
35 |
36 |
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_parse_frame_info.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_parse_frame_parameter.h
3 | Revised: Date: 2016-10-11
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR decode for AC frame parameters
7 |
8 | Revision log:
9 | * 2016-10-11: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_PARSE_FRAME_PARAMETER_H_
13 | #define _IRDA_PARSE_FRAME_PARAMETER_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_decode.h"
21 |
22 | extern INT8 parse_boot_code(struct tag_head *tag);
23 |
24 | extern INT8 parse_zero(struct tag_head *tag);
25 |
26 | extern INT8 parse_one(struct tag_head *tag);
27 |
28 | extern INT8 parse_delay_code(struct tag_head *tag);
29 |
30 | extern INT8 parse_frame_len(struct tag_head *tag, UINT16 len);
31 |
32 | extern INT8 parse_endian(struct tag_head *tag);
33 |
34 | extern INT8 parse_lastbit(struct tag_head *tag);
35 |
36 | extern INT8 parse_repeat_times(struct tag_head *tag);
37 |
38 | extern INT8 parse_bit_num(struct tag_head *tag);
39 |
40 | #ifdef __cplusplus
41 | }
42 | #endif
43 |
44 | #if defined(ARDUINO) && ARDUINO >= 100
45 | #include "arduino.h"
46 | #else
47 | #include "WProgram.h"
48 | #endif
49 |
50 | #endif // _IRDA_PARSE_FRAME_PARAMETER_H_
--------------------------------------------------------------------------------
/lib/ir/include/ir_ac_parse_parameter.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_parse_ac_parameter.h
3 | Revised: Date: 2016-10-12
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR decode for AC functionality parameters
7 |
8 | Revision log:
9 | * 2016-10-12: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_PARSE_AC_PARAMETER_H_
13 | #define _IRDA_PARSE_AC_PARAMETER_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_decode.h"
21 |
22 | extern INT8 parse_common_ac_parameter(t_tag_head *tag, t_tag_comp *comp_data, UINT8 with_end, UINT8 type);
23 |
24 | extern INT8 parse_default_code(struct tag_head *tag, t_ac_hex *default_code);
25 |
26 | extern INT8 parse_power_1(struct tag_head *tag, t_power_1 *power1);
27 |
28 | extern INT8 parse_temp_1(struct tag_head *tag, t_temp_1 *temp1);
29 |
30 | extern INT8 parse_mode_1(struct tag_head *tag, t_mode_1 *mode1);
31 |
32 | extern INT8 parse_speed_1(struct tag_head *tag, t_speed_1 *speed1);
33 |
34 | extern INT8 parse_swing_1(struct tag_head *tag, t_swing_1 *swing1, UINT16 swing_count);
35 |
36 | extern INT8 parse_checksum(struct tag_head *tag, t_checksum *checksum);
37 |
38 | extern INT8 parse_function_1_tag29(struct tag_head *tag, t_function_1 *function1);
39 |
40 | extern INT8 parse_temp_2(struct tag_head *tag, t_temp_2 *temp2);
41 |
42 | extern INT8 parse_mode_2(struct tag_head *tag, t_mode_2 *mode2);
43 |
44 | extern INT8 parse_speed_2(struct tag_head *tag, t_speed_2 *speed2);
45 |
46 | extern INT8 parse_swing_2(struct tag_head *tag, t_swing_2 *swing2, UINT16 swing_count);
47 |
48 | extern INT8 parse_function_2_tag34(struct tag_head *tag, t_function_2 *function2);
49 |
50 | extern INT8 parse_swing_info(struct tag_head *tag, t_swing_info *si);
51 |
52 | extern INT8 parse_solo_code(struct tag_head *tag, t_solo_code *sc);
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #if defined(ARDUINO) && ARDUINO >= 100
59 | #include "arduino.h"
60 | #else
61 | #include "WProgram.h"
62 | #endif
63 |
64 | #endif // _IRDA_PARSE_AC_PARAMETER_H_
--------------------------------------------------------------------------------
/lib/ir/include/ir_decode.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_decode.h
3 | Revised: Date: 2016-10-01
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR decode
7 |
8 | Revision log:
9 | * 2016-10-01: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_DECODE_H_
13 | #define _IRDA_DECODE_H_
14 | #define USE_DYNAMIC_TAG
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include
21 | #include "ir_defs.h"
22 | #include "ir_ac_control.h"
23 | #include "ir_tv_control.h"
24 |
25 | #define IR_DECODE_FAILED (-1)
26 | #define IR_DECODE_SUCCEEDED (0)
27 |
28 | #define IR_CATEGORY_AC 1
29 | #define IR_CATEGORY_TV 2
30 |
31 | #define IR_TYPE_STATUS 0
32 | #define IR_TYPE_COMMANDS 1
33 |
34 | #define SUB_CATEGORY_QUATERNARY 0
35 | #define SUB_CATEGORY_HEXADECIMAL 1
36 |
37 | // exported functions
38 | /**
39 | * function ir_file_open
40 | *
41 | * description: open IR binary code from file
42 | *
43 | * parameters: category (in) - category ID get from indexing API
44 | * sub_category (in) - subcategory ID get from indexing API
45 | * file_name (in) - file name of IR binary
46 | *
47 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
48 | *
49 | */
50 | extern INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* file_name);
51 |
52 | /**
53 | * function ir_binary_open
54 | *
55 | * description: open IR binary code from buffer
56 | *
57 | * parameters: category (in) - category ID get from indexing API
58 | * sub_category (in) - subcategory ID get from indexing API
59 | * binary (in) - pointer to binary buffer
60 | * binary_length (in) - binary buffer size
61 | *
62 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
63 | */
64 | extern INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 binary_length);
65 |
66 | /**
67 | * function ir_decode
68 | *
69 | * description: decode IR binary into INT16 array which indicates the IR levels
70 | *
71 | * parameters: key_code (in) - the code of pressed key
72 | * user_data (out) - output decoded data in INT16 array format
73 | * ac_status(in) - pointer to AC status (optional)
74 | * change_wind_direction (in) - if control changes wind direction for AC (for AC only)
75 | *
76 | * returns: length of decoded data (0 indicates decode failure)
77 | */
78 | extern UINT16 ir_decode(UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status, BOOL change_wind_direction);
79 |
80 | /**
81 | * function ir_close
82 | *
83 | * description: close IR binary code
84 | *
85 | * parameters: N/A
86 | *
87 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
88 | */
89 | extern INT8 ir_close();
90 |
91 | /**
92 | * function get_temperature_range
93 | *
94 | * description: get the supported temperature range [min, max] for the opened AC IR binary
95 | *
96 | * parameters: ac_mode (in) specify in which AC mode the application need to get temperature info
97 | * temp_min (out) the min temperature supported in a specified AC mode
98 | * temp_max (out) the max temperature supported in a specified AC mode
99 | *
100 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
101 | */
102 | extern INT8 get_temperature_range(UINT8 ac_mode, INT8 *temp_min, INT8 *temp_max);
103 |
104 | /**
105 | * function get_supported_mode
106 | *
107 | * description: get supported mode for the opened AC IR binary
108 | *
109 | * parameters: supported_mode (out) mode supported by the remote in lower 5 bits
110 | *
111 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
112 | */
113 | extern INT8 get_supported_mode(UINT8 *supported_mode);
114 |
115 | /**
116 | * function get_supported_wind_speed
117 | *
118 | * description: get supported wind speed levels for the opened AC IR binary in certain mode
119 | *
120 | * parameters: ac_mode (in) specify in which AC mode the application need to get wind speed info
121 | * supported_wind_speed (out) wind speed supported by the remote in lower 4 bits
122 | *
123 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
124 | */
125 | extern INT8 get_supported_wind_speed(UINT8 ac_mode, UINT8 *supported_wind_speed);
126 |
127 | /**
128 | * function get_supported_swing
129 | *
130 | * description: get supported swing functions for the opened AC IR binary in certain mode
131 | *
132 | * parameters: ac_mode (in) specify in which AC mode the application need to get swing info
133 | * supported_swing (out) swing supported by the remote in lower 2 bits
134 | *
135 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
136 | */
137 | extern INT8 get_supported_swing(UINT8 ac_mode, UINT8 *supported_swing);
138 |
139 | /**
140 | * function get_supported_wind_direction
141 | *
142 | * description: get supported wind directions for the opened AC IR binary in certain mode
143 | *
144 | * parameters: supported_wind_direction (out) swing supported by the remote in lower 2 bits
145 | *
146 | * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
147 | */
148 | extern INT8 get_supported_wind_direction(UINT8 *supported_wind_direction);
149 |
150 |
151 | // private extern function
152 | #if (defined BOARD_PC || defined BOARD_PC_DLL)
153 | extern void ir_lib_free_inner_buffer();
154 | #endif
155 |
156 | #ifdef __cplusplus
157 | }
158 | #endif
159 |
160 | #endif // _IRDA_DECODE_H_
161 |
--------------------------------------------------------------------------------
/lib/ir/include/ir_defs.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_defs.h
3 | Revised: Date: 2016-10-26
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR decode
7 |
8 | Revision log:
9 | * 2016-10-01: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef PARSE_IR_DEFS_H
13 | #define PARSE_IR_DEFS_H
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #if defined BOARD_ANDROID
21 | #include
22 | #define LOG_TAG "ir_decode"
23 | #endif
24 |
25 | #if defined BOARD_CC26XX
26 | #include "OSAL.h"
27 | #endif
28 |
29 | #define TRUE 1
30 | #define FALSE 0
31 |
32 | #define FORMAT_HEX 16
33 | #define FORMAT_DECIMAL 10
34 |
35 |
36 | typedef unsigned char UINT8;
37 | typedef signed char INT8;
38 | typedef unsigned short UINT16;
39 | typedef signed short INT16;
40 | typedef signed int INT;
41 | typedef unsigned int UINT;
42 | typedef int BOOL;
43 |
44 | void noprint(const char *fmt, ...);
45 |
46 | #if defined BOARD_CC26XX
47 | #define ir_malloc(A) ICall_malloc(A)
48 | #define ir_free(A) ICall_free(A)
49 | #else
50 | #define ir_malloc(A) malloc(A)
51 | #define ir_free(A) free(A)
52 | #endif
53 |
54 | #define ir_memcpy(A, B, C) memcpy(A, B, C)
55 | #define ir_memset(A, B, C) memset(A, B, C)
56 | #define ir_strlen(A) strlen(A)
57 | #if (defined BOARD_PC) && (!defined BOARD_PC_JNI)
58 | #define ir_printf printf
59 | #else
60 | #define ir_printf noprint
61 | #endif
62 | #define USER_DATA_SIZE 1636
63 |
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 |
68 |
69 | #endif //PARSE_IR_DEFS_H
70 |
--------------------------------------------------------------------------------
/lib/ir/include/ir_tv_control.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_lib.h
3 | Revised: Date: 2016-02-23
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR decode (compressed command type)
7 |
8 | Revision log:
9 | * 2016-10-21: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_LIB_H_
13 | #define _IRDA_LIB_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_defs.h"
21 |
22 | #define STB_CHANNEL_OFFSET 14
23 |
24 | #define IRDA_FLAG_NORMAL 0
25 | #define IRDA_FLAG_INVERSE 1
26 |
27 | #define IRDA_LEVEL_LOW 0
28 | #define IRDA_LEVEL_HIGH 1
29 |
30 | #define IRDA_LSB 0
31 | #define IRDA_MSB 1
32 |
33 | enum
34 | {
35 | IRDA_DECODE_1_BIT = 0,
36 | IRDA_DECODE_2_BITS,
37 | IRDA_DECODE_4_BITS,
38 | };
39 |
40 | /*
41 | * global type definitions
42 | */
43 | typedef enum ir_flags
44 | {
45 | IRDA_BOOT = 0,
46 | IRDA_STOP,
47 | IRDA_SEP,
48 | IRDA_ONE,
49 | IRDA_ZERO,
50 | IRDA_FLIP,
51 | IRDA_TWO,
52 | IRDA_THREE = 7,
53 | IRDA_FOUR,
54 | IRDA_FIVE,
55 | IRDA_SIX,
56 | IRDA_SEVEN,
57 | IRDA_EIGHT,
58 | IRDA_NINE,
59 | IRDA_A,
60 | IRDA_B,
61 | IRDA_C,
62 | IRDA_D,
63 | IRDA_E,
64 | IRDA_F,
65 | IRDA_MAX = 20,
66 | } t_ir_flags;
67 |
68 | typedef struct ir_data
69 | {
70 | UINT8 bits;
71 | UINT8 lsb;
72 | UINT8 mode;
73 | UINT8 index;
74 | } t_ir_data;
75 |
76 | #if !defined BOARD_51 && !defined BOARD_STM8
77 | #pragma pack(1)
78 | #endif
79 | typedef struct ir_cycles
80 | {
81 | UINT8 flag;
82 | UINT16 mask;
83 | UINT16 space;
84 | } t_ir_cycles;
85 |
86 | #if !defined BOARD_51 && !defined BOARD_STM8
87 | #pragma pack()
88 | #endif
89 |
90 | typedef enum tv_key_value
91 | {
92 | TV_POWER = 0,
93 | TV_MUTE,
94 | TV_UP,
95 | TV_DOWN,
96 | TV_LEFT,
97 | TV_RIGHT,
98 | TV_OK,
99 | TV_VOL_UP,
100 | TV_VOL_DOWN,
101 | TV_BACK,
102 | TV_INPUT,
103 | TV_MENU,
104 | TV_HOME,
105 | TV_SET,
106 | TV_0,
107 | TV_1,
108 | TV_2,
109 | TV_3,
110 | TV_4,
111 | TV_5,
112 | TV_6,
113 | TV_7,
114 | TV_8,
115 | TV_9,
116 | TV_KEY_MAX,
117 | } t_tv_key_value;
118 |
119 |
120 | typedef enum stb_key_value
121 | {
122 | STB_POWER = 0,
123 | STB_MUTE,
124 | STB_UP,
125 | STB_DOWN,
126 | STB_LEFT,
127 | STB_RIGHT,
128 | STB_OK,
129 | STB_VOL_UP,
130 | STB_VOL_DOWN,
131 | STB_BACK,
132 | STB_INPUT,
133 | STB_MENU,
134 | STB_PAGE_UP,
135 | STB_PAGE_DOWN,
136 | STB_0,
137 | STB_1,
138 | STB_2,
139 | STB_3,
140 | STB_4,
141 | STB_5,
142 | STB_6,
143 | STB_7,
144 | STB_8,
145 | STB_9,
146 | STB_KEY_MAX,
147 | } t_stb_key_value;
148 |
149 | typedef enum nw_key_value
150 | {
151 | NW_POWER = 0,
152 | NW_UP,
153 | NW_DOWN,
154 | NW_LEFT,
155 | NW_RIGHT,
156 | NW_OK,
157 | NW_VOL_UP,
158 | NW_VOL_DOWN,
159 | NW_BACK,
160 | NW_MENU,
161 | NW_HOME,
162 | NW_0,
163 | NW_1,
164 | NW_2,
165 | NW_3,
166 | NW_4,
167 | NW_5,
168 | NW_6,
169 | NW_7,
170 | NW_8,
171 | NW_9,
172 | NW_KEY_MAX,
173 | } t_nw_key_value;
174 |
175 | typedef enum cm_key_value
176 | {
177 | CM_POWER = 0,
178 | CM_UP,
179 | CM_DOWN,
180 | CM_LEFT,
181 | CM_RIGHT,
182 | CM_OK,
183 | CM_VOL_UP,
184 | CM_VOL_DOWN,
185 | CM_FUNC_1,
186 | CM_FUNC_2,
187 | CM_FUNC_3,
188 | CM_BACK,
189 | CM_HOME,
190 | CM_MENU,
191 | CM_MODE,
192 | CM_KEY_MAX,
193 | } t_cm_key_value;
194 |
195 | typedef struct ir_data_tv
196 | {
197 | char magic[4];
198 | UINT8 per_keycode_bytes;
199 | } t_ir_data_tv;
200 |
201 |
202 | extern INT8 tv_lib_open(UINT8 *binary, UINT16 binary_length);
203 |
204 | extern BOOL tv_lib_parse(UINT8 encode_type);
205 |
206 | extern UINT16 tv_lib_control(UINT8 key, UINT16 *user_data);
207 |
208 | extern UINT8 tv_lib_close();
209 |
210 | #ifdef __cplusplus
211 | }
212 | #endif
213 |
214 | #endif /* _IRDA_LIB_H_ */
215 |
216 |
--------------------------------------------------------------------------------
/lib/ir/include/ir_utils.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_utils.c
3 | Revised: Date: 2016-10-26
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides generic utils for IRDA algorithms
7 |
8 | Revision log:
9 | * 2016-10-01: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #ifndef _IRDA_UTILS_H_
13 | #define _IRDA_UTILS_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C"
17 | {
18 | #endif
19 |
20 | #include "ir_defs.h"
21 | #include "ir_decode.h"
22 |
23 | #include
24 |
25 | extern void string_to_hex(UINT8 *p, t_ac_hex *pac_hex);
26 |
27 | extern void string_to_hex_common(UINT8 *p, UINT8 *hex_data, UINT16 len);
28 |
29 | extern BOOL is_in(const UINT8 *array, UINT8 value, UINT8 len);
30 |
31 | extern void hex_byte_to_double_char(char *dest, UINT8 length, UINT8 src);
32 |
33 | #ifdef __cplusplus
34 | }
35 | #endif
36 |
37 | #if defined(ARDUINO) && ARDUINO >= 100
38 | #include "arduino.h"
39 | #else
40 | #include "WProgram.h"
41 | #endif
42 |
43 | #endif // _IRDA_UTILS_H_
--------------------------------------------------------------------------------
/lib/ir/src/ir_ac_binary_parse.cpp:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_ac_binary_parse.c
3 | Revised: Date: 2017-01-03
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides methods for AC binary parse
7 |
8 | Revision log:
9 | * 2017-01-03: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #include "../include/ir_ac_binary_parse.h"
13 | #include "../include/ir_decode.h"
14 |
15 | UINT16 tag_head_offset = 0;
16 |
17 | extern struct ir_bin_buffer *p_ir_buffer;
18 | extern struct tag_head* tags;
19 |
20 | UINT8 tag_count = 0;
21 | const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] =
22 | {
23 | 1, 2, 3, 4, 5, 6, 7,
24 | 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
25 | 41, 42, 43, 44, 45, 46, 47, 48
26 | };
27 |
28 | INT8 binary_parse_offset()
29 | {
30 | int i = 0;
31 |
32 | UINT8 *phead = (UINT8 *)&p_ir_buffer->data[1];
33 | //Serial.printf("\n&p_ir_buffer->data[1] = %0x\n", &p_ir_buffer->data[1]);
34 | //Serial.printf("p_ir_buffer->data[1] = %d\n", p_ir_buffer->data[1]);
35 | tag_count = p_ir_buffer->data[0];
36 | if (TAG_COUNT_FOR_PROTOCOL != tag_count)
37 | {
38 | return IR_DECODE_FAILED;
39 | }
40 |
41 | tag_head_offset = (UINT16) ((tag_count << 1) + 1);
42 |
43 | tags = (t_tag_head *) ir_malloc(tag_count * sizeof(t_tag_head));
44 | if (NULL == tags)
45 | {
46 | return IR_DECODE_FAILED;
47 | }
48 |
49 | //Serial.println();
50 | for (i = 0; i < tag_count; i++)
51 | {
52 | tags[i].tag = tag_index[i];
53 |
54 | #if defined BOARD_STM8 && defined COMPILER_IAR
55 | UINT16 offset = *(phead + i);
56 | tags[i].offset = (offset >> 8) | (offset << 8);
57 | #else
58 | if (phead != NULL) {
59 | UINT16 tmp_a = *(phead + i*2);
60 | UINT16 tmp_b = *(phead + i*2 + 1);
61 | tags[i].offset = tmp_b << 8 | tmp_a;
62 | }
63 | #endif
64 |
65 | if (tags[i].offset == TAG_INVALID)
66 | {
67 | tags[i].len = 0;
68 | }
69 | }
70 | return IR_DECODE_SUCCEEDED;
71 | }
72 |
73 | INT8 binary_parse_len()
74 | {
75 | UINT16 i = 0, j = 0;
76 | for (i = 0; i < (tag_count - 1); i++)
77 | {
78 | if (tags[i].offset == TAG_INVALID)
79 | {
80 | continue;
81 | }
82 |
83 | for (j = (UINT16) (i + 1); j < tag_count; j++)
84 | {
85 | if (tags[j].offset != TAG_INVALID)
86 | {
87 | break;
88 | }
89 | }
90 | if (j < tag_count)
91 | {
92 | tags[i].len = tags[j].offset - tags[i].offset;
93 | }
94 | else
95 | {
96 | tags[i].len = p_ir_buffer->len - tags[i].offset - tag_head_offset;
97 | return IR_DECODE_SUCCEEDED;
98 | }
99 | }
100 | if (tags[tag_count - 1].offset != TAG_INVALID)
101 | {
102 | tags[tag_count - 1].len = p_ir_buffer->len - tag_head_offset - tags[tag_count - 1].offset;
103 | }
104 |
105 | return IR_DECODE_SUCCEEDED;
106 | }
107 |
108 | void binary_tags_info()
109 | {
110 | #if defined BOARD_PC && defined DEBUG
111 | UINT16 i = 0;
112 | for (i = 0; i < tag_count; i++)
113 | {
114 | if (tags[i].len == 0)
115 | {
116 | continue;
117 | }
118 | ir_printf("tag(%d).len = %d\n", tags[i].tag, tags[i].len);
119 | }
120 | #endif
121 | }
122 |
123 | INT8 binary_parse_data()
124 | {
125 | UINT16 i = 0;
126 | for (i = 0; i < tag_count; i++)
127 | {
128 | tags[i].p_data = p_ir_buffer->data + tags[i].offset + tag_head_offset;
129 | }
130 |
131 | return IR_DECODE_SUCCEEDED;
132 | }
--------------------------------------------------------------------------------
/lib/ir/src/ir_ac_build_frame.cpp:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_irframe.c
3 | Revised: Date: 2016-10-01
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR frame build
7 |
8 | Revision log:
9 | * 2016-10-01: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #include "../include/ir_ac_build_frame.h"
13 | #include "../include/ir_decode.h"
14 |
15 | extern t_ac_protocol *context;
16 |
17 |
18 | //return bit number per byte,default value is 8
19 | UINT8 bits_per_byte(UINT8 index)
20 | {
21 | UINT8 i = 0;
22 | UINT8 size = 0;
23 |
24 | if (context->bit_num_cnt == 0)
25 | return 8; //defaut value
26 |
27 | if (context->bit_num_cnt >= MAX_BITNUM)
28 | size = MAX_BITNUM;
29 | else
30 | size = (UINT8) context->bit_num_cnt;
31 |
32 | for (i = 0; i < size; i++)
33 | {
34 | if (context->bit_num[i].pos == index)
35 | return (UINT8) context->bit_num[i].bits;
36 | if (context->bit_num[i].pos > index)
37 | return 8;
38 | }
39 | return 8;
40 | }
41 |
42 | UINT16 add_delaycode(UINT8 index)
43 | {
44 | UINT8 i = 0, j = 0;
45 | UINT8 size = 0;
46 | UINT8 tail_delaycode = 0;
47 | UINT16 tail_pos = 0;
48 |
49 | if (context->dc_cnt != 0)
50 | {
51 | size = (UINT8) context->dc_cnt;
52 |
53 | for (i = 0; i < size; i++)
54 | {
55 | if (context->dc[i].pos == index)
56 | {
57 | for (j = 0; j < context->dc[i].time_cnt; j++)
58 | {
59 | context->time[context->code_cnt++] = context->dc[i].time[j];
60 | }
61 | }
62 | else if (context->dc[i].pos == -1)
63 | {
64 | tail_delaycode = 1;
65 | tail_pos = i;
66 | }
67 | }
68 | }
69 |
70 | if ((context->last_bit == 0) && (index == (ir_hex_len - 1)))
71 | {
72 | context->time[context->code_cnt++] = context->one.low; //high
73 | }
74 |
75 | if (context->dc_cnt != 0)
76 | {
77 | if ((index == (ir_hex_len - 1)) && (tail_delaycode == 1))
78 | {
79 | for (i = 0; i < context->dc[tail_pos].time_cnt; i++)
80 | {
81 | context->time[context->code_cnt++] = context->dc[tail_pos].time[i];
82 | }
83 | }
84 | }
85 |
86 | return context->dc[i].time_cnt;
87 | }
88 |
89 | UINT16 create_ir_frame()
90 | {
91 | UINT16 i = 0, j = 0;
92 | UINT8 bitnum = 0;
93 | UINT8 *irdata = ir_hex_code;
94 | UINT8 mask = 1;
95 | UINT16 framelen = 0;
96 |
97 | context->code_cnt = 0;
98 |
99 | // boot code
100 | for (i = 0; i < context->boot_code.len; i++)
101 | {
102 | context->time[context->code_cnt++] = context->boot_code.data[i];
103 | }
104 | //code_cnt += context->boot_code.len;
105 |
106 | for (i = 0; i < ir_hex_len; i++)
107 | {
108 | bitnum = bits_per_byte((UINT8) i);
109 | for (j = 0; j < bitnum; j++)
110 | {
111 | if (context->endian == 0)
112 | mask = (UINT8) ((1 << (bitnum - 1)) >> j);
113 | else
114 | mask = (UINT8) (1 << j);
115 |
116 | if (irdata[i] & mask)
117 | {
118 | //ir_printf("%d,%d,", context->one.low, context->one.high);
119 | context->time[context->code_cnt++] = context->one.low;
120 | context->time[context->code_cnt++] = context->one.high;
121 | }
122 | else
123 | {
124 | //ir_printf("%d,%d,", context->zero.low, context->zero.high);
125 | context->time[context->code_cnt++] = context->zero.low;
126 | context->time[context->code_cnt++] = context->zero.high;
127 | }
128 | }
129 | add_delaycode((UINT8) i);
130 | }
131 |
132 | framelen = context->code_cnt;
133 |
134 | for (i = 0; i < (context->repeat_times - 1); i++)
135 | {
136 | for (j = 0; j < framelen; j++)
137 | {
138 | context->time[context->code_cnt++] = context->time[j];
139 | }
140 | }
141 |
142 | return context->code_cnt;
143 | }
144 |
145 |
146 |
--------------------------------------------------------------------------------
/lib/ir/src/ir_ac_parse_forbidden_info.cpp:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_parse_forbidden_info.c
3 | Revised: Date: 2016-10-05
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for forbidden area of AC code
7 |
8 | Revision log:
9 | * 2016-10-05: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include "../include/ir_decode.h"
17 | #include "../include/ir_ac_parse_forbidden_info.h"
18 |
19 |
20 | extern t_ac_protocol *context;
21 |
22 |
23 | INT8 parse_nmode_data_speed(char *pdata, t_ac_n_mode seq)
24 | {
25 | char buf[16] = {0};
26 | char *p = pdata;
27 | UINT16 pos = 0;
28 | UINT16 cnt = 0, index = 0;
29 |
30 | while (index <= ir_strlen(pdata))
31 | {
32 | while ((index != ir_strlen(pdata)) && (*(p++) != ','))
33 | {
34 | index++;
35 | }
36 | ir_memcpy(buf, pdata + pos, index - pos);
37 | pos = (UINT16) (index + 1);
38 | index = pos;
39 | context->n_mode[seq].speed[cnt++] = (UINT8) atoi(buf);
40 | context->n_mode[seq].speed_cnt = (UINT8) cnt;
41 | ir_memset(buf, 0, 16);
42 | }
43 |
44 | return IR_DECODE_SUCCEEDED;
45 | }
46 |
47 | INT8 parse_nmode_data_temp(char *pdata, t_ac_n_mode seq)
48 | {
49 |
50 | char buf[16] = {0};
51 | char *p = pdata;
52 | UINT16 pos = 0;
53 | UINT16 cnt = 0, index = 0;
54 |
55 | while (index <= ir_strlen(pdata))
56 | {
57 | while ((index != ir_strlen(pdata)) && (*(p++) != ','))
58 | {
59 | index++;
60 | }
61 | ir_memcpy(buf, pdata + pos, index - pos);
62 | pos = (UINT16) (index + 1);
63 | index = pos;
64 | context->n_mode[seq].temp[cnt++] = (UINT8) (atoi(buf) - 16);
65 | context->n_mode[seq].temp_cnt = (UINT8) cnt;
66 | ir_memset(buf, 0, 16);
67 | }
68 | return IR_DECODE_SUCCEEDED;
69 | }
70 |
71 | INT8 parse_nmode_pos(char *buf, t_ac_n_mode index)
72 | {
73 | UINT16 i = 0;
74 | char data[64] = {0};
75 | // char start[8] = {0};
76 | if (ir_strlen(buf) == 1)
77 | {
78 | if (buf[0] == 'S' || buf[0] == 's')
79 | {
80 | context->n_mode[index].all_speed = 1;
81 | }
82 | else if (buf[0] == 'T' || buf[0] == 't')
83 | {
84 | context->n_mode[index].all_temp = 1;
85 | }
86 | return IR_DECODE_SUCCEEDED;
87 | }
88 |
89 | for (i = 0; i < ir_strlen(buf); i++)
90 | {
91 | if (buf[i] == '&')
92 | {
93 | ir_memcpy(data, buf + i + 1, ir_strlen(buf) - i - 1);
94 | break;
95 | }
96 | }
97 | if (buf[0] == 'S')
98 | {
99 | parse_nmode_data_speed(data, index);
100 | }
101 | else
102 | {
103 | parse_nmode_data_temp(data, index);
104 | }
105 |
106 | return IR_DECODE_SUCCEEDED;
107 | }
108 |
109 | INT8 parse_nmode(struct tag_head *tag, t_ac_n_mode index)
110 | {
111 | UINT16 i = 0;
112 | UINT16 preindex = 0;
113 |
114 | char buf[64] = {0};
115 |
116 | if (tag->p_data[0] == 'N' && tag->p_data[1] == 'A')
117 | {
118 | // ban this function directly
119 | context->n_mode[index].enable = 0;
120 | return IR_DECODE_SUCCEEDED;
121 | }
122 | else
123 | {
124 | context->n_mode[index].enable = 1;
125 | }
126 |
127 | preindex = 0;
128 | for (i = 0; i < tag->len; i++)
129 | {
130 | if (tag->p_data[i] == '|')
131 | {
132 | ir_memcpy(buf, tag->p_data + preindex, i - preindex);
133 | preindex = (UINT16) (i + 1);
134 | parse_nmode_pos(buf, index);
135 | ir_memset(buf, 0, 64);
136 | }
137 |
138 | }
139 | ir_memcpy(buf, tag->p_data + preindex, i - preindex);
140 | parse_nmode_pos(buf, index);
141 | ir_memset(buf, 0, 64);
142 | return IR_DECODE_SUCCEEDED;
143 | }
144 |
--------------------------------------------------------------------------------
/lib/ir/src/ir_ac_parse_frame_info.cpp:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_parse_frame_parameter.c
3 | Revised: Date: 2016-10-11
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides algorithms for IR decode for AC frame parameters
7 |
8 | Revision log:
9 | * 2016-10-11: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include "../include/ir_utils.h"
17 | #include "../include/ir_ac_parse_frame_info.h"
18 |
19 |
20 | INT8 parse_boot_code(struct tag_head *tag)
21 | {
22 | UINT8 buf[16] = {0};
23 | UINT8 *p = NULL;
24 | UINT16 pos = 0;
25 | UINT16 cnt = 0, index = 0;
26 |
27 | if (NULL == tag)
28 | {
29 | return IR_DECODE_FAILED;
30 | }
31 | p = tag->p_data;
32 |
33 | if (NULL == p)
34 | {
35 | return IR_DECODE_FAILED;
36 | }
37 |
38 | while (index <= tag->len)
39 | {
40 | while ((index != (tag->len)) && (*(p++) != ','))
41 | {
42 | index++;
43 | }
44 | ir_memcpy(buf, tag->p_data + pos, index - pos);
45 | pos = (UINT16) (index + 1);
46 | index = pos;
47 | context->boot_code.data[cnt++] = (UINT16) (atoi((char *) buf));
48 | ir_memset(buf, 0, 16);
49 | }
50 | context->boot_code.len = cnt;
51 | return IR_DECODE_SUCCEEDED;
52 | }
53 |
54 | INT8 parse_zero(struct tag_head *tag)
55 | {
56 | UINT8 low[16] = {0};
57 | UINT8 high[16] = {0};
58 | UINT16 index = 0;
59 | UINT8 *p = NULL;
60 |
61 | if (NULL == tag)
62 | {
63 | return IR_DECODE_FAILED;
64 | }
65 | p = tag->p_data;
66 |
67 | if (NULL == p)
68 | {
69 | return IR_DECODE_FAILED;
70 | }
71 |
72 | while (*(p++) != ',')
73 | {
74 | index++;
75 | }
76 |
77 | ir_memcpy(low, tag->p_data, index);
78 | ir_memcpy(high, tag->p_data + index + 1, (size_t) (tag->len - index - 1));
79 |
80 | context->zero.low = (UINT16) (atoi((char *) low));
81 | context->zero.high = (UINT16) (atoi((char *) high));
82 | return IR_DECODE_SUCCEEDED;
83 | }
84 |
85 | INT8 parse_one(struct tag_head *tag)
86 | {
87 | UINT8 low[16] = {0};
88 | UINT8 high[16] = {0};
89 | UINT16 index = 0;
90 | UINT8 *p = NULL;
91 |
92 | if (NULL == tag)
93 | {
94 | return IR_DECODE_FAILED;
95 | }
96 | p = tag->p_data;
97 |
98 | if (NULL == p)
99 | {
100 | return IR_DECODE_FAILED;
101 | }
102 |
103 | while (*(p++) != ',')
104 | {
105 | index++;
106 | }
107 | ir_memcpy(low, tag->p_data, index);
108 | ir_memcpy(high, tag->p_data + index + 1, (size_t) (tag->len - index - 1));
109 |
110 | context->one.low = (UINT16) (atoi((char *) low));
111 | context->one.high = (UINT16) (atoi((char *) high));
112 |
113 | return IR_DECODE_SUCCEEDED;
114 | }
115 |
116 | INT8 parse_delay_code_data(UINT8 *pdata)
117 | {
118 | UINT8 buf[16] = {0};
119 | UINT8 *p = NULL;
120 | UINT16 pos = 0;
121 | UINT16 cnt = 0, index = 0;
122 |
123 | if (NULL == pdata)
124 | {
125 | return IR_DECODE_FAILED;
126 | }
127 | p = pdata;
128 |
129 | while (index <= ir_strlen((char *) pdata))
130 | {
131 | while ((index != ir_strlen((char *) pdata)) && (*(p++) != ','))
132 | {
133 | index++;
134 | }
135 | ir_memcpy(buf, pdata + pos, index - pos);
136 | pos = (UINT16) (index + 1);
137 | index = pos;
138 | context->dc[context->dc_cnt].time[cnt++] = (UINT16) (atoi((char *) buf));
139 | context->dc[context->dc_cnt].time_cnt = cnt;
140 | ir_memset(buf, 0, 16);
141 | }
142 |
143 | return IR_DECODE_SUCCEEDED;
144 | }
145 |
146 | INT8 parse_delay_code_pos(UINT8 *buf)
147 | {
148 | UINT16 i = 0;
149 | UINT8 data[64] = {0}, start[8] = {0};
150 |
151 | if (NULL == buf)
152 | {
153 | return IR_DECODE_FAILED;
154 | }
155 |
156 | for (i = 0; i < ir_strlen((char *) buf); i++)
157 | {
158 | if (buf[i] == '&')
159 | {
160 | ir_memcpy(start, buf, i);
161 | ir_memcpy(data, buf + i + 1, ir_strlen((char *) buf) - i - 1);
162 | break;
163 | }
164 | }
165 | parse_delay_code_data(data);
166 | context->dc[context->dc_cnt].pos = (UINT16) (atoi((char *) start));
167 |
168 | context->dc_cnt++;
169 | return IR_DECODE_SUCCEEDED;
170 | }
171 |
172 | INT8 parse_delay_code(struct tag_head *tag)
173 | {
174 | UINT8 buf[64] = {0};
175 | UINT16 i = 0;
176 | UINT16 preindex = 0;
177 | preindex = 0;
178 |
179 | if (NULL == tag)
180 | {
181 | return IR_DECODE_FAILED;
182 | }
183 |
184 | for (i = 0; i < tag->len; i++)
185 | {
186 | if (tag->p_data[i] == '|')
187 | {
188 | ir_memcpy(buf, tag->p_data + preindex, i - preindex);
189 | preindex = (UINT16) (i + 1);
190 | parse_delay_code_pos(buf);
191 | ir_memset(buf, 0, 64);
192 | }
193 |
194 | }
195 | ir_memcpy(buf, tag->p_data + preindex, i - preindex);
196 | parse_delay_code_pos(buf);
197 | ir_memset(buf, 0, 64);
198 |
199 | return IR_DECODE_SUCCEEDED;
200 | }
201 |
202 | INT8 parse_frame_len(struct tag_head *tag, UINT16 len)
203 | {
204 | UINT8 *temp = NULL;
205 |
206 | if (NULL == tag)
207 | {
208 | return IR_DECODE_FAILED;
209 | }
210 |
211 | temp = (UINT8 *) ir_malloc(len + 1);
212 |
213 | if (NULL == temp)
214 | {
215 | return IR_DECODE_FAILED;
216 | }
217 |
218 | ir_memset(temp, 0x00, len + 1);
219 |
220 | ir_memcpy(temp, tag->p_data, len);
221 | temp[len] = '\0';
222 |
223 | context->frame_length = (UINT16) (atoi((char *) temp));
224 |
225 | ir_free(temp);
226 | return IR_DECODE_SUCCEEDED;
227 | }
228 |
229 | INT8 parse_endian(struct tag_head *tag)
230 | {
231 | UINT8 buf[8] = {0};
232 |
233 | if (NULL == tag)
234 | {
235 | return IR_DECODE_FAILED;
236 | }
237 | ir_memcpy(buf, tag->p_data, tag->len);
238 | context->endian = (UINT8) (atoi((char *) buf));
239 | return IR_DECODE_SUCCEEDED;
240 | }
241 |
242 | INT8 parse_lastbit(struct tag_head *tag)
243 | {
244 | UINT8 buf[8] = {0};
245 |
246 | if (NULL == tag)
247 | {
248 | return IR_DECODE_FAILED;
249 | }
250 | ir_memcpy(buf, tag->p_data, tag->len);
251 | context->last_bit = (UINT8) (atoi((char *) buf));
252 | return IR_DECODE_SUCCEEDED;
253 | }
254 |
255 | INT8 parse_repeat_times(struct tag_head *tag)
256 | {
257 | char asc_code[8] = {0};
258 | if (NULL == tag)
259 | {
260 | return IR_DECODE_FAILED;
261 | }
262 |
263 | ir_memcpy(asc_code, tag->p_data, tag->len);
264 |
265 | context->repeat_times = (UINT16) (atoi((char *) asc_code));
266 |
267 | return IR_DECODE_SUCCEEDED;
268 | }
269 |
270 | INT8 parse_delay_code_tag48_pos(UINT8 *buf)
271 | {
272 | UINT16 i = 0;
273 | UINT8 data[64] = {0}, start[8] = {0};
274 |
275 | if (NULL == buf)
276 | {
277 | return IR_DECODE_FAILED;
278 | }
279 |
280 | for (i = 0; i < ir_strlen((char *) buf); i++)
281 | {
282 | if (buf[i] == '&')
283 | {
284 | ir_memcpy(start, buf, i);
285 | ir_memcpy(data, buf + i + 1, ir_strlen((char *) buf) - i - 1);
286 | break;
287 | }
288 | }
289 |
290 | context->bit_num[context->bit_num_cnt].pos = (UINT16) (atoi((char *) start));
291 | context->bit_num[context->bit_num_cnt].bits = (UINT16) (atoi((char *) data));
292 | context->bit_num_cnt++;
293 | return IR_DECODE_SUCCEEDED;
294 | }
295 |
296 | INT8 parse_bit_num(struct tag_head *tag)
297 | {
298 | UINT16 i = 0;
299 | UINT16 preindex = 0;
300 | UINT8 buf[64] = {0};
301 |
302 | if (NULL == tag)
303 | {
304 | return IR_DECODE_FAILED;
305 | }
306 |
307 | preindex = 0;
308 | for (i = 0; i < tag->len; i++)
309 | {
310 | if (tag->p_data[i] == '|')
311 | {
312 | ir_memcpy(buf, tag->p_data + preindex, i - preindex);
313 | preindex = (UINT16) (i + 1);
314 | parse_delay_code_tag48_pos(buf);
315 | ir_memset(buf, 0, 64);
316 | }
317 |
318 | }
319 | ir_memcpy(buf, tag->p_data + preindex, i - preindex);
320 | parse_delay_code_tag48_pos(buf);
321 | ir_memset(buf, 0, 64);
322 |
323 | for (i = 0; i < context->bit_num_cnt; i++)
324 | {
325 | if (context->bit_num[i].pos == -1)
326 | context->bit_num[i].pos = (UINT16) (context->default_code.len - 1); //convert -1 to last data pos
327 | }
328 | return IR_DECODE_SUCCEEDED;
329 | }
330 |
--------------------------------------------------------------------------------
/lib/ir/src/ir_utils.cpp:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | Filename: ir_utils.c
3 | Revised: Date: 2016-10-26
4 | Revision: Revision: 1.0
5 |
6 | Description: This file provides generic utils for IRDA algorithms
7 |
8 | Revision log:
9 | * 2016-10-01: created by strawmanbobi
10 | **************************************************************************************/
11 |
12 | #include "../include/ir_utils.h"
13 |
14 | UINT8 char_to_hex(char chr)
15 | {
16 | UINT8 value = 0;
17 | if (chr >= '0' && chr <= '9')
18 | value = (UINT8) (chr - '0');
19 | if (chr >= 'a' && chr <= 'f')
20 | value = (UINT8) (chr - 'a' + 10);
21 | if (chr >= 'A' && chr <= 'F')
22 | value = (UINT8) (chr - 'A' + 10);
23 | return value;
24 | }
25 |
26 | UINT8 chars_to_hex(const UINT8 *p)
27 | {
28 | return (char_to_hex(*p) << 4) + char_to_hex(*(p + 1));
29 | }
30 |
31 | void string_to_hex_common(UINT8 *p, UINT8 *hex_data, UINT16 len)
32 | {
33 | // in condition of hex_code is already assigned
34 | UINT16 i = 0;
35 |
36 | for (i = 0; i < len; i++)
37 | {
38 | hex_data[i] = chars_to_hex(p);
39 | p = p + 2;
40 | }
41 | }
42 |
43 | void string_to_hex(UINT8 *p, t_ac_hex *pac_hex)
44 | {
45 | UINT8 i = 0;
46 |
47 | pac_hex->len = chars_to_hex(p);
48 | p = p + 2;
49 | for (i = 0; i < pac_hex->len; i++)
50 | {
51 | pac_hex->data[i] = chars_to_hex(p);
52 | p = p + 2;
53 | }
54 | }
55 |
56 | char hex_half_byte_to_single_char(UINT8 length, UINT8 half_byte)
57 | {
58 | if (1 != length || half_byte >= 16)
59 | {
60 | return '0';
61 | }
62 | if (half_byte >= 10 && half_byte < 16)
63 | {
64 | return (char) (half_byte - 10 + 0x41);
65 | }
66 | else
67 | {
68 | return (char) (half_byte + 0x30);
69 | }
70 | }
71 |
72 | void hex_byte_to_double_char(char *dest, UINT8 length, UINT8 src)
73 | {
74 | UINT8 hi_num = 0;
75 | UINT8 lo_num = 0;
76 | if (NULL == dest || 2 != length)
77 | {
78 | return;
79 | }
80 | hi_num = (UINT8) ((src >> 4) & 0x0F);
81 | lo_num = (UINT8) (src & 0x0F);
82 |
83 | dest[0] = hex_half_byte_to_single_char(1, hi_num);
84 | dest[1] = hex_half_byte_to_single_char(1, lo_num);
85 | }
86 |
87 | BOOL is_in(const UINT8 *array, UINT8 value, UINT8 len)
88 | {
89 | UINT16 i = 0;
90 | for (i = 0; i < len; i++)
91 | {
92 | if (array[i] == value)
93 | {
94 | return TRUE;
95 | }
96 | }
97 | return FALSE;
98 | }
--------------------------------------------------------------------------------
/lib/readme.txt:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for the project specific (private) libraries.
3 | PlatformIO will compile them to static libraries and link to executable file.
4 |
5 | The source code of each library should be placed in separate directory, like
6 | "lib/private_lib/[here are source files]".
7 |
8 | For example, see how can be organized `Foo` and `Bar` libraries:
9 |
10 | |--lib
11 | | |
12 | | |--Bar
13 | | | |--docs
14 | | | |--examples
15 | | | |--src
16 | | | |- Bar.c
17 | | | |- Bar.h
18 | | | |- library.json (optional, custom build options, etc) http://docs.platformio.org/page/librarymanager/config.html
19 | | |
20 | | |--Foo
21 | | | |- Foo.c
22 | | | |- Foo.h
23 | | |
24 | | |- readme.txt --> THIS FILE
25 | |
26 | |- platformio.ini
27 | |--src
28 | |- main.c
29 |
30 | Then in `src/main.c` you should use:
31 |
32 | #include
33 | #include
34 |
35 | // rest H/C/CPP code
36 |
37 | PlatformIO will find your libraries automatically, configure preprocessor's
38 | include paths and build them.
39 |
40 | More information about PlatformIO Library Dependency Finder
41 | - http://docs.platformio.org/page/librarymanager/ldf.html
42 |
--------------------------------------------------------------------------------
/platformio.ini:
--------------------------------------------------------------------------------
1 | ; PlatformIO Project Configuration File
2 | ;
3 | ; Build options: build flags, source filter
4 | ; Upload options: custom upload port, speed and extra flags
5 | ; Library options: dependencies, extra library storages
6 | ; Advanced options: extra scripting
7 | ;
8 | ; Please visit documentation for the other options and examples
9 | ; http://docs.platformio.org/page/projectconf.html
10 |
11 | [env:esp12e]
12 | platform = espressif8266
13 | board = esp12e
14 | framework = arduino
15 | lib_deps = Bleeper
16 | lib_ldf_mode = deep
17 | lib_deps = PubSubClient
18 | lib_deps = SimpleDHT
19 | lib_deps = IRremoteESP8266
--------------------------------------------------------------------------------