Compare commits

..
200 Commits
Author SHA1 Message Date
ESPEasy release bot f59f25ee40 automaticly updated release notes for v2.0-20180510 2018-05-10 04:00:27 +02:00
Gijs NoorlanderandGitHub 14030ec15b Merge pull request #1395 from letscontrolit/revert-1389-patch-1
Revert "Update _P045_MPU6050.ino"
2018-05-09 23:42:50 +02:00
Gijs NoorlanderandGitHub 1fd6179408 Revert "Update _P045_MPU6050.ino" 2018-05-09 23:40:27 +02:00
Gijs NoorlanderandGitHub 22424fb03b Merge pull request #1389 from maartenpaauw/patch-1
Update _P045_MPU6050.ino
2018-05-09 23:33:26 +02:00
Maarten PaauwandGitHub 97cd06440e Update _P045_MPU6050.ino
Fix debug code (commented out code).
2018-05-08 23:14:08 +02:00
ESPEasy release bot 8346e39ac9 automaticly updated release notes for v2.0-20180322 2018-03-22 04:00:24 +01:00
TD-er 22371649a4 [WiFi] Take much more time for initial WiFi connect during setup
Accesspoint is still active, so it may take a lot more time to make the initial connection
2018-03-22 01:05:56 +01:00
Gijs NoorlanderandGitHub 8cbd9a0822 Merge pull request #1148 from TD-er/merge/mega_to_v2.0_0321
Merge/mega to v2.0 0321
2018-03-22 00:24:59 +01:00
TD-er 93f9d11738 [Memory] parseTemplate did not check if markers were found
"Free Mem" reported this function to be using quite a lot of memory.
Maybe that was related to parsing texts without matching ']' or '#'
Just added some checks to see if they were found.
2018-03-22 00:24:17 +01:00
TD-er cf3e0a3f0a [wifi] Make more robust checks and increase timeout
See #1145
2018-03-22 00:12:04 +01:00
s0170071andTD-er ccfd14dbd3 Serial WD crash 2018-03-22 00:11:48 +01:00
Bartlomiej ZimonandTD-er 3034738ad4 - P048 fetch params only when needed 2018-03-22 00:11:30 +01:00
TD-er 178d1c46a2 - P035 move strings to flash 2018-03-22 00:11:21 +01:00
Bartlomiej ZimonandTD-er cdfd1d986e - P023 fix command interpretation 2018-03-22 00:10:55 +01:00
Bartlomiej ZimonandTD-er 4b7aa53692 - P012 fix command interpretation 2018-03-22 00:10:50 +01:00
ESPEasy release bot cc02fa4481 automaticly updated release notes for v2.0-20180321 2018-03-21 04:00:21 +01:00
Gijs NoorlanderandGitHub ab3a406706 [merge issue] Forgotten #endif in merge 2018-03-20 23:46:43 +01:00
Unknown 3edfdbf5f7 [wifi] Setup with factory settings could not complete 2018-03-20 23:27:39 +01:00
ESPEasy release bot 1220c565c8 automaticly updated release notes for v2.0-20180320 2018-03-20 04:00:23 +01:00
Unknown f0987dab41 [issue #1097] WiFi connect with deepsleep enabled trigger watchdog reset
Did not allow for enough time to do background tasks while waiting for wifi connect with DeepSleep enabled.
2018-03-20 00:29:24 +01:00
Unknown af3e353181 Revert "Merge pull request #1116 from TD-er/feature/allow_own_defaults"
This reverts commit 8ccbdcadf0.
2018-03-19 22:51:23 +01:00
es-kaandUnknown c711d6ea51 Fix wiring description for SN75176 transceiver 2018-03-19 22:50:31 +01:00
ESPEasy release bot 1f084c51cc automaticly updated release notes for v2.0-20180319 2018-03-19 04:00:24 +01:00
Gijs NoorlanderandGitHub 85e8d98da8 Merge pull request #1121 from TD-er/merge/fixes_20180318_to_v2.0
Merge/fixes 20180318 to v2.0
2018-03-19 01:01:42 +01:00
Unknown 6d52a7e03a [merge] MIssing #endif due to merging. 2018-03-19 00:51:05 +01:00
Gijs Noorlander fa513b52f9 Merge pull request #1118 from TD-er/bugfix/mqtt_publish_after_deep_sleep
[issue #1097] MQTT publish after deep sleep
2018-03-19 00:46:03 +01:00
Unknown f98401524f Merge pull request #1116 from TD-er/feature/allow_own_defaults
[issue #1007] Allow user specific data in separate file
2018-03-19 00:45:52 +01:00
Unknown 4090b4f23c Merge pull request #1113 from TD-er/feature/reduce_impact_wifi_disconnect
[Relaxed WiFi] Perform WiFi initialization in steps
2018-03-19 00:42:58 +01:00
Gijs Noorlander b89c00008d Merge pull request #1114 from TD-er/feature/wifi_details_json
[JSON] Add uint name (#1099) and WiFi information (PR #1113)
2018-03-19 00:39:43 +01:00
Gijs Noorlander d57a617138 Merge pull request #1112 from uzi18/fix-p073
Fix p073 - #1111
2018-03-19 00:39:32 +01:00
Gijs Noorlander cefe6b4b7c Changed so that running all tasks immediately with deep sleep enabled… (#1110)
Changed so that running all tasks immediately with deep sleep enabled only happens on first iteration after wake up
2018-03-19 00:38:30 +01:00
Gijs Noorlander 2432740b41 - add encoder write command #1086 (#1103)
- add encoder write command #1086
2018-03-19 00:35:09 +01:00
Gijs Noorlander 44a934651c Add download button for current rule set (#1102)
Add download button for current rule set
2018-03-19 00:34:52 +01:00
ESPEasy release bot 6787bc8c0e automaticly updated release notes for v2.0-20180316 2018-03-16 04:00:23 +01:00
Gijs NoorlanderandGitHub cf644b45b1 Merge pull request #1095 from TD-er/merge/PR_1092_1093_1094
Merge/pr 1092 1093 1094
2018-03-16 00:43:16 +01:00
Unknown e6fe1c63a9 [issue #951] Changed System#Initialized => System#Wake
Changed System#Initialized  => System#Wake
New event name makes more sense and Initialized may be used later to indicate all needed connections, etc. are ready.
2018-03-16 00:38:00 +01:00
Unknown df978036f0 [issue #993] variable in MQTT subscribe topic
As [noted](https://github.com/letscontrolit/ESPEasy/issues/993#issuecomment-373140135) by @kluszcyn
2018-03-16 00:37:54 +01:00
Unknown 7cb375833d [issue #1057] AM PM display issue
X:XX PM (for hours 1...9)
X:XX AM (for hours 1...9)
XX:XX PM (for hours 10...12)
XX:XX AM (for hours 10...12)

Added for H:MM (without seconds) notations:
- `%systm_hm%`
-`%systm_hm_am%`
2018-03-16 00:37:45 +01:00
Gijs NoorlanderandGitHub 3218ea9839 Merge pull request #1091 from TD-er/merge/fixes_1073_1079_1081 into v2.0
Merge/fixes 1073 1079 1081 into v2.0
2018-03-15 23:05:06 +01:00
Gijs Noorlander eca8901fca Fixed multi instance problem on SHT3x #433 (#1081)
Fixed multi instance problem on SHT3x #433
2018-03-15 23:02:04 +01:00
Gijs Noorlander 6635eafe91 [issue #1066] Fix Webserver handle_control (#1079)
[issue #1066] Fix Webserver handle_control
2018-03-15 23:01:52 +01:00
Gijs Noorlander fe4d1f952f MCP3221 allow values for calibration (#1073)
MCP3221 allow values for calibration
2018-03-15 23:01:39 +01:00
Gijs NoorlanderandGitHub 4475a225cc Merge pull request #1090 from TD-er/merge/split_globals_v2.0
Merge/split globals v2.0
2018-03-15 22:46:46 +01:00
Unknown 2aece1c143 [v2.0 split globals] Base split on v2.0 version of ESPEasy.ino 2018-03-15 22:23:59 +01:00
Bartlomiej ZimonandUnknown 70df225e7e Merge branch 'mega' of github.com:letscontrolit/ESPEasy into mega
# Conflicts:
#	src/ESPEasy.ino
2018-03-15 22:05:36 +01:00
Unknown 19af52a3ef - move all structs from ESPEasy.ino into header file
- add some fix for headers
- add const to rtttl notes array
2018-03-15 22:05:22 +01:00
Gijs NoorlanderandGitHub 3d396575ff Merge pull request #1088 from TD-er/merge/rules_fix__and_globalsync_toV2.0
Merge/rules fix  and globalsync to v2.0
2018-03-15 21:52:41 +01:00
mvdbroandUnknown 826deaac89 Rules fix 2018-03-14 21:28:24 +01:00
mvdbroandUnknown cce621cff8 #893, part 2 receiving 2018-03-14 21:28:15 +01:00
mvdbroandUnknown 57eb38dbd0 Custom controller GUI option 2018-03-14 21:28:08 +01:00
mvdbroandUnknown fd2451bb07 #893 part1, send messages 2018-03-14 21:27:50 +01:00
ESPEasy release bot cc0b3dac26 automaticly updated release notes for v2.0-20180313 2018-03-13 04:00:23 +01:00
Gijs NoorlanderandGitHub d3434eb4d2 Merge/fix rules trailing spaces (#1065) #1074
Merge/fix rules trailing spaces (#1065)
2018-03-12 23:18:22 +01:00
Bartlomiej ZimonandUnknown bd2665041f - remove double trimm() 2018-03-12 23:15:48 +01:00
Bartlomiej ZimonandUnknown 1fd429a029 - fix for #1065 2018-03-12 23:15:40 +01:00
ESPEasy release bot e4d4463eab automaticly updated release notes for v2.0-20180312 2018-03-12 04:00:19 +01:00
Gijs NoorlanderandGitHub b29f56c6f4 Merge pull request #1063 from TD-er/merge/rule_engine_fix
Rule Engine minor fix and added dev debugging
2018-03-12 00:55:49 +01:00
Unknown 779514481d Rule Engine minor fix and added dev debugging 2018-03-12 00:52:30 +01:00
Gijs NoorlanderandGitHub 0a752dd26f Merge pull request #1062 from TD-er/merge/issue_1039
Merge/issue 1039
2018-03-12 00:44:02 +01:00
Unknown 8112e0e67a [webserver] Improve chunked transfer
Do chunked transfer using full buffer on all data sent to the streaming webserver.
2018-03-12 00:42:08 +01:00
Unknown 89a9f842fd [issue #1039 ] Change CSS to show topmost SSID on large screens
For screens with > 960 pixels width.
To show all accesspoints on AP selection.
2018-03-12 00:41:44 +01:00
ESPEasy release bot 92932fddb2 automaticly updated release notes for v2.0-20180311 2018-03-11 04:00:19 +01:00
Unknown 89581fd0fb [issue #1039] Topmost SSID are covered on mobile Browser
Added <span> tags with a class around the error, which allow the CSS to position the content below the header.
2018-03-11 01:59:51 +01:00
Unknown 3f84a961ad [DNS lookup] Controllers sometimes try to connect to 0.0.0.0
See issue #824
2018-03-11 01:38:50 +01:00
Unknown 96bfaa27f5 [OLED] fix drawProgressBar
See this PR: https://github.com/ThingPulse/esp8266-oled-ssd1306/pull/178
2018-03-10 23:04:03 +01:00
Unknown bcca0514dd [deepsleep] Make sure the 'shortcut' of running all services when sleep enabled
As pointed out on [the forum by arion_p](https://www.letscontrolit.com/forum/viewtopic.php?p=25771#p25771)
2018-03-10 23:03:55 +01:00
Gijs NoorlanderandGitHub bb9f8fc809 Merge pull request #1046 from TD-er/merge/mega_to_v2.0
Merge/mega to v2.0
2018-03-10 22:03:14 +01:00
Unknown 4d9504bce0 [P073] Remove tm1637_bitDelay()
Not used anymore
2018-03-10 22:01:27 +01:00
Unknown ff3a769033 Update P07 Plugin
added suppor for other version of TM1637 modules (4dgt+colon, 4dgt+dots,6dgt+dots)
2018-03-10 22:01:20 +01:00
Unknown e3de56a7a8 [AM/PM] Am/Pm notation doesn't have '0' hours
11.59 a.m. => 12.00 p.m.
12.59 p.m. => 1.00 p.m.
11.59 p.m. => 12.00 a.m.
2018-03-10 22:01:04 +01:00
Gijs NoorlanderandGitHub 2682b0bd2f [v2.0] Merge/rules process speed improvements (#1045)
[v2.0] Merge/rules process speed improvements
2018-03-10 21:55:25 +01:00
Unknown 5097157a09 Final ruleset speed-up
It's now down from 100 mSec to 19 mSec for 1 fully loaded non matching ruleset.
2018-03-10 21:41:13 +01:00
Unknown 02ea957894 Add read buffer to rule processing to speedup parsing
On a full ruleset (2k), a non matching event takes 100 mSec instead of 170 mSec.
2018-03-10 21:39:51 +01:00
mvdbroandUnknown c2b0d76595 Rule Engine, stop waisting time on non matching rules 2018-03-10 21:38:01 +01:00
Unknown 91b7cbe075 Improve flash read performance 2018-03-10 21:37:47 +01:00
ESPEasy release bot 64b38df187 automaticly updated release notes for v2.0-20180310 2018-03-10 04:00:20 +01:00
Gijs NoorlanderandGitHub 76f6dfdc59 Merge Mega -> v2.0: conversions & delay wifi init (#1037)
Merge Mega -> v2.0: conversions  & delay wifi init
2018-03-09 23:20:47 +01:00
Unknown 3a6f7acd15 [Conversions] Use more decimals in conversions and add AM/PM for time.
See comments on #1015
2018-03-09 23:19:19 +01:00
Unknown d65b126f84 Move plugin init before WiFi init
As suggested at PR #1032 by @M0ebiu5
2018-03-09 23:18:10 +01:00
ESPEasy release bot 8299e38b24 automaticly updated release notes for v2.0-20180309 2018-03-09 04:00:22 +01:00
Gijs NoorlanderandGitHub 67a28a7f97 Add other simple conversions like Celsius to Fahrenheit (#1033)
[issue #1015] Add other simple conversions like Celsius to Fahrenheit…
2018-03-09 00:35:06 +01:00
Unknown 18b8e61d32 [issue #1015] Add other simple conversions like Celsius to Fahrenheit, etc.
- %c_w_dir%   -  getBearing 
- %c_c2f%   -    String(CelsiusToFahrenheit) 
- %c_ms2Bft%   - String(m_secToBeaufort) 
- %c_cm2imp%   - centimeterToImperialLength 
- %c_mm2imp%   - millimeterToImperialLength 
- %c_m2day%   -  String(minutesToDay) 
- %c_m2dh%   -   minutesToDayHour 
- %c_m2dhm%   -  minutesToDayHourMinute 
- %c_s2dhms%   - secondsToDayHourMinuteSecond
2018-03-09 00:31:27 +01:00
Unknown 5821b0709c [issue #1015] Add other simple conversions like Celsius to Fahrenheit, etc.
- %c_w_dir%   -  getBearing 
- %c_c2f%   -    String(CelsiusToFahrenheit) 
- %c_ms2Bft%   - String(m_secToBeaufort) 
- %c_cm2imp%   - centimeterToImperialLength 
- %c_mm2imp%   - millimeterToImperialLength 
- %c_m2day%   -  String(minutesToDay) 
- %c_m2dh%   -   minutesToDayHour 
- %c_m2dhm%   -  minutesToDayHourMinute 
- %c_s2dhms%   - secondsToDayHourMinuteSecond
2018-03-09 00:29:52 +01:00
Unknown ec783fe03b [Rule Events] Add a number of events to handle in rules and awake timer
Changed the sleep checkbox to allow a number of seconds awake from deep sleep.

Also added the following events:

- MQTT#Connected
- WiFi#Connected
- System#Initialized
- Time#Set    Time set by an update from NTP.
- Time#Initialized  Time set for the first time since boot.
- Login#Failed

See #951
2018-03-08 23:00:33 +01:00
ESPEasy release bot 9122565431 automaticly updated release notes for v2.0-20180307 2018-03-07 04:00:21 +01:00
Unknown 64a0f79e02 [issue #1012] Removed Content-Length header + improved webserver speed
See: Web interface doesn't work on iOS #1012

The operatore+= String function now chunks long strings
2018-03-07 00:56:23 +01:00
Gijs Noorlander 92e4a8da9b [CSS] Quick fix for smaller displays (#1026)
[CSS] Quick fix for smaller displays by @doxikus
2018-03-06 21:53:54 +01:00
ESPEasy release bot 40e2d7ec8e automaticly updated release notes for v2.0-20180306 2018-03-06 04:00:17 +01:00
Gijs NoorlanderandDatuX 7318e87965 Fixes P073 plugin for latest TM1637 based 7 segments displays modules (#996) (#1022)
Fixes P073 plugin for latest TM1637 based 7 segments displays modules
2018-03-05 20:17:51 +01:00
ESPEasy release bot 9c3a28439f automaticly updated release notes for v2.0-20180305 2018-03-05 04:00:20 +01:00
Gijs NoorlanderandGitHub 127627a22c [issue #1003 ] Add conversion of wind direction to string (#1014)
[issue #1003 ] Add conversion of wind direction to string
2018-03-05 00:37:44 +01:00
Gijs NoorlanderandGitHub e59401e24f [issue #528] Set DOUT flash mode for all 1M builds (#1013)
[issue #528] Set DOUT flash mode for all 1M builds
2018-03-05 00:36:39 +01:00
Unknown 769f76d3dc [issue #1003 ] Add conversion of wind direction to string
Also made some clean-up of calls to string replacements.
Improved the lookup function to determine the wind direction (was 11.25 degree off)
Now it is also possible to add simple standard conversions like Celcius-Fahrenheit, m/s - Beaufort, etc.
2018-03-05 00:28:32 +01:00
Unknown 4eb7cf0859 [issue #528] Set DOUT flash mode for all 1M builds
See [this elaborate post on the different flash modes](https://www.esp32.com/viewtopic.php?t=1250)
2018-03-04 22:30:13 +01:00
Edwin Eefting a464f638ad automaticly updated release notes for v2.0-20180304b 2018-03-04 18:20:49 +01:00
Edwin Eefting a5cfe1beec dont build in silent mode to prevent travis timeouts 2018-03-04 18:14:27 +01:00
ESPEasy release bot a8fcb420e7 automaticly updated release notes for v2.0-20180304 2018-03-04 04:00:19 +01:00
Gijs NoorlanderandGitHub 3ed6564063 [issue #892 ] Only use sensor type when really needed (#1004)
[issue #892 ] Only use sensor type when really needed
2018-03-04 00:45:52 +01:00
Unknown 5f575c0224 [issue #892 ] Only use sensor type when really needed
Only the Domoticz controllers need the sensor type. The rest just needs the number of sensor values.
2018-03-04 00:37:18 +01:00
Gijs NoorlanderandGitHub 34c1ba158f [issue #993] Add %unit% variable in MQTT subscribe topic (PR #1002)
[issue #993] Add %unit% variable in MQTT subscribe topic
2018-03-03 22:40:18 +01:00
Unknown 04ca424085 [issue #993] Add %unit% variable in MQTT subscribe topic 2018-03-03 22:39:09 +01:00
Gijs Noorlander 7a8f476e05 _P072_HDC1080 allow to send values to the controllers (#999)
_P072_HDC1080 add success and break statement.
it seems that without the break statement and success set to true, the values aren't sent back to the controller(s).
2018-03-03 21:30:22 +01:00
Gijs Noorlander e42ab85f4b Merge pull request #1000 from uzi18/test3 (more comparisions in IF condition)
support for more comparisions in IF condition: >=,<=,!=,<>,<,>,= also fix extended conditions when first check is not '>'
2018-03-03 20:38:13 +01:00
ESPEasy release bot 3094cb5260 automaticly updated release notes for v2.0-20180303 2018-03-03 04:00:19 +01:00
Gijs NoorlanderandGitHub 0e67480f46 Merge pull request #995 from TD-er/bugfix/mqtt_proper_case
Bugfix/mqtt proper case
2018-03-03 02:19:49 +01:00
Unknown c32f2cc89d Add AND/OR to rules & prevent unwanted case changes in strings (#994) 2018-03-03 02:09:41 +01:00
Unknown ad489f0db2 [Issue #827] MQTT not using proper case for %sysname% variable.
Some functions and plugins could change strings to lowercase.
Added some check also to help debugging.
2018-03-03 02:03:20 +01:00
Gijs NoorlanderandGitHub d9267fa9c2 Add Task device type to json by @s0170071 (#991)
Add Task device type to json by @s0170071
2018-03-02 22:40:20 +01:00
Unknown e82fb37870 Add Task device type to json by @s0170071
Taken from his branch, he forgot to PR.
2018-03-02 22:30:55 +01:00
Gijs NoorlanderandGitHub 26f00dcdec [issue #293] json output nan values not double quoted (#990)
[issue #293] json output nan values not double quoted
2018-03-02 22:03:07 +01:00
Unknown b2bb1d039b [issue #293] json output nan values not double quoted
Generate valid JSON output
2018-03-02 21:49:06 +01:00
Unknown c58e975b7e revert json to non-chunking #988 from s0170071/mega
revert json to non-chunking
2018-03-02 20:40:13 +01:00
ESPEasy release bot 08312cbcb7 automaticly updated release notes for v2.0-20180302 2018-03-02 04:00:21 +01:00
Gijs NoorlanderandGitHub 953a53bb9a Merge pull request #985 from TD-er/bugfix/json_content-length
backport of "rule wildcard" + improve formatting of Webserver's StreamingBuffer
2018-03-02 01:58:53 +01:00
Unknown e9fac7926f [webserver] Layout of code to improve readability
Indentation was completely off, which made it hard to read.
Also added member json_format, which is set at start of stream.
2018-03-02 01:53:40 +01:00
mvdbroandUnknown 810a0b2aa9 Rule wildcard option on literal events
Added wildcard rule filter on literal string events
Changed "sendcontent free"content logging level to 'DEV'
2018-03-01 23:41:42 +01:00
Gijs NoorlanderandGitHub 5d9137d1d2 Merge pull request #976 from TD-er/bugfix/P053_PMSx003DustPlugin
[issue #914] _P053_PMSx003 Dust Sensor looses sync
2018-03-01 23:07:38 +01:00
Gijs Noorlander 8de49cd38e Merge pull request #983 from kahvm/mega
Added support for degree sign on LCD1602/2004
2018-03-01 22:42:58 +01:00
Gijs NoorlanderandGitHub fe1c44f6b3 Merge pull request #980 from uzi18/formatout
Format output marge from mega to v2.0
2018-03-01 22:34:08 +01:00
Gijs NoorlanderandGitHub e39d588530 Merge pull request #975 from TD-er/merge/important_fixes_from_mega
Merge/important fixes from mega
2018-03-01 22:31:36 +01:00
Unknown 4ca318f5a6 [Build error fix] Must-keep-focus-when-pressing-buttons...
Quickly commit + merge is never a good idea when some visitors arrive...
Fixed now.
2018-03-01 20:08:51 +01:00
Bartłomiej ZimońandBartlomiej Zimon 37a24933f5 add format #O to templates to show OFF/ON instead 0/1 (#949)
* - pcfgpio,port,2 sets pin as input
- fix for #222,#702 - we can mix inputs and outputs now

* - extend conditions with AND/OR, now it is possible to simplify rules

test rules:
on test do
  if [test#a]=0 or [test#b]=0 or [test#c]=0
    event ok
  else
    event nok
  endif
endon

on test2 do
  if [test#a]=1 and [test#b]=1 and [test#c]=1
    event ok
  else
    event nok
  endif
endon

on test3 do
  if [test#a]=1 and [test#b]=1 or [test#c]=0
    event ok
  else
    event nok
  endif
endon

on test4 do
  if [test#a]=0
    event ok
  else
    event nok
  endif
endon

* - remove Serial print

* - add format #O to templates to show OFF/ON instead 0/1 - eg.: Pump:[Outputs#pump#O]

* - add formating for active low outputs eg.: #O!
2018-02-28 23:06:01 +01:00
Bartlomiej Zimon a6b447600f Merge branch 'v2.0' of github.com:letscontrolit/ESPEasy into v2.0 2018-02-28 22:43:52 +01:00
Unknown 5fbb900e5b [issue #914] Check first 2 bytes of packet 2018-02-28 22:39:34 +01:00
ESPEasy release bot aa5dee01fb automaticly updated release notes for v2.0-20180228 2018-02-28 04:00:20 +01:00
Unknown 1a44ed6578 [issue #914] _P053_PMSx003 Dust Sensor looses sync
- Use peek instead of read, to make sure a complete packet is in the buffer.
- Flush buffer after processing a packet.
- Increased software serial buffer to the size of 3 packets.
- Peek (+ read garbage) 10 times per second to get the buffer in sync to start with start byte of packet.
- Decent delete + clean up of software serial allocation when changing settings (prevent memory leak)
- Move log String allocation to inside scope of function, not permanent allocated.
- Split into separate functions to make it better readable.
2018-02-28 02:11:33 +01:00
Bartłomiej ZimońandUnknown e86667e37e fix #964, add timeStringToSeconds and use it to compare time conditions (#965)
* - pcfgpio,port,2 sets pin as input
- fix for #222,#702 - we can mix inputs and outputs now

* - extend conditions with AND/OR, now it is possible to simplify rules

test rules:
on test do
  if [test#a]=0 or [test#b]=0 or [test#c]=0
    event ok
  else
    event nok
  endif
endon

on test2 do
  if [test#a]=1 and [test#b]=1 and [test#c]=1
    event ok
  else
    event nok
  endif
endon

on test3 do
  if [test#a]=1 and [test#b]=1 or [test#c]=0
    event ok
  else
    event nok
  endif
endon

on test4 do
  if [test#a]=0
    event ok
  else
    event nok
  endif
endon

* - remove Serial print

* - add format #O to templates to show OFF/ON instead 0/1 - eg.: Pump:[Outputs#pump#O]

* - add formating for active low outputs eg.: #O!

* - fix #964, add timeStringToSeconds and use it to compare time conditions

* - fix number of pages available to browse
2018-02-28 00:00:37 +01:00
s0170071andUnknown 0db1f78421 Add Factory Reset button to web interface (#954) 2018-02-27 23:59:31 +01:00
Bartłomiej ZimońandUnknown 780c34846e add format #O to templates to show OFF/ON instead 0/1 (#949)
* - pcfgpio,port,2 sets pin as input
- fix for #222,#702 - we can mix inputs and outputs now

* - extend conditions with AND/OR, now it is possible to simplify rules

test rules:
on test do
  if [test#a]=0 or [test#b]=0 or [test#c]=0
    event ok
  else
    event nok
  endif
endon

on test2 do
  if [test#a]=1 and [test#b]=1 and [test#c]=1
    event ok
  else
    event nok
  endif
endon

on test3 do
  if [test#a]=1 and [test#b]=1 or [test#c]=0
    event ok
  else
    event nok
  endif
endon

on test4 do
  if [test#a]=0
    event ok
  else
    event nok
  endif
endon

* - remove Serial print

* - add format #O to templates to show OFF/ON instead 0/1 - eg.: Pump:[Outputs#pump#O]

* - add formating for active low outputs eg.: #O!
2018-02-27 23:58:50 +01:00
Gijs NoorlanderandDatuX a938bc78c1 [issue #968] Use template parser for OLED commands (#974)
N.B. Now even task values can be used in commands, next to special characters.
2018-02-27 23:43:18 +01:00
Gijs NoorlanderandDatuX d2c7743197 [issue #966] Add %sysweekday% and %sysweekday_s% (#973)
- %sysweekday%  number of the day (Sunday = 1)
- %sysweekday_s%  3 letter String of the weekday (Sun, Mon, Tue, ...)
2018-02-27 23:43:01 +01:00
ESPEasy release bot d35a50be17 automaticly updated release notes for v2.0-20180227 2018-02-27 04:00:22 +01:00
Edwin Eefting 04de145dbb [test suite] changes from mega to 2.0 2018-02-27 00:41:27 +01:00
Edwin Eefting 21840d0b26 [test suite] changes from mega to 2.0 2018-02-27 00:41:21 +01:00
Gijs NoorlanderandDatuX 555ccbe229 [BuildError] StreamingBuffer code cleanup + fix order member initialize (#961)
The order in which the members are defined should also be the order in which they will be initialized.

Also applied #958
2018-02-26 22:52:27 +01:00
ESPEasy release bot b5e4994392 automaticly updated release notes for v2.0-20180226 2018-02-26 04:00:21 +01:00
s0170071andUnknown 51ede17d2a Update WebServer.ino 2018-02-25 21:15:33 +01:00
s0170071andUnknown 97ee69b371 V20 Webserver@LowMemory 2018-02-25 21:15:24 +01:00
Unknown f77ce9c8f7 [ping lib] Added ping library
It was linked as a dependency in PlatformIO.ini, but apparently will add complexity to Arduino IDE users.
2018-02-25 21:14:07 +01:00
Gijs NoorlanderandDatuX 848f43b704 [2k Webserver] Proper initialisation of StreamingBuffer members. (#941)
Was reported in Travis as build error.
2018-02-25 17:17:47 +01:00
Edwin Eefting 3a5ef5da81 device page doesnt need next/previous page buttons anymore 2018-02-25 17:12:45 +01:00
Gijs NoorlanderandDatuX 54628bfca9 [timeouts] Improve response when hosts are not reachable (#939)
See #922 and #847

Problem with DNS resolve is that it is quite slow when resulting in a failure and it tends to keep the ESP occupied and make it unresponsive.

Changed the way it is connecting to a controller.
Not sure if http requests are still OK, maybe we should make an exception for those when selected to use DNS.
2018-02-25 14:15:56 +01:00
Gijs NoorlanderandDatuX aed566b6db [v2.0] Use ESPeasySoftwareSerial (#936)
This one has virtual destructor and will use less memory.
See issue #930.
2018-02-25 14:12:33 +01:00
Gijs NoorlanderandDatuX 504ea0c813 [v2.0 merge] 2kwebserver_merge_to_mega #929 (#934)
The v2.0 branch merge of the 2k webserver PR.
As test build, please try [these builds](https://www.dropbox.com/s/ky6ldixh6wgzd8k/2k_webserver_build_v2.0_20180221.rar?dl=0)
2018-02-25 14:12:11 +01:00
Gijs NoorlanderandDatuX 4ca5ef3f72 [v2.0] Added Vcc-binaries to deploy process #933 (#935)
PR for the V2.0 branch to add the VCC binaries to the deploy process.
2018-02-25 14:11:34 +01:00
Bartłomiej ZimońandDatuX 67c8477a61 provide System@Sleep event (#875) (#931)
- provide System@Sleep event
- fixes #870 (mqtt not sent before sleep)
- call deepsleep at the end of loop - so we know all is done
2018-02-25 14:01:40 +01:00
Gijs NoorlanderandDatuX 3d07466904 [MQTT] LWT "Connected" message doesn't have the retained flag (#925)
See comments of [Superpiffer](https://github.com/letscontrolit/ESPEasy/commit/a93a078c0b8ae4090c22717eacc8bc8ba92ad780#commitcomment-27718045)
2018-02-25 13:10:58 +01:00
Bartłomiej ZimońandBartlomiej Zimon 03ee569510 provide System@Sleep event (#875)
- provide System@Sleep event
- fixes #870 (mqtt not sent before sleep)
- call deepsleep at the end of loop - so we know all is done
2018-02-23 19:57:01 +01:00
ESPEasy release bot af519748a6 automaticly updated release notes for v2.0-20180221 2018-02-21 04:00:20 +01:00
Edwin Eefting 2bece45712 apply PUYA patch to all available frameworks 2018-02-21 02:08:06 +01:00
Gijs NoorlanderandDatuX 10c73a001a [issue #899 ] Backport of DHT22 implementation on Mega (#913)
It has quite some changes, but according to [litrinhos](https://github.com/letscontrolit/ESPEasy/issues/899#issuecomment-366940174) it works, instead of the v2.0 implementation.
2018-02-21 01:26:08 +01:00
ESPEasy release bot 233ca2bf43 automaticly updated release notes for v2.0-20180220 2018-02-20 04:00:19 +01:00
Edwin Eefting edeea02f71 SENSOR_TYPE_TEMP_BARO changed, was probably implemented incorrectly before 2018-02-20 01:56:40 +01:00
Gijs NoorlanderandDatuX b31b1d913f [issue #893] Fix globalSync not working when no controllers active (#896)
* [issue #893] Fix globalSync not working when no controllers active

See #893 and [this topic on the forum](https://www.letscontrolit.com/forum/viewtopic.php?p=24851#p24851)

* [issue #893] Global Sync call when no other controllers active
2018-02-20 00:52:43 +01:00
Gijs NoorlanderandDatuX fa3d4af8cb [Cleanup] Move String manipulating functions to single file (#895)
Makes it easier to re-use functions and improve them.
2018-02-20 00:52:18 +01:00
Gijs NoorlanderandDatuX 29320aab90 [isue #877] Add VCC enable firmware file to release list (#894)
* [isue #877] Add VCC enable firmware file to release list

Added one for the testing build.
Not sure if we should add one for every build, since these flags will lead to an explosion of release versions. 
But at least we will test builds with FEATURE_ADC_VCC define enabled more often.

* Add define FEATURE_ADC_VCC to the PUYA build

Since it is so hard to make a puya version on your own.
2018-02-20 00:50:56 +01:00
Gijs NoorlanderandGitHub 3bc8609611 Merge pull request #905 from TD-er/bugfix/DHTinit_sequence_wrong
[issue #899] DHT22 readings not received
2018-02-20 00:16:51 +01:00
Gijs NoorlanderandGitHub c43d6b3769 Merge pull request #904 from TD-er/feature/log_event_name
[Event Log] Add event name to event processing time log
2018-02-20 00:16:19 +01:00
Gijs NoorlanderandGitHub e9e2ea32ed Merge pull request #903 from TD-er/bugfix/OpenHAB_MQTT_topic_parser_fix
[issue #847] Fix last letter of command is cut in OpenHAB MQTT
2018-02-20 00:15:51 +01:00
Unknown 24b7d1f438 [issue #899] DHT22 readings not received
Applied fix as suggested here: https://github.com/adafruit/DHT-sensor-library/issues/48
2018-02-20 00:04:13 +01:00
Unknown 4febf08501 [Event Log] Add event name to event processing time log
As suggested on the forum by [Methusalem](https://www.letscontrolit.com/forum/viewtopic.php?p=24887#p24887)
2018-02-19 23:31:19 +01:00
Unknown 7f4eae19f4 [issue #847] Fix last letter of command is cut in OpenHAB MQTT
Thanks [jivkopavlovski](https://github.com/letscontrolit/ESPEasy/commit/f23d9fa3d3def506e1401c2208c8a19a1d5d1da2#commitcomment-27660279) for pointing this out (and testing ofcourse)
2018-02-19 22:57:57 +01:00
ESPEasy release bot c13952d04c automaticly updated release notes for v2.0-20180219 2018-02-19 04:00:19 +01:00
Gijs NoorlanderandDatuX e51f7683a5 [issue #890] Split overlap for both Domoticz controllers to helper (#891)
* [issue #890] Split overlap for both Domoticz controllers to helper

Both Domoticz controllers had quite some overlap in code.
And where they differ, one of them was faulty and/or already fixed.

Now this overlap is split into a Domoticz helper file to keep code duplication to a minimum.

* [issue #890] Fix some wierd data corruption

Do not store references in a Json object, but just the string :)

* [Domoticz] Add WiFi strength and battery info
2018-02-18 13:18:23 +01:00
Gijs NoorlanderandDatuX 1ad6fd6ea0 [issue #885] MAC address as system variable (#887)
%mac% will be replaced by the MAC-address of the ESP board.
%mac_int% will show the integer representation of the last 24 bits (MAC address without the OUI part) for use in rules.
2018-02-18 13:16:42 +01:00
ESPEasy release bot d2ec15a4bf automaticly updated release notes for v2.0-20180218 2018-02-18 04:00:11 +01:00
Gijs NoorlanderandDatuX f23d9fa3d3 [issue #847 ] OpenHAB MQTT rewrite topic parser (#886)
* [issue #847 ] OpenHAB MQTT rewrite topic parser

When OpenHAB MQTT controller was selected, the web interface becomes unresponsive when the controller tab was selected.
Also the ESP almost freezes when MQTT messages were sent.

This is an attempt to make them work faster.
Also a lot of string manipulation, copies and resizes are now no longer needed and the received values are checked to be valid int or float before used.

* signed unsigned warning
2018-02-17 13:18:52 +01:00
ESPEasy release bot 3cea522ec4 automaticly updated release notes for v2.0-20180217 2018-02-17 04:00:18 +01:00
Gijs NoorlanderandDatuX a93a078c0b [issue #869] Added 'LWT' to last will topic and improved CPU load (#883)
* [issue #869] Added 'LWT' to last will topic and improved CPU load

See #869 for discussion on Last Will Topic.
Also changed the way it tried to reconnect to make it return a lot faster when connection is not (yet) possible and call the PubSubClient::loop() at a much slower pace to reduce CPU usage. (See #847)
This higher CPU load was probably introduced when fixing #683.

* [MQTT] Fix error reporting success status with longer payloads

Applied PR https://github.com/knolleary/pubsubclient/pull/360/files

* made MQTT_CALLBACK_SIGNATURE for esp32 functional

Applied PR https://github.com/knolleary/pubsubclient/pull/336
2018-02-16 21:32:53 +01:00
Gijs NoorlanderandDatuX 0e0e7be95a [OLED Framed] ESP Easy logo (#876) 2018-02-16 21:29:44 +01:00
Gijs NoorlanderandDatuX ce02c9e039 [issue #853] Favicon.ico (#874)
* [issue #853] Favicon.ico

Added a very small favicon.ico of the ESPeasy logo. (1150 Bytes, 16x16)

* [Favicon] Added instructions to change icon.

In the comments. Just use 'xxd' from the (Linux) commandline.
2018-02-16 21:27:58 +01:00
Gijs NoorlanderandDatuX 1e9dc1d14c [issue 866] Try to stop logging to serial when serial is not read. (#868)
First attempt, not clear yet how to detect it.
See #866

Also preparation for future improvement on logging. (to detect whether there is some logging active so Strings may not have to be prepared.
2018-02-16 21:26:18 +01:00
ESPEasy release bot 9a6f7360da automaticly updated release notes for v2.0-20180214 2018-02-14 04:00:21 +01:00
Edwin Eefting d835ef679c updated deploy script for PUYA 2018-02-14 03:23:50 +01:00
Edwin Eefting 9144e7901b travis build fix for PUYA 2018-02-14 03:10:30 +01:00
Edwin Eefting 858ce397c3 workaround for PUYA flash chips with write issues #650 2018-02-14 03:01:42 +01:00
Gijs NoorlanderandDatuX 78c9ff70be [v2.0] Blynk controller (#865)
* update Blynk controller

- use of real controller index
- we use idx
- check if password not empty
- use real password

* fix for Blynk Controller

- use of real controller index
- we use idx
- check if password not empty
- use real password
- use proper port

* Update _C012.ino

add SENSOR_TYPE_SWITCH support

* [v2.0] Blynk controller
2018-02-14 00:23:59 +01:00
ESPEasy release bot 40eb3e7ceb automaticly updated release notes for v2.0-20180213 2018-02-13 04:00:20 +01:00
Gijs NoorlanderandDatuX 88320d25fc [MQTT] Allow for background tests while waiting for wifi (#860)
Recent changes in 'early exit' when not connected, triggered lots of retry events.
Added some function to allow to wait for WiFi and in the meantime do some background tasks.
2018-02-13 03:01:15 +01:00
Gijs NoorlanderandDatuX d49197a621 [issue #825] Change labels and password form for Thingspeak controller (#849)
See #825

Added option for controllers to change their display string on some controller fields in the web interface.
When password field label is non-default it also implies to use a visible textfield instead of a password field.
2018-02-13 01:17:04 +01:00
Gijs NoorlanderandDatuX 9abdd097c9 Formatting user vars (re-do of PR#482) + enabled check OpenHabMQTT (#851)
Re-implementation of PR #482 which was done on Mega branch.
Just to keep merges simple between branches. (and improve readabilit)

Also added a simple check to C005 (OpenHAB MQTT) on receiving messages. (see #847 )
2018-02-13 01:07:24 +01:00
Gijs NoorlanderandDatuX f8849cb601 Bugfix/oled framed less memory (#859)
* [OLED] Move font to oled lib dir

It is specific for use wth that library.

* [OLED framed] Stop reading from flash constantly and live update WiFi

See #857
The OLED Framed plugin was reading from spiffs all of the time (on every display update)
Now the data is only read from SPIFFS when needed.
Also made the WiFi strength indicator update every second (only when changed) to be able to see changes in WiFi status much easier.
2018-02-13 01:05:36 +01:00
soifandDatuX b293e8fee0 P012 - Fix/handle lines exceeding LCD width + allow to clear line b4 print (#852)
* Update Library LiquidCrystal_I2C to the latest version

* Fix LCD command (when message is longer than columns) that get split into the wrong lines - issue #603

* Added a "LCD command mode" parameter to handle how exceeding message would be treated, and if the line should be first padded with space.
2018-02-13 01:03:24 +01:00
Gijs NoorlanderandDatuX 11b1c8505a [v2.0] Fix compile errors on ESP32 (#848)
Cherry pick from Mega branch to avoid future merge conflicts.
2018-02-13 00:39:12 +01:00
Gijs NoorlanderandDatuX 9cb3ceed83 [P001 Switch] Fix a mixup in previous fix for switch (#845)
It was causing issues when people upgraded from previous builds.
Leaving it would cause high CPU loads, instable wifi, and incorrect set switch type when upgrading from older builds.

Only thing is when people were using it as a dimmer and used one of the builds in the last few weeks.
Then it will be used as a 'switch', not a dimmer. Change and set and all is fine again.
2018-02-13 00:38:51 +01:00
Gijs NoorlanderandDatuX 2ac1df9482 [issue #839] Add command support for setting contrast for OLED Framed (#841)
* [issue #839] Add command support for setting contrast for OLED Framed

See #839

* [issue #839] Should not use 0 as off value, since that is default

With 0 as "off", the display would be off when not set.
Changed it to 1, which is not a value that can be set other than with the commands
2018-02-13 00:38:01 +01:00
Gijs NoorlanderandDatuX d4e5742b1c [#804] Degree symbol for non-framed OLED display (#835) 2018-02-13 00:24:32 +01:00
ESPEasy release bot f815564dc7 automaticly updated release notes for v2.0-20180212 2018-02-12 04:00:22 +01:00
Gijs NoorlanderandDatuX 2b51a4d7c4 [Issue #831] Use DOUT flash mode (#834)
Set DOUT flash mode in the firmware image.
2018-02-12 02:24:16 +01:00
soifandDatuX 01d0723424 Add Device Name in /json page (#815)
* Add Name in /json page

* Json dev friendly (updatable) syntax

* Reorder Json field
2018-02-12 02:11:01 +01:00
ESPEasy release bot aec539be43 automaticly updated release notes for v2.0-20180209 2018-02-09 04:00:26 +01:00
wdonkerandDatuX e49f31121c Add trigger for rulesprocessing (#826)
* Update _C002.ino

Trigger rulesprocessing om MQTT receive message

* Replace direct call by createRuleEvents

Change to createRuleEvents
2018-02-08 19:33:32 +01:00
ESPEasy release bot bd874c4a13 automaticly updated release notes for v2.0-20180206 2018-02-06 05:00:21 +01:00
Gijs NoorlanderandDatuX 6b8ea6c15b [issue #727] Proper user interface to set DST rules (#823)
See #727
And it only took 4 bytes extra storage :)

When initialized with an invalid setting for DST, (like fresh after flashing), it will use the CEST/CET setting.
2018-02-06 00:42:45 +01:00
Gijs NoorlanderandDatuX a62dd5ce8f [issue #817] Added mail header to SMTP (#820)
* [issue #817] Added mail header to SMTP

N.B. use only mail address (no name, no '<>' etc) as sender.

* [SMTP] Add user/pass to send email.

* [issue #817] Added user + passwd authentication to SMTP notifications

Tested with smtp2go.com (non TLS mail proxy)
It is now possible to add username + passwd when sending mail.
If both left empty, authentication will not be used.
2018-02-05 23:59:24 +01:00
Gijs NoorlanderandDatuX 92889b6cf1 Backport OLED framed from mega + support special characters (#818)
* [OLED framed] Backport of OLED lib upgrade from Mega to v2.0

Lots of issues with older lib and the newer version in the Mega branch appeared to be very stable.

* [OLED framed] Use less string allocations

And a first attempt to display the Euro sign. (does not yet work)

* [Special Char] Allow to use special characters

For some special characters, it is often hard to find them and/or use them in URL or JSON streams.
For a subset of supported special characters, a short notation and HTML equivalent is added.
These can be used anywhere.

* [OLED lib] Fixed memory leak

Man library did some allocs without free.
Also unneeded allocs.

* Applied pull requests from esp8266-oled-ssd1306:
https://github.com/squix78/esp8266-oled-ssd1306/pull/169
https://github.com/squix78/esp8266-oled-ssd1306/pull/157
https://github.com/squix78/esp8266-oled-ssd1306/pull/144

And applied the suggestions from issues:
https://github.com/squix78/esp8266-oled-ssd1306/issues/170
https://github.com/squix78/esp8266-oled-ssd1306/issues/161

* [OLED] Support multiple display resolutions

Applied PR from esp8266-oled-ssd1306:
https://github.com/squix78/esp8266-oled-ssd1306/pull/133

* [OLED] Better Brightness / Contrast control

Suggestions taken from this issue:
https://github.com/squix78/esp8266-oled-ssd1306/issues/134

* [OLED] Set contrast to High by default, when no choice was made

Sounds like a valid choice, based on the findings in issue #821

* Compiler error on comments

As suggested here: https://github.com/TD-er/ESPEasy/pull/3/files
2018-02-05 23:56:17 +01:00
soifandDatuX b5479575eb All Advanced Settings as 'DEFAULT_' Defines (#813)
* Implements all Advanced Settings as "DEFAULT_" defines

* Organise and comment "DEFAULT_" defines
2018-02-05 23:50:48 +01:00
ESPEasy release bot 6fead68f34 automaticly updated release notes for v2.0-20180203 2018-02-03 05:00:20 +01:00
GrovkillenandGitHub 2f26cd13bc Update README.md 2018-02-02 12:52:12 +01:00
ESPEasy release bot 3a9ef290e8 automaticly updated release notes for v2.0-20180202 2018-02-02 05:00:23 +01:00
130 changed files with 8289 additions and 8159 deletions
+1 -3
View File
@@ -26,8 +26,6 @@ Also there are more people on the forum that can help you with support.
* Incomplete or unstable plugins should have a PLUGIN_BUILD_DEV #ifdef around them. Also add [DEVELOPMENT] to the name.
* Do not modify any of the variables passed to your PLUGIN_WRITE handler.
* New plugins that seem to be working correctly should have a PLUGIN_BUILD_TESTING around until they are tested enough. Also add [TESTING] to the name
* New plugins that seem to be working correctly should have a PLUGIN_BUILD_TESTING around until they are tested enough.
* Also see our general guidelines at: https://www.letscontrolit.com/wiki/index.php/ESPEasyDevelopmentGuidelines
+7 -2
View File
@@ -25,9 +25,14 @@ install:
- pip install -U platformio
script:
# - cppcheck --enable=warning src/*.ino -q --force -I src --include=src/ESPEasy.ino --error-exitcode=1
- cppcheck --enable=warning src/*.ino -q --force -I src --include=src/ESPEasy.ino --error-exitcode=1
# - ./memanalyzer.py ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-objdump
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -s
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run
# patch platformio core libs for PUYA bug (https://github.com/letscontrolit/ESPEasy/issues/650)
- cd patches; ./check_puya_patch; cd ..
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -s --environment dev_ESP8266PUYA_1024
before_deploy:
- ./before_deploy
+26 -17
View File
@@ -1,35 +1,44 @@
# ESPEasy (development branch)
# ESPEasy (v2.0 stable branch)
Build status: [![Build Status](https://travis-ci.org/letscontrolit/ESPEasy.svg?branch=mega)](https://travis-ci.org/letscontrolit/ESPEasy)
Build status: [![Build Status](https://travis-ci.org/letscontrolit/ESPEasy.svg?branch=v2.0)](https://travis-ci.org/letscontrolit/ESPEasy)
Introduction and wiki: https://www.letscontrolit.com/wiki/index.php/ESPEasy#Introduction
This is the development branch of ESPEasy. All new untested features go into this branch. If you want to do a bugfix, do it on the stable branch, we will merge the fix to the development branch as well.
**v2.0**
:warning:This is the stable branch for the next upcoming ESPeasy release (2.0.0).:warning:
Next stable branch: https://github.com/letscontrolit/ESPEasy/tree/v2.0 (bug fixes only, since oct 2017))
If you're living on the edge and want the latest features and bugs, go to the development branch: https://github.com/letscontrolit/ESPEasy/tree/mega
If you're a developer: Bug fixes go into this v2.0 branch, we will merge them back to the development branch.
Check here to learn how to use this branch and help us improving ESPEasy: http://www.letscontrolit.com/wiki/index.php/ESPEasy#Source_code_development
## Versions
## Automated binary releases
* v2.0-YYYYMMDD: These are the nightly builds. Once a day this is automaticly released whenever there are new changes. (this replaces the manual v2.0-devX release system)
* v2.0.0-betaX: as soon as we THINK everything is fixed, we start beta testing.
* v2.0.0-rcX: release candidates (almost stable)
* v2.0.0: This will be the first stable release. After this we will use more standard numbering. Next bugfix release will probably be 2.0.1.
Every night our build-bot will build a new binary release: https://github.com/letscontrolit/ESPEasy/releases
## Firmware binary releases
The releases are named something like 'mega-20180102' (last number is the build date)
Binary development releases are here: https://github.com/letscontrolit/ESPEasy/releases
Depending on your needs, we release different types of files:
Depending on your needs, we release different types of files.
This uses version v2.0-20181001 as an example.
Firmware name | Hardware | Included plugins |
----------------------------------------------|-------------------------|-----------------------------|
ESPEasy_mega-20180102_normal_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable |
ESPEasy_mega-20180102_test_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable + Test |
ESPEasy_mega-20180102_dev_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable + Test + Development |
ESPEasy_mega-20180102_normal_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable |
ESPEasy_mega-20180102_test_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable + Test |
ESPEasy_mega-20180102_dev_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable + Test + Development |
ESPEasy_mega-20180102_normal_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable |
ESPEasy_mega-20180102_test_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable + Test |
ESPEasy_mega-20180102_dev_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable + Test + Development |
ESPEasy_v2.0-20181001_normal_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable |
ESPEasy_v2.0-20181001_test_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable + Test |
ESPEasy_v2.0-20181001_dev_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable + Test + Development |
ESPEasy_v2.0-20181001_normal_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable |
ESPEasy_v2.0-20181001_test_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable + Test |
ESPEasy_v2.0-20181001_dev_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable + Test + Development |
ESPEasy_v2.0-20181001_normal_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable |
ESPEasy_v2.0-20181001_test_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable + Test |
ESPEasy_v2.0-20181001_dev_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable + Test + Development |
## More info
+5 -2
View File
@@ -10,17 +10,20 @@ for ENV in \
normal_ESP8266_1024 \
normal_ESP8266_4096 \
normal_ESP8285_1024 \
normal_ESP8266_1024_DOUT \
test_ESP8266_1024\
test_ESP8266_4096\
test_ESP8266_4096_VCC\
test_ESP8285_1024\
dev_ESP8266_1024\
dev_ESP8266_4096\
dev_ESP8285_1024;\
dev_ESP8285_1024\
dev_ESP8266PUYA_1024\
dev_ESP8266PUYA_1024_VCC;\
do
echo
echo "### Deploying environment $ENV for version $VERSION"
BIN=.pioenvs/$ENV/firmware.bin
python2 crc2.py $BIN
cp $BIN dist/"ESP_Easy_$VERSION""_$ENV.bin"
done
-96
View File
@@ -1,96 +0,0 @@
import sys
import binascii
import struct
import md5
MD5DUMMY = "MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere..."
MemorySegmentStart,MemorySegmentEnd,MemoryContent=[],[],[]
##################################################################
# this subroutine shows the segments of a part
##################################################################
def showSegments (fileContent,offset):
global MemorySegmentStart, MemorySegmentEnd, MemoryContent
header = struct.unpack("ii", fileContent[offset:offset+8])
herestr =""
MemorySegmentStart.append(struct.pack("I",header[0]))
MemorySegmentEnd.append(struct.pack("I",header[0]+header[1]))
MemoryContent.append(fileContent[offset+8:offset+8+header[1]])
if fileContent.find( MD5DUMMY, offset+8, offset+8+header[1]) >0 :
herestr= " <-- CRC is here."
print ("SEGMENT "+ str(len(MemorySegmentStart)-1)+ ": memory position: " + hex(header[0])+" to " + hex(header[0]+header[1]) + " length: " + hex(header[1])+herestr)
#print ("first byte positoin in file: " + hex( offset+8))
#print ("last byte postion in file: " + hex(offset+8+header[1]-1))
return (8+offset+ header[1]); # return start of next segment
##################################################################
# this subroutine shows the parts of a binary file
##################################################################
def showParts(fileContent, offset):
header = struct.unpack("BBBBi", fileContent[offset:offset+8])
print ('\n\nBINARY PART\nSegments: ') + (hex(header[1]))
nextpos =offset+8
for x in range (0,header[1]):
nextpos = showSegments(fileContent,nextpos)
nextSegmentOffset = (fileContent.find("\xe9", nextpos))
return nextSegmentOffset
##################################################################
# MAIN
##################################################################
#if len(sys.argv) !=2 :
# print ("please give a filename")
# k=input("press close to exit")
# sys.exit(1)
FileName = sys.argv[1]#"C:/ArduinoPortable/sketchbooks/build/sketch_jan15a.ino.bin"
#FileName = "C:/ArduinoPortable/sketchbooks/build/sketch_jan15a.ino.bin"
print( "\n\nReplacing dummy MD5 checksum in .bin file")
with open(FileName, mode='rb') as file: # b is important -> binary
nextpos =0;
fileContent = file.read()
while nextpos >=0:
nextpos = showParts(fileContent,nextpos)
startArray,endArray,hashString = "","",""
includeStr = "hash includes segments:"
# memory sections:
# 0: bootloader (not readable)
# 1: program memory (SPI flash)
# 2: unknown but stable
# 3: RAM (initialized by bin file. Can be read but changes as you go :-( )
# 4: RAM
for i in (1,2 ): # use only stable segments, must be 4 in total. We use 2.
startArray =startArray + MemorySegmentStart[i]
endArray = endArray + MemorySegmentEnd[i]
hashString =hashString + MemoryContent[i]
with open(FileName+str(i), mode='wb') as file: # b is important -> binary
file.write(MemoryContent[i])
includeStr = includeStr +" "+ str(i)
print (includeStr)
# IMPORTANT: pad array with zeros if you use only 3 segments (see above)
while len(startArray) < 16 :
startArray =startArray + struct.pack("I",0)
endArray = endArray + struct.pack("I",0)
# debug print (binascii.hexlify(startArray))
# debug print (binascii.hexlify(endArray))
if (len(endArray) + len (startArray)) != 32 :
print("ERROR: please make sure you add / remove padding if you change the semgents.")
if fileContent.find( MD5DUMMY) < 0:
print("ERROR: MD5 dummy not found in binary")
else:
hashString=hashString.replace (MD5DUMMY,"",1)
m = md5.new()
m.update (hashString) #use segment 1
md5hash = m.digest()
print("MD5 hash: "+ m.hexdigest())
print("\nwriting output file:\n" + FileName)
with open(FileName, mode='wb') as file: # b is important -> binary
file.write(fileContent.replace(MD5DUMMY,md5hash+startArray+endArray))
#k=input("press close to exit")
+558 -377
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
-154
View File
@@ -1,154 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software< /span>
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
* extended sensor support to include color, voltage and current */
#ifndef _ADAFRUIT_SENSOR_H
#define _ADAFRUIT_SENSOR_H
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
/* Intentionally modeled after sensors.h in the Android API:
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
/* Constants */
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
#define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */
#define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */
#define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */
#define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */
#define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */
/** Sensor types */
typedef enum
{
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
SENSOR_TYPE_MAGNETIC_FIELD = (2),
SENSOR_TYPE_ORIENTATION = (3),
SENSOR_TYPE_GYROSCOPE = (4),
SENSOR_TYPE_LIGHT = (5),
SENSOR_TYPE_PRESSURE = (6),
SENSOR_TYPE_PROXIMITY = (8),
SENSOR_TYPE_GRAVITY = (9),
SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */
SENSOR_TYPE_ROTATION_VECTOR = (11),
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
SENSOR_TYPE_VOLTAGE = (15),
SENSOR_TYPE_CURRENT = (16),
SENSOR_TYPE_COLOR = (17)
} sensors_type_t;
/** struct sensors_vec_s is used to return a vector in a common format. */
typedef struct {
union {
float v[3];
struct {
float x;
float y;
float z;
};
/* Orientation sensors */
struct {
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */
float heading; /**< Angle between the longitudinal axis (the plane body) and magnetic north, measured clockwise when viewing from the top of the device. 0-359° */
};
};
int8_t status;
uint8_t reserved[3];
} sensors_vec_t;
/** struct sensors_color_s is used to return color data in a common format. */
typedef struct {
union {
float c[3];
/* RGB color space */
struct {
float r; /**< Red component */
float g; /**< Green component */
float b; /**< Blue component */
};
};
uint32_t rgba; /**< 24-bit RGBA value */
} sensors_color_t;
/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
typedef struct
{
int32_t version; /**< must be sizeof(struct sensors_event_t) */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< sensor type */
int32_t reserved0; /**< reserved */
int32_t timestamp; /**< time is in milliseconds */
union
{
float data[4];
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
sensors_vec_t orientation; /**< orientation values are in degrees */
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
float temperature; /**< temperature is in degrees centigrade (Celsius) */
float distance; /**< distance in centimeters */
float light; /**< light in SI lux units */
float pressure; /**< pressure in hectopascal (hPa) */
float relative_humidity; /**< relative humidity in percent */
float current; /**< current in milliamps (mA) */
float voltage; /**< voltage in volts (V) */
sensors_color_t color; /**< color in RGB component values */
};
} sensors_event_t;
/* Sensor details (40 bytes) */
/** struct sensor_s is used to describe basic information about a specific sensor. */
typedef struct
{
char name[12]; /**< sensor name */
int32_t version; /**< version of the hardware + driver */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
float max_value; /**< maximum value of this sensor's value in SI units */
float min_value; /**< minimum value of this sensor's value in SI units */
float resolution; /**< smallest difference between two values reported by this sensor */
int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */
} sensor_t;
class Adafruit_Sensor {
public:
// Constructor(s)
Adafruit_Sensor() {}
virtual ~Adafruit_Sensor() {}
// These must be defined by the subclass
virtual void enableAutoRange(bool enabled) {};
virtual bool getEvent(sensors_event_t*) = 0;
virtual void getSensor(sensor_t*) = 0;
private:
bool _autoRange;
};
#endif
-221
View File
@@ -1,221 +0,0 @@
# Adafruit Unified Sensor Driver #
Many small embedded systems exist to collect data from sensors, analyse the data, and either take an appropriate action or send that sensor data to another system for processing.
One of the many challenges of embedded systems design is the fact that parts you used today may be out of production tomorrow, or system requirements may change and you may need to choose a different sensor down the road.
Creating new drivers is a relatively easy task, but integrating them into existing systems is both error prone and time consuming since sensors rarely use the exact same units of measurement.
By reducing all data to a single **sensors\_event\_t** 'type' and settling on specific, **standardised SI units** for each sensor family the same sensor types return values that are comparable with any other similar sensor. This enables you to switch sensor models with very little impact on the rest of the system, which can help mitigate some of the risks and problems of sensor availability and code reuse.
The unified sensor abstraction layer is also useful for data-logging and data-transmission since you only have one well-known type to log or transmit over the air or wire.
## Unified Sensor Drivers ##
The following drivers are based on the Adafruit Unified Sensor Driver:
**Accelerometers**
- [Adafruit\_ADXL345](https://github.com/adafruit/Adafruit_ADXL345)
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
- [Adafruit\_MMA8451\_Library](https://github.com/adafruit/Adafruit_MMA8451_Library)
**Gyroscope**
- [Adafruit\_L3GD20\_U](https://github.com/adafruit/Adafruit_L3GD20_U)
**Light**
- [Adafruit\_TSL2561](https://github.com/adafruit/Adafruit_TSL2561)
- [Adafruit\_TSL2591\_Library](https://github.com/adafruit/Adafruit_TSL2591_Library)
**Magnetometers**
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
- [Adafruit\_HMC5883\_Unified](https://github.com/adafruit/Adafruit_HMC5883_Unified)
**Barometric Pressure**
- [Adafruit\_BMP085\_Unified](https://github.com/adafruit/Adafruit_BMP085_Unified)
- [Adafruit\_BMP183\_Unified\_Library](https://github.com/adafruit/Adafruit_BMP183_Unified_Library)
**Humidity & Temperature**
- [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library)
**Orientation**
- [Adafruit_BNO055](https://github.com/adafruit/Adafruit_BNO055)
## How Does it Work? ##
Any driver that supports the Adafruit unified sensor abstraction layer will implement the Adafruit\_Sensor base class. There are two main typedefs and one enum defined in Adafruit_Sensor.h that are used to 'abstract' away the sensor details and values:
**Sensor Types (sensors\_type\_t)**
These pre-defined sensor types are used to properly handle the two related typedefs below, and allows us determine what types of units the sensor uses, etc.
```
/** Sensor types */
typedef enum
{
SENSOR_TYPE_ACCELEROMETER = (1),
SENSOR_TYPE_MAGNETIC_FIELD = (2),
SENSOR_TYPE_ORIENTATION = (3),
SENSOR_TYPE_GYROSCOPE = (4),
SENSOR_TYPE_LIGHT = (5),
SENSOR_TYPE_PRESSURE = (6),
SENSOR_TYPE_PROXIMITY = (8),
SENSOR_TYPE_GRAVITY = (9),
SENSOR_TYPE_LINEAR_ACCELERATION = (10),
SENSOR_TYPE_ROTATION_VECTOR = (11),
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
SENSOR_TYPE_VOLTAGE = (15),
SENSOR_TYPE_CURRENT = (16),
SENSOR_TYPE_COLOR = (17)
} sensors_type_t;
```
**Sensor Details (sensor\_t)**
This typedef describes the specific capabilities of this sensor, and allows us to know what sensor we are using beneath the abstraction layer.
```
/* Sensor details (40 bytes) */
/** struct sensor_s is used to describe basic information about a specific sensor. */
typedef struct
{
char name[12];
int32_t version;
int32_t sensor_id;
int32_t type;
float max_value;
float min_value;
float resolution;
int32_t min_delay;
} sensor_t;
```
The individual fields are intended to be used as follows:
- **name**: The sensor name or ID, up to a maximum of twelve characters (ex. "MPL115A2")
- **version**: The version of the sensor HW and the driver to allow us to differentiate versions of the board or driver
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network
- **type**: The sensor type, based on **sensors\_type\_t** in sensors.h
- **max\_value**: The maximum value that this sensor can return (in the appropriate SI unit)
- **min\_value**: The minimum value that this sensor can return (in the appropriate SI unit)
- **resolution**: The smallest difference between two values that this sensor can report (in the appropriate SI unit)
- **min\_delay**: The minimum delay in microseconds between two sensor events, or '0' if there is no constant sensor rate
**Sensor Data/Events (sensors\_event\_t)**
This typedef is used to return sensor data from any sensor supported by the abstraction layer, using standard SI units and scales.
```
/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
typedef struct
{
int32_t version;
int32_t sensor_id;
int32_t type;
int32_t reserved0;
int32_t timestamp;
union
{
float data[4];
sensors_vec_t acceleration;
sensors_vec_t magnetic;
sensors_vec_t orientation;
sensors_vec_t gyro;
float temperature;
float distance;
float light;
float pressure;
float relative_humidity;
float current;
float voltage;
sensors_color_t color;
};
} sensors_event_t;
```
It includes the following fields:
- **version**: Contain 'sizeof(sensors\_event\_t)' to identify which version of the API we're using in case this changes in the future
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network (must match the sensor\_id value in the corresponding sensor\_t enum above!)
- **type**: the sensor type, based on **sensors\_type\_t** in sensors.h
- **timestamp**: time in milliseconds when the sensor value was read
- **data[4]**: An array of four 32-bit values that allows us to encapsulate any type of sensor data via a simple union (further described below)
**Required Functions**
In addition to the two standard types and the sensor type enum, all drivers based on Adafruit_Sensor must also implement the following two functions:
```
bool getEvent(sensors_event_t*);
```
Calling this function will populate the supplied sensors\_event\_t reference with the latest available sensor data. You should call this function as often as you want to update your data.
```
void getSensor(sensor_t*);
```
Calling this function will provide some basic information about the sensor (the sensor name, driver version, min and max values, etc.
**Standardised SI values for sensors\_event\_t**
A key part of the abstraction layer is the standardisation of values on SI units of a particular scale, which is accomplished via the data[4] union in sensors\_event\_t above. This 16 byte union includes fields for each main sensor type, and uses the following SI units and scales:
- **acceleration**: values are in **meter per second per second** (m/s^2)
- **magnetic**: values are in **micro-Tesla** (uT)
- **orientation**: values are in **degrees**
- **gyro**: values are in **rad/s**
- **temperature**: values in **degrees centigrade** (Celsius)
- **distance**: values are in **centimeters**
- **light**: values are in **SI lux** units
- **pressure**: values are in **hectopascal** (hPa)
- **relative\_humidity**: values are in **percent**
- **current**: values are in **milliamps** (mA)
- **voltage**: values are in **volts** (V)
- **color**: values are in 0..1.0 RGB channel luminosity and 32-bit RGBA format
## The Unified Driver Abstraction Layer in Practice ##
Using the unified sensor abstraction layer is relatively easy once a compliant driver has been created.
Every compliant sensor can now be read using a single, well-known 'type' (sensors\_event\_t), and there is a standardised way of interrogating a sensor about its specific capabilities (via sensor\_t).
An example of reading the [TSL2561](https://github.com/adafruit/Adafruit_TSL2561) light sensor can be seen below:
```
Adafruit_TSL2561 tsl = Adafruit_TSL2561(TSL2561_ADDR_FLOAT, 12345);
...
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Display the results (light is measured in lux) */
if (event.light)
{
Serial.print(event.light); Serial.println(" lux");
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Sensor overload");
}
```
Similarly, we can get the basic technical capabilities of this sensor with the following code:
```
sensor_t sensor;
sensor_t sensor;
tsl.getSensor(&sensor);
/* Display the sensor details */
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
Serial.println("------------------------------------");
Serial.println("");
```
-9
View File
@@ -1,9 +0,0 @@
name=Adafruit Unified Sensor
version=1.0.2
author=Adafruit <info@adafruit.com>
maintainer=Adafruit <info@adafruit.com>
sentence=Required for all Adafruit Unified Sensor based libraries.
paragraph=A unified sensor abstraction layer used by many Adafruit sensor libraries.
category=Sensors
url=https://github.com/adafruit/Adafruit_Sensor
architectures=*
-46
View File
@@ -1,46 +0,0 @@
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
- **For Arduino projects check these very common issues to ensure they don't apply**:
- For uploading sketches or communicating with the board make sure you're using
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
- **Be sure you are supplying adequate power to the board.** Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
- **Double check all soldering joints and connections.** Flakey connections
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
- **Ensure you are using an official Arduino or Adafruit board.** We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
VERSION HERE**
- List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): **LIST REPRO STEPS BELOW**
-26
View File
@@ -1,26 +0,0 @@
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
Before you open the request please review the following guidelines and tips to
help it be more easily integrated:
- **Describe the scope of your change--i.e. what the change does and what parts
of the code were modified.** This will help us understand any risks of integrating
the code.
- **Describe any known limitations with your change.** For example if the change
doesn't apply to a supported platform of the library please mention it.
- **Please run any tests or examples that can exercise your modified code.** We
strive to not break users of the code and running tests/examples helps with this
process.
Thank you again for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to manage and
can't immediately respond to every request. There is no need to bump or check in
on a pull request (it will clutter the discussion of the request).
Also don't be worried if the request is closed or not integrated--sometimes the
priorities of Adafruit's GitHub code (education, ease of use) might not match the
priorities of the pull request. Don't fret, the open source community thrives on
forks and GitHub makes it easy to keep your changes in a forked repo.
After reviewing the guidelines above you can delete this text from the pull request.
-504
View File
@@ -1,504 +0,0 @@
/**************************************************************************/
/*!
@file Adafruit_TSL2591.cpp
@author KT0WN (adafruit.com)
This is a library for the Adafruit TSL2591 breakout board
This library works with the Adafruit TSL2591 breakout
----> https://www.adafruit.com/products/1980
Check out the links above for our tutorials and wiring diagrams
These chips use I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2014 Adafruit Industries
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#if defined(ESP8266) || defined(ESP32)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#if defined(__AVR__)
#include <util/delay.h>
#endif
#include <stdlib.h>
#include "Adafruit_TSL2591.h"
Adafruit_TSL2591::Adafruit_TSL2591(int32_t sensorID)
{
_initialized = false;
_integration = TSL2591_INTEGRATIONTIME_100MS;
_gain = TSL2591_GAIN_MED;
_sensorID = sensorID;
// we cant do wire initialization till later, because we havent loaded Wire yet
}
boolean Adafruit_TSL2591::begin(void)
{
Wire.begin();
/*
for (uint8_t i=0; i<0x20; i++)
{
uint8_t id = read8(0x12);
Serial.print("$"); Serial.print(i, HEX);
Serial.print(" = 0x"); Serial.println(read8(i), HEX);
}
*/
uint8_t id = read8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_DEVICE_ID);
if (id == 0x50 )
{
// Serial.println("Found Adafruit_TSL2591");
}
else
{
return false;
}
_initialized = true;
// Set default integration time and gain
setTiming(_integration);
setGain(_gain);
// Note: by default, the device is in power down mode on bootup
disable();
return true;
}
void Adafruit_TSL2591::enable(void)
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
// Enable the device by setting the control bit to 0x01
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWERON | TSL2591_ENABLE_AEN | TSL2591_ENABLE_AIEN | TSL2591_ENABLE_NPIEN);
}
void Adafruit_TSL2591::disable(void)
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
// Disable the device by setting the control bit to 0x00
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWEROFF);
}
void Adafruit_TSL2591::setGain(tsl2591Gain_t gain)
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
enable();
_gain = gain;
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
disable();
}
tsl2591Gain_t Adafruit_TSL2591::getGain()
{
return _gain;
}
void Adafruit_TSL2591::setTiming(tsl2591IntegrationTime_t integration)
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
enable();
_integration = integration;
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
disable();
}
tsl2591IntegrationTime_t Adafruit_TSL2591::getTiming()
{
return _integration;
}
float Adafruit_TSL2591::calculateLuxf(uint16_t ch0, uint16_t ch1)
{
float atime, again;
float cpl, lux1, lux2, lux;
uint32_t chan0, chan1;
// Check for overflow conditions first
if ((ch0 == 0xFFFF) | (ch1 == 0xFFFF))
{
// Signal an overflow
return 0;
}
// Note: This algorithm is based on preliminary coefficients
// provided by AMS and may need to be updated in the future
switch (_integration)
{
case TSL2591_INTEGRATIONTIME_100MS :
atime = 100.0F;
break;
case TSL2591_INTEGRATIONTIME_200MS :
atime = 200.0F;
break;
case TSL2591_INTEGRATIONTIME_300MS :
atime = 300.0F;
break;
case TSL2591_INTEGRATIONTIME_400MS :
atime = 400.0F;
break;
case TSL2591_INTEGRATIONTIME_500MS :
atime = 500.0F;
break;
case TSL2591_INTEGRATIONTIME_600MS :
atime = 600.0F;
break;
default: // 100ms
atime = 100.0F;
break;
}
switch (_gain)
{
case TSL2591_GAIN_LOW :
again = 1.0F;
break;
case TSL2591_GAIN_MED :
again = 25.0F;
break;
case TSL2591_GAIN_HIGH :
again = 428.0F;
break;
case TSL2591_GAIN_MAX :
again = 9876.0F;
break;
default:
again = 1.0F;
break;
}
// cpl = (ATIME * AGAIN) / DF
cpl = (atime * again) / TSL2591_LUX_DF;
lux1 = (((float) ch0 - (float) ch1)) * (1.0F - ((float) ch1 / (float) ch0)) / cpl;//( (float)ch0 - (TSL2591_LUX_COEFB * (float)ch1) ) / cpl;
lux2 = ((TSL2591_LUX_COEFC * (float) ch0) - (TSL2591_LUX_COEFD * (float) ch1)) / cpl;
lux = lux1 > lux2 ? lux1 : lux2;
// Alternate lux calculation
//lux = ( (float)ch0 - ( 1.7F * (float)ch1 ) ) / cpl;
// Signal I2C had no errors
return lux;
}
uint32_t Adafruit_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1)
{
return (uint32_t) calculateLuxf(ch0, ch1);
}
uint32_t Adafruit_TSL2591::getFullLuminosity (void)
{
if (!_initialized)
{
if (!begin())
{
return 0;
}
}
// Enable the device
enable();
// Wait x ms for ADC to complete
for (uint8_t d=0; d<=_integration; d++)
{
delay(120);
}
uint32_t x;
uint16_t y;
y |= read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN0_LOW);
x = read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN1_LOW);
x <<= 16;
x |= y;
disable();
return x;
}
uint16_t Adafruit_TSL2591::getLuminosity (uint8_t channel)
{
uint32_t x = getFullLuminosity();
if (channel == TSL2591_FULLSPECTRUM)
{
// Reads two byte value from channel 0 (visible + infrared)
return (x & 0xFFFF);
}
else if (channel == TSL2591_INFRARED)
{
// Reads two byte value from channel 1 (infrared)
return (x >> 16);
}
else if (channel == TSL2591_VISIBLE)
{
// Reads all and subtracts out just the visible!
return ( (x & 0xFFFF) - (x >> 16));
}
// unknown channel!
return 0;
}
void Adafruit_TSL2591::registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold)
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
enable();
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAILTL, lowerThreshold);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAILTH, lowerThreshold >> 8);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAIHTL, upperThreshold);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAIHTH, upperThreshold >> 8);
disable();
}
void Adafruit_TSL2591::registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold, tsl2591Persist_t persist)
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
enable();
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_PERSIST_FILTER, persist);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AILTL, lowerThreshold);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AILTH, lowerThreshold >> 8);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AIHTL, upperThreshold);
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AIHTH, upperThreshold >> 8);
disable();
}
void Adafruit_TSL2591::clearInterrupt()
{
if (!_initialized)
{
if (!begin())
{
return;
}
}
enable();
write8(TSL2591_CLEAR_INT);
disable();
}
uint8_t Adafruit_TSL2591::getStatus()
{
if (!_initialized)
{
if (!begin())
{
return 0;
}
}
// Enable the device
enable();
uint8_t x;
x = read8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_DEVICE_STATUS);
disable();
return x;
}
uint8_t Adafruit_TSL2591::read8(uint8_t reg)
{
uint8_t x;
Wire.beginTransmission(TSL2591_ADDR);
#if ARDUINO >= 100
Wire.write(reg);
#else
Wire.send(reg);
#endif
Wire.endTransmission();
Wire.requestFrom(TSL2591_ADDR, 1);
#if ARDUINO >= 100
x = Wire.read();
#else
x = Wire.receive();
#endif
// while (! Wire.available());
// return Wire.read();
return x;
}
uint16_t Adafruit_TSL2591::read16(uint8_t reg)
{
uint16_t x;
uint16_t t;
Wire.beginTransmission(TSL2591_ADDR);
#if ARDUINO >= 100
Wire.write(reg);
#else
Wire.send(reg);
#endif
Wire.endTransmission();
Wire.requestFrom(TSL2591_ADDR, 2);
#if ARDUINO >= 100
t = Wire.read();
x = Wire.read();
#else
t = Wire.receive();
x = Wire.receive();
#endif
x <<= 8;
x |= t;
return x;
}
void Adafruit_TSL2591::write8 (uint8_t reg, uint8_t value)
{
Wire.beginTransmission(TSL2591_ADDR);
#if ARDUINO >= 100
Wire.write(reg);
Wire.write(value);
#else
Wire.send(reg);
Wire.send(value);
#endif
Wire.endTransmission();
}
void Adafruit_TSL2591::write8 (uint8_t reg)
{
Wire.beginTransmission(TSL2591_ADDR);
#if ARDUINO >= 100
Wire.write(reg);
#else
Wire.send(reg);
#endif
Wire.endTransmission();
}
/**************************************************************************/
/*!
@brief Gets the most recent sensor event
*/
/**************************************************************************/
bool Adafruit_TSL2591::getEvent(sensors_event_t *event)
{
uint16_t ir, full;
uint32_t lum = getFullLuminosity();
/* Early silicon seems to have issues when there is a sudden jump in */
/* light levels. :( To work around this for now sample the sensor 2x */
lum = getFullLuminosity();
ir = lum >> 16;
full = lum & 0xFFFF;
/* Clear the event */
memset(event, 0, sizeof(sensors_event_t));
event->version = sizeof(sensors_event_t);
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_LIGHT;
event->timestamp = millis();
/* Calculate the actual lux value */
/* 0 = sensor overflow (too much light) */
event->light = calculateLux(full, ir);
return true;
}
/**************************************************************************/
/*!
@brief Gets the sensor_t data
*/
/**************************************************************************/
void Adafruit_TSL2591::getSensor(sensor_t *sensor)
{
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));
/* Insert the sensor name in the fixed length char array */
strncpy (sensor->name, "TSL2591", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name)- 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_LIGHT;
sensor->min_delay = 0;
sensor->max_value = 88000.0;
sensor->min_value = 0.0;
sensor->resolution = 1.0;
}
-187
View File
@@ -1,187 +0,0 @@
/**************************************************************************/
/*!
@file Adafruit_TSL2591.h
@author KT0WN (adafruit.com)
This is a library for the Adafruit TSL2591 breakout board
This library works with the Adafruit TSL2591 breakout
----> https://www.adafruit.com/products/1980
Check out the links above for our tutorials and wiring diagrams
These chips use I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2014 Adafruit Industries
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#ifndef _TSL2591_H_
#define _TSL2591_H_
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <Adafruit_Sensor.h>
#include <Wire.h>
#define TSL2591_VISIBLE (2) // channel 0 - channel 1
#define TSL2591_INFRARED (1) // channel 1
#define TSL2591_FULLSPECTRUM (0) // channel 0
#define TSL2591_ADDR (0x29)
#define TSL2591_READBIT (0x01)
#define TSL2591_COMMAND_BIT (0xA0) // 1010 0000: bits 7 and 5 for 'command normal'
#define TSL2591_CLEAR_INT (0xE7)
#define TSL2591_TEST_INT (0xE4)
#define TSL2591_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
#define TSL2591_BLOCK_BIT (0x10) // 1 = using block read/write
#define TSL2591_ENABLE_POWEROFF (0x00)
#define TSL2591_ENABLE_POWERON (0x01)
#define TSL2591_ENABLE_AEN (0x02) // ALS Enable. This field activates ALS function. Writing a one activates the ALS. Writing a zero disables the ALS.
#define TSL2591_ENABLE_AIEN (0x10) // ALS Interrupt Enable. When asserted permits ALS interrupts to be generated, subject to the persist filter.
#define TSL2591_ENABLE_NPIEN (0x80) // No Persist Interrupt Enable. When asserted NP Threshold conditions will generate an interrupt, bypassing the persist filter
#define TSL2591_LUX_DF (408.0F)
#define TSL2591_LUX_COEFB (1.64F) // CH0 coefficient
#define TSL2591_LUX_COEFC (0.59F) // CH1 coefficient A
#define TSL2591_LUX_COEFD (0.86F) // CH2 coefficient B
enum
{
TSL2591_REGISTER_ENABLE = 0x00,
TSL2591_REGISTER_CONTROL = 0x01,
TSL2591_REGISTER_THRESHOLD_AILTL = 0x04, // ALS low threshold lower byte
TSL2591_REGISTER_THRESHOLD_AILTH = 0x05, // ALS low threshold upper byte
TSL2591_REGISTER_THRESHOLD_AIHTL = 0x06, // ALS high threshold lower byte
TSL2591_REGISTER_THRESHOLD_AIHTH = 0x07, // ALS high threshold upper byte
TSL2591_REGISTER_THRESHOLD_NPAILTL = 0x08, // No Persist ALS low threshold lower byte
TSL2591_REGISTER_THRESHOLD_NPAILTH = 0x09, // etc
TSL2591_REGISTER_THRESHOLD_NPAIHTL = 0x0A,
TSL2591_REGISTER_THRESHOLD_NPAIHTH = 0x0B,
TSL2591_REGISTER_PERSIST_FILTER = 0x0C,
TSL2591_REGISTER_PACKAGE_PID = 0x11,
TSL2591_REGISTER_DEVICE_ID = 0x12,
TSL2591_REGISTER_DEVICE_STATUS = 0x13,
TSL2591_REGISTER_CHAN0_LOW = 0x14,
TSL2591_REGISTER_CHAN0_HIGH = 0x15,
TSL2591_REGISTER_CHAN1_LOW = 0x16,
TSL2591_REGISTER_CHAN1_HIGH = 0x17
};
typedef enum
{
TSL2591_INTEGRATIONTIME_100MS = 0x00,
TSL2591_INTEGRATIONTIME_200MS = 0x01,
TSL2591_INTEGRATIONTIME_300MS = 0x02,
TSL2591_INTEGRATIONTIME_400MS = 0x03,
TSL2591_INTEGRATIONTIME_500MS = 0x04,
TSL2591_INTEGRATIONTIME_600MS = 0x05,
}
tsl2591IntegrationTime_t;
typedef enum
{
// bit 7:4: 0
TSL2591_PERSIST_EVERY = 0x00, // Every ALS cycle generates an interrupt
TSL2591_PERSIST_ANY = 0x01, // Any value outside of threshold range
TSL2591_PERSIST_2 = 0x02, // 2 consecutive values out of range
TSL2591_PERSIST_3 = 0x03, // 3 consecutive values out of range
TSL2591_PERSIST_5 = 0x04, // 5 consecutive values out of range
TSL2591_PERSIST_10 = 0x05, // 10 consecutive values out of range
TSL2591_PERSIST_15 = 0x06, // 15 consecutive values out of range
TSL2591_PERSIST_20 = 0x07, // 20 consecutive values out of range
TSL2591_PERSIST_25 = 0x08, // 25 consecutive values out of range
TSL2591_PERSIST_30 = 0x09, // 30 consecutive values out of range
TSL2591_PERSIST_35 = 0x0A, // 35 consecutive values out of range
TSL2591_PERSIST_40 = 0x0B, // 40 consecutive values out of range
TSL2591_PERSIST_45 = 0x0C, // 45 consecutive values out of range
TSL2591_PERSIST_50 = 0x0D, // 50 consecutive values out of range
TSL2591_PERSIST_55 = 0x0E, // 55 consecutive values out of range
TSL2591_PERSIST_60 = 0x0F, // 60 consecutive values out of range
}
tsl2591Persist_t;
typedef enum
{
TSL2591_GAIN_LOW = 0x00, // low gain (1x)
TSL2591_GAIN_MED = 0x10, // medium gain (25x)
TSL2591_GAIN_HIGH = 0x20, // medium gain (428x)
TSL2591_GAIN_MAX = 0x30, // max gain (9876x)
}
tsl2591Gain_t;
class Adafruit_TSL2591 : public Adafruit_Sensor
{
public:
Adafruit_TSL2591(int32_t sensorID = -1);
boolean begin ( void );
void enable ( void );
void disable ( void );
void write8 ( uint8_t r);
void write8 ( uint8_t r, uint8_t v );
uint16_t read16 ( uint8_t reg );
uint8_t read8 ( uint8_t reg );
uint32_t calculateLux ( uint16_t ch0, uint16_t ch1 );
float calculateLuxf ( uint16_t ch0, uint16_t ch1 );
void setGain ( tsl2591Gain_t gain );
void setTiming ( tsl2591IntegrationTime_t integration );
uint16_t getLuminosity (uint8_t channel );
uint32_t getFullLuminosity ( );
tsl2591IntegrationTime_t getTiming();
tsl2591Gain_t getGain();
// Interrupt
void clearInterrupt(void);
void registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold);
void registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold, tsl2591Persist_t persist);
uint8_t getStatus();
/* Unified Sensor API Functions */
bool getEvent ( sensors_event_t* );
void getSensor ( sensor_t* );
private:
tsl2591IntegrationTime_t _integration;
tsl2591Gain_t _gain;
int32_t _sensorID;
boolean _initialized;
};
#endif
-9
View File
@@ -1,9 +0,0 @@
This is an Arduino library for the TSL2591 digital luminosity (light) sensors.
Pick one up at http://www.adafruit.com/products/1980
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_TSL2591. Check that the Adafruit_TSL2591 folder contains Adafruit_TSL2591.cpp and Adafruit_TSL2591.h
Place the Adafruit_TSL2591 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
You'll also need the Adafruit_Sensor library from https://github.com/adafruit/Adafruit_Sensor
@@ -1,200 +0,0 @@
/* TSL2591 Digital Light Sensor */
/* Dynamic Range: 600M:1 */
/* Maximum Lux: 88K */
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
// Example for demonstrating the TSL2591 library - public domain!
// connect SCL to analog 5
// connect SDA to analog 4
// connect Vin to 3.3-5V DC
// connect GROUND to common ground
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
/**************************************************************************/
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" lux"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" lux"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" lux"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
delay(500);
}
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2591
*/
/**************************************************************************/
void configureSensor(void)
{
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
// tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
/* Display the gain and integration time for reference sake */
Serial.println(F("------------------------------------"));
Serial.print (F("Gain: "));
tsl2591Gain_t gain = tsl.getGain();
switch(gain)
{
case TSL2591_GAIN_LOW:
Serial.println(F("1x (Low)"));
break;
case TSL2591_GAIN_MED:
Serial.println(F("25x (Medium)"));
break;
case TSL2591_GAIN_HIGH:
Serial.println(F("428x (High)"));
break;
case TSL2591_GAIN_MAX:
Serial.println(F("9876x (Max)"));
break;
}
Serial.print (F("Timing: "));
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(F(" ms"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
}
/**************************************************************************/
/*
Program entry point for the Arduino sketch
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Starting Adafruit TSL2591 Test!"));
if (tsl.begin())
{
Serial.println(F("Found a TSL2591 sensor"));
}
else
{
Serial.println(F("No sensor found ... check your wiring?"));
while (1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
/* Configure the sensor */
configureSensor();
// Now we're ready to get readings ... move on to loop()!
}
/**************************************************************************/
/*
Shows how to perform a basic read on visible, full spectrum or
infrared light (returns raw 16-bit ADC values)
*/
/**************************************************************************/
void simpleRead(void)
{
// Simple data read example. Just read the infrared, fullspecrtrum diode
// or 'visible' (difference between the two) channels.
// This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
//uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
Serial.print(F("Luminosity: "));
Serial.println(x, DEC);
}
/**************************************************************************/
/*
Show how to read IR and Full Spectrum at once and convert to lux
*/
/**************************************************************************/
void advancedRead(void)
{
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
// That way you can do whatever math and comparisons you want!
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
Serial.print(F("IR: ")); Serial.print(ir); Serial.print(F(" "));
Serial.print(F("Full: ")); Serial.print(full); Serial.print(F(" "));
Serial.print(F("Visible: ")); Serial.print(full - ir); Serial.print(F(" "));
Serial.print(F("Lux: ")); Serial.println(tsl.calculateLux(full, ir));
}
/**************************************************************************/
/*
Performs a read using the Adafruit Unified Sensor API.
*/
/**************************************************************************/
void unifiedSensorAPIRead(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Display the results (light is measured in lux) */
Serial.print(F("[ ")); Serial.print(event.timestamp); Serial.print(F(" ms ] "));
if ((event.light == 0) |
(event.light > 4294966000.0) |
(event.light <-4294966000.0))
{
/* If event.light = 0 lux the sensor is probably saturated */
/* and no reliable data could be generated! */
/* if event.light is +/- 4294967040 there was a float over/underflow */
Serial.println(F("Invalid data (adjust gain or timing)"));
}
else
{
Serial.print(event.light); Serial.println(F(" lux"));
}
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void)
{
//simpleRead();
advancedRead();
// unifiedSensorAPIRead();
delay(500);
}
@@ -1,229 +0,0 @@
/* TSL2591 Digital Light Sensor, example with (simple) interrupt support */
/* Dynamic Range: 600M:1 */
/* Maximum Lux: 88K */
/* This example shows how the interrupt system on the TLS2591
* can be used to detect a meaningful change in light levels.
*
* Two thresholds can be set:
*
* Lower Threshold - Any light sample on CHAN0 below this value
* will trigger an interrupt
* Upper Threshold - Any light sample on CHAN0 above this value
* will trigger an interrupt
*
* If CHAN0 (full light) crosses below the low threshold specified,
* or above the higher threshold, an interrupt is asserted on the interrupt
* pin. The use of the HW pin is optional, though, since the change can
* also be detected in software by looking at the status byte via
* tsl.getStatus().
*
* An optional third parameter can be used in the .registerInterrupt
* function to indicate the number of samples that must stay outside
* the threshold window before the interrupt fires, providing some basic
* debouncing of light level data.
*
* For example, the following code will fire an interrupt on any and every
* sample outside the window threshold (meaning a sample below 100 or above
* 1500 on CHAN0 or FULL light):
*
* tsl.registerInterrupt(100, 1500, TSL2591_PERSIST_ANY);
*
* This code would require five consecutive changes before the interrupt
* fires though (see tls2591Persist_t in Adafruit_TLS2591.h for possible
* values):
*
* tsl.registerInterrupt(100, 1500, TSL2591_PERSIST_5);
*/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
// Example for demonstrating the TSL2591 library - public domain!
// connect SCL to analog 5
// connect SDA to analog 4
// connect Vin to 3.3-5V DC
// connect GROUND to common ground
// Interrupt thresholds and persistance
#define TLS2591_INT_THRESHOLD_LOWER (100)
#define TLS2591_INT_THRESHOLD_UPPER (1500)
//#define TLS2591_INT_PERSIST (TSL2591_PERSIST_ANY) // Fire on any valid change
#define TLS2591_INT_PERSIST (TSL2591_PERSIST_60) // Require at least 60 samples to fire
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
/**************************************************************************/
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2591
*/
/**************************************************************************/
void configureSensor(void)
{
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
// tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
/* Display the gain and integration time for reference sake */
Serial.println("------------------------------------");
Serial.print ("Gain: ");
tsl2591Gain_t gain = tsl.getGain();
switch (gain)
{
case TSL2591_GAIN_LOW:
Serial.println("1x (Low)");
break;
case TSL2591_GAIN_MED:
Serial.println("25x (Medium)");
break;
case TSL2591_GAIN_HIGH:
Serial.println("428x (High)");
break;
case TSL2591_GAIN_MAX:
Serial.println("9876x (Max)");
break;
}
Serial.print ("Timing: ");
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(" ms");
Serial.println("------------------------------------");
Serial.println("");
/* Setup the SW interrupt to trigger between 100 and 1500 lux */
/* Threshold values are defined at the top of this sketch */
tsl.clearInterrupt();
tsl.registerInterrupt(TLS2591_INT_THRESHOLD_LOWER,
TLS2591_INT_THRESHOLD_UPPER,
TLS2591_INT_PERSIST);
/* Display the interrupt threshold window */
Serial.print("Interrupt Threshold Window: -");
Serial.print(TLS2591_INT_THRESHOLD_LOWER, DEC);
Serial.print(" to +");
Serial.println(TLS2591_INT_THRESHOLD_LOWER, DEC);
Serial.println("");
}
/**************************************************************************/
/*
Program entry point for the Arduino sketch
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
// Enable this line for Flora, Zero and Feather boards with no FTDI chip
// Waits for the serial port to connect before sending data out
// while (!Serial) { delay(1); }
Serial.println("Starting Adafruit TSL2591 interrupt Test!");
if (tsl.begin())
{
Serial.println("Found a TSL2591 sensor");
}
else
{
Serial.println("No sensor found ... check your wiring?");
while (1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
/* Configure the sensor (including the interrupt threshold) */
configureSensor();
// Now we're ready to get readings ... move on to loop()!
}
/**************************************************************************/
/*
Show how to read IR and Full Spectrum at once and convert to lux
*/
/**************************************************************************/
void advancedRead(void)
{
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
// That way you can do whatever math and comparisons you want!
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
Serial.print("IR: "); Serial.print(ir); Serial.print(" ");
Serial.print("Full: "); Serial.print(full); Serial.print(" ");
Serial.print("Visible: "); Serial.print(full - ir); Serial.print(" ");
Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));
}
void getStatus(void)
{
uint8_t x = tsl.getStatus();
// bit 4: ALS Interrupt occured
// bit 5: No-persist Interrupt occurence
if (x & 0x10) {
Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
Serial.println("ALS Interrupt occured");
}
if (x & 0x20) {
Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
Serial.println("No-persist Interrupt occured");
}
// Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
Serial.print("Status: ");
Serial.println(x, BIN);
tsl.clearInterrupt();
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void)
{
advancedRead();
getStatus();
delay(500);
}
-9
View File
@@ -1,9 +0,0 @@
name=Adafruit TSL2591 Library
version=1.0.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Library for the TSL2591 digital luminosity (light) sensors.
paragraph=Library for the TSL2591 digital luminosity (light) sensors.
category=Sensors
url=https://github.com/adafruit/Adafruit_TSL2591_Library
architectures=*
+456
View File
@@ -0,0 +1,456 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
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 this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser 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 Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "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
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY 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
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
+40
View File
@@ -0,0 +1,40 @@
# ESP8266Ping
Let the ESP8266 ping a remote machine.
With this library an ESP8266 can ping a remote machine and know if it's reachable.
It provide some basic measurements on ping messages (avg response time).
## Usage
First, include the library in your sketch along with WiFi library:
```Arduino
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
```
Next, simply call the `Ping.ping()` function
```Arduino
IPAddress ip (192, 168, 0, 1); // The remote ip to ping
bool ret = Ping.ping(ip);
```
`ret` will be true if the remote responded to pings, false if not reachable.
The library supports hostname too, just pass a string instead of the ip address:
```Arduino
bool ret = Ping.ping("www.google.com");
```
Additionally, the function accept a second integer parameter `count` that specify how many pings has to be sent:
```Arduino
bool ret = Ping.ping(ip_or_host, 10);
```
After `Ping.ping()` has been called, the average response time (in milliseconds) can be retrieved with
```Arduino
int avg_time_ms = Ping.averageTime();
```
@@ -0,0 +1,43 @@
/*
* This example show how to ping a remote machine using it's hostname
*/
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
const char* ssid = "ssid";
const char* password = "passphrase";
const char* remote_host = "www.google.com";
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println();
Serial.print("WiFi connected with ip ");
Serial.println(WiFi.localIP());
Serial.print("Pinging host ");
Serial.println(remote_host);
if(Ping.ping(remote_host)) {
Serial.println("Success!!");
} else {
Serial.println("Error :(");
}
}
void loop() { }
@@ -0,0 +1,44 @@
/*
* With this library an ESP8266 can ping a remote machine and know if it's reachable.
* It provides some basic measurements on ping messages (avg response time).
*/
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
const char* ssid = "ssid";
const char* password = "passphrase";
const IPAddress remote_ip(192, 168, 0, 1);
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println();
Serial.print("WiFi connected with ip ");
Serial.println(WiFi.localIP());
Serial.print("Pinging ip ");
Serial.println(remote_ip);
if(Ping.ping(remote_ip)) {
Serial.println("Success!!");
} else {
Serial.println("Error :(");
}
}
void loop() { }
+26
View File
@@ -0,0 +1,26 @@
#######################################
# Syntax Coloring Map For ESP8266Ping
#######################################
#######################################
# Library (KEYWORD3)
#######################################
ESP8266Ping KEYWORD3
#######################################
# Datatypes (KEYWORD1)
#######################################
Ping KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
ping KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
@@ -0,0 +1,9 @@
name=ESPEasy_ESP8266Ping
version=1.0
author=Daniele Colanardi
maintainer=Daniele Colanardi <dancol90@gmail.com>
sentence=Let the ESP8266 ping a remote machine.
paragraph=With this library an ESP8266 can ping a remote machine and know if it's reachable. It provide some basic measurements on ping messages (avg response time). Lib name renamed to avoid conflicts in Arduino IDE.
category=Communication
url=
architectures=esp8266
+59
View File
@@ -0,0 +1,59 @@
/*
ESP8266Ping - Ping library for ESP8266
Copyright (c) 2015 Daniele Colanardi. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ESP8266Ping_H
#define ESP8266Ping_H
#include <Arduino.h>
#include <ESP8266WiFi.h>
extern "C" {
#include <ping.h>
}
#ifdef ENABLE_DEBUG_PING
#define DEBUG_PING(...) Serial.printf(__VA_ARGS__)
#else
#define DEBUG_PING(...)
#endif
class PingClass {
public:
PingClass();
bool ping(IPAddress dest, byte count = 5);
bool ping(const char* host, byte count = 5);
int averageTime();
protected:
static void _ping_sent_cb(void *opt, void *pdata);
static void _ping_recv_cb(void *opt, void *pdata);
IPAddress _dest;
ping_option _options;
static byte _expected_count, _errors, _success;
static int _avg_time;
};
#include "ESP8266Ping.impl.h"
PingClass Ping;
#endif
@@ -0,0 +1,111 @@
/*
ESP8266Ping - Ping library for ESP8266
Copyright (c) 2015 Daniele Colanardi. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
extern "C" void esp_schedule();
extern "C" void esp_yield();
PingClass::PingClass() {}
bool PingClass::ping(IPAddress dest, byte count) {
_expected_count = count;
_errors = 0;
_success = 0;
_avg_time = 0;
memset(&_options, 0, sizeof(struct ping_option));
// Repeat count (how many time send a ping message to destination)
_options.count = count;
// Time interval between two ping (seconds??)
_options.coarse_time = 1;
// Destination machine
_options.ip = dest;
// Callbacks
_options.recv_function = reinterpret_cast<ping_recv_function>(&PingClass::_ping_recv_cb);
_options.sent_function = NULL; //reinterpret_cast<ping_sent_function>(&_ping_sent_cb);
// Let's go!
if(ping_start(&_options)) {
// Suspend till the process end
esp_yield();
}
return (_success > 0);
}
bool PingClass::ping(const char* host, byte count) {
IPAddress remote_addr;
if (WiFi.hostByName(host, remote_addr))
return ping(remote_addr, count);
return false;
}
int PingClass::averageTime() {
return _avg_time;
}
void PingClass::_ping_recv_cb(void *opt, void *resp) {
// Cast the parameters to get some usable info
ping_resp* ping_resp = reinterpret_cast<struct ping_resp*>(resp);
//ping_option* ping_opt = reinterpret_cast<struct ping_option*>(opt);
// Error or success?
if (ping_resp->ping_err == -1)
_errors++;
else {
_success++;
_avg_time += ping_resp->resp_time;
}
// Some debug info
DEBUG_PING(
"DEBUG: ping reply\n"
"\ttotal_count = %d \n"
"\tresp_time = %d \n"
"\tseqno = %d \n"
"\ttimeout_count = %d \n"
"\tbytes = %d \n"
"\ttotal_bytes = %d \n"
"\ttotal_time = %d \n"
"\tping_err = %d \n",
ping_resp->total_count, ping_resp->resp_time, ping_resp->seqno,
ping_resp->timeout_count, ping_resp->bytes, ping_resp->total_bytes,
ping_resp->total_time, ping_resp->ping_err
);
// Is it time to end?
// Don't using seqno because it does not increase on error
if (_success + _errors == _expected_count) {
_avg_time = _avg_time / _expected_count;
DEBUG_PING("Avg resp time %d ms\n", _avg_time);
// Done, return to main functiom
esp_schedule();
}
}
byte PingClass::_expected_count = 0;
byte PingClass::_errors = 0;
byte PingClass::_success = 0;
int PingClass::_avg_time = 0;
+21 -11
View File
@@ -1,11 +1,4 @@
//www.DFRobot.com
//last updated on 21/12/2011
//Tim Starling Fix the reset bug (Thanks Tim)
//wiki doc http://www.dfrobot.com/wiki/index.php?title=I2C/TWI_LCD1602_Module_(SKU:_DFR0063)
//Support Forum: http://www.dfrobot.com/forum/
//Compatible with the Arduino IDE 1.0
//Library version:1.1
// Based on the work by DFRobot
#include "LiquidCrystal_I2C.h"
#include <inttypes.h>
@@ -16,7 +9,7 @@
#define printIIC(args) Wire.write(args)
inline size_t LiquidCrystal_I2C::write(uint8_t value) {
send(value, Rs);
return 0;
return 1;
}
#else
@@ -59,6 +52,11 @@ LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t l
_backlightval = LCD_NOBACKLIGHT;
}
void LiquidCrystal_I2C::oled_init(){
_oled = true;
init_priv();
}
void LiquidCrystal_I2C::init(){
init_priv();
}
@@ -134,6 +132,7 @@ void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
void LiquidCrystal_I2C::clear(){
command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
if (_oled) setCursor(0,0);
}
void LiquidCrystal_I2C::home(){
@@ -221,6 +220,15 @@ void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) {
}
}
//createChar with PROGMEM input
void LiquidCrystal_I2C::createChar(uint8_t location, const char *charmap) {
location &= 0x7; // we only have 8 locations 0-7
command(LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++) {
write(pgm_read_byte_near(charmap++));
}
}
// Turn the (optional) backlight off/on
void LiquidCrystal_I2C::noBacklight(void) {
_backlightval=LCD_NOBACKLIGHT;
@@ -309,6 +317,8 @@ void LiquidCrystal_I2C::printstr(const char c[]){
// unsupported API functions
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void LiquidCrystal_I2C::off(){}
void LiquidCrystal_I2C::on(){}
void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {}
@@ -318,5 +328,5 @@ uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;}
void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end){}
void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end){}
void LiquidCrystal_I2C::setContrast(uint8_t new_val){}
#pragma GCC diagnostic pop
+7 -2
View File
@@ -1,4 +1,4 @@
//DFRobot.com
//YWROBOT
#ifndef LiquidCrystal_I2C_h
#define LiquidCrystal_I2C_h
@@ -77,14 +77,18 @@ public:
void autoscroll();
void noAutoscroll();
void createChar(uint8_t, uint8_t[]);
void createChar(uint8_t location, const char *charmap);
// Example: const char bell[8] PROGMEM = {B00100,B01110,B01110,B01110,B11111,B00000,B00100,B00000};
void setCursor(uint8_t, uint8_t);
#if defined(ARDUINO) && ARDUINO >= 100
#if defined(ARDUINO) && ARDUINO >= 100
virtual size_t write(uint8_t);
#else
virtual void write(uint8_t);
#endif
void command(uint8_t);
void init();
void oled_init();
////compatibility API function aliases
void blink_on(); // alias for blink()
@@ -118,6 +122,7 @@ private:
uint8_t _displaycontrol;
uint8_t _displaymode;
uint8_t _numlines;
bool _oled = false;
uint8_t _cols;
uint8_t _rows;
uint8_t _backlightval;
+2
View File
@@ -0,0 +1,2 @@
# LiquidCrystal_I2C
LiquidCrystal Arduino library for the DFRobot I2C LCD displays
-69
View File
@@ -1,69 +0,0 @@
1,6c1
< //www.DFRobot.com
< //last updated on 26/11/2010
< //Tim Starling Fix the reset bug (Thanks Tim)
< //wiki doc http://www.dfrobot.com/wiki/index.php?title=I2C/TWI_LCD1602_Module_(SKU:_DFR0063)
< //Support Forum: http://www.dfrobot.com/forum/
<
---
> // LiquidCrystal_I2C V2.0
10d4
< #include "WProgram.h"
12c6
<
---
> #include "Arduino.h"
67c61
< delay(50);
---
> delayMicroseconds(50000);
77,90c71,84
< // we start in 8bit mode, try to set 4 bit mode
< write4bits(0x03 << 4);
< delayMicroseconds(4500); // wait min 4.1ms
<
< // second try
< write4bits(0x03 << 4);
< delayMicroseconds(4500); // wait min 4.1ms
<
< // third go!
< write4bits(0x03 << 4);
< delayMicroseconds(150);
<
< // finally, set to 4-bit interface
< write4bits(0x02 << 4);
---
> // we start in 8bit mode, try to set 4 bit mode
> write4bits(0x03);
> delayMicroseconds(4500); // wait min 4.1ms
>
> // second try
> write4bits(0x03);
> delayMicroseconds(4500); // wait min 4.1ms
>
> // third go!
> write4bits(0x03);
> delayMicroseconds(150);
>
> // finally, set to 4-bit interface
> write4bits(0x02);
225c219
< inline void LiquidCrystal_I2C::write(uint8_t value) {
---
> inline size_t LiquidCrystal_I2C::write(uint8_t value) {
226a221
> return 0;
235,238c230,233
< uint8_t highnib=value&0xf0;
< uint8_t lownib=(value<<4)&0xf0;
< write4bits((highnib)|mode);
< write4bits((lownib)|mode);
---
> uint8_t highnib=value>>4;
> uint8_t lownib=value & 0x0F;
> write4bits((highnib)|mode);
> write4bits((lownib)|mode);
248c243
< Wire.send((int)(_data) | _backlightval);
---
> Wire.write((int)(_data) | _backlightval);
+4 -4
View File
@@ -1,4 +1,4 @@
//DFRobot.com
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
@@ -19,7 +19,7 @@ uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
@@ -52,7 +52,7 @@ void displayKeyCodes(void) {
while (1) {
lcd.clear();
lcd.print("Codes 0x"); lcd.print(i, HEX);
lcd.print("-0x"); lcd.print(i+16, HEX);
lcd.print("-0x"); lcd.print(i+15, HEX);
lcd.setCursor(0, 1);
for (int j=0; j<16; j++) {
lcd.printByte(i+j);
@@ -67,4 +67,4 @@ void loop()
{
}
+11 -3
View File
@@ -1,20 +1,28 @@
//DFRobot.com
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
void loop()
{
}
+2 -2
View File
@@ -1,14 +1,14 @@
/*
* Displays text sent over the serial port (e.g. from the Serial Monitor) on
* an attached LCD.
* DFRobot.com
* YWROBOT
*Compatible with the Arduino IDE 1.0
*Library version:1.1
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
View File
+16
View File
@@ -0,0 +1,16 @@
{
"name": "LiquidCrystal_I2C",
"keywords": "LCD, liquidcrystal, I2C",
"description": "A library for DFRobot I2C LCD displays",
"repository":
{
"type": "git",
"url": "https://github.com/marcoschwartz/LiquidCrystal_I2C.git"
},
"frameworks": "arduino",
"platforms":
[
"atmelavr",
"espressif8266"
]
}
+9
View File
@@ -0,0 +1,9 @@
name=LiquidCrystal_I2C
version=1.1.4
author=Frank de Brabander
maintainer=Marco Schwartz <marcolivier.schwartz@gmail.com>
sentence=A library for I2C LCD displays.
paragraph= The library allows to control I2C displays with functions extremely similar to LiquidCrystal library. THIS LIBRARY MIGHT NOT BE COMPATIBLE WITH EXISTING SKETCHES.
category=Display
url=https://github.com/marcoschwartz/LiquidCrystal_I2C
architectures=avr
+29 -116
View File
@@ -25,7 +25,7 @@
#include "jkSDS011.h"
CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX)
CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX) : _serial(pinRX, pinTX)
{
_sws = ! ( pinRX < 0 || pinRX == 3 );
_pm2_5 = NAN;
@@ -35,131 +35,43 @@ CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX)
_pm10_avr = 0;
_avr = 0;
_data.SetPacketLength(10);
_command.SetPacketLength(19);
_working_period = -1;
_sleepmode_active = false;
_serial = new ESPeasySoftwareSerial(pinRX, pinTX);
_serial->begin(9600);
}
CjkSDS011::~CjkSDS011() {
delete _serial;
}
void CjkSDS011::SendCommand(byte byte1, byte byte2, byte byte3) {
_command[0] = 0xAA; // Head
_command[1] = 0xB4; // Command ID
_command[2] = byte1; // Data Byte 1
_command[3] = byte2; // Data Byte 2
_command[4] = byte3; // Data Byte 3
_command[5] = 0; // Data Byte 4
_command[6] = 0; // Data Byte 5
_command[7] = 0; // Data Byte 6
_command[8] = 0; // Data Byte 7
_command[9] = 0; // Data Byte 8
_command[10] = 0; // Data Byte 9
_command[11] = 0; // Data Byte 10
_command[12] = 0; // Data Byte 11
_command[13] = 0; // Data Byte 12
_command[14] = 0; // Data Byte 13
_command[15] = 0xFF; // Device ID byte 1, FF: All sensor response
_command[16] = 0xFF; // Device ID byte 2, FF: All sensor response
byte checksum = 0;
for (byte i=2; i< 17; ++i) {
checksum += _command[i];
}
_command[17] = checksum; // Checksum
_command[18] = 0xAB; // Tail
for (int i = 0; i < 19; ++i) {
_serial->write(_command[i]);
}
}
void CjkSDS011::SetSleepMode(bool enabled) {
byte databyte3 = enabled ? 0 : 1;
SendCommand(6, 1, databyte3);
}
void CjkSDS011::SetWorkingPeriod(int minutes) {
// Data byte 1: 8
// Data byte 2: 0: query the current mode
// 1: set mode
// Data byte 3: 0continuous(default)
// 1-30minutework 30 seconds and sleep n*60-30 seconds
if (minutes < 0 || minutes > 30) return;
// Working period is stored in the flash of the sensor. Only write to change.
const int currentWorkingPeriod = GetWorkingPeriod();
if (minutes != currentWorkingPeriod)
SendCommand(8, 1, minutes);
}
int CjkSDS011::GetWorkingPeriod() {
// Data byte 1: 8
// Data byte 2: 0: query the current mode
// 1: set mode
// Data byte 3: 0continuous(default)
// 1-30minutework 30 seconds and sleep n*60-30 seconds
SendCommand(8, 0, 0);
Process();
return _working_period;
}
void CjkSDS011::ParseCommandReply() {
switch(_data[2]) {
case 6: // Enable/Disable sleep mode.
if (_data[3] == 0)
_sleepmode_active = _data[4];
break;
case 8: // Set/Get working period
if (_data[3] == 0)
_working_period = _data[4];
break;
default:
// Not implemented.
break;
}
_serial.begin(9600);
}
void CjkSDS011::Process()
{
while (_serial->available())
while (_serial.available())
{
_data.AddData(_serial->read());
_data.AddData(_serial.read());
if (_data[0] == 0xAA && _data[9] == 0xAB) // correct packet frame?
if (_data[0] == 0xAA && _data[9] == 0xAB && (_data[1] == 0xC0 || _data[1] == 0xCF)) // correct packet frame?
{
byte checksum = 0;
for (byte i=2; i<= 7; i++)
checksum += _data[i];
checksum += _data[i];
if (checksum != _data[8])
continue;
switch(_data[1]) {
case 0xC0: // SDS011 or SDS018?
_pm2_5 = (float)((_data[3] << 8) | _data[2]) * 0.1;
_pm10_ = (float)((_data[5] << 8) | _data[4]) * 0.1;
_available = true;
break;
case 0xCF: // SDS198?
_pm2_5 = (float)((_data[5] << 8) | _data[4]);
_pm10_ = (float)((_data[3] << 8) | _data[2]);
_available = true;
break;
case 0xC5: // Reply on command ID 0xB4
ParseCommandReply();
break;
default:
break;
if (_data[1] == 0xC0) // SDS011 or SDS018?
{
_pm2_5 = (float)((_data[3] << 8) | _data[2]) * 0.1;
_pm10_ = (float)((_data[5] << 8) | _data[4]) * 0.1;
_available = true;
}
if (_available) {
_pm2_5avr += _pm2_5;
_pm10_avr += _pm10_;
_avr++;
_data.Clear();
return;
else if (_data[1] == 0xCF) // SDS198?
{
_pm2_5 = (float)((_data[5] << 8) | _data[4]);
_pm10_ = (float)((_data[3] << 8) | _data[2]);
_available = true;
}
else
continue;
_pm2_5avr += _pm2_5;
_pm10_avr += _pm10_;
_avr++;
return;
}
}
}
@@ -171,7 +83,7 @@ boolean CjkSDS011::available()
return ret;
}
boolean CjkSDS011::ReadAverage(float &pm25, float &pm10)
void CjkSDS011::ReadAverage(float &pm25, float &pm10)
{
if (_avr)
{
@@ -180,9 +92,10 @@ boolean CjkSDS011::ReadAverage(float &pm25, float &pm10)
_pm2_5avr = 0;
_pm10_avr = 0;
_avr = 0;
return true;
}
pm25 = NAN;
pm10 = NAN;
return false;
else
{
pm25 = NAN;
pm10 = NAN;
}
}
+3 -24
View File
@@ -27,15 +27,13 @@
#define _jkSDS011_H_
#include "Arduino.h"
//#include "SensorSerial.h"
#include "SensorSerial.h"
#include "SensorSerialBuffer.h"
#include "ESPeasySoftwareSerial.h"
class CjkSDS011
{
public:
CjkSDS011(int16_t pinRX, int16_t pinTX);
virtual ~CjkSDS011();
void Process();
@@ -44,28 +42,11 @@ public:
float GetPM2_5() { return _pm2_5; };
float GetPM10_() { return _pm10_; };
// Return true when there are valid samples.
boolean ReadAverage(float &pm25, float &pm10);
void SetSleepMode(bool enabled);
// Set interval to get new data, 0 .. 30 minutes.
// Minutes = 0 => continous mode.
// The setting is still effective after power off(factory default is continuous measurement)
void SetWorkingPeriod(int minutes);
// Get the working period in minutes (0 = continuous reading)
// Negative return value indicates error during communication.
int GetWorkingPeriod();
void ReadAverage(float &pm25, float &pm10);
private:
void SendCommand(byte byte1, byte byte2, byte byte3);
void ParseCommandReply();
// SensorSerial _serial;
ESPeasySoftwareSerial *_serial;
SensorSerial _serial;
CSensorSerialBuffer _data;
CSensorSerialBuffer _command;
float _pm2_5;
float _pm10_;
float _pm2_5avr;
@@ -73,8 +54,6 @@ private:
uint16_t _avr;
boolean _available;
boolean _sws;
int _working_period;
boolean _sleepmode_active;
};
#endif
@@ -22,6 +22,10 @@ SOFTWARE.
See more at http://blog.squix.ch
*/
#ifndef DIALOG_PLAIN_FONT_H
#define DIALOG_PLAIN_FONT_H
// OLED library version >= 3.0.0
// Created by http://oleddisplay.squix.ch/ Consider a donation
// In case of problems make sure that you are using the font file with the correct version!
@@ -481,3 +485,6 @@ const char Dialog_plain_12[] PROGMEM = {
0x00,0x00,0xFC,0x7F,0x40,0x04,0x20,0x08,0x20,0x08,0x60,0x0C,0xC0,0x07, // 254
0x00,0x00,0xE0,0x40,0x04,0x47,0x00,0x38,0x84,0x07,0xE0 // 255
};
#endif
+55 -34
View File
@@ -27,24 +27,32 @@
#include "OLEDDisplay.h"
OLEDDisplay::~OLEDDisplay() {
end();
}
bool OLEDDisplay::init() {
if (!this->connect()) {
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Can't establish connection to display\n");
return false;
}
if(this->buffer==NULL) {
this->buffer = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
if(!this->buffer) {
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Not enough memory to create display\n");
return false;
}
}
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
if(this->buffer_back==NULL) {
this->buffer_back = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
if(!this->buffer_back) {
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Not enough memory to create back buffer\n");
free(this->buffer);
return false;
}
}
#endif
sendInitCommands();
@@ -54,10 +62,11 @@ bool OLEDDisplay::init() {
}
void OLEDDisplay::end() {
if (this->buffer) free(this->buffer);
if (this->buffer) { free(this->buffer); this->buffer = NULL; }
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
if (this->buffer_back) free(this->buffer_back);
if (this->buffer_back) { free(this->buffer_back); this->buffer_back = NULL; }
#endif
if (this->logBuffer != NULL) { free(this->logBuffer); this->logBuffer = NULL; }
}
void OLEDDisplay::resetDisplay(void) {
@@ -73,11 +82,11 @@ void OLEDDisplay::setColor(OLEDDISPLAY_COLOR color) {
}
void OLEDDisplay::setPixel(int16_t x, int16_t y) {
if (x >= 0 && x < 128 && y >= 0 && y < 64) {
if (x >= 0 && x < this->width() && y >= 0 && y < this->height()) {
switch (color) {
case WHITE: buffer[x + (y / 8) * DISPLAY_WIDTH] |= (1 << (y & 7)); break;
case BLACK: buffer[x + (y / 8) * DISPLAY_WIDTH] &= ~(1 << (y & 7)); break;
case INVERSE: buffer[x + (y / 8) * DISPLAY_WIDTH] ^= (1 << (y & 7)); break;
case WHITE: buffer[x + (y / 8) * this->width()] |= (1 << (y & 7)); break;
case BLACK: buffer[x + (y / 8) * this->width()] &= ~(1 << (y & 7)); break;
case INVERSE: buffer[x + (y / 8) * this->width()] ^= (1 << (y & 7)); break;
}
}
}
@@ -222,21 +231,21 @@ void OLEDDisplay::fillCircle(int16_t x0, int16_t y0, int16_t radius) {
}
void OLEDDisplay::drawHorizontalLine(int16_t x, int16_t y, int16_t length) {
if (y < 0 || y >= DISPLAY_HEIGHT) { return; }
if (y < 0 || y >= this->height()) { return; }
if (x < 0) {
length += x;
x = 0;
}
if ( (x + length) > DISPLAY_WIDTH) {
length = (DISPLAY_WIDTH - x);
if ( (x + length) > this->width()) {
length = (this->width() - x);
}
if (length <= 0) { return; }
uint8_t * bufferPtr = buffer;
bufferPtr += (y >> 3) * DISPLAY_WIDTH;
bufferPtr += (y >> 3) * this->width();
bufferPtr += x;
uint8_t drawBit = 1 << (y & 7);
@@ -255,15 +264,15 @@ void OLEDDisplay::drawHorizontalLine(int16_t x, int16_t y, int16_t length) {
}
void OLEDDisplay::drawVerticalLine(int16_t x, int16_t y, int16_t length) {
if (x < 0 || x >= DISPLAY_WIDTH) return;
if (x < 0 || x >= this->width()) return;
if (y < 0) {
length += y;
y = 0;
}
if ( (y + length) > DISPLAY_HEIGHT) {
length = (DISPLAY_HEIGHT - y);
if ( (y + length) > this->height()) {
length = (this->height() - y);
}
if (length <= 0) return;
@@ -273,7 +282,7 @@ void OLEDDisplay::drawVerticalLine(int16_t x, int16_t y, int16_t length) {
uint8_t drawBit;
uint8_t *bufferPtr = buffer;
bufferPtr += (y >> 3) * DISPLAY_WIDTH;
bufferPtr += (y >> 3) * this->width();
bufferPtr += x;
if (yOffset) {
@@ -293,7 +302,7 @@ void OLEDDisplay::drawVerticalLine(int16_t x, int16_t y, int16_t length) {
if (length < yOffset) return;
length -= yOffset;
bufferPtr += DISPLAY_WIDTH;
bufferPtr += this->width();
}
if (length >= 8) {
@@ -303,14 +312,14 @@ void OLEDDisplay::drawVerticalLine(int16_t x, int16_t y, int16_t length) {
drawBit = (color == WHITE) ? 0xFF : 0x00;
do {
*bufferPtr = drawBit;
bufferPtr += DISPLAY_WIDTH;
bufferPtr += this->width();
length -= 8;
} while (length >= 8);
break;
case INVERSE:
do {
*bufferPtr = ~(*bufferPtr);
bufferPtr += DISPLAY_WIDTH;
bufferPtr += this->width();
length -= 8;
} while (length >= 8);
break;
@@ -340,7 +349,7 @@ void OLEDDisplay::drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16
drawHorizontalLine(xRadius, y + height, width - doubleRadius + 1);
drawCircleQuads(x + width - radius, yRadius, radius, 0b00001001);
uint16_t maxProgressWidth = (width - doubleRadius - 1) * progress / 100;
uint16_t maxProgressWidth = (width - doubleRadius + 1) * progress / 100;
fillCircle(xRadius, yRadius, innerRadius);
fillRect(xRadius + 1, y + 2, maxProgressWidth, height - 3);
@@ -353,7 +362,7 @@ void OLEDDisplay::drawFastImage(int16_t xMove, int16_t yMove, int16_t width, int
void OLEDDisplay::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *xbm) {
int16_t widthInXbm = (width + 7) / 8;
uint8_t data;
uint8_t data = 0;
for(int16_t y = 0; y < height; y++) {
for(int16_t x = 0; x < width; x++ ) {
@@ -388,11 +397,13 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u
case TEXT_ALIGN_RIGHT:
xMove -= textWidth;
break;
case TEXT_ALIGN_LEFT:
break;
}
// Don't draw anything if it is not on the screen.
if (xMove + textWidth < 0 || xMove > DISPLAY_WIDTH ) {return;}
if (yMove + textHeight < 0 || yMove > DISPLAY_HEIGHT) {return;}
if (xMove + textWidth < 0 || xMove > this->width() ) {return;}
if (yMove + textHeight < 0 || yMove > this->width() ) {return;}
for (uint16_t j = 0; j < textLength; j++) {
int16_t xPos = xMove + cursorX;
@@ -545,9 +556,16 @@ void OLEDDisplay::normalDisplay(void) {
sendCommand(NORMALDISPLAY);
}
void OLEDDisplay::setContrast(char contrast) {
void OLEDDisplay::setContrast(char contrast, char precharge, char comdetect) {
sendCommand(SETPRECHARGE); //0xD9
sendCommand(precharge); //0xF1 default, to lower the contrast, put 1-1F
sendCommand(SETCONTRAST);
sendCommand(contrast);
sendCommand(contrast); // 0-255
sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast)
sendCommand(comdetect); //0x40 default, to lower the contrast, put 0
sendCommand(DISPLAYALLON_RESUME);
sendCommand(NORMALDISPLAY);
sendCommand(DISPLAYON);
}
void OLEDDisplay::flipScreenVertically() {
@@ -596,6 +614,7 @@ bool OLEDDisplay::setLogBuffer(uint16_t lines, uint16_t chars){
uint16_t size = lines * chars;
if (size > 0) {
this->logBufferLine = 0; // Lines printed
this->logBufferFilled = 0; // Nothing stored yet
this->logBufferMaxLines = lines; // Lines max printable
this->logBufferSize = size; // Total number of characters the buffer can hold
this->logBuffer = (char *) malloc(size * sizeof(uint8_t));
@@ -670,7 +689,7 @@ void OLEDDisplay::sendInitCommands(void) {
sendCommand(SETDISPLAYCLOCKDIV);
sendCommand(0xF0); // Increase speed of the display max ~96Hz
sendCommand(SETMULTIPLEX);
sendCommand(0x3F);
sendCommand(this->height() - 1);
sendCommand(SETDISPLAYOFFSET);
sendCommand(0x00);
sendCommand(SETSTARTLINE);
@@ -681,11 +700,13 @@ void OLEDDisplay::sendInitCommands(void) {
sendCommand(SEGREMAP);
sendCommand(COMSCANINC);
sendCommand(SETCOMPINS);
sendCommand(0x12);
sendCommand(0x12); // according to the adafruit lib, sometimes this may need to be 0x02
sendCommand(SETCONTRAST);
sendCommand(0xCF);
sendCommand(SETPRECHARGE);
sendCommand(0xF1);
sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast)
sendCommand(0x40); //0x40 default, to lower the contrast, put 0
sendCommand(DISPLAYALLON_RESUME);
sendCommand(NORMALDISPLAY);
sendCommand(0x2e); // stop scroll
@@ -694,8 +715,8 @@ void OLEDDisplay::sendInitCommands(void) {
void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *data, uint16_t offset, uint16_t bytesInData) {
if (width < 0 || height < 0) return;
if (yMove + height < 0 || yMove > DISPLAY_HEIGHT) return;
if (xMove + width < 0 || xMove > DISPLAY_WIDTH) return;
if (yMove + height < 0 || yMove > this->height()) return;
if (xMove + width < 0 || xMove > this->width()) return;
uint8_t rasterHeight = 1 + ((height - 1) >> 3); // fast ceil(height / 8.0)
int8_t yOffset = yMove & 7;
@@ -717,13 +738,13 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt
byte currentByte = pgm_read_byte(data + offset + i);
int16_t xPos = xMove + (i / rasterHeight);
int16_t yPos = ((yMove >> 3) + (i % rasterHeight)) * DISPLAY_WIDTH;
int16_t yPos = ((yMove >> 3) + (i % rasterHeight)) * this->width();
int16_t yScreenPos = yMove + yOffset;
// int16_t yScreenPos = yMove + yOffset;
int16_t dataPos = xPos + yPos;
if (dataPos >= 0 && dataPos < DISPLAY_BUFFER_SIZE &&
xPos >= 0 && xPos < DISPLAY_WIDTH ) {
xPos >= 0 && xPos < this->width() ) {
if (yOffset >= 0) {
switch (this->color) {
@@ -731,11 +752,11 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt
case BLACK: buffer[dataPos] &= ~(currentByte << yOffset); break;
case INVERSE: buffer[dataPos] ^= currentByte << yOffset; break;
}
if (dataPos < (DISPLAY_BUFFER_SIZE - DISPLAY_WIDTH)) {
if (dataPos < (DISPLAY_BUFFER_SIZE - this->width())) {
switch (this->color) {
case WHITE: buffer[dataPos + DISPLAY_WIDTH] |= currentByte >> (8 - yOffset); break;
case BLACK: buffer[dataPos + DISPLAY_WIDTH] &= ~(currentByte >> (8 - yOffset)); break;
case INVERSE: buffer[dataPos + DISPLAY_WIDTH] ^= currentByte >> (8 - yOffset); break;
case WHITE: buffer[dataPos + this->width()] |= currentByte >> (8 - yOffset); break;
case BLACK: buffer[dataPos + this->width()] &= ~(currentByte >> (8 - yOffset)); break;
case INVERSE: buffer[dataPos + this->width()] ^= currentByte >> (8 - yOffset); break;
}
}
} else {
+21 -9
View File
@@ -44,9 +44,13 @@
// Display settings
#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 64
#define DISPLAY_BUFFER_SIZE 1024
#ifndef DISPLAY_WIDTH
#define DISPLAY_WIDTH 128
#endif
#ifndef DISPLAY_HEIGHT
#define DISPLAY_HEIGHT 64
#endif
#define DISPLAY_BUFFER_SIZE DISPLAY_WIDTH * DISPLAY_HEIGHT / 8
// Header Values
#define JUMPTABLE_BYTES 4
@@ -109,11 +113,17 @@ enum OLEDDISPLAY_TEXT_ALIGNMENT {
class OLEDDisplay : public Print {
private:
const int _width, _height;
public:
OLEDDisplay(const int width = DISPLAY_WIDTH, const int height = DISPLAY_HEIGHT) : _width(width), _height(height){ };
virtual ~OLEDDisplay();
virtual ~OLEDDisplay() {}
const int width(void) const { return _width; };
const int height(void) const { return _height; };
// Initialize the display
// Initialize the display
bool init();
// Free the memory used by the display
@@ -204,7 +214,9 @@ class OLEDDisplay : public Print {
void normalDisplay(void);
// Set display contrast
void setContrast(char contrast);
// really low brightness & contrast: contrast = 10, precharge = 5, comdetect = 0
// normal brightness & contrast: contrast = 100
void setContrast(char contrast, char precharge = 241, char comdetect = 64);
// Turn the display upside down
void flipScreenVertically();
@@ -229,10 +241,10 @@ class OLEDDisplay : public Print {
size_t write(uint8_t c);
size_t write(const char* s);
uint8_t *buffer;
uint8_t *buffer = NULL;
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
uint8_t *buffer_back;
uint8_t *buffer_back = NULL;
#endif
protected:
@@ -250,7 +262,7 @@ class OLEDDisplay : public Print {
char *logBuffer = NULL;
// Send a command to the display (low level function)
virtual void sendCommand(uint8_t com) {};
virtual void sendCommand(uint8_t com) {(void)com;};
// Connect to the display
virtual bool connect() { return false; };
+17 -17
View File
@@ -251,31 +251,31 @@ void OLEDDisplayUi::drawFrame(){
switch (this->state.frameState){
case IN_TRANSITION: {
float progress = (float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition;
int16_t x, y, x1, y1;
int16_t x = 0, y = 0, x1 = 0, y1 = 0;
switch(this->frameAnimationDirection){
case SLIDE_LEFT:
x = -128 * progress;
x = -this->display->width() * progress;
y = 0;
x1 = x + 128;
x1 = x + this->display->width();
y1 = 0;
break;
case SLIDE_RIGHT:
x = 128 * progress;
x = this->display->width() * progress;
y = 0;
x1 = x - 128;
x1 = x - this->display->width();
y1 = 0;
break;
case SLIDE_UP:
x = 0;
y = -64 * progress;
y = -this->display->height() * progress;
x1 = 0;
y1 = y + 64;
y1 = y + this->display->height();
break;
case SLIDE_DOWN:
x = 0;
y = 64 * progress;
y = this->display->height() * progress;
x1 = 0;
y1 = y - 64;
y1 = y - this->display->height();
break;
}
@@ -331,7 +331,7 @@ void OLEDDisplayUi::drawIndicator() {
return;
}
uint8_t posOfHighlightFrame;
uint8_t posOfHighlightFrame = 0;
float indicatorFadeProgress = 0;
// if the indicator needs to be slided in we want to
@@ -362,25 +362,25 @@ void OLEDDisplayUi::drawIndicator() {
uint16_t frameStartPos = (12 * frameCount / 2);
const char *image;
uint16_t x,y;
uint16_t x = 0, y = 0;
for (byte i = 0; i < this->frameCount; i++) {
switch (this->indicatorPosition){
case TOP:
y = 0 - (8 * indicatorFadeProgress);
x = 64 - frameStartPos + 12 * i;
x = (this->display->width() / 2) - frameStartPos + 12 * i;
break;
case BOTTOM:
y = 56 + (8 * indicatorFadeProgress);
x = 64 - frameStartPos + 12 * i;
y = (this->display->height() - 8) + (8 * indicatorFadeProgress);
x = (this->display->width() / 2) - frameStartPos + 12 * i;
break;
case RIGHT:
x = 120 + (8 * indicatorFadeProgress);
y = 32 - frameStartPos + 2 + 12 * i;
x = (this->display->width() - 8) + (8 * indicatorFadeProgress);
y = (this->display->height() / 2) - frameStartPos + 2 + 12 * i;
break;
case LEFT:
x = 0 - (8 * indicatorFadeProgress);
y = 32 - frameStartPos + 2 + 12 * i;
y = (this->display->height() / 2) - frameStartPos + 2 + 12 * i;
break;
}
@@ -0,0 +1,45 @@
#ifndef OLED_SSD1306_SH1106_IMAGES_H
#define OLED_SSD1306_SH1106_IMAGES_H
#define espeasy_logo_width 36
#define espeasy_logo_height 36
const char espeasy_logo_bits[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x40, 0xc0, 0x00, 0x00, 0x70, 0xf0, 0xe0,
0x01, 0x00, 0x78, 0xf8, 0xf0, 0x01, 0x00, 0x3c, 0x7c, 0xf8, 0x00, 0x00,
0x1e, 0x3e, 0x7c, 0x00, 0x00, 0x0f, 0x1f, 0x3e, 0x00, 0x80, 0x87, 0x0f,
0x1f, 0x00, 0xc0, 0xc3, 0x87, 0x0f, 0x00, 0xe0, 0xe1, 0xc3, 0x07, 0x00,
0xf0, 0xf0, 0xe1, 0xc3, 0x00, 0x78, 0xf8, 0xf0, 0xe1, 0x01, 0x30, 0x7c,
0xf8, 0xf0, 0x00, 0x00, 0x3e, 0x7c, 0x78, 0x00, 0x00, 0x1f, 0x3e, 0x3c,
0x00, 0x80, 0x0f, 0x1f, 0x1e, 0x00, 0xc0, 0x87, 0x0f, 0x0f, 0x00, 0xe0,
0xc3, 0x87, 0x07, 0x00, 0xf0, 0xe1, 0xc3, 0x03, 0x00, 0xf0, 0xf0, 0xe1,
0x01, 0x00, 0x78, 0xf8, 0xf0, 0x00, 0x00, 0x30, 0x7c, 0x78, 0x00, 0x00,
0x00, 0x3e, 0x3c, 0x00, 0x00, 0x00, 0x1f, 0x1e, 0x00, 0x00, 0x80, 0x0f,
0x0f, 0x78, 0x00, 0xc0, 0x87, 0x07, 0xfc, 0x00, 0xe0, 0xc3, 0x03, 0xfc,
0x01, 0xf0, 0xe1, 0x01, 0xfc, 0x01, 0xf8, 0xf0, 0x00, 0xfc, 0x00, 0x78,
0x70, 0x00, 0x78, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const char activeSymbole[] PROGMEM = {
B00000000,
B00000000,
B00011000,
B00100100,
B01000010,
B01000010,
B00100100,
B00011000
};
const char inactiveSymbole[] PROGMEM = {
B00000000,
B00000000,
B00000000,
B00000000,
B00011000,
B00011000,
B00000000,
B00000000
};
#endif
+13 -11
View File
@@ -38,7 +38,8 @@ class SSD1306Wire : public OLEDDisplay {
uint8_t _scl;
public:
SSD1306Wire(uint8_t _address, uint8_t _sda, uint8_t _scl) {
SSD1306Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, int width = DISPLAY_WIDTH, int height = DISPLAY_HEIGHT)
: OLEDDisplay(width, height) {
this->_address = _address;
this->_sda = _sda;
this->_scl = _scl;
@@ -53,6 +54,7 @@ class SSD1306Wire : public OLEDDisplay {
}
void display(void) {
const int x_offset = (128 - this->width()) / 2;
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
uint8_t minBoundY = ~0;
uint8_t maxBoundY = 0;
@@ -63,9 +65,9 @@ class SSD1306Wire : public OLEDDisplay {
// Calculate the Y bounding box of changes
// and copy buffer[pos] to buffer_back[pos];
for (y = 0; y < (DISPLAY_HEIGHT / 8); y++) {
for (x = 0; x < DISPLAY_WIDTH; x++) {
uint16_t pos = x + y * DISPLAY_WIDTH;
for (y = 0; y < (this->height() / 8); y++) {
for (x = 0; x < this->width(); x++) {
uint16_t pos = x + y * this->width();
if (buffer[pos] != buffer_back[pos]) {
minBoundY = _min(minBoundY, y);
maxBoundY = _max(maxBoundY, y);
@@ -80,11 +82,11 @@ class SSD1306Wire : public OLEDDisplay {
// If the minBoundY wasn't updated
// we can savely assume that buffer_back[pos] == buffer[pos]
// holdes true for all values of pos
if (minBoundY == ~0) return;
if (minBoundY == (uint8_t)(~0)) return;
sendCommand(COLUMNADDR);
sendCommand(minBoundX);
sendCommand(maxBoundX);
sendCommand(x_offset + minBoundX);
sendCommand(x_offset + maxBoundX);
sendCommand(PAGEADDR);
sendCommand(minBoundY);
@@ -97,7 +99,7 @@ class SSD1306Wire : public OLEDDisplay {
Wire.beginTransmission(_address);
Wire.write(0x40);
}
Wire.write(buffer[x + y * DISPLAY_WIDTH]);
Wire.write(buffer[x + y * this->width()]);
k++;
if (k == 16) {
Wire.endTransmission();
@@ -113,12 +115,12 @@ class SSD1306Wire : public OLEDDisplay {
#else
sendCommand(COLUMNADDR);
sendCommand(0x0);
sendCommand(0x7F);
sendCommand(x_offset);
sendCommand(x_offset + (this->width() - 1));
sendCommand(PAGEADDR);
sendCommand(0x0);
sendCommand(0x7);
sendCommand((this->height() / 8) - 1);
for (uint16_t i=0; i < DISPLAY_BUFFER_SIZE; i++) {
Wire.beginTransmission(this->_address);
+1 -1
View File
@@ -420,7 +420,7 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig
lastOutActivity = millis();
return rc == tlen + 4 + plength;
return rc == tlen + 3 + llen + plength;
}
boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
+1 -1
View File
@@ -73,7 +73,7 @@
#define MQTTQOS1 (1 << 1)
#define MQTTQOS2 (2 << 1)
#ifdef ESP8266
#if defined(ESP8266) || defined(ESP32)
#include <functional>
#define MQTT_CALLBACK_SIGNATURE std::function<void(char*, uint8_t*, unsigned int)> callback
#else
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
PATCH=puya.patch
for DIR in ~/.platformio/packages/framework-arduinoespressif8266*/; do
#not applied yet? (in upstream or otherwise)
if ! grep FLASH_QUIRK_WRITE_0_TO_1 $DIR/cores/esp8266/Esp.cpp >/dev/null; then
echo "Patching $DIR"
patch -p1 -d $DIR < $PATCH
fi
done
+32
View File
@@ -0,0 +1,32 @@
---
cores/esp8266/Esp.cpp | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp
index f4c0b220..c5c32f74 100644
--- a/cores/esp8266/Esp.cpp
+++ b/cores/esp8266/Esp.cpp
@@ -501,7 +501,21 @@ bool EspClass::flashEraseSector(uint32_t sector) {
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
ets_isr_mask(FLASH_INT_MASK);
- int rc = spi_flash_write(offset, (uint32_t*) data, size);
+ int rc;
+ uint32_t* ptr = data;
+#ifdef FLASH_QUIRK_WRITE_0_TO_1
+ static uint32_t read_buf[SPI_FLASH_SEC_SIZE / 4];
+ rc = spi_flash_read(offset, read_buf, size);
+ if (rc != 0) {
+ ets_isr_unmask(FLASH_INT_MASK);
+ return false;
+ }
+ for (size_t i = 0; i < size / 4; ++i) {
+ read_buf[i] &= data[i];
+ }
+ ptr = read_buf;
+#endif // FLASH_QUIRK_WRITE_0_TO_1
+ rc = spi_flash_write(offset, ptr, size);
ets_isr_unmask(FLASH_INT_MASK);
return rc == 0;
}
--
+56 -10
View File
@@ -22,11 +22,24 @@
[common]
build_flags = -D BUILD_GIT='"${env.TRAVIS_TAG}"'
lib_deps = ""
#normal version with stable plugins, 1024k version
[env:normal_ESP8266_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld
# upload_port = /dev/ttyUSB0
[env:normal_ESP8266_1024_DOUT]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp12e
upload_speed=460800
@@ -36,6 +49,7 @@ build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld
#normal version with stable plugins, 4096k version
[env:normal_ESP8266_4096]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
framework = arduino
board = esp12e
upload_speed=460800
@@ -45,6 +59,8 @@ build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.4m1m.ld
#normal version with stable plugins, 4096k version for esp8285
[env:normal_ESP8285_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp8285
upload_speed=460800
@@ -55,6 +71,8 @@ build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -DESP8285
#version with additional plugins (and dependend code) that are in test-stadium 1024k
[env:test_ESP8266_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp12e
upload_speed=460800
@@ -63,14 +81,25 @@ build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -D PLUGIN_BUILD
#version with additional plugins (and dependend code) that are in test-stadium 4096k
[env:test_ESP8266_4096]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.4m1m.ld -D PLUGIN_BUILD_TESTING
[env:test_ESP8266_4096_VCC]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.4m1m.ld -D PLUGIN_BUILD_TESTING -D FEATURE_ADC_VCC=true
#version with additional plugins (and dependend code) that are in test-stadium 4096k for esp8285
[env:test_ESP8285_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp8285
upload_speed=460800
@@ -80,6 +109,8 @@ build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -D PLUGIN_BUILD
#version with additional plugins (and dependend code) that is in development (probably broken or incomplete) 1024k
[env:dev_ESP8266_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp12e
upload_speed=460800
@@ -88,25 +119,40 @@ build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -D PLUGIN_BUILD
#version with additional plugins (and dependend code) that is in development (probably broken or incomplete) 4096k
[env:dev_ESP8266_4096]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.4m1m.ld -D PLUGIN_BUILD_TESTING -D PLUGIN_BUILD_DEV
#version with additional plugins (and dependend code) that is in development (probably broken or incomplete) 4096k
# Use latest ESP8266 core 2.4.0
[env:dev_ESP8266_4096_core2_4_0]
platform = espressif8266
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.4m1m.ld -D PLUGIN_BUILD_TESTING -D PLUGIN_BUILD_DEV
#version with additional plugins (and dependend code) that is in development (probably broken or incomplete) 4096k for esp8285
[env:dev_ESP8285_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp8285
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -D PLUGIN_BUILD_TESTING -D PLUGIN_BUILD_DEV -DESP8285
#special patched version for PUYA flash chips, see https://github.com/letscontrolit/ESPEasy/issues/650
[env:dev_ESP8266PUYA_1024]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -D PLUGIN_BUILD_TESTING -D PLUGIN_BUILD_DEV -D FLASH_QUIRK_WRITE_0_TO_1
#special patched version for PUYA flash chips, see https://github.com/letscontrolit/ESPEasy/issues/650
[env:dev_ESP8266PUYA_1024_VCC]
platform = espressif8266@1.5.0
lib_deps = ${common.lib_deps}
board_flash_mode = dout
framework = arduino
board = esp12e
upload_speed=460800
build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m128.ld -D PLUGIN_BUILD_TESTING -D PLUGIN_BUILD_DEV -D FLASH_QUIRK_WRITE_0_TO_1 -D FEATURE_ADC_VCC=true
+51 -26
View File
@@ -127,7 +127,7 @@ void ExecuteCommand(byte source, const char *Line)
SendUDPCommand(Par1, (char*)event.c_str(), event.length());
}
}
#ifdef FEATURE_SD
if (strcasecmp_P(Command, PSTR("sdcard")) == 0)
{
success = true;
@@ -146,7 +146,6 @@ void ExecuteCommand(byte source, const char *Line)
Serial.println(fname.c_str());
SD.remove((char*)fname.c_str());
}
#endif
if (strcasecmp_P(Command, PSTR("lowmem")) == 0)
{
@@ -179,21 +178,6 @@ void ExecuteCommand(byte source, const char *Line)
delay(60000);
}
if (strcasecmp_P(Command, PSTR("accessinfo")) == 0)
{
success = true;
Serial.print(F("Allowed IP range : "));
Serial.println(describeAllowedIPrange());
}
if (strcasecmp_P(Command, PSTR("clearaccessblock")) == 0)
{
success = true;
clearAccessBlock();
Serial.print(F("Allowed IP range : "));
Serial.println(describeAllowedIPrange());
}
if (strcasecmp_P(Command, PSTR("meminfo")) == 0)
{
success = true;
@@ -401,7 +385,12 @@ void ExecuteCommand(byte source, const char *Line)
IPAddress UDP_IP;
if(UDP_IP.fromString(ip)) {
portUDP.beginPacket(UDP_IP, port.toInt());
portUDP.write(message.c_str(), message.length());
#if defined(ESP8266)
portUDP.write(message.c_str(), message.length());
#endif
#if defined(ESP32)
portUDP.write((uint8_t*)message.c_str(), message.length());
#endif
portUDP.endPacket();
}
}
@@ -440,6 +429,42 @@ void ExecuteCommand(byte source, const char *Line)
}
}
// ****************************************
// special commands for Blynk
// ****************************************
#ifdef CPLUGIN_012
//FIXME: this should go to PLUGIN_WRITE in _C012.ino
if (strcasecmp_P(Command, PSTR("BlynkGet")) == 0)
{
byte first_enabled_blynk_controller = firstEnabledBlynkController();
if (first_enabled_blynk_controller == -1) {
status = F("Controller not enabled");
} else {
String strLine = Line;
strLine = strLine.substring(9);
int index = strLine.indexOf(',');
if (index > 0)
{
int index = strLine.lastIndexOf(',');
String blynkcommand = strLine.substring(index+1);
float value = 0;
if (Blynk_get(blynkcommand, first_enabled_blynk_controller, &value))
{
UserVar[(VARS_PER_TASK * (Par1 - 1)) + Par2 - 1] = value;
}
else
status = F("Error getting data");
}
else
{
if (!Blynk_get(strLine, first_enabled_blynk_controller))
{
status = F("Error getting data");
}
}
}
}
#endif
// ****************************************
// configure settings commands
@@ -517,12 +542,7 @@ void ExecuteCommand(byte source, const char *Line)
pinMode(0, INPUT);
pinMode(2, INPUT);
pinMode(15, INPUT);
#if defined(ESP8266)
ESP.reset();
#endif
#if defined(ESP32)
ESP.restart();
#endif
ESP.reset();
}
if (strcasecmp_P(Command, PSTR("Restart")) == 0)
@@ -542,6 +562,13 @@ void ExecuteCommand(byte source, const char *Line)
{
success = true;
ResetFactory();
#if defined(ESP8266)
ESP.reset();
#endif
#if defined(ESP32)
ESP.restart();
#endif
}
if (strcasecmp_P(Command, PSTR("Save")) == 0)
@@ -601,7 +628,6 @@ void ExecuteCommand(byte source, const char *Line)
yield();
}
#ifdef FEATURE_SD
void printDirectory(File dir, int numTabs) {
while (true) {
@@ -625,4 +651,3 @@ void printDirectory(File dir, int numTabs) {
entry.close();
}
}
#endif
+52 -60
View File
@@ -7,9 +7,6 @@ void sendData(struct EventStruct *event)
if (Settings.UseRules)
createRuleEvents(event->TaskIndex);
if (Settings.GlobalSync && Settings.TaskDeviceGlobalSync[event->TaskIndex])
SendUDPTaskData(0, event->TaskIndex, event->TaskIndex);
if (Settings.UseValueLogger && Settings.InitSPI && Settings.Pin_sd_cs >= 0)
SendValueLogger(event->TaskIndex);
@@ -62,11 +59,7 @@ void sendData(struct EventStruct *event)
boolean validUserVar(struct EventStruct *event) {
for (int i = 0; i < VARS_PER_TASK; ++i) {
const float f(UserVar[event->BaseVarIndex + i]);
if (f == NAN) return false; //("NaN");
if (f == INFINITY) return false; //("INFINITY");
if (-f == INFINITY)return false; //("-INFINITY");
if (isnan(f)) return false; //("isnan");
if (isinf(f)) return false; //("isinf");
if (!isValidFloat(f)) return false;
}
return true;
}
@@ -120,12 +113,14 @@ void callback(char* c_topic, byte* b_payload, unsigned int length) {
/*********************************************************************************************\
* Connect to MQTT message broker
\*********************************************************************************************/
void MQTTConnect(int controller_idx)
bool MQTTConnect(int controller_idx)
{
if (WiFi.status() != WL_CONNECTED) return;
ControllerSettingsStruct ControllerSettings;
LoadControllerSettings(controller_idx, (byte*)&ControllerSettings, sizeof(ControllerSettings));
if (!ControllerSettings.checkHostReachable(true))
return false;
if (MQTTclient.connected())
MQTTclient.disconnect();
if (ControllerSettings.UseDNS) {
MQTTclient.setServer(ControllerSettings.getHost().c_str(), ControllerSettings.Port);
} else {
@@ -136,61 +131,61 @@ void MQTTConnect(int controller_idx)
// MQTT needs a unique clientname to subscribe to broker
String clientid = F("ESPClient_");
clientid += WiFi.macAddress();
String subscribeTo = "";
String LWTTopic = ControllerSettings.Subscribe;
LWTTopic.replace(F("/#"), F("/status"));
LWTTopic.replace(F("%sysname%"), Settings.Name);
parseSystemVariables(LWTTopic, false);
LWTTopic += F("/LWT"); // Extend the topic for status updates of connected/disconnected status.
for (byte x = 1; x < 3; x++)
{
String log = "";
boolean MQTTresult = false;
boolean MQTTresult = false;
uint8_t willQos = 0;
boolean willRetain = true;
if ((SecuritySettings.ControllerUser[controller_idx] != 0) && (SecuritySettings.ControllerPassword[controller_idx] != 0))
MQTTresult = MQTTclient.connect(clientid.c_str(), SecuritySettings.ControllerUser[controller_idx], SecuritySettings.ControllerPassword[controller_idx], LWTTopic.c_str(), 0, 0, "Connection Lost");
else
MQTTresult = MQTTclient.connect(clientid.c_str(), LWTTopic.c_str(), 0, 1, "Connection Lost");
if (MQTTresult)
{
MQTTclient_should_reconnect = false;
log = F("MQTT : Connected to broker with client ID: ");
log += clientid;
addLog(LOG_LEVEL_INFO, log);
subscribeTo = ControllerSettings.Subscribe;
subscribeTo.replace(F("%sysname%"), Settings.Name);
MQTTclient.subscribe(subscribeTo.c_str());
log = F("Subscribed to: ");
log += subscribeTo;
addLog(LOG_LEVEL_INFO, log);
MQTTclient.publish(LWTTopic.c_str(), "Connected", 1);
statusLED(true);
break; // end loop if succesfull
}
else
{
log = F("MQTT : ClientID ");
log += clientid;
log +=" failed to connected to broker";
addLog(LOG_LEVEL_ERROR, log);
}
delay(500);
if ((SecuritySettings.ControllerUser[controller_idx] != 0) && (SecuritySettings.ControllerPassword[controller_idx] != 0)) {
MQTTresult = MQTTclient.connect(clientid.c_str(), SecuritySettings.ControllerUser[controller_idx], SecuritySettings.ControllerPassword[controller_idx],
LWTTopic.c_str(), willQos, willRetain, "Connection Lost");
} else {
MQTTresult = MQTTclient.connect(clientid.c_str(), LWTTopic.c_str(), willQos, willRetain, "Connection Lost");
}
yield();
if (!MQTTresult) {
addLog(LOG_LEVEL_ERROR, F("MQTT : Failed to connect to broker"));
return false;
}
MQTTclient_should_reconnect = false;
String log = F("MQTT : Connected to broker with client ID: ");
log += clientid;
addLog(LOG_LEVEL_INFO, log);
String subscribeTo = ControllerSettings.Subscribe;
parseSystemVariables(subscribeTo, false);
MQTTclient.subscribe(subscribeTo.c_str());
log = F("Subscribed to: ");
log += subscribeTo;
addLog(LOG_LEVEL_INFO, log);
if (MQTTclient.publish(LWTTopic.c_str(), "Connected", 1)) {
if (Settings.UseRules)
{
String event = F("MQTT#Connected");
rulesProcessing(event);
}
statusLED(true);
return true; // end loop if succesfull
}
return false;
}
/*********************************************************************************************\
* Check connection MQTT message broker
\*********************************************************************************************/
void MQTTCheck(int controller_idx)
bool MQTTCheck(int controller_idx)
{
byte ProtocolIndex = getProtocolIndex(Settings.Protocol[controller_idx]);
if (Protocol[ProtocolIndex].usesMQTT)
{
if (MQTTclient_should_reconnect || !MQTTclient.connected() || WiFi.status() != WL_CONNECTED)
if (MQTTclient_should_reconnect || !WiFiConnected(10) || !MQTTclient.connected())
{
if (MQTTclient_should_reconnect) {
addLog(LOG_LEVEL_ERROR, F("MQTT : Intentional reconnect"));
@@ -198,15 +193,13 @@ void MQTTCheck(int controller_idx)
addLog(LOG_LEVEL_ERROR, F("MQTT : Connection lost"));
connectionFailures += 2;
}
MQTTclient.disconnect();
if (WiFi.status() == WL_CONNECTED) {
delay(1000);
MQTTConnect(controller_idx);
}
}
else if (connectionFailures)
return MQTTConnect(controller_idx);
} else if (connectionFailures) {
connectionFailures--;
}
}
// When no MQTT protocol is enabled, all is fine.
return true;
}
@@ -236,7 +229,6 @@ boolean MQTTpublish(int controller_idx, const char* topic, const char* payload,
if (MQTTclient.publish(topic, payload, retained))
return true;
addLog(LOG_LEVEL_DEBUG, F("MQTT : publish failed"));
MQTTConnect(controller_idx);
return false;
}
@@ -251,7 +243,7 @@ void MQTTStatus(String& status)
LoadControllerSettings(enabledMqttController, (byte*)&ControllerSettings, sizeof(ControllerSettings));
String pubname = ControllerSettings.Subscribe;
pubname.replace(F("/#"), F("/status"));
pubname.replace(F("%sysname%"), Settings.Name);
parseSystemVariables(pubname, false);
MQTTpublish(enabledMqttController, pubname.c_str(), status.c_str(),Settings.MQTTRetainFlag);
}
}
+129
View File
@@ -0,0 +1,129 @@
/*********************************************************************************************\
Convert bearing in degree to bearing string
\*********************************************************************************************/
String getBearing(int degrees)
{
const __FlashStringHelper* bearing[] = {
F("N"),
F("NNE"),
F("NE"),
F("ENE"),
F("E"),
F("ESE"),
F("SE"),
F("SSE"),
F("S"),
F("SSW"),
F("SW"),
F("WSW"),
F("W"),
F("WNW"),
F("NW"),
F("NNW")
};
int nr_directions = (int) (sizeof(bearing)/sizeof(bearing[0]));
float stepsize = (360.0 / nr_directions);
if (degrees < 0) { degrees += 360; } // Allow for bearing -360 .. 359
int bearing_idx=int((degrees + (stepsize / 2.0)) / stepsize) % nr_directions;
if (bearing_idx < 0)
return("");
else
return(bearing[bearing_idx]);
}
float CelsiusToFahrenheit(float celsius) {
return celsius * (9.0 / 5.0) + 32;
}
int m_secToBeaufort(float m_per_sec) {
if (m_per_sec < 0.3) return 0;
if (m_per_sec < 1.6) return 1;
if (m_per_sec < 3.4) return 2;
if (m_per_sec < 5.5) return 3;
if (m_per_sec < 8.0) return 4;
if (m_per_sec < 10.8) return 5;
if (m_per_sec < 13.9) return 6;
if (m_per_sec < 17.2) return 7;
if (m_per_sec < 20.8) return 8;
if (m_per_sec < 24.5) return 9;
if (m_per_sec < 28.5) return 10;
if (m_per_sec < 32.6) return 11;
return 12;
}
String centimeterToImperialLength(float cm) {
return millimeterToImperialLength(cm * 10.0);
}
String millimeterToImperialLength(float mm) {
float inches = mm / 25.4;
int feet = inches /12;
inches = inches - (feet * 12);
String result;
result.reserve(10);
if (feet != 0) {
result += feet;
result += '\'';
}
result += toString(inches,1);
result += '"';
return result;
}
float minutesToDay(int minutes) {
return minutes / 1440.0;
}
String minutesToDayHour(int minutes) {
int days = minutes / 1440;
int hours = (minutes % 1440) / 60;
char TimeString[6]; //5 digits plus the null char
sprintf_P(TimeString, PSTR("%d%c%02d%c"), days, 'd', hours, 'h');
return TimeString;
}
String minutesToDayHourMinute(int minutes) {
int days = minutes / 1440;
int hours = (minutes % 1440) / 60;
int mins = (minutes % 1440) % 60;
char TimeString[20];
sprintf_P(TimeString, PSTR("%d%c%02d%c%02d%c"), days, 'd', hours, 'h', mins, 'm');
return TimeString;
}
String secondsToDayHourMinuteSecond(int seconds) {
int sec = seconds % 60;
int minutes = seconds / 60;
int days = minutes / 1440;
int hours = (minutes % 1440) / 60;
int mins = (minutes % 1440) % 60;
char TimeString[20];
sprintf_P(TimeString, PSTR("%d%c%02d%c%02d%c%02d"), days, 'd', hours, ':', mins, ':', sec);
return TimeString;
}
/********************************************************************************************\
In memory convert float to long
\*********************************************************************************************/
unsigned long float2ul(float f)
{
unsigned long ul;
memcpy(&ul, &f, 4);
return ul;
}
/********************************************************************************************\
In memory convert long to float
\*********************************************************************************************/
float ul2float(unsigned long ul)
{
float f;
memcpy(&f, &ul, 4);
return f;
}
+985
View File
@@ -0,0 +1,985 @@
#ifndef ESPEASY_GLOBALS_H_
#define ESPEASY_GLOBALS_H_
// ********************************************************************************
// User specific configuration
// ********************************************************************************
// Set default configuration settings if you want (not mandatory)
// You can always change these during runtime and save to eeprom
// After loading firmware, issue a 'reset' command to load the defaults.
// --- Basic Config Settings ------------------------------------------------------------------------
#define DEFAULT_NAME "ESP_Easy" // Enter your device friendly name
#define UNIT 0 // Unit Number
#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_KEY "configesp" // Enter network WPA key for AP (config) mode
// --- Wifi Client Mode -----------------------------------------------------------------------------
#define DEFAULT_SSID "ssid" // Enter your Wifi network SSID
#define DEFAULT_KEY "wpakey" // Enter your Wifi network WPA key
#define DEFAULT_USE_STATIC_IP false // (true|false) enabled or disabled static IP
#define DEFAULT_IP "192.168.0.50" // Enter your IP address
#define DEFAULT_DNS "192.168.0.1" // Enter your DNS
#define DEFAULT_GW "192.168.0.1" // Enter your Gateway
#define DEFAULT_SUBNET "255.255.255.0" // Enter your Subnet
#define DEFAULT_WIFI_CONNECTION_TIMEOUT 10000 // minimum timeout in ms for WiFi to be connected.
// --- Default Controller ------------------------------------------------------------------------------
#define DEFAULT_CONTROLLER false // true or false enabled or disabled, set 1st controller defaults
// using a default template, you also need to set a DEFAULT PROTOCOL to a suitable MQTT protocol !
#define DEFAULT_PUB "sensors/espeasy/%sysname%/%tskname%/%valname%" // Enter your pub
#define DEFAULT_SUB "sensors/espeasy/%sysname%/#" // Enter your sub
#define DEFAULT_SERVER "192.168.0.8" // Enter your Server IP address
#define DEFAULT_PORT 8080 // Enter your Server port value
#define DEFAULT_PROTOCOL 1 // Protocol used for controller communications
// 1 = Domoticz HTTP
// 2 = Domoticz MQTT
// 3 = Nodo Telnet
// 4 = ThingSpeak
// 5 = OpenHAB MQTT
// 6 = PiDome MQTT
// 7 = EmonCMS
// 8 = Generic HTTP
// 9 = FHEM HTTP
// --- Advanced Settings ---------------------------------------------------------------------------------
#define DEFAULT_USE_RULES false // (true|false) Enable Rules?
#define DEFAULT_MQTT_RETAIN false // (true|false) Retain MQTT messages?
#define DEFAULT_MQTT_DELAY 1000 // Time in milliseconds to retain MQTT messages
#define DEFAULT_USE_NTP false // (true|false) Use NTP Server
#define DEFAULT_NTP_HOST "" // NTP Server Hostname
#define DEFAULT_TIME_ZONE 0 // Time Offset (in minutes)
#define DEFAULT_USE_DST false // (true|false) Use Daily Time Saving
#define LOG_TO_SERIAL 1
#define LOG_TO_SYSLOG 2
#define LOG_TO_WEBLOG 3
#define LOG_TO_SDCARD 4
#define DEFAULT_SYSLOG_IP "" // Syslog IP Address
#define DEFAULT_SYSLOG_LEVEL 0 // Syslog Log Level
#define DEFAULT_SERIAL_LOG_LEVEL LOG_LEVEL_INFO // Serial Log Level
#define DEFAULT_WEB_LOG_LEVEL LOG_LEVEL_INFO // Web Log Level
#define DEFAULT_SD_LOG_LEVEL 0 // SD Card Log Level
#define DEFAULT_USE_SD_LOG false // (true|false) Enable Logging to the SD card
#define DEFAULT_USE_SERIAL true // (true|false) Enable Logging to the Serial Port
#define DEFAULT_SERIAL_BAUD 115200 // Serial Port Baud Rate
/*
// --- Experimental Advanced Settings (NOT ACTIVES at this time) ------------------------------------
#define DEFAULT_USE_GLOBAL_SYNC false // (true|false)
#define DEFAULT_SYNC_UDP_PORT 0 //
#define DEFAULT_IP_OCTET 0 //
#define DEFAULT_WD_IC2_ADDRESS 0 //
#define DEFAULT_USE_SSDP false // (true|false)
#define DEFAULT_CON_FAIL_THRES 0 //
#define DEFAULT_I2C_CLOCK_LIMIT 0 //
*/
// Enable FEATURE_ADC_VCC to measure supply voltage using the analog pin
// Please note that the TOUT pin has to be disconnected in this mode
// Use the "System Info" device to read the VCC value
#ifndef FEATURE_ADC_VCC
#define FEATURE_ADC_VCC false
#endif
//enable Arduino OTA updating.
//Note: This adds around 10kb to the firmware size, and 1kb extra ram.
// #define FEATURE_ARDUINO_OTA
//enable mDNS mode (adds about 6kb ram and some bytes IRAM)
// #define FEATURE_MDNS
//enable reporting status to ESPEasy developers.
//this informs us of crashes and stability issues.
// not finished yet!
// #define FEATURE_REPORTING
//Select which plugin sets you want to build.
//These are normally automaticly set via the Platformio build environment.
//If you use ArduinoIDE you might need to uncomment some of them, depending on your needs
//If you dont select any, a version with a minimal number of plugins will be biult for 512k versions.
//(512k is NOT finsihed or tested yet as of v2.0.0-dev6)
//build all the normal stable plugins (on by default)
#define PLUGIN_BUILD_NORMAL
//build all plugins that are in test stadium
//#define PLUGIN_BUILD_TESTING
//build all plugins that still are being developed and are broken or incomplete
//#define PLUGIN_BUILD_DEV
// ********************************************************************************
// DO NOT CHANGE ANYTHING BELOW THIS LINE
// ********************************************************************************
#include "core_version.h"
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0
#error ESPEasy v2.0 only support Arduino core 2.3.0. (Use the ESPEasy development branch to fix this)
#endif
#define ESP_PROJECT_PID 2016110801L
#define VERSION 2 // config file version (not ESPEasy version). increase if you make incompatible changes to config system.
#define BUILD 20000 // git version 2.0.0
#define BUILD_NOTES " - Mega"
#ifndef BUILD_GIT
#define BUILD_GIT "(custom)"
#endif
#define MAX_FLASHWRITES_PER_DAY 100 // per 24 hour window
#define NODE_TYPE_ID_ESP_EASY_STD 1
#define NODE_TYPE_ID_ESP_EASYM_STD 17
#define NODE_TYPE_ID_ESP_EASY32_STD 33
#define NODE_TYPE_ID_ARDUINO_EASY_STD 65
#define NODE_TYPE_ID_NANO_EASY_STD 81
#define NODE_TYPE_ID NODE_TYPE_ID_ESP_EASYM_STD
#define PLUGIN_INIT_ALL 1
#define PLUGIN_INIT 2
#define PLUGIN_READ 3
#define PLUGIN_ONCE_A_SECOND 4
#define PLUGIN_TEN_PER_SECOND 5
#define PLUGIN_DEVICE_ADD 6
#define PLUGIN_EVENTLIST_ADD 7
#define PLUGIN_WEBFORM_SAVE 8
#define PLUGIN_WEBFORM_LOAD 9
#define PLUGIN_WEBFORM_SHOW_VALUES 10
#define PLUGIN_GET_DEVICENAME 11
#define PLUGIN_GET_DEVICEVALUENAMES 12
#define PLUGIN_WRITE 13
#define PLUGIN_EVENT_OUT 14
#define PLUGIN_WEBFORM_SHOW_CONFIG 15
#define PLUGIN_SERIAL_IN 16
#define PLUGIN_UDP_IN 17
#define PLUGIN_CLOCK_IN 18
#define PLUGIN_TIMER_IN 19
#define PLUGIN_FIFTY_PER_SECOND 20
#define PLUGIN_SET_CONFIG 21
#define PLUGIN_GET_DEVICEGPIONAMES 22
#define PLUGIN_EXIT 23
#define PLUGIN_GET_CONFIG 24
#define CPLUGIN_PROTOCOL_ADD 1
#define CPLUGIN_PROTOCOL_TEMPLATE 2
#define CPLUGIN_PROTOCOL_SEND 3
#define CPLUGIN_PROTOCOL_RECV 4
#define CPLUGIN_GET_DEVICENAME 5
#define CPLUGIN_WEBFORM_SAVE 6
#define CPLUGIN_WEBFORM_LOAD 7
#define CPLUGIN_GET_PROTOCOL_DISPLAY_NAME 8
#define CPLUGIN_TASK_CHANGE_NOTIFICATION 9
#define CPLUGIN_INIT 10
#define CPLUGIN_UDP_IN 11
#define CONTROLLER_HOSTNAME 1
#define CONTROLLER_IP 2
#define CONTROLLER_PORT 3
#define CONTROLLER_USER 4
#define CONTROLLER_PASS 5
#define CONTROLLER_SUBSCRIBE 6
#define CONTROLLER_PUBLISH 7
#define NPLUGIN_PROTOCOL_ADD 1
#define NPLUGIN_GET_DEVICENAME 2
#define NPLUGIN_WEBFORM_SAVE 3
#define NPLUGIN_WEBFORM_LOAD 4
#define NPLUGIN_WRITE 5
#define NPLUGIN_NOTIFY 6
#define NPLUGIN_NOT_FOUND 255
#define LOG_LEVEL_ERROR 1
#define LOG_LEVEL_INFO 2
#define LOG_LEVEL_DEBUG 3
#define LOG_LEVEL_DEBUG_MORE 4
#define LOG_LEVEL_DEBUG_DEV 9 // use for testing/debugging only, not for regular use
#define CMD_REBOOT 89
#define CMD_WIFI_DISCONNECT 135
#if defined(PLUGIN_BUILD_TESTING) || defined(PLUGIN_BUILD_DEV)
#define DEVICES_MAX 72
#else
#define DEVICES_MAX 64
#endif
#if defined(ESP8266)
#define TASKS_MAX 12 // max 12!
#endif
#if defined(ESP32)
#define TASKS_MAX 32
#endif
#define CONTROLLER_MAX 3 // max 4!
#define NOTIFICATION_MAX 3 // max 4!
#define VARS_PER_TASK 4
#define PLUGIN_MAX DEVICES_MAX
#define PLUGIN_CONFIGVAR_MAX 8
#define PLUGIN_CONFIGFLOATVAR_MAX 4
#define PLUGIN_CONFIGLONGVAR_MAX 4
#define PLUGIN_EXTRACONFIGVAR_MAX 16
#define CPLUGIN_MAX 16
#define NPLUGIN_MAX 4
#define UNIT_MAX 32 // Only relevant for UDP unicast message 'sweeps' and the nodelist.
#define RULES_TIMER_MAX 8
#define SYSTEM_TIMER_MAX 8
#define SYSTEM_CMD_TIMER_MAX 2
#define PINSTATE_TABLE_MAX 32
#define RULES_MAX_SIZE 2048
#define RULES_MAX_NESTING_LEVEL 3
#define RULESETS_MAX 4
#define RULES_BUFFER_SIZE 64
#define PIN_MODE_UNDEFINED 0
#define PIN_MODE_INPUT 1
#define PIN_MODE_OUTPUT 2
#define PIN_MODE_PWM 3
#define PIN_MODE_SERVO 4
#define SEARCH_PIN_STATE true
#define NO_SEARCH_PIN_STATE false
#define DEVICE_TYPE_SINGLE 1 // connected through 1 datapin
#define DEVICE_TYPE_DUAL 2 // connected through 2 datapins
#define DEVICE_TYPE_TRIPLE 3 // connected through 3 datapins
#define DEVICE_TYPE_ANALOG 10 // AIN/tout pin
#define DEVICE_TYPE_I2C 20 // connected through I2C
#define DEVICE_TYPE_DUMMY 99 // Dummy device, has no physical connection
#define SENSOR_TYPE_SINGLE 1
#define SENSOR_TYPE_TEMP_HUM 2
#define SENSOR_TYPE_TEMP_BARO 3
#define SENSOR_TYPE_TEMP_HUM_BARO 4
#define SENSOR_TYPE_DUAL 5
#define SENSOR_TYPE_TRIPLE 6
#define SENSOR_TYPE_QUAD 7
#define SENSOR_TYPE_SWITCH 10
#define SENSOR_TYPE_DIMMER 11
#define SENSOR_TYPE_LONG 20
#define SENSOR_TYPE_WIND 21
#define VALUE_SOURCE_SYSTEM 1
#define VALUE_SOURCE_SERIAL 2
#define VALUE_SOURCE_HTTP 3
#define VALUE_SOURCE_MQTT 4
#define VALUE_SOURCE_UDP 5
#define BOOT_CAUSE_MANUAL_REBOOT 0
#define BOOT_CAUSE_COLD_BOOT 1
#define BOOT_CAUSE_DEEP_SLEEP 2
#define BOOT_CAUSE_EXT_WD 10
#define DAT_TASKS_SIZE 2048
#define DAT_TASKS_CUSTOM_OFFSET 1024
#define DAT_CUSTOM_CONTROLLER_SIZE 1024
#define DAT_CONTROLLER_SIZE 1024
#define DAT_NOTIFICATION_SIZE 1024
#define DAT_OFFSET_TASKS 4096 // each task = 2k, (1024 basic + 1024 bytes custom), 12 max
#define DAT_OFFSET_CONTROLLER 28672 // each controller = 1k, 4 max
#define DAT_OFFSET_CUSTOM_CONTROLLER 32768 // each custom controller config = 1k, 4 max.
/*
To modify the stock configuration without changing this repo file :
- define USE_CUSTOM_H as a build flags. ie : export PLATFORMIO_BUILD_FLAGS="'-DUSE_CUSTOM_H'"
- add a "Custom.h" file in this folder.
*/
#ifdef USE_CUSTOM_H
#include "Custom.h"
#endif
#define FILE_CONFIG "config.dat"
#define FILE_SECURITY "security.dat"
#define FILE_NOTIFICATION "notification.dat"
#define FILE_RULES "rules1.dat"
#include "ESPEasyTimeTypes.h"
#include "lwip/tcp_impl.h"
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
#include <DNSServer.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
#ifdef FEATURE_MDNS
#include <ESP8266mDNS.h>
#endif
#include <Wire.h>
#include <SPI.h>
#include <PubSubClient.h>
// #include <ArduinoJson.h>
// #include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define FS_NO_GLOBALS
#include <FS.h>
#include <SD.h>
#include <ESP8266HTTPUpdateServer.h>
ESP8266HTTPUpdateServer httpUpdater(true);
#include <base64.h>
#if FEATURE_ADC_VCC
ADC_MODE(ADC_VCC);
#endif
#ifndef LWIP_OPEN_SRC
#define LWIP_OPEN_SRC
#endif
#include "lwip/opt.h"
#include "lwip/udp.h"
#include "lwip/igmp.h"
#include "include/UdpContext.h"
#include "limits.h"
extern "C" {
#include "user_interface.h"
}
#ifdef FEATURE_ARDUINO_OTA
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>
bool ArduinoOTAtriggered=false;
#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;
#ifdef FEATURE_MDNS
MDNSResponder mdns;
#endif
// MQTT client
WiFiClient mqtt;
PubSubClient MQTTclient(mqtt);
bool MQTTclient_should_reconnect = true;
// WebServer
ESP8266WebServer WebServer(80);
// udp protocol stuff (syslog, global sync, node info list, ntp time)
WiFiUDP portUDP;
// Forward declarations.
bool WiFiConnected(uint32_t timeout_ms);
bool hostReachable(const IPAddress& ip);
bool hostReachable(const String& hostname);
extern "C" {
#include "spi_flash.h"
}
extern "C" uint32_t _SPIFFS_start;
extern "C" uint32_t _SPIFFS_end;
extern "C" uint32_t _SPIFFS_page;
extern "C" uint32_t _SPIFFS_block;
struct SecurityStruct
{
SecurityStruct() {
memset(WifiSSID, 0, sizeof(WifiSSID));
memset(WifiKey, 0, sizeof(WifiKey));
memset(WifiSSID2, 0, sizeof(WifiSSID2));
memset(WifiKey2, 0, sizeof(WifiKey2));
memset(WifiAPKey, 0, sizeof(WifiAPKey));
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
memset(ControllerUser[i], 0, sizeof(ControllerUser[i]));
memset(ControllerPassword[i], 0, sizeof(ControllerPassword[i]));
}
memset(Password, 0, sizeof(Password));
}
char WifiSSID[32];
char WifiKey[64];
char WifiSSID2[32];
char WifiKey2[64];
char WifiAPKey[64];
char ControllerUser[CONTROLLER_MAX][26];
char ControllerPassword[CONTROLLER_MAX][64];
char Password[26];
//its safe to extend this struct, up to 4096 bytes, default values in config are 0
} SecuritySettings;
struct SettingsStruct
{
SettingsStruct() :
PID(0), Version(0), Build(0), IP_Octet(0), Unit(0), Delay(0),
Pin_i2c_sda(-1), Pin_i2c_scl(-1), Pin_status_led(-1), Pin_sd_cs(-1),
UDPPort(0), SyslogLevel(0), SerialLogLevel(0), WebLogLevel(0), SDLogLevel(0),
BaudRate(0), MessageDelay(0), deepSleep(0),
CustomCSS(false), DST(false), WDI2CAddress(0),
UseRules(false), UseSerial(false), UseSSDP(false), UseNTP(false),
WireClockStretchLimit(0), ConnectionFailuresThreshold(0),
TimeZone(0), MQTTRetainFlag(false), InitSPI(false),
Pin_status_led_Inversed(false), deepSleepOnFail(false), UseValueLogger(false),
DST_Start(0), DST_End(0)
{
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
Protocol[i] = 0;
ControllerEnabled[i] = false;
for (byte task = 0; task < TASKS_MAX; ++task) {
TaskDeviceID[i][task] = 0;
TaskDeviceSendData[i][task] = false;
}
}
for (byte task = 0; task < TASKS_MAX; ++task) {
TaskDeviceNumber[task] = 0;
OLD_TaskDeviceID[task] = 0;
TaskDevicePin1PullUp[task] = false;
for (byte cv = 0; cv < PLUGIN_CONFIGVAR_MAX; ++cv) {
TaskDevicePluginConfig[task][cv] = 0;
}
TaskDevicePin1Inversed[task] = false;
for (byte cv = 0; cv < PLUGIN_CONFIGFLOATVAR_MAX; ++cv) {
TaskDevicePluginConfigFloat[task][cv] = 0.0;
}
for (byte cv = 0; cv < PLUGIN_CONFIGLONGVAR_MAX; ++cv) {
TaskDevicePluginConfigLong[task][cv] = 0;
}
OLD_TaskDeviceSendData[task] = false;
TaskDeviceGlobalSync[task] = false;
TaskDeviceDataFeed[task] = 0;
TaskDeviceTimer[task] = 0;
TaskDeviceEnabled[task] = false;
}
}
unsigned long PID;
int Version;
int16_t Build;
byte IP[4];
byte Gateway[4];
byte Subnet[4];
byte DNS[4];
byte IP_Octet;
byte Unit;
char Name[26];
char NTPHost[64];
unsigned long Delay;
int8_t Pin_i2c_sda;
int8_t Pin_i2c_scl;
int8_t Pin_status_led;
int8_t Pin_sd_cs;
int8_t PinBootStates[17];
byte Syslog_IP[4];
unsigned int UDPPort;
byte SyslogLevel;
byte SerialLogLevel;
byte WebLogLevel;
byte SDLogLevel;
unsigned long BaudRate;
unsigned long MessageDelay;
byte deepSleep;
boolean CustomCSS;
boolean DST;
byte WDI2CAddress;
boolean UseRules;
boolean UseSerial;
boolean UseSSDP;
boolean UseNTP;
unsigned long WireClockStretchLimit;
boolean _GlobalSync; // obsolete!
unsigned long ConnectionFailuresThreshold;
int16_t TimeZone;
boolean MQTTRetainFlag;
boolean InitSPI;
byte Protocol[CONTROLLER_MAX];
byte Notification[NOTIFICATION_MAX]; //notifications, point to a NPLUGIN id
byte TaskDeviceNumber[TASKS_MAX];
unsigned int OLD_TaskDeviceID[TASKS_MAX];
union {
struct {
int8_t TaskDevicePin1[TASKS_MAX];
int8_t TaskDevicePin2[TASKS_MAX];
int8_t TaskDevicePin3[TASKS_MAX];
byte TaskDevicePort[TASKS_MAX];
};
int8_t TaskDevicePin[4][TASKS_MAX];
};
boolean TaskDevicePin1PullUp[TASKS_MAX];
int16_t TaskDevicePluginConfig[TASKS_MAX][PLUGIN_CONFIGVAR_MAX];
boolean TaskDevicePin1Inversed[TASKS_MAX];
float TaskDevicePluginConfigFloat[TASKS_MAX][PLUGIN_CONFIGFLOATVAR_MAX];
long TaskDevicePluginConfigLong[TASKS_MAX][PLUGIN_CONFIGLONGVAR_MAX];
boolean OLD_TaskDeviceSendData[TASKS_MAX];
boolean TaskDeviceGlobalSync[TASKS_MAX];
byte TaskDeviceDataFeed[TASKS_MAX];
unsigned long TaskDeviceTimer[TASKS_MAX];
boolean TaskDeviceEnabled[TASKS_MAX];
boolean ControllerEnabled[CONTROLLER_MAX];
boolean NotificationEnabled[NOTIFICATION_MAX];
unsigned int TaskDeviceID[CONTROLLER_MAX][TASKS_MAX];
boolean TaskDeviceSendData[CONTROLLER_MAX][TASKS_MAX];
boolean Pin_status_led_Inversed;
boolean deepSleepOnFail;
boolean UseValueLogger;
uint16_t DST_Start;
uint16_t DST_End;
//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
} Settings;
struct ControllerSettingsStruct
{
ControllerSettingsStruct() : UseDNS(false), Port(0) {
for (byte i = 0; i < 4; ++i) {
IP[i] = 0;
}
memset(HostName, 0, sizeof(HostName));
memset(Publish, 0, sizeof(Publish));
memset(Subscribe, 0, sizeof(Subscribe));
}
boolean UseDNS;
byte IP[4];
unsigned int Port;
char HostName[65];
char Publish[129];
char Subscribe[129];
IPAddress getIP() const {
IPAddress host(IP[0], IP[1], IP[2], IP[3]);
return host;
}
String getHost() const {
if (UseDNS) {
return HostName;
}
return getIP().toString();
}
void setHostname(const String& controllerhostname) {
strncpy(HostName, controllerhostname.c_str(), sizeof(HostName));
updateIPcache();
}
boolean checkHostReachable(bool quick) {
if (!WiFiConnected(10)) {
return false; // Not connected, so no use in wasting time to connect to a host.
}
if (quick && ipSet()) return true;
if (UseDNS) {
if (!updateIPcache()) {
return false;
}
}
return hostReachable(getIP());
}
boolean connectToHost(WiFiClient &client) {
if (!checkHostReachable(true)) {
return false; // Host not reachable
}
byte retry = 2;
bool connected = false;
while (retry > 0 && !connected) {
--retry;
connected = client.connect(getIP(), Port);
if (connected) return true;
if (!checkHostReachable(false))
return false;
}
return false;
}
int beginPacket(WiFiUDP &client) {
if (!checkHostReachable(true)) {
return 0; // Host not reachable
}
byte retry = 2;
int connected = 0;
while (retry > 0 && !connected) {
--retry;
connected = client.beginPacket(getIP(), Port);
if (connected != 0) return connected;
if (!checkHostReachable(false))
return false;
delay(10);
}
return false;
}
String getHostPortString() const {
String result = getHost();
result += ":";
result += Port;
return result;
}
private:
bool ipSet() {
for (byte i = 0; i < 4; ++i) {
if (IP[i] != 0) return true;
}
return false;
}
bool updateIPcache() {
if (!UseDNS) {
return true;
}
IPAddress tmpIP;
if (WiFi.hostByName(HostName, tmpIP)) {
for (byte x = 0; x < 4; x++) {
IP[x] = tmpIP[x];
}
return true;
}
return false;
}
};
struct NotificationSettingsStruct
{
NotificationSettingsStruct() : Port(0), Pin1(0), Pin2(0) {
memset(Server, 0, sizeof(Server));
memset(Domain, 0, sizeof(Domain));
memset(Sender, 0, sizeof(Sender));
memset(Receiver, 0, sizeof(Receiver));
memset(Subject, 0, sizeof(Subject));
memset(Body, 0, sizeof(Body));
memset(User, 0, sizeof(User));
memset(Pass, 0, sizeof(Pass));
}
char Server[65];
unsigned int Port;
char Domain[65];
char Sender[65];
char Receiver[65];
char Subject[129];
char Body[513];
byte Pin1;
byte Pin2;
char User[49];
char Pass[33];
//its safe to extend this struct, up to 4096 bytes, default values in config are 0
};
struct ExtraTaskSettingsStruct
{
ExtraTaskSettingsStruct() : TaskIndex(0) {
TaskDeviceName[0] = 0;
for (byte i = 0; i < VARS_PER_TASK; ++i) {
for (byte j = 0; j < 41; ++j) {
TaskDeviceFormula[i][j] = 0;
TaskDeviceValueNames[i][j] = 0;
TaskDeviceValueDecimals[i] = 0;
}
}
for (byte i = 0; i < PLUGIN_EXTRACONFIGVAR_MAX; ++i) {
TaskDevicePluginConfigLong[i] = 0;
TaskDevicePluginConfig[i] = 0;
}
}
byte TaskIndex;
char TaskDeviceName[41];
char TaskDeviceFormula[VARS_PER_TASK][41];
char TaskDeviceValueNames[VARS_PER_TASK][41];
long TaskDevicePluginConfigLong[PLUGIN_EXTRACONFIGVAR_MAX];
byte TaskDeviceValueDecimals[VARS_PER_TASK];
int16_t TaskDevicePluginConfig[PLUGIN_EXTRACONFIGVAR_MAX];
} ExtraTaskSettings;
struct EventStruct
{
EventStruct() :
Source(0), TaskIndex(0), ControllerIndex(0), ProtocolIndex(0), NotificationIndex(0),
BaseVarIndex(0), idx(0), sensorType(0), Par1(0), Par2(0), Par3(0), Par4(0), Par5(0),
OriginTaskIndex(0), Data(NULL) {}
byte Source;
byte TaskIndex; // index position in TaskSettings array, 0-11
byte ControllerIndex; // index position in Settings.Controller, 0-3
byte ProtocolIndex; // index position in protocol array, depending on which controller plugins are loaded.
byte NotificationIndex; // index position in Settings.Notification, 0-3
//Edwin: Not needed, and wasnt used. We can determine the protocol index with getNotificationProtocolIndex(NotificationIndex)
// byte NotificationProtocolIndex; // index position in notification array, depending on which controller plugins are loaded.
byte BaseVarIndex;
int idx;
byte sensorType;
int Par1;
int Par2;
int Par3;
int Par4;
int Par5;
byte OriginTaskIndex;
String String1;
String String2;
String String3;
byte *Data;
};
#define LOG_STRUCT_MESSAGE_SIZE 128
#define LOG_STRUCT_MESSAGE_LINES 20
struct LogStruct {
LogStruct() : write_idx(0), read_idx(0) {
for (int i = 0; i < LOG_STRUCT_MESSAGE_LINES; ++i) {
memset(Message[i], 0, LOG_STRUCT_MESSAGE_SIZE);
timeStamp[i] = 0;
}
}
void add(const char *line) {
write_idx = (write_idx + 1) % LOG_STRUCT_MESSAGE_LINES;
if (write_idx == read_idx) {
// Buffer full, move read_idx to overwrite oldest entry.
read_idx = (read_idx + 1) % LOG_STRUCT_MESSAGE_LINES;
}
timeStamp[write_idx] = millis();
strncpy(Message[write_idx], line, LOG_STRUCT_MESSAGE_SIZE-1);
}
// Read the next item and append it to the given string.
// Returns whether new lines are available.
bool get(String& output, const String& lineEnd) {
if (!isEmpty()) {
read_idx = (read_idx + 1) % LOG_STRUCT_MESSAGE_LINES;
output += formatLine(read_idx, lineEnd);
}
return !isEmpty();
}
bool get(String& output, const String& lineEnd, int line) {
int tmpread((write_idx + 1+line) % LOG_STRUCT_MESSAGE_LINES);
if (timeStamp[tmpread] != 0) {
output += formatLine(tmpread, lineEnd);
}
return !isEmpty();
}
bool getAll(String& output, const String& lineEnd) {
int tmpread((write_idx + 1) % LOG_STRUCT_MESSAGE_LINES);
bool someAdded = false;
while (tmpread != write_idx) {
if (timeStamp[tmpread] != 0) {
output += formatLine(tmpread, lineEnd);
someAdded = true;
}
tmpread = (tmpread + 1)% LOG_STRUCT_MESSAGE_LINES;
}
return someAdded;
}
bool isEmpty() {
return (write_idx == read_idx);
}
private:
String formatLine(int index, const String& lineEnd) {
String output;
output += timeStamp[index];
output += " : ";
output += Message[index];
output += lineEnd;
return output;
}
int write_idx;
int read_idx;
unsigned long timeStamp[LOG_STRUCT_MESSAGE_LINES];
char Message[LOG_STRUCT_MESSAGE_LINES][LOG_STRUCT_MESSAGE_SIZE];
} Logging;
struct DeviceStruct
{
DeviceStruct() :
Number(0), Type(0), VType(0), Ports(0),
PullUpOption(false), InverseLogicOption(false), FormulaOption(false),
ValueCount(0), Custom(false), SendDataOption(false), GlobalSyncOption(false),
TimerOption(false), TimerOptional(false), DecimalsOnly(false) {}
byte Number;
byte Type;
byte VType;
byte Ports;
boolean PullUpOption;
boolean InverseLogicOption;
boolean FormulaOption;
byte ValueCount;
boolean Custom;
boolean SendDataOption;
boolean GlobalSyncOption;
boolean TimerOption;
boolean TimerOptional;
boolean DecimalsOnly;
} Device[DEVICES_MAX + 1]; // 1 more because first device is empty device
struct ProtocolStruct
{
ProtocolStruct() :
Number(0), usesMQTT(false), usesAccount(false), usesPassword(false),
defaultPort(0), usesTemplate(false), usesID(false), Custom(false) {}
byte Number;
boolean usesMQTT;
boolean usesAccount;
boolean usesPassword;
int defaultPort;
boolean usesTemplate;
boolean usesID;
boolean Custom;
} Protocol[CPLUGIN_MAX];
struct NotificationStruct
{
NotificationStruct() :
Number(0), usesMessaging(false), usesGPIO(0) {}
byte Number;
boolean usesMessaging;
byte usesGPIO;
} Notification[NPLUGIN_MAX];
struct NodeStruct
{
NodeStruct() :
age(0), build(0), nodeName(NULL), nodeType(0)
{
for (byte i = 0; i < 4; ++i) ip[i] = 0;
}
byte ip[4];
byte age;
uint16_t build;
char* nodeName;
byte nodeType;
} Nodes[UNIT_MAX];
struct systemTimerStruct
{
systemTimerStruct() :
timer(0), plugin(0), Par1(0), Par2(0), Par3(0) {}
unsigned long timer;
byte plugin;
byte Par1;
byte Par2;
byte Par3;
} systemTimers[SYSTEM_TIMER_MAX];
struct systemCMDTimerStruct
{
systemCMDTimerStruct() : timer(0) {}
unsigned long timer;
String action;
} systemCMDTimers[SYSTEM_CMD_TIMER_MAX];
struct pinStatesStruct
{
byte plugin;
byte index;
byte mode;
uint16_t value;
} pinStates[PINSTATE_TABLE_MAX];
// this offsets are in blocks, bytes = blocks * 4
#define RTC_BASE_STRUCT 64
#define RTC_BASE_USERVAR 74
//max 40 bytes: ( 74 - 64 ) * 4
struct RTCStruct
{
byte ID1;
byte ID2;
boolean unused1;
byte factoryResetCounter;
byte deepSleepState;
byte unused2;
byte flashDayCounter;
unsigned long flashCounter;
unsigned long bootCounter;
} RTC;
int deviceCount = -1;
int protocolCount = -1;
int notificationCount = -1;
boolean printToWeb = false;
String printWebString = "";
boolean printToWebJSON = false;
float UserVar[VARS_PER_TASK * TASKS_MAX];
unsigned long RulesTimer[RULES_TIMER_MAX];
unsigned long timerSensor[TASKS_MAX];
unsigned long timer100ms;
unsigned long timer20ms;
unsigned long timer1s;
unsigned long timerwd;
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;
unsigned long timerAPoff = 0;
unsigned long timerAwakeFromDeepSleep = 0;
#if FEATURE_ADC_VCC
float vcc = -1.0;
#endif
boolean WebLoggedIn = false;
int WebLoggedInTimer = 300;
boolean (*Plugin_ptr[PLUGIN_MAX])(byte, struct EventStruct*, String&);
byte Plugin_id[PLUGIN_MAX];
boolean (*CPlugin_ptr[CPLUGIN_MAX])(byte, struct EventStruct*, String&);
byte CPlugin_id[CPLUGIN_MAX];
boolean (*NPlugin_ptr[NPLUGIN_MAX])(byte, struct EventStruct*, String&);
byte NPlugin_id[NPLUGIN_MAX];
String dummyString = "";
byte lastBootCause = BOOT_CAUSE_MANUAL_REBOOT;
boolean wifiSetup = false;
boolean wifiSetupConnect = false;
uint8_t lastBSSID[6] = {0};
boolean wifiConnected = false;
unsigned long wifi_connect_timer = 0;
unsigned int wifi_connect_attempt = 0;
uint8_t lastWiFiSettings = 0;
unsigned long start = 0;
unsigned long elapsed = 0;
unsigned long loopCounter = 0;
unsigned long loopCounterLast = 0;
unsigned long loopCounterMax = 1;
unsigned long dailyResetCounter = 0;
String eventBuffer = "";
uint16_t lowestRAM = 0;
String lowestRAMfunction = "";
bool shouldReboot=false;
bool firstLoop=true;
boolean activeRuleSets[RULESETS_MAX];
#endif /* ESPEASY_GLOBALS_H_ */
+87 -915
View File
File diff suppressed because it is too large Load Diff
+34 -4
View File
@@ -1,3 +1,6 @@
#ifndef ESPEASY_TIMETYPES_H_
#define ESPEASY_TIMETYPES_H_
#include <stdint.h>
struct timeStruct {
@@ -12,7 +15,7 @@ struct timeStruct {
};
// convenient constants for TimeChangeRules
enum week_t {Last, First, Second, Third, Fourth};
enum week_t {Last=0, First, Second, Third, Fourth};
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
@@ -22,18 +25,45 @@ enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
// - https://www.timeanddate.com/time/dst/2018.html
// - https://en.wikipedia.org/wiki/Daylight_saving_time_by_country
struct TimeChangeRule {
TimeChangeRule() : week(0), dow(0), month(0), hour(0), offset(0) {}
TimeChangeRule(uint8_t weeknr, uint8_t downr, uint8_t m, uint8_t h, int minutesoffset) :
TimeChangeRule() : week(0), dow(1), month(1), hour(0), offset(0) {}
TimeChangeRule(uint8_t weeknr, uint8_t downr, uint8_t m, uint8_t h, uint16_t minutesoffset) :
week(weeknr), dow(downr), month(m), hour(h), offset(minutesoffset) {}
// Construct time change rule from stored values optimized for minimum space.
TimeChangeRule(uint16_t flash_stored_value, int16_t minutesoffset) : offset(minutesoffset) {
hour = flash_stored_value & 0x001f;
month = (flash_stored_value >> 5) & 0x000f;
dow = (flash_stored_value >> 9) & 0x0007;
week = (flash_stored_value >> 12) & 0x0007;
}
uint16_t toFlashStoredValue() const {
uint16_t value = hour;
value = value | (month << 5);
value = value | (dow << 9);
value = value | (week << 12);
return value;
}
bool isValid() const {
return (week <= 4) && (dow != 0) && (dow <= 7) &&
(month != 0) && (month <= 12) && (hour <= 23) &&
(offset > -720) && (offset < 900); // UTC-12h ... UTC+14h + 1h DSToffset
}
uint8_t week; // First, Second, Third, Fourth, or Last week of the month
uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat
uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec
uint8_t hour; // 0-23
int offset; // offset from UTC in minutes
int16_t offset; // offset from UTC in minutes
};
// Forward declartions
void applyTimeZone(uint32_t curTime = 0);
void setTimeZone(const TimeChangeRule& dstStart, const TimeChangeRule& stdStart, uint32_t curTime = 0);
uint32_t calcTimeChangeForRule(const TimeChangeRule& r, int yr);
String getTimeString(char delimiter, bool show_seconds=true);
String getTimeString_ampm(char delimiter, bool show_seconds=true);
#endif /* ESPEASY_TIMETYPES_H_ */
+5 -9
View File
@@ -1,5 +1,5 @@
/********************************************************************************************\
* Initialize specific hardware settings (only global ones, others are set through devices)
* Initialize specific hardware setings (only global ones, others are set through devices)
\*********************************************************************************************/
void hardwareInit()
@@ -37,9 +37,7 @@ void hardwareInit()
String log = F("INIT : I2C custom clockstretchlimit:");
log += Settings.WireClockStretchLimit;
addLog(LOG_LEVEL_INFO, log);
#if defined(ESP8266)
Wire.setClockStretchLimit(Settings.WireClockStretchLimit);
#endif
Wire.setClockStretchLimit(Settings.WireClockStretchLimit);
}
}
@@ -51,7 +49,7 @@ void hardwareInit()
Wire.write(0x83); // command to set pointer
Wire.write(17); // pointer value to status byte
Wire.endTransmission();
Wire.requestFrom(Settings.WDI2CAddress, (uint8_t)1);
if (Wire.available())
{
@@ -64,7 +62,7 @@ void hardwareInit()
}
}
}
// SPI Init
if (Settings.InitSPI)
{
@@ -79,8 +77,7 @@ void hardwareInit()
addLog(LOG_LEVEL_INFO, log);
}
#ifdef FEATURE_SD
if (Settings.Pin_sd_cs >= 0)
if (Settings.Pin_sd_cs > 0)
{
if (SD.begin(Settings.Pin_sd_cs))
{
@@ -93,7 +90,6 @@ void hardwareInit()
addLog(LOG_LEVEL_ERROR, log);
}
}
#endif
}
+567 -787
View File
File diff suppressed because it is too large Load Diff
+67 -198
View File
@@ -2,11 +2,6 @@
// 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
/*********************************************************************************************\
Syslog client
@@ -19,63 +14,32 @@ void syslog(const char *message)
portUDP.beginPacket(broadcastIP, 514);
char str[256];
str[0] = 0;
// An RFC3164 compliant message must be formated like : "<PRIO>[TimeStamp ]Hostname TaskName: Message"
// 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);
// Using Setting.Unit to build a Hostname
//snprintf_P(str, sizeof(str), PSTR("<7>EspEasy_%u ESP: %s"), Settings.Unit, message);
portUDP.write(str);
#if defined(ESP8266)
portUDP.write(str);
#endif
#if defined(ESP32)
portUDP.write((uint8_t*)str,strlen(str));
#endif
portUDP.endPacket();
}
}
/*********************************************************************************************\
Structs for UDP messaging
\*********************************************************************************************/
struct infoStruct
{
byte header = 255;
byte ID = 3;
byte sourcelUnit;
byte destUnit;
byte sourceTaskIndex;
byte destTaskIndex;
byte deviceNumber;
char taskName[26];
char ValueNames[VARS_PER_TASK][26];
};
struct dataStruct
{
byte header = 255;
byte ID = 5;
byte sourcelUnit;
byte destUnit;
byte sourceTaskIndex;
byte destTaskIndex;
float Values[VARS_PER_TASK];
};
//TODO: add sysinfoStruct
/*********************************************************************************************\
Check UDP messages (ESPEasy propiertary protocol)
\*********************************************************************************************/
boolean runningUPDCheck = false;
void checkUDP()
{
if (Settings.UDPPort == 0)
return;
if (runningUPDCheck)
return;
runningUPDCheck = true;
// UDP events
int packetSize = portUDP.parsePacket();
if (packetSize)
@@ -86,7 +50,6 @@ void checkUDP()
if (portUDP.remotePort() == 123)
{
// unexpected NTP reply, drop for now...
runningUPDCheck = false;
return;
}
char packetBuffer[128];
@@ -105,22 +68,10 @@ void checkUDP()
}
else
{
if (packetBuffer[1] > 1 && packetBuffer[1] < 6)
{
String log = (F("UDP : Sensor msg "));
for (byte x = 1; x < 6; x++)
{
log += " ";
log += (int)packetBuffer[x];
}
addLog(LOG_LEVEL_DEBUG_MORE, log);
}
// binary data!
switch (packetBuffer[1])
{
//TODO: use a nice struct for it
case 1: // sysinfo message
{
byte mac[6];
@@ -148,155 +99,27 @@ void checkUDP()
}
char macaddress[20];
formatMAC(mac, macaddress);
char ipaddress[20];
formatIP(ip, ipaddress);
sprintf_P(macaddress, PSTR("%02x:%02x:%02x:%02x:%02x:%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
char ipaddress[16];
sprintf_P(ipaddress, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
char log[80];
sprintf_P(log, PSTR("UDP : %s,%s,%u"), macaddress, ipaddress, unit);
addLog(LOG_LEVEL_DEBUG_MORE, log);
break;
}
case 2: // sensor info pull request
{
SendUDPTaskInfo(packetBuffer[2], packetBuffer[5], packetBuffer[4]);
break;
}
case 3: // sensor info
{
if (Settings.GlobalSync)
{
struct infoStruct infoReply;
memcpy((byte*)&infoReply, (byte*)&packetBuffer, sizeof(infoStruct));
// to prevent flash wear out (bugs in communication?) we can only write to an empty task
// so it will write only once and has to be cleared manually through webgui
if (Settings.TaskDeviceNumber[infoReply.destTaskIndex] == 0)
{
Settings.TaskDeviceNumber[infoReply.destTaskIndex] = infoReply.deviceNumber;
Settings.TaskDeviceDataFeed[infoReply.destTaskIndex] = 1; // remote feed
for (byte x=0; x < CONTROLLER_MAX; x++)
Settings.TaskDeviceSendData[x][infoReply.destTaskIndex] = false;
strcpy(ExtraTaskSettings.TaskDeviceName, infoReply.taskName);
for (byte x = 0; x < VARS_PER_TASK; x++)
strcpy( ExtraTaskSettings.TaskDeviceValueNames[x], infoReply.ValueNames[x]);
SaveTaskSettings(infoReply.destTaskIndex);
SaveSettings();
}
}
break;
}
case 4: // sensor data pull request
{
SendUDPTaskData(packetBuffer[2], packetBuffer[5], packetBuffer[4]);
break;
}
case 5: // sensor data
{
if (Settings.GlobalSync)
{
struct dataStruct dataReply;
memcpy((byte*)&dataReply, (byte*)&packetBuffer, sizeof(dataStruct));
// only if this task has a remote feed, update values
if (Settings.TaskDeviceDataFeed[dataReply.destTaskIndex] != 0)
{
for (byte x = 0; x < VARS_PER_TASK; x++)
{
UserVar[dataReply.destTaskIndex * VARS_PER_TASK + x] = dataReply.Values[x];
}
if (Settings.UseRules)
createRuleEvents(dataReply.destTaskIndex);
}
}
break;
}
default:
{
struct EventStruct TempEvent;
TempEvent.Data = (byte*)packetBuffer;
TempEvent.Par1 = remoteIP[3];
PluginCall(PLUGIN_UDP_IN, &TempEvent, dummyString);
CPluginCall(CPLUGIN_UDP_IN, &TempEvent);
break;
}
}
}
}
#if defined(ESP32) // testing
portUDP.flush();
#endif
runningUPDCheck = false;
}
/*********************************************************************************************\
Send task info using UDP message
\*********************************************************************************************/
void SendUDPTaskInfo(byte destUnit, byte sourceTaskIndex, byte destTaskIndex)
{
if (WiFi.status() != WL_CONNECTED) {
return;
}
struct infoStruct infoReply;
infoReply.sourcelUnit = Settings.Unit;
infoReply.sourceTaskIndex = sourceTaskIndex;
infoReply.destTaskIndex = destTaskIndex;
LoadTaskSettings(infoReply.sourceTaskIndex);
infoReply.deviceNumber = Settings.TaskDeviceNumber[infoReply.sourceTaskIndex];
strcpy(infoReply.taskName, ExtraTaskSettings.TaskDeviceName);
for (byte x = 0; x < VARS_PER_TASK; x++)
strcpy(infoReply.ValueNames[x], ExtraTaskSettings.TaskDeviceValueNames[x]);
byte firstUnit = 1;
byte lastUnit = UNIT_MAX - 1;
if (destUnit != 0)
{
firstUnit = destUnit;
lastUnit = destUnit;
}
for (byte x = firstUnit; x <= lastUnit; x++)
{
infoReply.destUnit = x;
sendUDP(x, (byte*)&infoReply, sizeof(infoStruct));
delay(10);
}
delay(50);
}
/*********************************************************************************************\
Send task data using UDP message
\*********************************************************************************************/
void SendUDPTaskData(byte destUnit, byte sourceTaskIndex, byte destTaskIndex)
{
if (WiFi.status() != WL_CONNECTED) {
return;
}
struct dataStruct dataReply;
dataReply.sourcelUnit = Settings.Unit;
dataReply.sourceTaskIndex = sourceTaskIndex;
dataReply.destTaskIndex = destTaskIndex;
for (byte x = 0; x < VARS_PER_TASK; x++)
dataReply.Values[x] = UserVar[dataReply.sourceTaskIndex * VARS_PER_TASK + x];
byte firstUnit = 1;
byte lastUnit = UNIT_MAX - 1;
if (destUnit != 0)
{
firstUnit = destUnit;
lastUnit = destUnit;
}
for (byte x = firstUnit; x <= lastUnit; x++)
{
dataReply.destUnit = x;
sendUDP(x, (byte*) &dataReply, sizeof(dataStruct));
delay(10);
}
delay(50);
}
@@ -305,7 +128,7 @@ void SendUDPTaskData(byte destUnit, byte sourceTaskIndex, byte destTaskIndex)
\*********************************************************************************************/
void SendUDPCommand(byte destUnit, char* data, byte dataLength)
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
return;
}
byte firstUnit = 1;
@@ -329,7 +152,7 @@ void SendUDPCommand(byte destUnit, char* data, byte dataLength)
\*********************************************************************************************/
void sendUDP(byte unit, byte* data, byte size)
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
return;
}
if (unit != 255)
@@ -375,7 +198,7 @@ void refreshNodeList()
void sendSysInfoUDP(byte repeats)
{
char log[80];
if (Settings.UDPPort == 0 || WiFi.status() != WL_CONNECTED)
if (Settings.UDPPort == 0 || !WiFiConnected(100))
return;
// TODO: make a nice struct of it and clean up
@@ -430,17 +253,19 @@ void sendSysInfoUDP(byte repeats)
}
}
#if defined(ESP8266)
/********************************************************************************************\
Respond to HTTP XML requests for SSDP information
\*********************************************************************************************/
void SSDP_schema(WiFiClient &client) {
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
return;
}
const IPAddress ip = WiFi.localIP();
const uint32_t chipId = ESP.getChipId();
IPAddress ip = WiFi.localIP();
char str[20];
sprintf_P(str, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
uint32_t chipId = ESP.getChipId();
char uuid[64];
sprintf_P(uuid, PSTR("38323636-4558-4dda-9188-cda0e6%02x%02x%02x"),
(uint16_t) ((chipId >> 16) & 0xff),
@@ -460,7 +285,7 @@ void SSDP_schema(WiFiClient &client) {
"<minor>0</minor>"
"</specVersion>"
"<URLBase>http://");
ssdp_schema += formatIP(ip);
ssdp_schema += str;
ssdp_schema += F(":80/</URLBase>"
"<device>"
"<deviceType>urn:schemas-upnp-org:device:BinaryLight:1</deviceType>"
@@ -747,6 +572,50 @@ void SSDP_update() {
while (_server->next())
_server->flush();
}
}
#endif
// Check WiFi connection. Maximum timeout 500 msec.
bool WiFiConnected(uint32_t timeout_ms) {
uint32_t timer = millis() + (timeout_ms > 500 ? 500 : timeout_ms);
uint32_t min_delay = timeout_ms / 20;
if (min_delay < 10) {
yield(); // Allow at least once time for backgroundtasks
min_delay = 10;
}
if (!wifiConnected) {
// Apparently something needs network, perform check to see if it is ready now.
if (tryConnectWiFi())
checkWifiJustConnected();
}
while (WiFi.status() != WL_CONNECTED) {
if (timeOutReached(timer)) {
return false;
}
delay(min_delay); // Allow the backgroundtasks to continue procesing.
}
return true;
}
bool hostReachable(const IPAddress& ip) {
// Only do 1 ping at a time to return early
byte retry = 3;
while (retry > 0) {
if (Ping.ping(ip, 1)) return true;
delay(50);
--retry;
}
String log = F("Host unreachable: ");
log += ip;
addLog(LOG_LEVEL_ERROR, log);
return false;
}
bool hostReachable(const String& hostname) {
IPAddress 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);
return false;
}
-51
View File
@@ -1,51 +0,0 @@
#define WiFi_Logo_width 60
#define WiFi_Logo_height 36
const char WiFi_Logo_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const char activeSymbole[] PROGMEM = {
B00000000,
B00000000,
B00011000,
B00100100,
B01000010,
B01000010,
B00100100,
B00011000
};
const char inactiveSymbole[] PROGMEM = {
B00000000,
B00000000,
B00000000,
B00000000,
B00011000,
B00011000,
B00000000,
B00000000
};
-51
View File
@@ -1,51 +0,0 @@
#define WiFi_Logo_width 60
#define WiFi_Logo_height 36
const char WiFi_Logo_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const char activeSymbole[] PROGMEM = {
B00000000,
B00000000,
B00011000,
B00100100,
B01000010,
B01000010,
B00100100,
B00011000
};
const char inactiveSymbole[] PROGMEM = {
B00000000,
B00000000,
B00000000,
B00000000,
B00011000,
B00011000,
B00000000,
B00000000
};
+383
View File
@@ -0,0 +1,383 @@
/********************************************************************************************\
Convert a char string to integer
\*********************************************************************************************/
//FIXME: change original code so it uses String and String.toInt()
unsigned long str2int(char *string)
{
unsigned long temp = atof(string);
return temp;
}
/********************************************************************************************\
Check if valid float and convert string to float.
\*********************************************************************************************/
bool string2float(const String& string, float& floatvalue) {
if (!isFloat(string)) return false;
floatvalue = atof(string.c_str());
return true;
}
/********************************************************************************************\
Convert a char string to IP byte array
\*********************************************************************************************/
boolean str2ip(const String& string, byte* IP) {
return str2ip(string.c_str(), IP);
}
boolean str2ip(const char *string, byte* IP)
{
IPAddress tmpip; // Default constructor => set to 0.0.0.0
if (*string == 0 || tmpip.fromString(string)) {
// Eiher empty string or a valid IP addres, so copy value.
for (byte i = 0; i < 4; ++i)
IP[i] = tmpip[i];
return true;
}
return false;
}
// Call this by first declaring a char array of size 20, like:
// char strIP[20];
// formatIP(ip, strIP);
void formatIP(const IPAddress& ip, char (&strIP)[20]) {
sprintf_P(strIP, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
}
String formatIP(const IPAddress& ip) {
char strIP[20];
formatIP(ip, strIP);
return String(strIP);
}
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]);
}
/*********************************************************************************************\
Workaround for removing trailing white space when String() converts a float with 0 decimals
\*********************************************************************************************/
String toString(float value, byte decimals)
{
String sValue = String(value, decimals);
sValue.trim();
return sValue;
}
/*********************************************************************************************\
Format a value to the set number of decimals
\*********************************************************************************************/
String formatUserVar(struct EventStruct *event, byte rel_index)
{
float f(UserVar[event->BaseVarIndex + rel_index]);
if (!isValidFloat(f)) {
String log = F("Invalid float value for TaskIndex: ");
log += event->TaskIndex;
log += F(" varnumber: ");
log += rel_index;
addLog(LOG_LEVEL_DEBUG, log);
f = 0;
}
return toString(f, ExtraTaskSettings.TaskDeviceValueDecimals[rel_index]);
}
/*********************************************************************************************\
Wrap a string with given pre- and postfix string.
\*********************************************************************************************/
String wrap_String(const String& string, const String& wrap) {
String result;
result.reserve(string.length() + 2* wrap.length());
result = wrap;
result += string;
result += wrap;
return result;
}
/*********************************************************************************************\
Format an object value pair for use in JSON.
\*********************************************************************************************/
String to_json_object_value(const String& object, const String& value) {
String result;
result.reserve(object.length() + value.length() + 6);
result = wrap_String(object, F("\""));
result += F(":");
if (value.length() == 0 || !isFloat(value)) {
result += wrap_String(value, F("\""));
} else {
result += value;
}
return result;
}
/*********************************************************************************************\
Parse a string and get the xth command or parameter
\*********************************************************************************************/
String parseString(String& string, byte indexFind)
{
String tmpString = string;
tmpString += ",";
tmpString.replace(" ", ",");
String locateString = "";
byte count = 0;
int index = tmpString.indexOf(',');
while (index > 0)
{
count++;
locateString = tmpString.substring(0, index);
tmpString = tmpString.substring(index + 1);
index = tmpString.indexOf(',');
if (count == indexFind)
{
locateString.toLowerCase();
return locateString;
}
}
return "";
}
/*********************************************************************************************\
Parse a string and get the xth command or parameter
\*********************************************************************************************/
int getParamStartPos(String& string, byte indexFind)
{
String tmpString = string;
byte count = 0;
tmpString.replace(" ", ",");
for (unsigned int x = 0; x < tmpString.length(); x++)
{
if (tmpString.charAt(x) == ',')
{
count++;
if (count == (indexFind - 1))
return x + 1;
}
}
return -1;
}
//escapes special characters in strings for use in html-forms
void htmlEscape(String & html)
{
html.replace("&", "&amp;");
html.replace("\"", "&quot;");
html.replace("'", "&#039;");
html.replace("<", "&lt;");
html.replace(">", "&gt;");
}
/********************************************************************************************\
replace other system variables like %sysname%, %systime%, %ip%
\*********************************************************************************************/
void parseControllerVariables(String& s, struct EventStruct *event, boolean useURLencode) {
parseSystemVariables(s, useURLencode);
parseEventVariables(s, event, useURLencode);
parseStandardConversions(s, useURLencode);
}
void repl(const String& key, const String& val, String& s, boolean useURLencode)
{
if (useURLencode) {
s.replace(key, URLEncode(val.c_str()));
} else {
s.replace(key, val);
}
}
void parseSpecialCharacters(String& s, boolean useURLencode)
{
bool no_accolades = s.indexOf('{') == -1 || s.indexOf('}') == -1;
bool no_html_entity = s.indexOf('&') == -1 || s.indexOf(';') == -1;
if (no_accolades && no_html_entity)
return; // Nothing to replace
{
// Degree
const char degree[3] = {0xc2, 0xb0, 0}; // Unicode degree symbol
const char degreeC[4] = {0xe2, 0x84, 0x83, 0}; // Unicode degreeC symbol
const char degree_C[4] = {0xc2, 0xb0, 'C', 0}; // Unicode degree symbol + captial C
repl(F("{D}"), degree, s, useURLencode);
repl(F("&deg;"), degree, s, useURLencode);
repl(degreeC, degree_C, s, useURLencode);
}
{
// Angle quotes
const char laquo[3] = {0xc2, 0xab, 0}; // Unicode left angle quotes symbol
const char raquo[3] = {0xc2, 0xbb, 0}; // Unicode right angle quotes symbol
repl(F("{<<}"), laquo, s, useURLencode);
repl(F("&laquo;"), laquo, s, useURLencode);
repl(F("{>>}"), raquo, s, useURLencode);
repl(F("&raquo;"), raquo, s, useURLencode);
}
{
// Greek letter Mu
const char mu[3] = {0xc2, 0xb5, 0}; // Unicode greek letter mu
repl(F("{u}"), mu, s, useURLencode);
repl(F("&micro;"), mu, s, useURLencode);
}
{
// Currency
const char euro[4] = {0xe2, 0x82, 0xac, 0}; // Unicode euro symbol
const char yen[3] = {0xc2, 0xa5, 0}; // Unicode yen symbol
const char pound[3] = {0xc2, 0xa3, 0}; // Unicode pound symbol
const char cent[3] = {0xc2, 0xa2, 0}; // Unicode cent symbol
repl(F("{E}"), euro, s, useURLencode);
repl(F("&euro;"), euro, s, useURLencode);
repl(F("{Y}"), yen, s, useURLencode);
repl(F("&yen;"), yen, s, useURLencode);
repl(F("{P}"), pound, s, useURLencode);
repl(F("&pound;"), pound, s, useURLencode);
repl(F("{c}"), cent, s, useURLencode);
repl(F("&cent;"), cent, s, useURLencode);
}
{
// Math symbols
const char sup1[3] = {0xc2, 0xb9, 0}; // Unicode sup1 symbol
const char sup2[3] = {0xc2, 0xb2, 0}; // Unicode sup2 symbol
const char sup3[3] = {0xc2, 0xb3, 0}; // Unicode sup3 symbol
const char frac14[3] = {0xc2, 0xbc, 0}; // Unicode frac14 symbol
const char frac12[3] = {0xc2, 0xbd, 0}; // Unicode frac12 symbol
const char frac34[3] = {0xc2, 0xbe, 0}; // Unicode frac34 symbol
const char plusmn[3] = {0xc2, 0xb1, 0}; // Unicode plusmn symbol
const char times[3] = {0xc3, 0x97, 0}; // Unicode times symbol
const char divide[3] = {0xc3, 0xb7, 0}; // Unicode divide symbol
repl(F("{^1}"), sup1, s, useURLencode);
repl(F("&sup1;"), sup1, s, useURLencode);
repl(F("{^2}"), sup2, s, useURLencode);
repl(F("&sup2;"), sup2, s, useURLencode);
repl(F("{^3}"), sup3, s, useURLencode);
repl(F("&sup3;"), sup3, s, useURLencode);
repl(F("{1_4}"), frac14, s, useURLencode);
repl(F("&frac14;"), frac14, s, useURLencode);
repl(F("{1_2}"), frac12, s, useURLencode);
repl(F("&frac12;"), frac12, s, useURLencode);
repl(F("{3_4}"), frac34, s, useURLencode);
repl(F("&frac34;"), frac34, s, useURLencode);
repl(F("{+-}"), plusmn, s, useURLencode);
repl(F("&plusmn;"), plusmn, s, useURLencode);
repl(F("{x}"), times, s, useURLencode);
repl(F("&times;"), times, s, useURLencode);
repl(F("{..}"), divide, s, useURLencode);
repl(F("&divide;"), divide, s, useURLencode);
}
}
// Simple macro to create the replacement string only when needed.
#define SMART_REPL(T,S) if (s.indexOf(T) != -1) { repl((T), (S), s, useURLencode);}
void parseSystemVariables(String& s, boolean useURLencode)
{
parseSpecialCharacters(s, useURLencode);
if (s.indexOf('%') == -1)
return; // Nothing to replace
#if FEATURE_ADC_VCC
repl(F("%vcc%"), String(vcc), s, useURLencode);
#endif
repl(F("%CR%"), F("\r"), s, useURLencode);
repl(F("%LF%"), F("\n"), s, useURLencode);
SMART_REPL(F("%ip%"),WiFi.localIP().toString())
SMART_REPL(F("%rssi%"), String((WiFi.status() == WL_CONNECTED) ? WiFi.RSSI() : 0))
SMART_REPL(F("%ssid%"), (WiFi.status() == WL_CONNECTED) ? WiFi.SSID() : F("--"))
SMART_REPL(F("%unit%"), String(Settings.Unit))
SMART_REPL(F("%mac%"), String(WiFi.macAddress()))
#if defined(ESP8266)
SMART_REPL(F("%mac_int%"), String(ESP.getChipId())) // Last 24 bit of MAC address as integer, to be used in rules.
#endif
if (s.indexOf(F("%sys")) != -1) {
SMART_REPL(F("%sysload%"), String(100 - (100 * loopCounterLast / loopCounterMax)))
SMART_REPL(F("%systm_hm%"), getTimeString(':', false))
SMART_REPL(F("%systm_hm_am%"), getTimeString_ampm(':', false))
SMART_REPL(F("%systime%"), getTimeString(':'))
SMART_REPL(F("%systime_am%"), getTimeString_ampm(':'))
repl(F("%sysname%"), Settings.Name, s, useURLencode);
// valueString is being used by the macro.
char valueString[5];
#define SMART_REPL_TIME(T,F,V) if (s.indexOf(T) != -1) { sprintf_P(valueString, (F), (V)); repl((T),valueString, s, 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("%sysday%"), PSTR("%02d"), day())
SMART_REPL_TIME(F("%sysmonth%"),PSTR("%02d"), month())
SMART_REPL_TIME(F("%sysyear%"), PSTR("%04d"), year())
SMART_REPL_TIME(F("%sysyears%"),PSTR("%02d"), year()%100)
SMART_REPL(F("%sysweekday%"), String(weekday()))
SMART_REPL(F("%sysweekday_s%"), weekday_str())
#undef SMART_REPL_TIME
}
SMART_REPL(F("%lcltime%"), getDateTimeString('-',':',' '))
SMART_REPL(F("%lcltime_am%"), getDateTimeString_ampm('-',':',' '))
SMART_REPL(F("%uptime%"), String(wdcounter / 2))
repl(F("%tskname%"), ExtraTaskSettings.TaskDeviceName, s, useURLencode);
if (s.indexOf("%vname") != -1) {
repl(F("%vname1%"), ExtraTaskSettings.TaskDeviceValueNames[0], s, useURLencode);
repl(F("%vname2%"), ExtraTaskSettings.TaskDeviceValueNames[1], s, useURLencode);
repl(F("%vname3%"), ExtraTaskSettings.TaskDeviceValueNames[2], s, useURLencode);
repl(F("%vname4%"), ExtraTaskSettings.TaskDeviceValueNames[3], s, useURLencode);
}
}
void parseEventVariables(String& s, struct EventStruct *event, boolean useURLencode)
{
SMART_REPL(F("%id%"), String(event->idx))
if (s.indexOf("%val") != -1) {
if (event->sensorType == SENSOR_TYPE_LONG) {
SMART_REPL(F("%val1%"), String((unsigned long)UserVar[event->BaseVarIndex] + ((unsigned long)UserVar[event->BaseVarIndex + 1] << 16)))
} else {
SMART_REPL(F("%val1%"), formatUserVar(event, 0))
SMART_REPL(F("%val2%"), formatUserVar(event, 1))
SMART_REPL(F("%val3%"), formatUserVar(event, 2))
SMART_REPL(F("%val4%"), formatUserVar(event, 3))
}
}
}
#undef SMART_REPL
bool getConvertArgument(const String& marker, const String& s, float& argument, int& startIndex, int& endIndex) {
startIndex = s.indexOf(marker);
if (startIndex == -1) return false;
int startIndexArgument = startIndex + marker.length();
if (s.charAt(startIndexArgument) != '(') {
return false;
}
++startIndexArgument;
endIndex = s.indexOf(')', startIndexArgument);
if (endIndex == -1) return false;
String argumentString = s.substring(startIndexArgument, endIndex);
if (argumentString.length() == 0 || !isFloat(argumentString)) return false;
argument = argumentString.toFloat();
++endIndex; // Must also strip ')' from the original string.
return true;
}
// Parse conversions marked with "%conv_marker%(float)"
// Must be called last, since all sensor values must be converted, processed, etc.
void parseStandardConversions(String& s, boolean useURLencode) {
if (s.indexOf(F("%c_")) == -1)
return; // Nothing to replace
float arg = 0.0;
int startIndex = 0;
int endIndex = 0;
// These replacements should be done in a while loop per marker,
// since they also replace the numerical parameter.
// The marker may occur more than once per string, but with different parameters.
#define SMART_CONV(T,FUN) while (getConvertArgument((T), s, arg, startIndex, endIndex)) { repl(s.substring(startIndex, endIndex), (FUN), s, useURLencode); }
SMART_CONV(F("%c_w_dir%"), getBearing(arg))
SMART_CONV(F("%c_c2f%"), toString(CelsiusToFahrenheit(arg), 1))
SMART_CONV(F("%c_ms2Bft%"), String(m_secToBeaufort(arg)))
SMART_CONV(F("%c_cm2imp%"), centimeterToImperialLength(arg))
SMART_CONV(F("%c_mm2imp%"), millimeterToImperialLength(arg))
SMART_CONV(F("%c_m2day%"), toString(minutesToDay(arg), 2))
SMART_CONV(F("%c_m2dh%"), minutesToDayHour(arg))
SMART_CONV(F("%c_m2dhm%"), minutesToDayHourMinute(arg))
SMART_CONV(F("%c_s2dhms%"), secondsToDayHourMinuteSecond(arg))
#undef SMART_CONV
}
+117 -66
View File
@@ -74,6 +74,13 @@ void setTime(unsigned long t) {
sysTime = (uint32_t)t;
nextSyncTime = (uint32_t)t + syncInterval;
prevMillis = millis(); // restart counting from now (thanks to Korman for this fix)
if (Settings.UseRules)
{
static bool firstUpdate = true;
String event = firstUpdate ? F("Time#Initialized") : F("Time#Set");
firstUpdate = false;
rulesProcessing(event);
}
}
unsigned long now() {
@@ -89,10 +96,11 @@ unsigned long now() {
setTime(t);
applyTimeZone(t);
} else {
nextSyncTime = sysTime + syncInterval;
// Unable to sync, retry again in a minute
nextSyncTime = sysTime + 60;
}
}
uint32 localSystime = toLocal(sysTime);
uint32_t localSystime = toLocal(sysTime);
breakTime(localSystime, tm);
return (unsigned long)localSystime;
}
@@ -141,11 +149,19 @@ byte second()
return tm.Second;
}
// day of week, sunday is day 1
int weekday()
{
return tm.Wday;
}
String weekday_str()
{
const int wday(weekday() - 1); // here: Count from Sunday = 0
const String weekDays = F("SunMonTueWedThuFriSat");
return weekDays.substring(wday * 3, wday * 3 + 3);
}
void initTime()
{
nextSyncTime = 0;
@@ -161,9 +177,10 @@ void checkTime()
PrevMinutes = tm.Minute;
if (Settings.UseRules)
{
String weekDays = F("AllSunMonTueWedThuFriSat");
String event = F("Clock#Time=");
event += weekDays.substring(weekday() * 3, weekday() * 3 + 3);
String event;
event.reserve(21);
event = F("Clock#Time=");
event += weekday_str();
event += ",";
if (hour() < 10)
event += "0";
@@ -180,68 +197,65 @@ void checkTime()
unsigned long getNtpTime()
{
if (WiFi.status() != WL_CONNECTED || !Settings.UseNTP) {
if (!Settings.UseNTP || !WiFiConnected(100)) {
return 0;
}
IPAddress timeServerIP;
const char* ntpServerName = "pool.ntp.org";
// Have to do a lookup eacht time, since the NTP pool always returns another IP
if (Settings.NTPHost[0] != 0)
WiFi.hostByName(Settings.NTPHost, timeServerIP);
else
WiFi.hostByName(ntpServerName, timeServerIP);
if (!hostReachable(timeServerIP))
return 0;
WiFiUDP udp;
udp.begin(123);
for (byte x = 1; x < 4; x++)
{
String log = F("NTP : NTP sync request:");
log += x;
addLog(LOG_LEVEL_DEBUG_MORE, log);
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
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
IPAddress timeServerIP;
const char* ntpServerName = "pool.ntp.org";
String log = F("NTP : NTP send to ");
log += timeServerIP.toString();
addLog(LOG_LEVEL_DEBUG_MORE, log);
if (Settings.NTPHost[0] != 0)
WiFi.hostByName(Settings.NTPHost, timeServerIP);
else
WiFi.hostByName(ntpServerName, timeServerIP);
while (udp.parsePacket() > 0) ; // discard any previously received packets
log = F("NTP : NTP send to ");
log += timeServerIP.toString();
addLog(LOG_LEVEL_DEBUG_MORE, log);
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
udp.beginPacket(timeServerIP, 123); //NTP requests are to port 123
udp.write(packetBuffer, NTP_PACKET_SIZE);
udp.endPacket();
while (udp.parsePacket() > 0) ; // discard any previously received packets
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
udp.beginPacket(timeServerIP, 123); //NTP requests are to port 123
udp.write(packetBuffer, NTP_PACKET_SIZE);
udp.endPacket();
uint32_t beginWait = millis();
while (!timeOutReached(beginWait + 1000)) {
int size = udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
log = F("NTP : NTP replied: ");
log += timePassedSince(beginWait);
log += F(" mSec");
addLog(LOG_LEVEL_DEBUG_MORE, log);
return secsSince1900 - 2208988800UL;
}
uint32_t beginWait = millis();
while (!timeOutReached(beginWait + 1000)) {
int size = udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
log = F("NTP : NTP replied: ");
log += timePassedSince(beginWait);
log += F(" mSec");
addLog(LOG_LEVEL_DEBUG_MORE, log);
return secsSince1900 - 2208988800UL;
}
log = F("NTP : No reply");
addLog(LOG_LEVEL_DEBUG_MORE, log);
}
log = F("NTP : No reply");
addLog(LOG_LEVEL_DEBUG_MORE, log);
return 0;
}
@@ -376,16 +390,40 @@ String getDateString()
// returns the current Time separated by the given delimiter
// time format example with ':' delimiter: 23:59:59 (HH:MM:SS)
String getTimeString(const timeStruct& ts, char delimiter)
String getTimeString(const timeStruct& ts, char delimiter, bool am_pm, bool show_seconds)
{
char TimeString[20]; //19 digits plus the null char
sprintf_P(TimeString, PSTR("%02d%c%02d%c%02d"), ts.Hour, delimiter, ts.Minute, delimiter, ts.Second);
if (am_pm) {
uint8_t hour(ts.Hour % 12);
if (hour == 0) { hour = 12; }
const char a_or_p = ts.Hour < 12 ? 'A' : 'P';
if (show_seconds) {
sprintf_P(TimeString, PSTR("%d%c%02d%c%02d %cM"),
hour, delimiter, ts.Minute, delimiter, ts.Second, a_or_p);
} else {
sprintf_P(TimeString, PSTR("%d%c%02d %cM"),
hour, delimiter, ts.Minute, a_or_p);
}
} else {
if (show_seconds) {
sprintf_P(TimeString, PSTR("%02d%c%02d%c%02d"),
ts.Hour, delimiter, ts.Minute, delimiter, ts.Second);
} else {
sprintf_P(TimeString, PSTR("%d%c%02d"),
ts.Hour, delimiter, ts.Minute);
}
}
return TimeString;
}
String getTimeString(char delimiter)
String getTimeString(char delimiter, bool show_seconds /*=true*/)
{
return getTimeString(tm, delimiter);
return getTimeString(tm, delimiter, false, show_seconds);
}
String getTimeString_ampm(char delimiter, bool show_seconds /*=true*/)
{
return getTimeString(tm, delimiter, true, show_seconds);
}
// returns the current Time without delimiter
@@ -395,26 +433,35 @@ String getTimeString()
return getTimeString('\0');
}
String getTimeString_ampm()
{
return getTimeString_ampm('\0');
}
// returns the current Date and Time separated by the given delimiter
// if called like this: getDateTimeString('\0', '\0', '\0');
// it will give back this: 20161231235959 (YYYYMMDDHHMMSS)
String getDateTimeString(const timeStruct& ts, char dateDelimiter, char timeDelimiter, char dateTimeDelimiter)
String getDateTimeString(const timeStruct& ts, char dateDelimiter, char timeDelimiter, char dateTimeDelimiter, bool am_pm)
{
String ret = getDateString(ts, dateDelimiter);
if (dateTimeDelimiter != '\0')
ret += dateTimeDelimiter;
ret += getTimeString(ts, timeDelimiter);
ret += getTimeString(ts, timeDelimiter, am_pm, true);
return ret;
}
String getDateTimeString(char dateDelimiter, char timeDelimiter, char dateTimeDelimiter) {
return getDateTimeString(tm, dateDelimiter, timeDelimiter, dateTimeDelimiter);
return getDateTimeString(tm, dateDelimiter, timeDelimiter, dateTimeDelimiter, false);
}
String getDateTimeString_ampm(char dateDelimiter, char timeDelimiter, char dateTimeDelimiter) {
return getDateTimeString(tm, dateDelimiter, timeDelimiter, dateTimeDelimiter, true);
}
/********************************************************************************************\
Convert a string like "Sun,12:30" into a 32 bit integer
\*********************************************************************************************/
unsigned long string2TimeLong(String &str)
unsigned long string2TimeLong(const String &str)
{
// format 0000WWWWAAAABBBBCCCCDDDD
// WWWW=weekday, AAAA=hours tens digit, BBBB=hours, CCCC=minutes tens digit DDDD=minutes
@@ -423,8 +470,12 @@ unsigned long string2TimeLong(String &str)
char TmpStr1[10];
int w, x, y;
unsigned long a;
str.toLowerCase();
str.toCharArray(command, 20);
{
// Within a scope so the tmpString is only used for copy.
String tmpString(str);
tmpString.toLowerCase();
tmpString.toCharArray(command, 20);
}
unsigned long lngTime = 0;
if (GetArgv(command, TmpStr1, 1))
+21 -6
View File
@@ -57,13 +57,28 @@ TimeChangeRule usPST = {First, dowSunday, Nov, 2, -480};
setTimeZone(usPDT, usPST);
*/
void applyTimeZone(uint32_t curTime) {
void getDefaultDst_flash_values(uint16_t& start, uint16_t& end) {
// DST start: Last Sunday March 2am => 3am
// DST end: Last Sunday October 3am => 2am
TimeChangeRule CEST(Last, Sun, Mar, 2, Settings.TimeZone); // Summer Time
TimeChangeRule CET(Last, Sun, Oct, 3, Settings.TimeZone); // Standard Time
start = CEST.toFlashStoredValue();
end = CET.toFlashStoredValue();
}
void applyTimeZone(uint32_t curTime) {
int dst_offset = Settings.DST ? 60 : 0;
TimeChangeRule CEST(Last, Sun, Mar, 2, Settings.TimeZone + dst_offset); // Summer Time
TimeChangeRule CET(Last, Sun, Oct, 3, Settings.TimeZone); // Standard Time
setTimeZone(CEST, CET, curTime);
uint16_t tmpStart(Settings.DST_Start);
uint16_t tmpEnd(Settings.DST_End);
for (int i = 0; i < 2; ++i) {
TimeChangeRule start(tmpStart, Settings.TimeZone + dst_offset); // Summer Time
TimeChangeRule end(tmpEnd, Settings.TimeZone); // Standard Time
if (start.isValid() && end.isValid()) {
setTimeZone(start, end, curTime);
return;
}
getDefaultDst_flash_values(tmpStart, tmpEnd);
}
}
void setTimeZone(const TimeChangeRule& dstStart, const TimeChangeRule& stdStart, uint32_t curTime) {
@@ -82,7 +97,7 @@ void logTimeZoneInfo() {
if (m_dstLoc != 0) {
timeStruct tmp;
breakTime(m_dstLoc, tmp);
log += getDateTimeString(tmp, '-', ':', ' ');
log += getDateTimeString(tmp, '-', ':', ' ', false);
}
log += F(" offset: ");
log += m_dst.offset;
@@ -93,7 +108,7 @@ void logTimeZoneInfo() {
if (m_stdLoc != 0) {
timeStruct tmp;
breakTime(m_stdLoc, tmp);
log += getDateTimeString(tmp, '-', ':', ' ');
log += getDateTimeString(tmp, '-', ':', ' ', false);
}
log += F(" offset: ");
log += m_std.offset;
+1722 -1368
View File
File diff suppressed because it is too large Load Diff
+278 -146
View File
@@ -4,7 +4,7 @@
String WifiGetAPssid()
{
String ssid(Settings.Name);
ssid+=F("_");
ssid+=F("-");
ssid+=Settings.Unit;
return (ssid);
}
@@ -27,7 +27,10 @@ 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
WiFi.softAP(WifiGetAPssid().c_str(), SecuritySettings.WifiAPKey);
String softAPSSID=WifiGetAPssid();
String pwd = SecuritySettings.WifiAPKey;
WiFi.softAP(softAPSSID.c_str(),pwd.c_str());
// We start in STA mode
WifiAPMode(false);
@@ -44,12 +47,7 @@ void WifiAPconfig()
bool WifiIsAP()
{
#if defined(ESP8266)
byte wifimode = wifi_get_opmode();
#endif
#if defined(ESP32)
byte wifimode = WiFi.getMode();
#endif
byte wifimode = wifi_get_opmode();
return(wifimode == 2 || wifimode == 3); //apmode is enabled
}
@@ -80,153 +78,306 @@ void WifiAPMode(boolean state)
//********************************************************************************
// Configure network and connect to Wifi SSID and SSID2
// Set Wifi config
//********************************************************************************
boolean WifiConnect(byte connectAttempts)
{
bool prepareWiFi() {
String log = "";
char hostname[40];
strncpy(hostname, WifiGetHostname().c_str(), sizeof(hostname));
#if defined(ESP8266)
wifi_station_set_hostname(hostname);
#endif
#if defined(ESP32)
WiFi.setHostname(hostname);
#endif
wifi_station_set_hostname(hostname);
//use static ip?
if (Settings.IP[0] != 0 && Settings.IP[0] != 255)
{
const IPAddress ip = Settings.IP;
char str[20];
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.IP[0], Settings.IP[1], Settings.IP[2], Settings.IP[3]);
log = F("IP : Static IP :");
log += ip;
log += str;
addLog(LOG_LEVEL_INFO, log);
const IPAddress gw = Settings.Gateway;
const IPAddress subnet = Settings.Subnet;
const IPAddress dns = Settings.DNS;
IPAddress ip = Settings.IP;
IPAddress gw = Settings.Gateway;
IPAddress subnet = Settings.Subnet;
IPAddress dns = Settings.DNS;
WiFi.config(ip, gw, subnet, dns);
}
return selectValidWiFiSettings();
}
//try to connect to one of the access points
if (WifiConnectSSID(SecuritySettings.WifiSSID, SecuritySettings.WifiKey, connectAttempts) ||
WifiConnectSSID(SecuritySettings.WifiSSID2, SecuritySettings.WifiKey2, connectAttempts))
{
// fix octet?
if (Settings.IP_Octet != 0 && Settings.IP_Octet != 255)
{
IPAddress ip = WiFi.localIP();
IPAddress gw = WiFi.gatewayIP();
IPAddress subnet = WiFi.subnetMask();
ip[3] = Settings.IP_Octet;
log = F("IP : Fixed IP octet:");
log += ip;
addLog(LOG_LEVEL_INFO, log);
WiFi.config(ip, gw, subnet);
//********************************************************************************
// Configure network and connect to Wifi SSID and SSID2
//********************************************************************************
boolean WifiConnect(byte connectAttempts)
{
if (prepareWiFi()) {
//try to connect to one of the access points
bool connected = WifiConnectAndWait(connectAttempts);
if (!connected) {
if (selectNextWiFiSettings()) {
connected = WifiConnectAndWait(connectAttempts);
}
}
if (connected) {
return(true);
}
#ifdef FEATURE_MDNS
String log = F("WIFI : ");
if (MDNS.begin(WifiGetHostname().c_str(), WiFi.localIP())) {
log += F("mDNS started, with name: ");
log += WifiGetHostname();
log += F(".local");
}
else{
log += F("mDNS failed");
}
addLog(LOG_LEVEL_INFO, log);
#endif
return(true);
}
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)
WifiAPMode(true);
return(false);
}
//********************************************************************************
// Start connect to WiFi and check later to see if connected.
//********************************************************************************
void WiFiConnectRelaxed() {
wifiConnected = false;
wifi_connect_attempt = 0;
if (prepareWiFi()) {
tryConnectWiFi();
return;
}
addLog(LOG_LEVEL_ERROR, F("WIFI : Could not connect to AP, no valid WiFi settings!"));
//everything failed, activate AP mode (will deactivate automatically after a while if its connected again)
WifiAPMode(true);
}
//********************************************************************************
// Manage WiFi credentials
//********************************************************************************
const char* getLastWiFiSettingsSSID() {
return lastWiFiSettings == 0 ? SecuritySettings.WifiSSID : SecuritySettings.WifiSSID2;
}
const char* getLastWiFiSettingsPassphrase() {
return lastWiFiSettings == 0 ? SecuritySettings.WifiKey : SecuritySettings.WifiKey2;
}
bool anyValidWifiSettings() {
if (wifiSettingsValid(SecuritySettings.WifiSSID, SecuritySettings.WifiKey))
return true;
if (wifiSettingsValid(SecuritySettings.WifiSSID2, SecuritySettings.WifiKey2))
return true;
addLog(LOG_LEVEL_ERROR, F("WIFI : No valid WiFi settings!"));
return false;
}
bool selectNextWiFiSettings() {
uint8_t tmp = lastWiFiSettings;
lastWiFiSettings = (lastWiFiSettings + 1) % 2;
if (!wifiSettingsValid(getLastWiFiSettingsSSID(), getLastWiFiSettingsPassphrase())) {
// other settings are not correct, switch back.
lastWiFiSettings = tmp;
return false; // Nothing changed.
}
return true;
}
bool selectValidWiFiSettings() {
if (wifiSettingsValid(getLastWiFiSettingsSSID(), getLastWiFiSettingsPassphrase()))
return true;
return selectNextWiFiSettings();
}
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 (strlen(ssid) > 32) return false;
if (strlen(pass) > 64) return false;
return true;
}
bool wifiConnectTimeoutReached() {
if (wifi_connect_attempt == 0) return true;
if (wifiSetupConnect) {
// Initial setup of WiFi, may take much longer since accesspoint is still active.
return timeOutReached(wifi_connect_timer + 20000);
}
// wait until it connects + add some device specific random offset to prevent
// all nodes overloading the accesspoint when turning on at the same time.
const unsigned int randomOffset_in_sec = wifi_connect_attempt == 1 ? 0 : 1000 * ((ESP.getChipId() & 0xF));
return timeOutReached(wifi_connect_timer + DEFAULT_WIFI_CONNECTION_TIMEOUT + randomOffset_in_sec);
}
//********************************************************************************
// Simply start the WiFi connection sequence
//********************************************************************************
bool tryConnectWiFi() {
if (wifiSetup && !wifiSetupConnect)
return false;
if (WiFi.status() == WL_CONNECTED)
return(true); //already connected, need to disconnect first
if (!wifiConnectTimeoutReached())
return true; // timeout not reached yet, thus no need to retry again.
if (!anyValidWifiSettings())
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 > 6) {
//everything failed, activate AP mode (will deactivate automatically after a while if its connected again)
WifiAPMode(true);
}
String ssid;
ssid.reserve(32);
String passphrase;
passphrase.reserve(64);
ssid = getLastWiFiSettingsSSID();
passphrase = getLastWiFiSettingsPassphrase();
String log = F("WIFI : Connecting ");
log += ssid;
log += F(" attempt #");
log += wifi_connect_attempt;
addLog(LOG_LEVEL_INFO, log);
wifi_connect_timer = millis();
switch (wifi_connect_attempt) {
case 0:
if (lastBSSID[0] == 0)
WiFi.begin(ssid.c_str(), passphrase.c_str());
else
WiFi.begin(ssid.c_str(), passphrase.c_str(), 0, &lastBSSID[0]);
break;
default:
WiFi.begin(ssid.c_str(), passphrase.c_str());
}
++wifi_connect_attempt;
switch (WiFi.status()) {
case WL_NO_SSID_AVAIL: {
log = F("WIFI : No SSID found matching: ");
log += ssid;
addLog(LOG_LEVEL_INFO, log);
return false;
}
case WL_CONNECT_FAILED: {
log = F("WIFI : Connection failed to: ");
log += ssid;
addLog(LOG_LEVEL_INFO, log);
return false;
}
case WL_CONNECTED:
checkWifiJustConnected();
break;
default:
break;
}
return true; // Sent
}
//********************************************************************************
// Connect to Wifi specific SSID
//********************************************************************************
boolean WifiConnectSSID(char WifiSSID[], char WifiKey[], byte connectAttempts)
boolean WifiConnectAndWait(byte connectAttempts)
{
String log;
//already connected, need to disconnect first
if (WiFi.status() == WL_CONNECTED)
return(true);
//no ssid specified
if ((WifiSSID[0] == 0) || (strcasecmp(WifiSSID, "ssid") == 0))
return(false);
for (byte tryConnect = 1; tryConnect <= connectAttempts; tryConnect++)
wifiConnected = false;
wifi_connect_attempt = 0;
for (byte tryConnect = 0; tryConnect < connectAttempts; tryConnect++)
{
log = F("WIFI : Connecting ");
log += WifiSSID;
log += F(" attempt #");
log += tryConnect;
addLog(LOG_LEVEL_INFO, log);
if (tryConnect == 1)
WiFi.begin(WifiSSID, WifiKey);
else
WiFi.begin();
//wait until it connects
for (byte x = 0; x < 200; x++)
{
if (WiFi.status() != WL_CONNECTED)
{
statusLED(false);
if (tryConnectWiFi()) {
do {
if (checkWifiJustConnected())
return true;
delay(50);
}
else
break;
} while (!wifiConnectTimeoutReached());
}
if (WiFi.status() == WL_CONNECTED)
// log = F("WIFI : Disconnecting!");
// addLog(LOG_LEVEL_INFO, log);
#if defined(ESP8266)
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
#endif
for (byte x = 0; x < 20; x++)
{
if (Settings.UseNTP) {
initTime();
}
log = F("WIFI : Connected! IP: ");
log += formatIP(WiFi.localIP());
log += F(" (");
log += WifiGetHostname();
log += F(")");
addLog(LOG_LEVEL_INFO, log);
statusLED(true);
return(true);
}
else
{
// log = F("WIFI : Disconnecting!");
// addLog(LOG_LEVEL_INFO, log);
#if defined(ESP8266)
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
#endif
for (byte x = 0; x < 20; x++)
{
statusLED(true);
delay(50);
}
delay(50);
}
}
return false;
}
bool checkWifiJustConnected() {
if (wifiConnected) return true;
delay(1);
if (WiFi.status() != WL_CONNECTED) {
statusLED(false);
return false;
}
wifiConnected = true;
String log = F("WIFI : WiFi connect attempt took: ");
log += timePassedSince(wifi_connect_timer);
log += F(" ms");
addLog(LOG_LEVEL_INFO, log);
// fix octet?
if (Settings.IP_Octet != 0 && Settings.IP_Octet != 255)
{
IPAddress ip = WiFi.localIP();
IPAddress gw = WiFi.gatewayIP();
IPAddress subnet = WiFi.subnetMask();
ip[3] = Settings.IP_Octet;
log = F("IP : Fixed IP octet:");
log += ip;
addLog(LOG_LEVEL_INFO, log);
WiFi.config(ip, gw, subnet);
}
#ifdef FEATURE_MDNS
String log = F("WIFI : ");
if (MDNS.begin(WifiGetHostname().c_str(), WiFi.localIP())) {
log += F("mDNS started, with name: ");
log += WifiGetHostname();
log += F(".local");
}
else{
log += F("mDNS failed");
}
addLog(LOG_LEVEL_INFO, log);
#endif
// First try to get the time, since that may be used in logs
if (Settings.UseNTP) {
initTime();
}
uint8_t* curBSSID = WiFi.BSSID();
bool changed = false;
for (byte i=0; i < 6; ++i) {
if (lastBSSID[i] != *(curBSSID + i)) {
changed = true;
lastBSSID[i] = *(curBSSID + i);
}
}
if (Settings.UseRules)
{
if (changed) {
String event = F("WiFi#ChangedAccesspoint");
rulesProcessing(event);
}
String event = F("WiFi#Connected");
rulesProcessing(event);
}
log = F("WIFI : Connected! IP: ");
log += formatIP(WiFi.localIP());
log += F(" (");
log += WifiGetHostname();
log += F(") AP: ");
log += WiFi.SSID();
log += F(" AP BSSID: ");
log += WiFi.BSSIDstr();
addLog(LOG_LEVEL_INFO, log);
statusLED(true);
return true;
}
//********************************************************************************
// Disconnect from Wifi AP
@@ -234,6 +385,7 @@ boolean WifiConnectSSID(char WifiSSID[], char WifiKey[], byte connectAttempts)
void WifiDisconnect()
{
WiFi.disconnect();
wifiConnected = false;
}
@@ -275,18 +427,20 @@ void WifiScan()
//********************************************************************************
void WifiCheck()
{
if(wifiSetup)
return;
if (WiFi.status() != WL_CONNECTED)
{
NC_Count++;
//give it time to automatically reconnect
//give it time to automaticly reconnect
if (NC_Count > 2)
{
WifiConnect(2);
if (wifiConnected) {
wifi_connect_attempt = 0;
wifiConnected = false;
WiFiConnectRelaxed();
}
C_Count=0;
NC_Count = 0;
}
@@ -301,30 +455,8 @@ void WifiCheck()
WifiAPMode(false);
}
}
}
//********************************************************************************
// Return subnet range of WiFi.
//********************************************************************************
bool getSubnetRange(IPAddress& low, IPAddress& high)
{
if (WifiIsAP()) {
// WiFi is active as accesspoint, do not check.
return false;
if (!wifiConnected) {
if (tryConnectWiFi())
checkWifiJustConnected();
}
if (WiFi.status() != WL_CONNECTED) {
return false;
}
const IPAddress ip = WiFi.localIP();
const IPAddress subnet = WiFi.subnetMask();
low = ip;
high = ip;
// Compute subnet range.
for (byte i=0; i < 4; ++i) {
if (subnet[i] != 255) {
low[i] = low[i] & subnet[i];
high[i] = high[i] | ~subnet[i];
}
}
return true;
}
+26 -90
View File
@@ -6,7 +6,6 @@
#define CPLUGIN_ID_001 1
#define CPLUGIN_NAME_001 "Domoticz HTTP"
boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
@@ -34,7 +33,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
{
if (event->idx != 0)
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
success = false;
break;
}
@@ -76,64 +75,6 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
url += F("&svalue=");
url += formatUserVar(event, 0);
break;
case SENSOR_TYPE_LONG: // single LONG value, stored in two floats (rfid tags)
url += F("&svalue=");
url += (unsigned long)UserVar[event->BaseVarIndex] + ((unsigned long)UserVar[event->BaseVarIndex + 1] << 16);
break;
case SENSOR_TYPE_DUAL: // any sensor that uses two simple values
url += F("&svalue=");
url += formatUserVar(event, 0);
url += (";");
url += formatUserVar(event, 1);
break;
case SENSOR_TYPE_TEMP_HUM: // temp + hum + hum_stat, used for DHT11
url += F("&svalue=");
url += formatUserVar(event, 0);
url += F(";");
url += formatUserVar(event, 1);
url += F(";");
url += humStat(UserVar[event->BaseVarIndex + 1]);
break;
case SENSOR_TYPE_TEMP_BARO: // temp + bar used for BMP085 and BMP280
url += F("&svalue=");
url += formatUserVar(event, 0);
url += F(";0;0;");
url += formatUserVar(event, 1);
url += F(";0");
break;
case SENSOR_TYPE_TRIPLE:
url += F("&svalue=");
url += formatUserVar(event, 0);
url += F(";");
url += formatUserVar(event, 1);
url += F(";");
url += formatUserVar(event, 2);
break;
case SENSOR_TYPE_TEMP_HUM_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BME280
url += F("&svalue=");
url += formatUserVar(event, 0);
url += F(";");
url += formatUserVar(event, 1);
url += F(";");
url += humStat(UserVar[event->BaseVarIndex + 1]);
url += F(";");
url += formatUserVar(event, 2);
url += F(";0");
break;
case SENSOR_TYPE_QUAD:
url += F("&svalue=");
url += formatUserVar(event, 0);
url += F(";");
url += formatUserVar(event, 1);
url += F(";");
url += formatUserVar(event, 2);
url += F(";");
url += formatUserVar(event, 3);
break;
case SENSOR_TYPE_SWITCH:
url = F("/json.htm?type=command&param=switchlight&idx=");
url += event->idx;
@@ -147,28 +88,39 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
url = F("/json.htm?type=command&param=switchlight&idx=");
url += event->idx;
url += F("&switchcmd=");
if (UserVar[event->BaseVarIndex] == 0)
if (UserVar[event->BaseVarIndex] == 0) {
url += ("Off");
else
{
} else {
url += F("Set%20Level&level=");
url += UserVar[event->BaseVarIndex];
}
break;
case (SENSOR_TYPE_WIND):
url += F("&svalue="); // WindDir in degrees; WindDir as text; Wind speed average ; Wind speed gust; 0
url += formatUserVar(event, 0);
url += ";";
url += getBearing(UserVar[event->BaseVarIndex]);
url += ";";
// Domoticz expects the wind speed in (m/s * 10)
url += toString((UserVar[event->BaseVarIndex + 1] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[1]);
url += ";";
url += toString((UserVar[event->BaseVarIndex + 2] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[2]);
url += ";0;0";
case SENSOR_TYPE_SINGLE:
case SENSOR_TYPE_LONG:
case SENSOR_TYPE_DUAL:
case SENSOR_TYPE_TRIPLE:
case SENSOR_TYPE_QUAD:
case SENSOR_TYPE_TEMP_HUM:
case SENSOR_TYPE_TEMP_BARO:
case SENSOR_TYPE_TEMP_HUM_BARO:
case SENSOR_TYPE_WIND:
default:
url = F("/json.htm?type=command&param=udevice&idx=");
url += event->idx;
url += F("&nvalue=0");
url += F("&svalue=");
url += formatDomoticzSensorType(event);
break;
}
// Add WiFi reception quality
url += F("&rssi=");
url += mapRSSItoDomoticz();
#if FEATURE_ADC_VCC
url += F("&battery=");
url += mapVccToDomoticz();
#endif
// This will send the request to the server
String request = F("GET ");
@@ -212,19 +164,3 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
}
return success;
}
int humStat(int hum){
int lHumStat;
if(hum<30){
lHumStat = 2;
}else if(hum<40){
lHumStat = 0;
}else if(hum<59){
lHumStat = 1;
}else{
lHumStat = 3;
}
return lHumStat;
}
+26 -110
View File
@@ -45,12 +45,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
// json[0] = 0;
// event->String2.toCharArray(json, 512);
// Find first enabled controller index with this protocol
byte ControllerID = CONTROLLER_MAX;
for (byte i=0; i < CONTROLLER_MAX; i++) {
if (Settings.Protocol[i] == CPLUGIN_ID_002 && Settings.ControllerEnabled[i]) {
ControllerID = i;
}
}
byte ControllerID = findFirstEnabledControllerWithId(CPLUGIN_ID_002);
if (ControllerID < CONTROLLER_MAX) {
StaticJsonBuffer<512> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(event->String2.c_str());
@@ -71,7 +66,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
switchtype = "?";
for (byte x = 0; x < TASKS_MAX; x++) {
// We need the index of the controller we are: 0-CONTROLLER_MAX
// We need the index of the controller we are: 0...CONTROLLER_MAX
if (Settings.TaskDeviceEnabled[x] && Settings.TaskDeviceID[ControllerID][x] == idx) // get idx for our controller index
{
String action = "";
@@ -125,6 +120,9 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
struct EventStruct TempEvent;
parseCommandString(&TempEvent, action);
PluginCall(PLUGIN_WRITE, &TempEvent, action);
// trigger rulesprocessing
if (Settings.UseRules)
createRuleEvents(x);
}
}
}
@@ -137,102 +135,23 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
{
if (event->idx != 0)
{
if (WiFi.status() != WL_CONNECTED) {
ControllerSettingsStruct ControllerSettings;
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
if (!ControllerSettings.checkHostReachable(true)) {
success = false;
break;
}
ControllerSettingsStruct ControllerSettings;
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root[F("idx")] = event->idx;
String values;
// char str[80];
root[F("RSSI")] = mapRSSItoDomoticz();
#if FEATURE_ADC_VCC
root[F("Battery")] = mapVccToDomoticz();
#endif
switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
// values.toCharArray(str, 80);
root[F("svalue")] = values.c_str();
break;
case SENSOR_TYPE_LONG: // single LONG value, stored in two floats (rfid tags)
root[F("nvalue")] = 0;
values = (unsigned long)UserVar[event->BaseVarIndex] + ((unsigned long)UserVar[event->BaseVarIndex + 1] << 16);
// values.toCharArray(str, 80);
root[F("svalue")] = values.c_str();
break;
case SENSOR_TYPE_DUAL: // any sensor that uses two simple values
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
values += ";";
values += formatUserVar(event, 1);
// values.toCharArray(str, 80);
root[F("svalue")] = values.c_str();
// root[F("svalue")] = str;
break;
case SENSOR_TYPE_TRIPLE: // any sensor that uses three simple values
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
values += ";";
values += formatUserVar(event, 1);
values += ";";
values += formatUserVar(event, 2);
// values.toCharArray(str, 80);
root[F("svalue")] = values.c_str();
// root[F("svalue")] = str;
break;
case SENSOR_TYPE_TEMP_HUM: // temp + hum + hum_stat, used for DHT11
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
values += ";";
values += formatUserVar(event, 1);
values += ";0";
// values.toCharArray(str, 80);
root[F("svalue")] = values.c_str();
// root[F("svalue")] = str;
break;
case SENSOR_TYPE_TEMP_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BMP085
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
values += ";0;0;";
values += formatUserVar(event, 1);
values += ";0";
// values.toCharArray(str, 80);
root[F("svalue")] = values.c_str();
// root[F("svalue")] = str;
break;
case SENSOR_TYPE_TEMP_HUM_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BME280
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
values += ";";
values += formatUserVar(event, 1);
values += ";0;";
values += formatUserVar(event, 2);
values += ";0";
root[F("svalue")] = values.c_str();
// values.toCharArray(str, 80);
// root[F("svalue")] = str;
break;
case SENSOR_TYPE_QUAD:
root[F("nvalue")] = 0;
values = formatUserVar(event, 0);
values += ";";
values += formatUserVar(event, 1);
values += ";";
values += formatUserVar(event, 2);
values += ";";
values += formatUserVar(event, 3);
root[F("svalue")] = values.c_str();
// values.toCharArray(str, 80);
// root[F("svalue")] = str;
break;
case SENSOR_TYPE_SWITCH:
root[F("command")] = String(F("switchlight"));
if (UserVar[event->BaseVarIndex] == 0)
@@ -247,22 +166,20 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
else
root[F("Set%20Level")] = UserVar[event->BaseVarIndex];
break;
case SENSOR_TYPE_WIND: // WindDir in degrees; WindDir as text; Wind speed average ; Wind speed gust
values = formatUserVar(event, 0);
values += ";";
values += getBearing(UserVar[event->BaseVarIndex]);
values += ";";
// Domoticz expects the wind speed in (m/s * 10)
values += toString((UserVar[event->BaseVarIndex + 1] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[1]);
values += ";";
values += toString((UserVar[event->BaseVarIndex + 2] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[2]);
values += ";0;0";
root[F("svalue")] = values.c_str();
// values.toCharArray(str, 80);
// root["svalue"] = str;
case SENSOR_TYPE_SINGLE:
case SENSOR_TYPE_LONG:
case SENSOR_TYPE_DUAL:
case SENSOR_TYPE_TRIPLE:
case SENSOR_TYPE_QUAD:
case SENSOR_TYPE_TEMP_HUM:
case SENSOR_TYPE_TEMP_BARO:
case SENSOR_TYPE_TEMP_HUM_BARO:
case SENSOR_TYPE_WIND:
default:
root[F("nvalue")] = 0;
root[F("svalue")] = formatDomoticzSensorType(event);
break;
}
String json;
@@ -272,8 +189,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
addLog(LOG_LEVEL_DEBUG, log);
String pubname = ControllerSettings.Publish;
parseSystemVariables(pubname, false);
parseEventVariables(pubname, event, false);
parseControllerVariables(pubname, event, false);
if (!MQTTpublish(event->ControllerIndex, pubname.c_str(), json.c_str(), Settings.MQTTRetainFlag))
{
connectionFailures++;
+18 -2
View File
@@ -16,7 +16,7 @@ boolean CPlugin_004(byte function, struct EventStruct *event, String& string)
{
Protocol[++protocolCount].Number = CPLUGIN_ID_004;
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesAccount = true;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 80;
Protocol[protocolCount].usesID = true;
@@ -29,6 +29,22 @@ boolean CPlugin_004(byte function, struct EventStruct *event, String& string)
break;
}
case CPLUGIN_GET_PROTOCOL_DISPLAY_NAME:
{
success = true;
switch (event->idx) {
case CONTROLLER_USER:
string = F("ThingHTTP Name");
break;
case CONTROLLER_PASS:
string = F("API Key");
break;
default:
success = false;
break;
}
}
case CPLUGIN_PROTOCOL_SEND:
{
ControllerSettingsStruct ControllerSettings;
@@ -94,7 +110,7 @@ boolean CPlugin_004(byte function, struct EventStruct *event, String& string)
addLog(LOG_LEVEL_DEBUG_MORE, log);
if (line.substring(0, 15) == F("HTTP/1.1 200 OK"))
{
strcpy_P(log, PSTR("HTTP : Success!"));
strcpy_P(log, PSTR("HTTP : Succes!"));
addLog(LOG_LEVEL_DEBUG, log);
success = true;
}
+39 -42
View File
@@ -39,51 +39,50 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
case CPLUGIN_PROTOCOL_RECV:
{
// Split topic into array
String tmpTopic = event->String1.substring(1);
String topicSplit[10];
int SlashIndex = tmpTopic.indexOf('/');
byte count = 0;
while (SlashIndex > 0 && count < 10 - 1)
{
topicSplit[count] = tmpTopic.substring(0, SlashIndex);
tmpTopic = tmpTopic.substring(SlashIndex + 1);
SlashIndex = tmpTopic.indexOf('/');
count++;
byte ControllerID = findFirstEnabledControllerWithId(CPLUGIN_ID_005);
if (ControllerID == CONTROLLER_MAX) {
// Controller is not enabled.
break;
} else {
String cmd;
struct EventStruct TempEvent;
bool validTopic = false;
const int lastindex = event->String1.lastIndexOf('/');
const String lastPartTopic = event->String1.substring(lastindex + 1);
if (lastPartTopic == F("cmd")) {
cmd = event->String2;
parseCommandString(&TempEvent, cmd);
TempEvent.Source = VALUE_SOURCE_MQTT;
validTopic = true;
} else {
if (lastindex > 0) {
// Topic has at least one separator
if (isFloat(event->String2) && isInt(lastPartTopic)) {
int prevLastindex = event->String1.lastIndexOf('/', lastindex - 1);
cmd = event->String1.substring(prevLastindex + 1, lastindex);
TempEvent.Par1 = lastPartTopic.toInt();
TempEvent.Par2 = event->String2.toFloat();
TempEvent.Par3 = 0;
validTopic = true;
}
}
}
if (validTopic) {
// in case of event, store to buffer and return...
String command = parseString(cmd, 1);
if (command == F("event")) {
eventBuffer = cmd.substring(6);
} else if (!PluginCall(PLUGIN_WRITE, &TempEvent, cmd)) {
remoteConfig(&TempEvent, cmd);
}
}
}
topicSplit[count] = tmpTopic;
String cmd = "";
struct EventStruct TempEvent;
if (topicSplit[count] == F("cmd"))
{
cmd = event->String2;
parseCommandString(&TempEvent, cmd);
TempEvent.Source = VALUE_SOURCE_MQTT;
}
else
{
cmd = topicSplit[count - 1];
TempEvent.Par1 = topicSplit[count].toInt();
TempEvent.Par2 = event->String2.toFloat();
TempEvent.Par3 = 0;
}
// in case of event, store to buffer and return...
String command = parseString(cmd, 1);
if (command == F("event"))
eventBuffer = cmd.substring(6);
else if
(PluginCall(PLUGIN_WRITE, &TempEvent, cmd));
else
remoteConfig(&TempEvent, cmd);
break;
}
case CPLUGIN_PROTOCOL_SEND:
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
success = false;
break;
}
@@ -96,8 +95,7 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
String pubname = ControllerSettings.Publish;
parseSystemVariables(pubname, false);
parseEventVariables(pubname, event, false);
parseControllerVariables(pubname, event, false);
String value = "";
// byte DeviceIndex = getDeviceIndex(Settings.TaskDeviceNumber[event->TaskIndex]);
@@ -110,7 +108,6 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
value = (unsigned long)UserVar[event->BaseVarIndex] + ((unsigned long)UserVar[event->BaseVarIndex + 1] << 16);
else
value = formatUserVar(event, x);
MQTTpublish(event->ControllerIndex, tmppubname.c_str(), value.c_str(), Settings.MQTTRetainFlag);
String log = F("MQTT : ");
log += tmppubname;
+2 -3
View File
@@ -76,7 +76,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
case CPLUGIN_PROTOCOL_SEND:
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
success = false;
break;
}
@@ -89,8 +89,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
String pubname = ControllerSettings.Publish;
parseSystemVariables(pubname, false);
parseEventVariables(pubname, event, false);
parseControllerVariables(pubname, event, false);
String value = "";
// byte DeviceIndex = getDeviceIndex(Settings.TaskDeviceNumber[event->TaskIndex]);
+15 -41
View File
@@ -31,10 +31,16 @@ boolean CPlugin_007(byte function, struct EventStruct *event, String& string)
case CPLUGIN_PROTOCOL_SEND:
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
success = false;
break;
}
const byte valueCount = getValueCountFromSensorType(event->sensorType);
if (valueCount == 0 || valueCount > 3) {
addLog(LOG_LEVEL_ERROR, F("emoncms : Unknown sensortype or too many sensor values"));
break;
}
ControllerSettingsStruct ControllerSettings;
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
@@ -59,46 +65,14 @@ boolean CPlugin_007(byte function, struct EventStruct *event, String& string)
postDataStr += Settings.Unit;
postDataStr += F("&json=");
switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
case SENSOR_TYPE_SWITCH: // report switch state
postDataStr += F("{field");
postDataStr += event->idx;
postDataStr += ":";
postDataStr += formatUserVar(event, 0);
postDataStr += "}";
break;
case SENSOR_TYPE_TEMP_HUM: // dual value
case SENSOR_TYPE_TEMP_BARO:
case SENSOR_TYPE_DUAL:
postDataStr += F("{field");
postDataStr += event->idx;
postDataStr += ":";
postDataStr += formatUserVar(event, 0);
postDataStr += F(",field");
postDataStr += event->idx + 1;
postDataStr += ":";
postDataStr += formatUserVar(event, 1);
postDataStr += "}";
break;
case SENSOR_TYPE_TEMP_HUM_BARO:
case SENSOR_TYPE_TRIPLE:
postDataStr += F("{field");
postDataStr += event->idx;
postDataStr += ":";
postDataStr += formatUserVar(event, 0);
postDataStr += F(",field");
postDataStr += event->idx + 1;
postDataStr += ":";
postDataStr += formatUserVar(event, 1);
postDataStr += F(",field");
postDataStr += event->idx + 2;
postDataStr += ":";
postDataStr += formatUserVar(event, 2);
postDataStr += "}";
break;
for (byte i = 0; i < valueCount; ++i) {
postDataStr += (i == 0) ? F("{") : F(",");
postDataStr += F("field");
postDataStr += event->idx + i;
postDataStr += ":";
postDataStr += formatUserVar(event, i);
}
postDataStr += "}";
postDataStr += F("&apikey=");
postDataStr += SecuritySettings.ControllerPassword[event->ControllerIndex]; // "0UDNN17RW6XAS2E5" // api key
@@ -131,7 +105,7 @@ boolean CPlugin_007(byte function, struct EventStruct *event, String& string)
addLog(LOG_LEVEL_DEBUG_MORE, log);
if (line.substring(0, 15) == F("HTTP/1.1 200 OK"))
{
strcpy_P(log, PSTR("HTTP : Success!"));
strcpy_P(log, PSTR("HTTP : Succes!"));
addLog(LOG_LEVEL_DEBUG, log);
success = true;
}
+4 -5
View File
@@ -21,7 +21,7 @@ boolean CPlugin_008(byte function, struct EventStruct *event, String& string)
Protocol[protocolCount].usesAccount = true;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 80;
Protocol[protocolCount].usesID = true;
Protocol[protocolCount].usesID = false;
break;
}
@@ -68,7 +68,7 @@ boolean CPlugin_008(byte function, struct EventStruct *event, String& string)
//********************************************************************************
boolean HTTPSend(struct EventStruct *event, byte varIndex, float value, unsigned long longValue)
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
return false;
}
ControllerSettingsStruct ControllerSettings;
@@ -105,8 +105,7 @@ boolean HTTPSend(struct EventStruct *event, byte varIndex, float value, unsigned
String url = "/";
url += ControllerSettings.Publish;
parseSystemVariables(url, true);
parseEventVariables(url, event, true);
parseControllerVariables(url, event, true);
url.replace(F("%valname%"), URLEncode(ExtraTaskSettings.TaskDeviceValueNames[varIndex]));
if (longValue)
@@ -136,7 +135,7 @@ boolean HTTPSend(struct EventStruct *event, byte varIndex, float value, unsigned
addLog(LOG_LEVEL_DEBUG_MORE, line);
if (line.startsWith(F("HTTP/1.1 200 OK")))
{
// strcpy_P(log, PSTR("HTTP : Success!"));
// strcpy_P(log, PSTR("HTTP : Succes!"));
// addLog(LOG_LEVEL_DEBUG, log);
addLog(LOG_LEVEL_DEBUG, F("HTTP : Success!"));
// success = true;
+2 -2
View File
@@ -20,7 +20,7 @@
- moved on/off translation for SENSOR_TYPE_SWITCH/DIMMER to FHEM module
- v1.03
- changed http request from GET to POST (RFC conform)
- removed obsolete http get url code
- removed obsolet http get url code
- v1.04
- added build options and node_type_id to JSON/device
/******************************************************************************/
@@ -56,7 +56,7 @@ boolean CPlugin_009(byte function, struct EventStruct *event, String& string)
case CPLUGIN_PROTOCOL_SEND:
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
success = false;
break;
}
+1 -5
View File
@@ -80,11 +80,7 @@ void C010_Send(struct EventStruct *event, byte varIndex, float value, unsigned l
String msg = "";
msg += ControllerSettings.Publish;
parseSystemVariables(msg, false);
parseEventVariables(msg, event, false);
msg.replace(F("%sysname%"), Settings.Name);
msg.replace(F("%tskname%"), ExtraTaskSettings.TaskDeviceName);
msg.replace(F("%id%"), String(event->idx));
parseControllerVariables(msg, event, false);
msg.replace(F("%valname%"), ExtraTaskSettings.TaskDeviceValueNames[varIndex]);
if (longValue)
msg.replace(F("%value%"), String(longValue));
+4 -35
View File
@@ -120,7 +120,7 @@ boolean CPlugin_011(byte function, struct EventStruct *event, String& string)
//********************************************************************************
boolean HTTPSend011(struct EventStruct *event)
{
if (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(100)) {
return false;
}
ControllerSettingsStruct ControllerSettings;
@@ -270,44 +270,13 @@ void ReplaceTokenByValue(String& s, struct EventStruct *event)
// %1%%vname1%,Standort=%tskname% Wert=%val1%%/1%%2%%LF%%vname2%,Standort=%tskname% Wert=%val2%%/2%%3%%LF%%vname3%,Standort=%tskname% Wert=%val3%%/3%%4%%LF%%vname4%,Standort=%tskname% Wert=%val4%%/4%
addLog(LOG_LEVEL_DEBUG_MORE, F("HTTP before parsing: "));
addLog(LOG_LEVEL_DEBUG_MORE, s);
switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE:
case SENSOR_TYPE_SWITCH:
case SENSOR_TYPE_DIMMER:
case SENSOR_TYPE_WIND:
case SENSOR_TYPE_LONG:
{
DeleteNotNeededValues(s,1);
break;
}
case SENSOR_TYPE_DUAL:
case SENSOR_TYPE_TEMP_HUM:
case SENSOR_TYPE_TEMP_BARO:
{
DeleteNotNeededValues(s,2);
break;
}
case SENSOR_TYPE_TRIPLE:
case SENSOR_TYPE_TEMP_HUM_BARO:
{
DeleteNotNeededValues(s,3);
break;
}
case SENSOR_TYPE_QUAD:
{
DeleteNotNeededValues(s,4);
break;
}
}
const byte valueCount = getValueCountFromSensorType(event->sensorType);
DeleteNotNeededValues(s,valueCount);
addLog(LOG_LEVEL_DEBUG_MORE, F("HTTP after parsing: "));
addLog(LOG_LEVEL_DEBUG_MORE, s);
//NOTE: cant we just call parseTemplate() for all the standard stuff??
parseSystemVariables(s, true);
parseEventVariables(s, event, true);
parseControllerVariables(s, event, true);
addLog(LOG_LEVEL_DEBUG_MORE, F("HTTP after replacements: "));
addLog(LOG_LEVEL_DEBUG_MORE, s);
+149
View File
@@ -0,0 +1,149 @@
//#######################################################################################################
//########################### Controller Plugin 012: Blynk #############################################
//#######################################################################################################
#ifdef PLUGIN_BUILD_TESTING
#define CPLUGIN_012
#define CPLUGIN_ID_012 12
#define CPLUGIN_NAME_012 "Blynk HTTP [TESTING]"
boolean CPlugin_012(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case CPLUGIN_PROTOCOL_ADD:
{
Protocol[++protocolCount].Number = CPLUGIN_ID_012;
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 80;
Protocol[protocolCount].usesID = true;
break;
}
case CPLUGIN_GET_DEVICENAME:
{
string = F(CPLUGIN_NAME_012);
break;
}
case CPLUGIN_PROTOCOL_SEND:
{
if (WiFi.status() != WL_CONNECTED) {
success = false;
break;
}
String postDataStr = F("");
const byte valueCount = getValueCountFromSensorType(event->sensorType);
success = CPlugin_012_send(event, valueCount);
break;
}
}
return success;
}
boolean CPlugin_012_send(struct EventStruct *event, int nrValues) {
String postDataStr = F("");
boolean success = true;
for (int i = 0; i < nrValues && success; ++i) {
postDataStr = F("update/V") ;
postDataStr += event->idx + i;
postDataStr += F("?value=");
postDataStr += formatUserVar(event, i);
success = Blynk_get(postDataStr, event->ControllerIndex);
}
return success;
}
boolean Blynk_get(const String& command, byte controllerIndex, float *data )
{
if (WiFi.status() != WL_CONNECTED) {
return false;
}
ControllerSettingsStruct ControllerSettings;
LoadControllerSettings(controllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
// Use WiFiClient class to create TCP connections
WiFiClient client;
if ((SecuritySettings.ControllerPassword[controllerIndex][0] == 0) || !ControllerSettings.connectToHost(client))
{
connectionFailures++;
addLog(LOG_LEVEL_ERROR, F("Blynk : connection failed"));
return false;
}
if (connectionFailures)
connectionFailures--;
// We now create a URI for the request
char request[300] = {0};
sprintf_P(request,
PSTR("GET /%s/%s HTTP/1.1\r\n Host: %s \r\n Connection: close\r\n\r\n"),
SecuritySettings.ControllerPassword[controllerIndex],
command.c_str(),
ControllerSettings.getHost().c_str());
addLog(LOG_LEVEL_DEBUG, request);
client.print(request);
unsigned long timer = millis() + 200;
while (!client.available() && !timeOutReached(timer))
yield();
boolean success = false;
char log[80] = {0};
// Read all the lines of the reply from server and log them
while (client.available()) {
String line;
safeReadStringUntil(client, line, '\n');
addLog(LOG_LEVEL_DEBUG_MORE, line);
// success ?
if (line.substring(0, 15) == "HTTP/1.1 200 OK") {
strcpy_P(log, PSTR("HTTP : Success"));
success = true;
}
else if (line.substring(0, 24) == "HTTP/1.1 400 Bad Request") {
strcpy_P(log, PSTR("HTTP : Unauthorized"));
}
else if (line.substring(0, 25) == "HTTP/1.1 401 Unauthorized") {
strcpy_P(log, PSTR("HTTP : Unauthorized"));
}
addLog(LOG_LEVEL_DEBUG, log);
// data only
if (data && line.startsWith("["))
{
String strValue = line;
byte pos = strValue.indexOf('"',2);
strValue = strValue.substring(2, pos);
strValue.trim();
float value = strValue.toFloat();
*data = value;
success = true;
char value_char[5] = {0};
strValue.toCharArray(value_char, 5);
sprintf_P(log, PSTR("Blynk get - %s => %s"),command.c_str(), value_char );
addLog(LOG_LEVEL_DEBUG, log);
}
yield();
}
strcpy_P(log, PSTR("HTTP : closing connection"));
addLog(LOG_LEVEL_DEBUG, log);
client.flush();
client.stop();
// important - backgroudtasks - free mem
timer = millis() + Settings.MessageDelay;
while (!timeOutReached(timer))
backgroundtasks();
return success;
}
#endif
+265
View File
@@ -0,0 +1,265 @@
//#######################################################################################################
//########################### Controller Plugin 013: ESPEasy P2P network ################################
//#######################################################################################################
#define CPLUGIN_013
#define CPLUGIN_ID_013 13
#define CPLUGIN_NAME_013 "ESPEasy P2P Networking"
WiFiUDP C013_portUDP;
struct infoStruct
{
byte header = 255;
byte ID = 3;
byte sourcelUnit;
byte destUnit;
byte sourceTaskIndex;
byte destTaskIndex;
byte deviceNumber;
char taskName[26];
char ValueNames[VARS_PER_TASK][26];
};
struct dataStruct
{
byte header = 255;
byte ID = 5;
byte sourcelUnit;
byte destUnit;
byte sourceTaskIndex;
byte destTaskIndex;
float Values[VARS_PER_TASK];
};
boolean CPlugin_013(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case CPLUGIN_PROTOCOL_ADD:
{
Protocol[++protocolCount].Number = CPLUGIN_ID_013;
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesTemplate = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = false;
Protocol[protocolCount].defaultPort = 65501;
Protocol[protocolCount].usesID = false;
Protocol[protocolCount].Custom = true;
break;
}
case CPLUGIN_GET_DEVICENAME:
{
string = F(CPLUGIN_NAME_013);
break;
}
case CPLUGIN_PROTOCOL_TEMPLATE:
{
event->String1 = "";
event->String2 = "";
break;
}
case CPLUGIN_INIT:
{
//C013_portUDP.begin(Settings.UDPPort);
break;
}
case CPLUGIN_TASK_CHANGE_NOTIFICATION:
{
C013_SendUDPTaskInfo(0, event->TaskIndex, event->TaskIndex);
break;
}
case CPLUGIN_PROTOCOL_SEND:
{
C013_Send(event, 0, UserVar[event->BaseVarIndex], 0);
break;
}
case CPLUGIN_UDP_IN:
{
C013_Receive(event);
break;
}
}
return success;
}
//********************************************************************************
// Generic UDP message
//********************************************************************************
void C013_Send(struct EventStruct *event, byte varIndex, float value, unsigned long longValue)
{
ControllerSettingsStruct ControllerSettings;
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
statusLED(true);
C013_SendUDPTaskData(0, event->TaskIndex, event->TaskIndex);
}
void C013_SendUDPTaskInfo(byte destUnit, byte sourceTaskIndex, byte destTaskIndex)
{
if (!WiFiConnected(100)) {
return;
}
struct infoStruct infoReply;
infoReply.sourcelUnit = Settings.Unit;
infoReply.sourceTaskIndex = sourceTaskIndex;
infoReply.destTaskIndex = destTaskIndex;
LoadTaskSettings(infoReply.sourceTaskIndex);
infoReply.deviceNumber = Settings.TaskDeviceNumber[infoReply.sourceTaskIndex];
strcpy(infoReply.taskName, ExtraTaskSettings.TaskDeviceName);
for (byte x = 0; x < VARS_PER_TASK; x++)
strcpy(infoReply.ValueNames[x], ExtraTaskSettings.TaskDeviceValueNames[x]);
byte firstUnit = 1;
byte lastUnit = UNIT_MAX - 1;
if (destUnit != 0)
{
firstUnit = destUnit;
lastUnit = destUnit;
}
for (byte x = firstUnit; x <= lastUnit; x++)
{
if (x != Settings.Unit){
infoReply.destUnit = x;
C013_sendUDP(x, (byte*)&infoReply, sizeof(infoStruct));
delay(10);
}
}
delay(50);
}
void C013_SendUDPTaskData(byte destUnit, byte sourceTaskIndex, byte destTaskIndex)
{
if (!WiFiConnected(100)) {
return;
}
struct dataStruct dataReply;
dataReply.sourcelUnit = Settings.Unit;
dataReply.sourceTaskIndex = sourceTaskIndex;
dataReply.destTaskIndex = destTaskIndex;
for (byte x = 0; x < VARS_PER_TASK; x++)
dataReply.Values[x] = UserVar[dataReply.sourceTaskIndex * VARS_PER_TASK + x];
byte firstUnit = 1;
byte lastUnit = UNIT_MAX - 1;
if (destUnit != 0)
{
firstUnit = destUnit;
lastUnit = destUnit;
}
for (byte x = firstUnit; x <= lastUnit; x++)
{
if (x != Settings.Unit){
dataReply.destUnit = x;
C013_sendUDP(x, (byte*) &dataReply, sizeof(dataStruct));
delay(10);
}
}
delay(50);
}
/*********************************************************************************************\
Send UDP message (unit 255=broadcast)
\*********************************************************************************************/
void C013_sendUDP(byte unit, byte* data, byte size)
{
if (!WiFiConnected(100)) {
return;
}
if (unit != 255)
if (Nodes[unit].ip[0] == 0)
return;
String log = "C013 : Send UDP message to ";
log += unit;
addLog(LOG_LEVEL_DEBUG_MORE, log);
statusLED(true);
IPAddress remoteNodeIP;
if (unit == 255)
remoteNodeIP = {255, 255, 255, 255};
else
remoteNodeIP = Nodes[unit].ip;
C013_portUDP.beginPacket(remoteNodeIP, Settings.UDPPort);
C013_portUDP.write(data, size);
C013_portUDP.endPacket();
}
void C013_Receive(struct EventStruct *event) {
if (event->Data[1] > 1 && event->Data[1] < 6)
{
String log = (F("C013 : msg "));
for (byte x = 1; x < 6; x++)
{
log += " ";
log += (int)event->Data[x];
}
addLog(LOG_LEVEL_DEBUG_MORE, log);
}
switch (event->Data[1]) {
case 2: // sensor info pull request
{
//SendUDPTaskInfo(packetBuffer[2], packetBuffer[5], packetBuffer[4]);
break;
}
case 3: // sensor info
{
struct infoStruct infoReply;
memcpy((byte*)&infoReply, (byte*)event->Data, sizeof(infoStruct));
// to prevent flash wear out (bugs in communication?) we can only write to an empty task
// so it will write only once and has to be cleared manually through webgui
if (Settings.TaskDeviceNumber[infoReply.destTaskIndex] == 0)
{
Settings.TaskDeviceNumber[infoReply.destTaskIndex] = infoReply.deviceNumber;
Settings.TaskDeviceDataFeed[infoReply.destTaskIndex] = 1; // remote feed
for (byte x = 0; x < CONTROLLER_MAX; x++)
Settings.TaskDeviceSendData[x][infoReply.destTaskIndex] = false;
strcpy(ExtraTaskSettings.TaskDeviceName, infoReply.taskName);
for (byte x = 0; x < VARS_PER_TASK; x++)
strcpy( ExtraTaskSettings.TaskDeviceValueNames[x], infoReply.ValueNames[x]);
SaveTaskSettings(infoReply.destTaskIndex);
SaveSettings();
}
break;
}
case 4: // sensor data pull request
{
//SendUDPTaskData(packetBuffer[2], packetBuffer[5], packetBuffer[4]);
break;
}
case 5: // sensor data
{
struct dataStruct dataReply;
memcpy((byte*)&dataReply, (byte*)event->Data, sizeof(dataStruct));
// only if this task has a remote feed, update values
if (Settings.TaskDeviceDataFeed[dataReply.destTaskIndex] != 0)
{
for (byte x = 0; x < VARS_PER_TASK; x++)
{
UserVar[dataReply.destTaskIndex * VARS_PER_TASK + x] = dataReply.Values[x];
}
if (Settings.UseRules)
createRuleEvents(dataReply.destTaskIndex);
}
break;
}
}
}
+140
View File
@@ -0,0 +1,140 @@
// HUM_STAT can be one of:
// 0=Normal
// 1=Comfortable
// 2=Dry
// 3=Wet
String humStatDomoticz(struct EventStruct *event, byte rel_index){
const int hum = UserVar[event->BaseVarIndex + rel_index];
if (hum < 30) { return formatUserVarDomoticz(2); }
if (hum < 40) { return formatUserVarDomoticz(0); }
if (hum < 59) { return formatUserVarDomoticz(1); }
return formatUserVarDomoticz(3);
}
int mapRSSItoDomoticz() {
long rssi = WiFi.RSSI();
if (-50 < rssi) { return 10; }
if (rssi <= -98) { return 0; }
rssi = rssi + 97; // Range 0..47 => 1..9
return (rssi / 5) + 1;
}
int mapVccToDomoticz() {
#if FEATURE_ADC_VCC
// Voltage range from 2.6V .. 3.6V => 0..100%
if (vcc < 2.6) return 0;
return (vcc - 2.6) * 100;
#else
return 255;
#endif
}
// Format including trailing semi colon
String formatUserVarDomoticz(struct EventStruct *event, byte rel_index) {
String text = formatUserVar(event, rel_index);
text += F(";");
return text;
}
String formatUserVarDomoticz(int value) {
String text;
text += value;
text.trim();
text += F(";");
return text;
}
String formatDomoticzSensorType(struct EventStruct *event) {
String values;
switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
values = formatUserVarDomoticz(event, 0);
break;
case SENSOR_TYPE_LONG: // single LONG value, stored in two floats (rfid tags)
values = (unsigned long)UserVar[event->BaseVarIndex] + ((unsigned long)UserVar[event->BaseVarIndex + 1] << 16);
break;
case SENSOR_TYPE_DUAL: // any sensor that uses two simple values
values = formatUserVarDomoticz(event, 0);
values += formatUserVarDomoticz(event, 1);
break;
case SENSOR_TYPE_TEMP_HUM:
// temp + hum + hum_stat, used for DHT11
// http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Temperature.2Fhumidity
values = formatUserVarDomoticz(event, 0); // TEMP = Temperature
values += formatUserVarDomoticz(event, 1); // HUM = Humidity
values += humStatDomoticz(event, 1); // HUM_STAT = Humidity status
break;
case SENSOR_TYPE_TEMP_HUM_BARO:
// temp + hum + hum_stat + bar + bar_fore, used for BME280
// http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Temperature.2Fhumidity.2Fbarometer
values = formatUserVarDomoticz(event, 0); // TEMP = Temperature
values += formatUserVarDomoticz(event, 1); // HUM = Humidity
values += humStatDomoticz(event, 1); // HUM_STAT = Humidity status
values += formatUserVarDomoticz(event, 2); // BAR = Barometric pressure
values += formatUserVarDomoticz(0); // BAR_FOR = Barometer forecast
break;
case SENSOR_TYPE_TEMP_BARO:
// temp + hum + hum_stat + bar + bar_fore, used for BMP085
// http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Temperature.2Fbarometer
values = formatUserVarDomoticz(event, 0); // TEMP = Temperature
values += formatUserVarDomoticz(event, 1); // BAR = Barometric pressure
values += formatUserVarDomoticz(0); // BAR_FOR = Barometer forecast
values += formatUserVarDomoticz(0); // ALTITUDE= Not used at the moment, can be 0
break;
case SENSOR_TYPE_TRIPLE:
values = formatUserVarDomoticz(event, 0);
values += formatUserVarDomoticz(event, 1);
values += formatUserVarDomoticz(event, 2);
break;
case SENSOR_TYPE_QUAD:
values = formatUserVarDomoticz(event, 0);
values += formatUserVarDomoticz(event, 1);
values += formatUserVarDomoticz(event, 2);
values += formatUserVarDomoticz(event, 3);
break;
case SENSOR_TYPE_WIND:
// WindDir in degrees; WindDir as text; Wind speed average ; Wind speed gust; 0
// http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Wind
values = formatUserVarDomoticz(event, 0); // WB = Wind bearing (0-359)
values += getBearing(UserVar[event->BaseVarIndex]); // WD = Wind direction (S, SW, NNW, etc.)
values += ";"; // Needed after getBearing
// Domoticz expects the wind speed in (m/s * 10)
values += toString((UserVar[event->BaseVarIndex + 1] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[1]);
values += ";"; // WS = 10 * Wind speed [m/s]
values += toString((UserVar[event->BaseVarIndex + 2] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[2]);
values += ";"; // WG = 10 * Gust [m/s]
values += formatUserVarDomoticz(0); // Temperature
values += formatUserVarDomoticz(0); // Temperature Windchill
break;
case SENSOR_TYPE_SWITCH:
case SENSOR_TYPE_DIMMER:
// Too specific for HTTP/MQTT
break;
default:
{
String log = F("Domoticz Controller: Not yet implemented sensor type: ");
log += event->sensorType;
log += F(" idx: ");
log += event->idx;
addLog(LOG_LEVEL_ERROR, log);
break;
}
}
// Now strip trailing semi colon.
int index_last_char = values.length() -1;
if (index_last_char > 0 && values.charAt(index_last_char) == ';') {
values.setCharAt(index_last_char, ' ');
}
values.trim();
{
String log = F(" Domoticz: Sensortype: ");
log += event->sensorType;
log += F(" idx: ");
log += event->idx;
log += F(" values: ");
log += values;
addLog(LOG_LEVEL_INFO, log);
}
return values;
}
+28
View File
@@ -0,0 +1,28 @@
/*********************************************************************************************\
Get value count from sensor type
\*********************************************************************************************/
byte getValueCountFromSensorType(byte sensorType)
{
switch (sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
case SENSOR_TYPE_SWITCH:
case SENSOR_TYPE_DIMMER:
return 1;
case SENSOR_TYPE_LONG: // single LONG value, stored in two floats (rfid tags)
return 1;
case SENSOR_TYPE_TEMP_HUM:
case SENSOR_TYPE_TEMP_BARO:
case SENSOR_TYPE_DUAL:
return 2;
case SENSOR_TYPE_TEMP_HUM_BARO:
case SENSOR_TYPE_TRIPLE:
case SENSOR_TYPE_WIND:
return 3;
case SENSOR_TYPE_QUAD:
return 4;
}
addLog(LOG_LEVEL_ERROR, F("getValueCountFromSensorType: Unknown sensortype"));
return 0;
}
+54 -25
View File
@@ -6,7 +6,7 @@
#define NPLUGIN_ID_001 1
#define NPLUGIN_NAME_001 "Email (SMTP)"
#define NPLUGIN_001_TIMEOUT 3000
#define NPLUGIN_001_TIMEOUT 5000
boolean NPlugin_001(byte function, struct EventStruct *event, String& string)
{
@@ -56,7 +56,7 @@ boolean NPlugin_001(byte function, struct EventStruct *event, String& string)
body = NotificationSettings.Body;
subject = parseTemplate(subject, subject.length());
body = parseTemplate(body, body.length());
NPlugin_001_send(NotificationSettings.Domain, NotificationSettings.Receiver, NotificationSettings.Sender, subject, body, NotificationSettings.Server, NotificationSettings.Port);
NPlugin_001_send(NotificationSettings, subject, body);
success = true;
}
@@ -64,29 +64,46 @@ boolean NPlugin_001(byte function, struct EventStruct *event, String& string)
return success;
}
boolean NPlugin_001_send(String aDomain , String aTo, String aFrom, String aSub, String aMesg, String aHost, int aPort)
{
boolean NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, const String& aSub, const String& aMesg) {
// String& aDomain , String aTo, String aFrom, String aSub, String aMesg, String aHost, int aPort)
boolean myStatus = false;
// Use WiFiClient class to create TCP connections
WiFiClient client;
addLog(LOG_LEVEL_DEBUG, String(F("EMAIL: Connecting to "))+aHost);
if (!client.connect(aHost.c_str(), aPort)) {
addLog(LOG_LEVEL_ERROR, String(F("EMAIL: Error connecting to "))+aHost);
String aHost = notificationsettings.Server;
addLog(LOG_LEVEL_DEBUG, String(F("EMAIL: Connecting to "))+aHost + notificationsettings.Port);
if (!client.connect(aHost.c_str(), notificationsettings.Port)) {
addLog(LOG_LEVEL_ERROR, String(F("EMAIL: Error connecting to "))+aHost + notificationsettings.Port);
myStatus = false;
}
else {
String mailheader = F(
"From: $nodename <$emailfrom>\r\n"
"To: $ato\r\n"
"Subject: $subject\r\n"
"Reply-To: $nodename <$emailfrom>\r\n"
"MIME-VERSION: 1.0\r\n"
"Content-type: text/html; charset=UTF-8\r\n"
"X-Mailer: EspEasy v$espeasyversion\r\n\r\n"
);
mailheader.replace(String(F("$nodename")), Settings.Name);
mailheader.replace(String(F("$emailfrom")), notificationsettings.Sender);
mailheader.replace(String(F("$ato")), notificationsettings.Receiver);
mailheader.replace(String(F("$subject")), aSub);
mailheader.replace(String(F("$espeasyversion")), String(BUILD));
// Wait for Client to Start Sending
// The MTA Exchange
while (true) {
if (NPlugin_001_MTA(client, "", F("220 ")) == false) break;
if (NPlugin_001_MTA(client, String(F("EHLO ")) + aDomain, F("250 ")) == false) break;
if (NPlugin_001_MTA(client, String(F("MAIL FROM:")) + aFrom + "", F("250 ")) == false) break;
if (NPlugin_001_MTA(client, String(F("RCPT TO:")) + aTo + "", F("250 ")) == false) break;
if (NPlugin_001_MTA(client, F("DATA"), F("354 ")) == false) break;
if (NPlugin_001_MTA(client, String(F("Subject:")) + aSub + F("\r\n\r\n") + aMesg + F("\r\n.\r\n"), F("250 ")) == false) break;
if (!NPlugin_001_MTA(client, "", F("220 "))) break;
if (!NPlugin_001_MTA(client, String(F("EHLO ")) + notificationsettings.Domain, F("250 "))) break;
if (!NPlugin_001_Auth(client, notificationsettings.User, notificationsettings.Pass)) break;
if (!NPlugin_001_MTA(client, String(F("MAIL FROM:")) + notificationsettings.Sender + "", F("250 "))) break;
if (!NPlugin_001_MTA(client, String(F("RCPT TO:")) + notificationsettings.Receiver + "", F("250 "))) break;
if (!NPlugin_001_MTA(client, F("DATA"), F("354 "))) break;
if (!NPlugin_001_MTA(client, mailheader + aMesg + String(F("\r\n.\r\n")), F("250 "))) break;
myStatus = true;
break;
@@ -100,21 +117,32 @@ boolean NPlugin_001_send(String aDomain , String aTo, String aFrom, String aSub,
addLog(LOG_LEVEL_INFO, F("EMAIL: Connection Closed Successfully"));
}
else {
addLog(LOG_LEVEL_ERROR, F("EMAIL: Connection Closed With Error"));
String log = F("EMAIL: Connection Closed With Error. Used header: ");
log += mailheader;
addLog(LOG_LEVEL_ERROR, log);
}
}
return myStatus;
}
boolean NPlugin_001_Auth(WiFiClient& client, String user, String pass) {
if (user.length() == 0 || pass.length() == 0) {
// No user/password given.
return true;
}
if (!NPlugin_001_MTA(client, String(F("AUTH LOGIN")), F("334 "))) return false;
base64 encoder;
String auth;
auth = encoder.encode(user);
if (!NPlugin_001_MTA(client, auth, F("334 "))) return false;
auth = encoder.encode(pass);
if (!NPlugin_001_MTA(client, auth, F("235 "))) return false;
return true;
}
boolean NPlugin_001_MTA(WiFiClient& client, String aStr, const String &aWaitForPattern)
{
boolean myStatus = false;
addLog(LOG_LEVEL_DEBUG, aStr);
if (aStr.length() ) client.println(aStr);
@@ -125,8 +153,10 @@ boolean NPlugin_001_MTA(WiFiClient& client, String aStr, const String &aWaitForP
unsigned long timer = millis() + NPLUGIN_001_TIMEOUT;
while (true) {
if (timeOutReached(timer)) {
myStatus = false;
break;
String log = F("Plugin_001_MTA: timeout. ");
log += aStr;
addLog(LOG_LEVEL_ERROR, log);
return false;
}
yield();
@@ -138,10 +168,9 @@ boolean NPlugin_001_MTA(WiFiClient& client, String aStr, const String &aWaitForP
addLog(LOG_LEVEL_DEBUG, line);
if (line.indexOf(aWaitForPattern) >= 0) {
myStatus = true;
break;
return true;
}
}
return myStatus;
return false;
}
+1 -1
View File
@@ -45,7 +45,7 @@ boolean NPlugin_002(byte function, struct EventStruct *event, String& string)
{
NotificationSettingsStruct NotificationSettings;
LoadNotificationSettings(event->NotificationIndex, (byte*)&NotificationSettings, sizeof(NotificationSettings));
//this reserves IRAM and uninitialized RAM
//this reserves IRAM and uninitalized RAM
tone(NotificationSettings.Pin1, 500, 500);
success = true;
}
+40 -70
View File
@@ -6,14 +6,12 @@
#define PLUGIN_ID_001 1
#define PLUGIN_NAME_001 "Switch input - Switch"
#define PLUGIN_VALUENAME1_001 "Switch"
#if defined(ESP8266)
Servo servo1;
Servo servo2;
#endif
Servo servo1;
Servo servo2;
// Make sure the initial default is a switch (value 0)
#define PLUGIN_001_TYPE_SWITCH 0
#define PLUGIN_001_TYPE_DIMMER 1
#define PLUGIN_001_TYPE_DIMMER 3 // Due to some changes in previous versions, do not use 2.
#define PLUGIN_001_BUTTON_TYPE_NORMAL_SWITCH 0
#define PLUGIN_001_BUTTON_TYPE_PUSH_ACTIVE_LOW 1
#define PLUGIN_001_BUTTON_TYPE_PUSH_ACTIVE_HIGH 2
@@ -61,23 +59,21 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_LOAD:
{
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
if (choice != PLUGIN_001_TYPE_SWITCH && choice != PLUGIN_001_TYPE_DIMMER)
choice = PLUGIN_001_TYPE_SWITCH;
String options[2];
options[0] = F("Switch");
options[1] = F("Dimmer");
int optionValues[2] = { PLUGIN_001_TYPE_SWITCH, PLUGIN_001_TYPE_DIMMER };
addFormSelector(string, F("Switch Type"), F("plugin_001_type"), 2, options, optionValues, choice);
const byte switchtype = P001_getSwitchType(event);
addFormSelector(string, F("Switch Type"), F("plugin_001_type"), 2, options, optionValues, switchtype);
if (Settings.TaskDevicePluginConfig[event->TaskIndex][0] == PLUGIN_001_TYPE_DIMMER)
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;
}
choice = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
String buttonOptions[3];
buttonOptions[0] = F("Normal Switch");
buttonOptions[1] = F("Push Button Active Low");
@@ -162,7 +158,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
byte output_value = sendState ? 1 : 0;
event->sensorType = SENSOR_TYPE_SWITCH;
if (Settings.TaskDevicePluginConfig[event->TaskIndex][0] == PLUGIN_001_TYPE_DIMMER) {
if (P001_getSwitchType(event) == PLUGIN_001_TYPE_DIMMER) {
if (sendState) {
output_value = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
// Only set type to being dimmer when setting a value else it is "switched off".
@@ -201,7 +197,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (command == F("gpio"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= PIN_D_MAX)
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
@@ -215,11 +211,10 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (command == F("pwm"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= PIN_D_MAX)
if (event->Par1 >= 0 && event->Par1 <= 16)
{
#if defined(ESP8266)
pinMode(event->Par1, OUTPUT);
#endif
pinMode(event->Par1, OUTPUT);
if(event->Par3 != 0)
{
byte prev_mode;
@@ -236,22 +231,12 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
curr_value += step_value;
int16_t new_value;
new_value = (uint16_t)(curr_value >> 12);
#if defined(ESP8266)
analogWrite(event->Par1, new_value);
#endif
#if defined(ESP32)
analogWriteESP32(event->Par1, new_value);
#endif
analogWrite(event->Par1, new_value);
delay(1);
}
}
#if defined(ESP8266)
analogWrite(event->Par1, event->Par2);
#endif
#if defined(ESP32)
analogWriteESP32(event->Par1, event->Par2);
#endif
analogWrite(event->Par1, event->Par2);
setPinState(PLUGIN_ID_001, event->Par1, PIN_MODE_PWM, event->Par2);
log = String(F("SW : GPIO ")) + String(event->Par1) + String(F(" Set PWM to ")) + String(event->Par2);
addLog(LOG_LEVEL_INFO, log);
@@ -262,7 +247,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (command == F("pulse"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= PIN_D_MAX)
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
@@ -279,7 +264,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
{
boolean time_in_msec = command == F("longpulse_ms");
success = true;
if (event->Par1 >= 0 && event->Par1 <= PIN_D_MAX)
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
@@ -302,16 +287,12 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
case 1:
//IRAM: doing servo stuff uses 740 bytes IRAM. (doesnt matter how many instances)
#if defined(ESP8266)
servo1.attach(event->Par2);
servo1.write(event->Par3);
#endif
servo1.attach(event->Par2);
servo1.write(event->Par3);
break;
case 2:
#if defined(ESP8266)
servo2.attach(event->Par2);
servo2.write(event->Par3);
#endif
servo2.attach(event->Par2);
servo2.write(event->Par3);
break;
}
setPinState(PLUGIN_ID_001, event->Par2, PIN_MODE_SERVO, event->Par3);
@@ -336,7 +317,6 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
outputstate[event->Par1] = event->Par2;
}
// 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"))
@@ -345,11 +325,10 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
// char sng[1024] ="";
String tmpString=string;
tmpString.replace("-","#");
// tmpString.toCharArray(sng, 1024);
play_rtttl(event->Par1, tmpString.c_str());
char sng[1024] ="";
string.replace("-","#");
string.toCharArray(sng, 1024);
play_rtttl(event->Par1, sng);
setPinState(PLUGIN_ID_001, event->Par1, PIN_MODE_OUTPUT, event->Par2);
log = String(F("SW : ")) + string;
addLog(LOG_LEVEL_INFO, log);
@@ -361,7 +340,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (command == F("tone"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= PIN_D_MAX)
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
tone(event->Par1, event->Par2, event->Par3);
@@ -386,28 +365,19 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
return success;
}
#if defined(ESP32)
void analogWriteESP32(int pin, int value)
{
// find existing channel if this pin has been used before
int8_t ledChannel = -1;
for(byte x = 0; x < 16; x++)
if (ledChannelPin[x] == pin)
ledChannel = x;
if(ledChannel == -1) // no channel set for this pin
{
for(byte x = 0; x < 16; x++) // find free channel
if (ledChannelPin[x] == -1)
{
int freq = 5000;
ledChannelPin[x] = pin; // store pin nr
ledcSetup(x, freq, 10); // setup channel
ledcAttachPin(pin, x); // attach to this pin
ledChannel = x;
break;
}
}
ledcWrite(ledChannel, value);
// TD-er: Needed to fix a mistake in earlier fixes.
byte P001_getSwitchType(struct EventStruct *event) {
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
switch (choice) {
case 2: // Old implementation for Dimmer
case PLUGIN_001_TYPE_DIMMER:
choice = PLUGIN_001_TYPE_DIMMER;
break;
case 1: // Old implementation for switch
case PLUGIN_001_TYPE_SWITCH:
default:
choice = PLUGIN_001_TYPE_SWITCH;
break;
}
return choice;
}
#endif
+2 -17
View File
@@ -47,11 +47,6 @@ 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]);
#endif
addFormCheckBox(string, F("Oversampling"), F("plugin_002_oversampling"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
addFormSubHeader(string, F("Two Point Calibration"));
@@ -90,12 +85,7 @@ boolean Plugin_002(byte function, struct EventStruct *event, String& string)
{
if (Settings.TaskDevicePluginConfig[event->TaskIndex][0]) //Oversampling?
{
#if defined(ESP8266)
Plugin_002_OversamplingValue += analogRead(A0);
#endif
#if defined(ESP32)
Plugin_002_OversamplingValue += analogRead(Settings.TaskDevicePin1[event->TaskIndex]);
#endif
Plugin_002_OversamplingValue += analogRead(A0);
Plugin_002_OversamplingCount ++;
}
success = true;
@@ -116,12 +106,7 @@ boolean Plugin_002(byte function, struct EventStruct *event, String& string)
}
else
{
#if defined(ESP8266)
int16_t value = analogRead(A0);
#endif
#if defined(ESP32)
int16_t value = analogRead(Settings.TaskDevicePin1[event->TaskIndex]);
#endif
int16_t value = analogRead(A0);
UserVar[event->BaseVarIndex] = (float)value;
log += value;
+60 -78
View File
@@ -2,8 +2,6 @@
// #################################### Plugin 004: TempSensor Dallas DS18B20 ###########################
// #######################################################################################################
// Maxim Integrated (ex Dallas) DS18B20 datasheet : https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
#define PLUGIN_004
#define PLUGIN_ID_004 4
#define PLUGIN_NAME_004 "Environment - DS18b20"
@@ -54,8 +52,9 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
Plugin_004_DallasPin = Settings.TaskDevicePin1[event->TaskIndex];
// get currently saved address
for (byte i = 0; i < 8; i++)
for (byte i = 0; i < 8; i++) {
savedAddress[i] = ExtraTaskSettings.TaskDevicePluginConfigLong[i];
}
// find all suitable devices
addRowLabel(string, F("Device Address"));
@@ -105,7 +104,6 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
ExtraTaskSettings.TaskDevicePluginConfigLong[x] = addr[x];
Plugin_004_DS_setResolution(addr, getFormItemInt(F("plugin_004_res")));
Plugin_004_DS_startConvertion(addr);
success = true;
break;
@@ -117,32 +115,24 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
{
if (x != 0)
string += "-";
// string += String(ExtraTaskSettings.TaskDevicePluginConfigLong[x], HEX);
string += String(ExtraTaskSettings.TaskDevicePluginConfigLong[x], HEX);
}
success = true;
break;
}
case PLUGIN_INIT:
{
Plugin_004_DallasPin = Settings.TaskDevicePin1[event->TaskIndex];
uint8_t addr[8];
Plugin_004_get_addr(addr, event->TaskIndex);
Plugin_004_DS_startConvertion(addr);
delay(800); //give it time to do intial conversion
success = true;
break;
}
case PLUGIN_READ:
{
if (ExtraTaskSettings.TaskDevicePluginConfigLong[0] != 0){
uint8_t addr[8];
Plugin_004_get_addr(addr, event->TaskIndex);
// Load ROM address from tasksettings
LoadTaskSettings(event->TaskIndex);
for (byte x = 0; x < 8; x++)
addr[x] = ExtraTaskSettings.TaskDevicePluginConfigLong[x];
Plugin_004_DallasPin = Settings.TaskDevicePin1[event->TaskIndex];
float value = 0;
String log = F("DS : Temperature: ");
if (Plugin_004_DS_readTemp(addr, &value))
{
UserVar[event->BaseVarIndex] = value;
@@ -154,7 +144,6 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
UserVar[event->BaseVarIndex] = NAN;
log += F("Error!");
}
Plugin_004_DS_startConvertion(addr);
log += (" (");
for (byte x = 0; x < 8; x++)
@@ -173,53 +162,28 @@ boolean Plugin_004(byte function, struct EventStruct * event, String& string)
return success;
}
void Plugin_004_get_addr(uint8_t addr[], byte TaskIndex)
{
// Load ROM address from tasksettings
LoadTaskSettings(TaskIndex);
for (byte x = 0; x < 8; x++)
addr[x] = ExtraTaskSettings.TaskDevicePluginConfigLong[x];
}
/*********************************************************************************************\
Dallas Scan bus
\*********************************************************************************************/
byte Plugin_004_DS_scan(byte getDeviceROM, uint8_t* ROM)
{
byte tmpaddr[8];
byte devCount = 0;
Plugin_004_DS_reset();
byte tmpaddr[8];
byte devCount = 0;
Plugin_004_DS_reset();
Plugin_004_DS_reset_search();
while (Plugin_004_DS_search(tmpaddr))
{
if (getDeviceROM == devCount)
for (byte i = 0; i < 8; i++)
ROM[i] = tmpaddr[i];
devCount++;
}
return devCount;
Plugin_004_DS_reset_search();
while (Plugin_004_DS_search(tmpaddr))
{
if (getDeviceROM == devCount)
for (byte i = 0; i < 8; i++)
ROM[i] = tmpaddr[i];
devCount++;
}
return devCount;
}
/*********************************************************************************************\
* Dallas Start Temperature Conversion, expected duration:
* 9 bits resolution -> 93.75 ms
* 10 bits resolution -> 187.5 ms
* 11 bits resolution -> 375 ms
* 12 bits resolution -> 750 ms
\*********************************************************************************************/
void Plugin_004_DS_startConvertion(uint8_t ROM[8])
{
Plugin_004_DS_reset();
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
Plugin_004_DS_write(ROM[i]);
Plugin_004_DS_write(0x44); // Take temperature mesurement
}
/*********************************************************************************************\
* Dallas Read temperature from scratchpad
* Dallas Read temperature
\*********************************************************************************************/
boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float * value)
{
@@ -230,13 +194,20 @@ boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float * value)
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
Plugin_004_DS_write(ROM[i]);
Plugin_004_DS_write(0x44);
delay(800);
Plugin_004_DS_reset();
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
Plugin_004_DS_write(ROM[i]);
Plugin_004_DS_write(0xBE); // Read scratchpad
for (byte i = 0; i < 9; i++) // read 9 bytes
for (byte i = 0; i < 9; i++) // copy 8 bytes
ScratchPad[i] = Plugin_004_DS_read();
if (!Plugin_004_DS_crc8(ScratchPad))
if (Plugin_004_DS_crc8(ScratchPad, 8) != ScratchPad[8])
{
*value = 0;
return false;
@@ -251,11 +222,15 @@ boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float * value)
{
DSTemp = (ScratchPad[1] << 11) | ScratchPad[0] << 3;
DSTemp = ((DSTemp & 0xfff0) << 3) - 16 +
(((ScratchPad[7] - ScratchPad[6]) << 7) / ScratchPad[7]);
(
((ScratchPad[7] - ScratchPad[6]) << 7) /
ScratchPad[7]
);
*value = float(DSTemp) * 0.0078125;
}
return true;
}
} // Plugin_004_DS_readTemp
/*********************************************************************************************\
* Dallas Get Resolution
@@ -270,15 +245,19 @@ int Plugin_004_DS_getResolution(uint8_t ROM[8])
Plugin_004_DS_reset();
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
{
Plugin_004_DS_write(ROM[i]);
}
Plugin_004_DS_write(0xBE); // Read scratchpad
for (byte i = 0; i < 9; i++) // read 9 bytes
for (byte i = 0; i < 9; i++) // copy 8 bytes
ScratchPad[i] = Plugin_004_DS_read();
if (!Plugin_004_DS_crc8(ScratchPad))
if (Plugin_004_DS_crc8(ScratchPad, 8) != ScratchPad[8])
{
return 0;
}
else
{
switch (ScratchPad[4])
@@ -293,7 +272,6 @@ int Plugin_004_DS_getResolution(uint8_t ROM[8])
return 10;
case 0x1F: // 9 bit
default:
return 9;
}
}
@@ -313,38 +291,44 @@ boolean Plugin_004_DS_setResolution(uint8_t ROM[8], byte res)
Plugin_004_DS_reset();
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
{
Plugin_004_DS_write(ROM[i]);
}
Plugin_004_DS_write(0xBE); // Read scratchpad
for (byte i = 0; i < 9; i++) // read 9 bytes
for (byte i = 0; i < 9; i++) // copy 8 bytes
ScratchPad[i] = Plugin_004_DS_read();
if (!Plugin_004_DS_crc8(ScratchPad))
return false;
if (Plugin_004_DS_crc8(ScratchPad, 8) != ScratchPad[8])
{
return 0;
}
else
{
switch (res)
{
case 12:
ScratchPad[4] = 0x7F; // 12 bits
ScratchPad[4] = 0x7F; // 12 bit
break;
case 11:
ScratchPad[4] = 0x5F; // 11 bits
ScratchPad[4] = 0x5F; // 11 bit
break;
case 10:
ScratchPad[4] = 0x3F; // 10 bits
ScratchPad[4] = 0x3F; // 10 bit
break;
case 9:
default:
ScratchPad[4] = 0x1F; // 9 bits
ScratchPad[4] = 0x1F; // 9 bit
break;
}
Plugin_004_DS_reset();
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
{
Plugin_004_DS_write(ROM[i]);
}
Plugin_004_DS_write(0x4E); // Write to EEPROM
Plugin_004_DS_write(ScratchPad[2]); // high alarm temp
@@ -353,7 +337,9 @@ boolean Plugin_004_DS_setResolution(uint8_t ROM[8], byte res)
Plugin_004_DS_write(0x55); // Choose ROM
for (byte i = 0; i < 8; i++)
{
Plugin_004_DS_write(ROM[i]);
}
// save the newly written values to eeprom
Plugin_004_DS_write(0x48);
@@ -608,17 +594,13 @@ void Plugin_004_DS_write_bit(uint8_t v)
}
}
/*********************************************************************************************\
* Dallas Calculate CRC8 and compare it of addr[0-7] and compares it to addr[8]
\*********************************************************************************************/
boolean Plugin_004_DS_crc8(uint8_t * addr)
uint8_t Plugin_004_DS_crc8(uint8_t * addr, uint8_t len)
{
uint8_t crc = 0;
uint8_t len = 8;
uint8_t crc = 0;
while (len--)
{
uint8_t inbyte = *addr++; // from 0 to 7
uint8_t inbyte = *addr++;
for (uint8_t i = 8; i; i--)
{
uint8_t mix = (crc ^ inbyte) & 0x01;
@@ -627,5 +609,5 @@ boolean Plugin_004_DS_crc8(uint8_t * addr)
inbyte >>= 1;
}
}
return crc == *addr; // addr 8
return crc;
}
+1 -1
View File
@@ -70,7 +70,7 @@ 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(string, F("Measurment 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]);
+98 -17
View File
@@ -7,6 +7,7 @@
// DS Temp:[Dallas1#Temperature#R]
// Lux:[Lux#Lux#R]
// Baro:[Baro#Pressure#R]
// Pump:[Pump#on#O] -> ON/OFF
#include <LiquidCrystal_I2C.h>
@@ -68,6 +69,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
}
addFormSelectorI2C(string, F("plugin_012_adr"), 16, optionValues, choice);
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
String options2[2];
options2[0] = F("2 x 16");
@@ -75,6 +77,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
int optionValues2[2] = { 1, 2 };
addFormSelector(string, 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++)
@@ -88,14 +91,23 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
string += F("'>");
}
string += F("<TR><TD>Display button:<TD>");
addRowLabel(string, "Display button");
addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);
char tmpString[128];
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;
String options3[3];
options3[0] = F("Continue to next line (as in v1.4)");
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]);
success = true;
break;
}
@@ -105,6 +117,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_012_adr"));
Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_012_size"));
Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_12_timer"));
Settings.TaskDevicePluginConfig[event->TaskIndex][3] = getFormItemInt(F("plugin_012_mode"));
char deviceTemplate[4][80];
for (byte varNr = 0; varNr < 4; varNr++)
@@ -190,7 +203,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
String tmpString = deviceTemplate[x];
if (lcd && tmpString.length())
{
String newString = parseTemplate(tmpString, col);
String newString = P012_parseTemplate(tmpString, col);
lcd->setCursor(0, x);
lcd->print(newString);
}
@@ -201,29 +214,87 @@ 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)
tmpString = tmpString.substring(0, argIndex);
if (lcd && tmpString.equalsIgnoreCase(F("LCD")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
lcd->setCursor(event->Par2 - 1, event->Par1 - 1);
lcd->print(tmpString.c_str());
}
if (lcd && tmpString.equalsIgnoreCase(F("LCDCMD")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
if (tmpString.equalsIgnoreCase(F("Off")))
lcd->noBacklight();
else if (tmpString.equalsIgnoreCase(F("On")))
lcd->backlight();
else if (tmpString.equalsIgnoreCase(F("Clear")))
lcd->clear();
if (tmpString.equalsIgnoreCase(F("Off"))){
lcd->noBacklight();
}
else if (tmpString.equalsIgnoreCase(F("On"))){
lcd->backlight();
}
else if (tmpString.equalsIgnoreCase(F("Clear"))){
lcd->clear();
}
}
else if (lcd && tmpString.equalsIgnoreCase(F("LCD")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
int colPos = event->Par2 - 1;
int rowPos = event->Par1 - 1;
//clear line before writing new string
if (Settings.TaskDevicePluginConfig[event->TaskIndex][3] == 2){
lcd->setCursor(colPos, rowPos);
for (byte i = colPos; i < 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){
lcd->setCursor(colPos, rowPos);
for (byte i = 0; i < cols - colPos; i++) {
if(tmpString[i]){
lcd->print(tmpString[i]);
}
}
}
// message exceeding cols will continue to next line
else{
// Fix Weird (native) lcd display behaviour that split long string into row 1,3,2,4, instead of 1,2,3,4
boolean stillProcessing = 1;
byte charCount = 1;
while(stillProcessing) {
if (++colPos > 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 ){
lcd->print(tmpString[charCount - 1]);
}
if (!tmpString[charCount]) { // no more chars to process?
stillProcessing = 0;
}
charCount += 1;
}
//lcd->print(tmpString.c_str());
// end fix
}
}
break;
}
@@ -231,3 +302,13 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
}
return success;
}
// Perform some specific changes for LCD display
// https://www.letscontrolit.com/forum/viewtopic.php?t=2368
String P012_parseTemplate(String &tmpString, byte lineSize) {
String result = parseTemplate(tmpString, lineSize);
const char degree[3] = {0xc2, 0xb0, 0}; // Unicode degree symbol
const char degree_lcd[2] = {0xdf, 0}; // P012_LCD degree symbol
result.replace(degree, degree_lcd);
return result;
}
+2 -37
View File
@@ -8,7 +8,7 @@
#define PLUGIN_VALUENAME1_022 "PWM"
#define PLUGIN_022_PCA9685_MODE1 0x00 // location for Mode1 register address
#define PCA9685_MODE2 0x01 // location for Mode2 register address
#define PCA9685_MODE2 0x01 // location for Mode2 reigster address
#define PCA9685_LED0 0x06 // location for start of LED0 registers
#define PCA9685_ADDRESS 0x40 // I2C address
@@ -63,16 +63,6 @@ boolean Plugin_022(byte function, struct EventStruct *event, String& string)
addLog(LOG_LEVEL_INFO, log);
SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_022, event->Par1, log, 0));
}
if (command == F("pcafrq"))
{
if (!Plugin_022_init) Plugin_022_initialize();
success = true;
Plugin_022_Frequency(event->Par1);
setPinState(PLUGIN_ID_022, 99, PIN_MODE_UNDEFINED, event->Par1);
log = String(F("PCA : FREQ ")) + String(event->Par1);
addLog(LOG_LEVEL_INFO, log);
SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_022, 99, log, 0));
}
if (command == F("status"))
{
@@ -100,15 +90,6 @@ void Plugin_022_writeRegister(int regAddress, byte data) {
Wire.endTransmission();
}
uint8_t Plugin_022_readRegister(int regAddress) {
uint8_t res = 0;
Wire.requestFrom(PCA9685_ADDRESS,1,1);
while (Wire.available()) {
res = Wire.read();
}
return res;
}
//********************************************************************************
// PCA9685 write
@@ -126,26 +107,10 @@ void Plugin_022_Write(byte Par1, int Par2)
Wire.write(highByte(LED_OFF));
Wire.endTransmission();
}
void Plugin_022_Frequency(uint16_t freq)
{
Plugin_022_writeRegister(PLUGIN_022_PCA9685_MODE1, (byte)0x0);
freq *= 0.9;
// prescale = 25000000 / 4096;
uint16_t prescale = 6103;
prescale /= freq;
prescale -= 1;
uint8_t oldmode = Plugin_022_readRegister(0);
uint8_t newmode = (oldmode&0x7f) | 0x10;
Plugin_022_writeRegister(PLUGIN_022_PCA9685_MODE1, (byte)newmode);
Plugin_022_writeRegister(0xfe, (byte)prescale); //prescale register
Plugin_022_writeRegister(PLUGIN_022_PCA9685_MODE1, (byte)oldmode);
delayMicroseconds(5000);
Plugin_022_writeRegister(PLUGIN_022_PCA9685_MODE1, (byte)oldmode | 0xa1);
}
void Plugin_022_initialize()
{
// default mode is open drain output, drive leds connected to VCC
// default mode is open drain ouput, drive leds connected to VCC
Plugin_022_writeRegister(PLUGIN_022_PCA9685_MODE1, (byte)0x01); // reset the device
delay(1);
Plugin_022_writeRegister(PLUGIN_022_PCA9685_MODE1, (byte)B10100000); // set up for auto increment
+143 -278
View File
@@ -15,19 +15,11 @@
byte Plugin_023_OLED_address = 0x3c;
byte Plugin_023_OLED_type = 0;
byte Plugin_023_OLED_font_width = 0;
enum
{
OLED_64x48 = 0x01,
OLED_rotated = 0x02,
OLED_128x32 = 0x04
};
enum
{
Size_normal = 0x01,
Size_optimized = 0x02
OLED_rotated = 0x02
};
boolean Plugin_023(byte function, struct EventStruct *event, String& string)
@@ -78,14 +70,9 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
addFormSelector(string, 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);
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);
String options3[2] = { F("128x64"), F("64x48") };
int optionValues3[2] = { 1, 2 };
addFormSelector(string, F("Display Size"), F("plugin_023_size"), 2, options3, optionValues3, choice3);
char deviceTemplate[8][64];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
@@ -108,7 +95,6 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_023_rotate"));
Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_23_timer"));
Settings.TaskDevicePluginConfig[event->TaskIndex][3] = getFormItemInt(F("plugin_023_size"));
Settings.TaskDevicePluginConfig[event->TaskIndex][4] = getFormItemInt(F("plugin_023_font_width"));
char deviceTemplate[8][64];
for (byte varNr = 0; varNr < 8; varNr++)
@@ -129,16 +115,6 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
{
Plugin_023_OLED_type = 0;
Plugin_023_OLED_address = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
if (Settings.TaskDevicePluginConfig[event->TaskIndex][3] == 3)
{
Plugin_023_OLED_type = OLED_128x32;
}
if (Settings.TaskDevicePluginConfig[event->TaskIndex][4] == 2)
{
Plugin_023_OLED_font_width = Size_optimized;
}
Plugin_023_StartUp_OLED();
Plugin_023_clear_display();
if (Settings.TaskDevicePluginConfig[event->TaskIndex][1] == 2)
@@ -194,7 +170,7 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
String tmpString = deviceTemplate[x];
if (tmpString.length())
{
String newString = parseTemplate(tmpString, 16);
String newString = P023_parseTemplate(tmpString, 16);
Plugin_023_sendStrXY(newString.c_str(), x, 0);
}
}
@@ -208,13 +184,6 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase(F("OLED")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
Plugin_023_sendStrXY(tmpString.c_str(), event->Par1 - 1, event->Par2 - 1);
}
if (tmpString.equalsIgnoreCase(F("OLEDCMD")))
{
success = true;
@@ -227,209 +196,128 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
else if (tmpString.equalsIgnoreCase(F("Clear")))
Plugin_023_clear_display();
}
else if (tmpString.equalsIgnoreCase(F("OLED")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
String newString = P023_parseTemplate(tmpString, 16);
Plugin_023_sendStrXY(newString.c_str(), event->Par1 - 1, event->Par2 - 1);
}
break;
}
}
return success;
}
const char Plugin_023_myFont_Size[] PROGMEM = {
0x05, // SPACE
0x05, // !
0x07, // "
0x08, // #
0x08, // $
0x08, // %
0x08, // &
0x06, // '
0x06, // (
0x06, // )
0x08, // *
0x08, // +
0x05, // ,
0x08, // -
0x05, // .
0x08, // /
0x08, // 0
0x07, // 1
0x08, // 2
0x08, // 3
0x08, // 4
0x08, // 5
0x08, // 6
0x08, // 7
0x08, // 8
0x08, // 9
0x06, // :
0x06, // ;
0x07, // <
0x08, // =
0x07, // >
0x08, // ?
0x08, // @
0x08, // A
0x08, // B
0x08, // C
0x08, // D
0x08, // E
0x08, // F
0x08, // G
0x08, // H
0x06, // I
0x08, // J
0x08, // K
0x08, // L
0x08, // M
0x08, // N
0x08, // O
0x08, // P
0x08, // Q
0x08, // R
0x08, // S
0x08, // T
0x08, // U
0x08, // V
0x08, // W
0x08, // X
0x08, // Y
0x08, // Z
0x06, // [
0x08, // BACKSLASH
0x06, // ]
0x08, // ^
0x08, // _
0x06, // `
0x08, // a
0x08, // b
0x07, // c
0x08, // d
0x08, // e
0x07, // f
0x08, // g
0x08, // h
0x05, // i
0x06, // j
0x07, // k
0x06, // l
0x08, // m
0x07, // n
0x07, // o
0x07, // p
0x07, // q
0x07, // r
0x07, // s
0x06, // t
0x07, // u
0x08, // v
0x08, // w
0x08, // x
0x07, // y
0x08, // z
0x06, // {
0x05, // |
0x06, // }
0x08, // ~
0x08 // DEL
};
// Perform some specific changes for OLED display
String P023_parseTemplate(String &tmpString, byte lineSize) {
String result = parseTemplate(tmpString, lineSize);
const char degree[3] = {0xc2, 0xb0, 0}; // Unicode degree symbol
const char degree_oled[2] = {0x7F, 0}; // P023_OLED degree symbol
result.replace(degree, degree_oled);
return result;
}
const char Plugin_023_myFont[][8] PROGMEM = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // SPACE
{0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00}, // !
{0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00}, // "
{0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x00}, // #
{0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x00}, // $
{0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x00}, // %
{0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, 0x00}, // &
{0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00}, // '
{0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x00}, // (
{0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x00}, // )
{0x00, 0x08, 0x2A, 0x1C, 0x2A, 0x08, 0x00, 0x00}, // *
{0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00}, // +
{0x00, 0xA0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, // ,
{0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00}, // -
{0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, // .
{0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00}, // /
{0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00}, // 0
{0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00}, // 1
{0x00, 0x62, 0x51, 0x49, 0x49, 0x46, 0x00, 0x00}, // 2
{0x00, 0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x00}, // 3
{0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00}, // 4
{0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x00}, // 5
{0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00, 0x00}, // 6
{0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, 0x00}, // 7
{0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00}, // 8
{0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00}, // 9
{0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00}, // :
{0x00, 0x00, 0xAC, 0x6C, 0x00, 0x00, 0x00, 0x00}, // ;
{0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00}, // <
{0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00}, // =
{0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x00, 0x00}, // >
{0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00, 0x00}, // ?
{0x00, 0x32, 0x49, 0x79, 0x41, 0x3E, 0x00, 0x00}, // @
{0x00, 0x7E, 0x09, 0x09, 0x09, 0x7E, 0x00, 0x00}, // A
{0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00}, // B
{0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x00}, // C
{0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00, 0x00}, // D
{0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00}, // E
{0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x00}, // F
{0x00, 0x3E, 0x41, 0x41, 0x51, 0x72, 0x00, 0x00}, // G
{0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00}, // H
{0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00, 0x00}, // I
{0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x00}, // J
{0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00}, // K
{0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00}, // L
{0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00, 0x00}, // M
{0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00}, // N
{0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00}, // O
{0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00}, // P
{0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x00}, // Q
{0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00}, // R
{0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00}, // S
{0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x00}, // T
{0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00}, // U
{0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x00}, // V
{0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x00}, // W
{0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x00}, // X
{0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x00}, // Y
{0x00, 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, 0x00}, // Z
{0x00, 0x7F, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00}, // [
{0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00}, // BACKSLASH
{0x00, 0x41, 0x41, 0x7F, 0x00, 0x00, 0x00, 0x00}, // ]
{0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x00}, // ^
{0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00}, // _
{0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00}, // `
{0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x00}, // a
{0x00, 0x7F, 0x48, 0x44, 0x44, 0x38, 0x00, 0x00}, // b
{0x00, 0x38, 0x44, 0x44, 0x28, 0x00, 0x00, 0x00}, // c
{0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, 0x00, 0x00}, // d
{0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x00}, // e
{0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, 0x00, 0x00}, // f
{0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x00, 0x00}, // g
{0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00}, // h
{0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00}, // i
{0x00, 0x80, 0x84, 0x7D, 0x00, 0x00, 0x00, 0x00}, // j
{0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00}, // k
{0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00}, // l
{0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00, 0x00}, // m
{0x00, 0x7C, 0x08, 0x04, 0x7C, 0x00, 0x00, 0x00}, // n
{0x00, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00}, // o
{0x00, 0xFC, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00}, // p
{0x00, 0x18, 0x24, 0x24, 0xFC, 0x00, 0x00, 0x00}, // q
{0x00, 0x00, 0x7C, 0x08, 0x04, 0x00, 0x00, 0x00}, // r
{0x00, 0x48, 0x54, 0x54, 0x24, 0x00, 0x00, 0x00}, // s
{0x00, 0x04, 0x7F, 0x44, 0x00, 0x00, 0x00, 0x00}, // t
{0x00, 0x3C, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00}, // u
{0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x00}, // v
{0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, 0x00}, // w
{0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00}, // x
{0x00, 0x1C, 0xA0, 0xA0, 0x7C, 0x00, 0x00, 0x00}, // y
{0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x00}, // z
{0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x00}, // {
{0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00}, // |
{0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x00, 0x00}, // }
{0x00, 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00}, // ~
{0x00, 0x02, 0x05, 0x05, 0x02, 0x00, 0x00, 0x00} // DEL
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00},
{0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x00},
{0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x00},
{0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x00},
{0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, 0x00},
{0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x08, 0x2A, 0x1C, 0x2A, 0x08, 0x00, 0x00},
{0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00},
{0x00, 0xA0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00},
{0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00},
{0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00},
{0x00, 0x62, 0x51, 0x49, 0x49, 0x46, 0x00, 0x00},
{0x00, 0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x00},
{0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00},
{0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x00},
{0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00, 0x00},
{0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, 0x00},
{0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00},
{0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00},
{0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0xAC, 0x6C, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00},
{0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00},
{0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x00, 0x00},
{0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00, 0x00},
{0x00, 0x32, 0x49, 0x79, 0x41, 0x3E, 0x00, 0x00},
{0x00, 0x7E, 0x09, 0x09, 0x09, 0x7E, 0x00, 0x00},
{0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00},
{0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x00},
{0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00, 0x00},
{0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00},
{0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x00},
{0x00, 0x3E, 0x41, 0x41, 0x51, 0x72, 0x00, 0x00},
{0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00},
{0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x00},
{0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00},
{0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
{0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00, 0x00},
{0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00},
{0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00},
{0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00},
{0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x00},
{0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00},
{0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00},
{0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x00},
{0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00},
{0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x00},
{0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x00},
{0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x00},
{0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x00},
{0x00, 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, 0x00},
{0x00, 0x7F, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00},
{0x00, 0x41, 0x41, 0x7F, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x00},
{0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00},
{0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x00},
{0x00, 0x7F, 0x48, 0x44, 0x44, 0x38, 0x00, 0x00},
{0x00, 0x38, 0x44, 0x44, 0x28, 0x00, 0x00, 0x00},
{0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, 0x00, 0x00},
{0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x00},
{0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, 0x00, 0x00},
{0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x00, 0x00},
{0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00},
{0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x80, 0x84, 0x7D, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00},
{0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00, 0x00},
{0x00, 0x7C, 0x08, 0x04, 0x7C, 0x00, 0x00, 0x00},
{0x00, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00},
{0x00, 0xFC, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00},
{0x00, 0x18, 0x24, 0x24, 0xFC, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x7C, 0x08, 0x04, 0x00, 0x00, 0x00},
{0x00, 0x48, 0x54, 0x54, 0x24, 0x00, 0x00, 0x00},
{0x00, 0x04, 0x7F, 0x44, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x3C, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00},
{0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x00},
{0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, 0x00},
{0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00},
{0x00, 0x1C, 0xA0, 0xA0, 0x7C, 0x00, 0x00, 0x00},
{0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x00},
{0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00},
{0x00, 0x02, 0x05, 0x05, 0x02, 0x00, 0x00, 0x00}
};
static void Plugin_023_reset_display(void)
@@ -556,20 +444,9 @@ static void Plugin_023_sendStrXY(const char *string, int X, int Y)
{
Plugin_023_setXY(X, Y);
unsigned char i = 0;
unsigned char font_width = 0;
while (*string)
{
switch (Plugin_023_OLED_font_width)
{
case Size_optimized:
font_width = pgm_read_byte(&(Plugin_023_myFont_Size[*string - 0x20]));
break;
default:
font_width = 8;
}
for (i = 0; i < font_width; i++)
for (i = 0; i < 8; i++)
{
Plugin_023_SendChar(pgm_read_byte(Plugin_023_myFont[*string - 0x20] + i));
}
@@ -580,47 +457,35 @@ static void Plugin_023_sendStrXY(const char *string, int X, int Y)
static void Plugin_023_init_OLED(void)
{
unsigned char multiplex;
unsigned char compins;
switch (Plugin_023_OLED_type)
{
case OLED_128x32:
multiplex = 0x1F;
compins = 0x02;
break;
default:
multiplex = 0x3F;
compins = 0x12;
}
Plugin_023_sendcommand(0xAE); //display off
Plugin_023_sendcommand(0xD5); //SETDISPLAYCLOCKDIV
Plugin_023_sendcommand(0x80); // the suggested ratio 0x80
Plugin_023_sendcommand(0xA8); //SSD1306_SETMULTIPLEX
Plugin_023_sendcommand(multiplex); //0x1F if 128x32, 0x3F if others (e.g. 128x64)
Plugin_023_sendcommand(0xD3); //SETDISPLAYOFFSET
Plugin_023_sendcommand(0x00); //no offset
Plugin_023_sendcommand(0x40 | 0x0); //SETSTARTLINE
Plugin_023_sendcommand(0x8D); //CHARGEPUMP
Plugin_023_sendcommand(0xae); //display off
Plugin_023_sendcommand(0xa6); //Set Normal Display (default)
Plugin_023_sendcommand(0xAE); //DISPLAYOFF
Plugin_023_sendcommand(0xD5); //SETDISPLAYCLOCKDIV
Plugin_023_sendcommand(0x80); // the suggested ratio 0x80
Plugin_023_sendcommand(0xA8); //SSD1306_SETMULTIPLEX
Plugin_023_sendcommand(0x3F);
Plugin_023_sendcommand(0xD3); //SETDISPLAYOFFSET
Plugin_023_sendcommand(0x0); //no offset
Plugin_023_sendcommand(0x40 | 0x0); //SETSTARTLINE
Plugin_023_sendcommand(0x8D); //CHARGEPUMP
Plugin_023_sendcommand(0x14);
Plugin_023_sendcommand(0x20); //MEMORYMODE
Plugin_023_sendcommand(0x00); //0x0 act like ks0108
Plugin_023_sendcommand(0xA0); //128x32 ???
Plugin_023_sendcommand(0xC0); //128x32 ???
Plugin_023_sendcommand(0xDA); //COMPINS
Plugin_023_sendcommand(compins); //0x02 if 128x32, 0x12 if others (e.g. 128x64)
Plugin_023_sendcommand(0x81); //SETCONTRAS
Plugin_023_sendcommand(0x20); //MEMORYMODE
Plugin_023_sendcommand(0x00); //0x0 act like ks0108
Plugin_023_sendcommand(0xA0);
Plugin_023_sendcommand(0xC0);
Plugin_023_sendcommand(0xDA); //0xDA
Plugin_023_sendcommand(0x12); //COMSCANDEC
Plugin_023_sendcommand(0x81); //SETCONTRAS
Plugin_023_sendcommand(0xCF);
Plugin_023_sendcommand(0xD9); //SETPRECHARGE
Plugin_023_sendcommand(0xd9); //SETPRECHARGE
Plugin_023_sendcommand(0xF1);
Plugin_023_sendcommand(0xDB); //SETVCOMDETECT
Plugin_023_sendcommand(0xDB); //SETVCOMDETECT
Plugin_023_sendcommand(0x40);
Plugin_023_sendcommand(0xA4); //DISPLAYALLON_RESUME
Plugin_023_sendcommand(0xA6); //NORMALDISPLAY
Plugin_023_sendcommand(0xA4); //DISPLAYALLON_RESUME
Plugin_023_sendcommand(0xA6); //NORMALDISPLAY
Plugin_023_clear_display();
Plugin_023_sendcommand(0x2E); // stop scroll
Plugin_023_sendcommand(0x2e); // stop scroll
Plugin_023_sendcommand(0x20); //Set Memory Addressing Mode
Plugin_023_sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode
}
+2 -8
View File
@@ -40,7 +40,7 @@ boolean Plugin_026(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_LOAD:
{
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
String options[10];
String options[9];
options[0] = F("Uptime");
options[1] = F("Free RAM");
options[2] = F("Wifi RSSI");
@@ -50,8 +50,7 @@ boolean Plugin_026(byte function, struct EventStruct *event, String& string)
options[6] = F("IP 2.Octet");
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(string, F("Indicator"), F("plugin_026"), 9, options, NULL, choice);
success = true;
break;
@@ -118,11 +117,6 @@ boolean Plugin_026(byte function, struct EventStruct *event, String& string)
value = WiFi.localIP()[3];
break;
}
case 9:
{
value = (millis()-lastWeb)/1000; // respond in seconds
break;
}
}
UserVar[event->BaseVarIndex] = value;
String log = F("SYS : ");
+122 -341
View File
@@ -2,57 +2,54 @@
//#################### Plugin 028 BME280 I2C Temp/Hum/Barometric Pressure Sensor #######################
//#######################################################################################################
//#include <math.h>
#define PLUGIN_028
#define PLUGIN_ID_028 28
#define PLUGIN_NAME_028 "Environment - BMx280"
#define PLUGIN_NAME_028 "Environment - BME280"
#define PLUGIN_VALUENAME1_028 "Temperature"
#define PLUGIN_VALUENAME2_028 "Humidity"
#define PLUGIN_VALUENAME3_028 "Pressure"
#define PLUGIN_028_BME280_DEVICE "BME280"
#define PLUGIN_028_BMP280_DEVICE "BMP280"
enum
{
BME280_REGISTER_DIG_T1 = 0x88,
BME280_REGISTER_DIG_T2 = 0x8A,
BME280_REGISTER_DIG_T3 = 0x8C,
// Minimal interval in msec.
#define BMx280_MEASUREMENT_INTERVAL_MSEC 50000
BME280_REGISTER_DIG_P1 = 0x8E,
BME280_REGISTER_DIG_P2 = 0x90,
BME280_REGISTER_DIG_P3 = 0x92,
BME280_REGISTER_DIG_P4 = 0x94,
BME280_REGISTER_DIG_P5 = 0x96,
BME280_REGISTER_DIG_P6 = 0x98,
BME280_REGISTER_DIG_P7 = 0x9A,
BME280_REGISTER_DIG_P8 = 0x9C,
BME280_REGISTER_DIG_P9 = 0x9E,
#define BMx280_REGISTER_DIG_T1 0x88
#define BMx280_REGISTER_DIG_T2 0x8A
#define BMx280_REGISTER_DIG_T3 0x8C
BME280_REGISTER_DIG_H1 = 0xA1,
BME280_REGISTER_DIG_H2 = 0xE1,
BME280_REGISTER_DIG_H3 = 0xE3,
BME280_REGISTER_DIG_H4 = 0xE4,
BME280_REGISTER_DIG_H5 = 0xE5,
BME280_REGISTER_DIG_H6 = 0xE7,
#define BMx280_REGISTER_DIG_P1 0x8E
#define BMx280_REGISTER_DIG_P2 0x90
#define BMx280_REGISTER_DIG_P3 0x92
#define BMx280_REGISTER_DIG_P4 0x94
#define BMx280_REGISTER_DIG_P5 0x96
#define BMx280_REGISTER_DIG_P6 0x98
#define BMx280_REGISTER_DIG_P7 0x9A
#define BMx280_REGISTER_DIG_P8 0x9C
#define BMx280_REGISTER_DIG_P9 0x9E
BME280_REGISTER_CHIPID = 0xD0,
BME280_REGISTER_VERSION = 0xD1,
BME280_REGISTER_SOFTRESET = 0xE0,
#define BMx280_REGISTER_DIG_H1 0xA1
#define BMx280_REGISTER_DIG_H2 0xE1
#define BMx280_REGISTER_DIG_H3 0xE3
#define BMx280_REGISTER_DIG_H4 0xE4
#define BMx280_REGISTER_DIG_H5 0xE5
#define BMx280_REGISTER_DIG_H6 0xE7
BME280_REGISTER_CAL26 = 0xE1, // R calibration stored in 0xE1-0xF0
#define BMx280_REGISTER_CHIPID 0xD0
#define BMx280_REGISTER_VERSION 0xD1
#define BMx280_REGISTER_SOFTRESET 0xE0
BME280_REGISTER_CONTROLHUMID = 0xF2,
BME280_REGISTER_STATUS = 0xF3,
BME280_REGISTER_CONTROL = 0xF4,
BME280_REGISTER_CONFIG = 0xF5,
BME280_REGISTER_PRESSUREDATA = 0xF7,
BME280_REGISTER_TEMPDATA = 0xFA,
BME280_REGISTER_HUMIDDATA = 0xFD,
#define BMx280_REGISTER_CAL26 0xE1 // R calibration stored in 0xE1-0xF0
#define BMx280_REGISTER_CONTROLHUMID 0xF2
#define BMx280_REGISTER_STATUS 0xF3
#define BMx280_REGISTER_CONTROL 0xF4
#define BMx280_REGISTER_CONFIG 0xF5
#define BMx280_REGISTER_PRESSUREDATA 0xF7
#define BMx280_REGISTER_TEMPDATA 0xFA
#define BMx280_REGISTER_HUMIDDATA 0xFD
#define BME280_CONTROL_SETTING_HUMIDITY 0x02 // Oversampling: 2x H
BME280_CONTROL_SETTING = 0x25, // Oversampling: 1x P, 1x T, forced
BME280_CONTROL_SETTING_HUMIDITY = 0x01, // Oversampling: 1x H
BME280_CONFIG_SETTING = 0xA0, // Tstandby 1000ms, filter off, 3-wire SPI Disable
};
typedef struct
{
@@ -79,99 +76,14 @@ typedef struct
} bme280_calib_data;
bme280_calib_data _bme280_calib[2];
boolean Plugin_028_init[2] = {false, false};
int Plugin_28_i2c_addresses[2] = { 0x76, 0x77 };
uint8_t _i2caddr;
int32_t _sensorID;
int32_t t_fine;
static float last_hum_val[2] = {0.0, 0.0};
static float last_press_val[2] = {0.0, 0.0};
static float last_temp_val[2] = {0.0, 0.0};
static float last_dew_temp_val[2] = {0.0, 0.0};
static unsigned long last_measurement[2] = {0, 0};
enum BMx_ChipId {
Unknown_DEVICE = 0,
BMP280_DEVICE_SAMPLE1 = 0x56,
BMP280_DEVICE_SAMPLE2 = 0x57,
BMP280_DEVICE = 0x58,
BME280_DEVICE = 0x60
};
BMx_ChipId _sensorID[2] = {Unknown_DEVICE, Unknown_DEVICE};
byte Plugin_028_get_config_settings() {
const uint8_t idx = Plugin_028_device_index(_i2caddr);
switch (_sensorID[idx]) {
case BMP280_DEVICE_SAMPLE1:
case BMP280_DEVICE_SAMPLE2:
case BMP280_DEVICE: return 0x28; // Tstandby 62.5ms, filter 4, 3-wire SPI Disable
case BME280_DEVICE: return 0x28; // Tstandby 62.5ms, filter 4, 3-wire SPI Disable
default: return 0;
}
}
byte Plugin_028_get_control_settings() {
const uint8_t idx = Plugin_028_device_index(_i2caddr);
switch (_sensorID[idx]) {
case BMP280_DEVICE_SAMPLE1:
case BMP280_DEVICE_SAMPLE2:
case BMP280_DEVICE: return 0x93; // Oversampling: 8x P, 8x T, normal mode
case BME280_DEVICE: return 0x93; // Oversampling: 8x P, 8x T, normal mode
default: return 0;
}
}
String Plugin_028_getFullDeviceName() {
const uint8_t idx = Plugin_028_device_index(_i2caddr);
String devicename = Plugin_028_getDeviceName();
if (_sensorID[idx] == BMP280_DEVICE_SAMPLE1 ||
_sensorID[idx] == BMP280_DEVICE_SAMPLE2)
{
devicename += F(" sample");
}
return devicename;
}
String Plugin_028_getDeviceName() {
const uint8_t idx = Plugin_028_device_index(_i2caddr);
switch (_sensorID[idx]) {
case BMP280_DEVICE_SAMPLE1:
case BMP280_DEVICE_SAMPLE2:
case BMP280_DEVICE: return PLUGIN_028_BMP280_DEVICE;
case BME280_DEVICE: return PLUGIN_028_BME280_DEVICE;
default: return F("Unknown");
}
}
boolean Plugin_028_hasHumidity() {
const uint8_t idx = Plugin_028_device_index(_i2caddr);
switch (_sensorID[idx]) {
case BMP280_DEVICE_SAMPLE1:
case BMP280_DEVICE_SAMPLE2:
case BMP280_DEVICE: return false;
case BME280_DEVICE: return true;
default: return false;
}
}
uint8_t Plugin_028_read8(byte reg, bool * is_ok = NULL); // Declaration
uint8_t Plugin_028_i2c_addr(struct EventStruct *event) {
_i2caddr = (uint8_t)Settings.TaskDevicePluginConfig[event->TaskIndex][0];
if (_i2caddr != Plugin_28_i2c_addresses[0] && _i2caddr != Plugin_28_i2c_addresses[1]) {
// Set to default address
_i2caddr = Plugin_28_i2c_addresses[0];
}
return _i2caddr;
}
uint8_t Plugin_028_device_index(const uint8_t i2cAddress) {
return i2cAddress & 0x1; //Addresses are 0x76 and 0x77 so we may use it this way
}
boolean Plugin_028_init[2] = {false, false};
boolean Plugin_028(byte function, struct EventStruct *event, String& string)
{
@@ -211,80 +123,68 @@ 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);
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);
}
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
/*
String options[2];
options[0] = F("0x76 - default settings (SDO Low)");
options[1] = F("0x77 - alternate settings (SDO HIGH)");
*/
int optionValues[2] = { 0x76, 0x77 };
addFormSelectorI2C(string, F("plugin_028_bme280_i2c"), 2, optionValues, choice);
addFormNote(string, 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(string, F("Temperature offset"), F("plugin_028_bme280_tempoffset"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
addUnit(string, 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);
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
const uint8_t i2cAddress = getFormItemInt(F("plugin_028_bme280_i2c"));
Plugin_028_check(i2cAddress); // Check id device is present
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = i2cAddress;
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_028_bme280_i2c"));
Settings.TaskDevicePluginConfig[event->TaskIndex][1] = getFormItemInt(F("plugin_028_bme280_elev"));
Settings.TaskDevicePluginConfig[event->TaskIndex][2] = getFormItemInt(F("plugin_028_bme280_tempoffset"));
success = true;
break;
}
case PLUGIN_READ:
{
const uint8_t i2cAddress = Plugin_028_i2c_addr(event);
const uint8_t idx = Plugin_028_device_index(i2cAddress);
const float tempOffset = Settings.TaskDevicePluginConfig[event->TaskIndex][2] / 10.0;
if (!Plugin_028_update_measurements(i2cAddress, tempOffset)) {
success = false;
break;
uint8_t idx = Settings.TaskDevicePluginConfig[event->TaskIndex][0] & 0x1; //Addresses are 0x76 and 0x77 so we may use it this way
Plugin_028_init[idx] &= Plugin_028_check(Settings.TaskDevicePluginConfig[event->TaskIndex][0]); // Check id device is present
Plugin_028_init[idx] &= (Plugin_028_read8(BME280_REGISTER_CONTROL) == BME280_CONTROL_SETTING); // Check if the coefficients are still valid
if (!Plugin_028_init[idx])
{
Plugin_028_init[idx] = Plugin_028_begin(Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
delay(65); //May be needed here as well to fix first wrong measurement?
}
UserVar[event->BaseVarIndex] = last_temp_val[idx];
UserVar[event->BaseVarIndex + 1] = last_hum_val[idx];
const int elev = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
if (elev) {
UserVar[event->BaseVarIndex + 2] = Plugin_028_pressureElevation(last_press_val[idx], elev);
} else {
UserVar[event->BaseVarIndex + 2] = last_press_val[idx];
}
String log;
log.reserve(40); // Prevent re-allocation
log = Plugin_028_getDeviceName();
log += F(" : Address: 0x");
log += String(_i2caddr,HEX);
addLog(LOG_LEVEL_INFO, log);
log = Plugin_028_getDeviceName();
log += F(" : Temperature: ");
log += UserVar[event->BaseVarIndex];
addLog(LOG_LEVEL_INFO, log);
if (Plugin_028_hasHumidity()) {
log = Plugin_028_getDeviceName();
log += F(" : Humidity: ");
if (Plugin_028_init[idx])
{
UserVar[event->BaseVarIndex] = Plugin_028_readTemperature(idx);
UserVar[event->BaseVarIndex + 1] = ((float)Plugin_028_readHumidity(idx));
int elev = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
if (elev)
{
UserVar[event->BaseVarIndex + 2] = Plugin_028_pressureElevation((float)Plugin_028_readPressure(idx) / 100, elev);
} else {
UserVar[event->BaseVarIndex + 2] = ((float)Plugin_028_readPressure(idx)) / 100;
}
String log = F("BME : Address: 0x");
log += String(_i2caddr,HEX);
addLog(LOG_LEVEL_INFO, log);
log = F("BME : Temperature: ");
log += UserVar[event->BaseVarIndex];
addLog(LOG_LEVEL_INFO, log);
log = F("BME : Humidity: ");
log += UserVar[event->BaseVarIndex + 1];
addLog(LOG_LEVEL_INFO, log);
log = F("BME : Barometric Pressure: ");
log += UserVar[event->BaseVarIndex + 2];
addLog(LOG_LEVEL_INFO, log);
success = true;
}
log = Plugin_028_getDeviceName();
log += F(" : Barometric Pressure: ");
log += UserVar[event->BaseVarIndex + 2];
addLog(LOG_LEVEL_INFO, log);
success = true;
break;
}
@@ -292,125 +192,18 @@ boolean Plugin_028(byte function, struct EventStruct *event, String& string)
return success;
}
// Only perform the measurements with big interval to prevent the sensor from warming up.
bool Plugin_028_update_measurements(uint8_t i2cAddress, float tempOffset) {
const uint8_t idx = Plugin_028_device_index(i2cAddress);
const unsigned long current_time = millis();
if ((last_measurement[idx] > BMx280_MEASUREMENT_INTERVAL_MSEC) &&
(current_time < (last_measurement[idx] + BMx280_MEASUREMENT_INTERVAL_MSEC)) &&
(current_time > last_measurement[idx])) {
// Timeout has not yet been reached.
return false;
}
Plugin_028_init[idx] &= Plugin_028_check(i2cAddress); // Check id device is present
if (!Plugin_028_init[idx]) {
Plugin_028_init[idx] = Plugin_028_begin(i2cAddress);
}
if (Plugin_028_init[idx]) {
last_measurement[idx] = current_time;
// Set the Sensor in sleep to be make sure that the following configs will be stored
Plugin_028_write8(BMx280_REGISTER_CONTROL, 0x00);
if (Plugin_028_hasHumidity()) {
Plugin_028_write8(BMx280_REGISTER_CONTROLHUMID, BME280_CONTROL_SETTING_HUMIDITY);
}
Plugin_028_write8(BMx280_REGISTER_CONFIG, Plugin_028_get_config_settings());
Plugin_028_write8(BMx280_REGISTER_CONTROL, Plugin_028_get_control_settings());
// Start measurement
delay(1000); // Wait one second to make sure the filtered values stabilize.
last_temp_val[idx] = Plugin_028_readTemperature(i2cAddress);
last_press_val[idx] = ((float)Plugin_028_readPressure(i2cAddress)) / 100;
last_hum_val[idx] = ((float)Plugin_028_readHumidity(i2cAddress));
// Set to sleep mode again to prevent the sensor from heating up.
Plugin_028_write8(BMx280_REGISTER_CONTROL, 0x00);
String log;
log.reserve(120); // Prevent re-allocation
log = Plugin_028_getDeviceName();
log += F(":");
boolean logAdded = false;
if (Plugin_028_hasHumidity()) {
// Apply half of the temp offset, to correct the dew point offset.
// The sensor is warmer than the surrounding air, which has effect on the perceived humidity.
last_dew_temp_val[idx] = compute_dew_point_temp(last_temp_val[idx] + (tempOffset / 2.0), last_hum_val[idx]);
} else {
// No humidity measurement, thus set dew point equal to air temperature.
last_dew_temp_val[idx] = last_temp_val[idx];
}
if (tempOffset > 0.1 || tempOffset < -0.1) {
// There is some offset to apply.
log += F(" Apply temp offset ");
log += tempOffset;
log += F("C");
if (Plugin_028_hasHumidity()) {
log += F(" humidity ");
log += last_hum_val[idx];
last_hum_val[idx] = compute_humidity_from_dewpoint(last_temp_val[idx] + tempOffset, last_dew_temp_val[idx]);
log += F("% => ");
log += last_hum_val[idx];
log += F("%");
}
log += F(" temperature ");
log += last_temp_val[idx];
last_temp_val[idx] = last_temp_val[idx] + tempOffset;
log += F("C => ");
log += last_temp_val[idx];
log += F("C");
logAdded = true;
}
if (Plugin_028_hasHumidity()) {
log += F(" dew point ");
log += last_dew_temp_val[idx];
log += F("C");
logAdded = true;
}
if (logAdded)
addLog(LOG_LEVEL_INFO, log);
return true;
}
return false;
}
//**************************************************************************/
// Check BME280 presence
//**************************************************************************/
bool Plugin_028_check(uint8_t a) {
_i2caddr = a?a:0x76;
const uint8_t idx = Plugin_028_device_index(_i2caddr);
bool wire_status = false;
const uint8_t chip_id = Plugin_028_read8(BMx280_REGISTER_CHIPID, &wire_status);
switch (chip_id) {
case BMP280_DEVICE_SAMPLE1:
case BMP280_DEVICE_SAMPLE2:
case BMP280_DEVICE:
case BME280_DEVICE: {
if (wire_status) {
// Store detected chip ID when chip found.
if (_sensorID[idx] != chip_id) {
_sensorID[idx] = static_cast<BMx_ChipId>(chip_id);
String log = F("BMx280 : Detected ");
log += Plugin_028_getFullDeviceName();
addLog(LOG_LEVEL_INFO, log);
}
} else {
_sensorID[idx] = Unknown_DEVICE;
}
break;
}
default:
_sensorID[idx] = Unknown_DEVICE;
break;
if (Plugin_028_read8(BME280_REGISTER_CHIPID, &wire_status) != 0x60) {
return false;
} else {
return wire_status;
}
if (_sensorID[idx] == Unknown_DEVICE) {
String log = F("BMx280 : Unable to detect chip ID");
addLog(LOG_LEVEL_INFO, log);
return false;
}
return wire_status;
}
//**************************************************************************/
@@ -419,11 +212,16 @@ bool Plugin_028_check(uint8_t a) {
bool Plugin_028_begin(uint8_t a) {
if (! Plugin_028_check(a))
return false;
// Perform soft reset
Plugin_028_write8(BMx280_REGISTER_SOFTRESET, 0xB6);
delay(2); // Startup time is 2 ms (datasheet)
Plugin_028_readCoefficients(a);
delay(65); //May be needed here as well to fix first wrong measurement?
Plugin_028_readCoefficients(_i2caddr & 0x01);
// Set the Sensor in sleep to be make sure that the following configs will be stored
Plugin_028_write8(BME280_REGISTER_CONTROL, 0x00);
Plugin_028_write8(BME280_REGISTER_CONFIG, BME280_CONFIG_SETTING);
Plugin_028_write8(BME280_REGISTER_CONTROLHUMID, BME280_CONTROL_SETTING_HUMIDITY);
Plugin_028_write8(BME280_REGISTER_CONTROL, BME280_CONTROL_SETTING);
return true;
}
@@ -516,48 +314,45 @@ int16_t Plugin_028_readS16_LE(byte reg)
//**************************************************************************/
// Reads the factory-set coefficients
//**************************************************************************/
void Plugin_028_readCoefficients(uint8_t i2cAddress)
void Plugin_028_readCoefficients(uint8_t idx)
{
const uint8_t idx = Plugin_028_device_index(i2cAddress);
_bme280_calib[idx].dig_T1 = Plugin_028_read16_LE(BME280_REGISTER_DIG_T1);
_bme280_calib[idx].dig_T2 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_T2);
_bme280_calib[idx].dig_T3 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_T3);
_bme280_calib[idx].dig_T1 = Plugin_028_read16_LE(BMx280_REGISTER_DIG_T1);
_bme280_calib[idx].dig_T2 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_T2);
_bme280_calib[idx].dig_T3 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_T3);
_bme280_calib[idx].dig_P1 = Plugin_028_read16_LE(BME280_REGISTER_DIG_P1);
_bme280_calib[idx].dig_P2 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P2);
_bme280_calib[idx].dig_P3 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P3);
_bme280_calib[idx].dig_P4 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P4);
_bme280_calib[idx].dig_P5 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P5);
_bme280_calib[idx].dig_P6 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P6);
_bme280_calib[idx].dig_P7 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P7);
_bme280_calib[idx].dig_P8 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P8);
_bme280_calib[idx].dig_P9 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_P9);
_bme280_calib[idx].dig_P1 = Plugin_028_read16_LE(BMx280_REGISTER_DIG_P1);
_bme280_calib[idx].dig_P2 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P2);
_bme280_calib[idx].dig_P3 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P3);
_bme280_calib[idx].dig_P4 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P4);
_bme280_calib[idx].dig_P5 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P5);
_bme280_calib[idx].dig_P6 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P6);
_bme280_calib[idx].dig_P7 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P7);
_bme280_calib[idx].dig_P8 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P8);
_bme280_calib[idx].dig_P9 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_P9);
if (Plugin_028_hasHumidity()) {
_bme280_calib[idx].dig_H1 = Plugin_028_read8(BMx280_REGISTER_DIG_H1);
_bme280_calib[idx].dig_H2 = Plugin_028_readS16_LE(BMx280_REGISTER_DIG_H2);
_bme280_calib[idx].dig_H3 = Plugin_028_read8(BMx280_REGISTER_DIG_H3);
_bme280_calib[idx].dig_H4 = (Plugin_028_read8(BMx280_REGISTER_DIG_H4) << 4) | (Plugin_028_read8(BMx280_REGISTER_DIG_H4 + 1) & 0xF);
_bme280_calib[idx].dig_H5 = (Plugin_028_read8(BMx280_REGISTER_DIG_H5 + 1) << 4) | (Plugin_028_read8(BMx280_REGISTER_DIG_H5) >> 4);
_bme280_calib[idx].dig_H6 = (int8_t)Plugin_028_read8(BMx280_REGISTER_DIG_H6);
}
_bme280_calib[idx].dig_H1 = Plugin_028_read8(BME280_REGISTER_DIG_H1);
_bme280_calib[idx].dig_H2 = Plugin_028_readS16_LE(BME280_REGISTER_DIG_H2);
_bme280_calib[idx].dig_H3 = Plugin_028_read8(BME280_REGISTER_DIG_H3);
_bme280_calib[idx].dig_H4 = (Plugin_028_read8(BME280_REGISTER_DIG_H4) << 4) | (Plugin_028_read8(BME280_REGISTER_DIG_H4 + 1) & 0xF);
_bme280_calib[idx].dig_H5 = (Plugin_028_read8(BME280_REGISTER_DIG_H5 + 1) << 4) | (Plugin_028_read8(BME280_REGISTER_DIG_H5) >> 4);
_bme280_calib[idx].dig_H6 = (int8_t)Plugin_028_read8(BME280_REGISTER_DIG_H6);
}
//**************************************************************************/
// Read temperature
//**************************************************************************/
float Plugin_028_readTemperature(uint8_t i2cAddress)
float Plugin_028_readTemperature(uint8_t idx)
{
const uint8_t idx = Plugin_028_device_index(i2cAddress);
int32_t var1, var2;
// set to forced mode, i.e. "take next measurement"
Plugin_028_write8(BME280_REGISTER_CONTROL, BME280_CONTROL_SETTING);
// wait until measurement has been completed, otherwise we would read
// the values from the last measurement
while (Plugin_028_read8(BMx280_REGISTER_STATUS) & 0x08)
while (Plugin_028_read8(BME280_REGISTER_STATUS) & 0x08)
delay(1);
int32_t adc_T = Plugin_028_read24(BMx280_REGISTER_TEMPDATA);
int32_t adc_T = Plugin_028_read24(BME280_REGISTER_TEMPDATA);
adc_T >>= 4;
var1 = ((((adc_T >> 3) - ((int32_t)_bme280_calib[idx].dig_T1 << 1))) *
@@ -576,12 +371,10 @@ float Plugin_028_readTemperature(uint8_t i2cAddress)
//**************************************************************************/
// Read pressure
//**************************************************************************/
float Plugin_028_readPressure(uint8_t i2cAddress)
{
const uint8_t idx = Plugin_028_device_index(i2cAddress);
float Plugin_028_readPressure(uint8_t idx) {
int64_t var1, var2, p;
int32_t adc_P = Plugin_028_read24(BMx280_REGISTER_PRESSUREDATA);
int32_t adc_P = Plugin_028_read24(BME280_REGISTER_PRESSUREDATA);
adc_P >>= 4;
var1 = ((int64_t)t_fine) - 128000;
@@ -607,21 +400,9 @@ float Plugin_028_readPressure(uint8_t i2cAddress)
//**************************************************************************/
// Read humidity
//**************************************************************************/
float Plugin_028_readHumidity(uint8_t i2cAddress)
{
if (!Plugin_028_hasHumidity()) {
// No support for humidity
return 0.0;
}
// It takes at least 1.587 sec for valit measurements to complete.
// The datasheet names this the "T63" moment.
// 1 second = 63% of the time needed to perform a measurement.
const uint8_t idx = Plugin_028_device_index(i2cAddress);
unsigned long difTime = millis() - last_measurement[idx];
if (difTime < 1587) {
delay(1587 - difTime);
}
int32_t adc_H = Plugin_028_read16(BMx280_REGISTER_HUMIDDATA);
float Plugin_028_readHumidity(uint8_t idx) {
int32_t adc_H = Plugin_028_read16(BME280_REGISTER_HUMIDDATA);
int32_t v_x1_u32r;
@@ -657,7 +438,7 @@ float Plugin_028_readAltitude(float seaLevel)
// at high altitude. See this thread for more information:
// http://forums.adafruit.com/viewtopic.php?f=22&t=58064
float atmospheric = Plugin_028_readPressure(_i2caddr) / 100.0F;
float atmospheric = Plugin_028_readPressure(_i2caddr & 0x01) / 100.0F;
return 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903));
}
+11 -11
View File
@@ -137,14 +137,14 @@ boolean Plugin_035(byte function, struct EventStruct *event, String& string)
for (uint t = 0; t < c0; t++)
printWebString += F("0");
}
//So, as we receive a "1", and processed the counted 0s
//So, as we recieve a "1", and processed the counted 0s
//sending them as a ms timing into the buffer, we clear
//the 0s counter
c0 = 0;
} else {
//So, bit is 0
//On first call, ignore 0s (suppress left-most 0s)
//On first call, ignore 0s (supress left-most 0s)
if (c0+c1 != 0) {
//add 1 to counter c0
c0++;
@@ -154,11 +154,11 @@ boolean Plugin_035(byte function, struct EventStruct *event, String& string)
//add the total ms into the buffer (number of 1s
//multiplied by defined pulse length ms)
buf[idx++] = c1 * IrPLen;
//print the number of 1s just for debugging/info purposes
//print the number of 1s just for debuging/info purpouses
for (uint t = 0; t < c1; t++)
printWebString += F("1");
}
//So, as we receive a "0", and processed the counted 1s
//So, as we recieve a "0", and processed the counted 1s
//sending them as a ms timing into the buffer, we clear
//the 1s counter
c1 = 0;
@@ -199,13 +199,13 @@ boolean Plugin_035(byte function, struct EventStruct *event, String& string)
if (GetArgv(command, TmpStr1, 3)) IrCode = strtoul(TmpStr1, NULL, 16); //(long) TmpStr1
if (GetArgv(command, TmpStr1, 4)) IrBits = str2int(TmpStr1);
if (IrType.equalsIgnoreCase("NEC")) Plugin_035_irSender->sendNEC(IrCode, IrBits);
if (IrType.equalsIgnoreCase("JVC")) Plugin_035_irSender->sendJVC(IrCode, IrBits, 2);
if (IrType.equalsIgnoreCase("RC5")) Plugin_035_irSender->sendRC5(IrCode, IrBits);
if (IrType.equalsIgnoreCase("RC6")) Plugin_035_irSender->sendRC6(IrCode, IrBits);
if (IrType.equalsIgnoreCase("SAMSUNG")) Plugin_035_irSender->sendSAMSUNG(IrCode, IrBits);
if (IrType.equalsIgnoreCase("SONY")) Plugin_035_irSender->sendSony(IrCode, IrBits);
if (IrType.equalsIgnoreCase("PANASONIC")) Plugin_035_irSender->sendPanasonic(IrBits, IrCode);
if (IrType.equalsIgnoreCase(F("NEC"))) Plugin_035_irSender->sendNEC(IrCode, IrBits);
if (IrType.equalsIgnoreCase(F("JVC"))) Plugin_035_irSender->sendJVC(IrCode, IrBits, 2);
if (IrType.equalsIgnoreCase(F("RC5"))) Plugin_035_irSender->sendRC5(IrCode, IrBits);
if (IrType.equalsIgnoreCase(F("RC6"))) Plugin_035_irSender->sendRC6(IrCode, IrBits);
if (IrType.equalsIgnoreCase(F("SAMSUNG"))) Plugin_035_irSender->sendSAMSUNG(IrCode, IrBits);
if (IrType.equalsIgnoreCase(F("SONY"))) Plugin_035_irSender->sendSony(IrCode, IrBits);
if (IrType.equalsIgnoreCase(F("PANASONIC"))) Plugin_035_irSender->sendPanasonic(IrBits, IrCode);
}
addLog(LOG_LEVEL_INFO, F("IRTX :IR Code Sent"));
+133 -36
View File
@@ -16,17 +16,30 @@
#define PLUGIN_NAME_036 "Display - OLED SSD1306/SH1106 Framed"
#define PLUGIN_VALUENAME1_036 "OLED"
#define Nlines 12 // The number of different lines which can be displayed - each line is 32 chars max
#define P36_Nlines 12 // The number of different lines which can be displayed - each line is 32 chars max
#define P36_Nchars 32
#define P36_CONTRAST_OFF 1
#define P36_CONTRAST_LOW 64
#define P36_CONTRAST_MED 0xCF
#define P36_CONTRAST_HIGH 0xFF
#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
static int8_t lastWiFiState = P36_WIFI_STATE_UNSET;
// Instantiate display here - does not work to do this within the INIT call
OLEDDisplay *display=NULL;
char P036_deviceTemplate[P36_Nlines][P36_Nchars];
boolean Plugin_036(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
@@ -123,12 +136,11 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
optionValues3[4] = 32;
addFormSelector(string, F("Scroll"), F("plugin_036_scroll"), 5, options3, optionValues3, choice3);
char deviceTemplate[Nlines][32];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
LoadCustomTaskSettings(event->TaskIndex, (byte*)&P036_deviceTemplate, sizeof(P036_deviceTemplate));
for (byte varNr = 0; varNr < Nlines; varNr++)
for (byte varNr = 0; varNr < P36_Nlines; varNr++)
{
addFormTextBox(string, String(F("Line ")) + (varNr + 1), String(F("Plugin_036_template")) + (varNr + 1), deviceTemplate[varNr], 32);
addFormTextBox(string, 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]);
@@ -136,15 +148,16 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
addFormNumericBox(string, 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;
String options6[3];
options6[0] = F("Low");
options6[1] = F("Medium");
options6[2] = F("High");
int optionValues6[3];
optionValues6[0] = 64;
optionValues6[1] = 0xCF;
optionValues6[2] = 0xFF;
addFormSelector(string, F("Contrast"), F("plugin_066_contrast"), 3, options6, optionValues6, choice6);
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);
success = true;
break;
@@ -153,7 +166,7 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_SAVE:
{
//update now
timerSensor[event->TaskIndex]=millis();
timerSensor[event->TaskIndex] = millis() + (Settings.TaskDeviceTimer[event->TaskIndex] * 1000);
frameCounter=0;
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_036_adr"));
@@ -166,15 +179,14 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
String argName;
char deviceTemplate[Nlines][32];
for (byte varNr = 0; varNr < Nlines; varNr++)
for (byte varNr = 0; varNr < P36_Nlines; varNr++)
{
argName = F("Plugin_036_template");
argName += varNr + 1;
strncpy(deviceTemplate[varNr], WebServer.arg(argName).c_str(), sizeof(deviceTemplate[varNr]));
strncpy(P036_deviceTemplate[varNr], WebServer.arg(argName).c_str(), sizeof(P036_deviceTemplate[varNr]));
}
SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
SaveCustomTaskSettings(event->TaskIndex, (byte*)&P036_deviceTemplate, sizeof(P036_deviceTemplate));
success = true;
break;
@@ -182,9 +194,9 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
// // Load the custom settings from flash
// char deviceTemplate[Nlines][32];
// LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
lastWiFiState = P36_WIFI_STATE_UNSET;
// Load the custom settings from flash
LoadCustomTaskSettings(event->TaskIndex, (byte*)&P036_deviceTemplate, sizeof(P036_deviceTemplate));
// Init the display and turn it on
if (display)
@@ -202,9 +214,8 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
display->init(); // call to local override of init function
display->displayOn();
// Set the display contrast
uint8_t OLED_contrast = Settings.TaskDevicePluginConfig[event->TaskIndex][6];
display->setContrast(OLED_contrast);
P36_setContrast(OLED_contrast);
// Set the initial value of OnOff to On
UserVar[event->BaseVarIndex] = 1;
@@ -214,7 +225,7 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
// Display the device name, logo, time and wifi
display_header();
// display_logo();
display_logo();
display->display();
// Set up the display timer
@@ -273,6 +284,13 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
UserVar[event->BaseVarIndex] = 0; // Save the fact that the display is now OFF
}
}
if (UserVar[event->BaseVarIndex] == 1) {
// Display is on.
if (display && display_wifibars()) {
// WiFi symbol was updated.
display->display();
}
}
success = true;
break;
@@ -280,9 +298,6 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
case PLUGIN_READ:
{
char deviceTemplate[Nlines][32];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
// Clear the init screen if this is the first call
// if (firstcall)
// {
@@ -292,18 +307,19 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
// Define Scroll area layout
linesPerFrame = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
NFrames = Nlines / linesPerFrame;
NFrames = P36_Nlines / linesPerFrame;
// Now create the string for the outgoing and incoming frames
String tmpString[4];
String tmpString;
tmpString.reserve(P36_Nchars);
String newString[4];
String oldString[4];
// Construct the outgoing string
for (byte i = 0; i < linesPerFrame; i++)
{
tmpString[i] = deviceTemplate[(linesPerFrame * frameCounter) + i];
oldString[i] = parseTemplate(tmpString[i], 20);
tmpString = P036_deviceTemplate[(linesPerFrame * frameCounter) + i];
oldString[i] = P36_parseTemplate(tmpString, 20);
oldString[i].trim();
}
@@ -328,8 +344,8 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
// Contruct incoming strings
for (byte i = 0; i < linesPerFrame; i++)
{
tmpString[i] = deviceTemplate[(linesPerFrame * frameCounter) + i];
newString[i] = parseTemplate(tmpString[i], 20);
tmpString = P036_deviceTemplate[(linesPerFrame * frameCounter) + i];
newString[i] = P36_parseTemplate(tmpString, 20);
newString[i].trim();
if (newString[i].length() > 0) foundText = true;
}
@@ -362,15 +378,21 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase(F("OLEDFRAMEDCMD")))
if (tmpString.equalsIgnoreCase(F("OLEDFRAMEDCMD")) && display)
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
if (tmpString.equalsIgnoreCase(F("Off")))
display->displayOff();
P36_setContrast(P36_CONTRAST_OFF);
else if (tmpString.equalsIgnoreCase(F("On")))
display->displayOn();
else if (tmpString.equalsIgnoreCase(F("Low")))
P36_setContrast(P36_CONTRAST_LOW);
else if (tmpString.equalsIgnoreCase(F("Med")))
P36_setContrast(P36_CONTRAST_MED);
else if (tmpString.equalsIgnoreCase(F("High")))
P36_setContrast(P36_CONTRAST_HIGH);
}
break;
}
@@ -379,6 +401,67 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string)
return success;
}
// Set the display contrast
// really low brightness & contrast: contrast = 10, precharge = 5, comdetect = 0
// normal brightness & contrast: contrast = 100
void P36_setContrast(uint8_t OLED_contrast) {
char contrast = 100;
char precharge = 241;
char comdetect = 64;
switch (OLED_contrast) {
case P36_CONTRAST_OFF:
if (display) {
display->displayOff();
}
return;
case P36_CONTRAST_LOW:
contrast = 10; precharge = 5; comdetect = 0;
break;
case P36_CONTRAST_MED:
contrast = P36_CONTRAST_MED; precharge = 0x1F; comdetect = 64;
break;
case P36_CONTRAST_HIGH:
default:
contrast = P36_CONTRAST_HIGH; precharge = 241; comdetect = 64;
break;
}
if (display) {
display->displayOn();
display->setContrast(contrast, precharge, comdetect);
}
}
// Perform some specific changes for OLED display
String P36_parseTemplate(String &tmpString, byte lineSize) {
String result = parseTemplate(tmpString, lineSize);
// OLED lib uses this routine to convert UTF8 to extended ASCII
// http://playground.arduino.cc/Main/Utf8ascii
// Attempt to display euro sign (FIXME)
/*
const char euro[4] = {0xe2, 0x82, 0xac, 0}; // Unicode euro symbol
const char euro_oled[3] = {0xc2, 0x80, 0}; // Euro symbol OLED display font
result.replace(euro, euro_oled);
*/
/*
if (tmpString.indexOf('{') != -1) {
String log = F("Gijs: '");
log += tmpString;
log += F("' hex:");
for (int i = 0; i < tmpString.length(); ++i) {
log += F(" ");
log += String(tmpString[i], HEX);
}
log += F(" out hex:");
for (int i = 0; i < result.length(); ++i) {
log += F(" ");
log += String(result[i], HEX);
}
addLog(LOG_LEVEL_INFO, log);
}
*/
return result;
}
// The screen is set up as 10 rows at the top for the header, 10 rows at the bottom for the footer and 44 rows in the middle for the scroll region
void display_header() {
@@ -420,8 +503,14 @@ void display_title(String& title) {
}
void display_logo() {
// draw an xbm image.
display->drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_16);
display->setColor(BLACK);
display->fillRect(0, 14, 128, 64);
display->setColor(WHITE);
display->drawString(65, 15, F("ESP"));
display->drawString(65, 34, F("Easy"));
display->drawXbm(24, 14, espeasy_logo_width, espeasy_logo_height, espeasy_logo_bits);
}
// Draw the frame position
@@ -538,14 +627,19 @@ void display_scroll(String outString[], String inString[], int nlines, int scrol
}
}
//Draw Signal Strength Bars
void display_wifibars() {
//Draw Signal Strength Bars, return true when there was an update.
bool display_wifibars() {
const bool connected = WiFi.status() == WL_CONNECTED;
const int nbars_filled = (WiFi.RSSI() + 100) / 8;
const int newState = connected ? nbars_filled : P36_WIFI_STATE_UNSET;
if (newState == lastWiFiState)
return false; // nothing to do.
int x = 105;
int y = 0;
int size_x = 15;
int size_y = 10;
int nbars = 5;
int nbars_filled = (WiFi.RSSI() + 100) / 8;
int16_t width = (size_x / nbars);
size_x = width * nbars - 1; // Correct for round errors.
@@ -571,5 +665,8 @@ void display_wifibars() {
display->fillRect(xpos, y + size_y - 1, width - 1, 1);
}
}
} else {
// Draw a not connected sign.
}
return true;
}
+4 -44
View File
@@ -166,13 +166,11 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
// This is a private option only used by the MQTT 037 callback function
// Get the payload and check it out
String Payload = event->String2;
float floatPayload = string2float(Payload);
LoadTaskSettings(event->TaskIndex);
if (floatPayload == -999) {
String Payload = event->String2;
float floatPayload;
if (!string2float(Payload, floatPayload)) {
String log = F("IMPT : Bad Import MQTT Command ");
log += event->String1;
addLog(LOG_LEVEL_ERROR, log);
@@ -340,7 +338,7 @@ 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 (WiFi.status() != WL_CONNECTED) {
if (!WiFiConnected(1000)) {
return false; // Not connected, so no use in wasting time to connect to a host.
}
ControllerSettingsStruct ControllerSettings;
@@ -450,41 +448,3 @@ boolean MQTTCheckSubscription_037(String Topic, String Subscription) {
}
return false;
}
// ***************************************************************************
// Convert String to float - returns -999 in case of error
float string2float(String myString) {
int i, len;
float value;
len = myString.length();
char tmp[(len + 1)]; // one extra for the zero termination
byte start = 0;
// Look for decimal point - they can be anywhere but no more than one of them!
int dotIndex = myString.indexOf('.');
//Serial.println(dotIndex);
if (dotIndex != -1)
{
int dotIndex2 = (myString.substring(dotIndex + 1)).indexOf('.');
//Serial.println(dotIndex2);
if (dotIndex2 != -1)return -999.00; // Give error if there is more than one dot
}
if (myString.charAt(0) == '-') {
tmp[0] = '-';
start = 1; //allow a minus in front of string
}
for (i = start; i < len; i++)
{
tmp[i] = myString.charAt(i);
if (!isdigit(tmp[i]))
{
if (tmp[i] != '.')return -999;
}
}
tmp[i] = 0;
value = atof(tmp);
return value;
}

Some files were not shown because too many files have changed in this diff Show More