├── .deepsource.toml ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── ESPconfig.h ├── LICENSE ├── README.md ├── esp32AP.png ├── esp32config ├── esp32config.ino ├── library.properties ├── sysconfig32.h └── upload │ ├── 404.html │ └── index.html ├── esp32mqtt.png ├── esp32screenshot1.png ├── esp32wifi.png ├── esp8266admin.png ├── esp8266config ├── esp8266config.ino ├── library.properties ├── sysconfig8266.h └── upload │ ├── 404.html │ └── index.html ├── esp8266screenshot1.png └── library.properties /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "javascript" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | environment = ["browser"] 9 | style_guide = "standard" 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /ESPconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPCONFIG_H 2 | #define ESPCONFIG_H 3 | 4 | // Include appropriate sysconfig file based on the architecture 5 | #ifdef ESP32 6 | #include "sysconfig32/sysconfig32.h" 7 | #elif defined(ESP8266) 8 | #include "sysconfig8266/sysconfig8266.h" 9 | #endif 10 | 11 | // Other shared code or declarations 12 | 13 | #endif // ESPCONFIG_H -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESPconfig 2 | A configuration tool for ESP32 & ESP8266 devices 3 | 4 |

I work with ESP32 & ESP8266 for various embedded projects and I have found the Arduino IDE to be rather primitive compared to almost every other IDE I have used however it has one huge advantage, it gives me an easy to use tool and common core for a wide range of SOC based boards with Atmel, ARM, ESP and several other processors along with very easy uploading to the target

5 |

The IDE is of course targeted at hobbyists so many of the libraries are written by non-professional coders leading to code quality and license issues for commercial developers
6 | Some amateur code is very good, unfortunately I would not class the available web based ESP configuration tools among them

7 |

As ESP devices are very low cost and include WiFi, they are strong candidates for low cost WiFi enabled IOT devices

8 |

It is because of this that I have decided to integrate various code chunks from a few different projects into a library that will address the config problem

9 |

It is being developed with the following goals

10 |
    11 |
  1. Ease of use ✅
  2. 12 |
  3. Persistent settings using a config file stored in SPIFFS ✅
  4. 13 |
  5. Time setting functions ✅
  6. 14 |
  7. OTA updates ✅
  8. 15 |
  9. User control ✅
  10. 16 |
  11. Online registration of the user & device (work in progress)❌
  12. 17 |
  13. Shared login update across multiple devices on the same subnet (work in progress) ❌
  14. 18 |
  15. (ESP32 only) Ability to login to multiple WiFi access points
  16. 19 |
  17. Hotspot, WiFi ✅
  18. 20 |
  19. (ESP8266 only) NAT extender✅
  20. 21 |
  21. For ESP32, Bluetooth configuration ✅
  22. 22 |
  23. Extendable config pages with easy to use form building objects
  24. 23 |
  25. Class based for ease of integration and use ✅
  26. 24 |
  27. Easy to brand by adding your own logo image and favicon ✅
  28. 25 |
  29. Help/About page supported and loaded from SPIFFS ✅
  30. 26 |
27 |

Arduino provides an easy path to OTA but its on constantly making it a security risk and it does not offer an easy to use file uploader

28 |

Some of the existing config systems use EEPROM emulation on ESP devices which does not incorporate wear leveling leading to relatively low write count and reliability issues

29 |

None of the config systems I have found offer an easy to use time setting function with NTP support

30 |

None seem to offer even the most basic login security

31 |

This work is FOSS under the Mozilla license.

32 |

https://github.com/peterjazenga/ESPconfig

33 |

 

34 |

Required: https://github.com/me-no-dev/arduino-esp32fs-plugin &
https://github.com/esp8266/arduino-esp8266fs-plugin

35 |

The files contained in the relevant upload folder must be uploaded for ESPconfig to function properly

36 | Built against time library from https://github.com/PaulStoffregen/Time or http://playground.arduino.cc/Code/Time version 1.5.0 37 | -------------------------------------------------------------------------------- /esp32AP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterjazenga/ESPconfig/5719a00ad6cfa4a22d50004bf8b482d33ad5aa4c/esp32AP.png -------------------------------------------------------------------------------- /esp32config/esp32config.ino: -------------------------------------------------------------------------------- 1 | /* author: Peter Dunne, +44 7932 676 847 peterjazenga@gmail.com 2 | * purpose: to control a relay or SSR via radio signal or WiFi signal 3 | * requirements: serial interface for radio, read only mode, initial design uses 433 mhz receiver 4 | * WiFi interface to facilitate remote control using JSON packets 5 | * Web interface to Configure WiFi interface and define control parameters for the radio transmitter device 6 | * Bluetooth (ESP32 only) control and Configuration interface to phones/tablets/etc. 7 | * 8 | * This module imports code by Peter Dunne from previous ESP projects in power sensing, RC and on/off power switches 9 | * 10 | * sysConfig.init(); is called after Serial.begin(); and it handles all WiFi, OTA, NAT, Time setting and Bluetooth configuration 11 | * WPS is also supported via sysConfig 12 | * sysConfig.run(); keeps things updated, provides for servicing of the OTA & Web server issues among others, it also handles the blinking of the status LED 13 | */ 14 | 15 | #include "sysconfig32.h"; 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | sysConfig.init(); 20 | Serial.println("Ready."); 21 | } 22 | 23 | void loop() { 24 | sysConfig.run(); 25 | } 26 | -------------------------------------------------------------------------------- /esp32config/library.properties: -------------------------------------------------------------------------------- 1 | name=sysConfig 2 | version=0.1 3 | author=Peter Dunne 4 | maintainer=Peter Dunne 5 | sentence=ESP8266/ESP32 WiFi/AP web configuration. 6 | paragraph=sysConfig will start up in AP (access point) mode, and provide a config portal for entering WiFi connection, bluetooth, time and access control settings. configuration and support files are stored in SPIFFS. It has been designed for easy branding and includes OTA function 7 | url=https://github.com/peterjazenga/ESPconfig 8 | architectures=esp32 9 | includes=sysConfig32.h -------------------------------------------------------------------------------- /esp32config/sysconfig32.h: -------------------------------------------------------------------------------- 1 | /* author: Peter Dunne, +44 7932 676 847 peterjazenga@gmail.com 2 | * purpose: to provide an effective configuration portal and the basis of ESP32 & ESP8266 IOT projects 3 | * Bluetooth (ESP32 only) control and Configuration interface to phones/tablets/etc. 4 | * the CSS file used is w3.css as it is compact and free to use 5 | * the js file w3.js provides enough functions to enable compact devices like the ESP32 & ESP8266 with reasonable web interfaces 6 | * https://www.w3schools.com/w3js/default.asp 7 | * https://www.w3schools.com/w3css/default.asp 8 | * https://www.w3schools.com/html/default.asp 9 | * the author is not affiliated with w3schools however its a clear source of useful information on html, css and several programming languages 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "esp_wps.h" 18 | #include 19 | #include 20 | #include "FS.h" 21 | #include "SPIFFS.h" 22 | /* BLEDevice & BLEServer are mutually exclusive 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "esp_bt_main.h" 30 | #include "esp_bt_device.h" 31 | #include"esp_gap_bt_api.h" 32 | #include "esp_err.h"*/ 33 | 34 | #include "sys/time.h" 35 | #include "esp_sleep.h" 36 | #include "time.h" 37 | 38 | 39 | #define ESP_WPS_MODE WPS_TYPE_PBC 40 | #define ESP_MANUFACTURER "ESPRESSIF" 41 | #define ESP_MODEL_NUMBER "ESP32" 42 | #define ESP_MODEL_NAME "ESPRESSIF IOT" 43 | #define ESP_DEVICE_NAME "ESP STATION" 44 | 45 | #define NAPT 1000 46 | #define NAPT_PORT 10 47 | // utility routines 48 | #ifndef LED_BUILTIN 49 | #ifdef ESP32 50 | #define LED_BUILTIN 2 // ESP32 built-in LED (GPIO 2) 51 | #elif defined(ESP8266) 52 | #define LED_BUILTIN 2 // ESP8266 built-in LED (GPIO 2) 53 | #else 54 | #define LED_BUILTIN 13 // Default to pin 13 if no board matches 55 | #endif 56 | #endif 57 | // define a structure for on/off timers to control the device activity 58 | typedef struct { 59 | time_t startTime; 60 | time_t endTime; 61 | byte dow;// used as a set of flags to define what day of the week its active 62 | // the msb is the enable bit for the timer 63 | } ttimer; 64 | 65 | typedef struct { 66 | char WiFiname[32]; 67 | char WiFipassword[32]; 68 | } WiFiParams; 69 | 70 | typedef struct { 71 | WiFiParams AccessPoints[5]; 72 | char APname[32]; 73 | char APpassword[32]; 74 | IPAddress ip; 75 | IPAddress gateway; 76 | IPAddress subnet; 77 | byte APchannel; 78 | char BLEname[32]; 79 | char BLEpassword[32]; 80 | byte ConfigPage; 81 | byte BLEConfig; 82 | byte APconfig; 83 | byte sensorConfig; 84 | byte timerConfig; 85 | time_t TZ; // defaults to GMT, offset in seconds 86 | time_t DST; // daylight saving time 87 | char NTPserver[128]; 88 | float setPoint; // also used as setPoint for PID loops 89 | float rangeValue; 90 | time_t min_on; 91 | time_t max_on; 92 | time_t min_off; 93 | byte OTA; 94 | char OTApass[32]; 95 | char MQTTserver[128]; 96 | byte MQTTport; 97 | char MQTTuser[32]; 98 | char MQTTpass[32]; 99 | float iceGuard; //used by heating and cooling to prevent icing, must be >0 to be active 100 | bool activeHigh; // heating activates when temperature drops below the lower trigger value 101 | bool PIDcontrolled; // if running on a PID, the value used for setPoint is setPoint 102 | ttimer timers[32]; // all timers default to inactive and zero values 103 | short burncount; 104 | time_t burntime; 105 | char userName[32]; 106 | char userPass[32]; 107 | char userEmail[128]; 108 | char firstname[32]; 109 | char lastname[32]; 110 | char phone[32]; 111 | char URL[128]; 112 | char NodeName[32]; 113 | //char bufferValue[32]; 114 | time_t regDate; 115 | long regID; 116 | long checksum; 117 | } dataframe; 118 | 119 | typedef struct { 120 | String css; 121 | String value; 122 | String placeholder; 123 | String label; 124 | String name; 125 | boolean required; 126 | String inlineJS; // this is what is included with the component on the page 127 | String functionalJS;// needs to be cleared each time as its meant to be added to the code library only once 128 | String hint; // adds an acronym object using the label as the key text 129 | } htmlproperties; 130 | 131 | // defines 132 | #define NaN -1 133 | #define NoString NaN-1 134 | #define Range NoString-1 135 | #define RangeLow Range-1 136 | #define RangeHigh RangeLow-1 137 | #define NotFound RangeHigh-1 138 | #define InvalidTime NotFound-1 139 | #define BadAddress InvalidTime-1 140 | #define OK 0 141 | 142 | #define FAST_BLINK 20 // use for errors 143 | #define SLOW_BLINK 50 // use for standard operations 144 | #define PT_IDLE 0b10100000101000001010000010100000 145 | #define PT_UPLOADING 0b10101010101010101010101010101010 146 | #define PT_CONNECTED 0b10001000100010001000100010001000 147 | #define PT_SCANNING 0b11010000110100001101000011010000 148 | #define SCAN_PERIOD 5000 149 | #define CONNECT_PERIOD 500 150 | 151 | // global variables 152 | IPAddress ip(192,168,4,1); 153 | IPAddress gateway(192,168,4,1); 154 | IPAddress subnet(255,255,255,0); 155 | byte APchannel = 11; 156 | unsigned int localPort = 2390; // local port to listen for UDP packets 157 | 158 | // main classes for Configuration management, time management and NAT 159 | enum s_class {s_none, s_byte, s_int32_t, s_float, s_text};// used by the select functions 160 | enum eSensorClass {s_undefined, s_NTC, s_BMP, s_BME, s_ADC, s_Freq, s_PWM, s_Weight}; 161 | 162 | typedef std::function TTimerFunction; 163 | String HTML; 164 | char buffer[256]; 165 | dataframe _data; // the data is contained in the private section as its not meant to be directly interatecd with by the main program 166 | //dataframe _formdata; // the data contained herein is used to process the form data 167 | 168 | class tSysConfig{ 169 | private: 170 | // LED information for heartbeat LED 171 | long lastBlinkMillis; 172 | int32_t blinkstate=5;// defines which blink is used, 0-3 are slow 4-7 are fast blink 173 | int32_t LEDstate=0;//inidicates which bit of the pattern is in use 174 | // WiFi connection information 175 | long currentMillis = 0; 176 | long lastScanMillis; 177 | long lastConnectMillis; 178 | // network scanning info 179 | bool STAconnected=false; 180 | int32_t n=-2; 181 | String ssid; 182 | uint8_t encryptionType; 183 | int32_t RSSI; 184 | uint8_t* BSSID; 185 | int32_t channel; 186 | bool isHidden; 187 | protected: 188 | uint32_t ideSize; 189 | FlashMode_t ideMode; 190 | int32_t error; // used singularly during form processing, each new element resets this 191 | int32_t errorcount; 192 | // String HTML; // used to build the web page 193 | // char buffer[256]; 194 | bool inForm; 195 | bool inFieldset; 196 | s_class inSelect; // if we are in a select group we need to know the class so it processes the correct information 197 | bool inOptgroup; 198 | bool lightHTML; 199 | public: 200 | int32_t configPin = 1; 201 | char *author; 202 | char *copyright; 203 | char *version; 204 | int32_t charsize; 205 | int32_t major; 206 | int32_t minor; 207 | bool hasBluetooth=true; 208 | // the sensor classes are for future use 209 | eSensorClass SensorClass=s_undefined; 210 | String SensorName; 211 | int SensorFrequency=100; // time in milliseconds 212 | public: 213 | // this is API to the Config system but the only routines that the user is required to utilize are tSysConfig(); & run(); 214 | // if desired, the device name can be changed prior to calling init 215 | htmlproperties webobj; 216 | WebServer server; 217 | WiFiMulti multiWiFi; 218 | WiFiUDP udp; 219 | /* this is meant to engage an automated Configuration mode that connects to a predefined WiFi and then calls some functions to get the logo, CSS, about, help and initConfig files 220 | * firstrun passes the device Mac number to the called program, this then sets a unique login ID for the device Configuration file 221 | * firstrun also exposes the AP with the default device name in the format of TRL-xxxxxx with the password of TRLinitialize 222 | */ 223 | void initNTP(); // time system 224 | void initWiFi(); 225 | void scanWiFi(); 226 | void initWebserver(); // sets up the network and servers 227 | bool readConfig();// reads from the Configuration file, also enters system defaults to complete initialization routines 228 | void initConfig();// reads the Configuration file, also responsiible for calling firstrun if the Config files do not exist 229 | bool writeConfig();// writes to the Configuration file 230 | void updateConfig();// reinitialize the unit 231 | void OTAinit(); // Over the air update system management 232 | void blink(); 233 | void init(); // startup code 234 | void run(); // called from the loop code to maintain periodic functions 235 | // there are lots of web functions as this is a web based Configuration program 236 | // procedures to handle forms 237 | boolean isinteger(String str); 238 | boolean isFloat(String str); 239 | boolean isTime(String str); 240 | boolean isIP(String str); 241 | 242 | // copy values from post function is overloaded and has default parameters, if min-max are equal, range is ignored otherwise range checking is used 243 | int32_t copyval(byte &var, char const *name, byte min=0, byte max=0); 244 | int32_t copyval(int32_t &var, char const *name, int32_t min=0, int32_t max=0); 245 | int32_t copyval(float &var, char const *name, float min=0, float max=0); 246 | int32_t copyval(char* var, char const *name, int32_t size, int32_t min=0); 247 | int32_t copyval(time_t &var, char const *name); 248 | int32_t copyval(bool &var, char const *name); // checkbox is unlike other fields, if its checked, it is included otherwise the field is not returned at all by the form post 249 | int32_t copyIP(IPAddress &var, char const *name); 250 | 251 | // form creation support 252 | void framehead();// to provide the header for all frame pages 253 | bool form(htmlproperties obj);// all forms are post request only 254 | bool form(); // if the buttoncaption is not included, then the standard send button is created 255 | void tab(char* tag); 256 | void fieldset(char* tag); // use to create groupboxes on the form 257 | void fieldset(); 258 | void label(htmlproperties obj); 259 | bool edit(htmlproperties obj, char* data, int32_t size); 260 | bool editurl(htmlproperties obj, char* data, int32_t size); 261 | bool editemail(htmlproperties obj, char* data, int32_t size); 262 | bool edittel(htmlproperties obj, char* data, int32_t size); 263 | bool edit(htmlproperties obj, time_t &data); 264 | bool edit(htmlproperties obj, byte &data, byte min=0, byte max=0); 265 | bool edit(htmlproperties obj, int32_t &data, int32_t min=0, int32_t max=0); 266 | bool edit(htmlproperties obj, float &data, float min=0.0, float max=0.0); 267 | // unlike other fields, password auto includes Label & verify dialog 268 | bool password(htmlproperties obj, char* data, int32_t size, int32_t min=0, int32_t max=0); 269 | bool text(htmlproperties obj, char* data, int32_t size, int32_t min=0, int32_t max=0); 270 | 271 | bool selectList(htmlproperties obj,int32_t &data); 272 | bool selectbyte(htmlproperties obj,byte &data); 273 | bool selectList(htmlproperties obj,float &data); 274 | bool selectList(htmlproperties obj,char* data, int32_t size);// using this forces options to use the name field as value 275 | bool selectList();// terminates the list 276 | bool optiongroup(char const *name); //groups a value list 277 | bool optiongroup(); //terminates the group 278 | 279 | bool option(bool data, char *name); 280 | bool option(byte data, char *name); 281 | bool option(int32_t data, char *name); 282 | bool option(float data, char *name); 283 | bool option(char* data, char *name); 284 | bool checkbox(htmlproperties obj, bool &data); 285 | bool checkbox(htmlproperties obj, int32_t &data); 286 | bool checkbox(htmlproperties obj, char* data, int32_t size); 287 | bool radio(htmlproperties obj, int32_t &data); 288 | bool radio(htmlproperties obj, char* data, int32_t size); 289 | // additional html elements of significant use to us 290 | // https://www.w3schools.com/tags/tag_meter.asp 291 | void meter(htmlproperties obj, int32_t value, int32_t min=0, int32_t max=0); 292 | void meter(htmlproperties obj, float value, float min =0, float max =0); 293 | // https://www.w3schools.com/tags/tag_progress.asp 294 | void progress(htmlproperties obj, int32_t value, int32_t min=0, int32_t max=0); 295 | void progress(htmlproperties obj, float value, float min =0, float max =0); 296 | // https://www.w3schools.com/tags/tag_details.asp 297 | void details(htmlproperties obj); 298 | void div(); 299 | 300 | // additional utility routines 301 | String formatbytes(size_t bytes); 302 | 303 | // server page support functions 304 | void getCharts();// does the charting page 305 | void drawGraph();// draws the actual image 306 | void getIcon(); 307 | void indexPage(void); 308 | 309 | void handleNotFound(); 310 | // to support a Configuration application, we have the JSON data exchanges, there are no individual pages in the JSON processing 311 | void getJSON();// format bytes 312 | }; 313 | 314 | void tSysConfig::blink() { 315 | int32_t t=SLOW_BLINK; 316 | if (blinkstate>3) {t=FAST_BLINK;} 317 | if (currentMillis - lastBlinkMillis > t) 318 | { 319 | LEDstate++; 320 | if (LEDstate>31){LEDstate=0;} 321 | switch (blinkstate){ 322 | case 0: 323 | case 4:{digitalWrite(LED_BUILTIN,(bool) PT_IDLE>>LEDstate ? true : false); break;} 324 | case 5: 325 | case 1:{digitalWrite(LED_BUILTIN,(bool) PT_UPLOADING>>LEDstate ? true : false); break;} 326 | case 6: 327 | case 2:{digitalWrite(LED_BUILTIN,(bool) PT_CONNECTED>LEDstate ? true : false); break;} 328 | case 7: 329 | case 3:{digitalWrite(LED_BUILTIN,(bool) PT_SCANNING>>LEDstate ? true : false); break;} 330 | } 331 | lastBlinkMillis = currentMillis; 332 | } 333 | } 334 | 335 | bool tSysConfig::readConfig(){ 336 | // read the parameters from flash 337 | Serial.println("Opening SPIFFS /config.bin"); 338 | File ConfigFile = SPIFFS.open("/config.bin", "r"); 339 | if (!ConfigFile) { 340 | Serial.println("Failed to open Config file, attempting to load manufacturer's configuration"); 341 | ConfigFile = SPIFFS.open("/defaults.bin", "r"); 342 | if (!ConfigFile) {Serial.println("No manufacturers config file"); return false;} 343 | } 344 | size_t size = ConfigFile.size(); 345 | if (size != sizeof(_data)) { 346 | Serial.println("Config file size is invalid"); 347 | Serial.print(size); 348 | Serial.println(":file size"); 349 | ConfigFile.close(); 350 | return false; 351 | } 352 | ConfigFile.read((byte*) &_data, sizeof(_data)); 353 | ConfigFile.close(); 354 | if (_data.OTA==3){_data.OTA=4;}// ensures OTA is off at reboot 355 | return true; 356 | } 357 | bool tSysConfig::writeConfig() { 358 | File configFile = SPIFFS.open("/config.bin", "w"); 359 | if (!configFile) { 360 | Serial.println("Failed to open config file for writing"); 361 | return false; 362 | } 363 | ++_data.burncount; 364 | _data.burntime=time(nullptr); 365 | configFile.write((byte*) &_data, sizeof(_data)); 366 | configFile.close(); 367 | SPIFFS.end(); 368 | SPIFFS.begin(); 369 | Serial.println("config.bin written"); 370 | return readConfig(); 371 | } 372 | 373 | void tSysConfig::updateConfig() { 374 | // intended to reinitialize the ESP without rebooting 375 | } 376 | 377 | void tSysConfig::OTAinit(){ 378 | ArduinoOTA.onStart([]() { 379 | String type; 380 | if (ArduinoOTA.getCommand() == U_FLASH) 381 | type = "sketch"; 382 | else // U_SPIFFS 383 | type = "filesystem"; 384 | // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() 385 | Serial.println("Start updating " + type); 386 | }); 387 | ArduinoOTA.onEnd([]() { 388 | Serial.println("\nEnd"); 389 | }); 390 | ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { 391 | Serial.printf("Progress: %u%%\r", progress / (total / 100)); 392 | }); 393 | ArduinoOTA.onError([](ota_error_t error) { 394 | Serial.printf("Error[%u]: ", error); 395 | if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); 396 | else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); 397 | else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); 398 | else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); 399 | else if (error == OTA_END_ERROR) Serial.println("End Failed"); 400 | }); 401 | ArduinoOTA.setHostname(_data.APname); 402 | ArduinoOTA.begin(); 403 | } 404 | 405 | void tSysConfig::initConfig() { 406 | if(!SPIFFS.begin()) 407 | { 408 | Serial.println("SPIFFS Initialization...failed"); 409 | } else { 410 | readConfig(); 411 | Serial.print("Last Config:"); 412 | Serial.println(_data.burntime); 413 | Serial.print("Burn count:"); 414 | Serial.println(_data.burncount); 415 | } 416 | if (_data.burncount == 0) { 417 | Serial.print("Init failure: "); 418 | // initialize the flash memory 419 | strlcpy(_data.AccessPoints[0].WiFiname,"DEFAULT",32); 420 | strlcpy(_data.AccessPoints[0].WiFipassword,"DEFAULT",32); 421 | strlcpy(_data.APname,"TRL_Device",32); 422 | strlcpy(_data.APpassword,"12345678",32); 423 | // Set a static ip address for the Access point mode 424 | // This can be used to directly connect to it instead of having to have a local network 425 | _data.ip = ip; 426 | _data.gateway = gateway; 427 | _data.subnet = subnet; 428 | _data.APchannel = APchannel; 429 | strlcpy(_data.BLEname,"TRL_Device",32); 430 | strlcpy(_data.BLEpassword,"1111",32); 431 | strlcpy(_data.userName,"admin",32); 432 | strlcpy(_data.userPass,"admin",32); 433 | _data.ConfigPage=1;// always available 434 | _data.BLEConfig=1; // always on 435 | _data.APconfig=1; // softap is always available 436 | _data.sensorConfig=2; // heating 437 | _data.timerConfig=2; //defaults to timer only mode 438 | strlcpy(_data.NTPserver,"north-america.pool.ntp.org",128); 439 | 440 | _data.TZ=120; // defaults to GMT 441 | _data.DST=60; 442 | _data.setPoint=0; // also used as setPoint for PID loops 443 | _data.rangeValue=0; 444 | _data.iceGuard=0; //used by heating and cooling to prevent icing, must be >0 to be active 445 | _data.activeHigh=false; // heating activates when temperature drops below the lower trigger value 446 | _data.PIDcontrolled=true; // if running on a PID, the value used for setPoint is setPoint*/ 447 | // initialize the timers to zero hours on zero days 448 | for ( byte i = 0; i < 5; i++ ) { 449 | _data.timers[i].startTime=86400; 450 | _data.timers[i].endTime=86400; 451 | } 452 | Serial.println("Default parameters loaded"); 453 | } 454 | } 455 | void tSysConfig::initWiFi(){ 456 | byte retries = 0; 457 | WiFi.mode(WIFI_AP_STA); 458 | WiFi.disconnect(); 459 | // scan for available networks 460 | scanWiFi(); 461 | for ( byte i = 0; i < 5; i++ ) { 462 | multiWiFi.addAP(_data.AccessPoints[i].WiFiname, _data.AccessPoints[i].WiFipassword); 463 | } 464 | WiFi.beginSmartConfig(); 465 | 466 | // WiFi.begin(_data.AccessPoints[0].WiFiname, _data.AccessPoints[0].WiFipassword); 467 | // wait for connection here 468 | while ((multiWiFi.run() != WL_CONNECTED) && (retries<30)) { 469 | delay(500); 470 | Serial.print("."); 471 | ++retries; 472 | } 473 | if (WiFi.status() == WL_CONNECTED){ 474 | STAconnected=true; 475 | Serial.println(""); 476 | Serial.println(F("WiFi connected")); 477 | Serial.println(F("IP address: ")); 478 | Serial.println(WiFi.localIP()); 479 | /*Serial.println(F("Starting Time UDP")); 480 | udp.begin(localPort); 481 | Serial.print(F("Local port: ")); 482 | Serial.println(udp.localPort());*/ 483 | } 484 | else{ 485 | Serial.println(F("WiFi failed to connect")); 486 | } 487 | WiFi.softAPConfig(_data.ip,_data.gateway,_data.subnet); 488 | // check if wifi is connected and what the AP rules are 489 | // Turn on local Access point 490 | switch (_data.APconfig){ 491 | case 0: break; 492 | case 1:{} 493 | case 2:{// enables softap using user IP settings, it has no code as the execution simply flows on to case 3: 494 | } 495 | case 3: {// enable AP, with android-compatible google domain 496 | if (_data.APconfig==3){ 497 | WiFi.softAPConfig( 498 | IPAddress(172, 217, 28, 254), 499 | IPAddress(172, 217, 28, 254), 500 | IPAddress(255, 255, 255, 0)); 501 | } 502 | // give DNS servers to AP side 503 | /* dhcps_set_dns(0, WiFi.dnsIP(0)); 504 | dhcps_set_dns(1, WiFi.dnsIP(1));*/ 505 | WiFi.softAP(_data.APname, _data.APpassword, _data.APchannel); 506 | /* err_t ret = ip_napt_init(NAPT, NAPT_PORT); 507 | if (ret == ERR_OK) { 508 | ret = ip_napt_enable_no(SOFTAP_IF, 1); 509 | if (ret == ERR_OK) { 510 | } 511 | }*/ 512 | break; 513 | } 514 | case 4: {}// mesh mode 515 | } 516 | if (WiFi.status() != WL_CONNECTED){ 517 | WiFi.softAP(_data.APname, _data.APpassword, _data.APchannel); 518 | Serial.println(F("WiFi AP started"));} 519 | Serial.println(_data.APname); 520 | Serial.println(_data.APpassword); 521 | Serial.println(_data.APchannel); 522 | } 523 | 524 | void tSysConfig::initNTP() { 525 | configTime(_data.TZ, _data.DST, _data.NTPserver); 526 | } 527 | 528 | void tSysConfig::initWebserver() { 529 | server.on("/", [&]{ indexPage(); }); 530 | server.on("/index", [&]{ indexPage(); }); 531 | server.on("/index.htm", [&]{ indexPage(); }); 532 | server.on("/index.html", [&]{ indexPage(); }); 533 | 534 | server.on("/favicon.ico", [&] { getIcon();} ); 535 | server.on("/data.json", [&]{ getJSON();} ); 536 | 537 | server.onNotFound([&](){ handleNotFound(); }); 538 | server.begin(); 539 | Serial.println('server startup'); 540 | } 541 | 542 | 543 | void tSysConfig::init() { 544 | WiFi.persistent(false); 545 | pinMode(LED_BUILTIN, OUTPUT); 546 | ideMode = ESP.getFlashChipMode(); 547 | Serial.printf(" ESP32 Chip revision = %d\n\r", ESP.getChipRevision()); 548 | Serial.printf("\n\nSdk version: %s\n", ESP.getSdkVersion()); 549 | Serial.printf("CPU Frequency: %u MHz\n", ESP.getCpuFreqMHz()); 550 | Serial.printf("Flash size: %u bytes\n\r", ESP.getFlashChipSize()); 551 | Serial.printf("Flash speed: %u Hz\n\r", ESP.getFlashChipSpeed()); 552 | Serial.printf("Flash mode: %s\n\r", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN")); 553 | 554 | Serial.print("Compilation date:"); 555 | Serial.print(__DATE__); 556 | Serial.print(" @ "); 557 | Serial.println(__TIME__); 558 | initConfig(); 559 | initWiFi(); 560 | initWebserver(); 561 | initNTP(); 562 | OTAinit(); // OTA update services 563 | } 564 | 565 | void tSysConfig::run() { 566 | // as there is no stop or end function in ArduinoOTA, this hack is used to stop it functioning 567 | // there is no provision for on demand update in the code yet 568 | // noob value is to activate OTA 569 | switch (_data.OTA){ 570 | case 0: ArduinoOTA.handle(); break; 571 | case 2:if (millis()<300000){ ArduinoOTA.handle();} break; // active on boot for 5 minutes 572 | case 4:break; // totally stopped 573 | default: ArduinoOTA.handle(); 574 | } 575 | server.handleClient(); 576 | // MDNS.update(); /////////////////////////////////////////////////////////////////////////////////////// 577 | currentMillis = millis(); 578 | blink(); 579 | } 580 | 581 | void tSysConfig::scanWiFi(){/* 582 | bool isConnected=WiFi.status() == WL_CONNECTED; 583 | int32_t retries=0; 584 | WiFi.mode(WIFI_AP_STA); 585 | WiFi.disconnect(); 586 | // scan for available networks 587 | n = WiFi.scanNetworks(); 588 | for (int32_t i = 0; i < n; i++) 589 | { 590 | WiFi.getNetworkInfo(i, ssid, encryptionType, RSSI, BSSID, channel, isHidden); 591 | Serial.printf("%d: %s, Ch:%d (%ddBm) %s %s\r\n", i + 1, ssid.c_str(), channel, RSSI, encryptionType == ENC_TYPE_NONE ? "open" : "", isHidden ? "hidden" : ""); 592 | } 593 | if (isConnected){ 594 | WiFi.begin(_data.AccessPoints[0].WiFiname, _data.AccessPoints[0].WiFipassword); 595 | // wait for connection here 596 | while ((WiFi.status() != WL_CONNECTED) && (retries<10)) { 597 | delay(1500); 598 | Serial.print("."); 599 | ++retries; 600 | } 601 | }*/ 602 | } 603 | 604 | // format bytes 605 | String tSysConfig::formatbytes(size_t bytes) { 606 | if (bytes < 1024) { 607 | return String(bytes) + "B"; 608 | } else if (bytes < (1024 * 1024)) { 609 | return String(bytes / 1024.0) + "KB"; 610 | } else if (bytes < (1024 * 1024 * 1024)) { 611 | return String(bytes / 1024.0 / 1024.0) + "MB"; 612 | } else { 613 | return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB"; 614 | } 615 | } 616 | 617 | boolean tSysConfig::isinteger(String str){ // check the input is an integer 618 | for(byte i=0;i255){ return false;} 669 | if (b.toInt()>255){ return false;} 670 | if (c.toInt()>255){ return false;} 671 | if (d.toInt()>255){ return false;} 672 | return true; 673 | } 674 | // copy values from post function is overloaded and has default parameters, if min-max are equal, range is ignored otherwise range checking is used 675 | 676 | int32_t tSysConfig::copyval(byte &var, char const *name, byte min, byte max){ 677 | String V; 678 | error = 0; 679 | if (server.hasArg(name)) { 680 | V=server.arg(name); 681 | if ((V.length()<1)|(!isinteger(V))){ 682 | errorcount++; 683 | error=NaN; 684 | return NaN; 685 | } 686 | var=(byte)V.toInt(); 687 | if(max!=min){ 688 | if ((var<=max)&&(var>=min)){ 689 | error = OK; 690 | return OK; 691 | } 692 | errorcount++; 693 | error = Range; 694 | return Range; 695 | } 696 | return OK; } 697 | else{ 698 | errorcount++; 699 | error = NotFound; 700 | return NotFound; 701 | } 702 | } 703 | 704 | int32_t tSysConfig::copyval(int32_t &var, char const *name, int32_t min, int32_t max){ 705 | String V; 706 | error = 0; 707 | if (server.hasArg(name)) { 708 | V=server.arg(name); 709 | if ((V.length()<1)|(!isinteger(V))){ 710 | errorcount++; 711 | error=NaN; 712 | return NaN; 713 | } 714 | var=V.toInt(); 715 | if(max!=min){ 716 | if ((var<=max)&&(var>=min)){ 717 | error = OK; 718 | return OK; 719 | } 720 | errorcount++; 721 | error = Range; 722 | return Range; 723 | } 724 | return OK; 725 | } 726 | else{ 727 | errorcount++; 728 | error = NotFound; 729 | return NotFound; 730 | } 731 | } 732 | int32_t tSysConfig::copyval(float &var, char const *name, float min, float max){ 733 | String V; 734 | error = 0; 735 | if (server.hasArg(name)) { 736 | V=server.arg(name); 737 | if ((V.length()<1)|(!isFloat(V))){ 738 | errorcount++; 739 | error=NaN; 740 | return NaN; 741 | } 742 | var=V.toFloat(); 743 | if(max!=min){ 744 | if ((var<=max)&&(var>=min)){ 745 | error = OK; 746 | return OK; 747 | } 748 | errorcount++; 749 | error = Range; 750 | return Range; 751 | } 752 | return OK; 753 | } 754 | else{ 755 | errorcount++; 756 | error = NotFound; 757 | return NotFound; 758 | } 759 | } 760 | 761 | int32_t tSysConfig::copyval(time_t &var, char const *name){ 762 | String V; 763 | String H; 764 | String M; 765 | error = 0; 766 | 767 | time_t t; 768 | 769 | if (server.hasArg(name)) { 770 | V=server.arg(name); 771 | if (!V.length()) { 772 | error = InvalidTime; 773 | return error; 774 | } 775 | Serial.print(name); 776 | Serial.print(" "); 777 | Serial.println(V); 778 | 779 | int pos = V.indexOf(":"); 780 | if (pos==-1){ error=InvalidTime; return error; } else { 781 | H=V.substring(0,pos); 782 | M=V.substring(pos+1); 783 | 784 | if (!isinteger(H) || !isinteger(M)){ error=InvalidTime; return error; } 785 | } 786 | var=(H.toInt()*60)+(M.toInt())+86400; 787 | } 788 | else{ 789 | errorcount++; 790 | error = NotFound; 791 | return NotFound; 792 | }/**/ 793 | } 794 | 795 | int32_t tSysConfig::copyval(char* var, char const *name, int32_t size, int32_t min){ 796 | ///char buf[128]=""; 797 | String V; 798 | int32_t bytes=0; 799 | if (server.hasArg(name)) { 800 | V=server.arg(name); 801 | if (min>0){if (V.length()",obj.css.c_str(), obj.name.c_str()); 844 | HTML+=buffer; 845 | } 846 | bool tSysConfig::form(){ 847 | // need to figure out how to autoinclude a submit button 848 | HTML+=F(""); 849 | } 850 | void tSysConfig::fieldset(char* tag){ 851 | // use to create groupboxes on the form 852 | if (inFieldset){ fieldset();} 853 | inFieldset=true; 854 | sprintf(buffer, "
",tag); 855 | HTML+=buffer; 856 | } 857 | void tSysConfig::fieldset(){ 858 | if (inFieldset){ 859 | inFieldset=false; 860 | HTML+=F("
"); 861 | } 862 | } 863 | void tSysConfig::tab(char* tag){ 864 | sprintf(buffer, "",tag); 865 | HTML+=buffer; 866 | } 867 | bool tSysConfig::edit(htmlproperties obj, char* data, int32_t size){ 868 | if ( server.method() == HTTP_POST ){ 869 | // POST functionality here, includes error handling 870 | error=copyval(data,obj.name.c_str(),size); 871 | } 872 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(),size, (obj.required)?" REQUIRED ":""); 873 | HTML+=buffer; 874 | } 875 | bool tSysConfig::edit(htmlproperties obj, byte &data, byte min, byte max){ 876 | if ( server.method() == HTTP_POST ){ 877 | // POST functionality here, includes error handling 878 | error=copyval(data,obj.name.c_str(),min,max); 879 | } 880 | if (min!=max){ 881 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(),min, max, (obj.required)?" REQUIRED ":""); 882 | } else { 883 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(), (obj.required)?" REQUIRED ":""); 884 | } 885 | HTML+=buffer; 886 | } 887 | bool tSysConfig::edit(htmlproperties obj, int32_t &data, int32_t min, int32_t max){ 888 | if ( server.method() == HTTP_POST ){ 889 | // POST functionality here, includes error handling 890 | error=copyval(data,obj.name.c_str(),min,max); 891 | } 892 | if (min!=max){ 893 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(),min, max, (obj.required)?" REQUIRED ":"");} else 894 | { 895 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(), (obj.required)?" REQUIRED ":""); 896 | } 897 | HTML+=buffer; 898 | } 899 | bool tSysConfig::edit(htmlproperties obj, float &data, float min, float max){ 900 | if ( server.method() == HTTP_POST ){ 901 | // POST functionality here, includes error handling 902 | error=copyval(data,obj.name.c_str(),min,max); 903 | } 904 | if (min!=max){ 905 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(),min, max, (obj.required)?" REQUIRED ":"");} else 906 | { 907 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(),min, max, (obj.required)?" REQUIRED ":""); 908 | } 909 | HTML+=buffer; 910 | } 911 | 912 | bool tSysConfig::password(htmlproperties obj, char* data, int32_t size, int32_t min, int32_t max){ 913 | // unlike other fields, password auto includes Label & verify dialog 914 | char p1[32]; 915 | char p2[32]; 916 | char field[32]; 917 | if ( server.method() == HTTP_POST ){ 918 | // POST functionality here, includes error handling 919 | // min, max are used to check minimum and maximum length of the password 920 | error=copyval(p1,obj.name.c_str(),size); 921 | sprintf(field,"%s_verify",obj.name.c_str()); 922 | error=copyval(p2,field,size); 923 | if (strcmp(p1,p2)==0){ error=copyval(data,obj.name.c_str(),size); } 924 | } 925 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,(obj.required)?" REQUIRED ":""); 926 | HTML+=buffer; 927 | sprintf(buffer,"",obj.name.c_str(),data, (obj.required)?" REQUIRED ":""); 928 | HTML+=buffer; 929 | } 930 | bool tSysConfig::text(htmlproperties obj, char* data, int32_t size, int32_t min, int32_t max){ 931 | if ( server.method() == HTTP_POST ){ 932 | // POST functionality here, includes error handling 933 | error=copyval(data,obj.name.c_str(),size); 934 | } 935 | sprintf(buffer,"",obj.name.c_str(),data,obj.placeholder.c_str(),size, (obj.required)?" REQUIRED ":""); 936 | HTML+=buffer; 937 | } 938 | bool tSysConfig::editemail(htmlproperties obj, char* data, int32_t size){ 939 | if ( server.method() == HTTP_POST ){ 940 | // POST functionality here, includes error handling 941 | error=copyval(data,obj.name.c_str(),size); 942 | } 943 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(),(obj.required)?" REQUIRED ":""); 944 | HTML+=buffer; 945 | } 946 | bool tSysConfig::editurl(htmlproperties obj, char* data, int32_t size){ 947 | if ( server.method() == HTTP_POST ){ 948 | // POST functionality here, includes error handling 949 | error=copyval(data,obj.name.c_str(),size); 950 | } 951 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(), (obj.required)?" REQUIRED ":""); 952 | HTML+=buffer; 953 | } 954 | bool tSysConfig::edittel(htmlproperties obj, char* data, int32_t size){ 955 | if ( server.method() == HTTP_POST ){ 956 | // POST functionality here, includes error handling 957 | error=copyval(data,obj.name.c_str(),size); 958 | } 959 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data,obj.placeholder.c_str(), (obj.required)?" REQUIRED ":""); 960 | HTML+=buffer; 961 | } 962 | bool tSysConfig::edit(htmlproperties obj, time_t &data){ 963 | if ( server.method() == HTTP_POST ){ 964 | // POST functionality here, includes error handling 965 | error=copyval(data,obj.name.c_str()); 966 | } 967 | 968 | //atime.Hour=13; 969 | //atime.Minute=14; 970 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),0,0,(obj.required)?" REQUIRED ":""); 971 | HTML+=buffer; 972 | } 973 | /* our select methods require some Javascript magic, the ",obj.name.c_str(),obj.label.c_str(),data); 986 | HTML+=buffer; 987 | return true; 988 | } 989 | bool tSysConfig::selectbyte(htmlproperties obj,byte &data){ 990 | if (inSelect) {selectList();} 991 | inSelect=s_byte; 992 | if ( server.method() == HTTP_POST ){ 993 | // POST functionality here, includes error handling 994 | error=copyval(data,obj.name.c_str()); 995 | } 996 | sprintf(buffer,"",obj.name.c_str(),obj.label.c_str(),data); 1008 | HTML+=buffer; 1009 | return true; 1010 | } 1011 | bool tSysConfig::selectList(htmlproperties obj,char* data, int32_t size){ 1012 | if (inSelect) {selectList();} 1013 | if ( server.method() == HTTP_POST ){ 1014 | // POST functionality here, includes error handling 1015 | error=copyval(data,obj.name.c_str(), size); 1016 | } 1017 | inSelect=s_text; 1018 | sprintf(buffer,""); 1025 | } 1026 | void tSysConfig::label(htmlproperties obj){ 1027 | if (obj.label.length()>0){ 1028 | sprintf(buffer,"
",obj.name.c_str(), obj.label.c_str()); 1029 | HTML+=buffer; 1030 | } 1031 | } 1032 | bool tSysConfig::optiongroup(char const *name){ 1033 | optiongroup();// close any previous group 1034 | inOptgroup=true; 1035 | sprintf(buffer,"",name); 1036 | HTML+=buffer; 1037 | } 1038 | bool tSysConfig::optiongroup(){ 1039 | if (inOptgroup){ 1040 | inOptgroup=false; 1041 | HTML+=F("");} 1042 | } 1043 | bool tSysConfig::option(char *data, char *name){ 1044 | sprintf(buffer,"",data,name); 1045 | HTML+=buffer; 1046 | } 1047 | bool tSysConfig::option(float data, char *name){ 1048 | sprintf(buffer,"",data,name); 1049 | HTML+=buffer; 1050 | } 1051 | bool tSysConfig::option(int32_t data, char *name){ 1052 | sprintf(buffer,"",data,name); 1053 | HTML+=buffer; 1054 | } 1055 | bool tSysConfig::option(byte data, char *name){ 1056 | sprintf(buffer,"",data,name); 1057 | HTML+=buffer; 1058 | } 1059 | bool tSysConfig::checkbox(htmlproperties obj, bool &data){ 1060 | if ( server.method() == HTTP_POST ){ 1061 | // POST functionality here, includes error handling 1062 | error=copyval(data,obj.name.c_str()); 1063 | } 1064 | sprintf(buffer,"",obj.name.c_str(),data,obj.label.c_str()); 1065 | HTML+=buffer; 1066 | } 1067 | bool tSysConfig::checkbox(htmlproperties obj, int32_t &data){ 1068 | if ( server.method() == HTTP_POST ){ 1069 | // POST functionality here, includes error handling 1070 | error=copyval(data,obj.name.c_str()); 1071 | } 1072 | sprintf(buffer,"",obj.name.c_str(),data,obj.label.c_str()); 1073 | HTML+=buffer; 1074 | } 1075 | bool tSysConfig::checkbox(htmlproperties obj, char* data, int32_t size){ 1076 | if ( server.method() == HTTP_POST ){ 1077 | // POST functionality here, includes error handling 1078 | error=copyval(data,obj.name.c_str(),size); 1079 | } 1080 | sprintf(buffer,"",obj.name.c_str(),data,obj.label.c_str()); 1081 | HTML+=buffer; 1082 | } 1083 | bool tSysConfig::radio(htmlproperties obj, int32_t &data){ 1084 | if ( server.method() == HTTP_POST ){ 1085 | // POST functionality here, includes error handling 1086 | error=copyval(data,obj.name.c_str()); 1087 | } 1088 | sprintf(buffer,"",obj.name.c_str(),data,obj.label.c_str()); 1089 | HTML+=buffer; 1090 | } 1091 | bool tSysConfig::radio(htmlproperties obj, char *data, int32_t size){ 1092 | if ( server.method() == HTTP_POST ){ 1093 | // POST functionality here, includes error handling 1094 | error=copyval(data,obj.name.c_str(), size); 1095 | } 1096 | sprintf(buffer,"",obj.name.c_str(),data,obj.label.c_str()); 1097 | HTML+=buffer; 1098 | } 1099 | // additional html elements of significant use to us 1100 | void tSysConfig::meter(htmlproperties obj, int32_t value, int32_t min, int32_t max){ 1101 | // name is not required as this item does not return information 1102 | if (obj.label.length()>0){ 1103 | sprintf(buffer," %d% ",obj.name.c_str(), obj.label.c_str(), value, min, max );} else { 1104 | sprintf(buffer," %d% ",obj.name.c_str(), value, min, max );} 1105 | HTML+=buffer; 1106 | } 1107 | void tSysConfig::meter(htmlproperties obj, float value, float min, float max){ 1108 | // name is not required as this item does not return information 1109 | if (obj.label.length()>0){ 1110 | sprintf(buffer," %f% ",obj.name.c_str(), obj.label.c_str(),value, min, max );} else { 1111 | sprintf(buffer," %f% ", obj.name.c_str(), value, min, max );} 1112 | HTML+=buffer; 1113 | } 1114 | void tSysConfig::progress(htmlproperties obj, int32_t value, int32_t min, int32_t max){ 1115 | // name is not required as this item does not return information 1116 | if (obj.label.length()>0){ 1117 | sprintf(buffer," %d% ",obj.name.c_str(), obj.label.c_str(),value, min, max );} else { 1118 | sprintf(buffer," %d% ", obj.name.c_str(), value, min, max );} 1119 | HTML+=buffer; 1120 | } 1121 | void tSysConfig::progress(htmlproperties obj, float value, float min, float max){ 1122 | // name is not required as this item does not return information 1123 | if (obj.label.length()>0){ 1124 | sprintf(buffer," %f% ",obj.name.c_str(), obj.label.c_str(), value, min, max );} else { 1125 | sprintf(buffer," %f% ",obj.name.c_str(), value, min, max );} 1126 | HTML+=buffer; 1127 | } 1128 | void tSysConfig::details(htmlproperties obj){ 1129 | // name is not required as this item does not return information https://www.w3schools.com/tags/tag_button.asp 1130 | sprintf(buffer,"
%s

%s

", obj.label.c_str(), obj.value.c_str() ); 1131 | HTML+=buffer; 1132 | } 1133 | 1134 | void tSysConfig::indexPage(void) { 1135 | Serial.println("indexPage"); 1136 | if ( server.method() == HTTP_POST ){ 1137 | Serial.println("post data"); 1138 | // POST functionality here, includes error handling 1139 | //WiFi 1140 | error=copyval(_data.AccessPoints[0].WiFiname ,"SSID_0",32); 1141 | error=copyval(_data.AccessPoints[1].WiFiname ,"SSID_1",32); 1142 | error=copyval(_data.AccessPoints[2].WiFiname ,"SSID_2",32); 1143 | error=copyval(_data.AccessPoints[3].WiFiname ,"SSID_3",32); 1144 | error=copyval(_data.AccessPoints[4].WiFiname ,"SSID_4",32); 1145 | error=copyval(_data.AccessPoints[0].WiFipassword ,"SSID_pass_0",32); 1146 | error=copyval(_data.AccessPoints[1].WiFipassword ,"SSID_pass_1",32); 1147 | error=copyval(_data.AccessPoints[2].WiFipassword ,"SSID_pass_2",32); 1148 | error=copyval(_data.AccessPoints[3].WiFipassword ,"SSID_pass_3",32); 1149 | error=copyval(_data.AccessPoints[4].WiFipassword ,"SSID_pass_4",32); 1150 | //AP 1151 | error=copyval(_data.APname ,"APname",32); 1152 | error=copyval(_data.APpassword ,"APpassword",32); 1153 | error=copyval(_data.APchannel,"APchannel",1,13 ); 1154 | error=copyval(_data.APconfig ,"APconfig",0,4); 1155 | //BLE 1156 | error=copyval(_data.BLEname ,"BLEname",32); 1157 | error=copyval(_data.BLEpassword ,"BLEpassword",32); 1158 | error=copyval(_data.BLEConfig ,"BLEconfig",0,4); 1159 | //NTP 1160 | error=copyval(_data.NTPserver ,"NTPserver",128); 1161 | error=copyval(_data.TZ ,"TZ"); 1162 | _data.TZ=_data.TZ-86400; 1163 | error=copyval(_data.DST ,"DST"); 1164 | _data.DST=_data.DST-86400; 1165 | //OTA 1166 | error=copyval(_data.OTA ,"OTA",0,3); 1167 | error=copyval(_data.OTApass ,"OTApass",32); 1168 | //ACL 1169 | error=copyval(_data.userName ,"userName",32); 1170 | error=copyval(_data.userPass ,"userPass",32); 1171 | //USER info 1172 | error=copyval(_data.firstname ,"fname",32); 1173 | error=copyval(_data.lastname ,"lname",32); 1174 | error=copyval(_data.userEmail ,"email",128); 1175 | error=copyval(_data.phone ,"phone",32); 1176 | error=copyval(_data.NodeName ,"Node",32); 1177 | // MQTT 1178 | error=copyval(_data.MQTTserver ,"MQTTserver",128); 1179 | error=copyval(_data.MQTTport ,"MQTTport"); 1180 | error=copyval(_data.MQTTuser ,"MQTTuser",32); 1181 | error=copyval(_data.MQTTpass ,"MQTTpass",32); 1182 | 1183 | // copy the time variables start time, stop time and day of week 1184 | for ( byte i = 0; i < 32; i++ ) { 1185 | sprintf(buffer,"st_%d",i); 1186 | error=copyval(_data.timers[i].startTime,buffer); 1187 | sprintf(buffer,"et_%d",i); 1188 | error=copyval(_data.timers[i].endTime,buffer); 1189 | sprintf(buffer,"d_%d",i); 1190 | error=copyval(_data.timers[i].dow,buffer); 1191 | } 1192 | writeConfig(); 1193 | } 1194 | File dataFile = SPIFFS.open("/index.html", "r"); 1195 | if (dataFile.size()<=0) {Serial.println("bad file size"); 1196 | } 1197 | if (server.streamFile(dataFile, "text/html") != dataFile.size()) {Serial.println(F("index.html streaming error")); 1198 | } 1199 | dataFile.close(); 1200 | } 1201 | 1202 | void tSysConfig::getIcon(){ 1203 | Serial.println("getIcon"); 1204 | File dataFile = SPIFFS.open("/favicon.ico", "r"); 1205 | if (dataFile.size()<=0) {Serial.println("icon bad file size"); 1206 | } 1207 | if (server.streamFile(dataFile, "image/vnd") != dataFile.size()) {Serial.println(F("icon streaming error")); 1208 | } 1209 | dataFile.close(); 1210 | } 1211 | 1212 | void tSysConfig::getJSON(){ 1213 | // needs a buffer 1214 | Serial.println("getJson"); 1215 | char* json ="{\"WiFi\":[\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"],\"data\":[\"%s\",\"%s\",%d,%d,\"%s\",\"%s\",%d,\"%s\",\"%s\",%d,\"%s\"],\"MQTT\":[\"%s\",%d,\"%s\",\"%s\"],\"time\":[\"%s\",%d,%d],\"sysInfo\":[%d,\"%s\",%d,%d,%d,\"%s\",\"%s\",%d,%d,%d,\"%s\",\"%s\"],\"alarms\":[%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]}"; 1216 | 1217 | char jsonbuf[sizeof(_data)+sizeof(json)+4]; 1218 | 1219 | sprintf(jsonbuf, json, 1220 | // SSID for up to 5 networks 1221 | _data.AccessPoints[0].WiFiname, 1222 | _data.AccessPoints[1].WiFiname, 1223 | _data.AccessPoints[2].WiFiname, 1224 | _data.AccessPoints[3].WiFiname, 1225 | _data.AccessPoints[4].WiFiname, 1226 | // access point settings 1227 | _data.APname, 1228 | _data.APpassword, 1229 | _data.APchannel, 1230 | _data.APconfig, 1231 | // bluetooth settings 1232 | _data.BLEname, 1233 | _data.BLEpassword, 1234 | _data.BLEConfig, 1235 | // configuration login 1236 | _data.userName, 1237 | _data.userPass, 1238 | // over the air updating 1239 | _data.OTA, 1240 | _data.OTApass, 1241 | _data.MQTTserver, 1242 | _data.MQTTport, 1243 | _data.MQTTuser, 1244 | _data.MQTTpass, 1245 | // NTP settings 1246 | _data.NTPserver, 1247 | _data.TZ, 1248 | _data.DST, // need to add current time to the data sent 1249 | 1250 | ESP.getChipRevision(), 1251 | ESP.getSdkVersion(), 1252 | ESP.getCpuFreqMHz(), 1253 | ESP.getFlashChipSpeed(), 1254 | ESP.getFlashChipSize(), 1255 | (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"), 1256 | WiFi.SSID().c_str(), // wifi config info 1257 | (uint32_t)WiFi.localIP(), 1258 | (uint32_t)WiFi.gatewayIP(), 1259 | (uint32_t)WiFi.softAPIP(), 1260 | __DATE__,__TIME__, // date & time this code was compiled 1261 | 1262 | // time parameters 32 start times, 32 end times and 32 dow values 1263 | _data.timers[0].startTime-86400, _data.timers[1].startTime-86400, _data.timers[2].startTime-86400, _data.timers[3].startTime-86400, 1264 | _data.timers[4].startTime-86400, _data.timers[5].startTime-86400, _data.timers[6].startTime-86400, _data.timers[7].startTime-86400, 1265 | _data.timers[8].startTime-86400, _data.timers[9].startTime-86400, _data.timers[10].startTime-86400, _data.timers[11].startTime-86400, 1266 | _data.timers[12].startTime-86400, _data.timers[13].startTime-86400, _data.timers[14].startTime-86400, _data.timers[15].startTime-86400, 1267 | _data.timers[16].startTime-86400, _data.timers[17].startTime-86400, _data.timers[18].startTime-86400, _data.timers[19].startTime-86400, 1268 | _data.timers[20].startTime-86400, _data.timers[21].startTime-86400, _data.timers[22].startTime-86400, _data.timers[23].startTime-86400, 1269 | _data.timers[24].startTime-86400, _data.timers[25].startTime-86400, _data.timers[26].startTime-86400, _data.timers[27].startTime-86400, 1270 | _data.timers[28].startTime-86400, _data.timers[29].startTime-86400, _data.timers[30].startTime-86400, _data.timers[31].startTime-86400, 1271 | 1272 | _data.timers[0].endTime-86400, _data.timers[1].endTime-86400, _data.timers[2].endTime-86400, _data.timers[3].endTime-86400, 1273 | _data.timers[4].endTime-86400, _data.timers[5].endTime-86400, _data.timers[6].endTime-86400, _data.timers[7].endTime-86400, 1274 | _data.timers[8].endTime-86400, _data.timers[9].endTime-86400, _data.timers[10].endTime-86400, _data.timers[11].endTime-86400, 1275 | _data.timers[12].endTime-86400, _data.timers[13].endTime-86400, _data.timers[14].endTime-86400, _data.timers[15].endTime-86400, 1276 | _data.timers[16].endTime-86400, _data.timers[17].endTime-86400, _data.timers[18].endTime-86400, _data.timers[19].endTime-86400, 1277 | _data.timers[20].endTime-86400, _data.timers[21].endTime-86400, _data.timers[22].endTime-86400, _data.timers[23].endTime-86400, 1278 | _data.timers[24].endTime-86400, _data.timers[25].endTime-86400, _data.timers[26].endTime-86400, _data.timers[27].endTime-86400, 1279 | _data.timers[28].endTime-86400, _data.timers[29].endTime-86400, _data.timers[30].endTime-86400, _data.timers[31].endTime-86400, 1280 | 1281 | _data.timers[0].dow, _data.timers[1].dow, _data.timers[2].dow, _data.timers[3].dow, 1282 | _data.timers[4].dow, _data.timers[5].dow, _data.timers[6].dow, _data.timers[7].dow, 1283 | _data.timers[8].dow, _data.timers[9].dow, _data.timers[10].dow, _data.timers[11].dow, 1284 | _data.timers[12].dow, _data.timers[13].dow, _data.timers[14].dow, _data.timers[15].dow, 1285 | _data.timers[16].dow, _data.timers[17].dow, _data.timers[18].dow, _data.timers[19].dow, 1286 | _data.timers[20].dow, _data.timers[21].dow, _data.timers[22].dow, _data.timers[23].dow, 1287 | _data.timers[24].dow, _data.timers[25].dow, _data.timers[26].dow, _data.timers[27].dow, 1288 | _data.timers[28].dow, _data.timers[29].dow, _data.timers[30].dow, _data.timers[31].dow 1289 | ); 1290 | /* Serial.println(WiFi.SSID().c_str()); // wifi config info 1291 | Serial.println(WiFi.localIP()); 1292 | Serial.println(WiFi.gatewayIP()); 1293 | Serial.println(WiFi.softAPIP());*/ 1294 | 1295 | server.send(200, "text/x-json", jsonbuf); 1296 | server.client().stop(); 1297 | } 1298 | void tSysConfig::getCharts(){ 1299 | HTML=F("ESP Timers Page"); 1300 | HTML=F(""); 1301 | HTML+=F("
"); 1302 | HTML+=F("Charts
"); 1303 | 1304 | HTML+=F(""); 1305 | server.send(200, "text/html", HTML);HTML=""; 1306 | // server.client().stop(); 1307 | } 1308 | void tSysConfig::drawGraph(){ 1309 | 1310 | } 1311 | 1312 | void tSysConfig::handleNotFound(){ 1313 | Serial.println("handleNotFound"); 1314 | // the 404 page, we want to show the message and give the user a link back to the index page 1315 | // unlike the other pages, this one is entirely self contained, including the CSS it needs 1316 | // one caveat, figure out if its framed or unframed from the uri 1317 | File dataFile = SPIFFS.open("/404.html", "r"); 1318 | if (dataFile.size()<=0) {Serial.println(F("help.htm bad file size")); 1319 | } 1320 | if (server.streamFile(dataFile, "text/html") != dataFile.size()) {Serial.println(F("404.html streaming error")); 1321 | } 1322 | dataFile.close(); 1323 | // server.client().stop(); 1324 | } 1325 | 1326 | tSysConfig sysConfig; 1327 | -------------------------------------------------------------------------------- /esp32config/upload/404.html: -------------------------------------------------------------------------------- 1 | 2 | ESP protopage 4 | 5 | 11 | 12 | 13 | 14 |
15 | 16 |

404 Error

17 |

Page not found
Please check your url or goto the Index page

18 |
19 | 21 | -------------------------------------------------------------------------------- /esp32config/upload/index.html: -------------------------------------------------------------------------------- 1 | ESP protopage 2 | 3 | 4 | 5 | 6 | 7 | 8 | 492 | 570 | 571 | 572 | 576 |
577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 |
596 |
597 |
598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 |
615 |
616 |
617 | 618 | 648 | 649 | 697 | 698 | 749 | 756 | 764 | 782 | 783 | 795 | 796 | 845 |
846 |
847 | 849 |
850 | 851 | 852 | -------------------------------------------------------------------------------- /esp32mqtt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterjazenga/ESPconfig/5719a00ad6cfa4a22d50004bf8b482d33ad5aa4c/esp32mqtt.png -------------------------------------------------------------------------------- /esp32screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterjazenga/ESPconfig/5719a00ad6cfa4a22d50004bf8b482d33ad5aa4c/esp32screenshot1.png -------------------------------------------------------------------------------- /esp32wifi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterjazenga/ESPconfig/5719a00ad6cfa4a22d50004bf8b482d33ad5aa4c/esp32wifi.png -------------------------------------------------------------------------------- /esp8266admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterjazenga/ESPconfig/5719a00ad6cfa4a22d50004bf8b482d33ad5aa4c/esp8266admin.png -------------------------------------------------------------------------------- /esp8266config/esp8266config.ino: -------------------------------------------------------------------------------- 1 | /* author: Peter Dunne, +44 7932 676 847 peterjazenga@gmail.com 2 | * purpose: to control a relay or SSR via radio signal or WiFi signal 3 | * requirements: serial interface for radio, read only mode, initial design uses 433 mhz receiver 4 | * WiFi interface to facilitate remote control using JSON packets 5 | * Web interface to Configure WiFi interface and define control parameters for the radio transmitter device 6 | * Bluetooth (ESP32 only) control and Configuration interface to phones/tablets/etc. 7 | * 8 | * This module imports code by Peter Dunne from previous ESP projects in power sensing, RC and on/off power switches 9 | * 10 | * sysConfig.init(); is called after Serial.begin(); and it handles all WiFi, OTA, NAT, Time setting and Bluetooth configuration 11 | * WPS is also supported via sysConfig 12 | * sysConfig.run(); keeps things updated, provides for servicing of the OTA & Web server issues among others, it also handles the blinking of the status LED 13 | */ 14 | 15 | #include "sysconfig8266.h"; 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | sysConfig.init(); 20 | Serial.println("Ready."); 21 | } 22 | 23 | void loop() { 24 | sysConfig.run(); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /esp8266config/library.properties: -------------------------------------------------------------------------------- 1 | name=sysConfig 2 | version=0.1 3 | author=Peter Dunne 4 | maintainer=Peter Dunne 5 | sentence=ESP8266/ESP32 WiFi/AP web configuration. 6 | paragraph=sysConfig will start up in AP (access point) mode, and provide a config portal for entering WiFi connection, bluetooth, time and access control settings. configuration and support files are stored in SPIFFS. It has been designed for easy branding and includes OTA function 7 | url=https://github.com/peterjazenga/ESPconfig 8 | architectures=esp8266 9 | includes=sysConfig32.h -------------------------------------------------------------------------------- /esp8266config/upload/404.html: -------------------------------------------------------------------------------- 1 | 2 | ESP protopage 4 | 5 | 11 | 12 | 13 | 14 |
15 | 16 |

404 Error

17 |

Page not found
Please check your url or goto the Index page

18 |
19 | 21 | -------------------------------------------------------------------------------- /esp8266config/upload/index.html: -------------------------------------------------------------------------------- 1 | ESP protopage 2 | 3 | 4 | 5 | 6 | 7 | 8 | 244 | 322 | 323 | 324 | 328 |
329 | 330 | 331 | ✉ Register 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 |
348 |
349 |
350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 |
367 |
368 |
369 | 370 | 400 | 401 | 449 | 450 | 501 | 508 | 516 | 534 | 535 | 547 | 548 | 597 |
598 |
599 | 601 | 602 | 603 | -------------------------------------------------------------------------------- /esp8266screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterjazenga/ESPconfig/5719a00ad6cfa4a22d50004bf8b482d33ad5aa4c/esp8266screenshot1.png -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESPConfig 2 | version=1.0.0 3 | author=Peter Dunne 4 | maintainer=Peter Dunne 5 | sentence=Simple library for ESP8266/ESP32 configuration using ESPconfig.h 6 | paragraph=ESPConfig is a lightweight library for easy configuration and management of ESP8266, ESP8285, and ESP32 devices. It supports WiFi setup, device parameter management, and configuration storage using SPIFFS. Includes specific configuration headers for each architecture. 7 | category=Communication 8 | url=https://github.com/peterjazenga/ESPconfig 9 | architectures=esp8266, esp8285, esp32 10 | depends=WiFi, SPIFFS 11 | includes=ESPconfig.h 12 | --------------------------------------------------------------------------------