mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
Compare commits
240
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49a0476487 | ||
|
|
f606d2c55d | ||
|
|
4f9a383d93 | ||
|
|
d4d0ee3b30 | ||
|
|
9705702f4c | ||
|
|
c3e015342c | ||
|
|
209484554e | ||
|
|
27377ab3ed | ||
|
|
7055d24693 | ||
|
|
62e6317a23 | ||
|
|
29f89b687d | ||
|
|
697d20a028 | ||
|
|
e9df0e75b9 | ||
|
|
f23f49931b | ||
|
|
4af29c405b | ||
|
|
d780f1a07f | ||
|
|
f9be283cb7 | ||
|
|
3f1cda7b81 | ||
|
|
2fd226d6bd | ||
|
|
3d1edcf33e | ||
|
|
cc740b46f1 | ||
|
|
e829058c92 | ||
|
|
685438c35d | ||
|
|
f8a4ef389f | ||
|
|
7e9c31131c | ||
|
|
99150c4214 | ||
|
|
ec7e6f80b0 | ||
|
|
dada682ed6 | ||
|
|
ab31b33a2c | ||
|
|
621585901f | ||
|
|
eaaf1fe888 | ||
|
|
41e4705198 | ||
|
|
c35fe3d500 | ||
|
|
e2da8ecbb9 | ||
|
|
3dad26a58a | ||
|
|
ae930a1d36 | ||
|
|
45e980beda | ||
|
|
8723e177df | ||
|
|
8454994023 | ||
|
|
50732aed8a | ||
|
|
f2888951dc | ||
|
|
56ac640986 | ||
|
|
df2d7be30b | ||
|
|
9e06cf4dc7 | ||
|
|
cd27339b8e | ||
|
|
ec38ba1fb7 | ||
|
|
b8fa42925f | ||
|
|
4169ca0ee8 | ||
|
|
578477bf6d | ||
|
|
0803e946b0 | ||
|
|
06001bbc94 | ||
|
|
f171d5b211 | ||
|
|
360b552424 | ||
|
|
d9597febf8 | ||
|
|
6aa21ea6f8 | ||
|
|
b1de652b62 | ||
|
|
5c3bf9e894 | ||
|
|
0acd7b0e70 | ||
|
|
8bbaffdeb0 | ||
|
|
19e86e7df3 | ||
|
|
311d6f01df | ||
|
|
61f47d5ffc | ||
|
|
72f0f95471 | ||
|
|
4e33472d81 | ||
|
|
69c4f970a9 | ||
|
|
28866bd08c | ||
|
|
0f93e3ed3c | ||
|
|
59a82ee17f | ||
|
|
e8af00f99f | ||
|
|
ad4b0f8008 | ||
|
|
ae2a0b5208 | ||
|
|
785266bd39 | ||
|
|
2e63e764b2 | ||
|
|
f7eaecf5d4 | ||
|
|
1bee80d0ec | ||
|
|
504a9aa295 | ||
|
|
059530a6b7 | ||
|
|
5b83c634e9 | ||
|
|
ff7ab3837e | ||
|
|
badad651de | ||
|
|
8a767b77e8 | ||
|
|
072a1a4080 | ||
|
|
394e4b095d | ||
|
|
ae1e62c8c6 | ||
|
|
0efb7823d7 | ||
|
|
3ee7d4d04e | ||
|
|
f2d3a5d222 | ||
|
|
904a5cc612 | ||
|
|
5241f93f5f | ||
|
|
6d33d21f70 | ||
|
|
045e2ef9f4 | ||
|
|
527267de62 | ||
|
|
29c01eeb38 | ||
|
|
1c5a1d3656 | ||
|
|
d6fe76750a | ||
|
|
1889c0f9e5 | ||
|
|
ebc16044e2 | ||
|
|
5695ea8fa8 | ||
|
|
16cc9aaa6b | ||
|
|
7f393af2a0 | ||
|
|
3e22607276 | ||
|
|
4de720382d | ||
|
|
a718572688 | ||
|
|
2d66c9fefa | ||
|
|
de51a130b3 | ||
|
|
a8020c9011 | ||
|
|
a2cbc6d474 | ||
|
|
ea5c99431c | ||
|
|
6f68d87f50 | ||
|
|
4aa9c5e0ba | ||
|
|
7e4666afed | ||
|
|
7651a07efc | ||
|
|
f961a9f331 | ||
|
|
bb49cbdc89 | ||
|
|
7fe1b41ea5 | ||
|
|
358e9f1e24 | ||
|
|
8f77ffc871 | ||
|
|
60faa58894 | ||
|
|
aba095b25d | ||
|
|
617ebe96de | ||
|
|
a1bf42dde1 | ||
|
|
b0b83543eb | ||
|
|
b97be9c718 | ||
|
|
33831b072b | ||
|
|
a5f94298d8 | ||
|
|
d0dc959d31 | ||
|
|
644aa2f65e | ||
|
|
e457fe7597 | ||
|
|
dcd409e9d9 | ||
|
|
c227c13ba2 | ||
|
|
c64566ce49 | ||
|
|
a9366c8f23 | ||
|
|
bbf470c61d | ||
|
|
1c1211c4f3 | ||
|
|
7da0bc4a44 | ||
|
|
91a0c51ff8 | ||
|
|
0aa523a329 | ||
|
|
cac7275eb9 | ||
|
|
109eaf7d25 | ||
|
|
9ba15f2c19 | ||
|
|
1c07d787c5 | ||
|
|
b7ae2ea5fe | ||
|
|
b75bb204e3 | ||
|
|
bfc8006205 | ||
|
|
aab2e4a442 | ||
|
|
abfdfe014e | ||
|
|
f82040d2ef | ||
|
|
56f2cf3121 | ||
|
|
6349f07d1a | ||
|
|
1b44559d3e | ||
|
|
a151e60755 | ||
|
|
ce11c84e74 | ||
|
|
9808bf86c4 | ||
|
|
cfae636e55 | ||
|
|
ebaaf50df6 | ||
|
|
5c0be9e89f | ||
|
|
36468663f7 | ||
|
|
fba32608ee | ||
|
|
06848e50c3 | ||
|
|
879d0d4916 | ||
|
|
d083a58cd7 | ||
|
|
b1e9ff9fdc | ||
|
|
304280f415 | ||
|
|
2c8ca1421f | ||
|
|
3ce0fb9f75 | ||
|
|
8a71d2abd6 | ||
|
|
1b174f4eac | ||
|
|
f1d18c7b41 | ||
|
|
204d4607ba | ||
|
|
51f7ce0cb6 | ||
|
|
8f73deb133 | ||
|
|
1d4147309c | ||
|
|
a68e4c1456 | ||
|
|
2ee51363dd | ||
|
|
172eb37b5b | ||
|
|
68e1d8ea69 | ||
|
|
ac8e8db0e7 | ||
|
|
d72bf9b76c | ||
|
|
6d3f535d16 | ||
|
|
0709763f3a | ||
|
|
538d843643 | ||
|
|
2339ee928c | ||
|
|
9550b951d5 | ||
|
|
0491af8a2f | ||
|
|
806a2757b2 | ||
|
|
3931b71d00 | ||
|
|
af0c3d5f62 | ||
|
|
c7a6ca4555 | ||
|
|
4a01e2eb49 | ||
|
|
d6ff20b35d | ||
|
|
0ada9aa105 | ||
|
|
6b04539571 | ||
|
|
9380ec13dc | ||
|
|
ae946c27c0 | ||
|
|
86cf00759f | ||
|
|
0eb5f55d63 | ||
|
|
f27d2aa7eb | ||
|
|
2d3285aaaf | ||
|
|
5bd2532853 | ||
|
|
765c56ccef | ||
|
|
4c755d83a6 | ||
|
|
1b9e1b92aa | ||
|
|
a4c73cc91e | ||
|
|
736fe2111a | ||
|
|
767b0af733 | ||
|
|
02255180e9 | ||
|
|
c3bde94f7a | ||
|
|
886958d479 | ||
|
|
84cbc19f38 | ||
|
|
178ec9dfa9 | ||
|
|
080be1ad0a | ||
|
|
232ca4f215 | ||
|
|
bfa6eac538 | ||
|
|
0ca06782b9 | ||
|
|
2079b0f28b | ||
|
|
32bf45e817 | ||
|
|
5d41bf9e73 | ||
|
|
dc5a2fd956 | ||
|
|
b20f05305b | ||
|
|
46586e5355 | ||
|
|
7e8a751657 | ||
|
|
7d61e55d34 | ||
|
|
2f663429a3 | ||
|
|
52e75ade78 | ||
|
|
525a0ba0a1 | ||
|
|
e774ef5751 | ||
|
|
eba1fb3388 | ||
|
|
3583db3e22 | ||
|
|
5d3f8bf073 | ||
|
|
dd88db1913 | ||
|
|
aab00567fc | ||
|
|
21cb6135dd | ||
|
|
07948c87aa | ||
|
|
5f4685337e | ||
|
|
08c158aa9c | ||
|
|
e9d71a8f35 | ||
|
|
3e3173cbb0 | ||
|
|
4543a10739 | ||
|
|
daecf2017e | ||
|
|
37122bc619 |
@@ -1,18 +1,43 @@
|
||||
**NOTE: This is not a support forum! For questions and support go here: https://www.letscontrolit.com/forum/viewforum.php?f=1**
|
||||
<!--- NOTE: This is not a support forum! For questions and support go here: --->
|
||||
<!--- https://www.letscontrolit.com/forum/viewforum.php?f=1 --->
|
||||
<!--- Remove topics that are not applicable to your feature request of issue --->
|
||||
<!--- Remember to have a "to the point" TITLE --->
|
||||
|
||||
### Steps to reproduce
|
||||
How can we trigger this problem?
|
||||
|
||||
Does the problem persists after powering off and on? (just resetting isn't enough sometimes)
|
||||
### Summarize of the problem/feature request
|
||||
<!--- Describe the problem or feature request --->
|
||||
YOUR TEXT GOES HERE
|
||||
|
||||
### Expected behavior
|
||||
Tell us what should happen?
|
||||
<!--- Tell us what should happen? --->
|
||||
YOUR TEXT GOES HERE
|
||||
|
||||
### Actual behavior
|
||||
Tell us what happens instead?
|
||||
<!--- Tell us what happens instead? --->
|
||||
YOUR TEXT GOES HERE
|
||||
|
||||
### Steps to reproduce
|
||||
<!--- How can we trigger this problem? --->
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
<!--- Does the problem persists after powering off and on? (just resetting isn't enough sometimes) --->
|
||||
<!--- Please document if you have restarted the unit and if the problem is then gone etc. etc. --->
|
||||
### System configuration
|
||||
|
||||
<!--- Please add as much information and screenshots as possible --->
|
||||
Hardware:
|
||||
|
||||
Software or git version:
|
||||
<!--- You should also provide links to hardware pages etc where we can find more info --->
|
||||
<!--- If you self compile, please state this and PLEASE try to ONLY REPORT ISSUES WITH OFFICIAL BUILDS! --->
|
||||
ESP Easy version:
|
||||
|
||||
<!--- In order to have a better readablity of your issue then you should place screenshots here --->
|
||||
<!--- Simply drag and drop them onto this template, move the text string below the "ESP Easy settings/screenshots" topic --->
|
||||
ESP Easy settings/screenshots:
|
||||
|
||||
### Rules or log data
|
||||
<!--- place your code/rules between the two ``` rows --->
|
||||
<!--- remove if not applicable! --->
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
@@ -16,3 +16,4 @@
|
||||
## Project #####################
|
||||
lib/readme.txt
|
||||
src/Custom.h
|
||||
test/output_export.cpp
|
||||
|
||||
Vendored
+423
@@ -1,3 +1,426 @@
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180429 (since mega-20180428)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sun Apr 29 04:00:07 CEST 2018
|
||||
|
||||
TD-er (7):
|
||||
[wifi] Setup static IP config after connecting to wifi.
|
||||
[wifi] Set static IP config before and after connect
|
||||
[wifi] Show number of reconnects in the sysinfo
|
||||
[wifi] Add wifi status log (Debug More) and DHCP/Static config to info page
|
||||
[wifi] ESP32 does not know wifi_station_get_connect_status()
|
||||
[wifi] Added connectionCheckHandler() to force reconnect when needed
|
||||
[wifi] Force wifi reconnect at lots of MQTT failed connects.
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180428 (since mega-20180426)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sat Apr 28 04:00:15 CEST 2018
|
||||
|
||||
TD-er (4):
|
||||
[wifi] Attempt to make event based wifi simpler
|
||||
[PlatformIO] Updated core to 2.4.1
|
||||
[wifi] Just disconnect when DNS lookup is not possible
|
||||
[Wifi] Avoid doing network communications when not connected.
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180426 (since mega-20180425)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Thu Apr 26 04:00:14 CEST 2018
|
||||
|
||||
Gijs Noorlander (1):
|
||||
Change use of core 2_4_0 to 2_3_0
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180425 (since mega-20180424)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Wed Apr 25 04:00:08 CEST 2018
|
||||
|
||||
Grovkillen (4):
|
||||
Added a void addCopyButton
|
||||
Made copy to clipboard JavaScript based instead
|
||||
Added copy to clipboard on log page
|
||||
Added new lines if BR + delimiter if wanted
|
||||
|
||||
Plebs (3):
|
||||
Fix for #1300
|
||||
Adding 3 new http commands: taskrun, taskvalueset and rules
|
||||
Fix another bug in LCD plugin
|
||||
|
||||
TD-er (2):
|
||||
[Modbus] PR #1128 made by @s0170071
|
||||
[wifi] More active reconnect to wifi when disconnected
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180424 (since mega-20180423)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Tue Apr 24 04:00:13 CEST 2018
|
||||
|
||||
Grovkillen (1):
|
||||
Added note to self compilers
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180423 (since mega-20180422)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Mon Apr 23 04:00:10 CEST 2018
|
||||
|
||||
Plebs (1):
|
||||
Fixing #1289 for backwards compatibility
|
||||
|
||||
TD-er (1):
|
||||
[wifi] Add delay between connection attempts
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180422 (since mega-20180421)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sun Apr 22 04:00:09 CEST 2018
|
||||
|
||||
Plebs (2):
|
||||
Syntax: [task#value#transformation#justification]
|
||||
Code changed as per TD-er suggestions
|
||||
|
||||
TD-er (1):
|
||||
[issue #1292] Remove CRC from settings, init settings and wifi fixes
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180421 (since mega-20180420)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sat Apr 21 04:00:08 CEST 2018
|
||||
|
||||
Grovkillen (1):
|
||||
Removed fade in of body added toast message!
|
||||
|
||||
Saverio Cisternino (4):
|
||||
Add Commands timerpause and timerresume
|
||||
Add Trigger Rules#TimerPause= and Rules#TimerResume=
|
||||
Add support at elseif statment
|
||||
Add debug info
|
||||
|
||||
TD-er (7):
|
||||
[WiFi] Init static IP before connect to wifi
|
||||
[Toast message] Change "Settings saved" to "Submitted"
|
||||
[info] Add more build related info to the log and wifi info link to wiki
|
||||
[Sonoff Pow] Add support for HLW8012
|
||||
[Sonoff Pow] Add support for HLW8012
|
||||
[Sonoff POW] Change Plugin ID to 76
|
||||
[Sonoff POW] Set some proper defaults for the Sonoff POW
|
||||
|
||||
Unknown (2):
|
||||
Merge remote-tracking branch 'papperone/mega' into merge/papperone
|
||||
Merge remote-tracking branch 'papperone/mega' into merge/papperone
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180420 (since mega-20180419)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Fri Apr 20 04:00:09 CEST 2018
|
||||
|
||||
Grovkillen (3):
|
||||
Added small fade in (0.5s)
|
||||
"bodymenu" was accidentally copied to all body
|
||||
Added extra breaks below "back to setup" button
|
||||
|
||||
TD-er (4):
|
||||
[Static IP] Make sure static mode is set correct always
|
||||
[wifi] Restart webserver when connection changes.
|
||||
[log] Make web log 30 lines for ESP32
|
||||
[wifi] Create event 'gotIP' after processing 'connected' event
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180419 (since mega-20180417)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Thu Apr 19 04:00:17 CEST 2018
|
||||
|
||||
Grovkillen (3):
|
||||
Updated the input, select, textareas with CSS
|
||||
Added CSS radio buttons to WiFi setup wizard
|
||||
Removed unused row on hardware settings page
|
||||
|
||||
Hans-Rune Bue (1):
|
||||
Implemented syslog facilities and levels
|
||||
|
||||
TD-er (3):
|
||||
[Static IP] Work-around for set _use_static_ip
|
||||
[PR #1257] Make it compile again
|
||||
[ESP32] Add Generic info plugin
|
||||
|
||||
sentinel073 (2):
|
||||
Issue #1211: Plugin template file and hints on writing new plugins
|
||||
Issue #1211: Plugin template file and hints on writing new plugins Added review comments
|
||||
|
||||
stefan (1):
|
||||
Changes for use of plugin sets
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180417 (since mega-20180416)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Tue Apr 17 04:00:09 CEST 2018
|
||||
|
||||
Grovkillen (11):
|
||||
Put borders around checkboxes
|
||||
Re-arranged Rules page
|
||||
Moved help button for sleep
|
||||
Moved help button on hardware page
|
||||
Made controller symbols a bit bigger (1)(2)(3)
|
||||
Change enable "off" to a nicer X
|
||||
Made input type password part of "wide"
|
||||
Added number input to CSS (width 100px)
|
||||
Made IDX column wider (device list)
|
||||
Added max widths for inputs
|
||||
"Ctr (IDX)" was accidentally removed, now added
|
||||
|
||||
TD-er (5):
|
||||
[wifi] Fix wifi reconnects with static IP
|
||||
[NTP] Add more information in the log when connecting to NTP server fail
|
||||
[issue #1260] parentheses error on the json page
|
||||
[P075] Nextion plugin (testing)
|
||||
[wifi] Fix build error for ESP32
|
||||
|
||||
Unknown (1):
|
||||
[Nextion] Initial support for Nextion displays
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180416 (since mega-20180415)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Mon Apr 16 04:00:09 CEST 2018
|
||||
|
||||
TD-er (4):
|
||||
[wifi] Prevent starting AP+STA mode with correct settings
|
||||
[Wifi] force STA mode at boot
|
||||
[wifi] Proper log of static IP configuration
|
||||
[info] Added FW information to help diagnose issues
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180415 (since mega-20180414)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sun Apr 15 04:00:08 CEST 2018
|
||||
|
||||
Gijs Noorlander (1):
|
||||
Added C013
|
||||
|
||||
Grovkillen (6):
|
||||
Made checkmarks CSS
|
||||
Fixed missed update.
|
||||
Added column width for separator...
|
||||
Updated some more stuff
|
||||
Made addFormSeparator function a lot cleaner
|
||||
Bumped delay timer for MQTT pub 10mSec
|
||||
|
||||
Nuno Sousa (1):
|
||||
Replace ultrasonic plugin with NewPing lib
|
||||
|
||||
Susis Strolch (4):
|
||||
add missing USES_XXX to _C*.ino, _N*.ino
|
||||
system variables %sysheap%, %syssec_d
|
||||
ignore power-on reset value (85.0 °C)
|
||||
DS_readTemp: handle power-on reset value
|
||||
|
||||
TD-er (4):
|
||||
[WebServer] Cleanup of all functions appending to a big string
|
||||
[PR #1247 ] Merged PR into the refactoring of Webserver
|
||||
[PR #1248] Fixed textarea sizes
|
||||
[Merge] Easier to merge, rebased on Mega branch.
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180414 (since mega-20180413)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sat Apr 14 04:00:08 CEST 2018
|
||||
|
||||
GHolli (3):
|
||||
Update _P049_MHZ19.ino
|
||||
Change comma to semicolon
|
||||
Downstream updates (#1)
|
||||
|
||||
Gerald (1):
|
||||
Update _P049_MHZ19.ino
|
||||
|
||||
Grovkillen (4):
|
||||
Added RSSI, BSSID, Channel to WifiScan/Setup
|
||||
Removed the serial print "done."
|
||||
Added better(?) format for tables
|
||||
Fixed main page!
|
||||
|
||||
Holli (2):
|
||||
It seems the offsets [3]..[4] for the detection range setting (command byte 0x99) are wrong in the latest online data sheet: http://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19b-co2-ver1_0.pdf According to the MH-Z19B data sheet version 1.2, valid from: 2017.03.22 (received 2018-03-07), the offset should be [6]..[7] instead. Fixing the implementation accordingly.
|
||||
Disable detection range commands by default.
|
||||
|
||||
Plebs (5):
|
||||
Fixes for #1208 and partial #1196
|
||||
modified float() call
|
||||
new #formats
|
||||
added more formats
|
||||
Added #I
|
||||
|
||||
TD-er (1):
|
||||
[issue #1239] %bssid% and %wi_ch% added as variables
|
||||
|
||||
clumsy-stefan (1):
|
||||
_P015_TSL2561 added Broadband and IR Values
|
||||
|
||||
linuxnico (1):
|
||||
add ds1822 definition to ds_read_temp function
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180413 (since mega-20180412)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Fri Apr 13 04:00:09 CEST 2018
|
||||
|
||||
TD-er (1):
|
||||
[wifi] Event based wifi, fix set AP and crash on start
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180412 (since mega-20180410)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Thu Apr 12 04:00:14 CEST 2018
|
||||
|
||||
Gijs Noorlander (1):
|
||||
[MQTT] Process MQTT loop on publish
|
||||
|
||||
TD-er (7):
|
||||
[issue #1215] Cannot login to accesspoint on new install
|
||||
[issue #1215] Cannot login to accesspoint on new install
|
||||
[Wifi] Use statemachine to move between Wifi states
|
||||
[WiFi] Event based wifi, now AP mode works
|
||||
[wifi] Make it work for ESP32 again
|
||||
[wifi] Fix wifi AP setup mode for ESP32.
|
||||
[wifi] Event based wifi, improve scan information.
|
||||
|
||||
flexiti (1):
|
||||
ESP CPU speed and ID
|
||||
|
||||
mvdbro (1):
|
||||
Reboot/Reset pin, build 20101 patch
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180410 (since mega-20180409)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Tue Apr 10 04:00:21 CEST 2018
|
||||
|
||||
Grovkillen (5):
|
||||
Added comments that will not show up on issues
|
||||
Update issue_template.md
|
||||
Update issue_template.md
|
||||
Update issue_template.md
|
||||
Update issue_template.md
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180409 (since mega-20180407)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Mon Apr 9 04:00:13 CEST 2018
|
||||
|
||||
mvdbro (2):
|
||||
Factory Reset (not enabled yet)
|
||||
Both reset/factoryreset option
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180407 (since mega-20180405)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sat Apr 7 04:00:12 CEST 2018
|
||||
|
||||
Grovkillen (1):
|
||||
Fixed clickable link www.letscontrolit.com (#1192)
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180405 (since mega-20180403)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Thu Apr 5 04:00:10 CEST 2018
|
||||
|
||||
Grovkillen (4):
|
||||
Updated JSON path for sensor values and names
|
||||
Delete WebServer.ino
|
||||
Moved to correct folder
|
||||
Added value number as discussed.
|
||||
|
||||
moi (3):
|
||||
Show CPU Load in JSON page
|
||||
Adds CPU Load LC in JSON page
|
||||
unwanted lib_ignore now properly commented
|
||||
|
||||
mvdbro (2):
|
||||
ESP32 RTOS config setting
|
||||
ESP32 RTOS 10 per second
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180403 (since mega-20180402)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Tue Apr 3 04:00:14 CEST 2018
|
||||
|
||||
Grovkillen (2):
|
||||
Update _P038_NeoPixel.ino
|
||||
Update _P029_Output.ino
|
||||
|
||||
mvdbro (1):
|
||||
ESP32 prep for RTOS multitasking
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180402 (since mega-20180401)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Mon Apr 2 04:00:10 CEST 2018
|
||||
|
||||
Gijs Noorlander (1):
|
||||
Revert "Merge pull request #1205 from s0170071/SerialSwap"
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180401 (since mega-20180331)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Sun Apr 1 04:00:08 CEST 2018
|
||||
|
||||
Grovkillen (1):
|
||||
P0059 (rotary encoder) and P0063 (ttp229, keypad)
|
||||
|
||||
TD-er (3):
|
||||
[issue #1201] MQTT#Disconnected event and MQTT stability improvements
|
||||
[issue #1201] MQTT#Disconnected event and MQTT stability improvements
|
||||
[deepsleep] Allow for some minimum wifi connect time
|
||||
|
||||
s0170071 (1):
|
||||
Serial Swap function
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180331 (since mega-20180330)
|
||||
-------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# PlatformIO folders
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
pio
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "HLW8012",
|
||||
"license": "GPL-3.0",
|
||||
"platforms": [
|
||||
"atmelavr",
|
||||
"espressif8266"
|
||||
],
|
||||
"repository": {
|
||||
"url": "https://bitbucket.org/xoseperez/hlw8012.git",
|
||||
"type": "git"
|
||||
},
|
||||
"frameworks": [
|
||||
"arduino"
|
||||
],
|
||||
"version": "1.0.0",
|
||||
"export": {
|
||||
"exclude": "tests"
|
||||
},
|
||||
"examples": [
|
||||
"examples/*/*.ino"
|
||||
],
|
||||
"dependencies": [],
|
||||
"authors": [
|
||||
{
|
||||
"maintainer": true,
|
||||
"name": "Xose Perez",
|
||||
"url": "http://tinkerman.cat",
|
||||
"email": "xose.perez@gmail.com"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"current",
|
||||
"hlw8012",
|
||||
"power",
|
||||
"voltage"
|
||||
],
|
||||
"id": 1281,
|
||||
"description": "HLW8012 library for Arduino and ESP8266"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# HLW8012 change log
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [1.0.0] 2017-01-13
|
||||
### Added
|
||||
- Added reactive power calculation
|
||||
- Added reset calibration values
|
||||
|
||||
### Fixed
|
||||
- Using volatile for variable inside callbacks
|
||||
|
||||
## [0.1.0] 2016-11-08
|
||||
- Initial working version
|
||||
@@ -0,0 +1,675 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# HLW8012
|
||||
|
||||
HLW8012 library for Arduino and ESP8266 using the [Arduino Core for ESP8266][1].
|
||||
|
||||

|
||||
|
||||
|
||||
This is the IC present in some chinese products like [Itead's Sonoff POW][2].
|
||||
The HLW8012 is a current, voltage and power monitor IC that outputs a pulse of a frequency inversely proportional to the value to be read.
|
||||
This IC provides two PWM outputs, the first one for power and the second one for current or voltage, depending on the SEL pin. The output values are always RMS. Power measurements are very consistent but current or voltage measurements require a minimum time lapse after changing the SEL pin value to become stable. This fact reduces sampling frequency.
|
||||
Higher values (of power, current or voltage) mean shorter pulses.
|
||||
|
||||
Typical values are:
|
||||
|
||||
* A 1Hz pulse on CF pin means around 12W RMS
|
||||
* A 1Hz pulse on CF1 pin means 15mA or 0.5V RMS depending on the value in SEL pin
|
||||
|
||||
These ratios are per datasheet typical application, but the actual circuitry might be different.
|
||||
Even if the circuit matches that on the datasheet the IC tolerances are quite loosy (+-15% for clock frequency, for instance).
|
||||
|
||||
## Features
|
||||
|
||||
The main features of the HLW8012 library are:
|
||||
|
||||
* Two available modes: interrupt-driven or non-interrupt-driven.
|
||||
* Default calibration based on product datasheet (3.1 Typical Applications).
|
||||
* You can specify the resistor values for your circuit.
|
||||
* Optional manual calibration based on expected values.
|
||||
|
||||
## Usage
|
||||
|
||||
Check the examples for indications on how to use the library.
|
||||
|
||||
### Interrupt driven mode
|
||||
|
||||
When using interrupts, values are monitored in the background. When calling the get***() methods the last sampled value is returned, this value might be up to a few seconds old if they are very low values. This is specially obvious when switching off the load. The new value of 0W or 0mA is ideally represented by infinite-length pulses. That means that the interrupt is not triggered, the value does not get updated and it will only timeout after 2 seconds (configurable through the pulse_timeout parameter in the begin() method). During that time lapse the library will still return the last non-zero value.
|
||||
|
||||
### Non interrupt mode
|
||||
|
||||
On the other hand, when not using interrupts, you have to let some time for the pulses in CF1 to stabilize before reading the value. So after calling setMode or toggleMode leave 2 seconds minimum before calling the get methods. The get method for the current mode will measure the pulse width and return the corresponding value, the other one will return the cached value (or 0 if none).
|
||||
|
||||
Use non-interrupt approach and a low pulse_timeout (200ms) only if you are deploying a battery powered device and you care more about your device power consumption than about precission. But then you should know the HLW8012 takes about 15mW...
|
||||
|
||||
### Notes
|
||||
|
||||
I've put together this library after doing a lot of tests with a Sonoff POW[2]. The HLW8012 datasheet (in the "docs" folder) gives some information but I couldn't find any about this issue in the CF1 line that requires some time for the pulse length to stabilize (apparently). Any help about that will be very welcome.
|
||||
|
||||
## Manual calibration
|
||||
|
||||
Use a pure resistive load with a well-known power consumption or use a multimeter to monitor it. A bulb is usually a good idea, although a toaster would be better since it's power consumption is higher.
|
||||
|
||||
Then use the expected*() methods and feed the values. For instance, for a 60W bulb in a 230 line that would be:
|
||||
|
||||
```
|
||||
hlw8012.expectedActivePower(60.0);
|
||||
hlw8012.expectedVoltage(230.0);
|
||||
hlw8012.expectedCurrent(60.0 / 230.0);
|
||||
```
|
||||
|
||||
|
||||
[1]:https://github.com/esp8266/Arduino
|
||||
[2]:https://www.itead.cc/sonoff-pow.html?acc=70efdf2ec9b086079795c442636b55fb
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@@ -0,0 +1,120 @@
|
||||
#include <Arduino.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
#define SERIAL_BAUDRATE 115200
|
||||
|
||||
// GPIOs
|
||||
#define RELAY_PIN 12
|
||||
#define SEL_PIN 5
|
||||
#define CF1_PIN 13
|
||||
#define CF_PIN 14
|
||||
|
||||
// Check values every 2 seconds
|
||||
#define UPDATE_TIME 2000
|
||||
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where a
|
||||
// the SEL_PIN drives a transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define CURRENT_MODE HIGH
|
||||
|
||||
// These are the nominal values for the resistors in the circuit
|
||||
#define CURRENT_RESISTOR 0.001
|
||||
#define VOLTAGE_RESISTOR_UPSTREAM ( 5 * 470000 ) // Real: 2280k
|
||||
#define VOLTAGE_RESISTOR_DOWNSTREAM ( 1000 ) // Real 1.009k
|
||||
|
||||
HLW8012 hlw8012;
|
||||
|
||||
void unblockingDelay(unsigned long mseconds) {
|
||||
unsigned long timeout = millis();
|
||||
while ((millis() - timeout) < mseconds) delay(1);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
|
||||
// Let's first read power, current and voltage
|
||||
// with an interval in between to allow the signal to stabilise:
|
||||
|
||||
hlw8012.getActivePower();
|
||||
|
||||
hlw8012.setMode(MODE_CURRENT);
|
||||
unblockingDelay(2000);
|
||||
hlw8012.getCurrent();
|
||||
|
||||
hlw8012.setMode(MODE_VOLTAGE);
|
||||
unblockingDelay(2000);
|
||||
hlw8012.getVoltage();
|
||||
|
||||
// Calibrate using a 60W bulb (pure resistive) on a 230V line
|
||||
hlw8012.expectedActivePower(60.0);
|
||||
hlw8012.expectedVoltage(230.0);
|
||||
hlw8012.expectedCurrent(60.0 / 230.0);
|
||||
|
||||
// Show corrected factors
|
||||
Serial.print("[HLW] New current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] New voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] New power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
// Init serial port and clean garbage
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Close the relay to switch on the load
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
|
||||
// Initialize HLW8012
|
||||
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
// * cf_pin, cf1_pin and sel_pin are GPIOs to the HLW8012 IC
|
||||
// * currentWhen is the value in sel_pin to select current sampling
|
||||
// * set use_interrupts to false, we will have to call handle() in the main loop to do the sampling
|
||||
// * set pulse_timeout to 500ms for a fast response but losing precision (that's ~24W precision :( )
|
||||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, false, 500000);
|
||||
|
||||
// These values are used to calculate current, voltage and power factors as per datasheet formula
|
||||
// These are the nominal values for the Sonoff POW resistors:
|
||||
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
|
||||
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
hlw8012.setResistors(CURRENT_RESISTOR, VOLTAGE_RESISTOR_UPSTREAM, VOLTAGE_RESISTOR_DOWNSTREAM);
|
||||
|
||||
// Show default (as per datasheet) multipliers
|
||||
Serial.print("[HLW] Default current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] Default voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] Default power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
calibrate();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
static unsigned long last = millis();
|
||||
|
||||
// This UPDATE_TIME should be at least twice the minimum time for the current or voltage
|
||||
// signals to stabilize. Experimentally that's about 1 second.
|
||||
if ((millis() - last) > UPDATE_TIME) {
|
||||
|
||||
last = millis();
|
||||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower());
|
||||
Serial.print("[HLW] Voltage (V) : "); Serial.println(hlw8012.getVoltage());
|
||||
Serial.print("[HLW] Current (A) : "); Serial.println(hlw8012.getCurrent());
|
||||
Serial.print("[HLW] Apparent Power (VA) : "); Serial.println(hlw8012.getApparentPower());
|
||||
Serial.print("[HLW] Power Factor (%) : "); Serial.println((int) (100 * hlw8012.getPowerFactor()));
|
||||
Serial.println();
|
||||
|
||||
// When not using interrupts we have to manually switch to current or voltage monitor
|
||||
// This means that every time we get into the conditional we only update one of them
|
||||
// while the other will return the cached value.
|
||||
hlw8012.toggleMode();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <Arduino.h>
|
||||
#include <LowPower.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
#define SERIAL_BAUDRATE 115200
|
||||
|
||||
// GPIOs
|
||||
#define SEL_PIN 5
|
||||
#define CF1_PIN 13
|
||||
#define CF_PIN 14
|
||||
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where a
|
||||
// the SEL_PIN drives a transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define CURRENT_MODE HIGH
|
||||
|
||||
// Maximum pulse width, a 2Hz pulse means a precission of ~24W
|
||||
#define MAX_PULSE_WIDTH 500000
|
||||
|
||||
HLW8012 hlw8012;
|
||||
|
||||
void setup() {
|
||||
|
||||
// Init serial port and clean garbage
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Initialize HLW8012
|
||||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, false, MAX_PULSE_WIDTH);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Sleep for 20 seconds
|
||||
for (unsigned short i = 0; i < 5; i++ ) {
|
||||
LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
|
||||
}
|
||||
|
||||
unsigned long start = millis();
|
||||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower());
|
||||
Serial.print("[HLW] Awake for (ms) : "); Serial.println(millis() - start);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
#include <Arduino.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
#define SERIAL_BAUDRATE 115200
|
||||
|
||||
// GPIOs
|
||||
#define RELAY_PIN 12
|
||||
#define SEL_PIN 5
|
||||
#define CF1_PIN 13
|
||||
#define CF_PIN 14
|
||||
|
||||
// Check values every 10 seconds
|
||||
#define UPDATE_TIME 10000
|
||||
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where a
|
||||
// the SEL_PIN drives a transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define CURRENT_MODE HIGH
|
||||
|
||||
// These are the nominal values for the resistors in the circuit
|
||||
#define CURRENT_RESISTOR 0.001
|
||||
#define VOLTAGE_RESISTOR_UPSTREAM ( 5 * 470000 ) // Real: 2280k
|
||||
#define VOLTAGE_RESISTOR_DOWNSTREAM ( 1000 ) // Real 1.009k
|
||||
|
||||
HLW8012 hlw8012;
|
||||
|
||||
// When using interrupts we have to call the library entry point
|
||||
// whenever an interrupt is triggered
|
||||
void hlw8012_cf1_interrupt() {
|
||||
hlw8012.cf1_interrupt();
|
||||
}
|
||||
void hlw8012_cf_interrupt() {
|
||||
hlw8012.cf_interrupt();
|
||||
}
|
||||
|
||||
// Library expects an interrupt on both edges
|
||||
void setInterrupts() {
|
||||
attachInterrupt(CF1_PIN, hlw8012_cf1_interrupt, CHANGE);
|
||||
attachInterrupt(CF_PIN, hlw8012_cf_interrupt, CHANGE);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
|
||||
// Let some time to register values
|
||||
unsigned long timeout = millis();
|
||||
while ((millis() - timeout) < 10000) {
|
||||
delay(1);
|
||||
}
|
||||
|
||||
// Calibrate using a 60W bulb (pure resistive) on a 230V line
|
||||
hlw8012.expectedActivePower(60.0);
|
||||
hlw8012.expectedVoltage(230.0);
|
||||
hlw8012.expectedCurrent(60.0 / 230.0);
|
||||
|
||||
// Show corrected factors
|
||||
Serial.print("[HLW] New current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] New voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] New power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
// Init serial port and clean garbage
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Close the relay to switch on the load
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
|
||||
// Initialize HLW8012
|
||||
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
// * cf_pin, cf1_pin and sel_pin are GPIOs to the HLW8012 IC
|
||||
// * currentWhen is the value in sel_pin to select current sampling
|
||||
// * set use_interrupts to true to use interrupts to monitor pulse widths
|
||||
// * leave pulse_timeout to the default value, recommended when using interrupts
|
||||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, true);
|
||||
|
||||
// These values are used to calculate current, voltage and power factors as per datasheet formula
|
||||
// These are the nominal values for the Sonoff POW resistors:
|
||||
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
|
||||
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
hlw8012.setResistors(CURRENT_RESISTOR, VOLTAGE_RESISTOR_UPSTREAM, VOLTAGE_RESISTOR_DOWNSTREAM);
|
||||
|
||||
// Show default (as per datasheet) multipliers
|
||||
Serial.print("[HLW] Default current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] Default voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] Default power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
setInterrupts();
|
||||
calibrate();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
static unsigned long last = millis();
|
||||
|
||||
// This UPDATE_TIME should be at least twice the interrupt timeout (2 second by default)
|
||||
if ((millis() - last) > UPDATE_TIME) {
|
||||
|
||||
last = millis();
|
||||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower());
|
||||
Serial.print("[HLW] Voltage (V) : "); Serial.println(hlw8012.getVoltage());
|
||||
Serial.print("[HLW] Current (A) : "); Serial.println(hlw8012.getCurrent());
|
||||
Serial.print("[HLW] Apparent Power (VA) : "); Serial.println(hlw8012.getApparentPower());
|
||||
Serial.print("[HLW] Power Factor (%) : "); Serial.println((int) (100 * hlw8012.getPowerFactor()));
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "HLW8012",
|
||||
"keywords": "hlw8012,power,current,voltage",
|
||||
"description": "HLW8012 library for Arduino and ESP8266",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://bitbucket.org/xoseperez/hlw8012.git"
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0",
|
||||
"exclude": "tests",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["atmelavr", "espressif8266"],
|
||||
"dependencies": [
|
||||
],
|
||||
"authors": {
|
||||
"name": "Xose Perez",
|
||||
"email": "xose.perez@gmail.com",
|
||||
"url": "http://tinkerman.cat",
|
||||
"maintainer": true
|
||||
},
|
||||
"examples": [
|
||||
"examples/*/*.ino"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name=HLW8012
|
||||
version=1.0.0
|
||||
author=Xose Pérez <xose.perez@gmail.com>
|
||||
maintainer=Xose Perez <xose.perez@gmail.com>
|
||||
sentence=HLW8012 for Arduino / ESP8216
|
||||
paragraph=HLW8012 power/current/voltage monitor IC library for Arduino and ESP8266. Use 2.x.x for ESP and 1.3 for AVR.
|
||||
category=Sensors
|
||||
url=https://bitbucket.org/xoseperez/hlw8012
|
||||
architectures=*
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
|
||||
HLW8012 1.0.0
|
||||
|
||||
Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
void HLW8012::begin(
|
||||
unsigned char cf_pin,
|
||||
unsigned char cf1_pin,
|
||||
unsigned char sel_pin,
|
||||
unsigned char currentWhen,
|
||||
bool use_interrupts,
|
||||
unsigned long pulse_timeout
|
||||
) {
|
||||
|
||||
_cf_pin = cf_pin;
|
||||
_cf1_pin = cf1_pin;
|
||||
_sel_pin = sel_pin;
|
||||
_current_mode = currentWhen;
|
||||
_use_interrupts = use_interrupts;
|
||||
_pulse_timeout = pulse_timeout;
|
||||
|
||||
pinMode(_cf_pin, INPUT_PULLUP);
|
||||
pinMode(_cf1_pin, INPUT_PULLUP);
|
||||
pinMode(_sel_pin, OUTPUT);
|
||||
|
||||
_calculateDefaultMultipliers();
|
||||
|
||||
_mode = _current_mode;
|
||||
digitalWrite(_sel_pin, _mode);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void HLW8012::setMode(hlw8012_mode_t mode) {
|
||||
_mode = (mode == MODE_CURRENT) ? _current_mode : 1 - _current_mode;
|
||||
digitalWrite(_sel_pin, _mode);
|
||||
if (_use_interrupts) {
|
||||
_last_cf1_interrupt = _first_cf1_interrupt = micros();
|
||||
}
|
||||
}
|
||||
|
||||
hlw8012_mode_t HLW8012::getMode() {
|
||||
return (_mode == _current_mode) ? MODE_CURRENT : MODE_VOLTAGE;
|
||||
}
|
||||
|
||||
hlw8012_mode_t HLW8012::toggleMode() {
|
||||
hlw8012_mode_t new_mode = getMode() == MODE_CURRENT ? MODE_VOLTAGE : MODE_CURRENT;
|
||||
setMode(new_mode);
|
||||
return new_mode;
|
||||
}
|
||||
|
||||
double HLW8012::getCurrent() {
|
||||
|
||||
// Power measurements are more sensitive to switch offs,
|
||||
// so we first check if power is 0 to set _current to 0 too
|
||||
if (_power == 0) {
|
||||
_current_pulse_width = 0;
|
||||
|
||||
} else if (_use_interrupts) {
|
||||
_checkCF1Signal();
|
||||
|
||||
} else if (_mode == _current_mode) {
|
||||
_current_pulse_width = pulseIn(_cf1_pin, HIGH, _pulse_timeout);
|
||||
}
|
||||
|
||||
_current = (_current_pulse_width > 0) ? _current_multiplier / _current_pulse_width / 2 : 0;
|
||||
return _current;
|
||||
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getVoltage() {
|
||||
if (_use_interrupts) {
|
||||
_checkCF1Signal();
|
||||
} else if (_mode != _current_mode) {
|
||||
_voltage_pulse_width = pulseIn(_cf1_pin, HIGH, _pulse_timeout);
|
||||
}
|
||||
_voltage = (_voltage_pulse_width > 0) ? _voltage_multiplier / _voltage_pulse_width / 2 : 0;
|
||||
return _voltage;
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getActivePower() {
|
||||
if (_use_interrupts) {
|
||||
_checkCFSignal();
|
||||
} else {
|
||||
_power_pulse_width = pulseIn(_cf_pin, HIGH, _pulse_timeout);
|
||||
}
|
||||
_power = (_power_pulse_width > 0) ? _power_multiplier / _power_pulse_width / 2 : 0;
|
||||
return _power;
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getApparentPower() {
|
||||
double current = getCurrent();
|
||||
unsigned int voltage = getVoltage();
|
||||
return voltage * current;
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getReactivePower() {
|
||||
unsigned int active = getActivePower();
|
||||
unsigned int apparent = getApparentPower();
|
||||
if (apparent > active) {
|
||||
return sqrt(apparent * apparent - active * active);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
double HLW8012::getPowerFactor() {
|
||||
unsigned int active = getActivePower();
|
||||
unsigned int apparent = getApparentPower();
|
||||
if (active > apparent) return 1;
|
||||
if (apparent == 0) return 0;
|
||||
return (double) active / apparent;
|
||||
}
|
||||
|
||||
void HLW8012::expectedCurrent(double value) {
|
||||
if (_current == 0) getCurrent();
|
||||
if (_current > 0) _current_multiplier *= (value / _current);
|
||||
}
|
||||
|
||||
void HLW8012::expectedVoltage(unsigned int value) {
|
||||
if (_voltage == 0) getVoltage();
|
||||
if (_voltage > 0) _voltage_multiplier *= ((double) value / _voltage);
|
||||
}
|
||||
|
||||
void HLW8012::expectedActivePower(unsigned int value) {
|
||||
if (_power == 0) getActivePower();
|
||||
if (_power > 0) _power_multiplier *= ((double) value / _power);
|
||||
}
|
||||
|
||||
void HLW8012::resetMultipliers() {
|
||||
_calculateDefaultMultipliers();
|
||||
}
|
||||
|
||||
void HLW8012::setResistors(double current, double voltage_upstream, double voltage_downstream) {
|
||||
if (voltage_downstream > 0) {
|
||||
_current_resistor = current;
|
||||
_voltage_resistor = (voltage_upstream + voltage_downstream) / voltage_downstream;
|
||||
_calculateDefaultMultipliers();
|
||||
}
|
||||
}
|
||||
|
||||
void HLW8012::cf_interrupt() {
|
||||
unsigned long now = micros();
|
||||
_power_pulse_width = now - _last_cf_interrupt;
|
||||
_last_cf_interrupt = now;
|
||||
}
|
||||
|
||||
void HLW8012::cf1_interrupt() {
|
||||
|
||||
unsigned long now = micros();
|
||||
unsigned long pulse_width;
|
||||
|
||||
if ((now - _first_cf1_interrupt) > _pulse_timeout) {
|
||||
|
||||
if (_last_cf1_interrupt == _first_cf1_interrupt) {
|
||||
pulse_width = 0;
|
||||
} else {
|
||||
pulse_width = now - _last_cf1_interrupt;
|
||||
}
|
||||
|
||||
if (_mode == _current_mode) {
|
||||
_current_pulse_width = pulse_width;
|
||||
} else {
|
||||
_voltage_pulse_width = pulse_width;
|
||||
}
|
||||
|
||||
_mode = 1 - _mode;
|
||||
digitalWrite(_sel_pin, _mode);
|
||||
_first_cf1_interrupt = now;
|
||||
|
||||
}
|
||||
|
||||
_last_cf1_interrupt = now;
|
||||
|
||||
}
|
||||
|
||||
void HLW8012::_checkCFSignal() {
|
||||
if ((micros() - _last_cf_interrupt) > _pulse_timeout) _power_pulse_width = 0;
|
||||
}
|
||||
|
||||
void HLW8012::_checkCF1Signal() {
|
||||
if ((micros() - _last_cf1_interrupt) > _pulse_timeout) {
|
||||
if (_mode == _current_mode) {
|
||||
_current_pulse_width = 0;
|
||||
} else {
|
||||
_voltage_pulse_width = 0;
|
||||
}
|
||||
toggleMode();
|
||||
}
|
||||
}
|
||||
|
||||
// These are the multipliers for current, voltage and power as per datasheet
|
||||
// These values divided by output period (in useconds) give the actual value
|
||||
// For power a frequency of 1Hz means around 12W
|
||||
// For current a frequency of 1Hz means around 15mA
|
||||
// For voltage a frequency of 1Hz means around 0.5V
|
||||
void HLW8012::_calculateDefaultMultipliers() {
|
||||
_current_multiplier = ( 1000000.0 * 512 * V_REF / _current_resistor / 24.0 / F_OSC );
|
||||
_voltage_multiplier = ( 1000000.0 * 512 * V_REF * _voltage_resistor / 2.0 / F_OSC );
|
||||
_power_multiplier = ( 1000000.0 * 128 * V_REF * V_REF * _voltage_resistor / _current_resistor / 48.0 / F_OSC );
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
|
||||
HLW8012 1.0.0
|
||||
|
||||
Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HLW8012_h
|
||||
#define HLW8012_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// Internal voltage reference value
|
||||
#define V_REF 2.43
|
||||
|
||||
// The factor of a 1mOhm resistor
|
||||
// as per recomended circuit in datasheet
|
||||
// A 1mOhm resistor allows a ~30A max measurement
|
||||
#define R_CURRENT 0.001
|
||||
|
||||
// This is the factor of a voltage divider of 6x 470K upstream and 1k downstream
|
||||
// as per recomended circuit in datasheet
|
||||
#define R_VOLTAGE 2821
|
||||
|
||||
// Frequency of the HLW8012 internal clock
|
||||
#define F_OSC 3579000
|
||||
|
||||
// Minimum delay between selecting a mode and reading a sample
|
||||
#define READING_INTERVAL 3000
|
||||
|
||||
// Maximum pulse with in microseconds
|
||||
// If longer than this pulse width is reset to 0
|
||||
// This value is purely experimental.
|
||||
// Higher values allow for a better precission but reduce sampling rate
|
||||
// and response speed to change
|
||||
// Lower values increase sampling rate but reduce precission
|
||||
// Values below 0.5s are not recommended since current and voltage output
|
||||
// will have no time to stabilise
|
||||
#define PULSE_TIMEOUT 2000000
|
||||
|
||||
// CF1 mode
|
||||
typedef enum {
|
||||
MODE_CURRENT,
|
||||
MODE_VOLTAGE
|
||||
} hlw8012_mode_t;
|
||||
|
||||
class HLW8012 {
|
||||
|
||||
public:
|
||||
|
||||
void cf_interrupt();
|
||||
void cf1_interrupt();
|
||||
|
||||
void begin(
|
||||
unsigned char cf_pin,
|
||||
unsigned char cf1_pin,
|
||||
unsigned char sel_pin,
|
||||
unsigned char currentWhen = HIGH,
|
||||
bool use_interrupts = true,
|
||||
unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
|
||||
void setMode(hlw8012_mode_t mode);
|
||||
hlw8012_mode_t getMode();
|
||||
hlw8012_mode_t toggleMode();
|
||||
|
||||
double getCurrent();
|
||||
unsigned int getVoltage();
|
||||
unsigned int getActivePower();
|
||||
unsigned int getApparentPower();
|
||||
double getPowerFactor();
|
||||
unsigned int getReactivePower();
|
||||
|
||||
void setResistors(double current, double voltage_upstream, double voltage_downstream);
|
||||
|
||||
void expectedCurrent(double current);
|
||||
void expectedVoltage(unsigned int current);
|
||||
void expectedActivePower(unsigned int power);
|
||||
|
||||
double getCurrentMultiplier() { return _current_multiplier; };
|
||||
double getVoltageMultiplier() { return _voltage_multiplier; };
|
||||
double getPowerMultiplier() { return _power_multiplier; };
|
||||
|
||||
void setCurrentMultiplier(double current_multiplier) { _current_multiplier = current_multiplier; };
|
||||
void setVoltageMultiplier(double voltage_multiplier) { _voltage_multiplier = voltage_multiplier; };
|
||||
void setPowerMultiplier(double power_multiplier) { _power_multiplier = power_multiplier; };
|
||||
void resetMultipliers();
|
||||
|
||||
private:
|
||||
|
||||
unsigned char _cf_pin;
|
||||
unsigned char _cf1_pin;
|
||||
unsigned char _sel_pin;
|
||||
|
||||
double _current_resistor = R_CURRENT;
|
||||
double _voltage_resistor = R_VOLTAGE;
|
||||
|
||||
double _current_multiplier;
|
||||
double _voltage_multiplier;
|
||||
double _power_multiplier;
|
||||
|
||||
unsigned long _pulse_timeout = PULSE_TIMEOUT;
|
||||
volatile unsigned long _voltage_pulse_width = 0;
|
||||
volatile unsigned long _current_pulse_width = 0;
|
||||
volatile unsigned long _power_pulse_width = 0;
|
||||
|
||||
double _current = 0;
|
||||
unsigned int _voltage = 0;
|
||||
unsigned int _power = 0;
|
||||
|
||||
unsigned char _current_mode = HIGH;
|
||||
volatile unsigned char _mode;
|
||||
|
||||
bool _use_interrupts = true;
|
||||
volatile unsigned long _last_cf_interrupt = 0;
|
||||
volatile unsigned long _last_cf1_interrupt = 0;
|
||||
volatile unsigned long _first_cf1_interrupt = 0;
|
||||
|
||||
void _checkCFSignal();
|
||||
void _checkCF1Signal();
|
||||
void _calculateDefaultMultipliers();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Executable
+362
@@ -0,0 +1,362 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Created by Tim Eckel - teckel@leethost.com
|
||||
// Copyright 2016 License: GNU GPL v3 http://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// See "NewPing.h" for purpose, syntax, version history, links, and more.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "NewPing.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// NewPing constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
NewPing::NewPing(uint8_t trigger_pin, uint8_t echo_pin, unsigned int max_cm_distance) {
|
||||
#if DO_BITWISE == true
|
||||
_triggerBit = digitalPinToBitMask(trigger_pin); // Get the port register bitmask for the trigger pin.
|
||||
_echoBit = digitalPinToBitMask(echo_pin); // Get the port register bitmask for the echo pin.
|
||||
|
||||
_triggerOutput = portOutputRegister(digitalPinToPort(trigger_pin)); // Get the output port register for the trigger pin.
|
||||
_echoInput = portInputRegister(digitalPinToPort(echo_pin)); // Get the input port register for the echo pin.
|
||||
|
||||
_triggerMode = (uint8_t *) portModeRegister(digitalPinToPort(trigger_pin)); // Get the port mode register for the trigger pin.
|
||||
#else
|
||||
_triggerPin = trigger_pin;
|
||||
_echoPin = echo_pin;
|
||||
#endif
|
||||
|
||||
set_max_distance(max_cm_distance); // Call function to set the max sensor distance.
|
||||
|
||||
#if (defined (__arm__) && defined (TEENSYDUINO)) || DO_BITWISE != true
|
||||
pinMode(echo_pin, INPUT); // Set echo pin to input (on Teensy 3.x (ARM), pins default to disabled, at least one pinMode() is needed for GPIO mode).
|
||||
pinMode(trigger_pin, OUTPUT); // Set trigger pin to output (on Teensy 3.x (ARM), pins default to disabled, at least one pinMode() is needed for GPIO mode).
|
||||
#endif
|
||||
|
||||
#if defined (ARDUINO_AVR_YUN)
|
||||
pinMode(echo_pin, INPUT); // Set echo pin to input for the Arduino Yun, not sure why it doesn't default this way.
|
||||
#endif
|
||||
|
||||
#if ONE_PIN_ENABLED != true && DO_BITWISE == true
|
||||
*_triggerMode |= _triggerBit; // Set trigger pin to output.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Standard ping methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
unsigned int NewPing::ping(unsigned int max_cm_distance) {
|
||||
if (max_cm_distance > 0) set_max_distance(max_cm_distance); // Call function to set a new max sensor distance.
|
||||
|
||||
if (!ping_trigger()) return NO_ECHO; // Trigger a ping, if it returns false, return NO_ECHO to the calling function.
|
||||
|
||||
#if URM37_ENABLED == true
|
||||
#if DO_BITWISE == true
|
||||
while (!(*_echoInput & _echoBit)) // Wait for the ping echo.
|
||||
#else
|
||||
while (!digitalRead(_echoPin)) // Wait for the ping echo.
|
||||
#endif
|
||||
if (micros() > _max_time) return NO_ECHO; // Stop the loop and return NO_ECHO (false) if we're beyond the set maximum distance.
|
||||
#else
|
||||
#if DO_BITWISE == true
|
||||
while (*_echoInput & _echoBit) // Wait for the ping echo.
|
||||
#else
|
||||
while (digitalRead(_echoPin)) // Wait for the ping echo.
|
||||
#endif
|
||||
if (micros() > _max_time) return NO_ECHO; // Stop the loop and return NO_ECHO (false) if we're beyond the set maximum distance.
|
||||
#endif
|
||||
|
||||
return (micros() - (_max_time - _maxEchoTime) - PING_OVERHEAD); // Calculate ping time, include overhead.
|
||||
}
|
||||
|
||||
|
||||
unsigned long NewPing::ping_cm(unsigned int max_cm_distance) {
|
||||
unsigned long echoTime = NewPing::ping(max_cm_distance); // Calls the ping method and returns with the ping echo distance in uS.
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_CM); // Call the ping method and returns the distance in centimeters (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_CM); // Convert uS to centimeters.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned long NewPing::ping_in(unsigned int max_cm_distance) {
|
||||
unsigned long echoTime = NewPing::ping(max_cm_distance); // Calls the ping method and returns with the ping echo distance in uS.
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_IN); // Call the ping method and returns the distance in inches (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_IN); // Convert uS to inches.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned long NewPing::ping_median(uint8_t it, unsigned int max_cm_distance) {
|
||||
unsigned int uS[it], last;
|
||||
uint8_t j, i = 0;
|
||||
unsigned long t;
|
||||
uS[0] = NO_ECHO;
|
||||
|
||||
while (i < it) {
|
||||
t = micros(); // Start ping timestamp.
|
||||
last = ping(max_cm_distance); // Send ping.
|
||||
|
||||
if (last != NO_ECHO) { // Ping in range, include as part of median.
|
||||
if (i > 0) { // Don't start sort till second ping.
|
||||
for (j = i; j > 0 && uS[j - 1] < last; j--) // Insertion sort loop.
|
||||
uS[j] = uS[j - 1]; // Shift ping array to correct position for sort insertion.
|
||||
} else j = 0; // First ping is sort starting point.
|
||||
uS[j] = last; // Add last ping to array in sorted position.
|
||||
i++; // Move to next ping.
|
||||
} else it--; // Ping out of range, skip and don't include as part of median.
|
||||
|
||||
if (i < it && micros() - t < PING_MEDIAN_DELAY)
|
||||
delay((PING_MEDIAN_DELAY + t - micros()) / 1000); // Millisecond delay between pings.
|
||||
|
||||
}
|
||||
return (uS[it >> 1]); // Return the ping distance median.
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Standard and timer interrupt ping method support functions (not called directly)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
boolean NewPing::ping_trigger() {
|
||||
#if DO_BITWISE == true
|
||||
#if ONE_PIN_ENABLED == true
|
||||
*_triggerMode |= _triggerBit; // Set trigger pin to output.
|
||||
#endif
|
||||
|
||||
*_triggerOutput &= ~_triggerBit; // Set the trigger pin low, should already be low, but this will make sure it is.
|
||||
delayMicroseconds(4); // Wait for pin to go low.
|
||||
*_triggerOutput |= _triggerBit; // Set trigger pin high, this tells the sensor to send out a ping.
|
||||
delayMicroseconds(10); // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.
|
||||
*_triggerOutput &= ~_triggerBit; // Set trigger pin back to low.
|
||||
|
||||
#if ONE_PIN_ENABLED == true
|
||||
*_triggerMode &= ~_triggerBit; // Set trigger pin to input (when using one Arduino pin, this is technically setting the echo pin to input as both are tied to the same Arduino pin).
|
||||
#endif
|
||||
|
||||
#if URM37_ENABLED == true
|
||||
if (!(*_echoInput & _echoBit)) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (*_echoInput & _echoBit) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#else
|
||||
if (*_echoInput & _echoBit) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (!(*_echoInput & _echoBit)) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#endif
|
||||
#else
|
||||
#if ONE_PIN_ENABLED == true
|
||||
pinMode(_triggerPin, OUTPUT); // Set trigger pin to output.
|
||||
#endif
|
||||
|
||||
digitalWrite(_triggerPin, LOW); // Set the trigger pin low, should already be low, but this will make sure it is.
|
||||
delayMicroseconds(4); // Wait for pin to go low.
|
||||
digitalWrite(_triggerPin, HIGH); // Set trigger pin high, this tells the sensor to send out a ping.
|
||||
delayMicroseconds(10); // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.
|
||||
digitalWrite(_triggerPin, LOW); // Set trigger pin back to low.
|
||||
|
||||
#if ONE_PIN_ENABLED == true
|
||||
pinMode(_triggerPin, INPUT); // Set trigger pin to input (when using one Arduino pin, this is technically setting the echo pin to input as both are tied to the same Arduino pin).
|
||||
#endif
|
||||
|
||||
#if URM37_ENABLED == true
|
||||
if (!digitalRead(_echoPin)) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (digitalRead(_echoPin)) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#else
|
||||
if (digitalRead(_echoPin)) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (!digitalRead(_echoPin)) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_max_time = micros() + _maxEchoTime; // Ping started, set the time-out.
|
||||
return true; // Ping started successfully.
|
||||
}
|
||||
|
||||
|
||||
void NewPing::set_max_distance(unsigned int max_cm_distance) {
|
||||
#if ROUNDING_ENABLED == false
|
||||
_maxEchoTime = min(max_cm_distance + 1, (unsigned int) MAX_SENSOR_DISTANCE + 1) * US_ROUNDTRIP_CM; // Calculate the maximum distance in uS (no rounding).
|
||||
#else
|
||||
_maxEchoTime = min(max_cm_distance, (unsigned int) MAX_SENSOR_DISTANCE) * US_ROUNDTRIP_CM + (US_ROUNDTRIP_CM / 2); // Calculate the maximum distance in uS.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if TIMER_ENABLED == true && DO_BITWISE == true
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Timer interrupt ping methods (won't work with non-AVR, ATmega128 and all ATtiny microcontrollers)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void NewPing::ping_timer(void (*userFunc)(void), unsigned int max_cm_distance) {
|
||||
if (max_cm_distance > 0) set_max_distance(max_cm_distance); // Call function to set a new max sensor distance.
|
||||
|
||||
if (!ping_trigger()) return; // Trigger a ping, if it returns false, return without starting the echo timer.
|
||||
timer_us(ECHO_TIMER_FREQ, userFunc); // Set ping echo timer check every ECHO_TIMER_FREQ uS.
|
||||
}
|
||||
|
||||
|
||||
boolean NewPing::check_timer() {
|
||||
if (micros() > _max_time) { // Outside the time-out limit.
|
||||
timer_stop(); // Disable timer interrupt
|
||||
return false; // Cancel ping timer.
|
||||
}
|
||||
|
||||
#if URM37_ENABLED == false
|
||||
if (!(*_echoInput & _echoBit)) { // Ping echo received.
|
||||
#else
|
||||
if (*_echoInput & _echoBit) { // Ping echo received.
|
||||
#endif
|
||||
timer_stop(); // Disable timer interrupt
|
||||
ping_result = (micros() - (_max_time - _maxEchoTime) - PING_TIMER_OVERHEAD); // Calculate ping time including overhead.
|
||||
return true; // Return ping echo true.
|
||||
}
|
||||
|
||||
return false; // Return false because there's no ping echo yet.
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Timer2/Timer4 interrupt methods (can be used for non-ultrasonic needs)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Variables used for timer functions
|
||||
void (*intFunc)();
|
||||
void (*intFunc2)();
|
||||
unsigned long _ms_cnt_reset;
|
||||
volatile unsigned long _ms_cnt;
|
||||
#if defined(__arm__) && defined(TEENSYDUINO)
|
||||
IntervalTimer itimer;
|
||||
#endif
|
||||
|
||||
|
||||
void NewPing::timer_us(unsigned int frequency, void (*userFunc)(void)) {
|
||||
intFunc = userFunc; // User's function to call when there's a timer event.
|
||||
timer_setup(); // Configure the timer interrupt.
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
OCR4C = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
|
||||
TIMSK4 = (1<<TOIE4); // Enable Timer4 interrupt.
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
|
||||
itimer.begin(userFunc, frequency); // Really simple on the Teensy 3.x, calls userFunc every 'frequency' uS.
|
||||
#else
|
||||
OCR2A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
|
||||
TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NewPing::timer_ms(unsigned long frequency, void (*userFunc)(void)) {
|
||||
intFunc = NewPing::timer_ms_cntdwn; // Timer events are sent here once every ms till user's frequency is reached.
|
||||
intFunc2 = userFunc; // User's function to call when user's frequency is reached.
|
||||
_ms_cnt = _ms_cnt_reset = frequency; // Current ms counter and reset value.
|
||||
timer_setup(); // Configure the timer interrupt.
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
OCR4C = 249; // Every count is 4uS, so 1ms = 250 counts - 1.
|
||||
TIMSK4 = (1<<TOIE4); // Enable Timer4 interrupt.
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
|
||||
itimer.begin(NewPing::timer_ms_cntdwn, 1000); // Set timer to 1ms (1000 uS).
|
||||
#else
|
||||
OCR2A = 249; // Every count is 4uS, so 1ms = 250 counts - 1.
|
||||
TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NewPing::timer_stop() { // Disable timer interrupt.
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
TIMSK4 = 0;
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
|
||||
itimer.end();
|
||||
#else
|
||||
TIMSK2 &= ~(1<<OCIE2A);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Timer2/Timer4 interrupt method support functions (not called directly)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void NewPing::timer_setup() {
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
timer_stop(); // Disable Timer4 interrupt.
|
||||
TCCR4A = TCCR4C = TCCR4D = TCCR4E = 0;
|
||||
TCCR4B = (1<<CS42) | (1<<CS41) | (1<<CS40) | (1<<PSR4); // Set Timer4 prescaler to 64 (4uS/count, 4uS-1020uS range).
|
||||
TIFR4 = (1<<TOV4);
|
||||
TCNT4 = 0; // Reset Timer4 counter.
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__) // Alternate timer commands for certain microcontrollers.
|
||||
timer_stop(); // Disable Timer2 interrupt.
|
||||
ASSR &= ~(1<<AS2); // Set clock, not pin.
|
||||
TCCR2 = (1<<WGM21 | 1<<CS22); // Set Timer2 to CTC mode, prescaler to 64 (4uS/count, 4uS-1020uS range).
|
||||
TCNT2 = 0; // Reset Timer2 counter.
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO)
|
||||
timer_stop(); // Stop the timer.
|
||||
#else
|
||||
timer_stop(); // Disable Timer2 interrupt.
|
||||
ASSR &= ~(1<<AS2); // Set clock, not pin.
|
||||
TCCR2A = (1<<WGM21); // Set Timer2 to CTC mode.
|
||||
TCCR2B = (1<<CS22); // Set Timer2 prescaler to 64 (4uS/count, 4uS-1020uS range).
|
||||
TCNT2 = 0; // Reset Timer2 counter.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NewPing::timer_ms_cntdwn() {
|
||||
if (!_ms_cnt--) { // Count down till we reach zero.
|
||||
intFunc2(); // Scheduled time reached, run the main timer event function.
|
||||
_ms_cnt = _ms_cnt_reset; // Reset the ms timer.
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
ISR(TIMER4_OVF_vect) {
|
||||
intFunc(); // Call wrapped function.
|
||||
}
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__) // Alternate timer commands for certain microcontrollers.
|
||||
ISR(TIMER2_COMP_vect) {
|
||||
intFunc(); // Call wrapped function.
|
||||
}
|
||||
#elif defined (__arm__)
|
||||
// Do nothing...
|
||||
#else
|
||||
ISR(TIMER2_COMPA_vect) {
|
||||
intFunc(); // Call wrapped function.
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Conversion methods (rounds result to nearest cm or inch).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
unsigned int NewPing::convert_cm(unsigned int echoTime) {
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_CM); // Convert uS to centimeters (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_CM); // Convert uS to centimeters.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned int NewPing::convert_in(unsigned int echoTime) {
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_IN); // Convert uS to inches (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_IN); // Convert uS to inches.
|
||||
#endif
|
||||
}
|
||||
Executable
+245
@@ -0,0 +1,245 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// NewPing Library - v1.8 - 07/30/2016
|
||||
//
|
||||
// AUTHOR/LICENSE:
|
||||
// Created by Tim Eckel - teckel@leethost.com
|
||||
// Copyright 2016 License: GNU GPL v3 http://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// LINKS:
|
||||
// Project home: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
|
||||
// Blog: http://arduino.cc/forum/index.php/topic,106043.0.html
|
||||
//
|
||||
// DISCLAIMER:
|
||||
// This software is furnished "as is", without technical support, and with no
|
||||
// warranty, express or implied, as to its usefulness for any purpose.
|
||||
//
|
||||
// BACKGROUND:
|
||||
// When I first received an ultrasonic sensor I was not happy with how poorly
|
||||
// it worked. Quickly I realized the problem wasn't the sensor, it was the
|
||||
// available ping and ultrasonic libraries causing the problem. The NewPing
|
||||
// library totally fixes these problems, adds many new features, and breaths
|
||||
// new life into these very affordable distance sensors.
|
||||
//
|
||||
// FEATURES:
|
||||
// * Works with many different ultrasonic sensors: SR04, SRF05, SRF06, DYP-ME007, URM37 & Parallax PING))).
|
||||
// * Compatible with the entire Arduino line-up (and clones), Teensy family (including $19 96Mhz 32 bit Teensy 3.2) and non-AVR microcontrollers.
|
||||
// * Interface with all but the SRF06 sensor using only one Arduino pin.
|
||||
// * Doesn't lag for a full second if no ping/echo is received.
|
||||
// * Ping sensors consistently and reliably at up to 30 times per second.
|
||||
// * Timer interrupt method for event-driven sketches.
|
||||
// * Built-in digital filter method ping_median() for easy error correction.
|
||||
// * Uses port registers for a faster pin interface and smaller code size.
|
||||
// * Allows you to set a maximum distance where pings beyond that distance are read as no ping "clear".
|
||||
// * Ease of using multiple sensors (example sketch with 15 sensors).
|
||||
// * More accurate distance calculation (cm, inches & uS).
|
||||
// * Doesn't use pulseIn, which is slow and gives incorrect results with some ultrasonic sensor models.
|
||||
// * Actively developed with features being added and bugs/issues addressed.
|
||||
//
|
||||
// CONSTRUCTOR:
|
||||
// NewPing sonar(trigger_pin, echo_pin [, max_cm_distance])
|
||||
// trigger_pin & echo_pin - Arduino pins connected to sensor trigger and echo.
|
||||
// NOTE: To use the same Arduino pin for trigger and echo, specify the same pin for both values.
|
||||
// max_cm_distance - [Optional] Maximum distance you wish to sense. Default=500cm.
|
||||
//
|
||||
// METHODS:
|
||||
// sonar.ping([max_cm_distance]) - Send a ping and get the echo time (in microseconds) as a result. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.ping_in([max_cm_distance]) - Send a ping and get the distance in whole inches. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.ping_cm([max_cm_distance]) - Send a ping and get the distance in whole centimeters. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.ping_median(iterations [, max_cm_distance]) - Do multiple pings (default=5), discard out of range pings and return median in microseconds. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// NewPing::convert_in(echoTime) - Convert echoTime from microseconds to inches (rounds to nearest inch).
|
||||
// NewPing::convert_cm(echoTime) - Convert echoTime from microseconds to centimeters (rounds to nearest cm).
|
||||
// sonar.ping_timer(function [, max_cm_distance]) - Send a ping and call function to test if ping is complete. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.check_timer() - Check if ping has returned within the set distance limit.
|
||||
// NewPing::timer_us(frequency, function) - Call function every frequency microseconds.
|
||||
// NewPing::timer_ms(frequency, function) - Call function every frequency milliseconds.
|
||||
// NewPing::timer_stop() - Stop the timer.
|
||||
//
|
||||
// HISTORY:
|
||||
// 07/30/2016 v1.8 - Added support for non-AVR microcontrollers. For non-AVR
|
||||
// microcontrollers, advanced ping_timer() timer methods are disabled due to
|
||||
// inconsistencies or no support at all between platforms. However, standard
|
||||
// ping methods are all supported. Added new optional variable to ping(),
|
||||
// ping_in(), ping_cm(), ping_median(), and ping_timer() methods which allows
|
||||
// you to set a new maximum distance for each ping. Added support for the
|
||||
// ATmega16, ATmega32 and ATmega8535 microcontrollers. Changed convert_cm()
|
||||
// and convert_in() methods to static members. You can now call them without
|
||||
// an object. For example: cm = NewPing::convert_cm(distance);
|
||||
//
|
||||
// 09/29/2015 v1.7 - Removed support for the Arduino Due and Zero because
|
||||
// they're both 3.3 volt boards and are not 5 volt tolerant while the HC-SR04
|
||||
// is a 5 volt sensor. Also, the Due and Zero don't support pin manipulation
|
||||
// compatibility via port registers which can be done (see the Teensy 3.2).
|
||||
//
|
||||
// 06/17/2014 v1.6 - Corrected delay between pings when using ping_median()
|
||||
// method. Added support for the URM37 sensor (must change URM37_ENABLED from
|
||||
// false to true). Added support for Arduino microcontrollers like the $20
|
||||
// 32 bit ARM Cortex-M4 based Teensy 3.2. Added automatic support for the
|
||||
// Atmel ATtiny family of microcontrollers. Added timer support for the
|
||||
// ATmega8 microcontroller. Rounding disabled by default, reduces compiled
|
||||
// code size (can be turned on with ROUNDING_ENABLED switch). Added
|
||||
// TIMER_ENABLED switch to get around compile-time "__vector_7" errors when
|
||||
// using the Tone library, or you can use the toneAC, NewTone or
|
||||
// TimerFreeTone libraries: https://bitbucket.org/teckel12/arduino-toneac/
|
||||
// Other speed and compiled size optimizations.
|
||||
//
|
||||
// 08/15/2012 v1.5 - Added ping_median() method which does a user specified
|
||||
// number of pings (default=5) and returns the median ping in microseconds
|
||||
// (out of range pings ignored). This is a very effective digital filter.
|
||||
// Optimized for smaller compiled size (even smaller than sketches that
|
||||
// don't use a library).
|
||||
//
|
||||
// 07/14/2012 v1.4 - Added support for the Parallax PING)))� sensor. Interface
|
||||
// with all but the SRF06 sensor using only one Arduino pin. You can also
|
||||
// interface with the SRF06 using one pin if you install a 0.1uf capacitor
|
||||
// on the trigger and echo pins of the sensor then tie the trigger pin to
|
||||
// the Arduino pin (doesn't work with Teensy). To use the same Arduino pin
|
||||
// for trigger and echo, specify the same pin for both values. Various bug
|
||||
// fixes.
|
||||
//
|
||||
// 06/08/2012 v1.3 - Big feature addition, event-driven ping! Uses Timer2
|
||||
// interrupt, so be mindful of PWM or timing conflicts messing with Timer2
|
||||
// may cause (namely PWM on pins 3 & 11 on Arduino, PWM on pins 9 and 10 on
|
||||
// Mega, and Tone library). Simple to use timer interrupt functions you can
|
||||
// use in your sketches totally unrelated to ultrasonic sensors (don't use if
|
||||
// you're also using NewPing's ping_timer because both use Timer2 interrupts).
|
||||
// Loop counting ping method deleted in favor of timing ping method after
|
||||
// inconsistent results kept surfacing with the loop timing ping method.
|
||||
// Conversion to cm and inches now rounds to the nearest cm or inch. Code
|
||||
// optimized to save program space and fixed a couple minor bugs here and
|
||||
// there. Many new comments added as well as line spacing to group code
|
||||
// sections for better source readability.
|
||||
//
|
||||
// 05/25/2012 v1.2 - Lots of code clean-up thanks to Arduino Forum members.
|
||||
// Rebuilt the ping timing code from scratch, ditched the pulseIn code as it
|
||||
// doesn't give correct results (at least with ping sensors). The NewPing
|
||||
// library is now VERY accurate and the code was simplified as a bonus.
|
||||
// Smaller and faster code as well. Fixed some issues with very close ping
|
||||
// results when converting to inches. All functions now return 0 only when
|
||||
// there's no ping echo (out of range) and a positive value for a successful
|
||||
// ping. This can effectively be used to detect if something is out of range
|
||||
// or in-range and at what distance. Now compatible with Arduino 0023.
|
||||
//
|
||||
// 05/16/2012 v1.1 - Changed all I/O functions to use low-level port registers
|
||||
// for ultra-fast and lean code (saves from 174 to 394 bytes). Tested on both
|
||||
// the Arduino Uno and Teensy 2.0 but should work on all Arduino-based
|
||||
// platforms because it calls standard functions to retrieve port registers
|
||||
// and bit masks. Also made a couple minor fixes to defines.
|
||||
//
|
||||
// 05/15/2012 v1.0 - Initial release.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#ifndef NewPing_h
|
||||
#define NewPing_h
|
||||
|
||||
#if defined (ARDUINO) && ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#include <pins_arduino.h>
|
||||
#endif
|
||||
|
||||
#if defined (__AVR__)
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#endif
|
||||
|
||||
// Shouldn't need to change these values unless you have a specific need to do so.
|
||||
#define MAX_SENSOR_DISTANCE 500 // Maximum sensor distance can be as high as 500cm, no reason to wait for ping longer than sound takes to travel this distance and back. Default=500
|
||||
#define US_ROUNDTRIP_CM 57 // Microseconds (uS) it takes sound to travel round-trip 1cm (2cm total), uses integer to save compiled code space. Default=57
|
||||
#define US_ROUNDTRIP_IN 146 // Microseconds (uS) it takes sound to travel round-trip 1 inch (2 inches total), uses integer to save compiled code space. Defalult=146
|
||||
#define ONE_PIN_ENABLED true // Set to "false" to disable one pin mode which saves around 14-26 bytes of binary size. Default=true
|
||||
#define ROUNDING_ENABLED false // Set to "true" to enable distance rounding which also adds 64 bytes to binary size. Default=false
|
||||
#define URM37_ENABLED false // Set to "true" to enable support for the URM37 sensor in PWM mode. Default=false
|
||||
#define TIMER_ENABLED true // Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true
|
||||
|
||||
// Probably shouldn't change these values unless you really know what you're doing.
|
||||
#define NO_ECHO 0 // Value returned if there's no ping echo within the specified MAX_SENSOR_DISTANCE or max_cm_distance. Default=0
|
||||
#define MAX_SENSOR_DELAY 5800 // Maximum uS it takes for sensor to start the ping. Default=5800
|
||||
#define ECHO_TIMER_FREQ 24 // Frequency to check for a ping echo (every 24uS is about 0.4cm accuracy). Default=24
|
||||
#define PING_MEDIAN_DELAY 29000 // Microsecond delay between pings in the ping_median method. Default=29000
|
||||
#define PING_OVERHEAD 5 // Ping overhead in microseconds (uS). Default=5
|
||||
#define PING_TIMER_OVERHEAD 13 // Ping timer overhead in microseconds (uS). Default=13
|
||||
#if URM37_ENABLED == true
|
||||
#undef US_ROUNDTRIP_CM
|
||||
#undef US_ROUNDTRIP_IN
|
||||
#define US_ROUNDTRIP_CM 50 // Every 50uS PWM signal is low indicates 1cm distance. Default=50
|
||||
#define US_ROUNDTRIP_IN 127 // If 50uS is 1cm, 1 inch would be 127uS (50 x 2.54 = 127). Default=127
|
||||
#endif
|
||||
|
||||
// Conversion from uS to distance (round result to nearest cm or inch).
|
||||
#define NewPingConvert(echoTime, conversionFactor) (max(((unsigned int)echoTime + conversionFactor / 2) / conversionFactor, (echoTime ? 1 : 0)))
|
||||
|
||||
// Detect non-AVR microcontrollers (Teensy 3.x, Arduino DUE, etc.) and don't use port registers or timer interrupts as required.
|
||||
#if (defined (__arm__) && defined (TEENSYDUINO))
|
||||
#undef PING_OVERHEAD
|
||||
#define PING_OVERHEAD 1
|
||||
#undef PING_TIMER_OVERHEAD
|
||||
#define PING_TIMER_OVERHEAD 1
|
||||
#define DO_BITWISE true
|
||||
#elif !defined (__AVR__)
|
||||
#undef PING_OVERHEAD
|
||||
#define PING_OVERHEAD 1
|
||||
#undef PING_TIMER_OVERHEAD
|
||||
#define PING_TIMER_OVERHEAD 1
|
||||
#undef TIMER_ENABLED
|
||||
#define TIMER_ENABLED false
|
||||
#define DO_BITWISE false
|
||||
#else
|
||||
#define DO_BITWISE true
|
||||
#endif
|
||||
|
||||
// Disable the timer interrupts when using ATmega128 and all ATtiny microcontrollers.
|
||||
#if defined (__AVR_ATmega128__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny261__) || defined (__AVR_ATtiny461__) || defined (__AVR_ATtiny861__) || defined (__AVR_ATtiny43U__)
|
||||
#undef TIMER_ENABLED
|
||||
#define TIMER_ENABLED false
|
||||
#endif
|
||||
|
||||
// Define timers when using ATmega8, ATmega16, ATmega32 and ATmega8535 microcontrollers.
|
||||
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__)
|
||||
#define OCR2A OCR2
|
||||
#define TIMSK2 TIMSK
|
||||
#define OCIE2A OCIE2
|
||||
#endif
|
||||
|
||||
class NewPing {
|
||||
public:
|
||||
NewPing(uint8_t trigger_pin, uint8_t echo_pin, unsigned int max_cm_distance = MAX_SENSOR_DISTANCE);
|
||||
unsigned int ping(unsigned int max_cm_distance = 0);
|
||||
unsigned long ping_cm(unsigned int max_cm_distance = 0);
|
||||
unsigned long ping_in(unsigned int max_cm_distance = 0);
|
||||
unsigned long ping_median(uint8_t it = 5, unsigned int max_cm_distance = 0);
|
||||
static unsigned int convert_cm(unsigned int echoTime);
|
||||
static unsigned int convert_in(unsigned int echoTime);
|
||||
#if TIMER_ENABLED == true
|
||||
void ping_timer(void (*userFunc)(void), unsigned int max_cm_distance = 0);
|
||||
boolean check_timer();
|
||||
unsigned long ping_result;
|
||||
static void timer_us(unsigned int frequency, void (*userFunc)(void));
|
||||
static void timer_ms(unsigned long frequency, void (*userFunc)(void));
|
||||
static void timer_stop();
|
||||
#endif
|
||||
private:
|
||||
boolean ping_trigger();
|
||||
void set_max_distance(unsigned int max_cm_distance);
|
||||
#if TIMER_ENABLED == true
|
||||
boolean ping_trigger_timer(unsigned int trigger_delay);
|
||||
boolean ping_wait_timer();
|
||||
static void timer_setup();
|
||||
static void timer_ms_cntdwn();
|
||||
#endif
|
||||
#if DO_BITWISE == true
|
||||
uint8_t _triggerBit;
|
||||
uint8_t _echoBit;
|
||||
volatile uint8_t *_triggerOutput;
|
||||
volatile uint8_t *_echoInput;
|
||||
volatile uint8_t *_triggerMode;
|
||||
#else
|
||||
uint8_t _triggerPin;
|
||||
uint8_t _echoPin;
|
||||
#endif
|
||||
unsigned int _maxEchoTime;
|
||||
unsigned long _max_time;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// This example code was used to successfully communicate with 15 ultrasonic sensors. You can adjust
|
||||
// the number of sensors in your project by changing SONAR_NUM and the number of NewPing objects in the
|
||||
// "sonar" array. You also need to change the pins for each sensor for the NewPing objects. Each sensor
|
||||
// is pinged at 33ms intervals. So, one cycle of all sensors takes 495ms (33 * 15 = 495ms). The results
|
||||
// are sent to the "oneSensorCycle" function which currently just displays the distance data. Your project
|
||||
// would normally process the sensor results in this function (for example, decide if a robot needs to
|
||||
// turn and call the turn function). Keep in mind this example is event-driven. Your complete sketch needs
|
||||
// to be written so there's no "delay" commands and the loop() cycles at faster than a 33ms rate. If other
|
||||
// processes take longer than 33ms, you'll need to increase PING_INTERVAL so it doesn't get behind.
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <NewPing.h>
|
||||
|
||||
#define SONAR_NUM 15 // Number of sensors.
|
||||
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
|
||||
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
|
||||
|
||||
unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
|
||||
unsigned int cm[SONAR_NUM]; // Where the ping distances are stored.
|
||||
uint8_t currentSensor = 0; // Keeps track of which sensor is active.
|
||||
|
||||
NewPing sonar[SONAR_NUM] = { // Sensor object array.
|
||||
NewPing(41, 42, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
|
||||
NewPing(43, 44, MAX_DISTANCE),
|
||||
NewPing(45, 20, MAX_DISTANCE),
|
||||
NewPing(21, 22, MAX_DISTANCE),
|
||||
NewPing(23, 24, MAX_DISTANCE),
|
||||
NewPing(25, 26, MAX_DISTANCE),
|
||||
NewPing(27, 28, MAX_DISTANCE),
|
||||
NewPing(29, 30, MAX_DISTANCE),
|
||||
NewPing(31, 32, MAX_DISTANCE),
|
||||
NewPing(34, 33, MAX_DISTANCE),
|
||||
NewPing(35, 36, MAX_DISTANCE),
|
||||
NewPing(37, 38, MAX_DISTANCE),
|
||||
NewPing(39, 40, MAX_DISTANCE),
|
||||
NewPing(50, 51, MAX_DISTANCE),
|
||||
NewPing(52, 53, MAX_DISTANCE)
|
||||
};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pingTimer[0] = millis() + 75; // First ping starts at 75ms, gives time for the Arduino to chill before starting.
|
||||
for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
|
||||
pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
|
||||
if (millis() >= pingTimer[i]) { // Is it this sensor's time to ping?
|
||||
pingTimer[i] += PING_INTERVAL * SONAR_NUM; // Set next time this sensor will be pinged.
|
||||
if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
|
||||
sonar[currentSensor].timer_stop(); // Make sure previous timer is canceled before starting a new ping (insurance).
|
||||
currentSensor = i; // Sensor being accessed.
|
||||
cm[currentSensor] = 0; // Make distance zero in case there's no ping echo for this sensor.
|
||||
sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
|
||||
}
|
||||
}
|
||||
// Other code that *DOESN'T* analyze ping results can go here.
|
||||
}
|
||||
|
||||
void echoCheck() { // If ping received, set the sensor distance to array.
|
||||
if (sonar[currentSensor].check_timer())
|
||||
cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
|
||||
}
|
||||
|
||||
void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
|
||||
// The following code would be replaced with your code that does something with the ping results.
|
||||
for (uint8_t i = 0; i < SONAR_NUM; i++) {
|
||||
Serial.print(i);
|
||||
Serial.print("=");
|
||||
Serial.print(cm[i]);
|
||||
Serial.print("cm ");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// This example shows how to use NewPing's ping_timer method which uses the Timer2 interrupt to get the
|
||||
// ping time. The advantage of using this method over the standard ping method is that it permits a more
|
||||
// event-driven sketch which allows you to appear to do two things at once. An example would be to ping
|
||||
// an ultrasonic sensor for a possible collision while at the same time navigating. This allows a
|
||||
// properly developed sketch to multitask. Be aware that because the ping_timer method uses Timer2,
|
||||
// other features or libraries that also use Timer2 would be effected. For example, the PWM function on
|
||||
// pins 3 & 11 on Arduino Uno (pins 9 and 11 on Arduino Mega) and the Tone library. Note, only the PWM
|
||||
// functionality of the pins is lost (as they use Timer2 to do PWM), the pins are still available to use.
|
||||
// NOTE: For Teensy/Leonardo (ATmega32U4) the library uses Timer4 instead of Timer2.
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <NewPing.h>
|
||||
|
||||
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on ping sensor.
|
||||
#define ECHO_PIN 11 // Arduino pin tied to echo pin on ping sensor.
|
||||
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
|
||||
|
||||
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
|
||||
|
||||
unsigned int pingSpeed = 50; // How frequently are we going to send out a ping (in milliseconds). 50ms would be 20 times a second.
|
||||
unsigned long pingTimer; // Holds the next ping time.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
|
||||
pingTimer = millis(); // Start now.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Notice how there's no delays in this sketch to allow you to do other processing in-line while doing distance pings.
|
||||
if (millis() >= pingTimer) { // pingSpeed milliseconds since last ping, do another ping.
|
||||
pingTimer += pingSpeed; // Set the next ping time.
|
||||
sonar.ping_timer(echoCheck); // Send out the ping, calls "echoCheck" function every 24uS where you can check the ping status.
|
||||
}
|
||||
// Do other stuff here, really. Think of it as multi-tasking.
|
||||
}
|
||||
|
||||
void echoCheck() { // Timer2 interrupt calls this function every 24uS where you can check the ping status.
|
||||
// Don't do anything here!
|
||||
if (sonar.check_timer()) { // This is how you check to see if the ping was received.
|
||||
// Here's where you can add code.
|
||||
Serial.print("Ping: ");
|
||||
Serial.print(sonar.ping_result / US_ROUNDTRIP_CM); // Ping returned, uS result in ping_result, convert to cm with US_ROUNDTRIP_CM.
|
||||
Serial.println("cm");
|
||||
}
|
||||
// Don't do anything here!
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Example NewPing library sketch that does a ping about 20 times per second.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <NewPing.h>
|
||||
|
||||
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
|
||||
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
|
||||
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
|
||||
|
||||
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
|
||||
Serial.print("Ping: ");
|
||||
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
|
||||
Serial.println("cm");
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// While the NewPing library's primary goal is to interface with ultrasonic sensors, interfacing with
|
||||
// the Timer2 interrupt was a result of creating an interrupt-based ping method. Since these Timer2
|
||||
// interrupt methods were built, the library may as well provide the functionality to use these methods
|
||||
// in your sketches. This shows how simple it is (no ultrasonic sensor required). Keep in mind that
|
||||
// these methods use Timer2, as does NewPing's ping_timer method for using ultrasonic sensors. You
|
||||
// can't use ping_timer at the same time you're using timer_ms or timer_us as all use the same timer.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <NewPing.h>
|
||||
|
||||
#define LED_PIN 13 // Pin with LED attached.
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
NewPing::timer_ms(500, toggleLED); // Create a Timer2 interrupt that calls toggleLED in your sketch once every 500 milliseconds.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Do anything here, the Timer2 interrupt will take care of the flashing LED without your intervention.
|
||||
}
|
||||
|
||||
void toggleLED() {
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Toggle the LED.
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
###################################
|
||||
# Syntax Coloring Map For NewPing
|
||||
###################################
|
||||
|
||||
###################################
|
||||
# Datatypes (KEYWORD1)
|
||||
###################################
|
||||
|
||||
NewPing KEYWORD1
|
||||
|
||||
###################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
###################################
|
||||
|
||||
ping KEYWORD2
|
||||
ping_in KEYWORD2
|
||||
ping_cm KEYWORD2
|
||||
ping_median KEYWORD2
|
||||
ping_timer KEYWORD2
|
||||
check_timer KEYWORD2
|
||||
timer_us KEYWORD2
|
||||
timer_ms KEYWORD2
|
||||
timer_stop KEYWORD2
|
||||
convert_in KEYWORD2
|
||||
convert_cm KEYWORD2
|
||||
|
||||
###################################
|
||||
# Constants (LITERAL1)
|
||||
###################################
|
||||
+88
-41
@@ -39,9 +39,15 @@ platform = espressif8266@1.5.0
|
||||
[core_2_4_0]
|
||||
platform = espressif8266@1.6.0
|
||||
|
||||
[core_2_4_1]
|
||||
platform = espressif8266@1.7.0
|
||||
|
||||
[core_staged]
|
||||
platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
|
||||
|
||||
[core_esp32]
|
||||
#platform = espressif32@0.12.0
|
||||
platform = https://github.com/platformio/platform-espressif32.git#feature/stage
|
||||
platform = espressif32@0.12.0
|
||||
#platform = https://github.com/platformio/platform-espressif32.git#feature/stage
|
||||
build_flags = -D BUILD_GIT='"${env.TRAVIS_TAG}"'
|
||||
lib_ignore = ESPeasySoftwareSerial, EspESPeasySoftwareSerial, AS_BH1750, ESP8266WiFi, ESP8266Ping, ESP8266WebServer, ESP8266HTTPUpdateServer, ESP8266mDNS, IRremoteESP8266, ESPEasy_ESP8266Ping, SerialSensors
|
||||
lib_deps = ESP32WebServer
|
||||
@@ -49,13 +55,23 @@ lib_deps = ESP32WebServer
|
||||
|
||||
[common]
|
||||
build_flags = -D BUILD_GIT='"${env.TRAVIS_TAG}"' ; ${compiler_warnings.build_flags}
|
||||
-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
|
||||
lib_deps = ""
|
||||
lib_ignore = ESP32_ping, ESP32WebServer
|
||||
lib_ldf_mode = chain
|
||||
upload_speed = 460800
|
||||
framework = arduino
|
||||
board = esp12e
|
||||
platform = ${core_2_3_0.platform}
|
||||
platform = ${core_2_4_1.platform}
|
||||
|
||||
[normal]
|
||||
platform = ${common.platform}
|
||||
|
||||
[testing]
|
||||
platform = ${core_2_4_1.platform}
|
||||
|
||||
[dev]
|
||||
platform = ${core_2_4_1.platform}
|
||||
|
||||
|
||||
[esp8266_1M]
|
||||
@@ -71,6 +87,13 @@ build_flags = ${esp8266_1M.build_flags} -DESP8285
|
||||
board = esp01_1m
|
||||
board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld
|
||||
platform = ${core_2_4_1.platform}
|
||||
|
||||
[Sonoff_8285]
|
||||
board_flash_mode = ${esp8285_1M.board_flash_mode}
|
||||
board = ${esp8285_1M.board}
|
||||
build_flags = ${esp8285_1M.build_flags}
|
||||
platform = ${core_2_4_1.platform}
|
||||
|
||||
[espWroom2M]
|
||||
board_flash_mode = dout
|
||||
@@ -156,7 +179,7 @@ build_flags = ${esp8266_4M.build_flags}
|
||||
|
||||
# TEST: 1024k version ----------------------------
|
||||
[env:test_ESP8266_1024]
|
||||
platform = ${common.platform}
|
||||
platform = ${testing.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -168,7 +191,7 @@ build_flags = ${esp8266_1M.build_flags} -D PLUGIN_BUILD_TESTING
|
||||
|
||||
# TEST: 1024k for esp8285 ------------------------
|
||||
[env:test_ESP8285_1024]
|
||||
platform = ${common.platform}
|
||||
platform = ${testing.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -180,7 +203,7 @@ build_flags = ${esp8285_1M.build_flags} -D PLUGIN_BUILD_TESTING
|
||||
|
||||
# TEST: 2048k version ----------------------------
|
||||
[env:test_WROOM02_2048]
|
||||
platform = ${common.platform}
|
||||
platform = ${testing.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -192,7 +215,7 @@ build_flags = ${espWroom2M.build_flags} -D PLUGIN_BUILD_TESTING
|
||||
|
||||
# TEST: 4096k version ----------------------------
|
||||
[env:test_ESP8266_4096]
|
||||
platform = ${common.platform}
|
||||
platform = ${testing.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -204,7 +227,7 @@ build_flags = ${esp8266_4M.build_flags} -D PLUGIN_BUILD_TESTING
|
||||
|
||||
# TEST: 4096k version + FEATURE_ADC_VCC ----------
|
||||
[env:test_ESP8266_4096_VCC]
|
||||
platform = ${common.platform}
|
||||
platform = ${testing.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -222,7 +245,7 @@ build_flags = ${esp8266_4M.build_flags} -D PLUGIN_BUILD_TESTING -D FEATURE_
|
||||
|
||||
# DEV : 1024k version ----------------------------
|
||||
[env:dev_ESP8266_1024]
|
||||
platform = ${common.platform}
|
||||
platform = ${dev.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -234,7 +257,7 @@ build_flags = ${esp8266_1M.build_flags} -D PLUGIN_BUILD_DEV
|
||||
|
||||
# DEV: 1024k for esp8285 -------------------------
|
||||
[env:dev_ESP8285_1024]
|
||||
platform = ${common.platform}
|
||||
platform = ${dev.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -246,7 +269,7 @@ build_flags = ${esp8285_1M.build_flags} -D PLUGIN_BUILD_DEV
|
||||
|
||||
# DEV: 2048k version -----------------------------
|
||||
[env:dev_WROOM02_2048]
|
||||
platform = ${common.platform}
|
||||
platform = ${dev.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -258,7 +281,7 @@ build_flags = ${espWroom2M.build_flags} -D PLUGIN_BUILD_DEV
|
||||
|
||||
# DEV : 4096k version ----------------------------
|
||||
[env:dev_ESP8266_4096]
|
||||
platform = ${common.platform}
|
||||
platform = ${dev.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -276,7 +299,7 @@ build_flags = ${esp8266_4M.build_flags} -D PLUGIN_BUILD_DEV
|
||||
|
||||
# DEV+PUYA : 1024k version -----------------------
|
||||
[env:dev_ESP8266PUYA_1024]
|
||||
platform = ${common.platform}
|
||||
platform = ${dev.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -288,7 +311,7 @@ build_flags = ${esp8266_1M.build_flags} -D PLUGIN_BUILD_DEV -D FLASH_QUIRK_
|
||||
|
||||
# DEV+PUYA : 1024k version + FEATURE_ADC_VCC -----
|
||||
[env:dev_ESP8266PUYA_1024_VCC]
|
||||
platform = ${common.platform}
|
||||
platform = ${dev.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
@@ -311,9 +334,9 @@ build_flags = ${esp8266_1M.build_flags} -D PLUGIN_BUILD_DEV -D FLASH_QUIRK_
|
||||
#[env:hard_SONOFF_BASIC]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
@@ -323,9 +346,9 @@ lib_ignore = ${common.lib_ignore}
|
||||
#[env:hard_SONOFF_TH10]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
@@ -335,33 +358,57 @@ lib_ignore = ${common.lib_ignore}
|
||||
#[env:hard_SONOFF_TH16]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
#build_flags = ${Sonoff.build_flags} -D PLUGIN_SET_SONOFF_TH16
|
||||
|
||||
# ITEAD / SONOFF POW version --------------------
|
||||
#[env:hard_SONOFF_POW]
|
||||
# Sonoff Pow (ESP8266 - HLW8012)
|
||||
# GPIO00 Button
|
||||
# GPIO05 HLW8012 Sel output
|
||||
# GPIO12 Red Led and Relay (0 = Off, 1 = On)
|
||||
# GPIO13 HLW8012 CF1 voltage / current
|
||||
# GPIO14 HLW8012 CF power
|
||||
# GPIO15 Blue Led (0 = On, 1 = Off)
|
||||
[env:hard_SONOFF_POW]
|
||||
upload_speed = ${common.upload_speed}
|
||||
framework = ${common.framework}
|
||||
platform = ${Sonoff.platform}
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
board = ${Sonoff.board}
|
||||
build_flags = ${Sonoff.build_flags} -D PLUGIN_SET_SONOFF_POW
|
||||
|
||||
# Sonoff Pow R2 (ESP8285 - CSE7766)
|
||||
# GPIO00 Button
|
||||
# GPIO01 Serial RXD 4800 baud 8E1 CSE7766 energy sensor
|
||||
# GPIO03 Serial TXD
|
||||
# GPIO12 Red Led and Relay (0 = Off, 1 = On)
|
||||
# GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
#[env:hard_SONOFF_POW_R2]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
#build_flags = ${Sonoff.build_flags} -D PLUGIN_SET_SONOFF_POW
|
||||
#board_flash_mode = ${Sonoff_8285.board_flash_mode}
|
||||
#board = ${Sonoff_8285.board}
|
||||
#build_flags = ${Sonoff_8285.build_flags} -D PLUGIN_SET_SONOFF_POW_R2
|
||||
|
||||
# ITEAD / SONOFF S20 version --------------------
|
||||
#[env:hard_SONOFF_S20]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
@@ -371,9 +418,9 @@ lib_ignore = ${common.lib_ignore}
|
||||
#[env:hard_SONOFF_4CH]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
@@ -383,9 +430,9 @@ lib_ignore = ${common.lib_ignore}
|
||||
#[env:hard_SONOFF_TOUCH]
|
||||
#upload_speed = ${common.upload_speed}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#platform = ${Sonoff.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${Sonoff.board_flash_mode}
|
||||
#board = ${Sonoff.board}
|
||||
@@ -401,7 +448,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -414,7 +461,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -426,7 +473,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -445,7 +492,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -458,7 +505,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -473,7 +520,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -485,7 +532,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -497,7 +544,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
@@ -509,7 +556,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
#framework = ${common.framework}
|
||||
#platform = ${common.platform}
|
||||
#lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
#lib_ignore = ${common.lib_ignore}
|
||||
#lib_ldf_mode = ${common.lib_ldf_mode}
|
||||
#board_flash_mode = ${esp8266_1M.board_flash_mode}
|
||||
#board = esp01_1m
|
||||
|
||||
+71
-4
@@ -126,6 +126,8 @@ Command commandStringToEnum(const char * cmd) {
|
||||
else if (strcmp_P(cmd_lc, PSTR("taskrun") ) == 0) return cmd_TaskRun;
|
||||
else if (strcmp_P(cmd_lc, PSTR("taskvalueset") ) == 0) return cmd_TaskValueSet;
|
||||
else if (strcmp_P(cmd_lc, PSTR("timerset") ) == 0) return cmd_TimerSet;
|
||||
else if (strcmp_P(cmd_lc, PSTR("timerpause") ) == 0) return cmd_TimerPause;
|
||||
else if (strcmp_P(cmd_lc, PSTR("timerresume") ) == 0) return cmd_TimerResume;
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
@@ -465,11 +467,76 @@ void ExecuteCommand(byte source, const char *Line)
|
||||
{
|
||||
success = true;
|
||||
if (Par2)
|
||||
{
|
||||
//start new timer
|
||||
RulesTimer[Par1 - 1] = millis() + (1000 * Par2);
|
||||
RulesTimer[Par1 - 1].interval = Par2*1000;
|
||||
RulesTimer[Par1 - 1].paused = false;
|
||||
RulesTimer[Par1 - 1].timestamp = millis() + (1000 * Par2);
|
||||
}
|
||||
else
|
||||
{
|
||||
//disable existing timer
|
||||
RulesTimer[Par1 - 1] = 0L;
|
||||
RulesTimer[Par1 - 1].interval = 0;
|
||||
RulesTimer[Par1 - 1].paused = false;
|
||||
RulesTimer[Par1 - 1].timestamp = 0L;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addLog(LOG_LEVEL_ERROR, F("TIMER: invalid timer number"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case cmd_TimerPause:
|
||||
{
|
||||
if (Par1>=1 && Par1<=RULES_TIMER_MAX)
|
||||
{
|
||||
success = true;
|
||||
if (RulesTimer[Par1 - 1].paused == false)
|
||||
{
|
||||
long delta = timePassedSince(RulesTimer[Par1 - 1].timestamp);
|
||||
if(RulesTimer[Par1 - 1].timestamp != 0L && delta < 0)
|
||||
{
|
||||
String event = F("Rules#TimerPause=");
|
||||
event += Par1;
|
||||
rulesProcessing(event);
|
||||
RulesTimer[Par1 - 1].paused = true;
|
||||
RulesTimer[Par1 - 1].interval = -delta; // set remaind time
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addLog(LOG_LEVEL_INFO, F("TIMER: already paused"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addLog(LOG_LEVEL_ERROR, F("TIMER: invalid timer number"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case cmd_TimerResume:
|
||||
{
|
||||
if (Par1>=1 && Par1<=RULES_TIMER_MAX)
|
||||
{
|
||||
success = true;
|
||||
if (RulesTimer[Par1 - 1].paused == true)
|
||||
{
|
||||
if(RulesTimer[Par1 - 1].interval > 0 && RulesTimer[Par1 - 1].timestamp != 0L)
|
||||
{
|
||||
String event = F("Rules#TimerResume=");
|
||||
event += Par1;
|
||||
rulesProcessing(event);
|
||||
RulesTimer[Par1 - 1].timestamp = millis() + (RulesTimer[Par1 - 1].interval);
|
||||
RulesTimer[Par1 - 1].paused = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addLog(LOG_LEVEL_INFO, F("TIMER: already resumed"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -694,7 +761,7 @@ void ExecuteCommand(byte source, const char *Line)
|
||||
|
||||
case cmd_WifiAPMode:
|
||||
{
|
||||
WifiAPMode(true);
|
||||
setAP(true);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
@@ -746,7 +813,7 @@ void ExecuteCommand(byte source, const char *Line)
|
||||
{
|
||||
success = true;
|
||||
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
|
||||
WiFi.disconnect(); // this will store empty ssid/wpa into sdk storage
|
||||
WifiDisconnect(); // this will store empty ssid/wpa into sdk storage
|
||||
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
|
||||
break;
|
||||
}
|
||||
|
||||
+15
-11
@@ -89,14 +89,16 @@ void callback(char* c_topic, byte* b_payload, unsigned int length) {
|
||||
strncpy(c_payload,(char*)b_payload,length);
|
||||
c_payload[length] = 0;
|
||||
|
||||
/*
|
||||
String log;
|
||||
log=F("MQTT : Topic: ");
|
||||
log+=c_topic;
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
|
||||
log=F("MQTT : Payload: ");
|
||||
log+=c_payload;
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
*/
|
||||
|
||||
// sprintf_P(log, PSTR("%s%s"), "MQTT : Topic: ", c_topic);
|
||||
// addLog(LOG_LEVEL_DEBUG, log);
|
||||
@@ -116,12 +118,15 @@ void callback(char* c_topic, byte* b_payload, unsigned int length) {
|
||||
\*********************************************************************************************/
|
||||
bool MQTTConnect(int controller_idx)
|
||||
{
|
||||
++mqtt_reconnect_count;
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(controller_idx, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
if (!ControllerSettings.checkHostReachable(true))
|
||||
return false;
|
||||
if (MQTTclient.connected())
|
||||
if (MQTTclient.connected()) {
|
||||
MQTTclient.disconnect();
|
||||
updateMQTTclient_connected();
|
||||
}
|
||||
if (ControllerSettings.UseDNS) {
|
||||
MQTTclient.setServer(ControllerSettings.getHost().c_str(), ControllerSettings.Port);
|
||||
} else {
|
||||
@@ -166,12 +171,9 @@ bool MQTTConnect(int controller_idx)
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
|
||||
if (MQTTclient.publish(LWTTopic.c_str(), "Connected", 1)) {
|
||||
if (Settings.UseRules)
|
||||
{
|
||||
String event = F("MQTT#Connected");
|
||||
rulesProcessing(event);
|
||||
}
|
||||
updateMQTTclient_connected();
|
||||
statusLED(true);
|
||||
mqtt_reconnect_count = 0;
|
||||
return true; // end loop if succesfull
|
||||
}
|
||||
return false;
|
||||
@@ -183,8 +185,9 @@ bool MQTTConnect(int controller_idx)
|
||||
\*********************************************************************************************/
|
||||
bool MQTTCheck(int controller_idx)
|
||||
{
|
||||
if (!WiFiConnected(10))
|
||||
if (!WiFiConnected(10)) {
|
||||
return false;
|
||||
}
|
||||
byte ProtocolIndex = getProtocolIndex(Settings.Protocol[controller_idx]);
|
||||
if (Protocol[ProtocolIndex].usesMQTT)
|
||||
{
|
||||
@@ -193,7 +196,6 @@ bool MQTTCheck(int controller_idx)
|
||||
if (MQTTclient_should_reconnect) {
|
||||
addLog(LOG_LEVEL_ERROR, F("MQTT : Intentional reconnect"));
|
||||
} else {
|
||||
addLog(LOG_LEVEL_ERROR, F("MQTT : Connection lost"));
|
||||
connectionFailures += 2;
|
||||
}
|
||||
return MQTTConnect(controller_idx);
|
||||
@@ -229,8 +231,10 @@ void SendStatus(byte source, String status)
|
||||
|
||||
boolean MQTTpublish(int controller_idx, const char* topic, const char* payload, boolean retained)
|
||||
{
|
||||
if (MQTTclient.publish(topic, payload, retained))
|
||||
if (MQTTclient.publish(topic, payload, retained)) {
|
||||
timermqtt = millis() + 10; // Make sure the MQTT is being processed as soon as possible.
|
||||
return true;
|
||||
}
|
||||
addLog(LOG_LEVEL_DEBUG, F("MQTT : publish failed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
+88
-11
@@ -16,7 +16,8 @@
|
||||
#define DEFAULT_DELAY 60 // Sleep Delay in seconds
|
||||
|
||||
// --- Wifi AP Mode (when your Wifi Network is not reachable) ----------------------------------------
|
||||
#define DEFAULT_AP_IP 192,168,4,1 // Enter IP address (comma separated) for AP (config) mode
|
||||
#define DEFAULT_AP_IP 192,168,4,1 // Enter IP address (comma separated) for AP (config) mode
|
||||
#define DEFAULT_AP_SUBNET 255,255,255,0 // Enter IP address (comma separated) for AP (config) mode
|
||||
#define DEFAULT_AP_KEY "configesp" // Enter network WPA key for AP (config) mode
|
||||
|
||||
// --- Wifi Client Mode -----------------------------------------------------------------------------
|
||||
@@ -53,8 +54,19 @@
|
||||
// 8 = Generic HTTP
|
||||
// 9 = FHEM HTTP
|
||||
|
||||
#define DEFAULT_PIN_I2C_SDA 4
|
||||
#define DEFAULT_PIN_I2C_SCL 5
|
||||
|
||||
#define DEFAULT_PIN_STATUS_LED -1
|
||||
#define DEFAULT_PIN_STATUS_LED_INVERSED true
|
||||
|
||||
|
||||
|
||||
// --- Advanced Settings ---------------------------------------------------------------------------------
|
||||
#if defined(ESP32)
|
||||
#define USE_RTOS_MULTITASKING
|
||||
#endif
|
||||
|
||||
#define DEFAULT_USE_RULES false // (true|false) Enable Rules?
|
||||
|
||||
#define DEFAULT_MQTT_RETAIN false // (true|false) Retain MQTT messages?
|
||||
@@ -79,6 +91,8 @@
|
||||
#define DEFAULT_USE_SERIAL true // (true|false) Enable Logging to the Serial Port
|
||||
#define DEFAULT_SERIAL_BAUD 115200 // Serial Port Baud Rate
|
||||
|
||||
#define DEFAULT_SYSLOG_FACILITY 0 // kern
|
||||
|
||||
/*
|
||||
// --- Experimental Advanced Settings (NOT ACTIVES at this time) ------------------------------------
|
||||
|
||||
@@ -149,7 +163,7 @@
|
||||
#define VERSION 3 // Change in config.dat mapping needs a full reset
|
||||
#endif
|
||||
|
||||
#define BUILD 20100 // git version 2.1.0
|
||||
#define BUILD 20102 // git version 2.1.02
|
||||
#if defined(ESP8266)
|
||||
#define BUILD_NOTES " - Mega"
|
||||
#endif
|
||||
@@ -235,9 +249,9 @@
|
||||
#define CMD_WIFI_DISCONNECT 135
|
||||
|
||||
#if defined(PLUGIN_BUILD_TESTING) || defined(PLUGIN_BUILD_DEV)
|
||||
#define DEVICES_MAX 72
|
||||
#define DEVICES_MAX 75
|
||||
#else
|
||||
#define DEVICES_MAX 64
|
||||
#define DEVICES_MAX 50
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
@@ -445,12 +459,15 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info);
|
||||
WiFiEventHandler stationConnectedHandler;
|
||||
WiFiEventHandler stationDisconnectedHandler;
|
||||
WiFiEventHandler stationGotIpHandler;
|
||||
WiFiEventHandler APModeStationConnectedHandler;
|
||||
WiFiEventHandler APModeStationDisconnectedHandler;
|
||||
#endif
|
||||
|
||||
// Setup DNS, only used if the ESP has no valid WiFi config
|
||||
const byte DNS_PORT = 53;
|
||||
IPAddress apIP(DEFAULT_AP_IP);
|
||||
DNSServer dnsServer;
|
||||
bool dnsServerActive = false;
|
||||
#ifdef FEATURE_MDNS
|
||||
MDNSResponder mdns;
|
||||
#endif
|
||||
@@ -459,6 +476,8 @@ MDNSResponder mdns;
|
||||
WiFiClient mqtt;
|
||||
PubSubClient MQTTclient(mqtt);
|
||||
bool MQTTclient_should_reconnect = true;
|
||||
bool MQTTclient_connected = false;
|
||||
int mqtt_reconnect_count = 0;
|
||||
|
||||
// udp protocol stuff (syslog, global sync, node info list, ntp time)
|
||||
WiFiUDP portUDP;
|
||||
@@ -518,6 +537,8 @@ enum Command {
|
||||
cmd_TaskRun,
|
||||
cmd_TaskValueSet,
|
||||
cmd_TimerSet,
|
||||
cmd_TimerPause,
|
||||
cmd_TimerResume,
|
||||
cmd_udptest,
|
||||
cmd_Unit,
|
||||
cmd_wdconfig,
|
||||
@@ -566,6 +587,7 @@ struct SecurityStruct
|
||||
byte AllowedIPrangeLow[4]; // TD-er: Use these
|
||||
byte AllowedIPrangeHigh[4];
|
||||
byte IPblockLevel;
|
||||
|
||||
//its safe to extend this struct, up to 4096 bytes, default values in config are 0. Make sure crc is last
|
||||
uint8_t ProgmemMd5[16]; // crc of the binary that last saved the struct to file.
|
||||
uint8_t md5[16];
|
||||
@@ -583,7 +605,8 @@ struct SettingsStruct
|
||||
WireClockStretchLimit(0), GlobalSync(false), ConnectionFailuresThreshold(0),
|
||||
TimeZone(0), MQTTRetainFlag(false), InitSPI(false),
|
||||
Pin_status_led_Inversed(false), deepSleepOnFail(false), UseValueLogger(false),
|
||||
DST_Start(0), DST_End(0)
|
||||
DST_Start(0), DST_End(0), UseRTOSMultitasking(false), Pin_Reset(-1),
|
||||
SyslogFacility(DEFAULT_SYSLOG_FACILITY), StructSize(0)
|
||||
{
|
||||
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
|
||||
Protocol[i] = 0;
|
||||
@@ -687,13 +710,20 @@ struct SettingsStruct
|
||||
boolean ArduinoOTAEnable;
|
||||
uint16_t DST_Start;
|
||||
uint16_t DST_End;
|
||||
boolean UseRTOSMultitasking;
|
||||
int8_t Pin_Reset;
|
||||
byte SyslogFacility;
|
||||
uint32_t StructSize; // Forced to be 32 bit, to make sure alignment is clear.
|
||||
|
||||
//its safe to extend this struct, up to several bytes, default values in config are 0
|
||||
//look in misc.ino how config.dat is used because also other stuff is stored in it at different offsets.
|
||||
//TODO: document config.dat somewhere here
|
||||
|
||||
// FIXME @TD-er: As discussed in #1292, the CRC for the settings is now disabled.
|
||||
// make sure crc is the last value in the struct
|
||||
uint8_t ProgmemMd5[16]; // crc of the binary that last saved the struct to file.
|
||||
uint8_t md5[16];
|
||||
// Try to extend settings to make the checksum 4-byte aligned.
|
||||
// uint8_t ProgmemMd5[16]; // crc of the binary that last saved the struct to file.
|
||||
// uint8_t md5[16];
|
||||
} Settings;
|
||||
|
||||
struct ControllerSettingsStruct
|
||||
@@ -795,6 +825,7 @@ private:
|
||||
if (!UseDNS) {
|
||||
return true;
|
||||
}
|
||||
if (WiFi.status() != WL_CONNECTED) return false;
|
||||
IPAddress tmpIP;
|
||||
if (WiFi.hostByName(HostName, tmpIP)) {
|
||||
for (byte x = 0; x < 4; x++) {
|
||||
@@ -889,7 +920,15 @@ struct EventStruct
|
||||
};
|
||||
|
||||
#define LOG_STRUCT_MESSAGE_SIZE 128
|
||||
#define LOG_STRUCT_MESSAGE_LINES 20
|
||||
#ifdef ESP32
|
||||
#define LOG_STRUCT_MESSAGE_LINES 30
|
||||
#else
|
||||
#if defined(PLUGIN_BUILD_TESTING) || defined(PLUGIN_BUILD_DEV)
|
||||
#define LOG_STRUCT_MESSAGE_LINES 10
|
||||
#else
|
||||
#define LOG_STRUCT_MESSAGE_LINES 15
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct LogStruct {
|
||||
LogStruct() : write_idx(0), read_idx(0) {
|
||||
@@ -1079,7 +1118,12 @@ String printWebString = "";
|
||||
boolean printToWebJSON = false;
|
||||
|
||||
float UserVar[VARS_PER_TASK * TASKS_MAX];
|
||||
unsigned long RulesTimer[RULES_TIMER_MAX];
|
||||
struct rulesTiemerStatus
|
||||
{
|
||||
unsigned long timestamp;
|
||||
unsigned int interval; //interval in millisencond
|
||||
boolean paused;
|
||||
} RulesTimer[RULES_TIMER_MAX];
|
||||
|
||||
unsigned long timerSensor[TASKS_MAX];
|
||||
unsigned long timer100ms;
|
||||
@@ -1090,8 +1134,6 @@ unsigned long timermqtt;
|
||||
unsigned long timermqtt_interval;
|
||||
unsigned long lastSend;
|
||||
unsigned long lastWeb;
|
||||
unsigned int NC_Count = 0;
|
||||
unsigned int C_Count = 0;
|
||||
byte cmd_within_mainloop = 0;
|
||||
unsigned long connectionFailures;
|
||||
unsigned long wdcounter = 0;
|
||||
@@ -1153,6 +1195,27 @@ enum WiFiDisconnectReason
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef ESP32
|
||||
// To do some reconnection check.
|
||||
#include <Ticker.h>
|
||||
Ticker connectionCheck;
|
||||
#endif
|
||||
|
||||
bool reconnectChecker = false;
|
||||
void connectionCheckHandler()
|
||||
{
|
||||
if (reconnectChecker == false && WiFi.status() != WL_CONNECTED){
|
||||
reconnectChecker = true;
|
||||
WiFi.reconnect();
|
||||
}
|
||||
else if (WiFi.status() == WL_CONNECTED && reconnectChecker == true){
|
||||
reconnectChecker = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool useStaticIP();
|
||||
|
||||
// WiFi related data
|
||||
boolean wifiSetup = false;
|
||||
boolean wifiSetupConnect = false;
|
||||
@@ -1160,6 +1223,7 @@ uint8_t lastBSSID[6] = {0};
|
||||
uint8_t wifiStatus = ESPEASY_WIFI_DISCONNECTED;
|
||||
unsigned long last_wifi_connect_attempt_moment = 0;
|
||||
unsigned int wifi_connect_attempt = 0;
|
||||
unsigned int wifi_reconnects = 0;
|
||||
uint8_t lastWiFiSettings = 0;
|
||||
String last_ssid;
|
||||
bool bssid_changed = false;
|
||||
@@ -1168,14 +1232,26 @@ WiFiDisconnectReason lastDisconnectReason = WIFI_DISCONNECT_REASON_UNSPECIFIED;
|
||||
unsigned long lastConnectMoment = 0;
|
||||
unsigned long lastDisconnectMoment = 0;
|
||||
unsigned long lastGetIPmoment = 0;
|
||||
unsigned long lastGetScanMoment = 0;
|
||||
unsigned long lastConnectedDuration = 0;
|
||||
bool intent_to_reboot = false;
|
||||
uint8_t lastMacConnectedAPmode[6] = {0};
|
||||
uint8_t lastMacDisconnectedAPmode[6] = {0};
|
||||
|
||||
//uint32_t scan_done_status = 0;
|
||||
uint8_t scan_done_number = 0;
|
||||
//uint8_t scan_done_scan_id = 0;
|
||||
|
||||
// Semaphore like booleans for processing data gathered from WiFi events.
|
||||
bool processedConnect = true;
|
||||
bool processedDisconnect = true;
|
||||
bool processedGetIP = true;
|
||||
bool processedConnectAPmode = true;
|
||||
bool processedDisconnectAPmode = true;
|
||||
bool processedScanDone = true;
|
||||
|
||||
bool webserver_state = false;
|
||||
bool webserver_init = false;
|
||||
|
||||
unsigned long start = 0;
|
||||
unsigned long elapsed = 0;
|
||||
@@ -1195,6 +1271,7 @@ bool firstLoop=true;
|
||||
|
||||
boolean activeRuleSets[RULESETS_MAX];
|
||||
|
||||
boolean UseRTOSMultitasking;
|
||||
|
||||
// These wifi event functions must be in a .h-file because otherwise the preprocessor
|
||||
// may not filter the ifdef checks properly.
|
||||
|
||||
+161
-51
@@ -96,7 +96,9 @@ int firstEnabledBlynkController() {
|
||||
\*********************************************************************************************/
|
||||
void setup()
|
||||
{
|
||||
|
||||
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
|
||||
WiFi.setAutoReconnect(false);
|
||||
setWifiMode(WIFI_OFF);
|
||||
|
||||
checkRAM(F("setup"));
|
||||
#if defined(ESP32)
|
||||
@@ -110,7 +112,6 @@ void setup()
|
||||
// Serial.print("\n\n\nBOOOTTT\n\n\n");
|
||||
|
||||
initLog();
|
||||
|
||||
#if defined(ESP32)
|
||||
WiFi.onEvent((WiFiEventFullCb)WiFiEvent);
|
||||
#else
|
||||
@@ -118,6 +119,8 @@ void setup()
|
||||
stationConnectedHandler = WiFi.onStationModeConnected(onConnected);
|
||||
stationDisconnectedHandler = WiFi.onStationModeDisconnected(onDisconnect);
|
||||
stationGotIpHandler = WiFi.onStationModeGotIP(onGotIP);
|
||||
APModeStationConnectedHandler = WiFi.onSoftAPModeStationConnected(onConnectedAPmode);
|
||||
APModeStationDisconnectedHandler = WiFi.onSoftAPModeStationDisconnected(onDisonnectedAPmode);
|
||||
#endif
|
||||
|
||||
if (SpiffsSectors() < 32)
|
||||
@@ -131,6 +134,14 @@ void setup()
|
||||
|
||||
String log = F("\n\n\rINIT : Booting version: ");
|
||||
log += BUILD_GIT;
|
||||
#if defined(ESP32)
|
||||
log += F(" (ESP32 SDK ");
|
||||
log += ESP.getSdkVersion();
|
||||
#else
|
||||
log += F(" (ESP82xx Core ");
|
||||
log += ESP.getCoreVersion();
|
||||
#endif
|
||||
log += F(")");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
|
||||
|
||||
@@ -170,9 +181,9 @@ void setup()
|
||||
fileSystemCheck();
|
||||
progMemMD5check();
|
||||
LoadSettings();
|
||||
|
||||
// setWifiMode(WIFI_STA);
|
||||
checkRuleSets();
|
||||
if (strcasecmp(SecuritySettings.WifiSSID, "ssid") == 0)
|
||||
wifiSetup = true;
|
||||
|
||||
ExtraTaskSettings.TaskIndex = 255; // make sure this is an unused nr to prevent cache load on boot
|
||||
|
||||
@@ -195,6 +206,7 @@ void setup()
|
||||
//make sure previous serial buffers are flushed before resetting baudrate
|
||||
Serial.flush();
|
||||
Serial.begin(Settings.BaudRate);
|
||||
// Serial.setDebugOutput(true);
|
||||
}
|
||||
|
||||
if (Settings.Build != BUILD)
|
||||
@@ -221,30 +233,61 @@ void setup()
|
||||
timer100ms = 0; // timer for periodic actions 10 x per/sec
|
||||
timer1s = 0; // timer for periodic actions once per/sec
|
||||
timerwd = 0; // timer for watchdog once per 30 sec
|
||||
timermqtt = 0; // Timer for the MQTT keep alive loop.
|
||||
timermqtt = 10000; // Timer for the MQTT keep alive loop, initial value can be high, since it will be set as soon as IP is set.
|
||||
timermqtt_interval = 250; // Interval for checking MQTT
|
||||
timerAwakeFromDeepSleep = millis();
|
||||
|
||||
PluginInit();
|
||||
CPluginInit();
|
||||
NPluginInit();
|
||||
log = F("INFO : Plugins: ");
|
||||
log += deviceCount + 1;
|
||||
#ifdef PLUGIN_BUILD_NORMAL
|
||||
log += F(" [Normal]");
|
||||
#endif
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
log += F(" [Testing]");
|
||||
#endif
|
||||
#ifdef PLUGIN_BUILD_DEV
|
||||
log += F(" [Development]");
|
||||
#endif
|
||||
#if defined(ESP32)
|
||||
log += F(" (ESP32 SDK ");
|
||||
log += ESP.getSdkVersion();
|
||||
#else
|
||||
log += F(" (ESP82xx Core ");
|
||||
log += ESP.getCoreVersion();
|
||||
#endif
|
||||
log += F(")");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
|
||||
if (deviceCount + 1 >= PLUGIN_MAX) {
|
||||
addLog(LOG_LEVEL_ERROR, F("Programming error! - Increase PLUGIN_MAX"));
|
||||
}
|
||||
|
||||
if (Settings.UseRules)
|
||||
{
|
||||
String event = F("System#Wake");
|
||||
rulesProcessing(event);
|
||||
}
|
||||
|
||||
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
|
||||
WifiAPconfig();
|
||||
|
||||
if (!selectValidWiFiSettings()) {
|
||||
wifiSetup = true;
|
||||
}
|
||||
/*
|
||||
// FIXME TD-er:
|
||||
// Async scanning for wifi doesn't work yet like it should.
|
||||
// So no selection of strongest network yet.
|
||||
if (selectValidWiFiSettings()) {
|
||||
WifiScanAsync();
|
||||
}
|
||||
*/
|
||||
WiFiConnectRelaxed();
|
||||
|
||||
#ifdef FEATURE_REPORTING
|
||||
ReportStatus();
|
||||
#endif
|
||||
|
||||
WebServerInit();
|
||||
|
||||
#ifdef FEATURE_ARDUINO_OTA
|
||||
ArduinoOTAInit();
|
||||
#endif
|
||||
@@ -262,12 +305,6 @@ void setup()
|
||||
vcc = ESP.getVcc() / 1000.0;
|
||||
#endif
|
||||
|
||||
// Start DNS, only used if the ESP has no valid WiFi config
|
||||
// It will reply with it's own address on all DNS requests
|
||||
// (captive portal concept)
|
||||
if (wifiSetup)
|
||||
dnsServer.start(DNS_PORT, "*", apIP);
|
||||
|
||||
if (Settings.UseRules)
|
||||
{
|
||||
String event = F("System#Boot");
|
||||
@@ -276,8 +313,52 @@ void setup()
|
||||
|
||||
writeDefaultCSS();
|
||||
|
||||
UseRTOSMultitasking = Settings.UseRTOSMultitasking;
|
||||
#ifdef USE_RTOS_MULTITASKING
|
||||
if(UseRTOSMultitasking){
|
||||
log = F("RTOS : Launching tasks");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
xTaskCreatePinnedToCore(RTOS_TaskServers, "RTOS_TaskServers", 8192, NULL, 1, NULL, 1);
|
||||
xTaskCreatePinnedToCore(RTOS_TaskSerial, "RTOS_TaskSerial", 8192, NULL, 1, NULL, 1);
|
||||
xTaskCreatePinnedToCore(RTOS_Task10ps, "RTOS_Task10ps", 8192, NULL, 1, NULL, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ESP32
|
||||
connectionCheck.attach(240, connectionCheckHandler);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_RTOS_MULTITASKING
|
||||
void RTOS_TaskServers( void * parameter )
|
||||
{
|
||||
while (true){
|
||||
delay(100);
|
||||
WebServer.handleClient();
|
||||
checkUDP();
|
||||
}
|
||||
}
|
||||
|
||||
void RTOS_TaskSerial( void * parameter )
|
||||
{
|
||||
while (true){
|
||||
delay(100);
|
||||
if (Settings.UseSerial)
|
||||
if (Serial.available())
|
||||
if (!PluginCall(PLUGIN_SERIAL_IN, 0, dummyString))
|
||||
serial();
|
||||
}
|
||||
}
|
||||
|
||||
void RTOS_Task10ps( void * parameter )
|
||||
{
|
||||
while (true){
|
||||
delay(100);
|
||||
run10TimesPerSecond();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int firstEnabledMQTTController() {
|
||||
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
|
||||
byte ProtocolIndex = getProtocolIndex(Settings.Protocol[i]);
|
||||
@@ -312,24 +393,31 @@ void loop()
|
||||
if (wifiStatus >= ESPEASY_WIFI_CONNECTED) processConnect();
|
||||
if (wifiStatus >= ESPEASY_WIFI_GOT_IP) processGotIP();
|
||||
if (wifiStatus == ESPEASY_WIFI_DISCONNECTED) processDisconnect();
|
||||
} else if (WiFi.status() != WL_CONNECTED) {
|
||||
// Somehow the WiFi has entered a limbo state.
|
||||
// FIXME TD-er: This may happen on WiFi config with AP_STA mode active.
|
||||
// addLog(LOG_LEVEL_ERROR, F("Wifi status out sync"));
|
||||
// resetWiFi();
|
||||
}
|
||||
if (!processedConnectAPmode) processConnectAPmode();
|
||||
if (!processedDisconnectAPmode) processDisconnectAPmode();
|
||||
if (!processedScanDone) processScanDone();
|
||||
|
||||
// Deep sleep mode, just run all tasks one time and go back to sleep as fast as possible
|
||||
if (firstLoop && isDeepSleepEnabled())
|
||||
bool firstLoopWiFiConnected = wifiStatus == ESPEASY_WIFI_SERVICES_INITIALIZED && firstLoop;
|
||||
if (firstLoopWiFiConnected) {
|
||||
firstLoop = false;
|
||||
timerAwakeFromDeepSleep = millis(); // Allow to run for "awake" number of seconds, now we have wifi.
|
||||
}
|
||||
|
||||
// Deep sleep mode, just run all tasks one (more) time and go back to sleep as fast as possible
|
||||
if ((firstLoopWiFiConnected || readyForSleep()) && isDeepSleepEnabled())
|
||||
{
|
||||
// Setup MQTT Client
|
||||
// Controller index is forced to the first enabled MQTT controller.
|
||||
// This is normally done via frequent checks, but there's no time for in deepsleep.
|
||||
int enabledMqttController = firstEnabledMQTTController();
|
||||
if (enabledMqttController >= 0) {
|
||||
MQTTConnect(enabledMqttController);
|
||||
}
|
||||
runPeriodicalMQTT();
|
||||
// Now run all frequent tasks
|
||||
run50TimesPerSecond();
|
||||
run10TimesPerSecond();
|
||||
runEach30Seconds();
|
||||
runOncePerSecond();
|
||||
runPeriodicalMQTT();
|
||||
}
|
||||
//normal mode, run each task when its time
|
||||
else
|
||||
@@ -339,7 +427,8 @@ void loop()
|
||||
run50TimesPerSecond();
|
||||
|
||||
if (timeOutReached(timer100ms))
|
||||
run10TimesPerSecond();
|
||||
if(!UseRTOSMultitasking)
|
||||
run10TimesPerSecond();
|
||||
|
||||
if (timeOutReached(timerwd))
|
||||
runEach30Seconds();
|
||||
@@ -366,28 +455,52 @@ void loop()
|
||||
deepSleep(Settings.Delay);
|
||||
//deepsleep will never return, its a special kind of reboot
|
||||
}
|
||||
firstLoop = false;
|
||||
}
|
||||
|
||||
|
||||
void runPeriodicalMQTT() {
|
||||
// MQTT_KEEPALIVE = 15 seconds.
|
||||
timermqtt = millis() + timermqtt_interval;
|
||||
if (!WiFiConnected(10)) {
|
||||
updateMQTTclient_connected();
|
||||
return;
|
||||
}
|
||||
//dont do this in backgroundtasks(), otherwise causes crashes. (https://github.com/letscontrolit/ESPEasy/issues/683)
|
||||
int enabledMqttController = firstEnabledMQTTController();
|
||||
if (enabledMqttController >= 0) {
|
||||
if (!MQTTclient.loop()) {
|
||||
if (!MQTTCheck(enabledMqttController)) {
|
||||
// Check failed, no need to retry it immediately.
|
||||
if (timermqtt_interval < 2000)
|
||||
timermqtt_interval += 250;
|
||||
} else {
|
||||
timermqtt_interval = 250;
|
||||
updateMQTTclient_connected();
|
||||
if (MQTTCheck(enabledMqttController)) {
|
||||
updateMQTTclient_connected();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (MQTTclient.connected()) {
|
||||
MQTTclient.disconnect();
|
||||
updateMQTTclient_connected();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateMQTTclient_connected() {
|
||||
if (MQTTclient_connected != MQTTclient.connected()) {
|
||||
MQTTclient_connected = !MQTTclient_connected;
|
||||
if (!MQTTclient_connected)
|
||||
addLog(LOG_LEVEL_ERROR, F("MQTT : Connection lost"));
|
||||
if (Settings.UseRules) {
|
||||
String event = MQTTclient_connected ? F("MQTT#Connected") : F("MQTT#Disconnected");
|
||||
rulesProcessing(event);
|
||||
}
|
||||
}
|
||||
if (!MQTTclient_connected) {
|
||||
if (timermqtt_interval < 2000) {
|
||||
timermqtt_interval += 250;
|
||||
}
|
||||
} else {
|
||||
timermqtt_interval = 250;
|
||||
}
|
||||
timermqtt = millis() + timermqtt_interval;
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Tasks that run 50 times per second
|
||||
\*********************************************************************************************/
|
||||
@@ -415,7 +528,9 @@ void run10TimesPerSecond()
|
||||
eventBuffer = "";
|
||||
}
|
||||
elapsed = micros() - start;
|
||||
WebServer.handleClient();
|
||||
#ifndef USE_RTOS_MULTITASKING
|
||||
WebServer.handleClient();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -503,12 +618,7 @@ void runOncePerSecond()
|
||||
Serial.print(F(" uS 1 ps:"));
|
||||
Serial.println(timer);
|
||||
}
|
||||
|
||||
if (timerAPoff != 0 && timeOutReached(timerAPoff))
|
||||
{
|
||||
timerAPoff = 0;
|
||||
WifiAPMode(false);
|
||||
}
|
||||
checkResetFactoryPin();
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
@@ -754,19 +864,19 @@ void backgroundtasks()
|
||||
tcpCleanup();
|
||||
#endif
|
||||
|
||||
if (Settings.UseSerial)
|
||||
if (Serial.available())
|
||||
if (!PluginCall(PLUGIN_SERIAL_IN, 0, dummyString))
|
||||
serial();
|
||||
if(!UseRTOSMultitasking){
|
||||
if (Settings.UseSerial)
|
||||
if (Serial.available())
|
||||
if (!PluginCall(PLUGIN_SERIAL_IN, 0, dummyString))
|
||||
serial();
|
||||
WebServer.handleClient();
|
||||
checkUDP();
|
||||
}
|
||||
|
||||
// process DNS, only used if the ESP has no valid WiFi config
|
||||
if (wifiSetup)
|
||||
if (dnsServerActive)
|
||||
dnsServer.processNextRequest();
|
||||
|
||||
WebServer.handleClient();
|
||||
|
||||
checkUDP();
|
||||
|
||||
#ifdef FEATURE_ARDUINO_OTA
|
||||
if(Settings.ArduinoOTAEnable)
|
||||
ArduinoOTA.handle();
|
||||
|
||||
+76
-7
@@ -1,3 +1,36 @@
|
||||
//********************************************************************************
|
||||
// Work-around for setting _useStaticIP
|
||||
// See reported issue: https://github.com/esp8266/Arduino/issues/4114
|
||||
//********************************************************************************
|
||||
#ifdef ESP32
|
||||
class WiFi_Access_Static_IP: public WiFiSTAClass {
|
||||
public:
|
||||
void set_use_static_ip(bool enabled) {
|
||||
_useStaticIp = enabled;
|
||||
}
|
||||
};
|
||||
#else
|
||||
class WiFi_Access_Static_IP: public ESP8266WiFiSTAClass {
|
||||
public:
|
||||
void set_use_static_ip(bool enabled) {
|
||||
_useStaticIp = enabled;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
void setUseStaticIP(bool enabled) {
|
||||
WiFi_Access_Static_IP tmp_wifi;
|
||||
tmp_wifi.set_use_static_ip(enabled);
|
||||
}
|
||||
|
||||
|
||||
void markGotIP() {
|
||||
lastGetIPmoment = millis();
|
||||
wifiStatus = ESPEASY_WIFI_GOT_IP;
|
||||
processedGetIP = false;
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Functions called on events.
|
||||
// Make sure not to call anything in these functions that result in delay() or yield()
|
||||
@@ -23,9 +56,26 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) {
|
||||
wifiStatus = ESPEASY_WIFI_DISCONNECTED;
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
lastGetIPmoment = millis();
|
||||
wifiStatus = ESPEASY_WIFI_GOT_IP;
|
||||
processedGetIP = false;
|
||||
markGotIP();
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STACONNECTED:
|
||||
for (byte i = 0; i < 6; ++i) {
|
||||
lastMacConnectedAPmode[i] = info.sta_connected.mac[i];
|
||||
}
|
||||
processedConnectAPmode = false;
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STADISCONNECTED:
|
||||
for (byte i = 0; i < 6; ++i) {
|
||||
lastMacConnectedAPmode[i] = info.sta_disconnected.mac[i];
|
||||
}
|
||||
processedDisconnectAPmode = false;
|
||||
break;
|
||||
case SYSTEM_EVENT_SCAN_DONE:
|
||||
lastGetScanMoment = millis();
|
||||
// scan_done_status = info.scan_done.status;
|
||||
scan_done_number = info.scan_done.number;
|
||||
// scan_done_scan_id = info.scan_done.scan_id;
|
||||
processedScanDone = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -55,14 +105,33 @@ void onDisconnect(const WiFiEventStationModeDisconnected& event){
|
||||
lastConnectedDuration = timeDiff(last_wifi_connect_attempt_moment, lastDisconnectMoment);
|
||||
} else
|
||||
lastConnectedDuration = timeDiff(lastConnectMoment, lastDisconnectMoment);
|
||||
processedDisconnect = false;
|
||||
lastDisconnectReason = event.reason;
|
||||
wifiStatus = ESPEASY_WIFI_DISCONNECTED;
|
||||
processedDisconnect = false;
|
||||
}
|
||||
|
||||
void onGotIP(const WiFiEventStationModeGotIP& event){
|
||||
lastGetIPmoment = millis();
|
||||
wifiStatus = ESPEASY_WIFI_GOT_IP;
|
||||
processedGetIP = false;
|
||||
markGotIP();
|
||||
}
|
||||
|
||||
void onConnectedAPmode(const WiFiEventSoftAPModeStationConnected& event) {
|
||||
for (byte i = 0; i < 6; ++i) {
|
||||
lastMacConnectedAPmode[i] = event.mac[i];
|
||||
}
|
||||
processedConnectAPmode = false;
|
||||
}
|
||||
|
||||
void onDisonnectedAPmode(const WiFiEventSoftAPModeStationDisconnected& event) {
|
||||
for (byte i = 0; i < 6; ++i) {
|
||||
lastMacDisconnectedAPmode[i] = event.mac[i];
|
||||
}
|
||||
processedDisconnectAPmode = false;
|
||||
}
|
||||
|
||||
void onScanFinished(int networksFound) {
|
||||
lastGetScanMoment = millis();
|
||||
scan_done_number = networksFound;
|
||||
processedScanDone = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+441
-169
@@ -1,4 +1,5 @@
|
||||
|
||||
#define WIFI_AP_OFF_TIMER_DURATION 60000 // in milliSeconds
|
||||
|
||||
//********************************************************************************
|
||||
// Functions to process the data gathered from the events.
|
||||
@@ -6,15 +7,16 @@
|
||||
//********************************************************************************
|
||||
void processConnect() {
|
||||
if (processedConnect) return;
|
||||
processedConnect = true;
|
||||
++wifi_reconnects;
|
||||
if (wifiStatus < ESPEASY_WIFI_CONNECTED) return;
|
||||
|
||||
const long connect_duration = timeDiff(last_wifi_connect_attempt_moment, lastConnectMoment);
|
||||
String log = F("WIFI : Connected! AP: ");
|
||||
log += WiFi.SSID();
|
||||
log += F(" (");
|
||||
log += WiFi.BSSIDstr();
|
||||
log += F(") Ch: ");
|
||||
log += last_channel;
|
||||
const long connect_duration = timeDiff(last_wifi_connect_attempt_moment, lastConnectMoment);
|
||||
if (connect_duration > 0 && connect_duration < 30000) {
|
||||
// Just log times when they make sense.
|
||||
log += F(" Duration: ");
|
||||
@@ -22,17 +24,20 @@ void processConnect() {
|
||||
log += F(" ms");
|
||||
}
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
|
||||
if (Settings.UseRules && bssid_changed) {
|
||||
String event = F("WiFi#ChangedAccesspoint");
|
||||
rulesProcessing(event);
|
||||
}
|
||||
wifi_connect_attempt = 0;
|
||||
processedConnect = true;
|
||||
if (useStaticIP()) {
|
||||
setupStaticIPconfig();
|
||||
markGotIP();
|
||||
}
|
||||
logConnectionStatus();
|
||||
}
|
||||
|
||||
void processDisconnect() {
|
||||
if (processedDisconnect) return;
|
||||
processedDisconnect = true;
|
||||
if (Settings.UseRules) {
|
||||
String event = F("WiFi#Disconnected");
|
||||
rulesProcessing(event);
|
||||
@@ -45,25 +50,18 @@ void processDisconnect() {
|
||||
log += format_msec_duration(lastConnectedDuration);
|
||||
}
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
processedDisconnect = true;
|
||||
|
||||
if (Settings.deepSleep && Settings.deepSleepOnFail) {
|
||||
//only one attempt in deepsleep, to conserve battery
|
||||
addLog(LOG_LEVEL_ERROR, F("SLEEP: Connection failed, going back to sleep."));
|
||||
deepSleep(Settings.Delay);
|
||||
}
|
||||
|
||||
if (!intent_to_reboot)
|
||||
WiFiConnectRelaxed();
|
||||
logConnectionStatus();
|
||||
}
|
||||
|
||||
|
||||
void processGotIP() {
|
||||
if (processedGetIP)
|
||||
return;
|
||||
if (wifiStatus < ESPEASY_WIFI_GOT_IP)
|
||||
return;
|
||||
IPAddress ip = WiFi.localIP();
|
||||
if (!useStaticIP())
|
||||
if (ip[0] == 0 && ip[1] == 0 && ip[2] == 0 && ip[3] == 0)
|
||||
return;
|
||||
processedGetIP = true;
|
||||
const IPAddress gw = WiFi.gatewayIP();
|
||||
const IPAddress subnet = WiFi.subnetMask();
|
||||
String log = F("WIFI : ");
|
||||
@@ -118,17 +116,272 @@ void processGotIP() {
|
||||
if (Settings.UseNTP) {
|
||||
initTime();
|
||||
}
|
||||
mqtt_reconnect_count = 0;
|
||||
timermqtt_interval = 100;
|
||||
timermqtt = millis() + timermqtt_interval;
|
||||
if (Settings.UseRules)
|
||||
{
|
||||
String event = F("WiFi#Connected");
|
||||
rulesProcessing(event);
|
||||
}
|
||||
statusLED(true);
|
||||
// WiFi.scanDelete();
|
||||
wifiStatus = ESPEASY_WIFI_SERVICES_INITIALIZED;
|
||||
processedGetIP = true;
|
||||
setWebserverRunning(true);
|
||||
wifi_connect_attempt = 0;
|
||||
if (wifiSetup) {
|
||||
// Wifi setup was active, Apparently these settings work.
|
||||
wifiSetup = false;
|
||||
SaveSettings();
|
||||
}
|
||||
logConnectionStatus();
|
||||
}
|
||||
|
||||
void processConnectAPmode() {
|
||||
if (processedConnectAPmode) return;
|
||||
processedConnectAPmode = true;
|
||||
String log = F("AP Mode: Client connected: ");
|
||||
log += formatMAC(lastMacConnectedAPmode);
|
||||
log += F(" Connected devices: ");
|
||||
log += WiFi.softAPgetStationNum();
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
timerAPoff = 0; // Disable timer to switch AP off
|
||||
setWebserverRunning(true);
|
||||
// Start DNS, only used if the ESP has no valid WiFi config
|
||||
// It will reply with it's own address on all DNS requests
|
||||
// (captive portal concept)
|
||||
if (!dnsServerActive) {
|
||||
dnsServerActive = true;
|
||||
dnsServer.start(DNS_PORT, "*", apIP);
|
||||
}
|
||||
}
|
||||
|
||||
void processDisconnectAPmode() {
|
||||
if (processedDisconnectAPmode) return;
|
||||
processedDisconnectAPmode = true;
|
||||
const int nrStationsConnected = WiFi.softAPgetStationNum();
|
||||
String log = F("AP Mode: Client disconnected: ");
|
||||
log += formatMAC(lastMacDisconnectedAPmode);
|
||||
log += F(" Connected devices: ");
|
||||
log += nrStationsConnected;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
if (nrStationsConnected == 0) {
|
||||
timerAPoff = millis() + WIFI_AP_OFF_TIMER_DURATION;
|
||||
}
|
||||
}
|
||||
|
||||
void processDisableAPmode() {
|
||||
if (timerAPoff == 0) return;
|
||||
if (WifiIsAP(WiFi.getMode())) {
|
||||
// disable AP after timeout.
|
||||
if (timeOutReached(timerAPoff)) {
|
||||
setAP(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void processScanDone() {
|
||||
if (processedScanDone) return;
|
||||
processedScanDone = true;
|
||||
String log = F("WIFI : Scan finished, found: ");
|
||||
log += scan_done_number;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
|
||||
int bestScanID = -1;
|
||||
int32_t bestRssi = -1000;
|
||||
uint8_t bestWiFiSettings = lastWiFiSettings;
|
||||
if (selectValidWiFiSettings()) {
|
||||
bool done = false;
|
||||
String lastWiFiSettingsSSID = getLastWiFiSettingsSSID();
|
||||
for (int settingNr = 0; !done && settingNr < 2; ++settingNr) {
|
||||
for (int i = 0; i < scan_done_number; ++i) {
|
||||
if (WiFi.SSID(i) == lastWiFiSettingsSSID) {
|
||||
int32_t rssi = WiFi.RSSI(i);
|
||||
if (bestRssi < rssi) {
|
||||
bestRssi = rssi;
|
||||
bestScanID = i;
|
||||
bestWiFiSettings = lastWiFiSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!selectNextWiFiSettings()) done = true;
|
||||
}
|
||||
if (bestScanID >= 0) {
|
||||
log = F("WIFI : Selected: ");
|
||||
log += formatScanResult(bestScanID, " ");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
lastWiFiSettings = bestWiFiSettings;
|
||||
uint8_t * scanbssid = WiFi.BSSID(bestScanID);
|
||||
if (scanbssid) {
|
||||
for (int i = 0; i < 6 ; ++i) {
|
||||
lastBSSID[i] = *(scanbssid + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void resetWiFi() {
|
||||
addLog(LOG_LEVEL_INFO, F("Reset WiFi."));
|
||||
setWifiMode(WIFI_OFF);
|
||||
setWifiMode(WIFI_STA);
|
||||
lastDisconnectMoment = millis();
|
||||
processedDisconnect = false;
|
||||
wifiStatus = ESPEASY_WIFI_DISCONNECTED;
|
||||
}
|
||||
|
||||
void WifiScanAsync() {
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : Start network scan"));
|
||||
#ifdef ESP32
|
||||
bool async = true;
|
||||
bool show_hidden = false;
|
||||
bool passive = false;
|
||||
uint32_t max_ms_per_chan = 300;
|
||||
WiFi.scanNetworks(async, show_hidden, passive, max_ms_per_chan);
|
||||
#else
|
||||
// 2.4.x only and it doesn't work like expected.
|
||||
// WiFi.scanNetworksAsync(onScanFinished);
|
||||
#endif
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// WiFi state
|
||||
//********************************************************************************
|
||||
// 0 Wifi off
|
||||
// 1 Start => STA
|
||||
// 2 Try connect => STA => successful, goto 7
|
||||
// 3 Connection fails => AP => no client in N seconds, goto 1
|
||||
// 4 Client connects => AP
|
||||
// 5 Credentials changed => STA_AP => goto 2
|
||||
// 6 Connect successful (AP on) => STA_AP => disable AP after N seconds, goto 8
|
||||
// 7 Connect successful => STA
|
||||
// 8 Disable AP after N seconds => STA
|
||||
//********************************************************************************
|
||||
|
||||
bool WifiIsAP(WiFiMode_t wifimode)
|
||||
{
|
||||
#if defined(ESP32)
|
||||
return (wifimode == WIFI_MODE_AP) || (wifimode == WIFI_MODE_APSTA);
|
||||
#else
|
||||
return (wifimode == WIFI_AP) || (wifimode == WIFI_AP_STA);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool WifiIsSTA(WiFiMode_t wifimode)
|
||||
{
|
||||
#if defined(ESP32)
|
||||
return ((wifimode & WIFI_MODE_STA) != 0);
|
||||
#else
|
||||
return ((wifimode & WIFI_STA) != 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************
|
||||
// Set Wifi Mode
|
||||
//********************************************************************************
|
||||
void setSTA(bool enable) {
|
||||
switch(WiFi.getMode()) {
|
||||
case WIFI_OFF:
|
||||
if (enable) setWifiMode(WIFI_STA);
|
||||
break;
|
||||
case WIFI_STA:
|
||||
if (!enable) setWifiMode(WIFI_OFF);
|
||||
break;
|
||||
case WIFI_AP:
|
||||
if (enable) setWifiMode(WIFI_AP_STA);
|
||||
break;
|
||||
case WIFI_AP_STA:
|
||||
if (!enable) setWifiMode(WIFI_AP);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setAP(bool enable) {
|
||||
switch(WiFi.getMode()) {
|
||||
case WIFI_OFF:
|
||||
if (enable) setWifiMode(WIFI_AP);
|
||||
break;
|
||||
case WIFI_STA:
|
||||
if (enable) setWifiMode(WIFI_AP_STA);
|
||||
break;
|
||||
case WIFI_AP:
|
||||
if (!enable) setWifiMode(WIFI_OFF);
|
||||
break;
|
||||
case WIFI_AP_STA:
|
||||
if (!enable) setWifiMode(WIFI_STA);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (enable) {
|
||||
timerAPoff = millis() + WIFI_AP_OFF_TIMER_DURATION;
|
||||
// create and store unique AP SSID/PW to prevent ESP from starting AP mode with default SSID and No password!
|
||||
// setup ssid for AP Mode when needed
|
||||
String softAPSSID=WifiGetAPssid();
|
||||
String pwd = SecuritySettings.WifiAPKey;
|
||||
IPAddress subnet(DEFAULT_AP_SUBNET);
|
||||
if (!WiFi.softAPConfig(apIP, apIP, subnet)) {
|
||||
addLog(LOG_LEVEL_ERROR, "WIFI : [AP] softAPConfig failed!");
|
||||
}
|
||||
if (WiFi.softAP(softAPSSID.c_str(),pwd.c_str())) {
|
||||
String log("WIFI : AP Mode ssid will be ");
|
||||
log += softAPSSID;
|
||||
log += F(" with address ");
|
||||
log += WiFi.softAPIP().toString();
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
} else {
|
||||
String log("WIFI : Error while starting AP Mode with SSID: ");
|
||||
log += softAPSSID;
|
||||
log += F(" IP: ");
|
||||
log += apIP.toString();
|
||||
addLog(LOG_LEVEL_ERROR, log);
|
||||
}
|
||||
#ifdef ESP32
|
||||
|
||||
#else
|
||||
if(wifi_softap_dhcps_status() != DHCP_STARTED) {
|
||||
if(!wifi_softap_dhcps_start()) {
|
||||
addLog(LOG_LEVEL_ERROR, "WIFI : [AP] wifi_softap_dhcps_start failed!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
timerAPoff = 0; // Disable timer to switch AP off
|
||||
if (dnsServerActive) {
|
||||
dnsServerActive = false;
|
||||
dnsServer.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setWifiMode(WiFiMode_t wifimode) {
|
||||
if (WiFi.getMode() == wifimode) {
|
||||
return;
|
||||
}
|
||||
switch (wifimode) {
|
||||
case WIFI_OFF:
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : Switch off WiFi"));
|
||||
break;
|
||||
case WIFI_STA:
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : Set WiFi to STA"));
|
||||
break;
|
||||
case WIFI_AP:
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : Set WiFi to AP"));
|
||||
break;
|
||||
case WIFI_AP_STA:
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : Set WiFi to AP+STA"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
setUseStaticIP(useStaticIP());
|
||||
WiFi.mode(wifimode);
|
||||
delay(30); // Must allow for some time to init.
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************
|
||||
@@ -137,7 +390,7 @@ void processGotIP() {
|
||||
String WifiGetAPssid()
|
||||
{
|
||||
String ssid(Settings.Name);
|
||||
ssid+=F("-");
|
||||
ssid+=F("_");
|
||||
ssid+=Settings.Unit;
|
||||
return (ssid);
|
||||
}
|
||||
@@ -154,76 +407,34 @@ String WifiGetHostname()
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************
|
||||
// Set Wifi AP Mode config
|
||||
//********************************************************************************
|
||||
void WifiAPconfig()
|
||||
{
|
||||
// create and store unique AP SSID/PW to prevent ESP from starting AP mode with default SSID and No password!
|
||||
// setup ssid for AP Mode when needed
|
||||
|
||||
String softAPSSID=WifiGetAPssid();
|
||||
String pwd = SecuritySettings.WifiAPKey;
|
||||
WiFi.softAP(softAPSSID.c_str(),pwd.c_str());
|
||||
// We start in STA mode
|
||||
WifiAPMode(false);
|
||||
|
||||
String log("WIFI : AP Mode ssid will be ");
|
||||
log=log+WifiGetAPssid();
|
||||
|
||||
log=log+F(" with address ");
|
||||
log=log+apIP.toString();
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
|
||||
bool WifiIsAP()
|
||||
{
|
||||
#if defined(ESP8266)
|
||||
byte wifimode = wifi_get_opmode();
|
||||
#endif
|
||||
#if defined(ESP32)
|
||||
byte wifimode = WiFi.getMode();
|
||||
#endif
|
||||
return(wifimode == 2 || wifimode == 3); //apmode is enabled
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Set Wifi AP Mode
|
||||
//********************************************************************************
|
||||
void WifiAPMode(boolean state)
|
||||
{
|
||||
if (WifiIsAP())
|
||||
{
|
||||
//want to disable?
|
||||
if (!state)
|
||||
{
|
||||
WiFi.mode(WIFI_STA);
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : AP Mode disabled"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//want to enable?
|
||||
if (state)
|
||||
{
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
addLog(LOG_LEVEL_INFO, F("WIFI : AP Mode enabled"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool useStaticIP() {
|
||||
return (Settings.IP[0] != 0 && Settings.IP[0] != 255);
|
||||
}
|
||||
|
||||
|
||||
void WiFiConnectRelaxed() {
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
return; //already connected, need to disconnect first
|
||||
if (prepareWiFi()) {
|
||||
if (selectValidWiFiSettings()) {
|
||||
tryConnectWiFi();
|
||||
return;
|
||||
}
|
||||
}
|
||||
addLog(LOG_LEVEL_ERROR, F("WIFI : Could not connect to AP!"));
|
||||
//everything failed, activate AP mode (will deactivate automatically after a while if its connected again)
|
||||
setAP(true);
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Set Wifi config
|
||||
//********************************************************************************
|
||||
bool prepareWiFi() {
|
||||
if (!selectValidWiFiSettings())
|
||||
if (!selectValidWiFiSettings()) {
|
||||
addLog(LOG_LEVEL_ERROR, F("WIFI : No valid wifi settings"));
|
||||
return false;
|
||||
|
||||
}
|
||||
setSTA(true);
|
||||
String log = "";
|
||||
char hostname[40];
|
||||
strncpy(hostname, WifiGetHostname().c_str(), sizeof(hostname));
|
||||
@@ -233,35 +444,9 @@ bool prepareWiFi() {
|
||||
#if defined(ESP32)
|
||||
WiFi.setHostname(hostname);
|
||||
#endif
|
||||
|
||||
//use static ip?
|
||||
if (useStaticIP())
|
||||
{
|
||||
const IPAddress ip = Settings.IP;
|
||||
log = F("IP : Static IP :");
|
||||
log += ip;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
const IPAddress gw = Settings.Gateway;
|
||||
const IPAddress subnet = Settings.Subnet;
|
||||
const IPAddress dns = Settings.DNS;
|
||||
WiFi.config(ip, gw, subnet, dns);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Start connect to WiFi and check later to see if connected.
|
||||
//********************************************************************************
|
||||
void WiFiConnectRelaxed() {
|
||||
if (prepareWiFi()) {
|
||||
tryConnectWiFi();
|
||||
return;
|
||||
}
|
||||
addLog(LOG_LEVEL_ERROR, F("WIFI : Could not connect to AP! (relaxed connect mode)"));
|
||||
//everything failed, activate AP mode (will deactivate automatically after a while if its connected again)
|
||||
WifiAPMode(true);
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************
|
||||
// Manage WiFi credentials
|
||||
@@ -295,7 +480,7 @@ bool wifiSettingsValid(const char* ssid, const char* pass) {
|
||||
if (ssid[0] == 0 || (strcasecmp(ssid, "ssid") == 0)) {
|
||||
return false;
|
||||
}
|
||||
if (pass[0] == 0) return false;
|
||||
// if (pass[0] == 0) return false; // Allow for empty pass
|
||||
if (strlen(ssid) > 32) return false;
|
||||
if (strlen(pass) > 64) return false;
|
||||
return true;
|
||||
@@ -307,7 +492,7 @@ bool wifiConnectTimeoutReached() {
|
||||
// Connection attempt was already ended.
|
||||
return true;
|
||||
}
|
||||
if (wifiSetupConnect) {
|
||||
if (WifiIsAP(WiFi.getMode())) {
|
||||
// Initial setup of WiFi, may take much longer since accesspoint is still active.
|
||||
return timeOutReached(last_wifi_connect_attempt_moment + 20000);
|
||||
}
|
||||
@@ -322,29 +507,50 @@ bool wifiConnectTimeoutReached() {
|
||||
return timeOutReached(last_wifi_connect_attempt_moment + DEFAULT_WIFI_CONNECTION_TIMEOUT + randomOffset_in_sec);
|
||||
}
|
||||
|
||||
void setupStaticIPconfig() {
|
||||
setUseStaticIP(useStaticIP());
|
||||
if (!useStaticIP()) return;
|
||||
const IPAddress ip = Settings.IP;
|
||||
const IPAddress gw = Settings.Gateway;
|
||||
const IPAddress subnet = Settings.Subnet;
|
||||
const IPAddress dns = Settings.DNS;
|
||||
String log = F("IP : Static IP : ");
|
||||
log += formatIP(ip);
|
||||
log += F(" GW: ");
|
||||
log += formatIP(gw);
|
||||
log += F(" SN: ");
|
||||
log += formatIP(subnet);
|
||||
log += F(" DNS: ");
|
||||
log += formatIP(dns);
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
WiFi.config(ip, gw, subnet, dns);
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Simply start the WiFi connection sequence
|
||||
//********************************************************************************
|
||||
bool tryConnectWiFi() {
|
||||
if (wifiSetup && !wifiSetupConnect)
|
||||
return false;
|
||||
if (wifiStatus != ESPEASY_WIFI_DISCONNECTED)
|
||||
return(true); //already connected, need to disconnect first
|
||||
if (wifiSetupConnect) {
|
||||
lastWiFiSettings = 0; // Force to load the first settings.
|
||||
wifi_connect_attempt = 0;
|
||||
}
|
||||
if (wifiStatus != ESPEASY_WIFI_DISCONNECTED) {
|
||||
if (!WifiIsAP(WiFi.getMode())) {
|
||||
// Only when not in AP mode.
|
||||
return(true); //already connected, need to disconnect first
|
||||
}
|
||||
}
|
||||
if (!wifiConnectTimeoutReached())
|
||||
return true; // timeout not reached yet, thus no need to retry again.
|
||||
if (!selectValidWiFiSettings()) {
|
||||
addLog(LOG_LEVEL_ERROR, F("WIFI : No valid WiFi settings!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (wifi_connect_attempt != 0 && ((wifi_connect_attempt % 3) == 0)) {
|
||||
// Change to other wifi settings.
|
||||
if (selectNextWiFiSettings())
|
||||
WiFi.disconnect();
|
||||
if (wifi_connect_attempt != 0 && (wifi_connect_attempt % 2) == 0) {
|
||||
selectNextWiFiSettings();
|
||||
}
|
||||
if (wifi_connect_attempt > 6) {
|
||||
//everything failed, activate AP mode (will deactivate automatically after a while if its connected again)
|
||||
WifiAPMode(true);
|
||||
if (wifi_connect_attempt > 5) {
|
||||
setAP(true);
|
||||
}
|
||||
const char* ssid = getLastWiFiSettingsSSID();
|
||||
const char* passphrase = getLastWiFiSettingsPassphrase();
|
||||
@@ -353,7 +559,7 @@ bool tryConnectWiFi() {
|
||||
log += F(" attempt #");
|
||||
log += wifi_connect_attempt;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
|
||||
setupStaticIPconfig();
|
||||
last_wifi_connect_attempt_moment = millis();
|
||||
switch (wifi_connect_attempt) {
|
||||
case 0:
|
||||
@@ -366,6 +572,7 @@ bool tryConnectWiFi() {
|
||||
WiFi.begin(ssid, passphrase);
|
||||
}
|
||||
++wifi_connect_attempt;
|
||||
logConnectionStatus();
|
||||
switch (WiFi.status()) {
|
||||
case WL_NO_SSID_AVAIL: {
|
||||
log = F("WIFI : No SSID found matching: ");
|
||||
@@ -390,7 +597,13 @@ bool tryConnectWiFi() {
|
||||
//********************************************************************************
|
||||
void WifiDisconnect()
|
||||
{
|
||||
WiFi.disconnect();
|
||||
#if defined(ESP32)
|
||||
WiFi.disconnect();
|
||||
#else
|
||||
ETS_UART_INTR_DISABLE();
|
||||
wifi_station_disconnect();
|
||||
ETS_UART_INTR_ENABLE();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -415,17 +628,79 @@ void WifiScan()
|
||||
Serial.print(F("WIFI : "));
|
||||
Serial.print(i + 1);
|
||||
Serial.print(": ");
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.print(" (");
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(")");
|
||||
Serial.println("");
|
||||
Serial.println(formatScanResult(i, " "));
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
String formatScanResult(int i, const String& separator) {
|
||||
String result = WiFi.SSID(i);
|
||||
result += separator;
|
||||
result += WiFi.BSSIDstr(i);
|
||||
result += separator;
|
||||
result += F("Ch:");
|
||||
result += WiFi.channel(i);
|
||||
result += F(" (");
|
||||
result += WiFi.RSSI(i);
|
||||
result += F("dBm) ");
|
||||
switch (WiFi.encryptionType(i)) {
|
||||
#ifdef ESP32
|
||||
case WIFI_AUTH_OPEN: result += F("open"); break;
|
||||
case WIFI_AUTH_WEP: result += F("WEP"); break;
|
||||
case WIFI_AUTH_WPA_PSK: result += F("WPA/PSK"); break;
|
||||
case WIFI_AUTH_WPA2_PSK: result += F("WPA2/PSK"); break;
|
||||
case WIFI_AUTH_WPA_WPA2_PSK: result += F("WPA/WPA2/PSK"); break;
|
||||
case WIFI_AUTH_WPA2_ENTERPRISE: result += F("WPA2 Enterprise"); break;
|
||||
#else
|
||||
case ENC_TYPE_WEP: result += F("WEP"); break;
|
||||
case ENC_TYPE_TKIP: result += F("WPA/PSK"); break;
|
||||
case ENC_TYPE_CCMP: result += F("WPA2/PSK"); break;
|
||||
case ENC_TYPE_NONE: result += F("open"); break;
|
||||
case ENC_TYPE_AUTO: result += F("WPA/WPA2/PSK"); break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void logConnectionStatus() {
|
||||
const uint8_t arduino_corelib_wifistatus = WiFi.status();
|
||||
String log;
|
||||
#ifndef ESP32
|
||||
const uint8_t sdk_wifistatus = wifi_station_get_connect_status();
|
||||
if (arduino_corelib_wifistatus != sdk_wifistatus) {
|
||||
log = F("WIFI : SDK station status differs from Arduino status. SDK-status: ");
|
||||
log += sdk_wifistatus;
|
||||
log += F(" Arduino status: ");
|
||||
log += arduino_corelib_wifistatus;
|
||||
addLog(LOG_LEVEL_ERROR, log);
|
||||
}
|
||||
#endif
|
||||
log = F("WIFI : Arduino wifi status: ");
|
||||
switch (arduino_corelib_wifistatus) {
|
||||
case WL_IDLE_STATUS: log += F("WL_IDLE_STATUS"); break;
|
||||
case WL_NO_SSID_AVAIL: log += F("WL_NO_SSID_AVAIL"); break;
|
||||
case WL_SCAN_COMPLETED: log += F("WL_SCAN_COMPLETED"); break;
|
||||
case WL_CONNECTED: log += F("WL_CONNECTED"); break;
|
||||
case WL_CONNECT_FAILED: log += F("WL_CONNECT_FAILED"); break;
|
||||
case WL_CONNECTION_LOST: log += F("WL_CONNECTION_LOST"); break;
|
||||
case WL_DISCONNECTED: log += F("WL_DISCONNECTED"); break;
|
||||
default: log += arduino_corelib_wifistatus; break;
|
||||
}
|
||||
log += F(" ESPeasy internal wifi status: ");
|
||||
switch (wifiStatus) {
|
||||
case ESPEASY_WIFI_DISCONNECTED: log += F("ESPEASY_WIFI_DISCONNECTED"); break;
|
||||
case ESPEASY_WIFI_CONNECTED: log += F("ESPEASY_WIFI_CONNECTED"); break;
|
||||
case ESPEASY_WIFI_GOT_IP: log += F("ESPEASY_WIFI_GOT_IP"); break;
|
||||
case ESPEASY_WIFI_SERVICES_INITIALIZED: log += F("ESPEASY_WIFI_SERVICES_INITIALIZED"); break;
|
||||
default: log += wifiStatus;
|
||||
}
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************
|
||||
// Check if we are still connected to a Wifi AP
|
||||
@@ -435,20 +710,12 @@ void WifiCheck()
|
||||
if(wifiSetup)
|
||||
return;
|
||||
|
||||
if (wifiStatus == ESPEASY_WIFI_DISCONNECTED)
|
||||
{
|
||||
NC_Count++;
|
||||
processDisableAPmode();
|
||||
if (wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED) {
|
||||
WiFiConnectRelaxed();
|
||||
}
|
||||
//connected
|
||||
else
|
||||
{
|
||||
C_Count++;
|
||||
NC_Count = 0;
|
||||
if (C_Count > 2) // disable AP after timeout if a Wifi connection is established...
|
||||
{
|
||||
WifiAPMode(false);
|
||||
}
|
||||
if (mqtt_reconnect_count > 10) {
|
||||
connectionCheckHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +724,7 @@ void WifiCheck()
|
||||
//********************************************************************************
|
||||
bool getSubnetRange(IPAddress& low, IPAddress& high)
|
||||
{
|
||||
if (WifiIsAP()) {
|
||||
if (WifiIsAP(WiFi.getMode())) {
|
||||
// WiFi is active as accesspoint, do not check.
|
||||
return false;
|
||||
}
|
||||
@@ -478,36 +745,41 @@ bool getSubnetRange(IPAddress& low, IPAddress& high)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
String getLastDisconnectReason() {
|
||||
String reason = F("(");
|
||||
reason += lastDisconnectReason;
|
||||
reason += F(") ");
|
||||
switch (lastDisconnectReason) {
|
||||
case WIFI_DISCONNECT_REASON_UNSPECIFIED: return F("Unspecified");
|
||||
case WIFI_DISCONNECT_REASON_AUTH_EXPIRE: return F("Auth expire");
|
||||
case WIFI_DISCONNECT_REASON_AUTH_LEAVE: return F("Auth leave");
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_EXPIRE: return F("Assoc expire");
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_TOOMANY: return F("Assoc toomany");
|
||||
case WIFI_DISCONNECT_REASON_NOT_AUTHED: return F("Not authed");
|
||||
case WIFI_DISCONNECT_REASON_NOT_ASSOCED: return F("Not assoced");
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_LEAVE: return F("Assoc leave");
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_NOT_AUTHED: return F("Assoc not authed");
|
||||
case WIFI_DISCONNECT_REASON_DISASSOC_PWRCAP_BAD: return F("Disassoc pwrcap bad");
|
||||
case WIFI_DISCONNECT_REASON_DISASSOC_SUPCHAN_BAD: return F("Disassoc supchan bad");
|
||||
case WIFI_DISCONNECT_REASON_IE_INVALID: return F("IE invalid");
|
||||
case WIFI_DISCONNECT_REASON_MIC_FAILURE: return F("Mic failure");
|
||||
case WIFI_DISCONNECT_REASON_4WAY_HANDSHAKE_TIMEOUT: return F("4way handshake timeout");
|
||||
case WIFI_DISCONNECT_REASON_GROUP_KEY_UPDATE_TIMEOUT: return F("Group key update timeout");
|
||||
case WIFI_DISCONNECT_REASON_IE_IN_4WAY_DIFFERS: return F("IE in 4way differs");
|
||||
case WIFI_DISCONNECT_REASON_GROUP_CIPHER_INVALID: return F("Group cipher invalid");
|
||||
case WIFI_DISCONNECT_REASON_PAIRWISE_CIPHER_INVALID: return F("Pairwise cipher invalid");
|
||||
case WIFI_DISCONNECT_REASON_AKMP_INVALID: return F("AKMP invalid");
|
||||
case WIFI_DISCONNECT_REASON_UNSUPP_RSN_IE_VERSION: return F("Unsupp RSN IE version");
|
||||
case WIFI_DISCONNECT_REASON_INVALID_RSN_IE_CAP: return F("Invalid RSN IE cap");
|
||||
case WIFI_DISCONNECT_REASON_802_1X_AUTH_FAILED: return F("802 1X auth failed");
|
||||
case WIFI_DISCONNECT_REASON_CIPHER_SUITE_REJECTED: return F("Cipher suite rejected");
|
||||
case WIFI_DISCONNECT_REASON_BEACON_TIMEOUT: return F("Beacon timeout");
|
||||
case WIFI_DISCONNECT_REASON_NO_AP_FOUND: return F("No AP found");
|
||||
case WIFI_DISCONNECT_REASON_AUTH_FAIL: return F("Auth fail");
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_FAIL: return F("Assoc fail");
|
||||
case WIFI_DISCONNECT_REASON_HANDSHAKE_TIMEOUT: return F("Handshake timeout");
|
||||
case WIFI_DISCONNECT_REASON_UNSPECIFIED: reason += F("Unspecified"); break;
|
||||
case WIFI_DISCONNECT_REASON_AUTH_EXPIRE: reason += F("Auth expire"); break;
|
||||
case WIFI_DISCONNECT_REASON_AUTH_LEAVE: reason += F("Auth leave"); break;
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_EXPIRE: reason += F("Assoc expire"); break;
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_TOOMANY: reason += F("Assoc toomany"); break;
|
||||
case WIFI_DISCONNECT_REASON_NOT_AUTHED: reason += F("Not authed"); break;
|
||||
case WIFI_DISCONNECT_REASON_NOT_ASSOCED: reason += F("Not assoced"); break;
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_LEAVE: reason += F("Assoc leave"); break;
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_NOT_AUTHED: reason += F("Assoc not authed"); break;
|
||||
case WIFI_DISCONNECT_REASON_DISASSOC_PWRCAP_BAD: reason += F("Disassoc pwrcap bad"); break;
|
||||
case WIFI_DISCONNECT_REASON_DISASSOC_SUPCHAN_BAD: reason += F("Disassoc supchan bad"); break;
|
||||
case WIFI_DISCONNECT_REASON_IE_INVALID: reason += F("IE invalid"); break;
|
||||
case WIFI_DISCONNECT_REASON_MIC_FAILURE: reason += F("Mic failure"); break;
|
||||
case WIFI_DISCONNECT_REASON_4WAY_HANDSHAKE_TIMEOUT: reason += F("4way handshake timeout"); break;
|
||||
case WIFI_DISCONNECT_REASON_GROUP_KEY_UPDATE_TIMEOUT: reason += F("Group key update timeout"); break;
|
||||
case WIFI_DISCONNECT_REASON_IE_IN_4WAY_DIFFERS: reason += F("IE in 4way differs"); break;
|
||||
case WIFI_DISCONNECT_REASON_GROUP_CIPHER_INVALID: reason += F("Group cipher invalid"); break;
|
||||
case WIFI_DISCONNECT_REASON_PAIRWISE_CIPHER_INVALID: reason += F("Pairwise cipher invalid"); break;
|
||||
case WIFI_DISCONNECT_REASON_AKMP_INVALID: reason += F("AKMP invalid"); break;
|
||||
case WIFI_DISCONNECT_REASON_UNSUPP_RSN_IE_VERSION: reason += F("Unsupp RSN IE version"); break;
|
||||
case WIFI_DISCONNECT_REASON_INVALID_RSN_IE_CAP: reason += F("Invalid RSN IE cap"); break;
|
||||
case WIFI_DISCONNECT_REASON_802_1X_AUTH_FAILED: reason += F("802 1X auth failed"); break;
|
||||
case WIFI_DISCONNECT_REASON_CIPHER_SUITE_REJECTED: reason += F("Cipher suite rejected"); break;
|
||||
case WIFI_DISCONNECT_REASON_BEACON_TIMEOUT: reason += F("Beacon timeout"); break;
|
||||
case WIFI_DISCONNECT_REASON_NO_AP_FOUND: reason += F("No AP found"); break;
|
||||
case WIFI_DISCONNECT_REASON_AUTH_FAIL: reason += F("Auth fail"); break;
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_FAIL: reason += F("Assoc fail"); break;
|
||||
case WIFI_DISCONNECT_REASON_HANDSHAKE_TIMEOUT: reason += F("Handshake timeout"); break;
|
||||
default: reason += F("Unknown"); break;
|
||||
}
|
||||
return F("Unknown");
|
||||
return reason;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ void hardwareInit()
|
||||
break;
|
||||
}
|
||||
|
||||
if (Settings.Pin_Reset != -1)
|
||||
pinMode(Settings.Pin_Reset,INPUT_PULLUP);
|
||||
|
||||
// configure hardware pins according to eeprom settings.
|
||||
if (Settings.Pin_i2c_sda != -1)
|
||||
{
|
||||
@@ -97,3 +100,27 @@ void hardwareInit()
|
||||
|
||||
}
|
||||
|
||||
void checkResetFactoryPin(){
|
||||
static byte factoryResetCounter=0;
|
||||
if (Settings.Pin_Reset == -1)
|
||||
return;
|
||||
|
||||
if (digitalRead(Settings.Pin_Reset) == 0){ // active low reset pin
|
||||
factoryResetCounter++; // just count every second
|
||||
}
|
||||
else
|
||||
{ // reset pin released
|
||||
if (factoryResetCounter > 9) // factory reset and reboot
|
||||
ResetFactory();
|
||||
if (factoryResetCounter > 3) // normal reboot
|
||||
#if defined(ESP8266)
|
||||
ESP.reset();
|
||||
#endif
|
||||
#if defined(ESP32)
|
||||
ESP.restart();
|
||||
#endif
|
||||
|
||||
factoryResetCounter = 0; // count was < 3, reset counter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+278
-51
@@ -44,6 +44,10 @@ bool readyForSleep()
|
||||
{
|
||||
if (!isDeepSleepEnabled())
|
||||
return false;
|
||||
if (wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED) {
|
||||
// Allow 6 seconds to connect to WiFi
|
||||
return timeOutReached(timerAwakeFromDeepSleep + 6000);
|
||||
}
|
||||
return timeOutReached(timerAwakeFromDeepSleep + 1000 * Settings.deepSleep);
|
||||
}
|
||||
|
||||
@@ -328,7 +332,7 @@ void statusLED(boolean traffic)
|
||||
}
|
||||
}
|
||||
//AP mode is active
|
||||
else if (WifiIsAP())
|
||||
else if (WifiIsAP(WiFi.getMode()))
|
||||
{
|
||||
nStatusValue = ((millis()>>1) & PWMRANGE) - (PWMRANGE>>2); //ramp up for 2 sec, 3/4 luminosity
|
||||
}
|
||||
@@ -478,6 +482,22 @@ String BuildFixes()
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.Build < 20101)
|
||||
{
|
||||
Serial.println(F("Fix reset Pin"));
|
||||
Settings.Pin_Reset = -1;
|
||||
}
|
||||
if (Settings.Build < 20102) {
|
||||
// Settings were 'mangled' by using older version
|
||||
// Have to patch settings to make sure no bogus data is being used.
|
||||
Serial.println(F("Fix settings with uninitalized data or corrupted by switching between versions"));
|
||||
Settings.UseRTOSMultitasking = false;
|
||||
Settings.Pin_Reset = -1;
|
||||
Settings.SyslogFacility = DEFAULT_SYSLOG_FACILITY;
|
||||
Settings.StructSize = sizeof(Settings);
|
||||
}
|
||||
|
||||
Settings.Build = BUILD;
|
||||
return(SaveSettings());
|
||||
}
|
||||
@@ -690,25 +710,42 @@ String SaveSettings(void)
|
||||
{
|
||||
checkRAM(F("SaveSettings"));
|
||||
MD5Builder md5;
|
||||
uint8_t tmp_md5[16] = {0};
|
||||
String err;
|
||||
|
||||
Settings.StructSize = sizeof(struct SettingsStruct);
|
||||
|
||||
// FIXME @TD-er: As discussed in #1292, the CRC for the settings is now disabled.
|
||||
/*
|
||||
memcpy( Settings.ProgmemMd5, CRCValues.runTimeMD5, 16);
|
||||
md5.begin();
|
||||
md5.add((uint8_t *)&Settings, sizeof(Settings)-16);
|
||||
md5.calculate();
|
||||
md5.getBytes(Settings.md5);
|
||||
|
||||
String err;
|
||||
err=SaveToFile((char*)FILE_CONFIG, 0, (byte*)&Settings, sizeof(struct SettingsStruct));
|
||||
if (err.length())
|
||||
return(err);
|
||||
md5.getBytes(tmp_md5);
|
||||
if (memcmp(tmp_md5, Settings.md5, 16) != 0) {
|
||||
// Settings have changed, save to file.
|
||||
memcpy(Settings.md5, tmp_md5, 16);
|
||||
*/
|
||||
err=SaveToFile((char*)FILE_CONFIG, 0, (byte*)&Settings, sizeof(Settings));
|
||||
if (err.length())
|
||||
return(err);
|
||||
// }
|
||||
|
||||
memcpy( SecuritySettings.ProgmemMd5, CRCValues.runTimeMD5, 16);
|
||||
md5.begin();
|
||||
md5.add((uint8_t *)&SecuritySettings, sizeof(SecuritySettings)-16);
|
||||
md5.calculate();
|
||||
md5.getBytes(SecuritySettings.md5);
|
||||
err=SaveToFile((char*)FILE_SECURITY, 0, (byte*)&SecuritySettings, sizeof(struct SecurityStruct));
|
||||
|
||||
return (err);
|
||||
md5.getBytes(tmp_md5);
|
||||
if (memcmp(tmp_md5, SecuritySettings.md5, 16) != 0) {
|
||||
// Settings have changed, save to file.
|
||||
memcpy(SecuritySettings.md5, tmp_md5, 16);
|
||||
err=SaveToFile((char*)FILE_SECURITY, 0, (byte*)&SecuritySettings, sizeof(SecuritySettings));
|
||||
if (WifiIsAP(WiFi.getMode())) {
|
||||
// Security settings are saved, may be update of WiFi settings or hostname.
|
||||
wifiSetupConnect = true;
|
||||
}
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
/********************************************************************************************\
|
||||
@@ -725,10 +762,14 @@ String LoadSettings()
|
||||
if (err.length())
|
||||
return(err);
|
||||
|
||||
md5.begin();
|
||||
md5.add((uint8_t *)&Settings, sizeof(Settings)-16);
|
||||
md5.calculate();
|
||||
md5.getBytes(calculatedMd5);
|
||||
// FIXME @TD-er: As discussed in #1292, the CRC for the settings is now disabled.
|
||||
/*
|
||||
if (Settings.StructSize > 16) {
|
||||
md5.begin();
|
||||
md5.add((uint8_t *)&Settings, Settings.StructSize -16);
|
||||
md5.calculate();
|
||||
md5.getBytes(calculatedMd5);
|
||||
}
|
||||
if (memcmp (calculatedMd5, Settings.md5,16)==0){
|
||||
addLog(LOG_LEVEL_INFO, F("CRC : Settings CRC ...OK"));
|
||||
if (memcmp(Settings.ProgmemMd5, CRCValues.runTimeMD5, 16)!=0)
|
||||
@@ -737,7 +778,7 @@ String LoadSettings()
|
||||
else{
|
||||
addLog(LOG_LEVEL_ERROR, F("CRC : Settings CRC ...FAIL"));
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
err=LoadFromFile((char*)FILE_SECURITY, 0, (byte*)&SecuritySettings, sizeof( SecurityStruct));
|
||||
md5.begin();
|
||||
@@ -752,6 +793,7 @@ String LoadSettings()
|
||||
else{
|
||||
addLog(LOG_LEVEL_ERROR, F("CRC : SecuritySettings CRC ...FAIL"));
|
||||
}
|
||||
setUseStaticIP(useStaticIP());
|
||||
return(err);
|
||||
}
|
||||
|
||||
@@ -1086,11 +1128,12 @@ void ResetFactory(void)
|
||||
SecuritySettings.IPblockLevel = DEFAULT_IP_BLOCK_LEVEL;
|
||||
|
||||
Settings.Delay = DEFAULT_DELAY;
|
||||
Settings.Pin_i2c_sda = 4;
|
||||
Settings.Pin_i2c_scl = 5;
|
||||
Settings.Pin_status_led = -1;
|
||||
Settings.Pin_status_led_Inversed = true;
|
||||
Settings.Pin_i2c_sda = DEFAULT_PIN_I2C_SDA;
|
||||
Settings.Pin_i2c_scl = DEFAULT_PIN_I2C_SCL;
|
||||
Settings.Pin_status_led = DEFAULT_PIN_STATUS_LED;
|
||||
Settings.Pin_status_led_Inversed = DEFAULT_PIN_STATUS_LED_INVERSED;
|
||||
Settings.Pin_sd_cs = -1;
|
||||
Settings.Pin_Reset = -1;
|
||||
Settings.Protocol[0] = DEFAULT_PROTOCOL;
|
||||
strcpy_P(Settings.Name, PSTR(DEFAULT_NAME));
|
||||
Settings.deepSleep = false;
|
||||
@@ -1124,6 +1167,7 @@ void ResetFactory(void)
|
||||
|
||||
Settings.SyslogLevel = DEFAULT_SYSLOG_LEVEL;
|
||||
Settings.SerialLogLevel = DEFAULT_SERIAL_LOG_LEVEL;
|
||||
Settings.SyslogFacility = DEFAULT_SYSLOG_FACILITY;
|
||||
Settings.WebLogLevel = DEFAULT_WEB_LOG_LEVEL;
|
||||
Settings.SDLogLevel = DEFAULT_SD_LOG_LEVEL;
|
||||
Settings.UseValueLogger = DEFAULT_USE_SD_LOG;
|
||||
@@ -1164,7 +1208,7 @@ void ResetFactory(void)
|
||||
delay(1000);
|
||||
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
|
||||
intent_to_reboot = true;
|
||||
WiFi.disconnect(); // this will store empty ssid/wpa into sdk storage
|
||||
WifiDisconnect(); // this will store empty ssid/wpa into sdk storage
|
||||
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
|
||||
#if defined(ESP8266)
|
||||
ESP.reset();
|
||||
@@ -1275,6 +1319,7 @@ void initLog()
|
||||
//make sure addLog doesnt do any stuff before initalisation of Settings is complete.
|
||||
Settings.UseSerial=true;
|
||||
Settings.SyslogLevel=0;
|
||||
Settings.SyslogFacility=0;
|
||||
Settings.SerialLogLevel=2; //logging during initialisation
|
||||
Settings.WebLogLevel=2;
|
||||
Settings.SDLogLevel=0;
|
||||
@@ -1309,6 +1354,8 @@ boolean loglevelActiveFor(byte destination, byte logLevel) {
|
||||
case LOG_TO_SERIAL: {
|
||||
if (!SerialAvailableForWrite()) return false;
|
||||
logLevelSettings = Settings.SerialLogLevel;
|
||||
if (wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED)
|
||||
logLevelSettings = 2;
|
||||
break;
|
||||
}
|
||||
case LOG_TO_SYSLOG: {
|
||||
@@ -1337,10 +1384,12 @@ boolean loglevelActive(byte logLevel, byte logLevelSettings) {
|
||||
void addLog(byte logLevel, const char *line)
|
||||
{
|
||||
if (loglevelActiveFor(LOG_TO_SERIAL, logLevel)) {
|
||||
Serial.print(millis());
|
||||
Serial.print(F(" : "));
|
||||
Serial.println(line);
|
||||
}
|
||||
if (loglevelActiveFor(LOG_TO_SYSLOG, logLevel)) {
|
||||
syslog(line);
|
||||
syslog(logLevel, line);
|
||||
}
|
||||
if (loglevelActiveFor(LOG_TO_WEBLOG, logLevel)) {
|
||||
Logging.add(line);
|
||||
@@ -1552,26 +1601,167 @@ String parseTemplate(String &tmpString, byte lineSize)
|
||||
else
|
||||
value = toString(UserVar[y * VARS_PER_TASK + z], ExtraTaskSettings.TaskDeviceValueDecimals[z]);
|
||||
|
||||
int oidx;
|
||||
if ((oidx = valueFormat.indexOf('O')) >= 0) // Output
|
||||
// start changes by giig1967g - 2018-04-20
|
||||
// Syntax: [task#value#transformation#justification]
|
||||
// valueFormat="transformation#justification"
|
||||
if (valueFormat.length() > 0) //do the checks only if a Format is defined to optimize loop
|
||||
{
|
||||
valueFormat.remove(oidx);
|
||||
oidx = valueFormat.indexOf('!'); // inverted or active low
|
||||
float val = value.toFloat();
|
||||
if (oidx >= 0) {
|
||||
valueFormat.remove(oidx);
|
||||
value = val == 0 ? " ON" : "OFF";
|
||||
} else {
|
||||
value = val == 0 ? "OFF" : " ON";
|
||||
String valueJust = "";
|
||||
|
||||
hashtagIndex = valueFormat.indexOf('#');
|
||||
if (hashtagIndex >= 0)
|
||||
{
|
||||
valueJust = valueFormat.substring(hashtagIndex + 1); //Justification part
|
||||
valueFormat = valueFormat.substring(0, hashtagIndex); //Transformation part
|
||||
}
|
||||
|
||||
// valueFormat="transformation"
|
||||
// valueJust="justification"
|
||||
if (valueFormat.length() > 0) //do the checks only if a Format is defined to optimize loop
|
||||
{
|
||||
const int val = value == "0" ? 0 : 1; //to be used for GPIO status (0 or 1)
|
||||
const float valFloat = value.toFloat();
|
||||
|
||||
String tempValueFormat = valueFormat;
|
||||
const int tempValueFormatLength = tempValueFormat.length();
|
||||
const int invertedIndex = tempValueFormat.indexOf('!');
|
||||
const bool inverted = invertedIndex >= 0 ? 1 : 0;
|
||||
if (inverted)
|
||||
tempValueFormat.remove(invertedIndex,1);
|
||||
|
||||
const int rightJustifyIndex = tempValueFormat.indexOf('R');
|
||||
const bool rightJustify = rightJustifyIndex >= 0 ? 1 : 0;
|
||||
if (rightJustify)
|
||||
tempValueFormat.remove(rightJustifyIndex,1);
|
||||
|
||||
//Check Transformation syntax
|
||||
if (tempValueFormatLength > 0)
|
||||
{
|
||||
switch (tempValueFormat[0])
|
||||
{
|
||||
case 'V': //value = value without transformations
|
||||
break;
|
||||
case 'O':
|
||||
value = val == inverted ? "OFF" : " ON"; //(equivalent to XOR operator)
|
||||
break;
|
||||
case 'C':
|
||||
value = val == inverted ? "CLOSE" : " OPEN";
|
||||
break;
|
||||
case 'U':
|
||||
value = val == inverted ? "DOWN" : " UP";
|
||||
break;
|
||||
case 'u':
|
||||
value = val == inverted ? "D" : "U";
|
||||
break;
|
||||
case 'Y':
|
||||
value = val == inverted ? " NO" : "YES";
|
||||
break;
|
||||
case 'y':
|
||||
value = val == inverted ? "N" : "Y";
|
||||
break;
|
||||
case 'X':
|
||||
value = val == inverted ? "O" : "X";
|
||||
break;
|
||||
case 'I':
|
||||
value = val == inverted ? "OUT" : " IN";
|
||||
break;
|
||||
case 'Z' :// return "0" or "1"
|
||||
value = val == inverted ? "0" : "1";
|
||||
break;
|
||||
case 'D' ://Dx.y min 'x' digits zero filled & 'y' decimal fixed digits
|
||||
int x;
|
||||
int y;
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
switch (tempValueFormatLength)
|
||||
{
|
||||
case 2: //Dx
|
||||
if (isDigit(tempValueFormat[1]))
|
||||
{
|
||||
x = (int)tempValueFormat[1]-'0';
|
||||
}
|
||||
break;
|
||||
case 3: //D.y
|
||||
if (tempValueFormat[1]=='.' && isDigit(tempValueFormat[2]))
|
||||
{
|
||||
y = (int)tempValueFormat[2]-'0';
|
||||
}
|
||||
break;
|
||||
case 4: //Dx.y
|
||||
if (isDigit(tempValueFormat[1]) && tempValueFormat[2]=='.' && isDigit(tempValueFormat[3]))
|
||||
{
|
||||
x = (int)tempValueFormat[1]-'0';
|
||||
y = (int)tempValueFormat[3]-'0';
|
||||
}
|
||||
break;
|
||||
case 1: //D
|
||||
default: //any other combination x=0; y=0;
|
||||
break;
|
||||
}
|
||||
value = toString(valFloat,y);
|
||||
int indexDot;
|
||||
indexDot = value.indexOf('.') > 0 ? value.indexOf('.') : value.length();
|
||||
for (byte f = 0; f < (x - indexDot); f++)
|
||||
value = "0" + value;
|
||||
break;
|
||||
case 'F' :// FLOOR (round down)
|
||||
value = (int)floorf(valFloat);
|
||||
break;
|
||||
case 'E' :// CEILING (round up)
|
||||
value = (int)ceilf(valFloat);
|
||||
break;
|
||||
default:
|
||||
value = "ERR";
|
||||
break;
|
||||
}
|
||||
|
||||
// Check Justification syntax
|
||||
const int valueJustLength = valueJust.length();
|
||||
if (valueJustLength > 0) //do the checks only if a Justification is defined to optimize loop
|
||||
{
|
||||
value.trim(); //remove right justification spaces for backward compatibility
|
||||
switch (valueJust[0])
|
||||
{
|
||||
case 'P' :// Prefix Fill with n spaces: Pn
|
||||
if (valueJustLength > 1)
|
||||
{
|
||||
if (isDigit(valueJust[1])) //Check Pn where n is between 0 and 9
|
||||
{
|
||||
int filler = valueJust[1] - value.length() - '0' ; //char '0' = 48; char '9' = 58
|
||||
for (byte f = 0; f < filler; f++)
|
||||
newString += " ";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'S' :// Suffix Fill with n spaces: Sn
|
||||
if (valueJustLength > 1)
|
||||
{
|
||||
if (isDigit(valueJust[1])) //Check Sn where n is between 0 and 9
|
||||
{
|
||||
int filler = valueJust[1] - value.length() - '0' ; //48
|
||||
for (byte f = 0; f < filler; f++)
|
||||
value += " ";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
newString += "ERR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rightJustify)
|
||||
{
|
||||
int filler = lineSize - newString.length() - value.length() - tmpString.length() ;
|
||||
for (byte f = 0; f < filler; f++)
|
||||
newString += " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//end of changes by giig1967g - 2018-04-18
|
||||
|
||||
if (valueFormat == "R")
|
||||
{
|
||||
int filler = lineSize - newString.length() - value.length() - tmpString.length() ;
|
||||
for (byte f = 0; f < filler; f++)
|
||||
newString += " ";
|
||||
}
|
||||
newString += String(value);
|
||||
break;
|
||||
}
|
||||
@@ -1977,6 +2167,7 @@ String rulesProcessingFile(String fileName, String& event)
|
||||
boolean conditional = false;
|
||||
boolean condition = false;
|
||||
boolean ifBranche = false;
|
||||
boolean ifBrancheJustMatch = false;
|
||||
|
||||
byte buf[RULES_BUFFER_SIZE];
|
||||
int len = 0;
|
||||
@@ -2070,25 +2261,57 @@ String rulesProcessingFile(String fileName, String& event)
|
||||
if (match) // rule matched for one action or a block of actions
|
||||
{
|
||||
int split = lcAction.indexOf("if "); // check for optional "if" condition
|
||||
if (split != -1)
|
||||
boolean elseif = lcAction.startsWith("elseif ");
|
||||
if (elseif == false && split != -1)
|
||||
{
|
||||
conditional = true;
|
||||
String check = lcAction.substring(split + 3);
|
||||
condition = conditionMatchExtended(check);
|
||||
log = F("[if ");
|
||||
log += check;
|
||||
log += "]=";
|
||||
condition = ifBrancheJustMatch == false && conditionMatchExtended(check);
|
||||
if(condition == true)
|
||||
{
|
||||
ifBrancheJustMatch = true;
|
||||
}
|
||||
ifBranche = true;
|
||||
isCommand = false;
|
||||
log += condition ? F("true") : F("false");
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
|
||||
if(elseif)
|
||||
{
|
||||
String check = lcAction.substring(7);
|
||||
log = F("[elseif ");
|
||||
log += check;
|
||||
log += "]=";
|
||||
condition = ifBrancheJustMatch == false && conditionMatchExtended(check);
|
||||
if(condition == true)
|
||||
{
|
||||
ifBrancheJustMatch = true;
|
||||
}
|
||||
ifBranche = true;
|
||||
isCommand = false;
|
||||
log += condition ? F("true") : F("false");
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
|
||||
if (lcAction == "else") // in case of an "else" block of actions, set ifBranche to false
|
||||
{
|
||||
ifBranche = false;
|
||||
isCommand = false;
|
||||
log = F("else = ");
|
||||
log += (conditional && (condition == ifBranche)) ? F("true") : F("false");
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
|
||||
if (lcAction == "endif") // conditional block ends here
|
||||
{
|
||||
conditional = false;
|
||||
isCommand = false;
|
||||
ifBranche = false;
|
||||
ifBrancheJustMatch = false;
|
||||
}
|
||||
|
||||
// process the action if it's a command and unconditional, or conditional and the condition matches the if or else block.
|
||||
@@ -2138,7 +2361,7 @@ String rulesProcessingFile(String fileName, String& event)
|
||||
|
||||
nestingLevel--;
|
||||
checkRAM(F("rulesProcessingFile2"));
|
||||
return (String());
|
||||
return (F(""));
|
||||
}
|
||||
|
||||
|
||||
@@ -2405,11 +2628,11 @@ void rulesTimers()
|
||||
{
|
||||
for (byte x = 0; x < RULES_TIMER_MAX; x++)
|
||||
{
|
||||
if (RulesTimer[x] != 0L) // timer active?
|
||||
if (!RulesTimer[x].paused && RulesTimer[x].timestamp != 0L) // timer active?
|
||||
{
|
||||
if (timeOutReached(RulesTimer[x])) // timer finished?
|
||||
if (timeOutReached(RulesTimer[x].timestamp)) // timer finished?
|
||||
{
|
||||
RulesTimer[x] = 0L; // turn off this timer
|
||||
RulesTimer[x].timestamp = 0L; // turn off this timer
|
||||
String event = F("Rules#Timer=");
|
||||
event += x + 1;
|
||||
rulesProcessing(event);
|
||||
@@ -2601,7 +2824,7 @@ void checkRAM( String &a ) {
|
||||
}
|
||||
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
//#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define isdigit(n) (n >= '0' && n <= '9')
|
||||
|
||||
@@ -2609,11 +2832,15 @@ void checkRAM( String &a ) {
|
||||
Generate a tone of specified frequency on pin
|
||||
\*********************************************************************************************/
|
||||
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
|
||||
analogWriteFreq(frequency);
|
||||
//NOTE: analogwrite reserves IRAM and uninitalized ram.
|
||||
analogWrite(_pin,100);
|
||||
delay(duration);
|
||||
analogWrite(_pin,0);
|
||||
#ifdef ESP32
|
||||
delay(duration);
|
||||
#else
|
||||
analogWriteFreq(frequency);
|
||||
//NOTE: analogwrite reserves IRAM and uninitalized ram.
|
||||
analogWrite(_pin,100);
|
||||
delay(duration);
|
||||
analogWrite(_pin,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************************************\
|
||||
@@ -2775,7 +3002,7 @@ void play_rtttl(uint8_t _pin, const char *p )
|
||||
checkRAM(F("play_rtttl2"));
|
||||
}
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
|
||||
#ifdef FEATURE_ARDUINO_OTA
|
||||
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
|
||||
# ifndef MODBUS_H
|
||||
# define MODBUS_H
|
||||
|
||||
enum MODBUS_states_t {MODBUS_IDLE, MODBUS_RECEIVE, MODBUS_RECEIVE_PAYLOAD};
|
||||
enum MODBUS_registerTypes_t {signed16, unsigned16, signed32, unsigned32, signed64, unsigned64};
|
||||
|
||||
#define MODBUS_FUNCTION_READ 4
|
||||
|
||||
class Modbus
|
||||
{
|
||||
public:
|
||||
Modbus(void);
|
||||
bool handle();
|
||||
bool begin(uint8_t function, uint8_t ModbusID, uint16_t ModbusRegister, MODBUS_registerTypes_t type, char* IPaddress);
|
||||
double read() {
|
||||
if (resultReceived) {
|
||||
resultReceived = false;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
};
|
||||
bool available() {
|
||||
return resultReceived;
|
||||
};
|
||||
unsigned int getReadErrors() {
|
||||
return errcnt;
|
||||
};
|
||||
void resetReadErrors() {
|
||||
errcnt = 0;
|
||||
};
|
||||
void stop() {
|
||||
TXRXstate = MODBUS_IDLE;
|
||||
handle();
|
||||
};
|
||||
bool tryRead (uint8_t ModbusID, uint16_t M_register, MODBUS_registerTypes_t type, char* IPaddress, double &result);
|
||||
|
||||
private:
|
||||
WiFiClient *ModbusClient; // pointer to tcp client
|
||||
unsigned int errcnt;
|
||||
char sendBuffer[12] = {0, 1, 0, 0, 0, 6, 0x7e, 4, 0x9d, 7, 0, 1};
|
||||
String LogString = ""; // for debug logging
|
||||
unsigned long timeout; // send and read timeout
|
||||
MODBUS_states_t TXRXstate;// state for handle() state machine
|
||||
unsigned int RXavailable;
|
||||
unsigned int payLoad; // number of bytes to receive as payload. Payload may come as seperate frame.
|
||||
bool hasTimeout();
|
||||
MODBUS_registerTypes_t incomingValue; // how to interpret the incoming value
|
||||
double result; // incoming value, converted to double
|
||||
bool resultReceived; // incoming value is valid ?
|
||||
bool isBusy(void) {
|
||||
return TXRXstate != MODBUS_IDLE;
|
||||
};
|
||||
uint16_t currentRegister;
|
||||
uint8_t currentFunction;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Modbus::Modbus() : ModbusClient(nullptr), errcnt(0), timeout(0),
|
||||
TXRXstate(MODBUS_IDLE), RXavailable(0), payLoad(0) {}
|
||||
|
||||
bool Modbus::begin(uint8_t function, uint8_t ModbusID, uint16_t ModbusRegister, MODBUS_registerTypes_t type, char* IPaddress)
|
||||
{
|
||||
currentRegister = ModbusRegister;
|
||||
currentFunction = function;
|
||||
incomingValue = type;
|
||||
resultReceived = false;
|
||||
ModbusClient = new WiFiClient();
|
||||
ModbusClient->setNoDelay(true);
|
||||
ModbusClient->setTimeout(200);
|
||||
timeout = millis();
|
||||
ModbusClient->flush();
|
||||
|
||||
if (ModbusClient->connected()) {
|
||||
LogString += F(" already connected. ");
|
||||
} else {
|
||||
LogString += F("connect: "); LogString += IPaddress;
|
||||
if ( !ModbusClient->connect(IPaddress, 502)) {
|
||||
LogString += F(" fail. ");
|
||||
TXRXstate = MODBUS_IDLE;
|
||||
errcnt++;
|
||||
if (LogString.length() > 1 ) addLog(LOG_LEVEL_DEBUG, LogString);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
LogString += F(" OK, sending read request: ");
|
||||
|
||||
sendBuffer[6] = ModbusID ;
|
||||
sendBuffer[7] = function;
|
||||
sendBuffer[8] = (ModbusRegister >> 8) ;
|
||||
sendBuffer[9] = (ModbusRegister & 0x00ff) ;
|
||||
if ((incomingValue == signed64) || (incomingValue == unsigned64))
|
||||
sendBuffer[11] = 4;
|
||||
if ((incomingValue == signed32) || (incomingValue == unsigned32))
|
||||
sendBuffer[11] = 2;
|
||||
if ((incomingValue == signed16) || (incomingValue == unsigned16))
|
||||
sendBuffer[11] = 1;
|
||||
ModbusClient->flush();
|
||||
ModbusClient->write(&sendBuffer[0], sizeof(sendBuffer));
|
||||
for (unsigned int i = 0; i < sizeof(sendBuffer); i++) {
|
||||
LogString += ((unsigned int)(sendBuffer[i]));
|
||||
LogString += (" ");
|
||||
}
|
||||
TXRXstate = MODBUS_RECEIVE;
|
||||
if (LogString.length() > 1 ) addLog(LOG_LEVEL_DEBUG, LogString);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Modbus::handle() {
|
||||
unsigned int RXavailable = 0;
|
||||
LogString = "";
|
||||
int64_t rxValue = 0;
|
||||
switch ( TXRXstate ) {
|
||||
|
||||
case MODBUS_IDLE:
|
||||
// clean up;
|
||||
if (ModbusClient) {
|
||||
ModbusClient->flush();
|
||||
ModbusClient->stop();
|
||||
delete (ModbusClient);
|
||||
delay(1);
|
||||
ModbusClient = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_RECEIVE:
|
||||
if (hasTimeout()) break;
|
||||
if (ModbusClient->available() < 9) break;
|
||||
|
||||
LogString += F("reading bytes: ");
|
||||
for (int a = 0; a < 9; a++) {
|
||||
payLoad = ModbusClient->read();
|
||||
LogString += (payLoad); LogString += F(" ");
|
||||
}
|
||||
LogString += F("> ");
|
||||
if (payLoad > 8) {
|
||||
LogString += "Payload too large !? ";
|
||||
errcnt++;
|
||||
TXRXstate = MODBUS_IDLE;
|
||||
}
|
||||
|
||||
case MODBUS_RECEIVE_PAYLOAD:
|
||||
if (hasTimeout()) break;
|
||||
RXavailable = ModbusClient->available();
|
||||
if (payLoad != RXavailable) {
|
||||
TXRXstate = MODBUS_RECEIVE_PAYLOAD;
|
||||
break;
|
||||
}
|
||||
for (unsigned int i = 0; i < RXavailable; i++) {
|
||||
rxValue = rxValue << 8;
|
||||
char a = ModbusClient->read();
|
||||
rxValue = rxValue | a;
|
||||
LogString += ((int)a); LogString += (" ");
|
||||
}
|
||||
switch (incomingValue) {
|
||||
case signed16:
|
||||
result = (int16_t) rxValue;
|
||||
break;
|
||||
case unsigned16:
|
||||
result = (uint16_t) rxValue;
|
||||
break;
|
||||
case signed32:
|
||||
result = (int32_t) rxValue;
|
||||
break;
|
||||
case unsigned32:
|
||||
result = (uint32_t) rxValue;
|
||||
break;
|
||||
case signed64:
|
||||
result = (int64_t) rxValue;
|
||||
break;
|
||||
case unsigned64:
|
||||
result = (uint64_t) rxValue;
|
||||
break;
|
||||
}
|
||||
|
||||
LogString += "value: "; LogString += result;
|
||||
//if ((Settings.UseNTP) && (hour() == 0)) errcnt = 0;
|
||||
|
||||
TXRXstate = MODBUS_IDLE;
|
||||
|
||||
resultReceived = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
LogString += F("default. ");
|
||||
TXRXstate = MODBUS_IDLE;
|
||||
break;
|
||||
|
||||
}
|
||||
if (LogString.length() > 1 ) addLog(LOG_LEVEL_DEBUG, LogString);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Modbus::hasTimeout()
|
||||
{
|
||||
if ( (millis() - timeout) > 10000) { // too many bytes or timeout
|
||||
LogString += F("Modbus RX timeout. "); LogString += String(ModbusClient->available());
|
||||
errcnt++;
|
||||
TXRXstate = MODBUS_IDLE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// tryread can be called in a round robin fashion. It will initiate a read if Modbus is idle and update the result once it is available.
|
||||
// subsequent calls (if Modbus is busy etc. ) will return false and not update the result.
|
||||
// Use to read multiple values non blocking in an re-entrant function. Not tested yet.
|
||||
bool Modbus::tryRead (uint8_t ModbusID, uint16_t M_register, MODBUS_registerTypes_t type, char* IPaddress, double &result) {
|
||||
if (isBusy()) return false; // not done yet
|
||||
if (available()) {
|
||||
if ((currentFunction == MODBUS_FUNCTION_READ ) && (currentRegister == M_register)) {
|
||||
result = read(); // result belongs to this request.
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
begin(MODBUS_FUNCTION_READ, ModbusID, M_register, type, IPaddress); // idle and no result -> begin read request
|
||||
}
|
||||
return false;
|
||||
}
|
||||
+25
-8
@@ -2,15 +2,15 @@
|
||||
// Syslog
|
||||
// UDP system messaging
|
||||
// SSDP
|
||||
#if LWIP_VERSION_MAJOR == 2
|
||||
#define IP2STR(addr) (uint8_t)((uint32_t)addr & 0xFF), (uint8_t)(((uint32_t)addr >> 8) & 0xFF), (uint8_t)(((uint32_t)addr >> 16) & 0xFF), (uint8_t)(((uint32_t)addr >> 24) & 0xFF)
|
||||
#endif
|
||||
// #if LWIP_VERSION_MAJOR == 2
|
||||
#define IPADDR2STR(addr) (uint8_t)((uint32_t)addr & 0xFF), (uint8_t)(((uint32_t)addr >> 8) & 0xFF), (uint8_t)(((uint32_t)addr >> 16) & 0xFF), (uint8_t)(((uint32_t)addr >> 24) & 0xFF)
|
||||
// #endif
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
Syslog client
|
||||
\*********************************************************************************************/
|
||||
void syslog(const char *message)
|
||||
void syslog(byte logLevel, const char *message)
|
||||
{
|
||||
if (Settings.Syslog_IP[0] != 0 && wifiStatus == ESPEASY_WIFI_SERVICES_INITIALIZED)
|
||||
{
|
||||
@@ -18,10 +18,18 @@ void syslog(const char *message)
|
||||
portUDP.beginPacket(broadcastIP, 514);
|
||||
char str[256];
|
||||
str[0] = 0;
|
||||
byte prio = Settings.SyslogFacility * 8;
|
||||
if ( logLevel == LOG_LEVEL_ERROR )
|
||||
prio += 3; // syslog error
|
||||
else if ( logLevel == LOG_LEVEL_INFO )
|
||||
prio += 5; // syslog notice
|
||||
else
|
||||
prio += 7;
|
||||
|
||||
// An RFC3164 compliant message must be formated like : "<PRIO>[TimeStamp ]Hostname TaskName: Message"
|
||||
|
||||
// Using Settings.Name as the Hostname (Hostname must NOT content space)
|
||||
snprintf_P(str, sizeof(str), PSTR("<7>%s EspEasy: %s"), Settings.Name, message);
|
||||
snprintf_P(str, sizeof(str), PSTR("<%u>%s EspEasy: %s"), prio, Settings.Name, message);
|
||||
|
||||
// Using Setting.Unit to build a Hostname
|
||||
//snprintf_P(str, sizeof(str), PSTR("<7>EspEasy_%u ESP: %s"), Settings.Unit, message);
|
||||
@@ -434,7 +442,7 @@ void SSDP_send(byte method) {
|
||||
SSDP_INTERVAL,
|
||||
Settings.Build,
|
||||
uuid,
|
||||
IP2STR(&ip)
|
||||
IPADDR2STR(&ip)
|
||||
);
|
||||
|
||||
_server->append(buffer, len);
|
||||
@@ -599,7 +607,7 @@ bool WiFiConnected(uint32_t timeout_ms) {
|
||||
// Apparently something needs network, perform check to see if it is ready now.
|
||||
// if (!tryConnectWiFi())
|
||||
// return false;
|
||||
while (wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED) {
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
if (timeOutReached(timer)) {
|
||||
return false;
|
||||
}
|
||||
@@ -609,6 +617,7 @@ bool WiFiConnected(uint32_t timeout_ms) {
|
||||
}
|
||||
|
||||
bool hostReachable(const IPAddress& ip) {
|
||||
if (WiFi.status() != WL_CONNECTED) return false;
|
||||
// Only do 1 ping at a time to return early
|
||||
byte retry = 3;
|
||||
while (retry > 0) {
|
||||
@@ -624,13 +633,21 @@ bool hostReachable(const IPAddress& ip) {
|
||||
String log = F("Host unreachable: ");
|
||||
log += formatIP(ip);
|
||||
addLog(LOG_LEVEL_ERROR, log);
|
||||
if (ip[1] == 0 && ip[2] == 0 && ip[3] == 0) {
|
||||
// Work-around to fix connected but not able to communicate.
|
||||
addLog(LOG_LEVEL_ERROR, F("Wifi : Detected strange behavior, reconnect wifi."));
|
||||
WifiDisconnect();
|
||||
}
|
||||
logConnectionStatus();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hostReachable(const String& hostname) {
|
||||
if (WiFi.status() != WL_CONNECTED) return false;
|
||||
IPAddress remote_addr;
|
||||
if (WiFi.hostByName(hostname.c_str(), remote_addr))
|
||||
if (WiFi.hostByName(hostname.c_str(), remote_addr)) {
|
||||
return hostReachable(remote_addr);
|
||||
}
|
||||
String log = F("Hostname cannot be resolved: ");
|
||||
log += hostname;
|
||||
addLog(LOG_LEVEL_ERROR, log);
|
||||
|
||||
@@ -54,6 +54,12 @@ void formatMAC(const uint8_t* mac, char (&strMAC)[20]) {
|
||||
sprintf_P(strMAC, PSTR("%02X:%02X:%02X:%02X:%02X:%02X"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
String formatMAC(const uint8_t* mac) {
|
||||
char str[20];
|
||||
formatMAC(mac, str);
|
||||
return String(str);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
Workaround for removing trailing white space when String() converts a float with 0 decimals
|
||||
\*********************************************************************************************/
|
||||
@@ -280,6 +286,8 @@ void parseSystemVariables(String& s, boolean useURLencode)
|
||||
SMART_REPL(F("%ip%"),WiFi.localIP().toString())
|
||||
SMART_REPL(F("%rssi%"), String((wifiStatus == ESPEASY_WIFI_DISCONNECTED) ? 0 : WiFi.RSSI()))
|
||||
SMART_REPL(F("%ssid%"), (wifiStatus == ESPEASY_WIFI_DISCONNECTED) ? F("--") : WiFi.SSID())
|
||||
SMART_REPL(F("%bssid%"), (wifiStatus == ESPEASY_WIFI_DISCONNECTED) ? F("00:00:00:00:00:00") : WiFi.BSSIDstr())
|
||||
SMART_REPL(F("%wi_ch%"), String((wifiStatus == ESPEASY_WIFI_DISCONNECTED) ? 0 : WiFi.channel()))
|
||||
SMART_REPL(F("%unit%"), String(Settings.Unit))
|
||||
SMART_REPL(F("%mac%"), String(WiFi.macAddress()))
|
||||
#if defined(ESP8266)
|
||||
@@ -288,6 +296,7 @@ void parseSystemVariables(String& s, boolean useURLencode)
|
||||
|
||||
if (s.indexOf(F("%sys")) != -1) {
|
||||
SMART_REPL(F("%sysload%"), String(100 - (100 * loopCounterLast / loopCounterMax)))
|
||||
SMART_REPL(F("%sysheap%"), String(ESP.getFreeHeap()));
|
||||
SMART_REPL(F("%systm_hm%"), getTimeString(':', false))
|
||||
SMART_REPL(F("%systm_hm_am%"), getTimeString_ampm(':', false))
|
||||
SMART_REPL(F("%systime%"), getTimeString(':'))
|
||||
@@ -300,6 +309,7 @@ void parseSystemVariables(String& s, boolean useURLencode)
|
||||
SMART_REPL_TIME(F("%syshour%"), PSTR("%02d"), hour())
|
||||
SMART_REPL_TIME(F("%sysmin%"), PSTR("%02d"), minute())
|
||||
SMART_REPL_TIME(F("%syssec%"),PSTR("%02d"), second())
|
||||
SMART_REPL_TIME(F("%syssec_d%"),PSTR("%d"), ((hour()*60) + minute())*60 + second());
|
||||
SMART_REPL_TIME(F("%sysday%"), PSTR("%02d"), day())
|
||||
SMART_REPL_TIME(F("%sysmonth%"),PSTR("%02d"), month())
|
||||
SMART_REPL_TIME(F("%sysyear%"), PSTR("%04d"), year())
|
||||
|
||||
+8
-4
@@ -202,7 +202,7 @@ unsigned long getNtpTime()
|
||||
return 0;
|
||||
}
|
||||
IPAddress timeServerIP;
|
||||
String log = F("NTP : NTP send to ");
|
||||
String log = F("NTP : NTP host ");
|
||||
if (Settings.NTPHost[0] != 0) {
|
||||
WiFi.hostByName(Settings.NTPHost, timeServerIP);
|
||||
log += Settings.NTPHost;
|
||||
@@ -219,7 +219,13 @@ unsigned long getNtpTime()
|
||||
nextSyncTime = sysTime + 5;
|
||||
}
|
||||
|
||||
log += F(" (");
|
||||
log += timeServerIP.toString();
|
||||
log += F(")");
|
||||
|
||||
if (!hostReachable(timeServerIP)) {
|
||||
log += F(" unreachable");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -229,9 +235,7 @@ unsigned long getNtpTime()
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
|
||||
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
|
||||
|
||||
log += F(" (");
|
||||
log += timeServerIP.toString();
|
||||
log += F(")");
|
||||
log += F(" queried");
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
|
||||
while (udp.parsePacket() > 0) ; // discard any previously received packets
|
||||
|
||||
+949
-783
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C001
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 001: Domoticz HTTP ######################################
|
||||
//#######################################################################################################
|
||||
@@ -165,3 +166,4 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C002
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 002: Domoticz MQTT ######################################
|
||||
//#######################################################################################################
|
||||
@@ -209,3 +210,4 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C003
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 003: Nodo Telnet #######################################
|
||||
//#######################################################################################################
|
||||
@@ -107,3 +108,4 @@ boolean CPlugin_003(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C004
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 004: ThingSpeak #########################################
|
||||
//#######################################################################################################
|
||||
@@ -127,3 +128,4 @@ boolean CPlugin_004(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C005
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 005: OpenHAB MQTT #######################################
|
||||
//#######################################################################################################
|
||||
@@ -122,3 +123,4 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C006
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 006: PiDome MQTT ########################################
|
||||
//#######################################################################################################
|
||||
@@ -109,3 +110,4 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C007
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 007: Emoncms ############################################
|
||||
//#######################################################################################################
|
||||
@@ -122,3 +123,4 @@ boolean CPlugin_007(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C008
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 008: Generic HTTP #######################################
|
||||
//#######################################################################################################
|
||||
@@ -151,3 +152,4 @@ boolean HTTPSend(struct EventStruct *event, byte varIndex, float value, unsigned
|
||||
|
||||
return(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C009
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 009: FHEM HTTP ##########################################
|
||||
//#######################################################################################################
|
||||
@@ -197,3 +198,4 @@ void FHEMHTTPsend(String & url, String & buffer, byte index)
|
||||
client.flush();
|
||||
client.stop();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C010
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 010: Generic UDP ########################################
|
||||
//#######################################################################################################
|
||||
@@ -97,3 +98,4 @@ void C010_Send(struct EventStruct *event, byte varIndex, float value, unsigned l
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
+3
-1
@@ -1,8 +1,9 @@
|
||||
#ifdef USES_C011
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 011: Generic HTTP #######################################
|
||||
//#######################################################################################################
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
// #ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define CPLUGIN_011
|
||||
#define CPLUGIN_ID_011 11
|
||||
@@ -283,3 +284,4 @@ void ReplaceTokenByValue(String& s, struct EventStruct *event)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
#ifdef USES_C012
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 012: Blynk #############################################
|
||||
//#######################################################################################################
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
// #ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define CPLUGIN_012
|
||||
#define CPLUGIN_ID_012 12
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_C013
|
||||
//#######################################################################################################
|
||||
//########################### Controller Plugin 013: ESPEasy P2P network ################################
|
||||
//#######################################################################################################
|
||||
@@ -262,4 +263,4 @@ void C013_Receive(struct EventStruct *event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_N001
|
||||
//#######################################################################################################
|
||||
//########################### Notification Plugin 001: Email ############################################
|
||||
//#######################################################################################################
|
||||
@@ -174,3 +175,4 @@ boolean NPlugin_001_MTA(WiFiClient& client, String aStr, const String &aWaitForP
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef USES_N002
|
||||
//#######################################################################################################
|
||||
//########################### Notification Plugin 002: Buzzer ###########################################
|
||||
//#######################################################################################################
|
||||
@@ -56,3 +57,4 @@ boolean NPlugin_002(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -69,13 +69,13 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
|
||||
options[1] = F("Dimmer");
|
||||
int optionValues[2] = { PLUGIN_001_TYPE_SWITCH, PLUGIN_001_TYPE_DIMMER };
|
||||
const byte switchtype = P001_getSwitchType(event);
|
||||
addFormSelector(string, F("Switch Type"), F("plugin_001_type"), 2, options, optionValues, switchtype);
|
||||
addFormSelector(F("Switch Type"), F("plugin_001_type"), 2, options, optionValues, switchtype);
|
||||
|
||||
if (switchtype == PLUGIN_001_TYPE_DIMMER)
|
||||
{
|
||||
char tmpString[128];
|
||||
sprintf_P(tmpString, PSTR("<TR><TD>Dim value:<TD><input type='text' name='plugin_001_dimvalue' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
string += tmpString;
|
||||
addHtml(tmpString);
|
||||
}
|
||||
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
|
||||
@@ -84,9 +84,9 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
|
||||
buttonOptions[1] = F("Push Button Active Low");
|
||||
buttonOptions[2] = F("Push Button Active High");
|
||||
int buttonOptionValues[3] = {PLUGIN_001_BUTTON_TYPE_NORMAL_SWITCH, PLUGIN_001_BUTTON_TYPE_PUSH_ACTIVE_LOW, PLUGIN_001_BUTTON_TYPE_PUSH_ACTIVE_HIGH};
|
||||
addFormSelector(string, F("Switch Button Type"), F("plugin_001_button"), 3, buttonOptions, buttonOptionValues, choice);
|
||||
addFormSelector(F("Switch Button Type"), F("plugin_001_button"), 3, buttonOptions, buttonOptionValues, choice);
|
||||
|
||||
addFormCheckBox(string, F("Send Boot state"),F("plugin_001_boot"),
|
||||
addFormCheckBox(F("Send Boot state"),F("plugin_001_boot"),
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
|
||||
success = true;
|
||||
@@ -149,7 +149,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PLUGIN_UNCONDITIONAL_POLL:
|
||||
{
|
||||
// port monitoring, on request by rule command
|
||||
@@ -389,7 +389,6 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
// FIXME: Absolutely no error checking in play_rtttl, until then keep it only in testing
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
//play a tune via a RTTTL string, look at https://www.letscontrolit.com/forum/viewtopic.php?f=4&t=343&hilit=speaker&start=10 for more info.
|
||||
if (command == F("rtttl"))
|
||||
{
|
||||
@@ -423,7 +422,6 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
|
||||
SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_001, event->Par1, log, 0));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
+12
-12
@@ -49,23 +49,23 @@ boolean Plugin_002(byte function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
#if defined(ESP32)
|
||||
string += F("<TR><TD>Analog Pin:<TD>");
|
||||
addPinSelect(false, string, "taskdevicepin1", Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
addHtml(F("<TR><TD>Analog Pin:<TD>"));
|
||||
addPinSelect(false, "taskdevicepin1", Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
#endif
|
||||
|
||||
addFormCheckBox(string, F("Oversampling"), F("plugin_002_oversampling"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
addFormSubHeader(string, F("Two Point Calibration"));
|
||||
addFormCheckBox(F("Oversampling"), F("plugin_002_oversampling"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
addFormCheckBox(string, F("Calibration Enabled"), F("plugin_002_cal"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
addFormSubHeader(F("Two Point Calibration"));
|
||||
|
||||
addFormNumericBox(string, F("Point 1"), F("plugin_002_adc1"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][0], 0, 1023);
|
||||
string += F(" ≙ ");
|
||||
addTextBox(string, F("plugin_002_out1"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0], 3), 10);
|
||||
addFormCheckBox(F("Calibration Enabled"), F("plugin_002_cal"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
|
||||
addFormNumericBox(string, F("Point 2"), F("plugin_002_adc2"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][1], 0, 1023);
|
||||
string += F(" ≙ ");
|
||||
addTextBox(string, F("plugin_002_out2"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1], 3), 10);
|
||||
addFormNumericBox(F("Point 1"), F("plugin_002_adc1"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][0], 0, 1023);
|
||||
addHtml(F(" ≙ "));
|
||||
addTextBox(F("plugin_002_out1"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0], 3), 10);
|
||||
|
||||
addFormNumericBox(F("Point 2"), F("plugin_002_adc2"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][1], 0, 1023);
|
||||
addHtml(F(" ≙ "));
|
||||
addTextBox(F("plugin_002_out2"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1], 3), 10);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+4
-4
@@ -65,16 +65,16 @@ boolean Plugin_003(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormNumericBox(string, F("Debounce Time (mSec)"), F("plugin_003")
|
||||
addFormNumericBox(F("Debounce Time (mSec)"), F("plugin_003")
|
||||
, Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
|
||||
String options[4] = { F("Delta"), F("Delta/Total/Time"), F("Total"), F("Delta/Total") };
|
||||
addFormSelector(string, F("Counter Type"), F("plugin_003_countertype"), 4, options, NULL, choice );
|
||||
addFormSelector(F("Counter Type"), F("plugin_003_countertype"), 4, options, NULL, choice );
|
||||
|
||||
if (choice !=0)
|
||||
string += F("<span style=\"color:red\">Total count is not persistent!</span>");
|
||||
addHtml(F("<span style=\"color:red\">Total count is not persistent!</span>"));
|
||||
|
||||
String modeRaise[4];
|
||||
modeRaise[0] = F("LOW");
|
||||
@@ -87,7 +87,7 @@ boolean Plugin_003(byte function, struct EventStruct *event, String& string)
|
||||
modeValues[2] = RISING;
|
||||
modeValues[3] = FALLING;
|
||||
|
||||
addFormSelector(string, F("Mode Type"), F("plugin_003_raisetype"), 4, modeRaise, modeValues, choice2 );
|
||||
addFormSelector(F("Mode Type"), F("plugin_003_raisetype"), 4, modeRaise, modeValues, choice2 );
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+12
-8
@@ -64,9 +64,9 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
|
||||
savedAddress[i] = ExtraTaskSettings.TaskDevicePluginConfigLong[i];
|
||||
|
||||
// find all suitable devices
|
||||
addRowLabel(string, F("Device Address"));
|
||||
addSelector_Head(string, F("plugin_004_dev"), false);
|
||||
addSelector_Item(string, "", -1, false, false, F(""));
|
||||
addRowLabel(F("Device Address"));
|
||||
addSelector_Head(F("plugin_004_dev"), false);
|
||||
addSelector_Item("", -1, false, false, F(""));
|
||||
uint8_t tmpAddress[8];
|
||||
byte count = 0;
|
||||
Plugin_004_DS_reset();
|
||||
@@ -80,10 +80,10 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
|
||||
if (j < 7) option += F("-");
|
||||
}
|
||||
bool selected = (memcmp(tmpAddress, savedAddress, 8) == 0) ? true : false;
|
||||
addSelector_Item(string, option, count, selected, false, F(""));
|
||||
addSelector_Item(option, count, selected, false, F(""));
|
||||
count ++;
|
||||
}
|
||||
addSelector_Foot(string);
|
||||
addSelector_Foot();
|
||||
|
||||
// Device Resolution select
|
||||
if (ExtraTaskSettings.TaskDevicePluginConfigLong[0] != 0)
|
||||
@@ -92,8 +92,8 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
|
||||
resolutionChoice = 9;
|
||||
String resultsOptions[4] = { "9", "10", "11", "12" };
|
||||
int resultsOptionValues[4] = { 9, 10, 11, 12 };
|
||||
addFormSelector(string, F("Device Resolution"), F("plugin_004_res"), 4, resultsOptions, resultsOptionValues, resolutionChoice);
|
||||
string += F(" Bit");
|
||||
addFormSelector(F("Device Resolution"), F("plugin_004_res"), 4, resultsOptions, resultsOptionValues, resolutionChoice);
|
||||
addHtml(F(" Bit"));
|
||||
}
|
||||
success = true;
|
||||
break;
|
||||
@@ -251,13 +251,17 @@ boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float * value)
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ROM[0] == 0x28 ) || (ROM[0] == 0x3b)) // DS18B20 or DS1825
|
||||
if ((ROM[0] == 0x28 ) || (ROM[0] == 0x3b) || (ROM[0] == 0x22)) // DS18B20 or DS1825 or DS1822
|
||||
{
|
||||
DSTemp = (ScratchPad[1] << 8) + ScratchPad[0];
|
||||
if (DSTemp == 0x550) // power-on reset value
|
||||
return false;
|
||||
*value = (float(DSTemp) * 0.0625);
|
||||
}
|
||||
else if (ROM[0] == 0x10) // DS1820 DS18S20
|
||||
{
|
||||
if (ScratchPad[0] == 0xaa) // power-on reset value
|
||||
return false;
|
||||
DSTemp = (ScratchPad[1] << 11) | ScratchPad[0] << 3;
|
||||
DSTemp = ((DSTemp & 0xfff0) << 3) - 16 +
|
||||
(((ScratchPad[7] - ScratchPad[6]) << 7) / ScratchPad[7]);
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ boolean Plugin_005(byte function, struct EventStruct *event, String& string)
|
||||
const String options[] = { F("DHT 11"), F("DHT 22"), F("DHT 12"), F("Sonoff am2301"), F("Sonoff si7021") };
|
||||
int indices[] = { 11, 22, 12, 23, 70 };
|
||||
|
||||
addFormSelector(string, F("DHT Type"), F("plugin_005_dhttype"), 5, options, indices, Settings.TaskDevicePluginConfig[event->TaskIndex][0] );
|
||||
addFormSelector(F("DHT Type"), F("plugin_005_dhttype"), 5, options, indices, Settings.TaskDevicePluginConfig[event->TaskIndex][0] );
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -50,7 +50,7 @@ boolean Plugin_006(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormNumericBox(string, F("Altitude [m]"), F("_p006_bmp085_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addFormNumericBox(F("Altitude [m]"), F("_p006_bmp085_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ boolean Plugin_009(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormCheckBox(string, F("Send Boot state") ,F("plugin_009_boot"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
addFormCheckBox(F("Send Boot state") ,F("plugin_009_boot"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -57,8 +57,8 @@ boolean Plugin_010(byte function, struct EventStruct *event, String& string)
|
||||
int optionValues[2];
|
||||
optionValues[0] = BH1750_DEFAULT_I2CADDR;
|
||||
optionValues[1] = BH1750_SECOND_I2CADDR;
|
||||
addFormSelectorI2C(string, F("plugin_010"), 2, optionValues, choice);
|
||||
addFormNote(string, F("ADDR Low=0x23, High=0x5c"));
|
||||
addFormSelectorI2C(F("plugin_010"), 2, optionValues, choice);
|
||||
addFormNote(F("ADDR Low=0x23, High=0x5c"));
|
||||
|
||||
byte choiceMode = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String optionsMode[4];
|
||||
@@ -71,9 +71,9 @@ boolean Plugin_010(byte function, struct EventStruct *event, String& string)
|
||||
optionValuesMode[1] = RESOLUTION_NORMAL;
|
||||
optionValuesMode[2] = RESOLUTION_HIGH;
|
||||
optionValuesMode[3] = RESOLUTION_AUTO_HIGH;
|
||||
addFormSelector(string, F("Measurement mode"), F("plugin_010_mode"), 4, optionsMode, optionValuesMode, choiceMode);
|
||||
addFormSelector(F("Measurement mode"), F("plugin_010_mode"), 4, optionsMode, optionValuesMode, choiceMode);
|
||||
|
||||
addFormCheckBox(string, F("Send sensor to sleep"), F("plugin_010_sleep"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
addFormCheckBox(F("Send sensor to sleep"), F("plugin_010_sleep"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ boolean Plugin_011(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
String options[2] = { F("Digital"), F("Analog") };
|
||||
addFormSelector(string, F("Port Type"), F("plugin_011"), 2, options, NULL, choice);
|
||||
addFormSelector(F("Port Type"), F("plugin_011"), 2, options, NULL, choice);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+39
-47
@@ -12,6 +12,9 @@
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
LiquidCrystal_I2C *lcd=NULL;
|
||||
int Plugin_012_cols = 16;
|
||||
int Plugin_012_rows = 2;
|
||||
int Plugin_012_mode = 1;
|
||||
|
||||
#define PLUGIN_012
|
||||
#define PLUGIN_ID_012 12
|
||||
@@ -67,7 +70,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
//options[x] = F("0x");
|
||||
//options[x] += String(optionValues[x], HEX);
|
||||
}
|
||||
addFormSelectorI2C(string, F("plugin_012_adr"), 16, optionValues, choice);
|
||||
addFormSelectorI2C(F("plugin_012_adr"), 16, optionValues, choice);
|
||||
|
||||
|
||||
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
@@ -75,30 +78,30 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
options2[0] = F("2 x 16");
|
||||
options2[1] = F("4 x 20");
|
||||
int optionValues2[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Display Size"), F("plugin_012_size"), 2, options2, optionValues2, choice2);
|
||||
addFormSelector(F("Display Size"), F("plugin_012_size"), 2, options2, optionValues2, choice2);
|
||||
|
||||
|
||||
char deviceTemplate[4][80];
|
||||
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
|
||||
for (byte varNr = 0; varNr < 4; varNr++)
|
||||
{
|
||||
string += F("<TR><TD>Line ");
|
||||
string += varNr + 1;
|
||||
string += F(":<TD><input type='text' size='80' maxlength='80' name='Plugin_012_template");
|
||||
string += varNr + 1;
|
||||
string += F("' value='");
|
||||
string += deviceTemplate[varNr];
|
||||
string += F("'>");
|
||||
addHtml(F("<TR><TD>Line "));
|
||||
addHtml(String(varNr + 1));
|
||||
addHtml(F(":<TD><input type='text' size='80' maxlength='80' name='Plugin_012_template"));
|
||||
addHtml(String(varNr + 1));
|
||||
addHtml(F("' value='"));
|
||||
addHtml(deviceTemplate[varNr]);
|
||||
addHtml(F("'>"));
|
||||
}
|
||||
|
||||
|
||||
addRowLabel(string, "Display button");
|
||||
addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
addRowLabel("Display button");
|
||||
addPinSelect(false, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
|
||||
|
||||
char tmpString[128];
|
||||
sprintf_P(tmpString, PSTR("<TR><TD>Display Timeout:<TD><input type='text' name='plugin_12_timer' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
string += tmpString;
|
||||
addHtml(tmpString);
|
||||
|
||||
|
||||
String options3[3];
|
||||
@@ -106,7 +109,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
options3[1] = F("Truncate exceeding message");
|
||||
options3[2] = F("Clear then truncate exceeding message");
|
||||
int optionValues3[3] = { 0,1,2 };
|
||||
addFormSelector(string, F("LCD command Mode"), F("plugin_012_mode"), 3, options3, optionValues3, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
addFormSelector(F("LCD command Mode"), F("plugin_012_mode"), 3, options3, optionValues3, Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
@@ -137,17 +140,21 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_INIT:
|
||||
{
|
||||
if (!lcd)
|
||||
{
|
||||
byte row = 2;
|
||||
byte col = 16;
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][1] == 2)
|
||||
{
|
||||
row = 4;
|
||||
col = 20;
|
||||
}
|
||||
lcd = new LiquidCrystal_I2C(Settings.TaskDevicePluginConfig[event->TaskIndex][0], col, row);
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][1] == 2) {
|
||||
Plugin_012_rows = 4;
|
||||
Plugin_012_cols = 20;
|
||||
} else if (Settings.TaskDevicePluginConfig[event->TaskIndex][1] == 1) {
|
||||
Plugin_012_rows = 2;
|
||||
Plugin_012_cols = 16;
|
||||
}
|
||||
|
||||
Plugin_012_mode = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
|
||||
|
||||
//TODO:LiquidCrystal_I2C class doesn't have destructor. So if LCD type (size) is changed better reboot for changes to take effect.
|
||||
// workaround is to fix the cols and rows at its maximum (20 and 4)
|
||||
if (!lcd)
|
||||
lcd = new LiquidCrystal_I2C(Settings.TaskDevicePluginConfig[event->TaskIndex][0], 20, 4); //Plugin_012_cols, Plugin_012_rows);
|
||||
|
||||
// Setup LCD display
|
||||
lcd->init(); // initialize the lcd
|
||||
lcd->backlight();
|
||||
@@ -190,20 +197,12 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
char deviceTemplate[4][80];
|
||||
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
|
||||
|
||||
byte row = 2;
|
||||
byte col = 16;
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][1] == 2)
|
||||
{
|
||||
row = 4;
|
||||
col = 20;
|
||||
}
|
||||
|
||||
for (byte x = 0; x < row; x++)
|
||||
for (byte x = 0; x < Plugin_012_rows; x++)
|
||||
{
|
||||
String tmpString = deviceTemplate[x];
|
||||
if (lcd && tmpString.length())
|
||||
{
|
||||
String newString = P012_parseTemplate(tmpString, col);
|
||||
String newString = P012_parseTemplate(tmpString, Plugin_012_cols);
|
||||
lcd->setCursor(0, x);
|
||||
lcd->print(newString);
|
||||
}
|
||||
@@ -214,13 +213,6 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WRITE:
|
||||
{
|
||||
byte rows = 2;
|
||||
byte cols = 16;
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][1] == 2){
|
||||
rows = 4;
|
||||
cols = 20;
|
||||
}
|
||||
|
||||
String tmpString = string;
|
||||
int argIndex = tmpString.indexOf(',');
|
||||
if (argIndex)
|
||||
@@ -244,7 +236,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
else if (lcd && tmpString.equalsIgnoreCase(F("LCD")))
|
||||
{
|
||||
success = true;
|
||||
tmpString = P012_parseTemplate(string, cols);
|
||||
tmpString = P012_parseTemplate(string, Plugin_012_cols);
|
||||
argIndex = tmpString.lastIndexOf(',');
|
||||
tmpString = tmpString.substring(argIndex + 1);
|
||||
|
||||
@@ -252,18 +244,18 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
int rowPos = event->Par1 - 1;
|
||||
|
||||
//clear line before writing new string
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][3] == 2){
|
||||
if (Plugin_012_mode == 2){
|
||||
lcd->setCursor(colPos, rowPos);
|
||||
for (byte i = colPos; i < cols; i++) {
|
||||
for (byte i = colPos; i < Plugin_012_cols; i++) {
|
||||
lcd->print(F(" "));
|
||||
}
|
||||
}
|
||||
|
||||
// truncate message exceeding cols
|
||||
lcd->setCursor(colPos, rowPos);
|
||||
if(Settings.TaskDevicePluginConfig[event->TaskIndex][3] == 1 || Settings.TaskDevicePluginConfig[event->TaskIndex][3] == 2){
|
||||
if(Plugin_012_mode == 1 || Plugin_012_mode == 2){
|
||||
lcd->setCursor(colPos, rowPos);
|
||||
for (byte i = 0; i < cols - colPos; i++) {
|
||||
for (byte i = 0; i < Plugin_012_cols - colPos; i++) {
|
||||
if(tmpString[i]){
|
||||
lcd->print(tmpString[i]);
|
||||
}
|
||||
@@ -276,14 +268,14 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
|
||||
boolean stillProcessing = 1;
|
||||
byte charCount = 1;
|
||||
while(stillProcessing) {
|
||||
if (++colPos > cols) { // have we printed 20 characters yet (+1 for the logic)
|
||||
if (++colPos > Plugin_012_cols) { // have we printed 20 characters yet (+1 for the logic)
|
||||
rowPos += 1;
|
||||
lcd->setCursor(0,rowPos); // move cursor down
|
||||
colPos = 1;
|
||||
}
|
||||
|
||||
//dont print if "lower" than the lcd
|
||||
if(rowPos < rows ){
|
||||
if(rowPos < Plugin_012_rows ){
|
||||
lcd->print(tmpString[charCount - 1]);
|
||||
}
|
||||
|
||||
|
||||
+33
-45
@@ -1,20 +1,19 @@
|
||||
#ifdef USES_P013
|
||||
//#######################################################################################################
|
||||
//#################################### Plugin 013: HC-SR04 ##############################################
|
||||
//############################### Plugin 013: HC-SR04, RCW-0001, etc. ###################################
|
||||
//#######################################################################################################
|
||||
|
||||
#define PLUGIN_013
|
||||
#define PLUGIN_ID_013 13
|
||||
#define PLUGIN_NAME_013 "Distance - HC-SR04"
|
||||
#define PLUGIN_NAME_013 "Distance - HC-SR04, RCW-0001, etc."
|
||||
#define PLUGIN_VALUENAME1_013 "Distance"
|
||||
|
||||
void Plugin_013_interrupt() ICACHE_RAM_ATTR;
|
||||
#include <NewPing.h>
|
||||
|
||||
boolean Plugin_013_init = false;
|
||||
volatile unsigned long Plugin_013_timer = 0;
|
||||
volatile unsigned long Plugin_013_state = 0;
|
||||
byte Plugin_013_TRIG_Pin = 0;
|
||||
byte Plugin_013_IRQ_Pin = 0;
|
||||
NewPing *sonar = NULL;
|
||||
|
||||
boolean Plugin_013(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
@@ -59,11 +58,11 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
|
||||
options[0] = F("Value");
|
||||
options[1] = F("State");
|
||||
int optionValues[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Mode"), F("plugin_013_mode"), 2, options, optionValues, choice);
|
||||
addFormSelector(F("Mode"), F("plugin_013_mode"), 2, options, optionValues, choice);
|
||||
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][0] == 2)
|
||||
{
|
||||
addFormNumericBox(string, F("Threshold"), F("plugin_013_threshold"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addFormNumericBox(F("Threshold"), F("plugin_013_threshold"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
}
|
||||
success = true;
|
||||
break;
|
||||
@@ -83,21 +82,38 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_INIT:
|
||||
{
|
||||
Plugin_013_init = true;
|
||||
pinMode(Settings.TaskDevicePin1[event->TaskIndex], OUTPUT);
|
||||
pinMode(Settings.TaskDevicePin2[event->TaskIndex], INPUT_PULLUP);
|
||||
|
||||
Plugin_013_TRIG_Pin = Settings.TaskDevicePin1[event->TaskIndex];
|
||||
Plugin_013_IRQ_Pin = Settings.TaskDevicePin2[event->TaskIndex];
|
||||
attachInterrupt(Settings.TaskDevicePin2[event->TaskIndex], Plugin_013_interrupt, CHANGE);
|
||||
|
||||
if (sonar)
|
||||
{
|
||||
delete sonar;
|
||||
sonar=NULL;
|
||||
}
|
||||
|
||||
sonar = new NewPing(Plugin_013_TRIG_Pin, Plugin_013_IRQ_Pin);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_EXIT:
|
||||
{
|
||||
if (sonar)
|
||||
{
|
||||
delete sonar;
|
||||
sonar=NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_READ: // If we select value mode, read and send the value based on global timer
|
||||
{
|
||||
if (Settings.TaskDevicePluginConfig[event->TaskIndex][0] == 1)
|
||||
{
|
||||
Plugin_013_TRIG_Pin = Settings.TaskDevicePin1[event->TaskIndex];
|
||||
float value = Plugin_013_read();
|
||||
String log = F("SR04 : Distance: ");
|
||||
String log = F("ULTRASONIC : Distance: ");
|
||||
if (value > 0)
|
||||
{
|
||||
UserVar[event->BaseVarIndex] = value;
|
||||
@@ -125,7 +141,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
|
||||
state = 1;
|
||||
if (state != switchstate[event->TaskIndex])
|
||||
{
|
||||
String log = F("SR04 : State ");
|
||||
String log = F("ULTRASONIC : State ");
|
||||
log += state;
|
||||
addLog(LOG_LEVEL_INFO,log);
|
||||
switchstate[event->TaskIndex] = state;
|
||||
@@ -146,39 +162,11 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
|
||||
float Plugin_013_read()
|
||||
/*********************************************************************/
|
||||
{
|
||||
float value = -1;
|
||||
Plugin_013_timer = 0;
|
||||
Plugin_013_state = 0;
|
||||
noInterrupts();
|
||||
digitalWrite(Plugin_013_TRIG_Pin, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(Plugin_013_TRIG_Pin, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(Plugin_013_TRIG_Pin, LOW);
|
||||
interrupts();
|
||||
if (!sonar)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
delay(25); // wait for measurement to finish (max 400 cm * 58 uSec = 23uSec)
|
||||
if (Plugin_013_state == 2)
|
||||
{
|
||||
value = (float)Plugin_013_timer / 58;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
void Plugin_013_interrupt()
|
||||
/*********************************************************************/
|
||||
{
|
||||
byte pinState = digitalRead(Plugin_013_IRQ_Pin);
|
||||
if (pinState == 1) // Start of pulse
|
||||
{
|
||||
Plugin_013_state = 1;
|
||||
Plugin_013_timer = micros();
|
||||
}
|
||||
else // End of pulse, calculate timelapse between start & end
|
||||
{
|
||||
Plugin_013_state = 2;
|
||||
Plugin_013_timer = micros() - Plugin_013_timer;
|
||||
}
|
||||
return sonar->ping_cm();
|
||||
}
|
||||
#endif // USES_P013
|
||||
|
||||
@@ -86,8 +86,8 @@ boolean Plugin_014(byte function, struct EventStruct *event, String& string)
|
||||
options[2] = F("Temp 12 bits / RH 8 bits");
|
||||
optionValues[3] = SI7021_RESOLUTION_11T_11RH;
|
||||
options[3] = F("Temp 11 bits / RH 11 bits");
|
||||
addFormSelector(string, F("Resolution"), F("plugin_014_res"), SI7021_RESOLUTION_OPTION, options, optionValues, choice);
|
||||
//addUnit(string, F("bits"));
|
||||
addFormSelector(F("Resolution"), F("plugin_014_res"), SI7021_RESOLUTION_OPTION, options, optionValues, choice);
|
||||
//addUnit(F("bits"));
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+26
-9
@@ -12,6 +12,8 @@
|
||||
#define PLUGIN_ID_015 15
|
||||
#define PLUGIN_NAME_015 "Light/Lux - TSL2561"
|
||||
#define PLUGIN_VALUENAME1_015 "Lux"
|
||||
#define PLUGIN_VALUENAME2_015 "Infrared"
|
||||
#define PLUGIN_VALUENAME3_015 "Broadband"
|
||||
|
||||
boolean Plugin_015_init = false;
|
||||
|
||||
@@ -219,7 +221,7 @@ boolean plugin_015_getData(unsigned int &data0, unsigned int &data1)
|
||||
}
|
||||
|
||||
|
||||
boolean plugin_015_getLux(unsigned char gain, unsigned int ms, unsigned int CH0, unsigned int CH1, double &lux)
|
||||
boolean plugin_015_getLux(unsigned char gain, unsigned int ms, unsigned int CH0, unsigned int CH1, double &lux, double &infrared, double &broadband)
|
||||
// Convert raw data to lux
|
||||
// gain: 0 (1X) or 1 (16X), see setTiming()
|
||||
// ms: integration time in ms, from setTiming() or from manual integration
|
||||
@@ -246,6 +248,10 @@ boolean plugin_015_getLux(unsigned char gain, unsigned int ms, unsigned int CH0,
|
||||
// We will need the ratio for subsequent calculations
|
||||
ratio = d1 / d0;
|
||||
|
||||
// save original values
|
||||
infrared = d1;
|
||||
broadband = d0;
|
||||
|
||||
// Normalize for integration time
|
||||
d0 *= (402.0/ms);
|
||||
d1 *= (402.0/ms);
|
||||
@@ -290,7 +296,6 @@ boolean plugin_015_getLux(unsigned char gain, unsigned int ms, unsigned int CH0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
boolean success = false;
|
||||
@@ -301,12 +306,12 @@ boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
Device[++deviceCount].Number = PLUGIN_ID_015;
|
||||
Device[deviceCount].Type = DEVICE_TYPE_I2C;
|
||||
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
|
||||
Device[deviceCount].VType = SENSOR_TYPE_TRIPLE;
|
||||
Device[deviceCount].Ports = 0;
|
||||
Device[deviceCount].PullUpOption = false;
|
||||
Device[deviceCount].InverseLogicOption = false;
|
||||
Device[deviceCount].FormulaOption = true;
|
||||
Device[deviceCount].ValueCount = 1;
|
||||
Device[deviceCount].ValueCount = 3;
|
||||
Device[deviceCount].SendDataOption = true;
|
||||
Device[deviceCount].TimerOption = true;
|
||||
Device[deviceCount].GlobalSyncOption = true;
|
||||
@@ -322,6 +327,9 @@ boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_GET_DEVICEVALUENAMES:
|
||||
{
|
||||
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_015));
|
||||
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_015));
|
||||
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_015));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -338,7 +346,7 @@ boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
optionValues1[0] = TSL2561_ADDR;
|
||||
optionValues1[1] = TSL2561_ADDR_1;
|
||||
optionValues1[2] = TSL2561_ADDR_0;
|
||||
addFormSelectorI2C(string, F("plugin_015_tsl2561_i2c"), 3, optionValues1, choice1);
|
||||
addFormSelectorI2C(F("plugin_015_tsl2561_i2c"), 3, optionValues1, choice1);
|
||||
|
||||
#define TSL2561_INTEGRATION_OPTION 3
|
||||
|
||||
@@ -351,12 +359,12 @@ boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
options2[1] = F("101 ms");
|
||||
optionValues2[2] = 0x02;
|
||||
options2[2] = F("402 ms");
|
||||
addFormSelector(string, F("Integration time"), F("plugin_015_integration"), TSL2561_INTEGRATION_OPTION, options2, optionValues2, choice2);
|
||||
addFormSelector(F("Integration time"), F("plugin_015_integration"), TSL2561_INTEGRATION_OPTION, options2, optionValues2, choice2);
|
||||
|
||||
addFormCheckBox(string, F("Send sensor to sleep:"), F("plugin_015_sleep"),
|
||||
addFormCheckBox(F("Send sensor to sleep:"), F("plugin_015_sleep"),
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
|
||||
addFormCheckBox(string, F("Enable 16x Gain:"), F("plugin_015_gain"),
|
||||
addFormCheckBox(F("Enable 16x Gain:"), F("plugin_015_gain"),
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
|
||||
success = true;
|
||||
@@ -403,12 +411,17 @@ boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
|
||||
double lux; // Resulting lux value
|
||||
double infrared; // Resulting infrared value
|
||||
double broadband; // Resulting broadband value
|
||||
boolean good; // True if neither sensor is saturated
|
||||
|
||||
// Perform lux calculation:
|
||||
|
||||
good = plugin_015_getLux(gain,ms,data0,data1,lux);
|
||||
good = plugin_015_getLux(gain,ms,data0,data1,lux, infrared, broadband);
|
||||
UserVar[event->BaseVarIndex] = lux;
|
||||
UserVar[event->BaseVarIndex + 1] = infrared;
|
||||
UserVar[event->BaseVarIndex + 2] = broadband;
|
||||
|
||||
if (!good)
|
||||
{
|
||||
addLog(LOG_LEVEL_INFO,F("TSL2561: Sensor saturated! > 65535 Lux"));
|
||||
@@ -423,6 +436,10 @@ boolean Plugin_015(byte function, struct EventStruct *event, String& string)
|
||||
log += String(gain,HEX);
|
||||
log += F(": Lux: ");
|
||||
log += UserVar[event->BaseVarIndex];
|
||||
log += F(": Infrared: ");
|
||||
log += UserVar[event->BaseVarIndex + 1];
|
||||
log += F(": Broadband: ");
|
||||
log += UserVar[event->BaseVarIndex + 2];
|
||||
addLog(LOG_LEVEL_INFO,log);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//#######################################################################################################
|
||||
|
||||
|
||||
#ifdef PLUGIN_BUILD_NORMAL
|
||||
|
||||
#include <IRremoteESP8266.h>
|
||||
IRrecv *irReceiver;
|
||||
@@ -93,5 +92,4 @@ boolean Plugin_016(byte function, struct EventStruct *event, String& string)
|
||||
return success;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // USES_P016
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ boolean Plugin_017(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormPinSelect(string, F("Reset Pin"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
addFormPinSelect(F("Reset Pin"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ boolean Plugin_019(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormCheckBox(string, F("Send Boot state"), F("plugin_019_boot"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
addFormCheckBox(F("Send Boot state"), F("plugin_019_boot"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -46,9 +46,9 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormNumericBox(string, F("TCP Port"), F("plugin_020_port"), ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
|
||||
addFormNumericBox(string, F("Baud Rate"), F("plugin_020_baud"), ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
|
||||
addFormNumericBox(string, F("Data bits"), F("plugin_020_data"), ExtraTaskSettings.TaskDevicePluginConfigLong[2]);
|
||||
addFormNumericBox(F("TCP Port"), F("plugin_020_port"), ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
|
||||
addFormNumericBox(F("Baud Rate"), F("plugin_020_baud"), ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
|
||||
addFormNumericBox(F("Data bits"), F("plugin_020_data"), ExtraTaskSettings.TaskDevicePluginConfigLong[2]);
|
||||
|
||||
byte choice = ExtraTaskSettings.TaskDevicePluginConfigLong[3];
|
||||
String options[3];
|
||||
@@ -59,13 +59,13 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
|
||||
optionValues[0] = 0;
|
||||
optionValues[1] = 2;
|
||||
optionValues[2] = 3;
|
||||
addFormSelector(string, F("Parity"), F("plugin_020_parity"), 3, options, optionValues, choice);
|
||||
addFormSelector(F("Parity"), F("plugin_020_parity"), 3, options, optionValues, choice);
|
||||
|
||||
addFormNumericBox(string, F("Stop bits"), F("plugin_020_stop"), ExtraTaskSettings.TaskDevicePluginConfigLong[4]);
|
||||
addFormNumericBox(F("Stop bits"), F("plugin_020_stop"), ExtraTaskSettings.TaskDevicePluginConfigLong[4]);
|
||||
|
||||
addFormPinSelect(string, F("Reset target after boot"), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
addFormPinSelect(F("Reset target after boot"), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
|
||||
addFormNumericBox(string, F("RX Receive Timeout (mSec)"), F("plugin_020_rxwait"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
addFormNumericBox(F("RX Receive Timeout (mSec)"), F("plugin_020_rxwait"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
|
||||
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
@@ -73,7 +73,7 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
|
||||
options2[0] = F("None");
|
||||
options2[1] = F("Generic");
|
||||
options2[2] = F("RFLink");
|
||||
addFormSelector(string, F("Event processing"), F("plugin_020_events"), 3, options2, NULL, choice2);
|
||||
addFormSelector(F("Event processing"), F("plugin_020_events"), 3, options2, NULL, choice2);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+6
-6
@@ -47,16 +47,16 @@ boolean Plugin_021(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
// char tmpString[128];
|
||||
|
||||
string += F("<TR><TD>Check Task:<TD>");
|
||||
addTaskSelect(string, "plugin_021_task", Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
addHtml(F("<TR><TD>Check Task:<TD>"));
|
||||
addTaskSelect("plugin_021_task", Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
LoadTaskSettings(Settings.TaskDevicePluginConfig[event->TaskIndex][0]); // we need to load the values from another task for selection!
|
||||
string += F("<TR><TD>Check Value:<TD>");
|
||||
addTaskValueSelect(string, "plugin_021_value", Settings.TaskDevicePluginConfig[event->TaskIndex][1], Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
addHtml(F("<TR><TD>Check Value:<TD>"));
|
||||
addTaskValueSelect("plugin_021_value", Settings.TaskDevicePluginConfig[event->TaskIndex][1], Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
addFormTextBox(string, F("Set Level"), F("plugin_021_setvalue"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0]), 8);
|
||||
addFormTextBox(F("Set Level"), F("plugin_021_setvalue"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0]), 8);
|
||||
|
||||
addFormTextBox(string, F("Hysteresis"), F("plugin_021_hyst"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]), 8);
|
||||
addFormTextBox(F("Hysteresis"), F("plugin_021_hyst"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]), 8);
|
||||
|
||||
LoadTaskSettings(event->TaskIndex); // we need to restore our original taskvalues!
|
||||
success = true;
|
||||
|
||||
+7
-7
@@ -71,33 +71,33 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
/*String options[2] = { F("3C"), F("3D") };*/
|
||||
int optionValues[2] = { 0x3C, 0x3D };
|
||||
addFormSelectorI2C(string, F("plugin_023_adr"), 2, optionValues, choice);
|
||||
addFormSelectorI2C(F("plugin_023_adr"), 2, optionValues, choice);
|
||||
|
||||
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String options2[2] = { F("Normal"), F("Rotated") };
|
||||
int optionValues2[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Rotation"), F("plugin_023_rotate"), 2, options2, optionValues2, choice2);
|
||||
addFormSelector(F("Rotation"), F("plugin_023_rotate"), 2, options2, optionValues2, choice2);
|
||||
|
||||
byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
|
||||
String options3[3] = { F("128x64"), F("128x32"), F("64x48") };
|
||||
int optionValues3[3] = { 1, 3, 2 };
|
||||
addFormSelector(string, F("Display Size"), F("plugin_023_size"), 3, options3, optionValues3, choice3);
|
||||
addFormSelector(F("Display Size"), F("plugin_023_size"), 3, options3, optionValues3, choice3);
|
||||
|
||||
byte choice4 = Settings.TaskDevicePluginConfig[event->TaskIndex][4];
|
||||
String options4[2] = { F("Normal"), F("Optimized") };
|
||||
int optionValues4[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Font Width"), F("plugin_023_font_width"), 2, options4, optionValues4, choice4);
|
||||
addFormSelector(F("Font Width"), F("plugin_023_font_width"), 2, options4, optionValues4, choice4);
|
||||
|
||||
char deviceTemplate[8][64];
|
||||
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
|
||||
for (byte varNr = 0; varNr < 8; varNr++)
|
||||
{
|
||||
addFormTextBox(string, String(F("Line ")) + (varNr + 1), String(F("Plugin_023_template")) + (varNr + 1), deviceTemplate[varNr], 64);
|
||||
addFormTextBox(String(F("Line ")) + (varNr + 1), String(F("Plugin_023_template")) + (varNr + 1), deviceTemplate[varNr], 64);
|
||||
}
|
||||
|
||||
addFormPinSelect(string, F("Display button"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
addFormPinSelect(F("Display button"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
|
||||
addFormNumericBox(string, F("Display Timeout"), F("plugin_23_timer"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
addFormNumericBox(F("Display Timeout"), F("plugin_23_timer"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -78,7 +78,7 @@ boolean Plugin_024(byte function, struct EventStruct *event, String& string)
|
||||
options[0] = F("IR object temperature");
|
||||
optionValues[1] = (0x06);
|
||||
options[1] = F("Ambient temperature");
|
||||
addFormSelector(string, F("Option"), F("plugin_024_option"), MLX90614_OPTION, options, optionValues, choice);
|
||||
addFormSelector(F("Option"), F("plugin_024_option"), MLX90614_OPTION, options, optionValues, choice);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+12
-12
@@ -67,9 +67,9 @@ boolean Plugin_025(byte function, struct EventStruct *event, String& string)
|
||||
#define ADS1115_I2C_OPTION 4
|
||||
byte addr = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
int optionValues[ADS1115_I2C_OPTION] = { 0x48, 0x49, 0x4A, 0x4B };
|
||||
addFormSelectorI2C(string, F("plugin_025_i2c"), ADS1115_I2C_OPTION, optionValues, addr);
|
||||
addFormSelectorI2C(F("plugin_025_i2c"), ADS1115_I2C_OPTION, optionValues, addr);
|
||||
|
||||
addFormSubHeader(string, F("Input"));
|
||||
addFormSubHeader(F("Input"));
|
||||
|
||||
#define ADS1115_PGA_OPTION 6
|
||||
byte pga = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
@@ -81,7 +81,7 @@ boolean Plugin_025(byte function, struct EventStruct *event, String& string)
|
||||
F("8x gain (FS=0.512V)"),
|
||||
F("16x gain (FS=0.256V)")
|
||||
};
|
||||
addFormSelector(string, F("Gain"), F("plugin_025_gain"), ADS1115_PGA_OPTION, pgaOptions, NULL, pga);
|
||||
addFormSelector(F("Gain"), F("plugin_025_gain"), ADS1115_PGA_OPTION, pgaOptions, NULL, pga);
|
||||
|
||||
#define ADS1115_MUX_OPTION 8
|
||||
byte mux = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
|
||||
@@ -95,19 +95,19 @@ boolean Plugin_025(byte function, struct EventStruct *event, String& string)
|
||||
F("AIN2 - GND (Single-Ended)"),
|
||||
F("AIN3 - GND (Single-Ended)"),
|
||||
};
|
||||
addFormSelector(string, F("Input Multiplexer"), F("plugin_025_mode"), ADS1115_MUX_OPTION, muxOptions, NULL, mux);
|
||||
addFormSelector(F("Input Multiplexer"), F("plugin_025_mode"), ADS1115_MUX_OPTION, muxOptions, NULL, mux);
|
||||
|
||||
addFormSubHeader(string, F("Two Point Calibration"));
|
||||
addFormSubHeader(F("Two Point Calibration"));
|
||||
|
||||
addFormCheckBox(string, F("Calibration Enabled"), F("plugin_025_cal"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
addFormCheckBox(F("Calibration Enabled"), F("plugin_025_cal"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
|
||||
addFormNumericBox(string, F("Point 1"), F("plugin_025_adc1"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][0], -32768, 32767);
|
||||
string += F(" ≙ ");
|
||||
addTextBox(string, F("plugin_025_out1"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0], 3), 10);
|
||||
addFormNumericBox(F("Point 1"), F("plugin_025_adc1"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][0], -32768, 32767);
|
||||
addHtml(F(" ≙ "));
|
||||
addTextBox(F("plugin_025_out1"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0], 3), 10);
|
||||
|
||||
addFormNumericBox(string, F("Point 2"), F("plugin_025_adc2"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][1], -32768, 32767);
|
||||
string += F(" ≙ ");
|
||||
addTextBox(string, F("plugin_025_out2"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1], 3), 10);
|
||||
addFormNumericBox(F("Point 2"), F("plugin_025_adc2"), Settings.TaskDevicePluginConfigLong[event->TaskIndex][1], -32768, 32767);
|
||||
addHtml(F(" ≙ "));
|
||||
addTextBox(F("plugin_025_out2"), String(Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1], 3), 10);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -52,7 +52,7 @@ boolean Plugin_026(byte function, struct EventStruct *event, String& string)
|
||||
options[7] = F("IP 3.Octet");
|
||||
options[8] = F("IP 4.Octet");
|
||||
options[9] = F("Web activity");
|
||||
addFormSelector(string, F("Indicator"), F("plugin_026"), 10, options, NULL, choice);
|
||||
addFormSelector(F("Indicator"), F("plugin_026"), 10, options, NULL, choice);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -138,13 +138,13 @@ boolean Plugin_027(byte function, struct EventStruct *event, String& string)
|
||||
optionValuesMode[0] = 0;
|
||||
optionValuesMode[1] = 1;
|
||||
optionValuesMode[2] = 2;
|
||||
addFormSelector(string, F("Measure range"), F("plugin_027_range"), 3, optionsMode, optionValuesMode, choiceMode);
|
||||
addFormSelector(F("Measure range"), F("plugin_027_range"), 3, optionsMode, optionValuesMode, choiceMode);
|
||||
|
||||
addFormSelectorI2C(string, F("plugin_027_i2c"), 4, Plugin_27_i2c_addresses, Plugin_027_i2c_addr(event));
|
||||
addFormSelectorI2C(F("plugin_027_i2c"), 4, Plugin_27_i2c_addresses, Plugin_027_i2c_addr(event));
|
||||
|
||||
byte choiceMeasureType = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
|
||||
String options[4] = { F("Voltage"), F("Current"), F("Power"), F("Voltage/Current/Power") };
|
||||
addFormSelector(string, F("Measurement Type"), F("plugin_027_measuretype"), 4, options, NULL, choiceMeasureType );
|
||||
addFormSelector(F("Measurement Type"), F("plugin_027_measuretype"), 4, options, NULL, choiceMeasureType );
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -213,25 +213,25 @@ boolean Plugin_028(byte function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
const uint8_t i2cAddress = Plugin_028_i2c_addr(event);
|
||||
addFormSelectorI2C(string, F("plugin_028_bme280_i2c"), 2, Plugin_28_i2c_addresses, i2cAddress);
|
||||
addFormSelectorI2C(F("plugin_028_bme280_i2c"), 2, Plugin_28_i2c_addresses, i2cAddress);
|
||||
const uint8_t idx = Plugin_028_device_index(i2cAddress);
|
||||
if (_sensorID[idx] != Unknown_DEVICE) {
|
||||
String detectedString = F("Detected: ");
|
||||
detectedString += Plugin_028_getFullDeviceName();
|
||||
addUnit(string, detectedString);
|
||||
addUnit(detectedString);
|
||||
}
|
||||
addFormNote(string, F("SDO Low=0x76, High=0x77"));
|
||||
addFormNote(F("SDO Low=0x76, High=0x77"));
|
||||
|
||||
addFormNumericBox(string, F("Altitude"), F("plugin_028_bme280_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addUnit(string, F("m"));
|
||||
addFormNumericBox(F("Altitude"), F("plugin_028_bme280_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addUnit(F("m"));
|
||||
|
||||
addFormNumericBox(string, F("Temperature offset"), F("plugin_028_bme280_tempoffset"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
addUnit(string, F("x 0.1C"));
|
||||
addFormNumericBox(F("Temperature offset"), F("plugin_028_bme280_tempoffset"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
addUnit(F("x 0.1C"));
|
||||
String offsetNote = F("Offset in units of 0.1 degree Celcius");
|
||||
if (Plugin_028_hasHumidity()) {
|
||||
offsetNote += F(" (also correct humidity)");
|
||||
}
|
||||
addFormNote(string, offsetNote);
|
||||
addFormNote(offsetNote);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#define PLUGIN_029
|
||||
#define PLUGIN_ID_029 29
|
||||
#define PLUGIN_NAME_029 "Output - (Domoticz MQTT helper)"
|
||||
#define PLUGIN_NAME_029 "Output - Domoticz MQTT Helper"
|
||||
#define PLUGIN_VALUENAME1_029 "Output"
|
||||
boolean Plugin_029(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
@@ -50,10 +50,10 @@ boolean Plugin_029(byte function, struct EventStruct *event, String& string)
|
||||
if (Settings.Protocol[i] == 2) { controllerNr = i; }
|
||||
}
|
||||
|
||||
string += F("<TR><TD>IDX:<TD>");
|
||||
addHtml(F("<TR><TD>IDX:<TD>"));
|
||||
String id = F("TDID"); //="taskdeviceid"
|
||||
id += controllerNr + 1;
|
||||
addNumericBox(string, id, Settings.TaskDeviceID[controllerNr][event->TaskIndex], 0, 9999);
|
||||
addNumericBox(id, Settings.TaskDeviceID[controllerNr][event->TaskIndex], 0, 9999);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -106,11 +106,11 @@ boolean Plugin_030(byte function, struct EventStruct *event, String& string)
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
/*String options[2] = { F("0x76 - default settings (SDO Low)"), F("0x77 - alternate settings (SDO HIGH)") };*/
|
||||
int optionValues[2] = { 0x76, 0x77 };
|
||||
addFormSelectorI2C(string, F("plugin_030_bmp280_i2c"), 2, optionValues, choice);
|
||||
addFormNote(string, F("SDO Low=0x76, High=0x77"));
|
||||
addFormSelectorI2C(F("plugin_030_bmp280_i2c"), 2, optionValues, choice);
|
||||
addFormNote(F("SDO Low=0x76, High=0x77"));
|
||||
|
||||
addFormNumericBox(string, F("Altitude"), F("plugin_030_bmp280_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addUnit(string, F("m"));
|
||||
addFormNumericBox(F("Altitude"), F("plugin_030_bmp280_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addUnit(F("m"));
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -73,9 +73,9 @@ boolean Plugin_032(byte function, struct EventStruct *event, String& string)
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
/*String options[2] = { F("0x77 - default I2C address"), F("0x76 - alternate I2C address") };*/
|
||||
int optionValues[2] = { 0x77, 0x76 };
|
||||
addFormSelectorI2C(string, F("plugin_032_ms5611_i2c"), 2, optionValues, choice);
|
||||
addFormSelectorI2C(F("plugin_032_ms5611_i2c"), 2, optionValues, choice);
|
||||
|
||||
addFormNumericBox(string, F("Altitude [m]"), F("plugin_032_ms5611_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addFormNumericBox(F("Altitude [m]"), F("plugin_032_ms5611_elev"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ boolean Plugin_033(byte function, struct EventStruct *event, String& string)
|
||||
optionValues[9] = SENSOR_TYPE_LONG;
|
||||
optionValues[10] = SENSOR_TYPE_WIND;
|
||||
|
||||
addFormSelector(string, F("Simulate Data Type"), F("plugin_033_sensortype"), 11, options, optionValues, choice );
|
||||
addFormSelector(F("Simulate Data Type"), F("plugin_033_sensortype"), 11, options, optionValues, choice );
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//#######################################################################################################
|
||||
//#################################### Plugin 035: Output IR ############################################
|
||||
//#######################################################################################################
|
||||
#ifdef PLUGIN_BUILD_NORMAL
|
||||
|
||||
#include <IRremoteESP8266.h>
|
||||
IRsend *Plugin_035_irSender;
|
||||
@@ -233,5 +232,4 @@ boolean Plugin_035(byte function, struct EventStruct *event, String& string)
|
||||
return success;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // USES_P035
|
||||
|
||||
+13
-13
@@ -26,10 +26,10 @@
|
||||
#define P36_CONTRAST_HIGH 0xFF
|
||||
|
||||
|
||||
#include "SSD1306.h"
|
||||
#include "SH1106Wire.h"
|
||||
#include "OLED_SSD1306_SH1106_images.h"
|
||||
#include "Dialog_Plain_12_font.h"
|
||||
#include "SSD1306.h"
|
||||
#include "SH1106Wire.h"
|
||||
#include "OLED_SSD1306_SH1106_images.h"
|
||||
#include "Dialog_Plain_12_font.h"
|
||||
|
||||
#define P36_WIFI_STATE_UNSET -2
|
||||
#define P36_WIFI_STATE_NOT_CONNECTED -1
|
||||
@@ -94,7 +94,7 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
|
||||
options5[0] = F("SSD1306");
|
||||
options5[1] = F("SH1106");
|
||||
int optionValues5[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Controler"), F("plugin_036_controler"), 2, options5, optionValues5, choice5);
|
||||
addFormSelector(F("Controler"), F("plugin_036_controler"), 2, options5, optionValues5, choice5);
|
||||
|
||||
byte choice0 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
/*
|
||||
@@ -105,14 +105,14 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
|
||||
int optionValues0[2];
|
||||
optionValues0[0] = 0x3C;
|
||||
optionValues0[1] = 0x3D;
|
||||
addFormSelectorI2C(string, F("plugin_036_adr"), 2, optionValues0, choice0);
|
||||
addFormSelectorI2C(F("plugin_036_adr"), 2, optionValues0, choice0);
|
||||
|
||||
byte choice1 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String options1[2];
|
||||
options1[0] = F("Normal");
|
||||
options1[1] = F("Rotated");
|
||||
int optionValues1[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Rotation"), F("plugin_036_rotate"), 2, options1, optionValues1, choice1);
|
||||
addFormSelector(F("Rotation"), F("plugin_036_rotate"), 2, options1, optionValues1, choice1);
|
||||
|
||||
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
|
||||
String options2[4];
|
||||
@@ -121,7 +121,7 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
|
||||
options2[2] = F("3");
|
||||
options2[3] = F("4");
|
||||
int optionValues2[4] = { 1, 2, 3, 4 };
|
||||
addFormSelector(string, F("Lines per Frame"), F("plugin_036_nlines"), 4, options2, optionValues2, choice2);
|
||||
addFormSelector(F("Lines per Frame"), F("plugin_036_nlines"), 4, options2, optionValues2, choice2);
|
||||
|
||||
byte choice3 = Settings.TaskDevicePluginConfig[event->TaskIndex][3];
|
||||
String options3[5];
|
||||
@@ -136,18 +136,18 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
|
||||
optionValues3[2] = 4;
|
||||
optionValues3[3] = 8;
|
||||
optionValues3[4] = 32;
|
||||
addFormSelector(string, F("Scroll"), F("plugin_036_scroll"), 5, options3, optionValues3, choice3);
|
||||
addFormSelector(F("Scroll"), F("plugin_036_scroll"), 5, options3, optionValues3, choice3);
|
||||
|
||||
LoadCustomTaskSettings(event->TaskIndex, (byte*)&P036_deviceTemplate, sizeof(P036_deviceTemplate));
|
||||
|
||||
for (byte varNr = 0; varNr < P36_Nlines; varNr++)
|
||||
{
|
||||
addFormTextBox(string, String(F("Line ")) + (varNr + 1), String(F("Plugin_036_template")) + (varNr + 1), P036_deviceTemplate[varNr], P36_Nchars);
|
||||
addFormTextBox(String(F("Line ")) + (varNr + 1), String(F("Plugin_036_template")) + (varNr + 1), P036_deviceTemplate[varNr], P36_Nchars);
|
||||
}
|
||||
|
||||
addFormPinSelect(string, F("Display button"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
addFormPinSelect(F("Display button"), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
|
||||
addFormNumericBox(string, F("Display Timeout"), F("plugin_036_timer"), Settings.TaskDevicePluginConfig[event->TaskIndex][4]);
|
||||
addFormNumericBox(F("Display Timeout"), F("plugin_036_timer"), Settings.TaskDevicePluginConfig[event->TaskIndex][4]);
|
||||
|
||||
byte choice6 = Settings.TaskDevicePluginConfig[event->TaskIndex][6];
|
||||
if (choice6 == 0) choice6 = P36_CONTRAST_HIGH;
|
||||
@@ -159,7 +159,7 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
|
||||
optionValues6[0] = P36_CONTRAST_LOW;
|
||||
optionValues6[1] = P36_CONTRAST_MED;
|
||||
optionValues6[2] = P36_CONTRAST_HIGH;
|
||||
addFormSelector(string, F("Contrast"), F("plugin_036_contrast"), 3, options6, optionValues6, choice6);
|
||||
addFormSelector(F("Contrast"), F("plugin_036_contrast"), 3, options6, optionValues6, choice6);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -20,8 +20,26 @@
|
||||
|
||||
// Declare a Wifi client for this plugin only
|
||||
|
||||
// TODO TD-er: These must be kept in some vector to allow multiple instances of MQTT import.
|
||||
WiFiClient espclient_037;
|
||||
PubSubClient *MQTTclient_037;
|
||||
PubSubClient *MQTTclient_037 = NULL;
|
||||
bool MQTTclient_037_connected = false;
|
||||
|
||||
void Plugin_037_update_connect_status() {
|
||||
bool connected = false;
|
||||
if (MQTTclient_037 != NULL) {
|
||||
connected = MQTTclient_037->connected();
|
||||
}
|
||||
if (MQTTclient_037_connected != connected) {
|
||||
MQTTclient_037_connected = !MQTTclient_037_connected;
|
||||
if (Settings.UseRules) {
|
||||
String event = connected ? F("MQTTimport#Connected") : F("MQTTimport#Disconnected");
|
||||
rulesProcessing(event);
|
||||
}
|
||||
if (!connected)
|
||||
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Connection lost"));
|
||||
}
|
||||
}
|
||||
|
||||
boolean Plugin_037(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
@@ -74,7 +92,7 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
for (byte varNr = 0; varNr < 4; varNr++)
|
||||
{
|
||||
addFormTextBox(string, String(F("MQTT Topic ")) + (varNr + 1), String(F("Plugin_037_template")) +
|
||||
addFormTextBox(String(F("MQTT Topic ")) + (varNr + 1), String(F("Plugin_037_template")) +
|
||||
(varNr + 1), deviceTemplate[varNr], 40);
|
||||
}
|
||||
success = true;
|
||||
@@ -122,7 +140,9 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_TEN_PER_SECOND:
|
||||
{
|
||||
MQTTclient_037->loop(); // Listen out for callbacks
|
||||
if (!MQTTclient_037->loop()) { // Listen out for callbacks
|
||||
Plugin_037_update_connect_status();
|
||||
}
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
@@ -134,13 +154,11 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
|
||||
if (!MQTTclient_037->connected() || MQTTclient_should_reconnect) {
|
||||
if (MQTTclient_should_reconnect) {
|
||||
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Intentional reconnect"));
|
||||
} else {
|
||||
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Connection lost"));
|
||||
}
|
||||
|
||||
|
||||
MQTTclient_037->disconnect();
|
||||
delay(1000);
|
||||
Plugin_037_update_connect_status();
|
||||
delay(250);
|
||||
|
||||
if (! MQTTConnect_037(ClientName)) {
|
||||
success = false;
|
||||
@@ -339,7 +357,8 @@ boolean MQTTConnect_037(String clientid)
|
||||
if (MQTTclient_037->connected()) return true;
|
||||
|
||||
// define stuff for the client - this could also be done in the intial declaration of MQTTclient_037
|
||||
if (!WiFiConnected(1000)) {
|
||||
if (!WiFiConnected(100)) {
|
||||
Plugin_037_update_connect_status();
|
||||
return false; // Not connected, so no use in wasting time to connect to a host.
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
@@ -380,7 +399,7 @@ boolean MQTTConnect_037(String clientid)
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Plugin_037_update_connect_status();
|
||||
return MQTTclient_037->connected();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ Adafruit_NeoPixel *Plugin_038_pixels;
|
||||
|
||||
#define PLUGIN_038
|
||||
#define PLUGIN_ID_038 38
|
||||
#define PLUGIN_NAME_038 "Output - NeoPixel (basic)"
|
||||
#define PLUGIN_NAME_038 "Output - NeoPixel (Basic)"
|
||||
#define PLUGIN_VALUENAME1_038 ""
|
||||
|
||||
int MaxPixels = 0;
|
||||
@@ -65,9 +65,9 @@ boolean Plugin_038(byte function, struct EventStruct *event, String& string)
|
||||
const String options[] = { F("GRB"), F("GRBW") };
|
||||
int indices[] = { 1, 2 };
|
||||
|
||||
addFormNumericBox(string, F("Led Count"), F("plugin_038_leds"), Settings.TaskDevicePluginConfig[event->TaskIndex][0],1,999);
|
||||
addFormPinSelect(string, F("GPIO"), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
addFormSelector(string, F("Strip Type"), F("plugin_038_strip"), 2, options, indices, Settings.TaskDevicePluginConfig[event->TaskIndex][1] );
|
||||
addFormNumericBox(F("Led Count"), F("plugin_038_leds"), Settings.TaskDevicePluginConfig[event->TaskIndex][0],1,999);
|
||||
addFormPinSelect(F("GPIO"), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
addFormSelector(F("Strip Type"), F("plugin_038_strip"), 2, options, indices, Settings.TaskDevicePluginConfig[event->TaskIndex][1] );
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -104,8 +104,8 @@ boolean Plugin_039(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormNote(string, F("<b>1st GPIO</b> = CS (Usable GPIOs : 0, 2, 4, 5, 15)"));
|
||||
//string += F("<TR><TD>Info GPIO:<TD><b>1st GPIO</b> = CS (Usable GPIOs : 0, 2, 4, 5, 15)");
|
||||
addFormNote(F("<b>1st GPIO</b> = CS (Usable GPIOs : 0, 2, 4, 5, 15)"));
|
||||
//addHtml(F("<TR><TD>Info GPIO:<TD><b>1st GPIO</b> = CS (Usable GPIOs : 0, 2, 4, 5, 15)"));
|
||||
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
String options[2];
|
||||
@@ -113,7 +113,7 @@ boolean Plugin_039(byte function, struct EventStruct *event, String& string)
|
||||
options[1] = F("MAX 31855");
|
||||
//options[2] = F("MAX 31865");
|
||||
int optionValues[2] = { 1, 2 };
|
||||
addFormSelector(string, F("Adapter IC"), F("plugin_039_maxtype"), 2, options, optionValues, choice);
|
||||
addFormSelector(F("Adapter IC"), F("plugin_039_maxtype"), 2, options, optionValues, choice);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -51,9 +51,9 @@ boolean Plugin_041(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormNumericBox(string, F("Red"), F("plugin_041_red"), Settings.TaskDevicePluginConfig[event->TaskIndex][0], 0, 255);
|
||||
addFormNumericBox(string, F("Green"), F("plugin_041_green"), Settings.TaskDevicePluginConfig[event->TaskIndex][1], 0, 255);
|
||||
addFormNumericBox(string, F("Blue"), F("plugin_041_blue"), Settings.TaskDevicePluginConfig[event->TaskIndex][2], 0, 255);
|
||||
addFormNumericBox(F("Red"), F("plugin_041_red"), Settings.TaskDevicePluginConfig[event->TaskIndex][0], 0, 255);
|
||||
addFormNumericBox(F("Green"), F("plugin_041_green"), Settings.TaskDevicePluginConfig[event->TaskIndex][1], 0, 255);
|
||||
addFormNumericBox(F("Blue"), F("plugin_041_blue"), Settings.TaskDevicePluginConfig[event->TaskIndex][2], 0, 255);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
+34
-34
@@ -135,7 +135,7 @@ boolean Plugin_042(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
string += F("<script src=\"jscolor.min.js\"></script>\n");
|
||||
addHtml(F("<script src=\"jscolor.min.js\"></script>\n"));
|
||||
|
||||
char tmpString[128];
|
||||
String options[8];
|
||||
@@ -157,25 +157,25 @@ boolean Plugin_042(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
// Candle Type Selection
|
||||
addFormSelector(string, F("Flame Type"), F("web_Candle_Type"), 8, options, NULL, choice);
|
||||
addFormSelector(F("Flame Type"), F("web_Candle_Type"), 8, options, NULL, choice);
|
||||
|
||||
// Advanced Color options
|
||||
Candle_color = (ColorType)Settings.TaskDevicePluginConfig[event->TaskIndex][5];
|
||||
string += F("<TR><TD>Color Handling:<TD>"); // checked
|
||||
string += F("<input type='radio' id='web_Color_Default' name='web_Color_Type' value='0'");
|
||||
addHtml(F("<TR><TD>Color Handling:<TD>")); // checked
|
||||
addHtml(F("<input type='radio' id='web_Color_Default' name='web_Color_Type' value='0'"));
|
||||
if (Candle_color == ColorDefault) {
|
||||
string += F(" checked>");
|
||||
addHtml(F(" checked>"));
|
||||
} else {
|
||||
string += F(">");
|
||||
addHtml(F(">"));
|
||||
}
|
||||
string += F("<label for='web_Color_Default'> Use default color</label><br>");
|
||||
string += F("<input type='radio' id='web_Color_Selected' name='web_Color_Type' value='1'");
|
||||
addHtml(F("<label for='web_Color_Default'> Use default color</label><br>"));
|
||||
addHtml(F("<input type='radio' id='web_Color_Selected' name='web_Color_Type' value='1'"));
|
||||
if (Candle_color == ColorSelected) {
|
||||
string += F(" checked>");
|
||||
addHtml(F(" checked>"));
|
||||
} else {
|
||||
string += F(">");
|
||||
addHtml(F(">"));
|
||||
}
|
||||
string += F("<label for='web_Color_Selected'> Use selected color</label><br>");
|
||||
addHtml(F("<label for='web_Color_Selected'> Use selected color</label><br>"));
|
||||
|
||||
// Color Selection
|
||||
char hexvalue[7] = {0};
|
||||
@@ -185,36 +185,36 @@ boolean Plugin_042(byte function, struct EventStruct *event, String& string)
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
|
||||
// http://jscolor.com/examples/
|
||||
string += F("<TR><TD>Color:<TD><input class=\"jscolor {onFineChange:'update(this)'}\" value='");
|
||||
string += hexvalue;
|
||||
string += F("'>");
|
||||
addFormNumericBox(string, F("RGB Color"), F("web_RGB_Red"), Settings.TaskDevicePluginConfig[event->TaskIndex][0], 0, 255);
|
||||
addNumericBox(string, F("web_RGB_Green"), Settings.TaskDevicePluginConfig[event->TaskIndex][1], 0, 255);
|
||||
addNumericBox(string, F("web_RGB_Blue"), Settings.TaskDevicePluginConfig[event->TaskIndex][2], 0, 255);
|
||||
addHtml(F("<TR><TD>Color:<TD><input class=\"jscolor {onFineChange:'update(this)'}\" value='"));
|
||||
addHtml(hexvalue);
|
||||
addHtml(F("'>"));
|
||||
addFormNumericBox(F("RGB Color"), F("web_RGB_Red"), Settings.TaskDevicePluginConfig[event->TaskIndex][0], 0, 255);
|
||||
addNumericBox(F("web_RGB_Green"), Settings.TaskDevicePluginConfig[event->TaskIndex][1], 0, 255);
|
||||
addNumericBox(F("web_RGB_Blue"), Settings.TaskDevicePluginConfig[event->TaskIndex][2], 0, 255);
|
||||
|
||||
// Brightness Selection
|
||||
string += F("<TR><TD>Brightness:<TD>min<input type='range' id='web_Bright_Slide' min='0' max='255' value='");
|
||||
string += Settings.TaskDevicePluginConfig[event->TaskIndex][3];
|
||||
string += F("'> max");
|
||||
addHtml(F("<TR><TD>Brightness:<TD>min<input type='range' id='web_Bright_Slide' min='0' max='255' value='"));
|
||||
addHtml(String(Settings.TaskDevicePluginConfig[event->TaskIndex][3]));
|
||||
addHtml(F("'> max"));
|
||||
|
||||
sprintf_P(tmpString, PSTR("<TR><TD>Brightness Value:<TD><input type='text' name='web_Bright_Text' id='web_Bright_Text' size='3' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
string += tmpString;
|
||||
addHtml(tmpString);
|
||||
|
||||
// Some Javascript we need to update the items
|
||||
string += F("<script script type='text/javascript'>");
|
||||
string += F("function update(picker) {");
|
||||
string += F(" document.getElementById('web_RGB_Red').value = Math.round(picker.rgb[0]);");
|
||||
string += F(" document.getElementById('web_RGB_Green').value = Math.round(picker.rgb[1]);");
|
||||
string += F(" document.getElementById('web_RGB_Blue').value = Math.round(picker.rgb[2]);");
|
||||
string += F("}");
|
||||
string += F("</script>");
|
||||
addHtml(F("<script script type='text/javascript'>"));
|
||||
addHtml(F("function update(picker) {"));
|
||||
addHtml(F(" document.getElementById('web_RGB_Red').value = Math.round(picker.rgb[0]);"));
|
||||
addHtml(F(" document.getElementById('web_RGB_Green').value = Math.round(picker.rgb[1]);"));
|
||||
addHtml(F(" document.getElementById('web_RGB_Blue').value = Math.round(picker.rgb[2]);"));
|
||||
addHtml(F("}"));
|
||||
addHtml(F("</script>"));
|
||||
|
||||
string += F("<script type='text/javascript'>window.addEventListener('load', function(){");
|
||||
string += F("var slider = document.getElementById('web_Bright_Slide');");
|
||||
string += F("slider.addEventListener('change', function(){");
|
||||
string += F("document.getElementById('web_Bright_Text').value = this.value;");
|
||||
string += F("});");
|
||||
string += F("});</script>");
|
||||
addHtml(F("<script type='text/javascript'>window.addEventListener('load', function(){"));
|
||||
addHtml(F("var slider = document.getElementById('web_Bright_Slide');"));
|
||||
addHtml(F("slider.addEventListener('change', function(){"));
|
||||
addHtml(F("document.getElementById('web_Bright_Text').value = this.value;"));
|
||||
addHtml(F("});"));
|
||||
addHtml(F("});</script>"));
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+10
-10
@@ -50,18 +50,18 @@ boolean Plugin_043(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
for (byte x = 0; x < PLUGIN_043_MAX_SETTINGS; x++)
|
||||
{
|
||||
addFormTextBox(string, String(F("Day,Time ")) + (x + 1), String(F("plugin_043_clock")) + (x), timeLong2String(ExtraTaskSettings.TaskDevicePluginConfigLong[x]), 32);
|
||||
// string += F("<TR><TD>Day,Time ");
|
||||
// string += x+1;
|
||||
// string += F(":<TD><input type='text' name='plugin_043_clock");
|
||||
// string += x;
|
||||
// string += F("' value='");
|
||||
// string += timeLong2String(ExtraTaskSettings.TaskDevicePluginConfigLong[x]);
|
||||
// string += F("'>");
|
||||
addFormTextBox(String(F("Day,Time ")) + (x + 1), String(F("plugin_043_clock")) + (x), timeLong2String(ExtraTaskSettings.TaskDevicePluginConfigLong[x]), 32);
|
||||
// addHtml(F("<TR><TD>Day,Time "));
|
||||
// addHtml(x+1);
|
||||
// addHtml(F(":<TD><input type='text' name='plugin_043_clock"));
|
||||
// addHtml(x);
|
||||
// addHtml(F("' value='"));
|
||||
// addHtml(timeLong2String(ExtraTaskSettings.TaskDevicePluginConfigLong[x]));
|
||||
// addHtml(F("'>"));
|
||||
|
||||
string += F(" ");
|
||||
addHtml(F(" "));
|
||||
byte choice = ExtraTaskSettings.TaskDevicePluginConfig[x];
|
||||
addSelector(string, String(F("plugin_043_state")) + (x), 3, options, NULL, NULL, choice, false);
|
||||
addSelector(String(F("plugin_043_state")) + (x), 3, options, NULL, NULL, choice, false);
|
||||
}
|
||||
success = true;
|
||||
break;
|
||||
|
||||
@@ -66,9 +66,9 @@ boolean Plugin_044(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormNumericBox(string, F("TCP Port"), F("plugin_044_port"), ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
|
||||
addFormNumericBox(string, F("Baud Rate"), F("plugin_044_baud"), ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
|
||||
addFormNumericBox(string, F("Data bits"), F("plugin_044_data"), ExtraTaskSettings.TaskDevicePluginConfigLong[2]);
|
||||
addFormNumericBox(F("TCP Port"), F("plugin_044_port"), ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
|
||||
addFormNumericBox(F("Baud Rate"), F("plugin_044_baud"), ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
|
||||
addFormNumericBox(F("Data bits"), F("plugin_044_data"), ExtraTaskSettings.TaskDevicePluginConfigLong[2]);
|
||||
|
||||
byte choice = ExtraTaskSettings.TaskDevicePluginConfigLong[3];
|
||||
String options[3];
|
||||
@@ -76,13 +76,13 @@ boolean Plugin_044(byte function, struct EventStruct *event, String& string)
|
||||
options[1] = F("Even");
|
||||
options[2] = F("Odd");
|
||||
int optionValues[3] = { 0, 2, 3 };
|
||||
addFormSelector(string, F("Parity"), F("plugin_044_parity"), 3, options, optionValues, choice);
|
||||
addFormSelector(F("Parity"), F("plugin_044_parity"), 3, options, optionValues, choice);
|
||||
|
||||
addFormNumericBox(string, F("Stop bits"), F("plugin_044_stop"), ExtraTaskSettings.TaskDevicePluginConfigLong[4]);
|
||||
addFormNumericBox(F("Stop bits"), F("plugin_044_stop"), ExtraTaskSettings.TaskDevicePluginConfigLong[4]);
|
||||
|
||||
addFormPinSelect(string, F("Reset target after boot"), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
addFormPinSelect(F("Reset target after boot"), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
|
||||
addFormNumericBox(string, F("RX Receive Timeout (mSec)"), F("plugin_044_rxwait"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
addFormNumericBox(F("RX Receive Timeout (mSec)"), F("plugin_044_rxwait"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
|
||||
+17
-19
@@ -55,7 +55,6 @@
|
||||
// Settings.TaskDevicePluginConfigLong[x][0] - Minimal detection threshold counter
|
||||
// Settings.TaskDevicePluginConfigLong[x][1] - Detection threshold window counter
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define MPU6050_RA_GYRO_CONFIG 0x1B
|
||||
#define MPU6050_RA_ACCEL_CONFIG 0x1C
|
||||
@@ -123,8 +122,8 @@ boolean Plugin_045(byte function, struct EventStruct *event, String& string)
|
||||
int optionValues[2];
|
||||
optionValues[0] = 0x68;
|
||||
optionValues[1] = 0x69;
|
||||
addFormSelectorI2C(string, F("plugin_045_address"), 2, optionValues, choice);
|
||||
addFormNote(string, F("ADDR Low=0x68, High=0x69"));
|
||||
addFormSelectorI2C(F("plugin_045_address"), 2, optionValues, choice);
|
||||
addFormNote(F("ADDR Low=0x68, High=0x69"));
|
||||
|
||||
choice = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String options[10];
|
||||
@@ -138,28 +137,28 @@ boolean Plugin_045(byte function, struct EventStruct *event, String& string)
|
||||
options[7] = F("G-force X");
|
||||
options[8] = F("G-force Y");
|
||||
options[9] = F("G-force Z");
|
||||
addFormSelector(string, F("Function"), F("plugin_045_function"), 10, options, NULL, choice);
|
||||
addFormSelector(F("Function"), F("plugin_045_function"), 10, options, NULL, choice);
|
||||
|
||||
if (choice == 0) {
|
||||
// If this is instance function 0, setup webform for additional vars
|
||||
// Show some user information about the webform and what the vars mean.
|
||||
string += F("<TR><TD><TD>The thresholdvalues (0-65535) can be used to set a threshold for one or more<br>");
|
||||
string += F("axis. The axis will trigger when the range for that axis exceeds the threshold<br>");
|
||||
string += F("value. A value of 0 disables movement detection for that axis.");
|
||||
addHtml(F("<TR><TD><TD>The thresholdvalues (0-65535) can be used to set a threshold for one or more<br>"));
|
||||
addHtml(F("axis. The axis will trigger when the range for that axis exceeds the threshold<br>"));
|
||||
addHtml(F("value. A value of 0 disables movement detection for that axis."));
|
||||
|
||||
addFormNumericBox(string, F("Detection threshold X"), F("plugin_045_threshold_x"), Settings.TaskDevicePluginConfig[event->TaskIndex][2], 0, 65535);
|
||||
addFormNumericBox(string, F("Detection threshold Y"), F("plugin_045_threshold_y"), Settings.TaskDevicePluginConfig[event->TaskIndex][3], 0, 65535);
|
||||
addFormNumericBox(string, F("Detection threshold Z"), F("plugin_045_threshold_z"), Settings.TaskDevicePluginConfig[event->TaskIndex][4], 0, 65535);
|
||||
addFormNumericBox(F("Detection threshold X"), F("plugin_045_threshold_x"), Settings.TaskDevicePluginConfig[event->TaskIndex][2], 0, 65535);
|
||||
addFormNumericBox(F("Detection threshold Y"), F("plugin_045_threshold_y"), Settings.TaskDevicePluginConfig[event->TaskIndex][3], 0, 65535);
|
||||
addFormNumericBox(F("Detection threshold Z"), F("plugin_045_threshold_z"), Settings.TaskDevicePluginConfig[event->TaskIndex][4], 0, 65535);
|
||||
|
||||
string += F("<TR><TD><TD>Each 30 seconds a counter for the detection window is increased plus all axis<br>");
|
||||
string += F("are checked and if they *all* exceeded the threshold values, a counter is increased.<br>");
|
||||
string += F("Each period, defined by the [detection window], the counter is checked against<br>");
|
||||
string += F("the [min. detection count] and if found equal or larger, movement is detected.<br>");
|
||||
string += F("If in the next window the [min. detection count] value is not met, movement has stopped.");
|
||||
string += F("The [detection window] cannot be smaller than the [min. detection count].");
|
||||
addHtml(F("<TR><TD><TD>Each 30 seconds a counter for the detection window is increased plus all axis<br>"));
|
||||
addHtml(F("are checked and if they *all* exceeded the threshold values, a counter is increased.<br>"));
|
||||
addHtml(F("Each period, defined by the [detection window], the counter is checked against<br>"));
|
||||
addHtml(F("the [min. detection count] and if found equal or larger, movement is detected.<br>"));
|
||||
addHtml(F("If in the next window the [min. detection count] value is not met, movement has stopped."));
|
||||
addHtml(F("The [detection window] cannot be smaller than the [min. detection count]."));
|
||||
|
||||
addFormNumericBox(string, F("Min. detection count"), F("plugin_045_threshold_counter"), Settings.TaskDevicePluginConfig[event->TaskIndex][5], 0, 999999);
|
||||
addFormNumericBox(string, F("Detection window"), F("plugin_045_threshold_window"), Settings.TaskDevicePluginConfig[event->TaskIndex][6], 0, 999999);
|
||||
addFormNumericBox(F("Min. detection count"), F("plugin_045_threshold_counter"), Settings.TaskDevicePluginConfig[event->TaskIndex][5], 0, 999999);
|
||||
addFormNumericBox(F("Detection window"), F("plugin_045_threshold_window"), Settings.TaskDevicePluginConfig[event->TaskIndex][6], 0, 999999);
|
||||
|
||||
}
|
||||
success = true;
|
||||
@@ -401,5 +400,4 @@ void _P045_writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t
|
||||
Wire.endTransmission();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // USES_P045
|
||||
|
||||
+29
-30
@@ -78,7 +78,6 @@
|
||||
|
||||
//edwin: Disabled for now: hardware is not generic enough and uses lots of ram and iram,
|
||||
#ifdef PLUGIN_BUILD_DISABLED
|
||||
// #ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define PLUGIN_046_DEBUG true // Shows received frames and crc in log@INFO
|
||||
|
||||
@@ -155,74 +154,74 @@ boolean Plugin_046(byte function, struct EventStruct *event, String& string)
|
||||
options[7] = F("Unknown 2, byte 16");
|
||||
options[8] = F("Unknown 3, byte 19");
|
||||
|
||||
addFormSelector(string, F("Plugin function"), F("plugin_046"), nrchoices, options, NULL, choice);
|
||||
addFormSelector(F("Plugin function"), F("plugin_046"), nrchoices, options, NULL, choice);
|
||||
|
||||
if (choice==0) {
|
||||
string += F("<TR><TD>1st GPIO (5-MOSI):<TD>");
|
||||
addPinSelect(false, string, "taskdevicepin1", Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
string += F("<TR><TD>2nd GPIO (6-SCLK):<TD>");
|
||||
addPinSelect(false, string, "taskdevicepin2", Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
string += F("<TR><TD>3rd GPIO (7-nSEL):<TD>");
|
||||
addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
string += F("<TR><TD>4th GPIO (8-MISO):<TD>");
|
||||
addPinSelect(false, string, "taskdeviceport", Settings.TaskDevicePluginConfig[event->TaskIndex][4]);
|
||||
addHtml(F("<TR><TD>1st GPIO (5-MOSI):<TD>"));
|
||||
addPinSelect(false, "taskdevicepin1", Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addHtml(F("<TR><TD>2nd GPIO (6-SCLK):<TD>"));
|
||||
addPinSelect(false, "taskdevicepin2", Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
addHtml(F("<TR><TD>3rd GPIO (7-nSEL):<TD>"));
|
||||
addPinSelect(false, "taskdevicepin3", Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
|
||||
addHtml(F("<TR><TD>4th GPIO (8-MISO):<TD>"));
|
||||
addPinSelect(false, "taskdeviceport", Settings.TaskDevicePluginConfig[event->TaskIndex][4]);
|
||||
}
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case (0):
|
||||
{
|
||||
string += F("<TR><TD><B>Be sure you only have 1 main plugin!</B></TD>");
|
||||
string += F("<TR><TD>Value 1: Temperature, 1 decimal<BR>Value 2: Humidity, 0 decimals");
|
||||
string += F("<BR>Value 3: not used</TD>");
|
||||
addHtml(F("<TR><TD><B>Be sure you only have 1 main plugin!</B></TD>"));
|
||||
addHtml(F("<TR><TD>Value 1: Temperature, 1 decimal<BR>Value 2: Humidity, 0 decimals"));
|
||||
addHtml(F("<BR>Value 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
case (1):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Direction, 0 decimals<BR>");
|
||||
string += F("Value 2: Average, 1 decimal<Br>Value 3: Gust, 1 decimal</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Direction, 0 decimals<BR>"));
|
||||
addHtml(F("Value 2: Average, 1 decimal<Br>Value 3: Gust, 1 decimal</TD>"));
|
||||
break;
|
||||
}
|
||||
case (2):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Rain in mm per hour<BR>Value 2: Total rain in mm");
|
||||
string += F("<BR>Value 3: not used</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Rain in mm per hour<BR>Value 2: Total rain in mm"));
|
||||
addHtml(F("<BR>Value 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
case (3):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: UV, 1 decimal");
|
||||
string += F("<BR>Values 2, 3</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: UV, 1 decimal"));
|
||||
addHtml(F("<BR>Values 2, 3</TD>"));
|
||||
break;
|
||||
}
|
||||
case (4):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Strikes this hour, 0 decimals");
|
||||
string += F("<BR>Values 2, 3: not used</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Strikes this hour, 0 decimals"));
|
||||
addHtml(F("<BR>Values 2, 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
case (5):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Distance in km, 0 decimals");
|
||||
string += F("<BR>Values 2, 3: not used</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Distance in km, 0 decimals"));
|
||||
addHtml(F("<BR>Values 2, 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
case (6):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Batterybyte, 0 decimals");
|
||||
string += F("<BR>Values 2, 3: not used</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Batterybyte, 0 decimals"));
|
||||
addHtml(F("<BR>Values 2, 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
case (7):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Last rainbyte, 0 decimals");
|
||||
string += F("<BR>Values 2, 3: not used</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Last rainbyte, 0 decimals"));
|
||||
addHtml(F("<BR>Values 2, 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
case (8):
|
||||
{
|
||||
string += F("<TR><TD>Value 1: Last lightningbyte, 0 decimals");
|
||||
string += F("<BR>Values 2, 3: not used</TD>");
|
||||
addHtml(F("<TR><TD>Value 1: Last lightningbyte, 0 decimals"));
|
||||
addHtml(F("<BR>Values 2, 3: not used</TD>"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -499,5 +498,5 @@ void Plugin_046_ISR_SCLK() // Interrupt on
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // PLUGIN_BUILD_DISABLED
|
||||
#endif // USES_P046
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
// this code is based on version 1.1.2 of the above library
|
||||
//
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define PLUGIN_047
|
||||
#define PLUGIN_ID_047 47
|
||||
@@ -76,20 +75,20 @@ boolean Plugin_047(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormTextBox(string, F("I2C Address (Hex)"), F("plugin_047_i2cSoilMoisture_i2cAddress"), String(F("0x")) +
|
||||
addFormTextBox(F("I2C Address (Hex)"), F("plugin_047_i2cSoilMoisture_i2cAddress"), String(F("0x")) +
|
||||
String(Settings.TaskDevicePluginConfig[event->TaskIndex][0],HEX), 4);
|
||||
|
||||
addFormCheckBox(string, F("Send sensor to sleep"), F("plugin_047_sleep"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
addFormCheckBox(F("Send sensor to sleep"), F("plugin_047_sleep"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
|
||||
addFormCheckBox(string, F("Check sensor version") ,F("plugin_047_version"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
addFormCheckBox(F("Check sensor version") ,F("plugin_047_version"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
|
||||
addFormSeparator(string);
|
||||
addFormSeparator(2);
|
||||
|
||||
addFormCheckBox(string, F("Change Sensor address"),F("plugin_047_changeAddr"), false);
|
||||
addFormTextBox(string, F("Change I2C Addr. to (Hex)"), F("plugin_047_i2cSoilMoisture_changeAddr"), String(F("0x")) +
|
||||
addFormCheckBox(F("Change Sensor address"),F("plugin_047_changeAddr"), false);
|
||||
addFormTextBox(F("Change I2C Addr. to (Hex)"), F("plugin_047_i2cSoilMoisture_changeAddr"), String(F("0x")) +
|
||||
String(Settings.TaskDevicePluginConfig[event->TaskIndex][0],HEX), 4);
|
||||
|
||||
addFormSeparator(string);
|
||||
addFormSeparator(2);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
@@ -302,5 +301,4 @@ bool Plugin_047_setAddress(int addr) {
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif // USES_P047
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
// written by https://github.com/krikk
|
||||
// Currently DC Motors and Steppers are implemented, Servos are in default firmware!!!
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#include <Adafruit_MotorShield.h>
|
||||
|
||||
@@ -59,13 +58,13 @@ boolean Plugin_048(byte function, struct EventStruct *event, String& string) {
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD: {
|
||||
|
||||
addFormTextBox(string, F("I2C Address (Hex)"), F("plugin_048_adr"), String(F("0x")) +
|
||||
addFormTextBox(F("I2C Address (Hex)"), F("plugin_048_adr"), String(F("0x")) +
|
||||
String(Settings.TaskDevicePluginConfig[event->TaskIndex][0],HEX), 4);
|
||||
|
||||
addFormNumericBox(string, F("Stepper: steps per revolution"), F("plugin_048_MotorStepsPerRevolution")
|
||||
addFormNumericBox(F("Stepper: steps per revolution"), F("plugin_048_MotorStepsPerRevolution")
|
||||
, Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
|
||||
|
||||
addFormNumericBox(string, F("Stepper speed (rpm)"), F("plugin_048_StepperSpeed")
|
||||
addFormNumericBox(F("Stepper speed (rpm)"), F("plugin_048_StepperSpeed")
|
||||
, Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
|
||||
|
||||
success = true;
|
||||
@@ -276,5 +275,4 @@ boolean Plugin_048(byte function, struct EventStruct *event, String& string) {
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif // USES_P048
|
||||
|
||||
+57
-12
@@ -6,10 +6,25 @@
|
||||
Additional features based on https://geektimes.ru/post/285572/ by Gerben (infernix__AT__gmail.com)
|
||||
|
||||
This plugin reads the CO2 value from MH-Z19 NDIR Sensor
|
||||
DevicePin1 - is RX for ESP
|
||||
DevicePin2 - is TX for ESP
|
||||
|
||||
Pin-out:
|
||||
Hd o
|
||||
SR o o PWM
|
||||
Tx o o AOT
|
||||
Rx o o GND
|
||||
Vo o o Vin
|
||||
(bottom view)
|
||||
Skipping pin numbers due to inconsistancies in individual data sheet revisions.
|
||||
MHZ19: Connection:
|
||||
VCC 5 V
|
||||
GND GND
|
||||
Tx ESP8266 1st GPIO specified in Device-settings
|
||||
Rx ESP8266 2nd GPIO specified in Device-settings
|
||||
*/
|
||||
|
||||
// Uncomment the following define to enable the detection range commands:
|
||||
//#define ENABLE_DETECTION_RANGE_COMMANDS
|
||||
|
||||
#define PLUGIN_049
|
||||
#define PLUGIN_ID_049 49
|
||||
#define PLUGIN_NAME_049 "Gases - CO2 MH-Z19"
|
||||
@@ -37,31 +52,56 @@ enum mhzCommands : byte { mhzCmdReadPPM,
|
||||
mhzCmdABCEnable,
|
||||
mhzCmdABCDisable,
|
||||
mhzCmdReset,
|
||||
#ifdef ENABLE_DETECTION_RANGE_COMMANDS
|
||||
mhzCmdMeasurementRange1000,
|
||||
mhzCmdMeasurementRange2000,
|
||||
mhzCmdMeasurementRange3000,
|
||||
mhzCmdMeasurementRange5000 };
|
||||
mhzCmdMeasurementRange5000
|
||||
#endif
|
||||
};
|
||||
// 9 byte commands:
|
||||
// mhzCmdReadPPM[] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
|
||||
// mhzCmdCalibrateZero[] = {0xFF,0x01,0x87,0x00,0x00,0x00,0x00,0x00,0x78};
|
||||
// mhzCmdABCEnable[] = {0xFF,0x01,0x79,0xA0,0x00,0x00,0x00,0x00,0xE6};
|
||||
// mhzCmdABCDisable[] = {0xFF,0x01,0x79,0x00,0x00,0x00,0x00,0x00,0x86};
|
||||
// mhzCmdReset[] = {0xFF,0x01,0x8d,0x00,0x00,0x00,0x00,0x00,0x72};
|
||||
// mhzCmdMeasurementRange1000[] = {0xFF,0x01,0x99,0x03,0xE8,0x00,0x00,0x00,0x7B};
|
||||
// mhzCmdMeasurementRange2000[] = {0xFF,0x01,0x99,0x07,0xD0,0x00,0x00,0x00,0x8F};
|
||||
// mhzCmdMeasurementRange3000[] = {0xFF,0x01,0x99,0x0B,0xB8,0x00,0x00,0x00,0xA3};
|
||||
// mhzCmdMeasurementRange5000[] = {0xFF,0x01,0x99,0x13,0x88,0x00,0x00,0x00,0xCB};
|
||||
// Removing redundant data, just keeping offsets [2]..[4]:
|
||||
/* It seems the offsets [3]..[4] for the detection range setting (command byte 0x99) are wrong in the latest
|
||||
* online data sheet: http://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19b-co2-ver1_0.pdf
|
||||
* According to the MH-Z19B datasheet version 1.2, valid from: 2017.03.22 (received 2018-03-07)
|
||||
* the offset should be [6]..[7] instead.
|
||||
* 0x99 - Detection range setting, send command:
|
||||
* /---------+---------+---------+---------+---------+---------+---------+---------+---------\
|
||||
* | Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 | Byte 7 | Byte 8 |
|
||||
* |---------+---------+---------+---------+---------+---------+---------+---------+---------|
|
||||
* | Start | Reserved| Command | Reserved|Detection|Detection|Detection|Detection| Checksum|
|
||||
* | Byte | | | |range |range |range |range | |
|
||||
* | | | | |24~32 bit|16~23 bit|8~15 bit |0~7 bit | |
|
||||
* |---------+---------+---------+---------+---------+---------+---------+---------+---------|
|
||||
* | 0xFF | 0x01 | 0x99 | 0x00 | Data 1 | Data 2 | Data 3 | Data 4 | Checksum|
|
||||
* \---------+---------+---------+---------+---------+---------+---------+---------+---------/
|
||||
* Note: Detection range should be 0~2000, 0~5000, 0~10000 ppm.
|
||||
* For example: set 0~2000 ppm detection range, send command: FF 01 99 00 00 00 07 D0 8F
|
||||
* set 0~10000 ppm detection range, send command: FF 01 99 00 00 00 27 10 8F
|
||||
* The latter, updated version above is implemented here.
|
||||
*/
|
||||
// mhzCmdMeasurementRange1000[] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x03,0xE8,0x7B};
|
||||
// mhzCmdMeasurementRange2000[] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x07,0xD0,0x8F};
|
||||
// mhzCmdMeasurementRange3000[] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x0B,0xB8,0xA3};
|
||||
// mhzCmdMeasurementRange5000[] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x13,0x88,0xCB};
|
||||
// Removing redundant data, just keeping offsets [2], [6]..[7]:
|
||||
const PROGMEM byte mhzCmdData[][3] = {
|
||||
{0x86,0x00,0x00},
|
||||
{0x87,0x00,0x00},
|
||||
{0x79,0xA0,0x00},
|
||||
{0x79,0x00,0x00},
|
||||
{0x8d,0x00,0x00},
|
||||
#ifdef ENABLE_DETECTION_RANGE_COMMANDS
|
||||
{0x99,0x03,0xE8},
|
||||
{0x99,0x07,0xD0},
|
||||
{0x99,0x0B,0xB8},
|
||||
{0x99,0x13,0x88}};
|
||||
{0x99,0x13,0x88}
|
||||
#endif
|
||||
};
|
||||
|
||||
byte mhzResp[9]; // 9 byte response buffer
|
||||
|
||||
@@ -163,7 +203,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)
|
||||
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
String options[2] = { F("Normal"), F("ABC disabled") };
|
||||
int optionValues[2] = { ABC_enabled, ABC_disabled };
|
||||
addFormSelector(string, F("Auto Base Calibration"), F("plugin_049_abcdisable"), 2, options, optionValues, choice);
|
||||
addFormSelector(F("Auto Base Calibration"), F("plugin_049_abcdisable"), 2, options, optionValues, choice);
|
||||
byte choiceFilter = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String filteroptions[5] = { F("Skip Unstable"), F("Use Unstable"), F("Fast Response"), F("Medium Response"), F("Slow Response") };
|
||||
int filteroptionValues[5] = {
|
||||
@@ -172,7 +212,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)
|
||||
PLUGIN_049_FILTER_FAST,
|
||||
PLUGIN_049_FILTER_MEDIUM,
|
||||
PLUGIN_049_FILTER_SLOW };
|
||||
addFormSelector(string, F("Filter"), F("plugin_049_filter"), 5, filteroptions, filteroptionValues, choiceFilter);
|
||||
addFormSelector(F("Filter"), F("plugin_049_filter"), 5, filteroptions, filteroptionValues, choiceFilter);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
@@ -246,6 +286,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)
|
||||
success = true;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DETECTION_RANGE_COMMANDS
|
||||
if (command == F("mhzmeasurementrange1000"))
|
||||
{
|
||||
_P049_send_mhzCmd(mhzCmdMeasurementRange1000);
|
||||
@@ -273,6 +314,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)
|
||||
addLog(LOG_LEVEL_INFO, F("MHZ19: Sent measurement range 0-5000PPM!"));
|
||||
success = true;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -413,6 +455,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
break;
|
||||
|
||||
//#ifdef ENABLE_DETECTION_RANGE_COMMANDS
|
||||
// Sensor responds with 0x99 whenever we send it a measurement range adjustment
|
||||
} else if (mhzResp[0] == 0xFF && mhzResp[1] == 0x99 && mhzResp[8] == checksum) {
|
||||
|
||||
@@ -420,6 +463,7 @@ boolean Plugin_049(byte function, struct EventStruct *event, String& string)
|
||||
addLog(LOG_LEVEL_INFO, F("Expecting sensor reset..."));
|
||||
success = false;
|
||||
break;
|
||||
//#endif
|
||||
|
||||
// log verbosely anything else that the sensor reports
|
||||
} else {
|
||||
@@ -457,7 +501,8 @@ size_t _P049_send_mhzCmd(byte CommandId)
|
||||
mhzResp[0] = 0xFF; // Start byte, fixed
|
||||
mhzResp[1] = 0x01; // Sensor number, 0x01 by default
|
||||
memcpy_P(&mhzResp[2], mhzCmdData[CommandId], sizeof(mhzCmdData[0]));
|
||||
mhzResp[5] = mhzResp[6] = mhzResp[7] = 0x00;
|
||||
mhzResp[6] = mhzResp[3]; mhzResp[7] = mhzResp[4];
|
||||
mhzResp[3] = mhzResp[4] = mhzResp[5] = 0x00;
|
||||
mhzResp[8] = _P049_calculateChecksum(mhzResp);
|
||||
|
||||
return Plugin_049_SoftSerial->write(mhzResp, sizeof(mhzResp));
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
// this code is based on 20170331 date version of the above library
|
||||
// this code is UNTESTED, because my TCS34725 sensor is still not shipped :(
|
||||
//
|
||||
#ifdef PLUGIN_BUILD_DEV
|
||||
|
||||
#include "Adafruit_TCS34725.h"
|
||||
|
||||
@@ -79,7 +78,7 @@ boolean Plugin_050(byte function, struct EventStruct *event, String& string)
|
||||
optionValuesMode[3] = TCS34725_INTEGRATIONTIME_101MS;
|
||||
optionValuesMode[4] = TCS34725_INTEGRATIONTIME_154MS;
|
||||
optionValuesMode[5] = TCS34725_INTEGRATIONTIME_700MS;
|
||||
addFormSelector(string, F("Integration Time"), F("plugin_050_integrationTime"), 6, optionsMode, optionValuesMode, choiceMode);
|
||||
addFormSelector(F("Integration Time"), F("plugin_050_integrationTime"), 6, optionsMode, optionValuesMode, choiceMode);
|
||||
|
||||
byte choiceMode2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String optionsMode2[4];
|
||||
@@ -92,7 +91,7 @@ boolean Plugin_050(byte function, struct EventStruct *event, String& string)
|
||||
optionValuesMode2[1] = TCS34725_GAIN_4X;
|
||||
optionValuesMode2[2] = TCS34725_GAIN_16X;
|
||||
optionValuesMode2[3] = TCS34725_GAIN_60X;
|
||||
addFormSelector(string, F("Gain"), F("plugin_050_gain"), 4, optionsMode2, optionValuesMode2, choiceMode2);
|
||||
addFormSelector(F("Gain"), F("plugin_050_gain"), 4, optionsMode2, optionValuesMode2, choiceMode2);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
@@ -176,5 +175,4 @@ boolean Plugin_050(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif // USES_P050
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
// of the above library
|
||||
//
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#include <AM2320.h>
|
||||
|
||||
@@ -102,5 +101,4 @@ boolean Plugin_051(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif // USES_P051
|
||||
|
||||
@@ -101,14 +101,14 @@ boolean Plugin_052(byte function, struct EventStruct *event, String& string)
|
||||
byte choiceSensor = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
|
||||
|
||||
String optionsSensor[7] = { F("Error Status"), F("Carbon Dioxide"), F("Temperature"), F("Humidity"), F("Relay Status"), F("Temperature Adjustment"), F("ABC period") };
|
||||
addFormSelector(string, F("Sensor"), F("plugin_052_sensor"), 7, optionsSensor, NULL, choiceSensor);
|
||||
addFormSelector(F("Sensor"), F("plugin_052_sensor"), 7, optionsSensor, NULL, choiceSensor);
|
||||
|
||||
/*
|
||||
// ABC functionality disabled for now, due to a bug in the firmware.
|
||||
// See https://github.com/letscontrolit/ESPEasy/issues/759
|
||||
byte choiceABCperiod = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
|
||||
String optionsABCperiod[9] = { F("disable"), F("1 h"), F("12 h"), F("1 day"), F("2 days"), F("4 days"), F("7 days"), F("14 days"), F("30 days") };
|
||||
addFormSelector(string, F("ABC period"), F("plugin_052_ABC_period"), 9, optionsABCperiod, NULL, choiceABCperiod);
|
||||
addFormSelector(F("ABC period"), F("plugin_052_ABC_period"), 9, optionsABCperiod, NULL, choiceABCperiod);
|
||||
*/
|
||||
|
||||
success = true;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
// together with a laser, count the amount of particles. These sensors have an integrated microcontroller
|
||||
// that counts particles and transmits measurement data over the serial connection.
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#include <ESPeasySoftwareSerial.h>
|
||||
|
||||
@@ -301,5 +300,4 @@ boolean Plugin_053(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif // PLUGIN_BUILD_TESTING
|
||||
#endif // USES_P053
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
|
||||
//#include <*.h> //no lib needed
|
||||
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
|
||||
#define PLUGIN_054
|
||||
#define PLUGIN_ID_054 54
|
||||
@@ -101,8 +100,8 @@ boolean Plugin_054(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
Settings.TaskDevicePin1[event->TaskIndex] = 2;
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = Plugin_054_DMXSize;
|
||||
addFormNote(string, F("Only GPIO-2 (D4) can be used as TX1!"));
|
||||
addFormNumericBox(string, F("Channels"), F("channels"), Plugin_054_DMXSize, 1, 512);
|
||||
addFormNote(F("Only GPIO-2 (D4) can be used as TX1!"));
|
||||
addFormNumericBox(F("Channels"), F("channels"), Plugin_054_DMXSize, 1, 512);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
@@ -256,5 +255,4 @@ boolean Plugin_054(byte function, struct EventStruct *event, String& string)
|
||||
return success;
|
||||
}
|
||||
|
||||
#endif //PLUGIN_BUILD_TESTING
|
||||
#endif // USES_P054
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user