|
1 |
| -# iobroker-IoT-WindSensor |
2 |
| -Wind speed and direction sensor for the ioBroker IoT framework |
| 1 | +# ioBroker-IoT-WindSensor |
| 2 | + |
| 3 | +**Important: This project based on my ioBroker IoT Framework V5** |
| 4 | + |
| 5 | +[AndreasExner/ioBroker-IoT-Framework: ioBroker IoT Framework (based on NodeMCU ESP8266) (github.com)](https://github.com/AndreasExner/ioBroker-IoT-Framework) |
| 6 | + |
| 7 | +**Please refer to this documentation for the the basic setup and configuration.** |
| 8 | + |
| 9 | +Required Version: 5.2.0 (or higher) |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Description |
| 14 | + |
| 15 | +#### Introduction |
| 16 | + |
| 17 | +This sketch reads the wind speed and direction from devices similar to these (**no** affiliate links!): |
| 18 | + |
| 19 | +[Broco Garten Signalausgang Aluminiumlegierung Windrichtung Sensor Windfahne: AmazonSmile: Küche & Haushalt](https://smile.amazon.de/gp/product/B081NNH9RX/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1) |
| 20 | + |
| 21 | +[Rosilesi Windgeschwindigkeitssensor - Impulssignalausgang Aluminiumlegierter Windgeschwindigkeitssensor Anemometer: AmazonSmile: Garten](https://smile.amazon.de/gp/product/B08J4DLPBV/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1) |
| 22 | + |
| 23 | +Both are sold from different sellers and under different names as well. Since the wind speed sensor offers an analog output the wind direction sensor uses the RS486 interface. |
| 24 | + |
| 25 | +The raw data will be send to the ioborker, because oversampling can be a challenging part of the this project. |
| 26 | + |
| 27 | +#### Wiring |
| 28 | + |
| 29 | +Both sensors require 12-24V DC power. The RS485 shield is used to convert RS485 into TTL. |
| 30 | + |
| 31 | +<img src="https://github.com/AndreasExner/ioBroker-IoT-WindSensor/blob/main/WindSensor_Steckplatine.png?raw=true" style="zoom: 50%;" /> |
| 32 | + |
| 33 | +Voltage divider resistors: 330 ohm and 150 ohm, 1% or better, 1/4 watts |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +## History |
| 38 | + |
| 39 | +Version: F5_1.0 (release) 2020-12-06 |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +#### Tested environment |
| 44 | + |
| 45 | +- Software |
| 46 | + - Arduino IDE 1.8.13 (Windows) |
| 47 | + - EspSoftwareSerial 6.10.0 [plerup/espsoftwareserial: Implementation of the Arduino software serial for ESP8266 (github.com)](https://github.com/plerup/espsoftwareserial) |
| 48 | +- Hardware |
| 49 | + - NodeMCU Lolin V3 (ESP8266MOD 12-F) |
| 50 | + - NodeMCU D1 Mini (ESP8266MOD 12-F) |
| 51 | + - 5 V MAX485 / RS485 Modul TTL to RS-485 MCU |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +## Prerequisites |
| 56 | + |
| 57 | +* You need a running Arduino IDE and at least basic knowledge how it works. |
| 58 | +* You also need a running ioBroker instance and a little more than basic knowledge on that stuff. |
| 59 | +* You need a REST API in your ioBroker setup |
| 60 | +* You need to **secure** the REST API (for example, expose the required data only and hide any confidential and secret stuff) |
| 61 | +* You need a userdata section in your ioBroker objects |
| 62 | +* You should know how to work with IoT devices and electronics |
| 63 | +* You need to read this first: [AndreasExner/ioBroker-IoT-Framework: ioBroker IoT Framework (based on NodeMCU ESP8266) (github.com)](https://github.com/AndreasExner/ioBroker-IoT-Framework) |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +## Setup |
| 68 | + |
| 69 | +- Create a folder in your Arduino library folder |
| 70 | +- Copy the primary sketch (e.g. WindSensor.ino) and the extension file (AEX_iobroker_IoT_Framework.ino) into the folder |
| 71 | +- Open the primary sketch (e.g. WindSensor.ino) |
| 72 | +- **Install required libraries into your Arduino IDE** |
| 73 | +- Create (import) the datapoints in iobroker |
| 74 | + - 0_userdata.0.IoT-Devices.07.json (generic device configuration and monitoring) |
| 75 | + - 0_userdata.0.IoT.WindSensor.json (specific device configuration and data, production) |
| 76 | + - 0_userdata.0.IoT-Dev.WindSensor.json (specific device configuration and data, development, optional) |
| 77 | +- Set values for datapoints (see iobroker datapoints) |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +#### Generic device section |
| 84 | + |
| 85 | +```c++ |
| 86 | +// device settings - change settings to match your requirements |
| 87 | + |
| 88 | +const char* ssid = "<ssid>"; // Wifi SSID |
| 89 | +const char* password = "<password>"; //Wifi password |
| 90 | + |
| 91 | +String SensorID = "DEV"; //predefinded sensor ID, DEV by default to prevent overwriting productive data |
| 92 | + |
| 93 | +int interval = 10; // waiting time for the first masurement and fallback on error reading interval from iobroker |
| 94 | + |
| 95 | +bool DevMode = true; //enable DEV mode on boot (do not change) |
| 96 | +bool debug = true; //debug to serial monitor |
| 97 | +bool led = true; //enable external status LED on boot |
| 98 | +bool sensor_active = false; // dectivate sensor(s) on boot (do not change) |
| 99 | +``` |
| 100 | + |
| 101 | +- Enter proper Wifi information |
| 102 | +- The **`SensorID`** is part of the URL's and important for the the iobroker communications |
| 103 | +- **`Interval`** defines the delay between two data transmissions / measurements. This value is used initially after boot. The interval dynamically updates from iobroker |
| 104 | +- The **`DevMode`** switch prevents the device from sending data into your productive datapoints. It is enabled by default and can be overwritten dynamically from iobroker |
| 105 | +- **`debug`** enables a more detailed serial output |
| 106 | +- **`led`** enables the onboard led (status) |
| 107 | +- The **`sensor_active`** switch disables the loading of hardware specific code on startup. This is very useful to test a sketch on the bread board without the connected hardware. It is disabled by default and gets dynamically enabled from the iobrocker during boot, as long as nothing else is configured. |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +#### Base URL's |
| 112 | + |
| 113 | +```c++ |
| 114 | +/* |
| 115 | + * build base URL's |
| 116 | + * Change IP/FQND and path to match your environment |
| 117 | + */ |
| 118 | + |
| 119 | +String baseURL_DEVICE_GET = "http://192.168.1.240:8087/getPlainValue/0_userdata.0.IoT-Devices." + SensorID + "."; |
| 120 | +String baseURL_DEVICE_SET = "http://192.168.1.240:8087/set/0_userdata.0.IoT-Devices." + SensorID + "."; |
| 121 | +``` |
| 122 | + |
| 123 | +The base url's, one for read and one to write data, are pointing to your iobroker datapoints in the devices section. The SensorID will be added to complete the path. |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +## iobroker datapoints |
| 128 | + |
| 129 | +#### Devices section |
| 130 | + |
| 131 | +The default path for the devices root folder is: **`0_userdata.0.IoT-Devices`**. When the path is changed, it has to be changed in the sketch as well. |
| 132 | + |
| 133 | +**It is mandatory to setup the following datapoints prior the first device boot:** |
| 134 | + |
| 135 | +- **`DevMode`** If true, the baseURL's for the IoT-Dev section are used to prevent overwriting your production data. Also see generic device section. |
| 136 | + |
| 137 | +- **`LED`** Controls the status LED. Also see generic device section. |
| 138 | + |
| 139 | +- **`SensorActive`** Controls the hardware sensors. Also see generic device section. |
| 140 | + |
| 141 | +- **`SensorName`** Easy to understand name for the sensor. Not used in the code. |
| 142 | + |
| 143 | +- **`baseURL_GET_DEV`** points to the IoT-Dev datapoints in iobroker (e.g. 0_userdata.0.IoT-Dev.DEV) |
| 144 | + |
| 145 | + - ``` |
| 146 | + http://192.168.1.240:8087/getPlainValue/0_userdata.0.IoT-Dev.WindSensor. |
| 147 | + ``` |
| 148 | +
|
| 149 | +- **`baseURL_SET_DEV`** points to the IoT-Dev datapoints in iobroker (e.g. 0_userdata.0.IoT-Dev.DEV) |
| 150 | +
|
| 151 | + - ``` |
| 152 | + http://192.168.1.240:8087/set/0_userdata.0.IoT-Dev.WindSensor. |
| 153 | + ``` |
| 154 | +
|
| 155 | +- **`baseURL_GET_PROD`** points to the IoT datapoints in iobroker (e.g. 0_userdata.0.IoT.Weather) |
| 156 | +
|
| 157 | + - ``` |
| 158 | + http://192.168.1.240:8087/getPlainValue/0_userdata.0.IoT.WindSensor. |
| 159 | + ``` |
| 160 | +
|
| 161 | +- **`baseURL_SET_PROD`** points to the IoT datapoints in iobroker (e.g. 0_userdata.0.IoT.Weather) |
| 162 | +
|
| 163 | + - ``` |
| 164 | + http://192.168.1.240:8087/set/0_userdata.0.IoT.WindSensor. |
| 165 | + ``` |
| 166 | +
|
| 167 | +
|
| 168 | +
|
| 169 | +#### Specific device configuration and data |
| 170 | +
|
| 171 | +Depending on the **`DevMode`**, the device reads config and writes data into different datapoint sections: |
| 172 | +
|
| 173 | +- Development root folder: **`0_userdata.0.IoT-Dev`** |
| 174 | +- Production root folder: **`0_userdata.0.IoT`** |
| 175 | +
|
| 176 | +It is recommended to keep the datapoints in both sections identical to avoid errors when changing the **`DevMode`**. The values can be different. Setup these datapoints before boot up the device: |
| 177 | +
|
| 178 | +- **`Interval`** [10] Defines the delay (in seconds) between two data transmissions |
| 179 | +- **`A0_Step_Voltage`** The voltage per step of the A/D converter for the windspeed sensor. Due to the line resistance it might be necessary to adjust these values individually. A good point to start is 0.03 V. |
| 180 | +- These datapoints are for output only: |
| 181 | +
|
| 182 | +- **`WindDirection`** Wind direction in degrees |
| 183 | +- **`WindDirectionString`** Wind direction as string |
| 184 | +- **`WindSpeed`** Wind speed |
| 185 | +- **`SensorID`** Sensor device ID |
| 186 | +
|
| 187 | +
|
| 188 | +
|
| 189 | +## How it works |
| 190 | +
|
| 191 | +#### Boot phase / setup |
| 192 | +
|
| 193 | +- Connect Wifi |
| 194 | +- Get Wifi State |
| 195 | +- Get the dynamic configuration from iobroker (generic devices section) |
| 196 | +- Build specific device URL's (based on the dynamic configuration) |
| 197 | +- Send devices IP address |
| 198 | +- Send device ID |
| 199 | +- Send information about the last restart / reset |
| 200 | +- Run's setup for active sensors |
| 201 | +
|
| 202 | +
|
| 203 | +
|
| 204 | +#### Loop |
| 205 | +
|
| 206 | +Every n-th tick, defined by the **`Interval`**, the following sequence will proceed: |
| 207 | +
|
| 208 | +- Loop (1 Hz) |
| 209 | + - Get data of all sensors |
| 210 | + - Serial output all sensor data |
| 211 | + - Interval reached |
| 212 | + - Get Wifi State (try reconnect first, then reset if not connected) |
| 213 | + - Send devices IP address |
| 214 | + - Get the dynamic configuration from iobroker (generic devices section) |
| 215 | + - Build specific device URL's (based on the dynamic configuration) |
| 216 | + - Send data to iobroker |
| 217 | + - Get configurationdata (A0_Step_Voltage) for wind sensor from iobroker |
| 218 | + - Run setup for inactive sensors (if activated now) |
| 219 | + - Get the new interval (specific device section) |
| 220 | + - LED Blink |
| 221 | +
|
| 222 | +
|
| 223 | +
|
| 224 | +## Appendix |
| 225 | +
|
| 226 | +
|
| 227 | +
|
0 commit comments