diff --git a/SmartEVSE-3/.github/ISSUE_TEMPLATE/bug_report.md b/SmartEVSE-3/.github/ISSUE_TEMPLATE/bug_report.md
deleted file mode 100644
index 19620f9..0000000
--- a/SmartEVSE-3/.github/ISSUE_TEMPLATE/bug_report.md
+++ /dev/null
@@ -1,28 +0,0 @@
----
-name: Bug report
-about: Create a report to help us improve
-title: ''
-labels: ''
-assignees: ''
-
----
-
-**Describe the bug**
-A clear and concise description of what the bug is.
-
-**Upload your config**
-Press the "raw" button in the SmartEVSE webserver and upload the json settings file, so we can look at your configuration.
-
-**Upload a debug log**
-Flash the debug version of the firmware (see https://github.com/dingo35/SmartEVSE-3.5/blob/master/SmartEVSE-3/HowToFlash.txt), telnet to your device, capture the debug log, cut it so that it shows JUST BEFORE and JUST AFTER the problem arises, and upload it here.
-
-**To Reproduce**
-Steps to reproduce the behavior:
-1. What Mode are you in? Normal, Smart or Solar?
-2. What steps do you take so the problem arises?
-
-**Expected behavior**
-A clear and concise description of what you expected to happen; expected Charging Current?
-
-**Screenshots**
-Only add screenshots if it adds any information, e.g. when you are reporting a problem on the webserver screen.
diff --git a/SmartEVSE-3/.github/ISSUE_TEMPLATE/feature_request.md b/SmartEVSE-3/.github/ISSUE_TEMPLATE/feature_request.md
deleted file mode 100644
index 1b87256..0000000
--- a/SmartEVSE-3/.github/ISSUE_TEMPLATE/feature_request.md
+++ /dev/null
@@ -1,21 +0,0 @@
----
-name: Feature request
-about: Suggest an idea for this project
-title: ''
-labels: ''
-assignees: ''
-
----
-
-**Is your feature request related to a problem? Please describe.**
-A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
-ALSO, if your feature request relates to any reported issues previously, please LINK them here!
-
-**Describe the solution you'd like**
-A clear and concise description of what you want to happen.
-
-**Describe alternatives you've considered**
-A clear and concise description of any alternative solutions or features you've considered.
-
-**Additional context**
-Add any other context or screenshots about the feature request here.
diff --git a/SmartEVSE-3/.github/workflows/pio-build.yaml b/SmartEVSE-3/.github/workflows/pio-build.yaml
deleted file mode 100644
index 198a913..0000000
--- a/SmartEVSE-3/.github/workflows/pio-build.yaml
+++ /dev/null
@@ -1,130 +0,0 @@
-name: PlatformIO CI
-on:
- workflow_call:
- inputs:
- major:
- required: true
- type: string
- minor:
- required: true
- type: string
- patch:
- required: true
- type: string
- prerelease:
- required: false
- type: string
- outputs:
- artifact:
- description: "The first output string"
- value: ${{ jobs.build.outputs.artifact }}
- push:
- branches:
- - master
- - release/*
-jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - name: Get current branch
- id: branch
- run: echo "branch=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
- - name: Get current datetime
- id: datetime
- run: echo "datetime=$(date +'%Y%m%dT%H%M%S')" >> $GITHUB_OUTPUT
- - name: Get current time
- id: time
- run: echo "time=$(date +'%H%M%S')" >> $GITHUB_OUTPUT
- - name: Get version
- id: version
- shell: bash
- run: |
- if [ -z "${{ inputs.major }}" ]
- then
- echo "version=${{ steps.time.outputs.time }}" >> $GITHUB_OUTPUT
- else
- if [ -z "${{ inputs.prerelease }}" ]
- then
- echo "version=${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}" >> $GITHUB_OUTPUT
- else
- echo "version=${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}-${{ inputs.prerelease }}" >> $GITHUB_OUTPUT
- fi
- fi
- - uses: actions/checkout@v3
- - name: Cache pip
- uses: actions/cache@v3
- with:
- path: ~/.cache/pip
- key: '${{ runner.os }}-pip-${{ hashFiles(''**/requirements.txt'') }}'
- restore-keys: |
- ${{ runner.os }}-pip-
- - name: Cache PlatformIO
- uses: actions/cache@v3
- with:
- path: ~/.platformio
- key: '${{ runner.os }}-${{ hashFiles(''**/lockfiles'') }}'
- - name: Set up Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.10'
- - name: Install PlatformIO
- run: |
- python -m pip install --upgrade pip
- pip install --upgrade platformio
- - name: Install libs
- run: |
- cd SmartEVSE-3
- pio lib install
- - name: Build normal version
- env:
- super_secret: ${{ secrets.SECRET_RSA_KEY }}
- run: |
- PLATFORMIO_BUILD_FLAGS='-DVERSION=\"v${{ steps.version.outputs.version }}\" -DDBG=0' pio run -d SmartEVSE-3/
- # Create a temporary file
- secret_file=$(mktemp)
- # Write the secret to the temporary file, because passing it as command line argument might reveal it for users using ps -a
- echo "$super_secret" > "$secret_file"
- # Create signature file
- openssl dgst -sign "$secret_file" -keyform PEM -sha256 -out firmware.sign -binary ./SmartEVSE-3/.pio/build/release/firmware.bin
- # throw it all in one file
- cat firmware.sign ./SmartEVSE-3/.pio/build/release/firmware.bin > ./SmartEVSE-3/.pio/build/release/firmware.signed.bin
- # Remove the temporary file
- rm -f "$secret_file"
- - name: Upload firmware.bin
- uses: actions/upload-artifact@v3
- with:
- name: dists_zip
- path: ./SmartEVSE-3/.pio/build/release/*.bin
- retention-days: 10
- - name: Upload HowToFlash.txt
- uses: actions/upload-artifact@v3
- with:
- name: dists_zip
- path: ./SmartEVSE-3/HowToFlash.txt
- retention-days: 10
- - name: Build debug version
- env:
- super_secret: ${{ secrets.SECRET_RSA_KEY }}
- run: |
- PLATFORMIO_BUILD_FLAGS='-DVERSION=\"v${{ steps.version.outputs.version }}\" -DDBG=1' pio run -d SmartEVSE-3/
- # Create a temporary file
- secret_file=$(mktemp)
- # Write the secret to the temporary file, because passing it as command line argument might reveal it for users using ps -a
- echo "$super_secret" > "$secret_file"
- # Create signature file
- openssl dgst -sign "$secret_file" -keyform PEM -sha256 -out firmware.sign -binary ./SmartEVSE-3/.pio/build/release/firmware.bin
- # throw it all in one file
- cat firmware.sign ./SmartEVSE-3/.pio/build/release/firmware.bin > ./SmartEVSE-3/.pio/build/release/firmware.signed.bin
- # Remove the temporary file
- rm -f "$secret_file"
- mv ./SmartEVSE-3/.pio/build/release/firmware.bin ./SmartEVSE-3/.pio/build/release/firmware.debug.bin
- mv ./SmartEVSE-3/.pio/build/release/firmware.signed.bin ./SmartEVSE-3/.pio/build/release/firmware.debug.signed.bin
- - name: Upload Artifact debug firmware
- uses: actions/upload-artifact@v3
- with:
- name: dists_zip
- path: ./SmartEVSE-3/.pio/build/release/*.bin
- retention-days: 10
-
- outputs:
- artifact: dists_zip
diff --git a/SmartEVSE-3/.github/workflows/pio-release.yaml b/SmartEVSE-3/.github/workflows/pio-release.yaml
deleted file mode 100644
index 680cb4f..0000000
--- a/SmartEVSE-3/.github/workflows/pio-release.yaml
+++ /dev/null
@@ -1,62 +0,0 @@
-on:
- push:
- tags:
- - 'v*'
-
-name: Create Release
-jobs:
- version:
- runs-on: ubuntu-latest
- steps:
- - id: get_version
- uses: battila7/get-version-action@v2
- outputs:
- major: ${{ steps.get_version.outputs.major }}
- minor: ${{ steps.get_version.outputs.minor }}
- patch: ${{ steps.get_version.outputs.patch }}
- prerelease: ${{ steps.get_version.outputs.prerelease }}
- build:
- needs: version
- uses: ./.github/workflows/pio-build.yaml
- with:
- major: ${{ needs.version.outputs.major }}
- minor: ${{ needs.version.outputs.minor }}
- patch: ${{ needs.version.outputs.patch }}
- prerelease: ${{ needs.version.outputs.prerelease }}
- secrets: inherit
- release:
- permissions: write-all
- needs: build
- name: Upload Release Asset
- runs-on: ubuntu-latest
- steps:
- - name: Get current tag
- id: tag
- run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
- - uses: actions/checkout@v3
- - uses: actions/download-artifact@v3
- id: download
- with:
- path: dist
- - name: Create Release
- id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- tag_name: ${{ github.ref }}
- release_name: Release ${{ github.ref }}
- draft: false
- prerelease: true
- - name: Zip
- run: zip -j ${{ steps.tag.outputs.tag }}-dist.zip ./dist/${{ needs.build.outputs.artifact }}/*
- - name: Upload Release Asset
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./${{ steps.tag.outputs.tag }}-dist.zip
- asset_name: ${{ steps.tag.outputs.tag }}-dist.zip
- asset_content_type: application/zip
diff --git a/SmartEVSE-3/.gitignore b/SmartEVSE-3/.gitignore
deleted file mode 100644
index add810d..0000000
--- a/SmartEVSE-3/.gitignore
+++ /dev/null
@@ -1,11 +0,0 @@
-.pio
-.log
-sdkconfig.*
-*/.vscode/.browse.c_cpp.db*
-*/.vscode/c_cpp_properties.json
-*/.vscode/launch.json
-*/.vscode/ipch
-
-.DS_Store
-*/.DS_Store
-.idea
diff --git a/SmartEVSE-3/LICENSE b/SmartEVSE-3/LICENSE
deleted file mode 100644
index 99ea426..0000000
--- a/SmartEVSE-3/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2021 SmartEVSE
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/SmartEVSE-3/README.md b/SmartEVSE-3/README.md
deleted file mode 100644
index bae3886..0000000
--- a/SmartEVSE-3/README.md
+++ /dev/null
@@ -1,65 +0,0 @@
-SmartEVSE v3
-=========
-
-Smart Electric Vehicle Charge Controller
-
-
-
-# What is it?
-
-It's an open source EVSE (Electric Vehicle Supply Equipment). It supports 1-3 phase charging, fixed charging cable or charging socket. Locking actuator support (5 different types). And it can directly drive a mains contactor for supplying power to the EV. It features a display from which all module parameters can be configured.
-Up to 8 modules can be connected together to charge up to eight EV's from one mains connection without overloading it.
-The mains connection can be monitored by the (optional) sensorbox or a modbus kWh meter. This allows smart charging.
-Communication between the SmartEVSE(s) / Sensorbox or kWh meters is done over RS485(modbus).
-
-
-# Features
-
-- Fits into a standard DIN rail enclosure.
-- Measures the current consumption of other appliances, and automatically lowers or increases the charging current to the EV. (sensorbox required)
-- The load balancing feature let's you connect up to 8 SmartEVSE's to one mains supply.
-- Two switched 230VAC outputs, for contactors.
-- Powered RS485 communication bus for sensorbox / Modbus kWh Meters.
-- Can be used with fixed cable, or socket and charging cable.
-- Automatically selects current capacity of the connected cable (13/16/32A)
-- Locking actuator support, locks the charging cable in the socket.
-- RFID reader support, restrict the use of the charging station to max 20 RFID cards.
-- An optional modbus kWh meter will measure power and charged energy, and display this on the LCD.
-- Built-in temperature sensor.
-- RGB led output for status information while charging.
-- All module parameters can be configured using the display and buttons.
-- WiFi status page.
-- Firmware upgradable through USB-C port or through the built in webserver.
-- REST API for communication with external software (e.g. HomeAssistant)
-- MQTT API
-- Rudimentary support for home batteries
-- Supporting delayed charging
-
-# Connecting the SmartESVE to WiFi
-
-In order to connect the SmartEVSE to your local WiFi network, a temporarily hotspot is created by the SmartESVE to which you can connect using a phone/tablet.
-Here you can then scan for your local WiFi, and enter your Wifi network password. Then the SmartEVSE will use this information to connect to your local Wifi network.
-
-The steps to connect the SmartEVSE to Wifi are as follows:
-- in the SmartEVSE menu, go to the option WIFI, then select SetupWiFi.
-- after 10 seconds, a hotspot/access point SmartESVE-xxxx is started. (xxxx is the serial nr of your SmartEVSE)
-- Using a phone or tablet, connect to this access point.
-- You will be asked to enter a password. This password is visible on the top right corner of the SmartEVSE's display. (PW:xxxxxxxx)
-- Once connected you will be able to select your local WiFi network, and enter the password for this network.
-- click SAVE, the SmartEVSE will try to connect to your local WiFi network.
-- Enter the menu of your SmartEVSE again. The SmartEVSE should now display the IP address on the top row of the display.
-- use this IP address in a webbrowser to connect to the webserver of the controller. You can also use http://smartevse-xxxx.local (replace xxxx with the serial nr of your controller)
-
-# Updating Firmware
-
-Connect the SmartEVSE controller to your WiFi network (using the menu of the SmartEVSE), and then browse to http://IPaddress/update where IPaddress is the IP which is shown on the display.
-You can also use http://smartevse-xxxx.local/update where xxxx is the serial nr of your controller.
-Here you can select the firmware.bin and press update to update the firmware.
-It's also possible to update the spiffs partition from this page. (for v3.0.1 this is not needed)
-After updating the firmware, you can access the status page again using the normal url: http://smartevse-xxxx.local (replace xxxx with the serial nr of your controller)
-
-# Documentation
-
-[Hardware installation](docs/installation.md)
-[Configuration](docs/configuration.md)
-[Operation](docs/operation.md)
diff --git a/SmartEVSE-3/SmartEVSE-3/.gitignore b/SmartEVSE-3/SmartEVSE-3/.gitignore
deleted file mode 100644
index 89cc49c..0000000
--- a/SmartEVSE-3/SmartEVSE-3/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-.pio
-.vscode/.browse.c_cpp.db*
-.vscode/c_cpp_properties.json
-.vscode/launch.json
-.vscode/ipch
diff --git a/SmartEVSE-3/SmartEVSE-3/CMakeLists.txt b/SmartEVSE-3/SmartEVSE-3/CMakeLists.txt
deleted file mode 100644
index 73d6dae..0000000
--- a/SmartEVSE-3/SmartEVSE-3/CMakeLists.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-cmake_minimum_required(VERSION 3.16.0)
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-project(SmartEVSE32)
diff --git a/SmartEVSE-3/SmartEVSE-3/HowToFlash.txt b/SmartEVSE-3/SmartEVSE-3/HowToFlash.txt
deleted file mode 100644
index 0587456..0000000
--- a/SmartEVSE-3/SmartEVSE-3/HowToFlash.txt
+++ /dev/null
@@ -1,5 +0,0 @@
--surf to http://your-smartevse/update
--select the firmware.bin from this archive, OR if you want the debug version (via telnet over your wifi),
- rename firmware.debug.bin to firmware.bin and select that. YOU CANNOT FLASH A FILE WITH ANOTHER NAME!
--if you get FAIL, check your wifi connection and try again;
--after OK, wait 10-30 seconds and your new firmware including the webserver should be online!
diff --git a/SmartEVSE-3/SmartEVSE-3/data/cert.pem b/SmartEVSE-3/SmartEVSE-3/data/cert.pem
deleted file mode 100644
index b6fa7a5..0000000
--- a/SmartEVSE-3/SmartEVSE-3/data/cert.pem
+++ /dev/null
@@ -1,13 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIB4DCCAYWgAwIBAgIUZNoNpf/c2H+t54PnIoe4PgiahV0wCgYIKoZIzj0EAwIw
-RTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGElu
-dGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA1MDQwNjEyMDNaFw0yNDA2MDMw
-NjEyMDNaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYD
-VQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjO
-PQMBBwNCAAQLQqPNIgyYn4J8SE3LRBVhkDyLAT6cumGL73QGB+OzEsj6cv2B0kGs
-jpvUrsclwmCVLVo0T6FxHR4Pw/Fy3qgvo1MwUTAdBgNVHQ4EFgQUpqjPZrPqhA23
-ghR5bdmj0gceVRgwHwYDVR0jBBgwFoAUpqjPZrPqhA23ghR5bdmj0gceVRgwDwYD
-VR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNJADBGAiEA2IitVasCjmRsbz9ZcG4U
-jn3tudAVCXs9Fet7AVLNvDkCIQDJGRWuWmctvD/7DBPUra822bIlWhwFKljWpNTW
-wZAdFg==
------END CERTIFICATE-----
diff --git a/SmartEVSE-3/SmartEVSE-3/data/favicon.ico b/SmartEVSE-3/SmartEVSE-3/data/favicon.ico
deleted file mode 100644
index 0c6b947..0000000
Binary files a/SmartEVSE-3/SmartEVSE-3/data/favicon.ico and /dev/null differ
diff --git a/SmartEVSE-3/SmartEVSE-3/data/index.html b/SmartEVSE-3/SmartEVSE-3/data/index.html
deleted file mode 100644
index 26f051f..0000000
--- a/SmartEVSE-3/SmartEVSE-3/data/index.html
+++ /dev/null
@@ -1,1035 +0,0 @@
-
-
-
firmware.bin or firmware.signed.bin (to update the firmware);
-
firmware.debug.bin or firmware.debug.signed.bin (if you want to telnet to your SmartEVSE to see debug messages);
-
rfix.txt (if you want to bulk upload allowed NFC tags for the RFID reader);
-
- You should only flash files with those exact names. No need to flash spiffs.bin for versions 3.6.0-RC1 and newer! No need to rename firmware.debug.bin anymore for versions 3.6.0-RC2 and newer! Signed firmware is verified to be original and can be handled by versions 3.6.2 and newer.
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SmartEVSE-3/SmartEVSE-3/data/update3.html b/SmartEVSE-3/SmartEVSE-3/data/update3.html
deleted file mode 100644
index 21ef75d..0000000
--- a/SmartEVSE-3/SmartEVSE-3/data/update3.html
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
- SmartEVSEv3
-
-
-
-
-
-
-
-
diff --git a/SmartEVSE-3/SmartEVSE-3/include/OneWire.h b/SmartEVSE-3/SmartEVSE-3/include/OneWire.h
deleted file mode 100644
index 6a8e944..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/OneWire.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-; Project: Smart EVSE
-;
-;
-;
-; Permission is hereby granted, free of charge, to any person obtaining a copy
-; of this software and associated documentation files (the "Software"), to deal
-; in the Software without restriction, including without limitation the rights
-; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-; copies of the Software, and to permit persons to whom the Software is
-; furnished to do so, subject to the following conditions:
-;
-; The above copyright notice and this permission notice shall be included in
-; all copies or substantial portions of the Software.
-;
-; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-; THE SOFTWARE.
-*/
-
-
-#ifndef __ONEWIRE_H
-#define __ONEWIRE_H
-
-extern Preferences preferences;
-
-void ReadRFIDlist(void);
-void DeleteAllRFID(void);
-void CheckRFID(void);
-void LoadandStoreRFID(unsigned int *RFIDparam);
-
-#endif // #ifndef __ONEWIRE_H
diff --git a/SmartEVSE-3/SmartEVSE-3/include/README b/SmartEVSE-3/SmartEVSE-3/include/README
deleted file mode 100644
index 194dcd4..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/README
+++ /dev/null
@@ -1,39 +0,0 @@
-
-This directory is intended for project header files.
-
-A header file is a file containing C declarations and macro definitions
-to be shared between several project source files. You request the use of a
-header file in your project source file (C, C++, etc) located in `src` folder
-by including it, with the C preprocessing directive `#include'.
-
-```src/main.c
-
-#include "header.h"
-
-int main (void)
-{
- ...
-}
-```
-
-Including a header file produces the same results as copying the header file
-into each source file that needs it. Such copying would be time-consuming
-and error-prone. With a header file, the related declarations appear
-in only one place. If they need to be changed, they can be changed in one
-place, and programs that include the header file will automatically use the
-new version when next recompiled. The header file eliminates the labor of
-finding and changing all the copies as well as the risk that a failure to
-find one copy will result in inconsistencies within a program.
-
-In C, the usual convention is to give header files names that end with `.h'.
-It is most portable to use only letters, digits, dashes, and underscores in
-header file names, and at most one dot.
-
-Read more about using header files in official GCC documentation:
-
-* Include Syntax
-* Include Operation
-* Once-Only Headers
-* Computed Includes
-
-https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
diff --git a/SmartEVSE-3/SmartEVSE-3/include/evse.h b/SmartEVSE-3/SmartEVSE-3/include/evse.h
deleted file mode 100644
index b60d73f..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/evse.h
+++ /dev/null
@@ -1,592 +0,0 @@
-/*
-; Project: Smart EVSE v3
-;
-;
-; Permission is hereby granted, free of charge, to any person obtaining a copy
-; of this software and associated documentation files (the "Software"), to deal
-; in the Software without restriction, including without limitation the rights
-; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-; copies of the Software, and to permit persons to whom the Software is
-; furnished to do so, subject to the following conditions:
-;
-; The above copyright notice and this permission notice shall be included in
-; all copies or substantial portions of the Software.
-;
-; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-; THE SOFTWARE.
- */
-
-#ifndef __EVSE_MAIN
-
-#define __EVSE_MAIN
-
-#ifndef DBG
-//the wifi-debugger is available by telnetting to your SmartEVSE device
-#define DBG 0 //comment or set to 0 for production release, 0 = no debug 1 = debug over telnet, 2 = debug over usb serial
-#endif
-
-#ifndef FAKE_RFID
-//set FAKE_RFID to 1 to emulate an rfid reader with rfid of card = 123456
-//showing the rfid card is simulated by executing http://smartevse-xxx.lan/debug?showrfid=1
-//don't forget to first store the card before it can activate charging
-#define FAKE_RFID 0
-#endif
-
-#ifndef AUTOMATED_TESTING
-//set AUTOMATED_TESTING to 1 to make hardware-related paramaters like MaxCurrent and MaxCircuit updatable via REST API
-//e.g. by executing curl -X POST http://smartevse-xxx.lan/automated_testing?maxcurrent=100
-#define AUTOMATED_TESTING 0
-#endif
-
-#ifndef FAKE_SUNNY_DAY
-//set this to 1 to emulate a sunny day where your solar charger is injecting current in the grid:
-#define FAKE_SUNNY_DAY 0
-//disclaimer: might not work for CT1 calibration/uncalibration stuff, since I can't test that
-//the number of Amperes you want to have fake injected into Lx
-#endif
-
-#if FAKE_SUNNY_DAY
-#define INJECT_CURRENT_L1 10
-#define INJECT_CURRENT_L2 0
-#define INJECT_CURRENT_L3 0
-#endif
-
-#ifndef MQTT
-#define MQTT 1 // Uncomment or set to 0 to disable MQTT support in code
-#endif
-
-#ifndef MODEM
-//the wifi-debugger is available by telnetting to your SmartEVSE device
-#define MODEM 0 //0 = no modem 1 = modem
-#endif
-
-#ifndef VERSION
-//please note that this version will only be displayed with the correct time/date if the program is recompiled
-//so the webserver will show correct version if evse.cpp is recompiled
-//the lcd display will show correct version if glcd.cpp is recompiled
-#define VERSION (__TIME__ " @" __DATE__)
-#endif
-
-
-#if DBG == 0
-//used to steer RemoteDebug
-#define DEBUG_DISABLED 1
-#define _LOG_W( ... ) //dummy
-#define _LOG_I( ... ) //dummy
-#define _LOG_D( ... ) //dummy
-#define _LOG_V( ... ) //dummy
-#define _LOG_A( ... ) //dummy
-#define _LOG_W_NO_FUNC( ... ) //dummy
-#define _LOG_I_NO_FUNC( ... ) //dummy
-#define _LOG_D_NO_FUNC( ... ) //dummy
-#define _LOG_V_NO_FUNC( ... ) //dummy
-#define _LOG_A_NO_FUNC( ... ) //dummy
-#endif
-
-#if DBG == 1
-#define _LOG_A(fmt, ...) if (Debug.isActive(Debug.ANY)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) //Always = Errors!!!
-#define _LOG_P(fmt, ...) if (Debug.isActive(Debug.PROFILER)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
-#define _LOG_V(fmt, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) //Verbose
-#define _LOG_D(fmt, ...) if (Debug.isActive(Debug.DEBUG)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) //Debug
-#define _LOG_I(fmt, ...) if (Debug.isActive(Debug.INFO)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) //Info
-#define _LOG_W(fmt, ...) if (Debug.isActive(Debug.WARNING)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) //Warning
-#define _LOG_E(fmt, ...) if (Debug.isActive(Debug.ERROR)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) //Error not used!
-#define _LOG_A_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.ANY)) Debug.printf(fmt, ##__VA_ARGS__)
-#define _LOG_P_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.PROFILER)) Debug.printf(fmt, ##__VA_ARGS__)
-#define _LOG_V_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.printf(fmt, ##__VA_ARGS__)
-#define _LOG_D_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.DEBUG)) Debug.printf(fmt, ##__VA_ARGS__)
-#define _LOG_I_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.INFO)) Debug.printf(fmt, ##__VA_ARGS__)
-#define _LOG_W_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.WARNING)) Debug.printf(fmt, ##__VA_ARGS__)
-#define _LOG_E_NO_FUNC(fmt, ...) if (Debug.isActive(Debug.ERROR)) Debug.printf(fmt, ##__VA_ARGS__)
-#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
-extern RemoteDebug Debug;
-#endif
-
-#if DBG == 2
-#define DEBUG_DISABLED 1
-#define _LOG_W( ... ) log_w ( __VA_ARGS__ )
-#define _LOG_I( ... ) log_i ( __VA_ARGS__ )
-#define _LOG_D( ... ) log_d ( __VA_ARGS__ )
-#define _LOG_V( ... ) log_v ( __VA_ARGS__ )
-#define _LOG_A( ... ) log_n ( __VA_ARGS__ )
-#define _LOG_W_NO_FUNC( ... ) Serial.printf ( __VA_ARGS__ )
-#define _LOG_I_NO_FUNC( ... ) Serial.printf ( __VA_ARGS__ )
-#define _LOG_D_NO_FUNC( ... ) Serial.printf ( __VA_ARGS__ )
-#define _LOG_V_NO_FUNC( ... ) Serial.printf ( __VA_ARGS__ )
-#define _LOG_A_NO_FUNC( ... ) Serial.printf ( __VA_ARGS__ )
-#endif
-
-// Pin definitions left side ESP32
-#define PIN_TEMP 36
-#define PIN_CP_IN 39
-#define PIN_PP_IN 34
-#define PIN_LOCK_IN 35
-#define PIN_SSR 32
-#define PIN_LCD_SDO_B3 33 // = SPI_MOSI
-#define PIN_LCD_A0_B2 25
-#define PIN_LCD_CLK 26 // = SPI_SCK
-#define PIN_SSR2 27
-#define PIN_LCD_LED 14
-#define PIN_LEDB 12
-#define PIN_RCM_FAULT 13
-
-// Pin definitions right side ESP32
-#define PIN_RS485_RX 23
-#define PIN_RS485_DIR 22
-//#define PIN_RXD
-//#define PIN_TXD
-#define PIN_RS485_TX 21
-#define PIN_CP_OUT 19
-#define PIN_ACTB 18
-#define PIN_LCD_RST 5
-#define PIN_ACTA 17
-#define PIN_SW_IN 16
-#define PIN_LEDG 4
-#define PIN_IO0_B1 0
-#define PIN_LEDR 2
-#define PIN_CPOFF 15
-
-#define SPI_MOSI 33 // SPI connections to LCD
-#define SPI_MISO -1
-#define SPI_SCK 26
-#define SPI_SS -1
-
-#define CP_CHANNEL 0
-#define RED_CHANNEL 2 // PWM channel 2 (0 and 1 are used by CP signal)
-#define GREEN_CHANNEL 3
-#define BLUE_CHANNEL 4
-#define LCD_CHANNEL 5 // LED Backlight LCD
-
-#define PWM_5 50 // 5% of PWM
-#define PWM_95 950 // 95% of PWM
-#define PWM_100 1000 // 100% of PWM
-
-#define ICAL 1024 // Irms Calibration value (for Current transformers)
-#define MAX_MAINS 25 // max Current the Mains connection can supply
-#define MAX_SUMMAINS 600 // only used for capacity rate limiting, max current over the sum of all phases
-#define MAX_CURRENT 13 // max charging Current for the EV
-#ifndef MIN_CURRENT
-#define MIN_CURRENT 6 // minimum Current the EV will accept
-#endif
-#define MODE 0 // Normal EVSE mode
-#define LOCK 0 // No Cable lock
-#define MAX_CIRCUIT 16 // Max current of the EVSE circuit breaker
-#define CONFIG 0 // Configuration: 0= TYPE 2 socket, 1= Fixed Cable
-#define LOADBL 0 // Load Balancing disabled
-#define SWITCH 0 // 0= Charge on plugin, 1= (Push)Button on IO2 is used to Start/Stop charging.
-#define RC_MON 0 // Residual Current Monitoring on IO3. Disabled=0, RCM14=1
-#define CHARGEDELAY 60 // Seconds to wait after overcurrent, before trying again
-#define BACKLIGHT 120 // Seconds delay for the LCD backlight to turn off.
-#define RFIDLOCKTIME 60 // Seconds delay for the EVSE to lock again (RFIDreader = EnableOne)
-#define START_CURRENT 4 // Start charging when surplus current on sum of all phases exceeds 4A (Solar)
-#define STOP_TIME 10 // Stop charging after 10 minutes at MIN charge current (Solar)
-#define IMPORT_CURRENT 0 // Allow the use of grid power when solar charging (Amps)
-#define MAINS_METER 0 // Mains Meter, 0=Disabled, 1= Sensorbox, 2=Phoenix, 3= Finder, 4= Eastron, 5=Custom
-#define GRID 0 // Grid, 0= 4-Wire CW, 1= 4-Wire CCW, 2= 3-Wire CW, 3= 3-Wire CCW
-#define MAINS_METER_ADDRESS 10
-#define PV_METER 0
-#define PV_METER_ADDRESS 11
-#define EV_METER 0
-#define EV_METER_ADDRESS 12
-#define MIN_METER_ADDRESS 10
-#define MAX_METER_ADDRESS 247
-#define EMCUSTOM_ENDIANESS 0
-#define EMCUSTOM_DATATYPE 0
-#define EMCUSTOM_FUNCTION 4
-#define EMCUSTOM_UREGISTER 0
-#define EMCUSTOM_UDIVISOR 8
-#define EMCUSTOM_IREGISTER 0
-#define EMCUSTOM_IDIVISOR 8
-#define EMCUSTOM_PREGISTER 0
-#define EMCUSTOM_PDIVISOR 8
-#define EMCUSTOM_EREGISTER 0
-#define EMCUSTOM_EDIVISOR 8
-#define RFID_READER 0
-#define ACCESS_BIT 1
-#define WIFI_MODE 0
-#define AP_PASSWORD "00000000"
-#define CARD_OFFSET 0
-#define INITIALIZED 0
-#define ENABLE_C2 ALWAYS_ON
-#define MAX_TEMPERATURE 65
-#define DELAYEDSTARTTIME 0 // The default StartTime for delayed charged, 0 = not delaying
-#define DELAYEDSTOPTIME 0 // The default StopTime for delayed charged, 0 = not stopping
-#define SOLARSTARTTIME 40 // Seconds to keep chargecurrent at 6A
-#define PUBLIC_KEY "5c7a848c3445793002487608a65fa259cefb16790f7c2f4a1d10af702393f7db\0";
-
-
-// Mode settings
-#define MODE_NORMAL 0
-#define MODE_SMART 1
-#define MODE_SOLAR 2
-
-#define MODBUS_BAUDRATE 9600
-#define MODBUS_TIMEOUT 4
-#define ACK_TIMEOUT 1000 // 1000ms timeout
-#define NR_EVSES 8
-#define BROADCAST_ADR 0x09
-#define COMM_TIMEOUT 11 // Timeout for MainsMeter
-#define COMM_EVTIMEOUT 8*NR_EVSES // Timeout for EV Energy Meters
-
-#define STATE_A 0 // A Vehicle not connected
-#define STATE_B 1 // B Vehicle connected / not ready to accept energy
-#define STATE_C 2 // C Vehicle connected / ready to accept energy / ventilation not required
-#define STATE_D 3 // D Vehicle connected / ready to accept energy / ventilation required (not implemented)
-#define STATE_COMM_B 4 // E State change request A->B (set by node)
-#define STATE_COMM_B_OK 5 // F State change A->B OK (set by master)
-#define STATE_COMM_C 6 // G State change request B->C (set by node)
-#define STATE_COMM_C_OK 7 // H State change B->C OK (set by master)
-#define STATE_ACTSTART 8 // I Activation mode in progress
-#define STATE_B1 9 // J Vehicle connected / EVSE not ready to deliver energy: no PWM signal
-#define STATE_C1 10 // K Vehicle charging / EVSE not ready to deliver energy: no PWM signal (temp state when stopping charge from EVSE)
-#define STATE_MODEM_REQUEST 11 // L Vehicle connected / requesting ISO15118 communication, 0% duty
-#define STATE_MODEM_WAIT 12 // M Vehicle connected / requesting ISO15118 communication, 5% duty
-#define STATE_MODEM_DONE 13 // Modem communication succesful, SoCs extracted. Here, re-plug vehicle
-#define STATE_MODEM_DENIED 14 // Modem access denied based on EVCCID, re-plug vehicle and try again
-
-#define NOSTATE 255
-
-#define PILOT_12V 1 // State A - vehicle disconnected
-#define PILOT_9V 2 // State B - vehicle connected
-#define PILOT_6V 3 // State C - EV charge
-#define PILOT_3V 4
-#define PILOT_DIODE 5
-#define PILOT_NOK 0
-
-
-#define NO_ERROR 0
-#define LESS_6A 1
-#define CT_NOCOMM 2
-#define TEMP_HIGH 4
-#define EV_NOCOMM 8
-#define RCM_TRIPPED 16 // RCM tripped. >6mA DC residual current detected.
-#define NO_SUN 32
-#define Test_IO 64
-#define BL_FLASH 128
-
-#define STATE_A_LED_BRIGHTNESS 40
-#define STATE_B_LED_BRIGHTNESS 255
-#define ERROR_LED_BRIGHTNESS 255
-#define WAITING_LED_BRIGHTNESS 255
-#define LCD_BRIGHTNESS 255
-
-
-#define CP_ON digitalWrite(PIN_CPOFF, LOW);
-#define CP_OFF digitalWrite(PIN_CPOFF, HIGH);
-
-#define PILOT_CONNECTED digitalWrite(PIN_CPOFF, LOW);
-#define PILOT_DISCONNECTED digitalWrite(PIN_CPOFF, HIGH);
-
-#define CONTACTOR1_ON _LOG_A("Switching Contactor1 ON.\n"); digitalWrite(PIN_SSR, HIGH);
-#define CONTACTOR1_OFF _LOG_A("Switching Contactor1 OFF.\n"); digitalWrite(PIN_SSR, LOW);
-
-#define CONTACTOR2_ON _LOG_A("Switching Contactor2 ON.\n"); digitalWrite(PIN_SSR2, HIGH);
-#define CONTACTOR2_OFF _LOG_A("Switching Contactor2 OFF.\n"); digitalWrite(PIN_SSR2, LOW);
-
-#define BACKLIGHT_ON digitalWrite(PIN_LCD_LED, HIGH);
-#define BACKLIGHT_OFF digitalWrite(PIN_LCD_LED, LOW);
-
-#define ACTUATOR_LOCK { _LOG_A("Locking Actuator.\n"); digitalWrite(PIN_ACTB, HIGH); digitalWrite(PIN_ACTA, LOW); }
-#define ACTUATOR_UNLOCK { _LOG_A("Unlocking Actuator.\n"); digitalWrite(PIN_ACTB, LOW); digitalWrite(PIN_ACTA, HIGH); }
-#define ACTUATOR_OFF { digitalWrite(PIN_ACTB, HIGH); digitalWrite(PIN_ACTA, HIGH); }
-
-#define ONEWIRE_LOW { digitalWrite(PIN_SW_IN, LOW); pinMode(PIN_SW_IN, OUTPUT); } // SW set to 0, set to output (driven low)
-#define ONEWIRE_HIGH { digitalWrite(PIN_SW_IN, HIGH); pinMode(PIN_SW_IN, OUTPUT); } // SW set to 1, set to output (driven high)
-#define ONEWIRE_FLOATHIGH pinMode(PIN_SW_IN, INPUT_PULLUP ); // SW input (floating high)
-
-#define RCMFAULT digitalRead(PIN_RCM_FAULT)
-#define FREE(x) free(x); x = NULL;
-#define FW_DOWNLOAD_PATH "http://smartevse-3.s3.eu-west-2.amazonaws.com"
-
-#define MODBUS_INVALID 0
-#define MODBUS_OK 1
-#define MODBUS_REQUEST 2
-#define MODBUS_RESPONSE 3
-#define MODBUS_EXCEPTION 4
-
-#define MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS 0x02
-#define MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE 0x03
-
-#define MODBUS_EVSE_STATUS_START 0x0000
-#define MODBUS_EVSE_STATUS_COUNT 12
-#define MODBUS_EVSE_CONFIG_START 0x0100
-#define MODBUS_EVSE_CONFIG_COUNT 10
-#define MODBUS_SYS_CONFIG_START 0x0200
-#define MODBUS_SYS_CONFIG_COUNT 26
-
-#define MODBUS_MAX_REGISTER_READ MODBUS_SYS_CONFIG_COUNT
-#define MODBUS_BUFFER_SIZE MODBUS_MAX_REGISTER_READ * 2 + 10
-
-// EVSE status
-#define STATUS_STATE 64 // 0x0000: State
-#define STATUS_ERROR 65 // 0x0001: Error
-#define STATUS_CURRENT 66 // 0x0002: Charging current (A * 10)
-#define STATUS_MODE 67 // 0x0003: EVSE Mode
-#define STATUS_SOLAR_TIMER 68 // 0x0004: Solar Timer
-#define STATUS_ACCESS 69 // 0x0005: Access bit
-#define STATUS_CONFIG_CHANGED 70 // 0x0006: Configuration changed
-#define STATUS_MAX 71 // 0x0007: Maximum charging current (RO)
-#define STATUS_PHASE_COUNT 72 // 0x0008: Number of used phases (RO) (ToDo)
-#define STATUS_REAL_CURRENT 73 // 0x0009: Real charging current (RO) (ToDo)
-#define STATUS_TEMP 74 // 0x000A: Temperature (RO)
-#define STATUS_SERIAL 75 // 0x000B: Serial number (RO)
-
-// Node specific configuration
-#define MENU_ENTER 1
-#define MENU_CONFIG 2 // 0x0100: Configuration
-#define MENU_LOCK 3 // 0x0101: Cable lock
-#define MENU_MIN 4 // 0x0102: MIN Charge Current the EV will accept
-#define MENU_MAX 5 // 0x0103: MAX Charge Current for this EVSE
-#define MENU_LOADBL 6 // 0x0104: Load Balance
-#define MENU_SWITCH 7 // 0x0105: External Start/Stop button
-#define MENU_RCMON 8 // 0x0106: Residual Current Monitor
-#define MENU_RFIDREADER 9 // 0x0107: Use RFID reader
-#define MENU_EVMETER 10 // 0x0108: Type of EV electric meter
-#define MENU_EVMETERADDRESS 11 // 0x0109: Address of EV electric meter
-
-// System configuration (same on all SmartEVSE in a LoadBalancing setup)
-#define MENU_MODE 12 // 0x0200: EVSE mode
-#define MENU_CIRCUIT 13 // 0x0201: EVSE Circuit max Current
-#define MENU_GRID 14 // 0x0202: Grid type to which the Sensorbox is connected
-#define MENU_CAL 15 // 0x0203: CT calibration value
-#define MENU_MAINS 16 // 0x0204: Max Mains Current
-#define MENU_START 17 // 0x0205: Surplus energy start Current
-#define MENU_STOP 18 // 0x0206: Stop solar charging at 6A after this time
-#define MENU_IMPORT 19 // 0x0207: Allow grid power when solar charging
-#define MENU_MAINSMETER 20 // 0x0208: Type of Mains electric meter
-#define MENU_MAINSMETERADDRESS 21 // 0x0209: Address of Mains electric meter
-#define MENU_EMCUSTOM_ENDIANESS 22 // 0x020D: Byte order of custom electric meter
-#define MENU_EMCUSTOM_DATATYPE 23 // 0x020E: Data type of custom electric meter
-#define MENU_EMCUSTOM_FUNCTION 24 // 0x020F: Modbus Function (3/4) of custom electric meter
-#define MENU_EMCUSTOM_UREGISTER 25 // 0x0210: Register for Voltage (V) of custom electric meter
-#define MENU_EMCUSTOM_UDIVISOR 26 // 0x0211: Divisor for Voltage (V) of custom electric meter (10^x)
-#define MENU_EMCUSTOM_IREGISTER 27 // 0x0212: Register for Current (A) of custom electric meter
-#define MENU_EMCUSTOM_IDIVISOR 28 // 0x0213: Divisor for Current (A) of custom electric meter (10^x)
-#define MENU_EMCUSTOM_PREGISTER 29 // 0x0214: Register for Power (W) of custom electric meter
-#define MENU_EMCUSTOM_PDIVISOR 30 // 0x0215: Divisor for Power (W) of custom electric meter (10^x)
-#define MENU_EMCUSTOM_EREGISTER 31 // 0x0216: Register for Energy (kWh) of custom electric meter
-#define MENU_EMCUSTOM_EDIVISOR 32 // 0x0217: Divisor for Energy (kWh) of custom electric meter (10^x)
-#define MENU_EMCUSTOM_READMAX 33 // 0x0218: Maximum register read (ToDo)
-#define MENU_WIFI 34 // 0x0219: WiFi mode
-#define MENU_C2 35
-#define MENU_MAX_TEMP 36
-#define MENU_SUMMAINS 37
-#define MENU_OFF 38 // so access bit is reset and charging stops when pressing < button 2 seconds
-#define MENU_ON 39 // so access bit is set and charging starts when pressing > button 2 seconds
-#define MENU_EXIT 40
-
-#define MENU_STATE 50
-
-#define _RSTB_0 digitalWrite(PIN_LCD_RST, LOW);
-#define _RSTB_1 digitalWrite(PIN_LCD_RST, HIGH);
-#define _A0_0 digitalWrite(PIN_LCD_A0_B2, LOW);
-#define _A0_1 digitalWrite(PIN_LCD_A0_B2, HIGH);
-
-#define EM_SENSORBOX 1 // Mains meter types
-#define EM_PHOENIX_CONTACT 2
-#define EM_FINDER_7E 3
-#define EM_EASTRON3P 4
-#define EM_EASTRON3P_INV 5
-#define EM_ABB 6
-#define EM_SOLAREDGE 7
-#define EM_WAGO 8
-#define EM_API 9
-#define EM_EASTRON1P 10
-#define EM_FINDER_7M 11
-#define EM_UNUSED_SLOT1 12
-#define EM_UNUSED_SLOT2 13
-#define EM_UNUSED_SLOT3 14
-#define EM_UNUSED_SLOT4 15
-#define EM_CUSTOM 16
-
-#define ENDIANESS_LBF_LWF 0
-#define ENDIANESS_LBF_HWF 1
-#define ENDIANESS_HBF_LWF 2
-#define ENDIANESS_HBF_HWF 3
-
-#define OWNER_FACT "SmartEVSE"
-#define REPO_FACT "SmartEVSE-3"
-#define OWNER_COMM "dingo35"
-#define REPO_COMM "SmartEVSE-3.5"
-
-typedef enum mb_datatype {
- MB_DATATYPE_INT32 = 0,
- MB_DATATYPE_FLOAT32 = 1,
- MB_DATATYPE_INT16 = 2,
- MB_DATATYPE_MAX,
-} MBDataType;
-
-
-extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
-
-#define RTC_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock)
-#define RTC_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock)
-
-
-extern String APpassword;
-extern struct tm timeinfo;
-
-
-extern uint16_t ICal; // CT calibration value
-extern uint8_t Mode; // EVSE mode
-extern uint8_t LoadBl; // Load Balance Setting (Disable, Master or Node)
-extern uint8_t Grid;
-extern uint8_t MainsMeterAddress;
-extern uint8_t EVMeter; // Type of EV electric meter (0: Disabled / Constants EM_*)
-extern uint8_t EVMeterAddress;
-#if FAKE_RFID
-extern uint8_t Show_RFID;
-#endif
-
-extern int16_t Irms[3]; // Momentary current per Phase (Amps *10) (23 = 2.3A)
-extern int16_t Irms_EV[3]; // Momentary current per Phase (Amps *10) (23 = 2.3A)
-
-extern uint8_t State;
-extern uint8_t ErrorFlags;
-extern uint8_t NextState;
-
-extern int16_t Isum;
-extern uint16_t Balanced[NR_EVSES]; // Amps value per EVSE
-
-extern uint8_t LCDTimer;
-extern uint16_t BacklightTimer; // remaining seconds the LCD backlight is active
-extern uint8_t ButtonState; // Holds latest push Buttons state (LSB 2:0)
-extern uint8_t OldButtonState; // Holds previous push Buttons state (LSB 2:0)
-extern uint8_t LCDNav;
-extern uint8_t LCDupdate;
-extern uint8_t SubMenu;
-extern uint32_t ScrollTimer;
-extern uint8_t ChargeDelay; // Delays charging in seconds.
-extern uint8_t TestState;
-extern uint8_t Access_bit;
-extern uint16_t CardOffset;
-
-extern uint8_t GridActive; // When the CT's are used on Sensorbox2, it enables the GRID menu option.
-extern uint8_t CalActive; // When the CT's are used on Sensorbox(1.5 or 2), it enables the CAL menu option.
-extern uint16_t Iuncal;
-extern uint16_t SolarStopTimer;
-extern int32_t EnergyCharged;
-extern int32_t EnergyCapacity;
-extern int16_t PowerMeasured;
-extern uint8_t RFIDstatus;
-extern bool LocalTimeSet;
-extern uint32_t serialnr;
-
-extern uint8_t MenuItems[MENU_EXIT];
-
-enum EnableC2_t { NOT_PRESENT, ALWAYS_OFF, SOLAR_OFF, ALWAYS_ON, AUTO };
-enum Modem_t { NOTPRESENT, EXPERIMENT };
-const static char StrEnableC2[][12] = { "Not present", "Always Off", "Solar Off", "Always On", "Auto" };
-const static char StrModem[][12] = { "Not present", "Experiment" };
-enum Single_Phase_t { FALSE, GOING_TO_SWITCH, AFTER_SWITCH };
-extern Single_Phase_t Switching_To_Single_Phase;
-extern uint8_t Nr_Of_Phases_Charging;
-
-const struct {
- char LCD[10];
- char Desc[52];
- uint16_t Min;
- uint16_t Max;
- uint16_t Default;
-} MenuStr[MENU_EXIT + 1] = {
- {"", "Not in menu", 0, 0, 0},
- {"", "Hold 2 sec", 0, 0, 0},
-
- // Node specific configuration
- /* LCD, Desc, Min, Max, Default */
- {"CONFIG", "Fixed Cable or Type 2 Socket", 0, 1, CONFIG},
- {"LOCK", "Cable locking actuator type", 0, 2, LOCK},
- {"MIN", "MIN Charge Current the EV will accept (per phase)", MIN_CURRENT, 16, MIN_CURRENT},
- {"MAX", "MAX Charge Current for this EVSE (per phase)", 6, 80, MAX_CURRENT},
- {"PWR SHARE", "Share Power between multiple SmartEVSEs (2-8)", 0, NR_EVSES, LOADBL},
- {"SWITCH", "Switch function control on pin SW", 0, 4, SWITCH},
- {"RCMON", "Residual Current Monitor on pin RCM", 0, 1, RC_MON},
- {"RFID", "RFID reader, learn/remove cards", 0, 5, RFID_READER},
- {"EV METER","Type of EV electric meter", 0, EM_CUSTOM, EV_METER},
- {"EV ADDR", "Address of EV electric meter", MIN_METER_ADDRESS, MAX_METER_ADDRESS, EV_METER_ADDRESS},
-
- // System configuration
- /* LCD, Desc, Min, Max, Default */
- {"MODE", "Normal, Smart or Solar EVSE mode", 0, 2, MODE},
- {"CIRCUIT", "EVSE Circuit max Current", 10, 160, MAX_CIRCUIT},
- {"GRID", "Grid type to which the Sensorbox is connected", 0, 1, GRID},
- {"CAL", "Calibrate CT1 (CT2+3 will also change)", (unsigned int) (ICAL * 0.3), (unsigned int) (ICAL * 2.0), ICAL}, // valid range is 0.3 - 2.0 times measured value
- {"MAINS", "Max MAINS Current (per phase)", 10, 200, MAX_MAINS},
- {"START", "Surplus energy start Current (sum of phases)", 0, 48, START_CURRENT},
- {"STOP", "Stop solar charging at 6A after this time", 0, 60, STOP_TIME},
- {"IMPORT", "Allow grid power when solar charging (sum of phase)",0, 48, IMPORT_CURRENT},
- {"MAINS MET","Type of mains electric meter", 0, EM_CUSTOM, MAINS_METER},
- {"MAINS ADR","Address of mains electric meter", MIN_METER_ADDRESS, MAX_METER_ADDRESS, MAINS_METER_ADDRESS},
- {"BYTE ORD","Byte order of custom electric meter", 0, 3, EMCUSTOM_ENDIANESS},
- {"DATA TYPE","Data type of custom electric meter", 0, MB_DATATYPE_MAX - 1, EMCUSTOM_DATATYPE},
- {"FUNCTION","Modbus Function of custom electric meter", 3, 4, EMCUSTOM_FUNCTION},
- {"VOL REGI","Register for Voltage (V) of custom electric meter", 0, 65530, EMCUSTOM_UREGISTER},
- {"VOL DIVI","Divisor for Voltage (V) of custom electric meter", 0, 7, EMCUSTOM_UDIVISOR},
- {"CUR REGI","Register for Current (A) of custom electric meter", 0, 65530, EMCUSTOM_IREGISTER},
- {"CUR DIVI","Divisor for Current (A) of custom electric meter", 0, 7, EMCUSTOM_IDIVISOR},
- {"POW REGI","Register for Power (W) of custom electric meter", 0, 65534, EMCUSTOM_PREGISTER},
- {"POW DIVI","Divisor for Power (W) of custom electric meter", 0, 7, EMCUSTOM_PDIVISOR},
- {"ENE REGI","Register for Energy (kWh) of custom electric meter", 0, 65534, EMCUSTOM_EREGISTER},
- {"ENE DIVI","Divisor for Energy (kWh) of custom electric meter", 0, 7, EMCUSTOM_EDIVISOR},
- {"READ MAX","Max register read at once of custom electric meter", 3, 255, 3},
- {"WIFI", "Connect to WiFi access point", 0, 2, WIFI_MODE},
- {"CONTACT 2","Contactor2 (C2) behaviour", 0, sizeof(StrEnableC2) / sizeof(StrEnableC2[0])-1, ENABLE_C2},
- {"MAX TEMP","Maximum temperature for the EVSE module", 40, 75, MAX_TEMPERATURE},
- {"SUM MAINS","Capacity Rate limit on sum of MAINS Current (A)", 10, 600, MAX_SUMMAINS},
- {"", "Hold 2 sec to stop charging", 0, 0, 0},
- {"", "Hold 2 sec to start charging", 0, 0, 0},
-
- {"EXIT", "EXIT", 0, 0, 0}
-};
-
-
-struct EMstruct {
- uint8_t Desc[10];
- uint8_t Endianness; // 0: low byte first, low word first, 1: low byte first, high word first, 2: high byte first, low word first, 3: high byte first, high word first
- uint8_t Function; // 3: holding registers, 4: input registers
- MBDataType DataType; // How data is represented on this Modbus meter
- uint16_t URegister; // Single phase voltage (V)
- int8_t UDivisor; // 10^x
- uint16_t IRegister; // Single phase current (A)
- int8_t IDivisor; // 10^x
- uint16_t PRegister; // Total power (W) -- only used for EV/PV meter momentary power
- int8_t PDivisor; // 10^x
- uint16_t ERegister; // Total imported energy (kWh); equals total energy if meter doesnt support exported energy
- int8_t EDivisor; // 10^x
- uint16_t ERegister_Exp; // Total exported energy (kWh)
- int8_t EDivisor_Exp; // 10^x
-};
-
-extern struct EMstruct EMConfig[EM_CUSTOM + 1];
-
-struct DelayedTimeStruct {
- uint32_t epoch2; // in case of Delayed Charging the StartTime in epoch2; if zero we are NOT Delayed Charging
- // epoch2 is the number of seconds since 1/1/2023 00:00 UTC, which equals epoch 1672531200
- // we avoid using epoch so we don't need expensive 64bits arithmetics with difftime
- // and we can store dates until 7/2/2159
- int32_t diff; // StartTime minus current time in seconds
-};
-
-#define EPOCH2_OFFSET 1672531200
-
-extern struct DelayedTimeStruct DelayedStartTime;
-
-void CheckAPpassword(void);
-void read_settings();
-void write_settings(void);
-void setSolarStopTimer(uint16_t Timer);
-void setState(uint8_t NewState);
-void setAccess(bool Access);
-void SetCPDuty(uint32_t DutyCycle);
-uint8_t setItemValue(uint8_t nav, uint16_t val);
-uint16_t getItemValue(uint8_t nav);
-void ConfigureModbusMode(uint8_t newmode);
-
-void handleWIFImode(void);
-
-#endif
diff --git a/SmartEVSE-3/SmartEVSE-3/include/glcd.h b/SmartEVSE-3/SmartEVSE-3/include/glcd.h
deleted file mode 100644
index 861db85..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/glcd.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-; Project: Smart EVSE
-;
-;
-;
-; Permission is hereby granted, free of charge, to any person obtaining a copy
-; of this software and associated documentation files (the "Software"), to deal
-; in the Software without restriction, including without limitation the rights
-; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-; copies of the Software, and to permit persons to whom the Software is
-; furnished to do so, subject to the following conditions:
-;
-; The above copyright notice and this permission notice shall be included in
-; all copies or substantial portions of the Software.
-;
-; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-; THE SOFTWARE.
-*/
-
-#ifndef __GLCD_H
-#define __GLCD_H
-
-#define GLCD_MERGE 0b00001000
-#define GLCD_HIRES_FONT
-#define GLCD_FULL_CHARSET
-#define GLCD_ALIGN_LEFT 0
-#define GLCD_ALIGN_CENTER 1
-#define GLCD_ALIGN_RIGHT 2
-
-extern void GLCDHelp(void);
-extern void GLCD(void);
-extern void GLCDMenu(unsigned char Buttons);
-extern void GLCD_init(void);
-extern void GLCD_version(void);
-
-
-#endif // #ifndef __GLCD_H
\ No newline at end of file
diff --git a/SmartEVSE-3/SmartEVSE-3/include/modbus.h b/SmartEVSE-3/SmartEVSE-3/include/modbus.h
deleted file mode 100644
index 15f64ba..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/modbus.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-; Project: Smart EVSE
-;
-;
-;
-; Permission is hereby granted, free of charge, to any person obtaining a copy
-; of this software and associated documentation files (the "Software"), to deal
-; in the Software without restriction, including without limitation the rights
-; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-; copies of the Software, and to permit persons to whom the Software is
-; furnished to do so, subject to the following conditions:
-;
-; The above copyright notice and this permission notice shall be included in
-; all copies or substantial portions of the Software.
-;
-; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-; THE SOFTWARE.
-*/
-
-#ifndef __EVSE_MODBUS
-#define __EVSE_MODBUS
-
-struct ModBus {
- uint8_t Address;
- uint8_t Function;
- uint16_t Register;
- uint16_t RegisterCount;
- uint16_t Value;
- uint8_t *Data;
- uint8_t DataLength;
- uint8_t Type;
- uint8_t RequestAddress;
- uint8_t RequestFunction;
- uint16_t RequestRegister;
- uint8_t Exception;
-};
-
-// definition of MBserver / MBclient class is done in evse.cpp
-extern ModbusServerRTU MBserver;
-extern ModbusClientRTU MBclient;
-
-void RS485SendBuf(uint8_t *buffer, uint8_t len);
-uint8_t mapModbusRegister2ItemID();
-
-// ########################### Modbus main functions ###########################
-
-void ModbusReadInputRequest(uint8_t address, uint8_t function, uint16_t reg, uint16_t quantity);
-void ModbusReadInputResponse(uint8_t address, uint8_t function, uint16_t *values, uint8_t count);
-void ModbusWriteSingleRequest(uint8_t address, uint16_t reg, uint16_t value);
-void ModbusWriteMultipleRequest(uint8_t address, uint16_t reg, uint16_t *values, uint8_t count);
-void ModbusException(uint8_t address, uint8_t function, uint8_t exception);
-void ModbusDecode(uint8_t *buf, uint8_t len);
-
-// ########################### EVSE modbus functions ###########################
-
-signed int receiveMeasurement(uint8_t *buf, uint8_t pos, uint8_t Endianness, MBDataType dataType, signed char Divisor);
-void requestMeasurement(uint8_t Meter, uint8_t Address, uint16_t Register, uint8_t Count);
-void requestCurrentMeasurement(uint8_t Meter, uint8_t Address);
-uint8_t receiveCurrentMeasurement(uint8_t *buf, uint8_t Meter, signed int *var);
-
-//void ReadItemValueResponse(void);
-//void WriteItemValueResponse(void);
-//void WriteMultipleItemValueResponse(void);
-
-
-#endif
diff --git a/SmartEVSE-3/SmartEVSE-3/include/mongoose.h b/SmartEVSE-3/SmartEVSE-3/include/mongoose.h
deleted file mode 100644
index 9ae5071..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/mongoose.h
+++ /dev/null
@@ -1,2930 +0,0 @@
-// Copyright (c) 2004-2013 Sergey Lyubka
-// Copyright (c) 2013-2024 Cesanta Software Limited
-// All rights reserved
-//
-// This software is dual-licensed: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation. For the terms of this
-// license, see http://www.gnu.org/licenses/
-//
-// You are free to use this software under the terms of the GNU General
-// Public License, but WITHOUT ANY WARRANTY; without even the implied
-// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-// See the GNU General Public License for more details.
-//
-// Alternatively, you can license this software under a commercial
-// license, as set out in https://www.mongoose.ws/licensing/
-//
-// SPDX-License-Identifier: GPL-2.0-only or commercial
-
-#ifndef MONGOOSE_H
-#define MONGOOSE_H
-
-#define MG_VERSION "7.13"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define MG_ARCH_CUSTOM 0 // User creates its own mongoose_custom.h
-#define MG_ARCH_UNIX 1 // Linux, BSD, Mac, ...
-#define MG_ARCH_WIN32 2 // Windows
-#define MG_ARCH_ESP32 3 // ESP32
-#define MG_ARCH_ESP8266 4 // ESP8266
-#define MG_ARCH_FREERTOS 5 // FreeRTOS
-#define MG_ARCH_AZURERTOS 6 // MS Azure RTOS
-#define MG_ARCH_ZEPHYR 7 // Zephyr RTOS
-#define MG_ARCH_NEWLIB 8 // Bare metal ARM
-#define MG_ARCH_CMSIS_RTOS1 9 // CMSIS-RTOS API v1 (Keil RTX)
-#define MG_ARCH_TIRTOS 10 // Texas Semi TI-RTOS
-#define MG_ARCH_RP2040 11 // Raspberry Pi RP2040
-#define MG_ARCH_ARMCC 12 // Keil MDK-Core with Configuration Wizard
-#define MG_ARCH_CMSIS_RTOS2 13 // CMSIS-RTOS API v2 (Keil RTX5, FreeRTOS)
-#define MG_ARCH_RTTHREAD 14 // RT-Thread RTOS
-
-#if !defined(MG_ARCH)
-#if defined(__unix__) || defined(__APPLE__)
-#define MG_ARCH MG_ARCH_UNIX
-#elif defined(_WIN32)
-#define MG_ARCH MG_ARCH_WIN32
-#elif defined(ICACHE_FLASH) || defined(ICACHE_RAM_ATTR)
-#define MG_ARCH MG_ARCH_ESP8266
-#elif defined(__ZEPHYR__)
-#define MG_ARCH MG_ARCH_ZEPHYR
-#elif defined(ESP_PLATFORM)
-#define MG_ARCH MG_ARCH_ESP32
-#elif defined(FREERTOS_IP_H)
-#define MG_ARCH MG_ARCH_FREERTOS
-#define MG_ENABLE_FREERTOS_TCP 1
-#elif defined(AZURE_RTOS_THREADX)
-#define MG_ARCH MG_ARCH_AZURERTOS
-#elif defined(PICO_TARGET_NAME)
-#define MG_ARCH MG_ARCH_RP2040
-#elif defined(__RTTHREAD__)
-#define MG_ARCH MG_ARCH_RTTHREAD
-#endif
-#endif // !defined(MG_ARCH)
-
-#if !defined(MG_ARCH) || (MG_ARCH == MG_ARCH_CUSTOM)
-#include "mongoose_custom.h" // keep this include
-#endif
-
-#if !defined(MG_ARCH)
-#error "MG_ARCH is not specified and we couldn't guess it. Set -D MG_ARCH=..."
-#endif
-
-// http://esr.ibiblio.org/?p=5095
-#define MG_BIG_ENDIAN (*(uint16_t *) "\0\xff" < 0x100)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#if MG_ARCH == MG_ARCH_AZURERTOS
-
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-#define PATH_MAX FX_MAXIMUM_PATH
-#define MG_DIRSEP '\\'
-
-#define socklen_t int
-#define closesocket(x) soc_close(x)
-
-#undef FOPEN_MAX
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_ESP32
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-#define MG_PATH_MAX 128
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_ESP8266
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-#define MG_PATH_MAX 128
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_FREERTOS
-
-#include
-#if !defined(MG_ENABLE_LWIP) || !MG_ENABLE_LWIP
-#include
-#endif
-#include
-#include
-#include
-#include
-#include
-#include // rand(), strtol(), atoi()
-#include
-#if defined(__ARMCC_VERSION)
-#define mode_t size_t
-#include
-#include
-#else
-#include
-#endif
-
-#include
-#include
-
-#ifndef MG_IO_SIZE
-#define MG_IO_SIZE 512
-#endif
-
-#define calloc(a, b) mg_calloc(a, b)
-#define free(a) vPortFree(a)
-#define malloc(a) pvPortMalloc(a)
-#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
-
-// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
-static inline void *mg_calloc(size_t cnt, size_t size) {
- void *p = pvPortMalloc(cnt * size);
- if (p != NULL) memset(p, 0, size * cnt);
- return p;
-}
-
-#define mkdir(a, b) mg_mkdir(a, b)
-static inline int mg_mkdir(const char *path, mode_t mode) {
- (void) path, (void) mode;
- return -1;
-}
-
-#endif // MG_ARCH == MG_ARCH_FREERTOS
-
-
-#if MG_ARCH == MG_ARCH_NEWLIB
-#define _POSIX_TIMERS
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define MG_PATH_MAX 100
-#define MG_ENABLE_SOCKET 0
-#define MG_ENABLE_DIRLIST 0
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_RP2040
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-int mkdir(const char *, mode_t);
-#endif
-
-
-#if MG_ARCH == MG_ARCH_RTTHREAD
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#ifndef MG_IO_SIZE
-#define MG_IO_SIZE 1460
-#endif
-
-#endif // MG_ARCH == MG_ARCH_RTTHREAD
-
-
-#if MG_ARCH == MG_ARCH_ARMCC || MG_ARCH == MG_ARCH_CMSIS_RTOS1 || \
- MG_ARCH == MG_ARCH_CMSIS_RTOS2
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#if MG_ARCH == MG_ARCH_CMSIS_RTOS1
-#include "cmsis_os.h" // keep this include
-// https://developer.arm.com/documentation/ka003821/latest
-extern uint32_t rt_time_get(void);
-#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
-#include "cmsis_os2.h" // keep this include
-#endif
-
-#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
-
-#if defined(__ARMCC_VERSION)
-#define mode_t size_t
-#define mkdir(a, b) mg_mkdir(a, b)
-static inline int mg_mkdir(const char *path, mode_t mode) {
- (void) path, (void) mode;
- return -1;
-}
-#endif
-
-#if (MG_ARCH == MG_ARCH_CMSIS_RTOS1 || MG_ARCH == MG_ARCH_CMSIS_RTOS2) && \
- !defined MG_ENABLE_RL && (!defined(MG_ENABLE_LWIP) || !MG_ENABLE_LWIP) && \
- (!defined(MG_ENABLE_TCPIP) || !MG_ENABLE_TCPIP)
-#define MG_ENABLE_RL 1
-#ifndef MG_SOCK_LISTEN_BACKLOG_SIZE
-#define MG_SOCK_LISTEN_BACKLOG_SIZE 3
-#endif
-#endif
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_TIRTOS
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_UNIX
-
-#define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors
-
-#if defined(__APPLE__)
-#include
-#endif
-
-#if !defined(MG_ENABLE_EPOLL) && defined(__linux__)
-#define MG_ENABLE_EPOLL 1
-#elif !defined(MG_ENABLE_POLL)
-#define MG_ENABLE_POLL 1
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#if defined(MG_ENABLE_EPOLL) && MG_ENABLE_EPOLL
-#include
-#elif defined(MG_ENABLE_POLL) && MG_ENABLE_POLL
-#include
-#else
-#include
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#ifndef MG_ENABLE_DIRLIST
-#define MG_ENABLE_DIRLIST 1
-#endif
-
-#ifndef MG_PATH_MAX
-#define MG_PATH_MAX FILENAME_MAX
-#endif
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_WIN32
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-
-#ifndef _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_WARNINGS
-#endif
-
-#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
-#define _WINSOCK_DEPRECATED_NO_WARNINGS
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#if defined(_MSC_VER) && _MSC_VER < 1700
-#define __func__ ""
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-typedef unsigned char uint8_t;
-typedef char int8_t;
-typedef unsigned short uint16_t;
-typedef short int16_t;
-typedef unsigned int uint32_t;
-typedef int int32_t;
-typedef enum { false = 0, true = 1 } bool;
-#else
-#include
-#include
-#include
-#endif
-
-#include
-#include
-#include
-
-// Protect from calls like std::snprintf in app code
-// See https://github.com/cesanta/mongoose/issues/1047
-#ifndef __cplusplus
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
-#ifndef strdup // For MSVC with _DEBUG, see #1359
-#define strdup(x) _strdup(x)
-#endif
-#endif
-
-#define MG_INVALID_SOCKET INVALID_SOCKET
-#define MG_SOCKET_TYPE SOCKET
-typedef unsigned long nfds_t;
-#if defined(_MSC_VER)
-#pragma comment(lib, "ws2_32.lib")
-#ifndef alloca
-#define alloca(a) _alloca(a)
-#endif
-#endif
-#define poll(a, b, c) WSAPoll((a), (b), (c))
-#define closesocket(x) closesocket(x)
-
-typedef int socklen_t;
-#define MG_DIRSEP '\\'
-
-#ifndef MG_PATH_MAX
-#define MG_PATH_MAX FILENAME_MAX
-#endif
-
-#ifndef SO_EXCLUSIVEADDRUSE
-#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
-#endif
-
-#define MG_SOCK_ERR(errcode) ((errcode) < 0 ? WSAGetLastError() : 0)
-
-#define MG_SOCK_PENDING(errcode) \
- (((errcode) < 0) && \
- (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS || \
- WSAGetLastError() == WSAEWOULDBLOCK))
-
-#define MG_SOCK_RESET(errcode) \
- (((errcode) < 0) && (WSAGetLastError() == WSAECONNRESET))
-
-#define realpath(a, b) _fullpath((b), (a), MG_PATH_MAX)
-#define sleep(x) Sleep((x) *1000)
-#define mkdir(a, b) _mkdir(a)
-#define timegm(x) _mkgmtime(x)
-
-#ifndef S_ISDIR
-#define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
-#endif
-
-#ifndef MG_ENABLE_DIRLIST
-#define MG_ENABLE_DIRLIST 1
-#endif
-
-#ifndef SIGPIPE
-#define SIGPIPE 0
-#endif
-
-#endif
-
-
-#if MG_ARCH == MG_ARCH_ZEPHYR
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define MG_PUTCHAR(x) printk("%c", x)
-#ifndef strdup
-#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
-#endif
-#define strerror(x) zsock_gai_strerror(x)
-
-#ifndef FD_CLOEXEC
-#define FD_CLOEXEC 0
-#endif
-
-#ifndef F_SETFD
-#define F_SETFD 0
-#endif
-
-#define MG_ENABLE_SSI 0
-
-int rand(void);
-int sscanf(const char *, const char *, ...);
-
-#endif
-
-
-#if defined(MG_ENABLE_FREERTOS_TCP) && MG_ENABLE_FREERTOS_TCP
-
-#include
-#include
-
-#include
-#include
-#include // contents to be moved and file removed, some day
-
-#define MG_SOCKET_TYPE Socket_t
-#define MG_INVALID_SOCKET FREERTOS_INVALID_SOCKET
-
-// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
-// with FreeRTOS_ prefix, is beyond me
-#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
-#define IPPROTO_UDP FREERTOS_IPPROTO_UDP
-#define AF_INET FREERTOS_AF_INET
-#define SOCK_STREAM FREERTOS_SOCK_STREAM
-#define SOCK_DGRAM FREERTOS_SOCK_DGRAM
-#define SO_BROADCAST 0
-#define SO_ERROR 0
-#define SOL_SOCKET 0
-#define SO_REUSEADDR 0
-
-#define MG_SOCK_ERR(errcode) ((errcode) < 0 ? (errcode) : 0)
-
-#define MG_SOCK_PENDING(errcode) \
- ((errcode) == -pdFREERTOS_ERRNO_EWOULDBLOCK || \
- (errcode) == -pdFREERTOS_ERRNO_EISCONN || \
- (errcode) == -pdFREERTOS_ERRNO_EINPROGRESS || \
- (errcode) == -pdFREERTOS_ERRNO_EAGAIN)
-
-#define MG_SOCK_RESET(errcode) ((errcode) == -pdFREERTOS_ERRNO_ENOTCONN)
-
-// actually only if optional timeout is enabled
-#define MG_SOCK_INTR(fd) (fd == NULL)
-
-#define sockaddr_in freertos_sockaddr
-#define sockaddr freertos_sockaddr
-#define accept(a, b, c) FreeRTOS_accept((a), (b), (c))
-#define connect(a, b, c) FreeRTOS_connect((a), (b), (c))
-#define bind(a, b, c) FreeRTOS_bind((a), (b), (c))
-#define listen(a, b) FreeRTOS_listen((a), (b))
-#define socket(a, b, c) FreeRTOS_socket((a), (b), (c))
-#define send(a, b, c, d) FreeRTOS_send((a), (b), (c), (d))
-#define recv(a, b, c, d) FreeRTOS_recv((a), (b), (c), (d))
-#define setsockopt(a, b, c, d, e) FreeRTOS_setsockopt((a), (b), (c), (d), (e))
-#define sendto(a, b, c, d, e, f) FreeRTOS_sendto((a), (b), (c), (d), (e), (f))
-#define recvfrom(a, b, c, d, e, f) \
- FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
-#define closesocket(x) FreeRTOS_closesocket(x)
-#define gethostbyname(x) FreeRTOS_gethostbyname(x)
-#define getsockname(a, b, c) mg_getsockname((a), (b), (c))
-#define getpeername(a, b, c) mg_getpeername((a), (b), (c))
-
-static inline int mg_getsockname(MG_SOCKET_TYPE fd, void *buf, socklen_t *len) {
- (void) fd, (void) buf, (void) len;
- return -1;
-}
-
-static inline int mg_getpeername(MG_SOCKET_TYPE fd, void *buf, socklen_t *len) {
- (void) fd, (void) buf, (void) len;
- return 0;
-}
-#endif
-
-
-#if defined(MG_ENABLE_LWIP) && MG_ENABLE_LWIP
-
-#if defined(__GNUC__) && !defined(__ARMCC_VERSION)
-#include
-#endif
-
-struct timeval;
-
-#include
-
-#if !LWIP_TIMEVAL_PRIVATE
-#if defined(__GNUC__) && !defined(__ARMCC_VERSION) // armclang sets both
-#include
-#else
-struct timeval {
- time_t tv_sec;
- long tv_usec;
-};
-#endif
-#endif
-
-#if LWIP_SOCKET != 1
-// Sockets support disabled in LWIP by default
-#error Set LWIP_SOCKET variable to 1 (in lwipopts.h)
-#endif
-#endif
-
-
-#if defined(MG_ENABLE_RL) && MG_ENABLE_RL
-#include
-
-#define closesocket(x) closesocket(x)
-
-#define TCP_NODELAY SO_KEEPALIVE
-
-#define MG_SOCK_ERR(errcode) ((errcode) < 0 ? (errcode) : 0)
-
-#define MG_SOCK_PENDING(errcode) \
- ((errcode) == BSD_EWOULDBLOCK || (errcode) == BSD_EALREADY || \
- (errcode) == BSD_EINPROGRESS)
-
-#define MG_SOCK_RESET(errcode) \
- ((errcode) == BSD_ECONNABORTED || (errcode) == BSD_ECONNRESET)
-
-// In blocking mode, which is enabled by default, accept() waits for a
-// connection request. In non blocking mode, you must call accept()
-// again if the error code BSD_EWOULDBLOCK is returned.
-#define MG_SOCK_INTR(fd) (fd == BSD_EWOULDBLOCK)
-
-#define socklen_t int
-#endif
-
-
-#ifndef MG_ENABLE_LOG
-#define MG_ENABLE_LOG 1
-#endif
-
-#ifndef MG_ENABLE_CUSTOM_LOG
-#define MG_ENABLE_CUSTOM_LOG 0 // Let user define their own MG_LOG
-#endif
-
-#ifndef MG_ENABLE_TCPIP
-#define MG_ENABLE_TCPIP 0 // Mongoose built-in network stack
-#endif
-
-#ifndef MG_ENABLE_LWIP
-#define MG_ENABLE_LWIP 0 // lWIP network stack
-#endif
-
-#ifndef MG_ENABLE_FREERTOS_TCP
-#define MG_ENABLE_FREERTOS_TCP 0 // Amazon FreeRTOS-TCP network stack
-#endif
-
-#ifndef MG_ENABLE_RL
-#define MG_ENABLE_RL 0 // ARM MDK network stack
-#endif
-
-#ifndef MG_ENABLE_SOCKET
-#define MG_ENABLE_SOCKET !MG_ENABLE_TCPIP
-#endif
-
-#ifndef MG_ENABLE_POLL
-#define MG_ENABLE_POLL 0
-#endif
-
-#ifndef MG_ENABLE_EPOLL
-#define MG_ENABLE_EPOLL 0
-#endif
-
-#ifndef MG_ENABLE_FATFS
-#define MG_ENABLE_FATFS 0
-#endif
-
-#ifndef MG_ENABLE_SSI
-#define MG_ENABLE_SSI 0
-#endif
-
-#ifndef MG_ENABLE_IPV6
-#define MG_ENABLE_IPV6 0
-#endif
-
-#ifndef MG_IPV6_V6ONLY
-#define MG_IPV6_V6ONLY 0 // IPv6 socket binds only to V6, not V4 address
-#endif
-
-#ifndef MG_ENABLE_MD5
-#define MG_ENABLE_MD5 1
-#endif
-
-// Set MG_ENABLE_WINSOCK=0 for Win32 builds with external IP stack (like LWIP)
-#ifndef MG_ENABLE_WINSOCK
-#define MG_ENABLE_WINSOCK 1
-#endif
-
-#ifndef MG_ENABLE_DIRLIST
-#define MG_ENABLE_DIRLIST 0
-#endif
-
-#ifndef MG_ENABLE_CUSTOM_RANDOM
-#define MG_ENABLE_CUSTOM_RANDOM 0
-#endif
-
-#ifndef MG_ENABLE_CUSTOM_MILLIS
-#define MG_ENABLE_CUSTOM_MILLIS 0
-#endif
-
-#ifndef MG_ENABLE_PACKED_FS
-#define MG_ENABLE_PACKED_FS 0
-#endif
-
-#ifndef MG_ENABLE_ASSERT
-#define MG_ENABLE_ASSERT 0
-#endif
-
-#ifndef MG_IO_SIZE
-#define MG_IO_SIZE 2048 // Granularity of the send/recv IO buffer growth
-#endif
-
-#ifndef MG_MAX_RECV_SIZE
-#define MG_MAX_RECV_SIZE (3UL * 1024UL * 1024UL) // Maximum recv IO buffer size
-#endif
-
-#ifndef MG_DATA_SIZE
-#define MG_DATA_SIZE 32 // struct mg_connection :: data size
-#endif
-
-#ifndef MG_MAX_HTTP_HEADERS
-#define MG_MAX_HTTP_HEADERS 30
-#endif
-
-#ifndef MG_HTTP_INDEX
-#define MG_HTTP_INDEX "index.html"
-#endif
-
-#ifndef MG_PATH_MAX
-#ifdef PATH_MAX
-#define MG_PATH_MAX PATH_MAX
-#else
-#define MG_PATH_MAX 128
-#endif
-#endif
-
-#ifndef MG_SOCK_LISTEN_BACKLOG_SIZE
-#define MG_SOCK_LISTEN_BACKLOG_SIZE 128
-#endif
-
-#ifndef MG_DIRSEP
-#define MG_DIRSEP '/'
-#endif
-
-#ifndef MG_ENABLE_POSIX_FS
-#if defined(FOPEN_MAX)
-#define MG_ENABLE_POSIX_FS 1
-#else
-#define MG_ENABLE_POSIX_FS 0
-#endif
-#endif
-
-#ifndef MG_INVALID_SOCKET
-#define MG_INVALID_SOCKET (-1)
-#endif
-
-#ifndef MG_SOCKET_TYPE
-#define MG_SOCKET_TYPE int
-#endif
-
-#ifndef MG_SOCKET_ERRNO
-#define MG_SOCKET_ERRNO errno
-#endif
-
-#if MG_ENABLE_EPOLL
-#define MG_EPOLL_ADD(c) \
- do { \
- struct epoll_event ev = {EPOLLIN | EPOLLERR | EPOLLHUP, {c}}; \
- epoll_ctl(c->mgr->epoll_fd, EPOLL_CTL_ADD, (int) (size_t) c->fd, &ev); \
- } while (0)
-#define MG_EPOLL_MOD(c, wr) \
- do { \
- struct epoll_event ev = {EPOLLIN | EPOLLERR | EPOLLHUP, {c}}; \
- if (wr) ev.events |= EPOLLOUT; \
- epoll_ctl(c->mgr->epoll_fd, EPOLL_CTL_MOD, (int) (size_t) c->fd, &ev); \
- } while (0)
-#else
-#define MG_EPOLL_ADD(c)
-#define MG_EPOLL_MOD(c, wr)
-#endif
-
-#ifndef MG_ENABLE_PROFILE
-#define MG_ENABLE_PROFILE 0
-#endif
-
-
-
-
-struct mg_str {
- const char *ptr; // Pointer to string data
- size_t len; // String len
-};
-
-#define MG_C_STR(a) \
- { (a), sizeof(a) - 1 }
-
-// Using macro to avoid shadowing C++ struct constructor, see #1298
-#define mg_str(s) mg_str_s(s)
-
-struct mg_str mg_str(const char *s);
-struct mg_str mg_str_n(const char *s, size_t n);
-int mg_lower(const char *s);
-int mg_ncasecmp(const char *s1, const char *s2, size_t len);
-int mg_casecmp(const char *s1, const char *s2);
-int mg_vcmp(const struct mg_str *s1, const char *s2);
-int mg_vcasecmp(const struct mg_str *str1, const char *str2);
-int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
-struct mg_str mg_strstrip(struct mg_str s);
-struct mg_str mg_strdup(const struct mg_str s);
-const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
-bool mg_match(struct mg_str str, struct mg_str pattern, struct mg_str *caps);
-bool mg_globmatch(const char *pattern, size_t plen, const char *s, size_t n);
-bool mg_span(struct mg_str s, struct mg_str *a, struct mg_str *b, char delim);
-char *mg_hex(const void *buf, size_t len, char *dst);
-void mg_unhex(const char *buf, size_t len, unsigned char *to);
-unsigned long mg_unhexn(const char *s, size_t len);
-bool mg_path_is_sane(const char *path);
-
-
-
-
-// Single producer, single consumer non-blocking queue
-
-struct mg_queue {
- char *buf;
- size_t size;
- volatile size_t tail;
- volatile size_t head;
-};
-
-void mg_queue_init(struct mg_queue *, char *, size_t); // Init queue
-size_t mg_queue_book(struct mg_queue *, char **buf, size_t); // Reserve space
-void mg_queue_add(struct mg_queue *, size_t); // Add new message
-size_t mg_queue_next(struct mg_queue *, char **); // Get oldest message
-void mg_queue_del(struct mg_queue *, size_t); // Delete oldest message
-
-
-
-
-typedef void (*mg_pfn_t)(char, void *); // Output function
-typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer
-
-size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *);
-size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...);
-
-
-
-
-
-
-// Convenience wrappers around mg_xprintf
-size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap);
-size_t mg_snprintf(char *, size_t, const char *fmt, ...);
-char *mg_vmprintf(const char *fmt, va_list *ap);
-char *mg_mprintf(const char *fmt, ...);
-size_t mg_queue_vprintf(struct mg_queue *, const char *fmt, va_list *);
-size_t mg_queue_printf(struct mg_queue *, const char *fmt, ...);
-
-// %M print helper functions
-size_t mg_print_base64(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_esc(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_hex(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_ip4(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_ip6(void (*out)(char, void *), void *arg, va_list *ap);
-size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap);
-
-// Various output functions
-void mg_pfn_iobuf(char ch, void *param); // param: struct mg_iobuf *
-void mg_pfn_stdout(char c, void *param); // param: ignored
-
-// A helper macro for printing JSON: mg_snprintf(buf, len, "%m", MG_ESC("hi"))
-#define MG_ESC(str) mg_print_esc, 0, (str)
-
-
-
-
-
-
-enum { MG_LL_NONE, MG_LL_ERROR, MG_LL_INFO, MG_LL_DEBUG, MG_LL_VERBOSE };
-extern int mg_log_level; // Current log level, one of MG_LL_*
-
-void mg_log(const char *fmt, ...);
-void mg_log_prefix(int ll, const char *file, int line, const char *fname);
-// bool mg_log2(int ll, const char *file, int line, const char *fmt, ...);
-void mg_hexdump(const void *buf, size_t len);
-void mg_log_set_fn(mg_pfn_t fn, void *param);
-
-#define mg_log_set(level_) mg_log_level = (level_)
-
-#if MG_ENABLE_LOG
-#define MG_LOG(level, args) \
- do { \
- if ((level) <= mg_log_level) { \
- mg_log_prefix((level), __FILE__, __LINE__, __func__); \
- mg_log args; \
- } \
- } while (0)
-#else
-#define MG_LOG(level, args) \
- do { \
- if (0) mg_log args; \
- } while (0)
-#endif
-
-#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
-#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
-#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
-#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
-
-
-
-
-struct mg_timer {
- unsigned long id; // Timer ID
- uint64_t period_ms; // Timer period in milliseconds
- uint64_t expire; // Expiration timestamp in milliseconds
- unsigned flags; // Possible flags values below
-#define MG_TIMER_ONCE 0 // Call function once
-#define MG_TIMER_REPEAT 1 // Call function periodically
-#define MG_TIMER_RUN_NOW 2 // Call immediately when timer is set
- void (*fn)(void *); // Function to call
- void *arg; // Function argument
- struct mg_timer *next; // Linkage
-};
-
-void mg_timer_init(struct mg_timer **head, struct mg_timer *timer,
- uint64_t milliseconds, unsigned flags, void (*fn)(void *),
- void *arg);
-void mg_timer_free(struct mg_timer **head, struct mg_timer *);
-void mg_timer_poll(struct mg_timer **head, uint64_t new_ms);
-bool mg_timer_expired(uint64_t *expiration, uint64_t period, uint64_t now);
-
-
-
-
-
-enum { MG_FS_READ = 1, MG_FS_WRITE = 2, MG_FS_DIR = 4 };
-
-// Filesystem API functions
-// st() returns MG_FS_* flags and populates file size and modification time
-// ls() calls fn() for every directory entry, allowing to list a directory
-//
-// NOTE: UNIX-style shorthand names for the API functions are deliberately
-// chosen to avoid conflicts with some libraries that make macros for e.g.
-// stat(), write(), read() calls.
-struct mg_fs {
- int (*st)(const char *path, size_t *size, time_t *mtime); // stat file
- void (*ls)(const char *path, void (*fn)(const char *, void *),
- void *); // List directory entries: call fn(file_name, fn_data)
- // for each directory entry
- void *(*op)(const char *path, int flags); // Open file
- void (*cl)(void *fd); // Close file
- size_t (*rd)(void *fd, void *buf, size_t len); // Read file
- size_t (*wr)(void *fd, const void *buf, size_t len); // Write file
- size_t (*sk)(void *fd, size_t offset); // Set file position
- bool (*mv)(const char *from, const char *to); // Rename file
- bool (*rm)(const char *path); // Delete file
- bool (*mkd)(const char *path); // Create directory
-};
-
-extern struct mg_fs mg_fs_posix; // POSIX open/close/read/write/seek
-extern struct mg_fs mg_fs_packed; // Packed FS, see examples/device-dashboard
-extern struct mg_fs mg_fs_fat; // FAT FS
-
-// File descriptor
-struct mg_fd {
- void *fd;
- struct mg_fs *fs;
-};
-
-struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags);
-void mg_fs_close(struct mg_fd *fd);
-bool mg_fs_ls(struct mg_fs *fs, const char *path, char *buf, size_t len);
-struct mg_str mg_file_read(struct mg_fs *fs, const char *path);
-bool mg_file_write(struct mg_fs *fs, const char *path, const void *, size_t);
-bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...);
-
-// Packed API
-const char *mg_unpack(const char *path, size_t *size, time_t *mtime);
-const char *mg_unlist(size_t no); // Get no'th packed filename
-struct mg_str mg_unpacked(const char *path); // Packed file as mg_str
-
-
-
-
-
-
-
-#if MG_ENABLE_ASSERT
-#include
-#elif !defined(assert)
-#define assert(x)
-#endif
-
-void mg_bzero(volatile unsigned char *buf, size_t len);
-void mg_random(void *buf, size_t len);
-char *mg_random_str(char *buf, size_t len);
-uint16_t mg_ntohs(uint16_t net);
-uint32_t mg_ntohl(uint32_t net);
-uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
-uint64_t mg_millis(void); // Return milliseconds since boot
-uint64_t mg_now(void); // Return milliseconds since Epoch
-
-#define mg_htons(x) mg_ntohs(x)
-#define mg_htonl(x) mg_ntohl(x)
-
-#define MG_U32(a, b, c, d) \
- (((uint32_t) ((a) &255) << 24) | ((uint32_t) ((b) &255) << 16) | \
- ((uint32_t) ((c) &255) << 8) | (uint32_t) ((d) &255))
-
-// For printing IPv4 addresses: printf("%d.%d.%d.%d\n", MG_IPADDR_PARTS(&ip))
-#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
-#define MG_IPADDR_PARTS(ADDR) \
- MG_U8P(ADDR)[0], MG_U8P(ADDR)[1], MG_U8P(ADDR)[2], MG_U8P(ADDR)[3]
-
-#define MG_REG(x) ((volatile uint32_t *) (x))[0]
-#define MG_BIT(x) (((uint32_t) 1U) << (x))
-#define MG_SET_BITS(R, CLRMASK, SETMASK) (R) = ((R) & ~(CLRMASK)) | (SETMASK)
-
-#define MG_ROUND_UP(x, a) ((a) == 0 ? (x) : ((((x) + (a) -1) / (a)) * (a)))
-#define MG_ROUND_DOWN(x, a) ((a) == 0 ? (x) : (((x) / (a)) * (a)))
-
-#ifdef __GNUC__
-#define MG_ARM_DISABLE_IRQ() asm volatile("cpsid i" : : : "memory")
-#define MG_ARM_ENABLE_IRQ() asm volatile("cpsie i" : : : "memory")
-#else
-#define MG_ARM_DISABLE_IRQ()
-#define MG_ARM_ENABLE_IRQ()
-#endif
-
-#if defined(__CC_ARM)
-#define MG_DSB() __dsb(0xf)
-#elif defined(__ARMCC_VERSION)
-#define MG_DSB() __builtin_arm_dsb(0xf)
-#elif defined(__GNUC__) && defined(__arm__) && defined(__thumb__)
-#define MG_DSB() asm("DSB 0xf")
-#elif defined(__ICCARM__)
-#define MG_DSB() __iar_builtin_DSB()
-#else
-#define MG_DSB()
-#endif
-
-struct mg_addr;
-int mg_check_ip_acl(struct mg_str acl, struct mg_addr *remote_ip);
-
-// Linked list management macros
-#define LIST_ADD_HEAD(type_, head_, elem_) \
- do { \
- (elem_)->next = (*head_); \
- *(head_) = (elem_); \
- } while (0)
-
-#define LIST_ADD_TAIL(type_, head_, elem_) \
- do { \
- type_ **h = head_; \
- while (*h != NULL) h = &(*h)->next; \
- *h = (elem_); \
- } while (0)
-
-#define LIST_DELETE(type_, head_, elem_) \
- do { \
- type_ **h = head_; \
- while (*h != (elem_)) h = &(*h)->next; \
- *h = (elem_)->next; \
- } while (0)
-
-
-
-unsigned short mg_url_port(const char *url);
-int mg_url_is_ssl(const char *url);
-struct mg_str mg_url_host(const char *url);
-struct mg_str mg_url_user(const char *url);
-struct mg_str mg_url_pass(const char *url);
-const char *mg_url_uri(const char *url);
-
-
-
-
-struct mg_iobuf {
- unsigned char *buf; // Pointer to stored data
- size_t size; // Total size available
- size_t len; // Current number of bytes
- size_t align; // Alignment during allocation
-};
-
-int mg_iobuf_init(struct mg_iobuf *, size_t, size_t);
-int mg_iobuf_resize(struct mg_iobuf *, size_t);
-void mg_iobuf_free(struct mg_iobuf *);
-size_t mg_iobuf_add(struct mg_iobuf *, size_t, const void *, size_t);
-size_t mg_iobuf_del(struct mg_iobuf *, size_t ofs, size_t len);
-
-
-size_t mg_base64_update(unsigned char input_byte, char *buf, size_t len);
-size_t mg_base64_final(char *buf, size_t len);
-size_t mg_base64_encode(const unsigned char *p, size_t n, char *buf, size_t);
-size_t mg_base64_decode(const char *src, size_t n, char *dst, size_t);
-
-
-
-
-typedef struct {
- uint32_t buf[4];
- uint32_t bits[2];
- unsigned char in[64];
-} mg_md5_ctx;
-
-void mg_md5_init(mg_md5_ctx *c);
-void mg_md5_update(mg_md5_ctx *c, const unsigned char *data, size_t len);
-void mg_md5_final(mg_md5_ctx *c, unsigned char[16]);
-
-
-
-
-typedef struct {
- uint32_t state[5];
- uint32_t count[2];
- unsigned char buffer[64];
-} mg_sha1_ctx;
-
-void mg_sha1_init(mg_sha1_ctx *);
-void mg_sha1_update(mg_sha1_ctx *, const unsigned char *data, size_t len);
-void mg_sha1_final(unsigned char digest[20], mg_sha1_ctx *);
-
-
-
-
-typedef struct {
- uint32_t state[8];
- uint64_t bits;
- uint32_t len;
- unsigned char buffer[64];
-} mg_sha256_ctx;
-
-void mg_sha256_init(mg_sha256_ctx *);
-void mg_sha256_update(mg_sha256_ctx *, const unsigned char *data, size_t len);
-void mg_sha256_final(unsigned char digest[32], mg_sha256_ctx *);
-void mg_hmac_sha256(uint8_t dst[32], uint8_t *key, size_t keysz, uint8_t *data,
- size_t datasz);
-/******************************************************************************
- *
- * THIS SOURCE CODE IS HEREBY PLACED INTO THE PUBLIC DOMAIN FOR THE GOOD OF ALL
- *
- * This is a simple and straightforward implementation of the AES Rijndael
- * 128-bit block cipher designed by Vincent Rijmen and Joan Daemen. The focus
- * of this work was correctness & accuracy. It is written in 'C' without any
- * particular focus upon optimization or speed. It should be endian (memory
- * byte order) neutral since the few places that care are handled explicitly.
- *
- * This implementation of Rijndael was created by Steven M. Gibson of GRC.com.
- *
- * It is intended for general purpose use, but was written in support of GRC's
- * reference implementation of the SQRL (Secure Quick Reliable Login) client.
- *
- * See: http://csrc.nist.gov/archive/aes/rijndael/wsdindex.html
- *
- * NO COPYRIGHT IS CLAIMED IN THIS WORK, HOWEVER, NEITHER IS ANY WARRANTY MADE
- * REGARDING ITS FITNESS FOR ANY PARTICULAR PURPOSE. USE IT AT YOUR OWN RISK.
- *
- *******************************************************************************/
-
-#ifndef AES_HEADER
-#define AES_HEADER
-
-/******************************************************************************/
-#define AES_DECRYPTION 1 // whether AES decryption is supported
-/******************************************************************************/
-
-#define ENCRYPT 1 // specify whether we're encrypting
-#define DECRYPT 0 // or decrypting
-
-
-
-typedef unsigned char uchar; // add some convienent shorter types
-typedef unsigned int uint;
-
-/******************************************************************************
- * AES_INIT_KEYGEN_TABLES : MUST be called once before any AES use
- ******************************************************************************/
-void aes_init_keygen_tables(void);
-
-/******************************************************************************
- * AES_CONTEXT : cipher context / holds inter-call data
- ******************************************************************************/
-typedef struct {
- int mode; // 1 for Encryption, 0 for Decryption
- int rounds; // keysize-based rounds count
- uint32_t *rk; // pointer to current round key
- uint32_t buf[68]; // key expansion buffer
-} aes_context;
-
-/******************************************************************************
- * AES_SETKEY : called to expand the key for encryption or decryption
- ******************************************************************************/
-int aes_setkey(aes_context *ctx, // pointer to context
- int mode, // 1 or 0 for Encrypt/Decrypt
- const uchar *key, // AES input key
- uint keysize); // size in bytes (must be 16, 24, 32 for
- // 128, 192 or 256-bit keys respectively)
- // returns 0 for success
-
-/******************************************************************************
- * AES_CIPHER : called to encrypt or decrypt ONE 128-bit block of data
- ******************************************************************************/
-int aes_cipher(aes_context *ctx, // pointer to context
- const uchar input[16], // 128-bit block to en/decipher
- uchar output[16]); // 128-bit output result block
- // returns 0 for success
-
-#endif /* AES_HEADER */
-/******************************************************************************
- *
- * THIS SOURCE CODE IS HEREBY PLACED INTO THE PUBLIC DOMAIN FOR THE GOOD OF ALL
- *
- * This is a simple and straightforward implementation of AES-GCM authenticated
- * encryption. The focus of this work was correctness & accuracy. It is written
- * in straight 'C' without any particular focus upon optimization or speed. It
- * should be endian (memory byte order) neutral since the few places that care
- * are handled explicitly.
- *
- * This implementation of AES-GCM was created by Steven M. Gibson of GRC.com.
- *
- * It is intended for general purpose use, but was written in support of GRC's
- * reference implementation of the SQRL (Secure Quick Reliable Login) client.
- *
- * See: http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
- * http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ \
- * gcm/gcm-revised-spec.pdf
- *
- * NO COPYRIGHT IS CLAIMED IN THIS WORK, HOWEVER, NEITHER IS ANY WARRANTY MADE
- * REGARDING ITS FITNESS FOR ANY PARTICULAR PURPOSE. USE IT AT YOUR OWN RISK.
- *
- *******************************************************************************/
-#ifndef GCM_HEADER
-#define GCM_HEADER
-
-
-#define GCM_AUTH_FAILURE 0x55555555 // authentication failure
-
-/******************************************************************************
- * GCM_CONTEXT : GCM context / holds keytables, instance data, and AES ctx
- ******************************************************************************/
-typedef struct {
- int mode; // cipher direction: encrypt/decrypt
- uint64_t len; // cipher data length processed so far
- uint64_t add_len; // total add data length
- uint64_t HL[16]; // precalculated lo-half HTable
- uint64_t HH[16]; // precalculated hi-half HTable
- uchar base_ectr[16]; // first counter-mode cipher output for tag
- uchar y[16]; // the current cipher-input IV|Counter value
- uchar buf[16]; // buf working value
- aes_context aes_ctx; // cipher context used
-} gcm_context;
-
-/******************************************************************************
- * GCM_CONTEXT : MUST be called once before ANY use of this library
- ******************************************************************************/
-int gcm_initialize(void);
-
-/******************************************************************************
- * GCM_SETKEY : sets the GCM (and AES) keying material for use
- ******************************************************************************/
-int gcm_setkey(gcm_context *ctx, // caller-provided context ptr
- const uchar *key, // pointer to cipher key
- const uint keysize // size in bytes (must be 16, 24, 32 for
- // 128, 192 or 256-bit keys respectively)
-); // returns 0 for success
-
-/******************************************************************************
- *
- * GCM_CRYPT_AND_TAG
- *
- * This either encrypts or decrypts the user-provided data and, either
- * way, generates an authentication tag of the requested length. It must be
- * called with a GCM context whose key has already been set with GCM_SETKEY.
- *
- * The user would typically call this explicitly to ENCRYPT a buffer of data
- * and optional associated data, and produce its an authentication tag.
- *
- * To reverse the process the user would typically call the companion
- * GCM_AUTH_DECRYPT function to decrypt data and verify a user-provided
- * authentication tag. The GCM_AUTH_DECRYPT function calls this function
- * to perform its decryption and tag generation, which it then compares.
- *
- ******************************************************************************/
-int gcm_crypt_and_tag(
- gcm_context *ctx, // gcm context with key already setup
- int mode, // cipher direction: ENCRYPT (1) or DECRYPT (0)
- const uchar *iv, // pointer to the 12-byte initialization vector
- size_t iv_len, // byte length if the IV. should always be 12
- const uchar *add, // pointer to the non-ciphered additional data
- size_t add_len, // byte length of the additional AEAD data
- const uchar *input, // pointer to the cipher data source
- uchar *output, // pointer to the cipher data destination
- size_t length, // byte length of the cipher data
- uchar *tag, // pointer to the tag to be generated
- size_t tag_len); // byte length of the tag to be generated
-
-/******************************************************************************
- *
- * GCM_AUTH_DECRYPT
- *
- * This DECRYPTS a user-provided data buffer with optional associated data.
- * It then verifies a user-supplied authentication tag against the tag just
- * re-created during decryption to verify that the data has not been altered.
- *
- * This function calls GCM_CRYPT_AND_TAG (above) to perform the decryption
- * and authentication tag generation.
- *
- ******************************************************************************/
-int gcm_auth_decrypt(
- gcm_context *ctx, // gcm context with key already setup
- const uchar *iv, // pointer to the 12-byte initialization vector
- size_t iv_len, // byte length if the IV. should always be 12
- const uchar *add, // pointer to the non-ciphered additional data
- size_t add_len, // byte length of the additional AEAD data
- const uchar *input, // pointer to the cipher data source
- uchar *output, // pointer to the cipher data destination
- size_t length, // byte length of the cipher data
- const uchar *tag, // pointer to the tag to be authenticated
- size_t tag_len); // byte length of the tag <= 16
-
-/******************************************************************************
- *
- * GCM_START
- *
- * Given a user-provided GCM context, this initializes it, sets the encryption
- * mode, and preprocesses the initialization vector and additional AEAD data.
- *
- ******************************************************************************/
-int gcm_start(
- gcm_context *ctx, // pointer to user-provided GCM context
- int mode, // ENCRYPT (1) or DECRYPT (0)
- const uchar *iv, // pointer to initialization vector
- size_t iv_len, // IV length in bytes (should == 12)
- const uchar *add, // pointer to additional AEAD data (NULL if none)
- size_t add_len); // length of additional AEAD data (bytes)
-
-/******************************************************************************
- *
- * GCM_UPDATE
- *
- * This is called once or more to process bulk plaintext or ciphertext data.
- * We give this some number of bytes of input and it returns the same number
- * of output bytes. If called multiple times (which is fine) all but the final
- * invocation MUST be called with length mod 16 == 0. (Only the final call can
- * have a partial block length of < 128 bits.)
- *
- ******************************************************************************/
-int gcm_update(gcm_context *ctx, // pointer to user-provided GCM context
- size_t length, // length, in bytes, of data to process
- const uchar *input, // pointer to source data
- uchar *output); // pointer to destination data
-
-/******************************************************************************
- *
- * GCM_FINISH
- *
- * This is called once after all calls to GCM_UPDATE to finalize the GCM.
- * It performs the final GHASH to produce the resulting authentication TAG.
- *
- ******************************************************************************/
-int gcm_finish(gcm_context *ctx, // pointer to user-provided GCM context
- uchar *tag, // ptr to tag buffer - NULL if tag_len = 0
- size_t tag_len); // length, in bytes, of the tag-receiving buf
-
-/******************************************************************************
- *
- * GCM_ZERO_CTX
- *
- * The GCM context contains both the GCM context and the AES context.
- * This includes keying and key-related material which is security-
- * sensitive, so it MUST be zeroed after use. This function does that.
- *
- ******************************************************************************/
-void gcm_zero_ctx(gcm_context *ctx);
-
-#endif /* GCM_HEADER */
-//
-// aes-gcm.h
-// MKo
-//
-// Created by Markus Kosmal on 20/11/14.
-//
-//
-
-#ifndef mko_aes_gcm_h
-#define mko_aes_gcm_h
-
-int aes_gcm_encrypt(unsigned char *output, const unsigned char *input,
- size_t input_length, const unsigned char *key,
- const size_t key_len, const unsigned char *iv,
- const size_t iv_len, unsigned char *aead, size_t aead_len,
- unsigned char *tag, const size_t tag_len);
-
-int aes_gcm_decrypt(unsigned char *output, const unsigned char *input,
- size_t input_length, const unsigned char *key,
- const size_t key_len, const unsigned char *iv,
- const size_t iv_len);
-
-#endif
-
-// End of aes128 PD
-
-
-
-#define uECC_SUPPORTS_secp256r1 1
-/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
-
-#ifndef _UECC_H_
-#define _UECC_H_
-
-/* Platform selection options.
-If uECC_PLATFORM is not defined, the code will try to guess it based on compiler
-macros. Possible values for uECC_PLATFORM are defined below: */
-#define uECC_arch_other 0
-#define uECC_x86 1
-#define uECC_x86_64 2
-#define uECC_arm 3
-#define uECC_arm_thumb 4
-#define uECC_arm_thumb2 5
-#define uECC_arm64 6
-#define uECC_avr 7
-
-/* If desired, you can define uECC_WORD_SIZE as appropriate for your platform
-(1, 4, or 8 bytes). If uECC_WORD_SIZE is not explicitly defined then it will be
-automatically set based on your platform. */
-
-/* Optimization level; trade speed for code size.
- Larger values produce code that is faster but larger.
- Currently supported values are 0 - 4; 0 is unusably slow for most
- applications. Optimization level 4 currently only has an effect ARM platforms
- where more than one curve is enabled. */
-#ifndef uECC_OPTIMIZATION_LEVEL
-#define uECC_OPTIMIZATION_LEVEL 2
-#endif
-
-/* uECC_SQUARE_FUNC - If enabled (defined as nonzero), this will cause a
-specific function to be used for (scalar) squaring instead of the generic
-multiplication function. This can make things faster somewhat faster, but
-increases the code size. */
-#ifndef uECC_SQUARE_FUNC
-#define uECC_SQUARE_FUNC 0
-#endif
-
-/* uECC_VLI_NATIVE_LITTLE_ENDIAN - If enabled (defined as nonzero), this will
-switch to native little-endian format for *all* arrays passed in and out of the
-public API. This includes public and private keys, shared secrets, signatures
-and message hashes. Using this switch reduces the amount of call stack memory
-used by uECC, since less intermediate translations are required. Note that this
-will *only* work on native little-endian processors and it will treat the
-uint8_t arrays passed into the public API as word arrays, therefore requiring
-the provided byte arrays to be word aligned on architectures that do not support
-unaligned accesses. IMPORTANT: Keys and signatures generated with
-uECC_VLI_NATIVE_LITTLE_ENDIAN=1 are incompatible with keys and signatures
-generated with uECC_VLI_NATIVE_LITTLE_ENDIAN=0; all parties must use the same
-endianness. */
-#ifndef uECC_VLI_NATIVE_LITTLE_ENDIAN
-#define uECC_VLI_NATIVE_LITTLE_ENDIAN 0
-#endif
-
-/* Curve support selection. Set to 0 to remove that curve. */
-#ifndef uECC_SUPPORTS_secp160r1
-#define uECC_SUPPORTS_secp160r1 0
-#endif
-#ifndef uECC_SUPPORTS_secp192r1
-#define uECC_SUPPORTS_secp192r1 0
-#endif
-#ifndef uECC_SUPPORTS_secp224r1
-#define uECC_SUPPORTS_secp224r1 0
-#endif
-#ifndef uECC_SUPPORTS_secp256r1
-#define uECC_SUPPORTS_secp256r1 1
-#endif
-#ifndef uECC_SUPPORTS_secp256k1
-#define uECC_SUPPORTS_secp256k1 0
-#endif
-
-/* Specifies whether compressed point format is supported.
- Set to 0 to disable point compression/decompression functions. */
-#ifndef uECC_SUPPORT_COMPRESSED_POINT
-#define uECC_SUPPORT_COMPRESSED_POINT 1
-#endif
-
-struct uECC_Curve_t;
-typedef const struct uECC_Curve_t *uECC_Curve;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if uECC_SUPPORTS_secp160r1
-uECC_Curve uECC_secp160r1(void);
-#endif
-#if uECC_SUPPORTS_secp192r1
-uECC_Curve uECC_secp192r1(void);
-#endif
-#if uECC_SUPPORTS_secp224r1
-uECC_Curve uECC_secp224r1(void);
-#endif
-#if uECC_SUPPORTS_secp256r1
-uECC_Curve uECC_secp256r1(void);
-#endif
-#if uECC_SUPPORTS_secp256k1
-uECC_Curve uECC_secp256k1(void);
-#endif
-
-/* uECC_RNG_Function type
-The RNG function should fill 'size' random bytes into 'dest'. It should return 1
-if 'dest' was filled with random data, or 0 if the random data could not be
-generated. The filled-in values should be either truly random, or from a
-cryptographically-secure PRNG.
-
-A correctly functioning RNG function must be set (using uECC_set_rng()) before
-calling uECC_make_key() or uECC_sign().
-
-Setting a correctly functioning RNG function improves the resistance to
-side-channel attacks for uECC_shared_secret() and uECC_sign_deterministic().
-
-A correct RNG function is set by default when building for Windows, Linux, or OS
-X. If you are building on another POSIX-compliant system that supports
-/dev/random or /dev/urandom, you can define uECC_POSIX to use the predefined
-RNG. For embedded platforms there is no predefined RNG function; you must
-provide your own.
-*/
-typedef int (*uECC_RNG_Function)(uint8_t *dest, unsigned size);
-
-/* uECC_set_rng() function.
-Set the function that will be used to generate random bytes. The RNG function
-should return 1 if the random data was generated, or 0 if the random data could
-not be generated.
-
-On platforms where there is no predefined RNG function (eg embedded platforms),
-this must be called before uECC_make_key() or uECC_sign() are used.
-
-Inputs:
- rng_function - The function that will be used to generate random bytes.
-*/
-void uECC_set_rng(uECC_RNG_Function rng_function);
-
-/* uECC_get_rng() function.
-
-Returns the function that will be used to generate random bytes.
-*/
-uECC_RNG_Function uECC_get_rng(void);
-
-/* uECC_curve_private_key_size() function.
-
-Returns the size of a private key for the curve in bytes.
-*/
-int uECC_curve_private_key_size(uECC_Curve curve);
-
-/* uECC_curve_public_key_size() function.
-
-Returns the size of a public key for the curve in bytes.
-*/
-int uECC_curve_public_key_size(uECC_Curve curve);
-
-/* uECC_make_key() function.
-Create a public/private key pair.
-
-Outputs:
- public_key - Will be filled in with the public key. Must be at least 2 *
-the curve size (in bytes) long. For example, if the curve is secp256r1,
-public_key must be 64 bytes long. private_key - Will be filled in with the
-private key. Must be as long as the curve order; this is typically the same as
-the curve size, except for secp160r1. For example, if the curve is secp256r1,
-private_key must be 32 bytes long.
-
- For secp160r1, private_key must be 21 bytes long! Note that
-the first byte will almost always be 0 (there is about a 1 in 2^80 chance of it
-being non-zero).
-
-Returns 1 if the key pair was generated successfully, 0 if an error occurred.
-*/
-int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve);
-
-/* uECC_shared_secret() function.
-Compute a shared secret given your secret key and someone else's public key. If
-the public key is not from a trusted source and has not been previously
-verified, you should verify it first using uECC_valid_public_key(). Note: It is
-recommended that you hash the result of uECC_shared_secret() before using it for
-symmetric encryption or HMAC.
-
-Inputs:
- public_key - The public key of the remote party.
- private_key - Your private key.
-
-Outputs:
- secret - Will be filled in with the shared secret value. Must be the same
-size as the curve size; for example, if the curve is secp256r1, secret must be
-32 bytes long.
-
-Returns 1 if the shared secret was generated successfully, 0 if an error
-occurred.
-*/
-int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
- uint8_t *secret, uECC_Curve curve);
-
-#if uECC_SUPPORT_COMPRESSED_POINT
-/* uECC_compress() function.
-Compress a public key.
-
-Inputs:
- public_key - The public key to compress.
-
-Outputs:
- compressed - Will be filled in with the compressed public key. Must be at
-least (curve size + 1) bytes long; for example, if the curve is secp256r1,
- compressed must be 33 bytes long.
-*/
-void uECC_compress(const uint8_t *public_key, uint8_t *compressed,
- uECC_Curve curve);
-
-/* uECC_decompress() function.
-Decompress a compressed public key.
-
-Inputs:
- compressed - The compressed public key.
-
-Outputs:
- public_key - Will be filled in with the decompressed public key.
-*/
-void uECC_decompress(const uint8_t *compressed, uint8_t *public_key,
- uECC_Curve curve);
-#endif /* uECC_SUPPORT_COMPRESSED_POINT */
-
-/* uECC_valid_public_key() function.
-Check to see if a public key is valid.
-
-Note that you are not required to check for a valid public key before using any
-other uECC functions. However, you may wish to avoid spending CPU time computing
-a shared secret or verifying a signature using an invalid public key.
-
-Inputs:
- public_key - The public key to check.
-
-Returns 1 if the public key is valid, 0 if it is invalid.
-*/
-int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve);
-
-/* uECC_compute_public_key() function.
-Compute the corresponding public key for a private key.
-
-Inputs:
- private_key - The private key to compute the public key for
-
-Outputs:
- public_key - Will be filled in with the corresponding public key
-
-Returns 1 if the key was computed successfully, 0 if an error occurred.
-*/
-int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key,
- uECC_Curve curve);
-
-/* uECC_sign() function.
-Generate an ECDSA signature for a given hash value.
-
-Usage: Compute a hash of the data you wish to sign (SHA-2 is recommended) and
-pass it in to this function along with your private key.
-
-Inputs:
- private_key - Your private key.
- message_hash - The hash of the message to sign.
- hash_size - The size of message_hash in bytes.
-
-Outputs:
- signature - Will be filled in with the signature value. Must be at least 2 *
-curve size long. For example, if the curve is secp256r1, signature must be 64
-bytes long.
-
-Returns 1 if the signature generated successfully, 0 if an error occurred.
-*/
-int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash,
- unsigned hash_size, uint8_t *signature, uECC_Curve curve);
-
-/* uECC_HashContext structure.
-This is used to pass in an arbitrary hash function to uECC_sign_deterministic().
-The structure will be used for multiple hash computations; each time a new hash
-is computed, init_hash() will be called, followed by one or more calls to
-update_hash(), and finally a call to finish_hash() to produce the resulting
-hash.
-
-The intention is that you will create a structure that includes uECC_HashContext
-followed by any hash-specific data. For example:
-
-typedef struct SHA256_HashContext {
- uECC_HashContext uECC;
- SHA256_CTX ctx;
-} SHA256_HashContext;
-
-void init_SHA256(uECC_HashContext *base) {
- SHA256_HashContext *context = (SHA256_HashContext *)base;
- SHA256_Init(&context->ctx);
-}
-
-void update_SHA256(uECC_HashContext *base,
- const uint8_t *message,
- unsigned message_size) {
- SHA256_HashContext *context = (SHA256_HashContext *)base;
- SHA256_Update(&context->ctx, message, message_size);
-}
-
-void finish_SHA256(uECC_HashContext *base, uint8_t *hash_result) {
- SHA256_HashContext *context = (SHA256_HashContext *)base;
- SHA256_Final(hash_result, &context->ctx);
-}
-
-... when signing ...
-{
- uint8_t tmp[32 + 32 + 64];
- SHA256_HashContext ctx = {{&init_SHA256, &update_SHA256, &finish_SHA256, 64,
-32, tmp}}; uECC_sign_deterministic(key, message_hash, &ctx.uECC, signature);
-}
-*/
-typedef struct uECC_HashContext {
- void (*init_hash)(const struct uECC_HashContext *context);
- void (*update_hash)(const struct uECC_HashContext *context,
- const uint8_t *message, unsigned message_size);
- void (*finish_hash)(const struct uECC_HashContext *context,
- uint8_t *hash_result);
- unsigned
- block_size; /* Hash function block size in bytes, eg 64 for SHA-256. */
- unsigned
- result_size; /* Hash function result size in bytes, eg 32 for SHA-256. */
- uint8_t *tmp; /* Must point to a buffer of at least (2 * result_size +
- block_size) bytes. */
-} uECC_HashContext;
-
-/* uECC_sign_deterministic() function.
-Generate an ECDSA signature for a given hash value, using a deterministic
-algorithm (see RFC 6979). You do not need to set the RNG using uECC_set_rng()
-before calling this function; however, if the RNG is defined it will improve
-resistance to side-channel attacks.
-
-Usage: Compute a hash of the data you wish to sign (SHA-2 is recommended) and
-pass it to this function along with your private key and a hash context. Note
-that the message_hash does not need to be computed with the same hash function
-used by hash_context.
-
-Inputs:
- private_key - Your private key.
- message_hash - The hash of the message to sign.
- hash_size - The size of message_hash in bytes.
- hash_context - A hash context to use.
-
-Outputs:
- signature - Will be filled in with the signature value.
-
-Returns 1 if the signature generated successfully, 0 if an error occurred.
-*/
-int uECC_sign_deterministic(const uint8_t *private_key,
- const uint8_t *message_hash, unsigned hash_size,
- const uECC_HashContext *hash_context,
- uint8_t *signature, uECC_Curve curve);
-
-/* uECC_verify() function.
-Verify an ECDSA signature.
-
-Usage: Compute the hash of the signed data using the same hash as the signer and
-pass it to this function along with the signer's public key and the signature
-values (r and s).
-
-Inputs:
- public_key - The signer's public key.
- message_hash - The hash of the signed data.
- hash_size - The size of message_hash in bytes.
- signature - The signature value.
-
-Returns 1 if the signature is valid, 0 if it is invalid.
-*/
-int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
- unsigned hash_size, const uint8_t *signature, uECC_Curve curve);
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif /* _UECC_H_ */
-
-/* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
-
-#ifndef _UECC_VLI_H_
-#define _UECC_VLI_H_
-
-//
-//
-
-/* Functions for raw large-integer manipulation. These are only available
- if uECC.c is compiled with uECC_ENABLE_VLI_API defined to 1. */
-#ifndef uECC_ENABLE_VLI_API
-#define uECC_ENABLE_VLI_API 0
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if uECC_ENABLE_VLI_API
-
-void uECC_vli_clear(uECC_word_t *vli, wordcount_t num_words);
-
-/* Constant-time comparison to zero - secure way to compare long integers */
-/* Returns 1 if vli == 0, 0 otherwise. */
-uECC_word_t uECC_vli_isZero(const uECC_word_t *vli, wordcount_t num_words);
-
-/* Returns nonzero if bit 'bit' of vli is set. */
-uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit);
-
-/* Counts the number of bits required to represent vli. */
-bitcount_t uECC_vli_numBits(const uECC_word_t *vli,
- const wordcount_t max_words);
-
-/* Sets dest = src. */
-void uECC_vli_set(uECC_word_t *dest, const uECC_word_t *src,
- wordcount_t num_words);
-
-/* Constant-time comparison function - secure way to compare long integers */
-/* Returns one if left == right, zero otherwise */
-uECC_word_t uECC_vli_equal(const uECC_word_t *left, const uECC_word_t *right,
- wordcount_t num_words);
-
-/* Constant-time comparison function - secure way to compare long integers */
-/* Returns sign of left - right, in constant time. */
-cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right,
- wordcount_t num_words);
-
-/* Computes vli = vli >> 1. */
-void uECC_vli_rshift1(uECC_word_t *vli, wordcount_t num_words);
-
-/* Computes result = left + right, returning carry. Can modify in place. */
-uECC_word_t uECC_vli_add(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, wordcount_t num_words);
-
-/* Computes result = left - right, returning borrow. Can modify in place. */
-uECC_word_t uECC_vli_sub(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, wordcount_t num_words);
-
-/* Computes result = left * right. Result must be 2 * num_words long. */
-void uECC_vli_mult(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, wordcount_t num_words);
-
-/* Computes result = left^2. Result must be 2 * num_words long. */
-void uECC_vli_square(uECC_word_t *result, const uECC_word_t *left,
- wordcount_t num_words);
-
-/* Computes result = (left + right) % mod.
- Assumes that left < mod and right < mod, and that result does not overlap
- mod. */
-void uECC_vli_modAdd(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, const uECC_word_t *mod,
- wordcount_t num_words);
-
-/* Computes result = (left - right) % mod.
- Assumes that left < mod and right < mod, and that result does not overlap
- mod. */
-void uECC_vli_modSub(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, const uECC_word_t *mod,
- wordcount_t num_words);
-
-/* Computes result = product % mod, where product is 2N words long.
- Currently only designed to work for mod == curve->p or curve_n. */
-void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product,
- const uECC_word_t *mod, wordcount_t num_words);
-
-/* Calculates result = product (mod curve->p), where product is up to
- 2 * curve->num_words long. */
-void uECC_vli_mmod_fast(uECC_word_t *result, uECC_word_t *product,
- uECC_Curve curve);
-
-/* Computes result = (left * right) % mod.
- Currently only designed to work for mod == curve->p or curve_n. */
-void uECC_vli_modMult(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, const uECC_word_t *mod,
- wordcount_t num_words);
-
-/* Computes result = (left * right) % curve->p. */
-void uECC_vli_modMult_fast(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, uECC_Curve curve);
-
-/* Computes result = left^2 % mod.
- Currently only designed to work for mod == curve->p or curve_n. */
-void uECC_vli_modSquare(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *mod, wordcount_t num_words);
-
-/* Computes result = left^2 % curve->p. */
-void uECC_vli_modSquare_fast(uECC_word_t *result, const uECC_word_t *left,
- uECC_Curve curve);
-
-/* Computes result = (1 / input) % mod.*/
-void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
- const uECC_word_t *mod, wordcount_t num_words);
-
-#if uECC_SUPPORT_COMPRESSED_POINT
-/* Calculates a = sqrt(a) (mod curve->p) */
-void uECC_vli_mod_sqrt(uECC_word_t *a, uECC_Curve curve);
-#endif
-
-/* Converts an integer in uECC native format to big-endian bytes. */
-void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes,
- const uECC_word_t *native);
-/* Converts big-endian bytes to an integer in uECC native format. */
-void uECC_vli_bytesToNative(uECC_word_t *native, const uint8_t *bytes,
- int num_bytes);
-
-unsigned uECC_curve_num_words(uECC_Curve curve);
-unsigned uECC_curve_num_bytes(uECC_Curve curve);
-unsigned uECC_curve_num_bits(uECC_Curve curve);
-unsigned uECC_curve_num_n_words(uECC_Curve curve);
-unsigned uECC_curve_num_n_bytes(uECC_Curve curve);
-unsigned uECC_curve_num_n_bits(uECC_Curve curve);
-
-const uECC_word_t *uECC_curve_p(uECC_Curve curve);
-const uECC_word_t *uECC_curve_n(uECC_Curve curve);
-const uECC_word_t *uECC_curve_G(uECC_Curve curve);
-const uECC_word_t *uECC_curve_b(uECC_Curve curve);
-
-int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve);
-
-/* Multiplies a point by a scalar. Points are represented by the X coordinate
- followed by the Y coordinate in the same array, both coordinates are
- curve->num_words long. Note that scalar must be curve->num_n_words long (NOT
- curve->num_words). */
-void uECC_point_mult(uECC_word_t *result, const uECC_word_t *point,
- const uECC_word_t *scalar, uECC_Curve curve);
-
-/* Generates a random integer in the range 0 < random < top.
- Both random and top have num_words words. */
-int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top,
- wordcount_t num_words);
-
-#endif /* uECC_ENABLE_VLI_API */
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif /* _UECC_VLI_H_ */
-
-/* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
-
-#ifndef _UECC_TYPES_H_
-#define _UECC_TYPES_H_
-
-#ifndef uECC_PLATFORM
-#if defined(__AVR__) && __AVR__
-#define uECC_PLATFORM uECC_avr
-#elif defined(__thumb2__) || \
- defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */
-#define uECC_PLATFORM uECC_arm_thumb2
-#elif defined(__thumb__)
-#define uECC_PLATFORM uECC_arm_thumb
-#elif defined(__arm__) || defined(_M_ARM)
-#define uECC_PLATFORM uECC_arm
-#elif defined(__aarch64__)
-#define uECC_PLATFORM uECC_arm64
-#elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \
- defined(__I86__)
-#define uECC_PLATFORM uECC_x86
-#elif defined(__amd64__) || defined(_M_X64)
-#define uECC_PLATFORM uECC_x86_64
-#else
-#define uECC_PLATFORM uECC_arch_other
-#endif
-#endif
-
-#ifndef uECC_ARM_USE_UMAAL
-#if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6)
-#define uECC_ARM_USE_UMAAL 1
-#elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && \
- (!defined(__ARM_ARCH_7M__) || !__ARM_ARCH_7M__)
-#define uECC_ARM_USE_UMAAL 1
-#else
-#define uECC_ARM_USE_UMAAL 0
-#endif
-#endif
-
-#ifndef uECC_WORD_SIZE
-#if uECC_PLATFORM == uECC_avr
-#define uECC_WORD_SIZE 1
-#elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64)
-#define uECC_WORD_SIZE 8
-#else
-#define uECC_WORD_SIZE 4
-#endif
-#endif
-
-#if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8)
-#error "Unsupported value for uECC_WORD_SIZE"
-#endif
-
-#if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1))
-#pragma message("uECC_WORD_SIZE must be 1 for AVR")
-#undef uECC_WORD_SIZE
-#define uECC_WORD_SIZE 1
-#endif
-
-#if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \
- uECC_PLATFORM == uECC_arm_thumb2) && \
- (uECC_WORD_SIZE != 4))
-#pragma message("uECC_WORD_SIZE must be 4 for ARM")
-#undef uECC_WORD_SIZE
-#define uECC_WORD_SIZE 4
-#endif
-
-typedef int8_t wordcount_t;
-typedef int16_t bitcount_t;
-typedef int8_t cmpresult_t;
-
-#if (uECC_WORD_SIZE == 1)
-
-typedef uint8_t uECC_word_t;
-typedef uint16_t uECC_dword_t;
-
-#define HIGH_BIT_SET 0x80
-#define uECC_WORD_BITS 8
-#define uECC_WORD_BITS_SHIFT 3
-#define uECC_WORD_BITS_MASK 0x07
-
-#elif (uECC_WORD_SIZE == 4)
-
-typedef uint32_t uECC_word_t;
-typedef uint64_t uECC_dword_t;
-
-#define HIGH_BIT_SET 0x80000000
-#define uECC_WORD_BITS 32
-#define uECC_WORD_BITS_SHIFT 5
-#define uECC_WORD_BITS_MASK 0x01F
-
-#elif (uECC_WORD_SIZE == 8)
-
-typedef uint64_t uECC_word_t;
-
-#define HIGH_BIT_SET 0x8000000000000000U
-#define uECC_WORD_BITS 64
-#define uECC_WORD_BITS_SHIFT 6
-#define uECC_WORD_BITS_MASK 0x03F
-
-#endif /* uECC_WORD_SIZE */
-
-#endif /* _UECC_TYPES_H_ */
-// End of uecc BSD-2
-
-
-struct mg_connection;
-typedef void (*mg_event_handler_t)(struct mg_connection *, int ev,
- void *ev_data);
-void mg_call(struct mg_connection *c, int ev, void *ev_data);
-void mg_error(struct mg_connection *c, const char *fmt, ...);
-
-enum {
- MG_EV_ERROR, // Error char *error_message
- MG_EV_OPEN, // Connection created NULL
- MG_EV_POLL, // mg_mgr_poll iteration uint64_t *uptime_millis
- MG_EV_RESOLVE, // Host name is resolved NULL
- MG_EV_CONNECT, // Connection established NULL
- MG_EV_ACCEPT, // Connection accepted NULL
- MG_EV_TLS_HS, // TLS handshake succeeded NULL
- MG_EV_READ, // Data received from socket long *bytes_read
- MG_EV_WRITE, // Data written to socket long *bytes_written
- MG_EV_CLOSE, // Connection closed NULL
- MG_EV_HTTP_MSG, // HTTP request/response struct mg_http_message *
- MG_EV_WS_OPEN, // Websocket handshake done struct mg_http_message *
- MG_EV_WS_MSG, // Websocket msg, text or bin struct mg_ws_message *
- MG_EV_WS_CTL, // Websocket control msg struct mg_ws_message *
- MG_EV_MQTT_CMD, // MQTT low-level command struct mg_mqtt_message *
- MG_EV_MQTT_MSG, // MQTT PUBLISH received struct mg_mqtt_message *
- MG_EV_MQTT_OPEN, // MQTT CONNACK received int *connack_status_code
- MG_EV_SNTP_TIME, // SNTP time received uint64_t *epoch_millis
- MG_EV_WAKEUP, // mg_wakeup() data received struct mg_str *data
- MG_EV_USER // Starting ID for user events
-};
-
-
-
-
-
-
-
-
-
-struct mg_dns {
- const char *url; // DNS server URL
- struct mg_connection *c; // DNS server connection
-};
-
-struct mg_addr {
- uint8_t ip[16]; // Holds IPv4 or IPv6 address, in network byte order
- uint16_t port; // TCP or UDP port in network byte order
- uint8_t scope_id; // IPv6 scope ID
- bool is_ip6; // True when address is IPv6 address
-};
-
-struct mg_mgr {
- struct mg_connection *conns; // List of active connections
- struct mg_dns dns4; // DNS for IPv4
- struct mg_dns dns6; // DNS for IPv6
- int dnstimeout; // DNS resolve timeout in milliseconds
- bool use_dns6; // Use DNS6 server by default, see #1532
- unsigned long nextid; // Next connection ID
- unsigned long timerid; // Next timer ID
- void *userdata; // Arbitrary user data pointer
- void *tls_ctx; // TLS context shared by all TLS sessions
- uint16_t mqtt_id; // MQTT IDs for pub/sub
- void *active_dns_requests; // DNS requests in progress
- struct mg_timer *timers; // Active timers
- int epoll_fd; // Used when MG_EPOLL_ENABLE=1
- void *priv; // Used by the MIP stack
- size_t extraconnsize; // Used by the MIP stack
- MG_SOCKET_TYPE pipe; // Socketpair end for mg_wakeup()
-#if MG_ENABLE_FREERTOS_TCP
- SocketSet_t ss; // NOTE(lsm): referenced from socket struct
-#endif
-};
-
-struct mg_connection {
- struct mg_connection *next; // Linkage in struct mg_mgr :: connections
- struct mg_mgr *mgr; // Our container
- struct mg_addr loc; // Local address
- struct mg_addr rem; // Remote address
- void *fd; // Connected socket, or LWIP data
- unsigned long id; // Auto-incrementing unique connection ID
- struct mg_iobuf recv; // Incoming data
- struct mg_iobuf send; // Outgoing data
- struct mg_iobuf prof; // Profile data enabled by MG_ENABLE_PROFILE
- struct mg_iobuf rtls; // TLS only. Incoming encrypted data
- mg_event_handler_t fn; // User-specified event handler function
- void *fn_data; // User-specified function parameter
- mg_event_handler_t pfn; // Protocol-specific handler function
- void *pfn_data; // Protocol-specific function parameter
- char data[MG_DATA_SIZE]; // Arbitrary connection data
- void *tls; // TLS specific data
- unsigned is_listening : 1; // Listening connection
- unsigned is_client : 1; // Outbound (client) connection
- unsigned is_accepted : 1; // Accepted (server) connection
- unsigned is_resolving : 1; // Non-blocking DNS resolution is in progress
- unsigned is_arplooking : 1; // Non-blocking ARP resolution is in progress
- unsigned is_connecting : 1; // Non-blocking connect is in progress
- unsigned is_tls : 1; // TLS-enabled connection
- unsigned is_tls_hs : 1; // TLS handshake is in progress
- unsigned is_udp : 1; // UDP connection
- unsigned is_websocket : 1; // WebSocket connection
- unsigned is_mqtt5 : 1; // For MQTT connection, v5 indicator
- unsigned is_hexdumping : 1; // Hexdump in/out traffic
- unsigned is_draining : 1; // Send remaining data, then close and free
- unsigned is_closing : 1; // Close and free the connection immediately
- unsigned is_full : 1; // Stop reads, until cleared
- unsigned is_resp : 1; // Response is still being generated
- unsigned is_readable : 1; // Connection is ready to read
- unsigned is_writable : 1; // Connection is ready to write
-};
-
-void mg_mgr_poll(struct mg_mgr *, int ms);
-void mg_mgr_init(struct mg_mgr *);
-void mg_mgr_free(struct mg_mgr *);
-
-struct mg_connection *mg_listen(struct mg_mgr *, const char *url,
- mg_event_handler_t fn, void *fn_data);
-struct mg_connection *mg_connect(struct mg_mgr *, const char *url,
- mg_event_handler_t fn, void *fn_data);
-struct mg_connection *mg_wrapfd(struct mg_mgr *mgr, int fd,
- mg_event_handler_t fn, void *fn_data);
-void mg_connect_resolved(struct mg_connection *);
-bool mg_send(struct mg_connection *, const void *, size_t);
-size_t mg_printf(struct mg_connection *, const char *fmt, ...);
-size_t mg_vprintf(struct mg_connection *, const char *fmt, va_list *ap);
-bool mg_aton(struct mg_str str, struct mg_addr *addr);
-
-// These functions are used to integrate with custom network stacks
-struct mg_connection *mg_alloc_conn(struct mg_mgr *);
-void mg_close_conn(struct mg_connection *c);
-bool mg_open_listener(struct mg_connection *c, const char *url);
-
-// Utility functions
-bool mg_wakeup(struct mg_mgr *, unsigned long id, const void *buf, size_t len);
-bool mg_wakeup_init(struct mg_mgr *);
-struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
- unsigned flags, void (*fn)(void *), void *arg);
-
-
-
-
-
-
-
-
-struct mg_http_header {
- struct mg_str name; // Header name
- struct mg_str value; // Header value
-};
-
-struct mg_http_message {
- struct mg_str method, uri, query, proto; // Request/response line
- struct mg_http_header headers[MG_MAX_HTTP_HEADERS]; // Headers
- struct mg_str body; // Body
- struct mg_str head; // Request + headers
- struct mg_str message; // Request + headers + body
-};
-
-// Parameter for mg_http_serve_dir()
-struct mg_http_serve_opts {
- const char *root_dir; // Web root directory, must be non-NULL
- const char *ssi_pattern; // SSI file name pattern, e.g. #.shtml
- const char *extra_headers; // Extra HTTP headers to add in responses
- const char *mime_types; // Extra mime types, ext1=type1,ext2=type2,..
- const char *page404; // Path to the 404 page, or NULL by default
- struct mg_fs *fs; // Filesystem implementation. Use NULL for POSIX
-};
-
-// Parameter for mg_http_next_multipart
-struct mg_http_part {
- struct mg_str name; // Form field name
- struct mg_str filename; // Filename for file uploads
- struct mg_str body; // Part contents
-};
-
-int mg_http_parse(const char *s, size_t len, struct mg_http_message *);
-int mg_http_get_request_len(const unsigned char *buf, size_t buf_len);
-void mg_http_printf_chunk(struct mg_connection *cnn, const char *fmt, ...);
-void mg_http_write_chunk(struct mg_connection *c, const char *buf, size_t len);
-void mg_http_delete_chunk(struct mg_connection *c, struct mg_http_message *hm);
-struct mg_connection *mg_http_listen(struct mg_mgr *, const char *url,
- mg_event_handler_t fn, void *fn_data);
-struct mg_connection *mg_http_connect(struct mg_mgr *, const char *url,
- mg_event_handler_t fn, void *fn_data);
-void mg_http_serve_dir(struct mg_connection *, struct mg_http_message *hm,
- const struct mg_http_serve_opts *);
-void mg_http_serve_file(struct mg_connection *, struct mg_http_message *hm,
- const char *path, const struct mg_http_serve_opts *);
-void mg_http_reply(struct mg_connection *, int status_code, const char *headers,
- const char *body_fmt, ...);
-struct mg_str *mg_http_get_header(struct mg_http_message *, const char *name);
-struct mg_str mg_http_var(struct mg_str buf, struct mg_str name);
-int mg_http_get_var(const struct mg_str *, const char *name, char *, size_t);
-int mg_url_decode(const char *s, size_t n, char *to, size_t to_len, int form);
-size_t mg_url_encode(const char *s, size_t n, char *buf, size_t len);
-void mg_http_creds(struct mg_http_message *, char *, size_t, char *, size_t);
-bool mg_http_match_uri(const struct mg_http_message *, const char *glob);
-long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
- struct mg_fs *fs, const char *dir, size_t max_size);
-void mg_http_bauth(struct mg_connection *, const char *user, const char *pass);
-struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v);
-size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *);
-int mg_http_status(const struct mg_http_message *hm);
-void mg_hello(const char *url);
-
-
-void mg_http_serve_ssi(struct mg_connection *c, const char *root,
- const char *fullpath);
-
-
-#define MG_TLS_NONE 0 // No TLS support
-#define MG_TLS_MBED 1 // mbedTLS
-#define MG_TLS_OPENSSL 2 // OpenSSL
-#define MG_TLS_BUILTIN 3 // Built-in
-#define MG_TLS_CUSTOM 4 // Custom implementation
-
-#ifndef MG_TLS
-#define MG_TLS MG_TLS_NONE
-#endif
-
-
-
-
-
-struct mg_tls_opts {
- struct mg_str ca; // PEM or DER
- struct mg_str cert; // PEM or DER
- struct mg_str key; // PEM or DER
- struct mg_str name; // If not empty, enable host name verification
-};
-
-void mg_tls_init(struct mg_connection *, const struct mg_tls_opts *opts);
-void mg_tls_free(struct mg_connection *);
-long mg_tls_send(struct mg_connection *, const void *buf, size_t len);
-long mg_tls_recv(struct mg_connection *, void *buf, size_t len);
-size_t mg_tls_pending(struct mg_connection *);
-void mg_tls_handshake(struct mg_connection *);
-
-// Private
-void mg_tls_ctx_init(struct mg_mgr *);
-void mg_tls_ctx_free(struct mg_mgr *);
-
-// Low-level IO primives used by TLS layer
-enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
-long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
-long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
-
-
-
-
-
-
-
-#if MG_TLS == MG_TLS_MBED
-#include
-#include
-#include
-#include
-
-struct mg_tls_ctx {
- int dummy;
-#ifdef MBEDTLS_SSL_SESSION_TICKETS
- mbedtls_ssl_ticket_context tickets;
-#endif
-};
-
-struct mg_tls {
- mbedtls_x509_crt ca; // Parsed CA certificate
- mbedtls_x509_crt cert; // Parsed certificate
- mbedtls_pk_context pk; // Private key context
- mbedtls_ssl_context ssl; // SSL/TLS context
- mbedtls_ssl_config conf; // SSL-TLS config
-#ifdef MBEDTLS_SSL_SESSION_TICKETS
- mbedtls_ssl_ticket_context ticket; // Session tickets context
-#endif
-};
-#endif
-
-
-#if MG_TLS == MG_TLS_OPENSSL
-
-#include
-#include
-
-struct mg_tls {
- BIO_METHOD *bm;
- SSL_CTX *ctx;
- SSL *ssl;
-};
-#endif
-
-
-#define WEBSOCKET_OP_CONTINUE 0
-#define WEBSOCKET_OP_TEXT 1
-#define WEBSOCKET_OP_BINARY 2
-#define WEBSOCKET_OP_CLOSE 8
-#define WEBSOCKET_OP_PING 9
-#define WEBSOCKET_OP_PONG 10
-
-
-
-struct mg_ws_message {
- struct mg_str data; // Websocket message data
- uint8_t flags; // Websocket message flags
-};
-
-struct mg_connection *mg_ws_connect(struct mg_mgr *, const char *url,
- mg_event_handler_t fn, void *fn_data,
- const char *fmt, ...);
-void mg_ws_upgrade(struct mg_connection *, struct mg_http_message *,
- const char *fmt, ...);
-size_t mg_ws_send(struct mg_connection *, const void *buf, size_t len, int op);
-size_t mg_ws_wrap(struct mg_connection *, size_t len, int op);
-size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...);
-size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt,
- va_list *);
-
-
-
-
-struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
- mg_event_handler_t fn, void *fn_data);
-void mg_sntp_request(struct mg_connection *c);
-int64_t mg_sntp_parse(const unsigned char *buf, size_t len);
-
-
-
-
-
-#define MQTT_CMD_CONNECT 1
-#define MQTT_CMD_CONNACK 2
-#define MQTT_CMD_PUBLISH 3
-#define MQTT_CMD_PUBACK 4
-#define MQTT_CMD_PUBREC 5
-#define MQTT_CMD_PUBREL 6
-#define MQTT_CMD_PUBCOMP 7
-#define MQTT_CMD_SUBSCRIBE 8
-#define MQTT_CMD_SUBACK 9
-#define MQTT_CMD_UNSUBSCRIBE 10
-#define MQTT_CMD_UNSUBACK 11
-#define MQTT_CMD_PINGREQ 12
-#define MQTT_CMD_PINGRESP 13
-#define MQTT_CMD_DISCONNECT 14
-#define MQTT_CMD_AUTH 15
-
-#define MQTT_PROP_PAYLOAD_FORMAT_INDICATOR 0x01
-#define MQTT_PROP_MESSAGE_EXPIRY_INTERVAL 0x02
-#define MQTT_PROP_CONTENT_TYPE 0x03
-#define MQTT_PROP_RESPONSE_TOPIC 0x08
-#define MQTT_PROP_CORRELATION_DATA 0x09
-#define MQTT_PROP_SUBSCRIPTION_IDENTIFIER 0x0B
-#define MQTT_PROP_SESSION_EXPIRY_INTERVAL 0x11
-#define MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER 0x12
-#define MQTT_PROP_SERVER_KEEP_ALIVE 0x13
-#define MQTT_PROP_AUTHENTICATION_METHOD 0x15
-#define MQTT_PROP_AUTHENTICATION_DATA 0x16
-#define MQTT_PROP_REQUEST_PROBLEM_INFORMATION 0x17
-#define MQTT_PROP_WILL_DELAY_INTERVAL 0x18
-#define MQTT_PROP_REQUEST_RESPONSE_INFORMATION 0x19
-#define MQTT_PROP_RESPONSE_INFORMATION 0x1A
-#define MQTT_PROP_SERVER_REFERENCE 0x1C
-#define MQTT_PROP_REASON_STRING 0x1F
-#define MQTT_PROP_RECEIVE_MAXIMUM 0x21
-#define MQTT_PROP_TOPIC_ALIAS_MAXIMUM 0x22
-#define MQTT_PROP_TOPIC_ALIAS 0x23
-#define MQTT_PROP_MAXIMUM_QOS 0x24
-#define MQTT_PROP_RETAIN_AVAILABLE 0x25
-#define MQTT_PROP_USER_PROPERTY 0x26
-#define MQTT_PROP_MAXIMUM_PACKET_SIZE 0x27
-#define MQTT_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE 0x28
-#define MQTT_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE 0x29
-#define MQTT_PROP_SHARED_SUBSCRIPTION_AVAILABLE 0x2A
-
-enum {
- MQTT_PROP_TYPE_BYTE,
- MQTT_PROP_TYPE_STRING,
- MQTT_PROP_TYPE_STRING_PAIR,
- MQTT_PROP_TYPE_BINARY_DATA,
- MQTT_PROP_TYPE_VARIABLE_INT,
- MQTT_PROP_TYPE_INT,
- MQTT_PROP_TYPE_SHORT
-};
-
-enum { MQTT_OK, MQTT_INCOMPLETE, MQTT_MALFORMED };
-
-struct mg_mqtt_prop {
- uint8_t id; // Enumerated at MQTT5 Reference
- uint32_t iv; // Integer value for 8-, 16-, 32-bit integers types
- struct mg_str key; // Non-NULL only for user property type
- struct mg_str val; // Non-NULL only for UTF-8 types and user properties
-};
-
-struct mg_mqtt_opts {
- struct mg_str user; // Username, can be empty
- struct mg_str pass; // Password, can be empty
- struct mg_str client_id; // Client ID
- struct mg_str topic; // message/subscription topic
- struct mg_str message; // message content
- uint8_t qos; // message quality of service
- uint8_t version; // Can be 4 (3.1.1), or 5. If 0, assume 4
- uint16_t keepalive; // Keep-alive timer in seconds
- bool retain; // Retain flag
- bool clean; // Clean session flag
- struct mg_mqtt_prop *props; // MQTT5 props array
- size_t num_props; // number of props
- struct mg_mqtt_prop *will_props; // Valid only for CONNECT packet (MQTT5)
- size_t num_will_props; // Number of will props
-};
-
-struct mg_mqtt_message {
- struct mg_str topic; // Parsed topic for PUBLISH
- struct mg_str data; // Parsed message for PUBLISH
- struct mg_str dgram; // Whole MQTT packet, including headers
- uint16_t id; // For PUBACK, PUBREC, PUBREL, PUBCOMP, SUBACK, PUBLISH
- uint8_t cmd; // MQTT command, one of MQTT_CMD_*
- uint8_t qos; // Quality of service
- uint8_t ack; // CONNACK return code, 0 = success
- size_t props_start; // Offset to the start of the properties (MQTT5)
- size_t props_size; // Length of the properties
-};
-
-struct mg_connection *mg_mqtt_connect(struct mg_mgr *, const char *url,
- const struct mg_mqtt_opts *opts,
- mg_event_handler_t fn, void *fn_data);
-struct mg_connection *mg_mqtt_listen(struct mg_mgr *mgr, const char *url,
- mg_event_handler_t fn, void *fn_data);
-void mg_mqtt_login(struct mg_connection *c, const struct mg_mqtt_opts *opts);
-void mg_mqtt_pub(struct mg_connection *c, const struct mg_mqtt_opts *opts);
-void mg_mqtt_sub(struct mg_connection *, const struct mg_mqtt_opts *opts);
-int mg_mqtt_parse(const uint8_t *, size_t, uint8_t, struct mg_mqtt_message *);
-void mg_mqtt_send_header(struct mg_connection *, uint8_t cmd, uint8_t flags,
- uint32_t len);
-void mg_mqtt_ping(struct mg_connection *);
-void mg_mqtt_pong(struct mg_connection *);
-void mg_mqtt_disconnect(struct mg_connection *, const struct mg_mqtt_opts *);
-size_t mg_mqtt_next_prop(struct mg_mqtt_message *, struct mg_mqtt_prop *,
- size_t ofs);
-
-
-
-
-
-// Mongoose sends DNS queries that contain only one question:
-// either A (IPv4) or AAAA (IPv6) address lookup.
-// Therefore, we expect zero or one answer.
-// If `resolved` is true, then `addr` contains resolved IPv4 or IPV6 address.
-struct mg_dns_message {
- uint16_t txnid; // Transaction ID
- bool resolved; // Resolve successful, addr is set
- struct mg_addr addr; // Resolved address
- char name[256]; // Host name
-};
-
-struct mg_dns_header {
- uint16_t txnid; // Transaction ID
- uint16_t flags;
- uint16_t num_questions;
- uint16_t num_answers;
- uint16_t num_authority_prs;
- uint16_t num_other_prs;
-};
-
-// DNS resource record
-struct mg_dns_rr {
- uint16_t nlen; // Name or pointer length
- uint16_t atype; // Address type
- uint16_t aclass; // Address class
- uint16_t alen; // Address length
-};
-
-void mg_resolve(struct mg_connection *, const char *url);
-void mg_resolve_cancel(struct mg_connection *);
-bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *);
-size_t mg_dns_parse_rr(const uint8_t *buf, size_t len, size_t ofs,
- bool is_question, struct mg_dns_rr *);
-
-
-
-
-
-#ifndef MG_JSON_MAX_DEPTH
-#define MG_JSON_MAX_DEPTH 30
-#endif
-
-// Error return values - negative. Successful returns are >= 0
-enum { MG_JSON_TOO_DEEP = -1, MG_JSON_INVALID = -2, MG_JSON_NOT_FOUND = -3 };
-int mg_json_get(struct mg_str json, const char *path, int *toklen);
-
-struct mg_str mg_json_get_tok(struct mg_str json, const char *path);
-bool mg_json_get_num(struct mg_str json, const char *path, double *v);
-bool mg_json_get_bool(struct mg_str json, const char *path, bool *v);
-long mg_json_get_long(struct mg_str json, const char *path, long dflt);
-char *mg_json_get_str(struct mg_str json, const char *path);
-char *mg_json_get_hex(struct mg_str json, const char *path, int *len);
-char *mg_json_get_b64(struct mg_str json, const char *path, int *len);
-
-bool mg_json_unescape(struct mg_str str, char *buf, size_t len);
-size_t mg_json_next(struct mg_str obj, size_t ofs, struct mg_str *key,
- struct mg_str *val);
-
-
-
-
-// JSON-RPC request descriptor
-struct mg_rpc_req {
- struct mg_rpc **head; // RPC handlers list head
- struct mg_rpc *rpc; // RPC handler being called
- mg_pfn_t pfn; // Response printing function
- void *pfn_data; // Response printing function data
- void *req_data; // Arbitrary request data
- struct mg_str frame; // Request, e.g. {"id":1,"method":"add","params":[1,2]}
-};
-
-// JSON-RPC method handler
-struct mg_rpc {
- struct mg_rpc *next; // Next in list
- struct mg_str method; // Method pattern
- void (*fn)(struct mg_rpc_req *); // Handler function
- void *fn_data; // Handler function argument
-};
-
-void mg_rpc_add(struct mg_rpc **head, struct mg_str method_pattern,
- void (*handler)(struct mg_rpc_req *), void *handler_data);
-void mg_rpc_del(struct mg_rpc **head, void (*handler)(struct mg_rpc_req *));
-void mg_rpc_process(struct mg_rpc_req *);
-
-// Helper functions to print result or error frame
-void mg_rpc_ok(struct mg_rpc_req *, const char *fmt, ...);
-void mg_rpc_vok(struct mg_rpc_req *, const char *fmt, va_list *ap);
-void mg_rpc_err(struct mg_rpc_req *, int code, const char *fmt, ...);
-void mg_rpc_verr(struct mg_rpc_req *, int code, const char *fmt, va_list *);
-void mg_rpc_list(struct mg_rpc_req *r);
-// Copyright (c) 2023 Cesanta Software Limited
-// All rights reserved
-
-
-
-
-
-#define MG_OTA_NONE 0 // No OTA support
-#define MG_OTA_FLASH 1 // OTA via an internal flash
-#define MG_OTA_CUSTOM 100 // Custom implementation
-
-#ifndef MG_OTA
-#define MG_OTA MG_OTA_NONE
-#endif
-
-#if defined(__GNUC__) && !defined(__APPLE__)
-#define MG_IRAM __attribute__((section(".iram")))
-#else
-#define MG_IRAM
-#endif
-
-// Firmware update API
-bool mg_ota_begin(size_t new_firmware_size); // Start writing
-bool mg_ota_write(const void *buf, size_t len); // Write chunk, aligned to 1k
-bool mg_ota_end(void); // Stop writing
-
-enum {
- MG_OTA_UNAVAILABLE = 0, // No OTA information is present
- MG_OTA_FIRST_BOOT = 1, // Device booting the first time after the OTA
- MG_OTA_UNCOMMITTED = 2, // Ditto, but marking us for the rollback
- MG_OTA_COMMITTED = 3 // The firmware is good
-};
-enum { MG_FIRMWARE_CURRENT = 0, MG_FIRMWARE_PREVIOUS = 1 };
-
-int mg_ota_status(int firmware); // Return firmware status MG_OTA_*
-uint32_t mg_ota_crc32(int firmware); // Return firmware checksum
-uint32_t mg_ota_timestamp(int firmware); // Firmware timestamp, UNIX UTC epoch
-size_t mg_ota_size(int firmware); // Firmware size
-
-bool mg_ota_commit(void); // Commit current firmware
-bool mg_ota_rollback(void); // Rollback to the previous firmware
-MG_IRAM void mg_ota_boot(void); // Bootloader function
-// Copyright (c) 2023 Cesanta Software Limited
-// All rights reserved
-
-
-
-
-
-#define MG_DEVICE_NONE 0 // Dummy system
-#define MG_DEVICE_STM32H5 1 // STM32 H5
-#define MG_DEVICE_STM32H7 2 // STM32 H7
-#define MG_DEVICE_RT1020 3 // IMXRT1020
-#define MG_DEVICE_RT1060 4 // IMXRT1060
-#define MG_DEVICE_CH32V307 100 // WCH CH32V307
-#define MG_DEVICE_CUSTOM 1000 // Custom implementation
-
-#ifndef MG_DEVICE
-#define MG_DEVICE MG_DEVICE_NONE
-#endif
-
-// Flash information
-void *mg_flash_start(void); // Return flash start address
-size_t mg_flash_size(void); // Return flash size
-size_t mg_flash_sector_size(void); // Return flash sector size
-size_t mg_flash_write_align(void); // Return flash write align, minimum 4
-int mg_flash_bank(void); // 0: not dual bank, 1: bank1, 2: bank2
-
-// Write, erase, swap bank
-bool mg_flash_write(void *addr, const void *buf, size_t len);
-bool mg_flash_erase(void *sector);
-bool mg_flash_swap_bank(void);
-
-// Convenience functions to store data on a flash sector with wear levelling
-// If `sector` is NULL, then the last sector of flash is used
-bool mg_flash_load(void *sector, uint32_t key, void *buf, size_t len);
-bool mg_flash_save(void *sector, uint32_t key, const void *buf, size_t len);
-
-void mg_device_reset(void); // Reboot device immediately
-
-
-
-
-
-
-#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP
-struct mg_tcpip_if; // Mongoose TCP/IP network interface
-
-struct mg_tcpip_driver {
- bool (*init)(struct mg_tcpip_if *); // Init driver
- size_t (*tx)(const void *, size_t, struct mg_tcpip_if *); // Transmit frame
- size_t (*rx)(void *buf, size_t len, struct mg_tcpip_if *); // Receive frame
- bool (*up)(struct mg_tcpip_if *); // Up/down status
-};
-
-// Network interface
-struct mg_tcpip_if {
- uint8_t mac[6]; // MAC address. Must be set to a valid MAC
- uint32_t ip, mask, gw; // IP address, mask, default gateway
- struct mg_str tx; // Output (TX) buffer
- bool enable_dhcp_client; // Enable DCHP client
- bool enable_dhcp_server; // Enable DCHP server
- bool enable_get_gateway; // DCHP server sets client as gateway
- bool enable_crc32_check; // Do a CRC check on RX frames and strip it
- bool enable_mac_check; // Do a MAC check on RX frames
- struct mg_tcpip_driver *driver; // Low level driver
- void *driver_data; // Driver-specific data
- struct mg_mgr *mgr; // Mongoose event manager
- struct mg_queue recv_queue; // Receive queue
- uint16_t mtu; // Interface MTU
-#define MG_TCPIP_MTU_DEFAULT 1500
-
- // Internal state, user can use it but should not change it
- uint8_t gwmac[6]; // Router's MAC
- uint64_t now; // Current time
- uint64_t timer_1000ms; // 1000 ms timer: for DHCP and link state
- uint64_t lease_expire; // Lease expiration time, in ms
- uint16_t eport; // Next ephemeral port
- volatile uint32_t ndrop; // Number of received, but dropped frames
- volatile uint32_t nrecv; // Number of received frames
- volatile uint32_t nsent; // Number of transmitted frames
- volatile uint32_t nerr; // Number of driver errors
- uint8_t state; // Current state
-#define MG_TCPIP_STATE_DOWN 0 // Interface is down
-#define MG_TCPIP_STATE_UP 1 // Interface is up
-#define MG_TCPIP_STATE_REQ 2 // Interface is up and has requested an IP
-#define MG_TCPIP_STATE_READY 3 // Interface is up and has an IP assigned
-};
-
-void mg_tcpip_init(struct mg_mgr *, struct mg_tcpip_if *);
-void mg_tcpip_free(struct mg_tcpip_if *);
-void mg_tcpip_qwrite(void *buf, size_t len, struct mg_tcpip_if *ifp);
-
-extern struct mg_tcpip_driver mg_tcpip_driver_stm32f;
-extern struct mg_tcpip_driver mg_tcpip_driver_w5500;
-extern struct mg_tcpip_driver mg_tcpip_driver_tm4c;
-extern struct mg_tcpip_driver mg_tcpip_driver_stm32h;
-extern struct mg_tcpip_driver mg_tcpip_driver_imxrt;
-extern struct mg_tcpip_driver mg_tcpip_driver_same54;
-extern struct mg_tcpip_driver mg_tcpip_driver_cmsis;
-
-// Drivers that require SPI, can use this SPI abstraction
-struct mg_tcpip_spi {
- void *spi; // Opaque SPI bus descriptor
- void (*begin)(void *); // SPI begin: slave select low
- void (*end)(void *); // SPI end: slave select high
- uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
-};
-#endif
-
-
-
-// Macros to record timestamped events that happens with a connection.
-// They are saved into a c->prof IO buffer, each event is a name and a 32-bit
-// timestamp in milliseconds since connection init time.
-//
-// Test (run in two separate terminals):
-// make -C examples/http-server/ CFLAGS_EXTRA=-DMG_ENABLE_PROFILE=1
-// curl localhost:8000
-// Output:
-// 1ea1f1e7 2 net.c:150:mg_close_conn 3 profile:
-// 1ea1f1e8 2 net.c:150:mg_close_conn 1ea1f1e6 init
-// 1ea1f1e8 2 net.c:150:mg_close_conn 0 EV_OPEN
-// 1ea1f1e8 2 net.c:150:mg_close_conn 0 EV_ACCEPT
-// 1ea1f1e8 2 net.c:150:mg_close_conn 0 EV_READ
-// 1ea1f1e8 2 net.c:150:mg_close_conn 0 EV_HTTP_MSG
-// 1ea1f1e8 2 net.c:150:mg_close_conn 0 EV_WRITE
-// 1ea1f1e8 2 net.c:150:mg_close_conn 1 EV_CLOSE
-//
-// Usage:
-// Enable profiling by setting MG_ENABLE_PROFILE=1
-// Invoke MG_PROF_ADD(c, "MY_EVENT_1") in the places you'd like to measure
-
-#if MG_ENABLE_PROFILE
-struct mg_profitem {
- const char *name; // Event name
- uint32_t timestamp; // Milliseconds since connection creation (MG_EV_OPEN)
-};
-
-#define MG_PROFILE_ALLOC_GRANULARITY 256 // Can save 32 items wih to realloc
-
-// Adding a profile item to the c->prof. Must be as fast as possible.
-// Reallocation of the c->prof iobuf is not desirable here, that's why we
-// pre-allocate c->prof with MG_PROFILE_ALLOC_GRANULARITY.
-// This macro just inits and copies 8 bytes, and calls mg_millis(),
-// which should be fast enough.
-#define MG_PROF_ADD(c, name_) \
- do { \
- struct mg_iobuf *io = &c->prof; \
- uint32_t inittime = ((struct mg_profitem *) io->buf)->timestamp; \
- struct mg_profitem item = {name_, (uint32_t) mg_millis() - inittime}; \
- mg_iobuf_add(io, io->len, &item, sizeof(item)); \
- } while (0)
-
-// Initialising profile for a new connection. Not time sensitive
-#define MG_PROF_INIT(c) \
- do { \
- struct mg_profitem first = {"init", (uint32_t) mg_millis()}; \
- mg_iobuf_init(&(c)->prof, 0, MG_PROFILE_ALLOC_GRANULARITY); \
- mg_iobuf_add(&c->prof, c->prof.len, &first, sizeof(first)); \
- } while (0)
-
-#define MG_PROF_FREE(c) mg_iobuf_free(&(c)->prof)
-
-// Dumping the profile. Not time sensitive
-#define MG_PROF_DUMP(c) \
- do { \
- struct mg_iobuf *io = &c->prof; \
- struct mg_profitem *p = (struct mg_profitem *) io->buf; \
- struct mg_profitem *e = &p[io->len / sizeof(*p)]; \
- MG_INFO(("%lu profile:", c->id)); \
- while (p < e) { \
- MG_INFO(("%5lx %s", (unsigned long) p->timestamp, p->name)); \
- p++; \
- } \
- } while (0)
-
-#else
-#define MG_PROF_INIT(c)
-#define MG_PROF_FREE(c)
-#define MG_PROF_ADD(c, name)
-#define MG_PROF_DUMP(c)
-#endif
-
-
-#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_CMSIS) && MG_ENABLE_DRIVER_CMSIS
-
-#include "Driver_ETH_MAC.h" // keep this include
-#include "Driver_ETH_PHY.h" // keep this include
-
-#endif
-
-
-struct mg_tcpip_driver_imxrt_data {
- // MDC clock divider. MDC clock is derived from IPS Bus clock (ipg_clk),
- // must not exceed 2.5MHz. Configuration for clock range 2.36~2.50 MHz
- // 37.5.1.8.2, Table 37-46 : f = ipg_clk / (2(mdc_cr + 1))
- // ipg_clk mdc_cr VALUE
- // --------------------------
- // -1 <-- TODO() tell driver to guess the value
- // 25 MHz 4
- // 33 MHz 6
- // 40 MHz 7
- // 50 MHz 9
- // 66 MHz 13
- int mdc_cr; // Valid values: -1 to 63
-
- uint8_t phy_addr; // PHY address
-};
-
-
-struct mg_tcpip_driver_same54_data {
- int mdc_cr;
-};
-
-
-struct mg_tcpip_driver_stm32f_data {
- // MDC clock divider. MDC clock is derived from HCLK, must not exceed 2.5MHz
- // HCLK range DIVIDER mdc_cr VALUE
- // -------------------------------------
- // -1 <-- tell driver to guess the value
- // 60-100 MHz HCLK/42 0
- // 100-150 MHz HCLK/62 1
- // 20-35 MHz HCLK/16 2
- // 35-60 MHz HCLK/26 3
- // 150-216 MHz HCLK/102 4 <-- value for Nucleo-F* on max speed
- // 216-310 MHz HCLK/124 5
- // 110, 111 Reserved
- int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
-
- uint8_t phy_addr; // PHY address
-};
-
-
-struct mg_tcpip_driver_stm32h_data {
- // MDC clock divider. MDC clock is derived from HCLK, must not exceed 2.5MHz
- // HCLK range DIVIDER mdc_cr VALUE
- // -------------------------------------
- // -1 <-- tell driver to guess the value
- // 60-100 MHz HCLK/42 0
- // 100-150 MHz HCLK/62 1
- // 20-35 MHz HCLK/16 2
- // 35-60 MHz HCLK/26 3
- // 150-250 MHz HCLK/102 4 <-- value for Nucleo-H* on max speed driven by HSI
- // 250-300 MHz HCLK/124 5 <-- value for Nucleo-H* on max speed driven by CSI
- // 110, 111 Reserved
- int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
-};
-
-
-struct mg_tcpip_driver_tm4c_data {
- // MDC clock divider. MDC clock is derived from SYSCLK, must not exceed 2.5MHz
- // SYSCLK range DIVIDER mdc_cr VALUE
- // -------------------------------------
- // -1 <-- tell driver to guess the value
- // 60-100 MHz SYSCLK/42 0
- // 100-150 MHz SYSCLK/62 1 <-- value for EK-TM4C129* on max speed
- // 20-35 MHz SYSCLK/16 2
- // 35-60 MHz SYSCLK/26 3
- // 0x4-0xF Reserved
- int mdc_cr; // Valid values: -1, 0, 1, 2, 3
-};
-
-#ifdef __cplusplus
-}
-#endif
-#endif // MONGOOSE_H
diff --git a/SmartEVSE-3/SmartEVSE-3/include/utils.h b/SmartEVSE-3/SmartEVSE-3/include/utils.h
deleted file mode 100644
index c30e34e..0000000
--- a/SmartEVSE-3/SmartEVSE-3/include/utils.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-; Project: Smart EVSE
-;
-;
-;
-; Permission is hereby granted, free of charge, to any person obtaining a copy
-; of this software and associated documentation files (the "Software"), to deal
-; in the Software without restriction, including without limitation the rights
-; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-; copies of the Software, and to permit persons to whom the Software is
-; furnished to do so, subject to the following conditions:
-;
-; The above copyright notice and this permission notice shall be included in
-; all copies or substantial portions of the Software.
-;
-; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-; THE SOFTWARE.
- */
-
-// This is a guard condition so that contents of this file are not included
-// more than once.
-#ifndef UTILS_H
-#define UTILS_H
-
-extern unsigned long pow_10[10];
-
-uint32_t MacId();
-unsigned char crc8(unsigned char *buf, unsigned char len);
-unsigned int crc16(unsigned char *buf, unsigned char len);
-void sprintfl(char *str, const char *Format, signed long Value, unsigned char Divisor, unsigned char Decimal);
-unsigned char triwave8(unsigned char in);
-unsigned char scale8(unsigned char i, unsigned char scale);
-unsigned char ease8InOutQuad(unsigned char i);
-
-#endif /* UTILS_H */
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/README b/SmartEVSE-3/SmartEVSE-3/lib/README
deleted file mode 100644
index 58415f5..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/README
+++ /dev/null
@@ -1,45 +0,0 @@
-This directory is intended for project specific (private) libraries.
-PlatformIO will compile them to static libraries and link into executable file.
-
-The source code of each library should be placed in a an own separate directory
-("lib/your_library_name/[here are source files]").
-
-For example, see a structure of the following two libraries `Foo` and `Bar`:
-
-|--lib
-| |
-| |--Bar
-| | |--docs
-| | |--examples
-| | |--src
-| | |- Bar.c
-| | |- Bar.h
-| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
-| |
-| |--Foo
-| | |- Foo.c
-| | |- Foo.h
-| |
-| |- README --> THIS FILE
-|
-|- platformio.ini
-|--src
- |- main.c
-
-and a contents of `src/main.c`:
-```
-#include
-#include
-
-int main (void)
-{
- ...
-}
-
-```
-
-PlatformIO Library Dependency Finder will find automatically dependent
-libraries scanning project source files.
-
-More information about PlatformIO Library Dependency Finder
-- https://docs.platformio.org/page/librarymanager/ldf.html
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.github/ISSUE_TEMPLATE/bug_report.md b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.github/ISSUE_TEMPLATE/bug_report.md
deleted file mode 100644
index daf40f6..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.github/ISSUE_TEMPLATE/bug_report.md
+++ /dev/null
@@ -1,29 +0,0 @@
----
-name: Bug report
-about: Create a report to help us improve
-
----
-
-**Describe the bug**
-A clear and concise description of what the bug is.
-
-**To Reproduce**
-Steps to reproduce the behavior:
-1.
-2.
-3.
-
-**Expected behavior**
-A clear and concise description of what you expected to happen.
-
-**Screenshots**
-If applicable, add screenshots to help explain your problem.
-
-**Arduino Information:**
- - OS: [e.g. Windows, MacOS, Linux]
- - IDE [e.g. Arduino IDE, Eclipse, VSCode]
- - IDE Version [e.g. 1.8.6]
- - Board [e.g ESP32]
-
-**Additional context**
-Add any other context about the problem here.
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.github/ISSUE_TEMPLATE/feature_request.md b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.github/ISSUE_TEMPLATE/feature_request.md
deleted file mode 100644
index 066b2d9..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.github/ISSUE_TEMPLATE/feature_request.md
+++ /dev/null
@@ -1,17 +0,0 @@
----
-name: Feature request
-about: Suggest an idea for this project
-
----
-
-**Is your feature request related to a problem? Please describe.**
-A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
-
-**Describe the solution you'd like**
-A clear and concise description of what you want to happen.
-
-**Describe alternatives you've considered**
-A clear and concise description of any alternative solutions or features you've considered.
-
-**Additional context**
-Add any other context or screenshots about the feature request here.
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.gitignore b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.gitignore
deleted file mode 100644
index e43b0f9..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-.DS_Store
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/LICENSE.txt b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/LICENSE.txt
deleted file mode 100755
index 6a981c5..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/LICENSE.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2018 Joao Lopes
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
\ No newline at end of file
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/README.md b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/README.md
deleted file mode 100755
index d524463..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/README.md
+++ /dev/null
@@ -1,737 +0,0 @@
-# RemoteDebug Library
-
-A library for Arduino to debug projects over WiFi, with web app or telnet client,
-with Print commands like Serial Monitor.
-
-
-
-[](https://www.ardu-badge.com/RemoteDebug)
-[](#releases)
-[](https://www.codacy.com/app/JoaoLopesF/RemoteDebug?utm_source=github.com&utm_medium=referral&utm_content=JoaoLopesF/RemoteDebug&utm_campaign=Badge_Grade)
-[](https://github.com/arduino)
-[](https://github.com/JoaoLopesF/RemoteDebug/blob/master/LICENSE.txt)
-[](#github)
-[](http://github.com/JoaoLopesF/RemoteDebug/issues)
-[](http://github.com/JoaoLopesF/RemoteDebug)
-
-
-
-
-## A library to remotely debug over a WiFi connection by telnet or web browser
-
-### RemoteDebug setup a TCP/IP server, that you connect to debugging, as an alternative to the serial connection
-
-## Contents
-
-- [About](#about)
-- [How it looks](#how-it-looks)
-- [Github](#github)
-- [News](#news)
-- [Benefits](#benefits)
-- [HTML5 web app](#web-app)
-- [Telnet client](#telnet)
-- [Wishlist](#wishlist)
-- [Install](#install)
-- [Using](#usage)
-- [Known issues](#known-issues)
-- [Releases](#releases)
-- [Thanks](#thanks)
-
-## About
-
-By default the Arduino only has as debug possibility via the Serial port.
-This has a few disadvantages:
-
-- requires a physical cable to the Arduino device (if the device is far away or in a remote location this is not easy)
-- debugging multiple Arduinos at the same time requires many serial ports and a lot of cables
-
-With the ESP8266 (NodeMCU) or ESP32 we now have network connectivity (WiFi) which can be used for streaming debugging information in real-time.
-
-This library is good for IoT projects, home automation, mobile robots (can debug it in moviment with a cable ?) or
-another WiFi projects.
-
-In fact, this library was born of a need to debug an IoT project of home automation.
-In this project there was a central module and three auxiliary modules,
-and these were far from each other. One was hard to reach, under the roof of the house.
-To debug this project, accompanying the exchange of messages in realtime,
-is impossible to do with traditional way, by USB cable.
-
-The MiP_ESP8266_Library and my ESP32 WiFi robot are example of projects that uses __RemoteDebug__.
-See it in: [MiP_ESP8266_Library](https://github.com/Tiogaplanet/MiP_ESP8266_Library) and [ESPlorer_v1](https://github.com/JoaoLopesF/ESPlorer_v1)
-
-__RemoteDebug__ is improved with client buffering (is last send is <= 10ms),
-to avoid mysterious delays of WiFi networking on ESP32 and ESP8266 boards
-
-Note: If your project not use WiFi, you can use my another library,
-the __[SerialDebug](https://github.com/JoaoLopesF/SerialDebug)__ library,
-this library works with any Arduino board.
-
-Note II: __RemoteDebug__ library is now only to Espressif boards, as ESP32 and ESP8266,
-If need for another WiFi boards, please add an issue about this
-and we will see if it is possible made the port for your board.
-
-## How it looks
-
-Image: In RemoteDebugApp (web app)
-
-
-
-Image: In telnet client
-
-
-
-Youtube (RemoteDebug v2):
-
-[](https://youtu.be/T4nxdsFUGgg)
-
-Youtube (3 telnet connections with RemoteDebug) v1:
-
-[](http://www.youtube.com/watch?v=lOo-MAD8gPo)
-
-## Github
-
-Contribute to this library development by creating an account on GitHub.
-
-Please give a star, if you find this library useful,
-this help an another people, discover it too.
-
-Please add an issue for problems or suggestion.
-
-## News
-
-- RemoteDebugApp Beta
-
- - Now have another repository, [RemoteDebugApp](https://github.com/JoaoLopesF/RemoteDebugApp)
- It is for local copy of web app in internet.
- It is updated with lastest version of web app,
- after it is publised in web server: [http://joaolopesf.net/remotedebugapp](http://joaolopesf.net/remotedebugapp/).
- Download it, for use when internet is offline.
- As it is a local copy, the app will check for new versions periodically.
-
- - An HTML5 web app to use for debugging in web browser, instead telnet client,
- that uses web socket to comunicate.
-
- - Now RemoteDebug v3 have a web socket server too,
- to support the RemoteDebugApp connection.
-
- - RemoteDebugApp is in beta,
- if you have any problems or suggestions, please add issue about this.
-
- - The telnet connection remains, to any want this,
- or to internet offline uses.
-
-- Version 2.1.1
-
- - Now __RemoteDebug__ have a code converter, for help you to convert your codes:
- to do it, please access the [RemoteDebugConverter](https://github.com/JoaoLopesF/RemoteDebugConverter)
-
-- Version 2.0.0
-
- - Now __RemoteDebug__ can have the same simple software debugger, that __SerialDebug__ library have.
- This is done, installing another library, the __[RemoteDebugger](https://github.com/JoaoLopesF/RemoteDebugger)__
- The __RemoteDebugger__ act as an add on to __RemoteDebug__.
- To support this addon, the changes in __RemoteDebug__, is minimum, just a few callbacks
- It is done to no add extra overhead to projects that no need an debugger.
- To more informations please access the __[RemoteDebugger](https://github.com/JoaoLopesF/RemoteDebugger)__ github repository.
-
- - Now __RemoteDebug__ have a new color system, using more colors, as done in __SerialDebugApp__
-
- Note: due the __RemoteDebug__ library, is migrate to Arduino 1.5 format, with folder "src",
- please delete and reinstall the library to avoid duplication of RemoteDebug sources files.
-
-- Version 1.5.*
-
- In 1.5.0 version, we have debug* and rdebug* macros (see below), that put automatically,
- the name of function that called, and core id (core id is only for ESP32)
-
-## Benefits
-
-__SerialDebug__ is better than Arduino default debugging by Serial.print commands:
-
-### This is more __optimized__
-
- Being or not debugging via USB cable,
- the Serial.print command allways is processed,
- waste CPU time on microcontroller.
- In other words, the debug commands are processed,
- with someone connected in the serial or not.
-
- With __RemoteDebug__, all debug output is processed only
- if exists anyone debugging via telnet or web app connection.
-
- And with the debug levels of resource, the volume displayed
- of messages are reduced for higher levels.
- For example, only process all messages,
- if the level is the lowest, the verbose,
-
- __RemoteDebug__ is otimized to reduce overheads,
- in CPU and memory and include client buffering feature.
-
-### Have __debug levels__
-
- During the development, we can put a lot of debug messages...
-
- But with __RemoteDebug__, we can put a level in each one.
-
- For all messages (except levels always (debugA) or error (debugE),
- the message only is processed and showed,
- if debug level is equal or higher than it level
-
- __RemoteDebug__ have 6 debug levels, in order of priority:
-
- Alway showed:
-
- __Error__: Critical errors
-
- __Always__: Important messages
-
- Another levels (showed if level is equal or higher that actual one):
-
- __Warning__: Error conditions but not critical
-
- __Info__: Information messages
-
- __Debug__: Extra information
-
- __Verbose__: More information than the usual
-
- So We can change the level to verbose, to see all messages.
- Or to debug to see only debug or higher level, etc.
-
- Is very good to reduce a quantity of messages that a project can generate,
- to help debugging.
-
-### It is __easy__ to migrate
-
- __RemoteDebug__ have a converter to help migrate your Arduino codes,
- from Serial.prints to this library.
-
- [RemoteDebugConverter](https://github.com/JoaoLopesF/RemoteDebugConverter)
-
- Even if you want to do this manually, it's very simple. Please see topic [Using](#usage) above.
-
-### Have __auto__ function name and simple __profiler__
-
- A simple debug:
-
- ```cpp
- debugV("* Run time: %02u:%02u:%02u (VERBOSE)", mRunHours, mRunMinutes, mRunSeconds);
- ````
-
- Can generate this output in serial monitor:
-
- (V p:3065 loop C1) * Run time: 00:41:23 (VERBOSE)
-
- Where: V: is the level
- p: is a profiler time, elased, between this and previous debug
- loop: is a function name, that executed this debug
- C1: is a core that executed this debug (and a function of this) (only for ESP32)
- The remaining is the message formatted (printf)
-
- For ESP32, the core id in each debug is very good to optimizer multicore programming.
-
-### Have __commands__ to execute from telnet or web app
-
- For example:
-
-- Show help (__?__)
-- Change the level of debug (__v__,__d__,__i__,__w__,__e__),
- to show less or more messages.
-- See memory (__m__)
-- Reset the board (__reset__)
-
- See about __RemoteDebug__ commands below.
-
- You can add your own commands, see the examples please
-
- If your project have __[RemoteDebugger](https://github.com/JoaoLopesF/RemoteDebugger)__ installed,
- have a new commands, e.g. call a function, see/change variables, ...
-
-### Have a simple __software debugger__
-
- Now __RemoteDebug__ (version >= 2.0.0), have an simple software debuggger,
- based in codes of SerialDebug library.
-
- This is another library, that act as an addon to __RemoteDebug__.
-
- Please acess the RemoteDebugger repository to more informations: __[RemoteDebugger](https://github.com/JoaoLopesF/RemoteDebugger)__
-
-### Ready for __production__ (release compiler)
-
- For release your device, just uncomment DEBUG_DISABLED in your project
- Done this, and no more debug processing.
- And better for DEBUG_DISABLED, __RemoteDebug__ have ZERO overhead,
- due is nothing of this is compiled.
-
-## Web app
-
-As SerialDebug, now RemoteDebug (v3) have an app,the RemoteDebugApp,
-to debug in web browser.
-
-This app is an HTM5 web app, with websocket to comunicate to Arduino board.
-For it, RemoteDebug v3 have a web socket server (can be disabled).
-It used a local copy of [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) library,
-due it not in Arduino Library manager.
-
-As a large web page on web server, the solution for Arduino is save it in a storage,
-like SPIFFS. But not have automatically updates new version in data saved this way,
-this SPIFFS data is good for a project but not for a library.
-
-Due it, this app not is stored and served by board,
-instead the app is in web: [http://joaolopesf.net/remotedebugapp](http://joaolopesf.net/remotedebugapp)
-Note: this not uses SSL (https), due web server socket on Arduino, not supports SSL (wss).
-But after page load, all traffic is in local network, no data is exposed on internet.
-
-The RemoteDebugApp is a modern HTML5 and needs a modern browsers to work.
-Internet Explorer 11 and Safari 10 are an examples that not supported.
-But you can use anothers, as Chrome, Edge, Firefox.
-
-The web app is in beta, please add an issue,
-for problems or suggestions.
-
-Now have another repository, [RemoteDebugApp](https://github.com/JoaoLopesF/RemoteDebugApp)
-It is for local copy of web app in internet.
-It is updated with lastest version of web app,
-after it is publised in web server: [http://joaolopesf.net/remotedebugapp](http://joaolopesf.net/remotedebugapp/).
-Download it, for use when internet is offline.
-As it is a local copy, the app will check for new versions periodically,
-for you can download a new version.
-
-The telnet remains work, for when want this,
-or for fails on web app.
-
-## Telnet
-
-Telnet is a standard way of remotely connecting to a server and
-is supported on all operating systems (Windows, Mac, Linux...).
-
-MacOSx and Linux have a native telnet client.
-
-For Windows, a typical telnet client is the __Putty__: [putty](https://www.putty.org/) .
-
-Have a good tool for mobiles: the __Fing__, please find it in your mobile store.
-Its show all devices in local network (WiFi), show ports opened and can execute the telnet client too (external App)
-
-__RemoteDebug__ sets-up a telnet server which is listening to any telnet client that wants to connect. After connection, logging is streamed to the telnet client.
-
-__RemoteDebug__ is very simple to use, after a few lines of initialization code, you can use the well-known "print" commands to stream your logging to the remote client.
-
-### Debug levels
-
-__RemoteDebug__ supports the filtering of logging based on __debug levels__:
-
-Only show for it actual debug level:
-
-- Verbose
-- Debug
-- Info
-- Warnings
-
-Note: These levels are in the order of most-logging -> least-logging.
-
-Or for always show (not depends of actual debug level):
-
-- Any
-- Errors
-
-Note: All debugs is processed and showed only if have a client connection.
-
-The telnet client or web app can set the debug level by typing a few simple commands.
-
-### Profiler
-
-__RemoteDebug__ includes a simple profiler. It can be enabled by the connected client (telnet or web app)
-or the Arduino code itself.
-
-When enabled, it shows the time between 2 debug statements, using different colors depending on the elapsed time.
-
-A typical example would be to insert logging just before and after a function after which you can see how much the is spent in the function.
-
-### Lightweight
-
-__RemoteDebug__ is designed to give minimal overhead (connected or not) and
-only process debugs,if there is a client (telnet or web app) connected.
-
-### Custom commands
-
-__RemoteDebug__ supports custom commands that can be entered in the client (telnet or web app).
- These trigger the execution of a custom function in the Arduino code. For example this can be used to send back a status on request of the client.
-
-### DISCLAIMER
-
-The current version of __RemoteDebug__ does not yet include any encrypted authentication,
-only plain text and is intended only for development, not use in production/release.
-
-Future versions, if is possible, will include a secure way for authentication and further testing to support production environments.
-
-## Wishlist
-
- - An app to RemoteDebug like SerialDebug have.
- - Http page to begin/stop the telnet server or websocket server.
- - Authentication as telnet support (kerberos, etc.) to support production environment
-
-## Install
-
-Just download or clone this repository.
-
-Or for Arduino IDE, you can use the library manager to install and update the library.
-
-For install help, please click on this: [](https://www.ardu-badge.com/RemoteDebug)
-
-
-
-For another IDE, or not using the library manager of Arduino IDE,
-I suggest you use a [Github Desktop](https://desktop.github.com/) app to clone,it help to keep updated.
-
-Please open the projects in example folder, to see it working.
-
-## Usage
-
-### includes
-
-```cpp
-#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
-```
-
-### instance
-
-RemoteDebug Debug;
-
-### setup
-
-In the setup function after WiFi initialization
-
-```cpp
-// Initialize the server (telnet or web socket) of RemoteDebug
-
-Debug.begin(HOST_NAME);
-
-// OR
-
-Debug.begin(HOST_NAME, startingDebugLevel);
-
-// Options
-
-Debug.setResetCmdEnabled(true); // Enable the reset command
-
-// Debug.showProfiler(true); // To show profiler - time between messages of Debug
-
-```
-
-Note: to enable the debugger, by RemoteDebugger, please acess this github repository:
-__[RemoteDebugger](https://github.com/JoaoLopesF/RemoteDebugger)__
-
-In the tail of loop function
-
-```cpp
-// Remote debug over WiFi
-
-Debug.handle();
-
-// Or
-
-debugHandle(); // Equal to SerialDebug
-
-```
-
-In any place of you code:
-
-```cpp
-#ifndef DEBUG_DISABLED
-if (Debug.isActive(Debug.)) {
- Debug.printf("bla bla bla: %d %s", number, str); // OR
- Debug.printf("bla bla bla: %d %s", number, str.c_str()); // Note: if type is String need c_str() // OR
- Debug.println("bla bla bla 2 ln");
- Debug.printf("float: %f\n", value); // Not works in ESP8266 :-(
- // Note: to show floats with printf (ESP8266 only),
- // you can use my ArduinoUtil library -> https://github.com/JoaoLopesF/ArduinoUtil
- Debug.printf("float: %s\n", Util.formatFloat(value, 0, 5).c_str());
-}
-#endif
-```
-
-Note: Using isActive, you need surround the code by DEBUG_DISABLE precompile condition,
- to avoid compile it for production/release
-
-Or short way (equal to SerialDebug) (prefered if only one debug at time):
-
-```cpp
-debugA("This is a any (always showed) - var %d", var);
-debugV("This is a verbose - var %d", var);
-debugD("This is a debug - var %d", var);
-debugI("This is a information - var %d", var);
-debugW("This is a warning - var %d", var);
-debugE("This is a error - var %d", var);
-
-debugV("This is a println");
-```
-
-Or if your project uses several Serial.print commands to generate a single debug message
-for example:
-
-```cpp
-Serial.print("a = ");
-Serial.print(a);
-Serial.print(" b = ");
-Serial.print(b);
-Serial.print(" c = ");
-Serial.println(c);
-```
-
-can be use rdebug* macros:
-
-```cpp
-rdebugV("a = ");
-rdebugV(a);
-rdebugV(" b = ");
-rdebugV(b);
-rdebugV(" c = ");
-rdebugVln(c);
-```
-
-Note: in future, I suggest that you migrate this to a single debug command:
-
-```cpp
-debugV(a = %d b = %d c = %d", a, b, c);
-```
-
-An example of use debug levels: (supposing the data is a lot of characters)
-
-```cpp
-if (Debug.isActive(Debug.VERBOSE)) { // Debug message long
- Debug.printf("routine: data received: %s\n", data.c_str()); // Note: if type is String need c_str()
-} else if (Debug.isActive(Debug.DEBUG)) { // Debug message short
- Debug.printf("routine: data received: %s ...\n", data.substring(0, 20).c_str()); // %.20s not working :-|
-}
-```
-
-Starting at version 1.5.0, debug macros (debug* and rdebug*), automatically put the name of function that called the macro,
-and core id (core id only for ESP32).
-
-So:
-
-```cpp
-void foo() {
-
- uint8_t var = 1;
- debugV("this is a debug - var %u", var);
-}
-
-```
-
- It will show in client (telnet or web app):
-
- (V p:^0000ms) (foo)(C1) this is a debug - var 1
-
- Where:
-
- V -> verbose
- p -> profiler time
- (foo) -> this is a function name that calls the debug macro
- (C1) -> It is running it Core 1 (only for ESP32)
-
-An example of use debug with serial enabled
-
- Useful to see messages if setup or
- in cause the ESP8266/ESP32 is rebooting (client connection stop before received all messages)
- Only for this purposes I suggest it
-
-```cpp
-// Setup after Debug.begin
-
-Debug.setSerialEnabled(true); // All messages too send to serial too, and can be see in serial monitor
-```
-
-For reduce overheads RemoteDebug is disconnect the client (telnet or web app), if it not active.
-
- - Please press enter or any key if you need keep the connection
- - The default is 5 minutes (You can change it in RemoteDebug.h)
- - You can use mDNS to register each node with different name, it helps to connect without know the IP.
-
-Please not forget to use if clause with Debug.isActive (if not using debug macros)
-
- ---> This is very important to reduce overheads and work of debug levels
-
-Please see the samples, basic or advanced, to learn how to use
-
-In advanced sample, I used WifiManager library, ArduinoOTA and mDNS, please see it.
-
-## Releases
-
-### 3.0.5 - 2019-03-23
-
- - Ajustment on debugA macro, thanks @jetpax and @cmidgley to add this issue.
-
-### 3.0.4 - 2019-03-19
-
- - All public configurations (#defines) have moved to RemoteDebugCfg.h, to facilitate changes for anybody.
- - Changed examples, with warnings on change any #define in project,
- with workarounds if it not work. (thanks to @22MarioZ for added this issue)
-
-### 3.0.3 - 2019-03-18
-
- - Adjustments if web socket is disabled
-
-### 3.0.2 - 2019-03-16
-
- - Adjustments in examples, added one for debugger
-
-### 3.0.1 - 2019-03-13
-
- - Adjustments in silente mode
- - Commands from RemoteDebugApp now is treated
- - Adjusts to RemoteDebugger support connection by web sockets
-
-### 3.0.0 - 2019-03-10
-
- - If not disabled, add a web socket server to comunicate with RemoteDebugApp (HTML5 web app)
- - The standard telnet still working, to debug with internet offline
- - Ajustment on debugA macro, thanks @jetpax to add this issue
-
-### 2.1.2 - 2019-03-08
-
- - Add empty rprint* macros, if debug is disabled
-
-### 2.1.1 - 2019-03-06
-
- - Create option DEBUG_DISABLE_AUTO_FUNC
- - Create macros to be used for code converter: rprint and rprintln
- RemoteDebug now have an code converters to help migrate codes
-
-### 2.1.0 - 2019-03-04
-
- - Create precompiler DEBUG_DISABLED to compile for production/release,
- equal that have in SerialDebug
- - Adjustments in examples
-
-### 2.0.1 - 2019-03-01
-
- - Adjustments for the debugger: it still disable until dbg command, equal to SerialDebug
- - The callback will to be called before print debug messages now
- - And only if debugger is enabled in RemoteDebugger (command dbg)
- - Changed handle debugger logic
-
-### 2.0.0 - 2019-02-28
-
- - Added support to RemoteDebug addon library: the RemoteDebugger, an simple software debugger, based on SerialDebug
- - New color system
-
-### 1.5.9 - 2019-02-18
-
- - Bug -> sometimes the command is process twice
- - Workaround -> check time
-
-### 1.5.8 - 2019-02-08
-
- - New macros to compatibility with SerialDebug (can use RemoteDebug or SerialDebug) thanks to @phrxmd
-
-### 1.5.7 - 2018-11-03
-
- - Fixed bug for MAX_TIME_INACTIVE, thanks to @achuchev to add this issue
-
-### 1.5.6 - 2018-10-19
-
- - Adjustments based on pull request from @jeroenst (to allow serial output with telnet password and setPassword method)
-
-### 1.5.5 - 2018-10-19
-
- - Serial output is now not allowed if telnet password is enabled
- - Few adjustments
-
-### 1.5.4 - 2018-10-05
-
- - Few adjustment in write logic
-
-### 1.5.3 - 2018-09-04
-
- - Serial output adjustments (due bug in password logic)
-
-### 1.5.2
-
- - Correct rdebug macro (thanks @stritti)
-
-### 1.5.1 - 2018-08-28
-
- - New silent mode (command s)
-
-### 1.5.0 - 2018-08=26
-
- - Auto function name and ESP32 core id for rdebug* macros
- - begin method have a option for port number
- - Few adjustments
- - Added new rdebug?ln to put auto new line
-
-### 1.4.0 - 2018-08-18
-
- - Simple text password request feature (disabled by default)
-
- Notes:
- It is very simple feature, only text, no cryptography,
- and the password is echoed in screen (I not discovery yet how disable it)
-
- telnet use advanced authentication (kerberos, etc.)
- Such as now RemoteDebug is not for production (releases),
- this kind of authentication will not be done now.
-
-### 1.3.1 - 2018-08-18
-
- - Adjustments in precompiler macros
-
-### 1.3.0 - 2018-08-17
-
- - Bug in write with latest ESP8266 SDK
- - Port number can be modified in project Arduino (.ino file)
- - Few adjustments as ESP32 includes
-
-### 1.2.2
-
- - Adjustments, as avoid ESP32 include errors
- - Telnet port of server can be modified by project
- Just put it in your .ino, before the include:
-
-### 1.2.0
-
- - Shortcuts and client buffering to avoid mysterious delay of ESP networking
-
-### 1.1.0
-
- - Adjustments and now runs in Esp32 too.
-
-### 1.0.0
-
- - Adjustments and improvements from Beta versions.
-
- New features:
-
- - Filter
- - Colors
- - Support to Windows telnet client
-
-### 0.9
-
- - First Beta
-
-## Known issues
-
- - Sometimes (rarely) the connection over telnet becomes very slow.
- Especially right after uploading firmware.
- Reset command in telnet connection or turn off/on can be resolve it.
- But I need find why it occurs
-
-## Thanks
-
- First thanks a lot for Igrr for bring to us the Arduino ESP8266 and to Espressif to Arduino ESP32
-
- Thanks to Links2004 for a good web server socket, used for web app connection.
-
- For the logo: thanks to a freepik and pngtree sites for free icons that have in logo
-
- Resources:
-
- - Example of TelnetServer code in http://www.rudiswiki.de/wiki9/WiFiTelnetServer
- - arduinoWebSockets library in https://github.com/Links2004/arduinoWebSockets
-
-## End of README
-
-Hit counter on this file, starting at 2019-03-03:
-[](http://hits.dwyl.io/JoaoLopesF/RemoteDebug)
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/examples/RemoteDebug_Advanced/RemoteDebug_Advanced.ino b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/examples/RemoteDebug_Advanced/RemoteDebug_Advanced.ino
deleted file mode 100644
index c96f1f7..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/examples/RemoteDebug_Advanced/RemoteDebug_Advanced.ino
+++ /dev/null
@@ -1,634 +0,0 @@
-////////
-// Library: Remote debug - debug over WiFi - for Esp8266 (NodeMCU) or ESP32
-// Author : Joao Lopes
-// File : RemoteDebug_Advanced.ino
-// Notes :
-//
-// Attention: This library is only for help development. Please not use this in production
-//
-// Sample to show how to use advanced features of Arduino and RemoteDebug library
-//
-// Example of use:
-//
-//#ifndef DEBUG_DISABLED
-// if (Debug.isActive(Debug.)) { // <--- This is very important to reduce overheads and work of debug levels
-// Debug.printf("bla bla bla: %d %s\n", number, str);
-// Debug.println("bla bla bla");
-// }
-//#endif
-//
-// Or short way (prefered if only one debug at time)
-//
-// debugA("This is a any (always showed) - var %d", var);
-//
-// debugV("This is a verbose - var %d", var);
-// debugD("This is a debug - var %d", var);
-// debugI("This is a information - var %d", var);
-// debugW("This is a warning - var %d", var);
-// debugE("This is a error - var %d", var);
-//
-// debugV("This is println");
-//
-///////
-
-////// Defines
-
-// Host name (please change it)
-
-#define HOST_NAME "remotedebug"
-
-// Board especific libraries
-
-#if defined ESP8266 || defined ESP32
-
-// Use mDNS ? (comment this do disable it)
-
-#define USE_MDNS true
-
-// Arduino OTA (uncomment this to enable)
-
-//#define USE_ARDUINO_OTA true
-
-#else
-
-// RemoteDebug library is now only to Espressif boards,
-// as ESP32 and ESP82266,
-// If need for another WiFi boards,
-// please add an issue about this
-// and we will see if it is possible made the port for your board.
-// access: https://github.com/JoaoLopesF/RemoteDebug/issues
-
-#error "The board must be ESP8266 or ESP32"
-
-#endif // ESP
-
-// Web server (uncomment this to need this)
-
-//#define WEB_SERVER_ENABLED true
-
-////// Includes
-
-#if defined ESP8266
-
-// Includes of ESP8266
-
-#include
-
-#ifdef USE_MDNS
-#include
-#include
-#endif
-
-#ifdef WEB_SERVER_ENABLED
-#include
-#endif
-
-#elif defined ESP32
-
-// Includes of ESP32
-
-#include
-
-#ifdef USE_MDNS
-#include
-#include "ESPmDNS.h"
-#endif
-
-#ifdef WEB_SERVER_ENABLED
-#include
-#endif
-
-#else
-
-#error "For now, RemoteDebug support only boards Espressif, as ESP8266 and ESP32"
-
-#endif // ESP
-
-// Arduino OTA
-
-#ifdef USE_ARDUINO_OTA
-#include
-#endif
-
-// HTTP Web server
-
-#ifdef WEB_SERVER_ENABLED
-
-#if defined ESP8266
-
-ESP8266WebServer HTTPServer(80);
-
-#elif defined ESP32
-
-WebServer HTTPServer(80);
-
-#endif
-
-#endif // WEB_SERVER_ENABLED
-
-///// Remote debug over WiFi - not recommended for production/release, only for development
-
-// Options for RemoteDebug of this project
-
-// Attention: read this, before you change any option
-//
-// If yot changed it and not works, the compiler is using catching old compiled files
-// To workaround this:
-// - If have a clean project option in IDE (as Eclipse/Platformio), do it
-// - or force compiler to compiler all (changing any configuration of board)
-// - or to this change globally in RemoteDebugCfg.h (on library directory)
-// - And upload again
-//
-// thanks to @22MarioZ for added this issue
-
-// Disable all debug ?
-// Important to compile for prodution/release
-// Disable all debug ? Good to release builds (production)
-// as nothing of RemoteDebug is compiled, zero overhead :-)
-// Uncomment the line below, to do it:
-//#define DEBUG_DISABLED true
-
-// Disable te auto function feature of RemoteDebug
-// Good if your code already have func name on debug messages
-// Uncomment the line below, to do it:
-//#define DEBUG_DISABLE_AUTO_FUNC true
-
-// Disable Websocket? This is used with RemoteDebugApp connection
-// Uncomment the line below, to do it:
-//#define WEBSOCKET_DISABLED true
-
-#ifndef WEBSOCKET_DISABLED // Only if Web socket enabled (RemoteDebugApp)
-// If enabled, you can change the port here (8232 is default)
-// Uncomment the line below, to do it:
-//#define WEBSOCKET_PORT 8232
-
-// Internally, the RemoteDebug uses a local copy of the arduinoWebSockets library (https://github.com/Links2004/arduinoWebSockets)
-// Due it not in Arduino Library Manager
-// If your project already use this library,
-// Uncomment the line below, to do it:
-//#define USE_LIB_WEBSOCKET true
-#endif
-
-// Include libraries
-
-#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
-
-#ifndef DEBUG_DISABLED // Only if debug is not disabled (for production/release)
-
-// Instance of RemoteDebug
-
-RemoteDebug Debug;
-
-#endif
-
-// WiFi credentials
-// Note: if commented, is used the smartConfig
-// That allow to it in mobile app
-// See more details in http://www.iotsharing.com/2017/05/how-to-use-smartconfig-on-esp32.html
-
-//#define WIFI_SSID "..." // your network SSID (name)
-//#define WIFI_PASS "..." // your network key
-
-/////// Variables
-
-// Time
-
-uint32_t mTimeToSec = 0;
-uint32_t mTimeSeconds = 0;
-
-////// Setup
-
-void setup() {
-
- // Initialize the Serial (use only in setup codes)
-
- Serial.begin(230400);
-
- // Buildin led
-
-#ifdef LED_BUILTIN
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
-#endif
-
- // Connect WiFi
-
- connectWiFi();
-
- // Host name of WiFi
-
-#ifdef ESP8266
- WiFi.hostname(HOST_NAME);
-#endif
-
-#ifdef USE_ARDUINO_OTA
- // Update over air (OTA)
-
- initializeOTA();
-#endif
-
- // Register host name in mDNS
-
-#if defined USE_MDNS && defined HOST_NAME
-
- if (MDNS.begin(HOST_NAME)) {
- Serial.print("* MDNS responder started. Hostname -> ");
- Serial.println(HOST_NAME);
- }
-
- // Register the services
-
-#ifdef WEB_SERVER_ENABLED
- MDNS.addService("http", "tcp", 80); // Web server
-#endif
-
-#ifndef DEBUG_DISABLED
- MDNS.addService("telnet", "tcp", 23); // Telnet server of RemoteDebug, register as telnet
-#endif
-
-#endif // MDNS
-
- // HTTP web server
-
-#ifdef WEB_SERVER_ENABLED
- HTTPServer.on("/", handleRoot);
-
- HTTPServer.onNotFound(handleNotFound);
-
- HTTPServer.begin();
-
- Serial.println("* HTTP server started");
-#endif
-
-#ifndef DEBUG_DISABLED // Only for development
-
- // Initialize RemoteDebug
-
- Debug.begin(HOST_NAME); // Initialize the WiFi server
-
- //Debug.setPassword("r3m0t0."); // Password for WiFi client connection (telnet or webapp) ?
-
- Debug.setResetCmdEnabled(true); // Enable the reset command
-
- Debug.showProfiler(true); // Profiler (Good to measure times, to optimize codes)
-
- Debug.showColors(true); // Colors
-
- // Debug.setSerialEnabled(true); // if you wants serial echo - only recommended if ESP is plugged in USB
-
- // Project commands
-
- String helpCmd = "bench1 - Benchmark 1\n";
- helpCmd.concat("bench2 - Benchmark 2");
-
- Debug.setHelpProjectsCmds(helpCmd);
- Debug.setCallBackProjectCmds(&processCmdRemoteDebug);
-
- // End of setup - show IP
-
- Serial.println("* Arduino RemoteDebug Library");
- Serial.println("*");
- Serial.print("* WiFI connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.println("*");
- Serial.println("* Please use the telnet client (telnet for Mac/Unix or putty and others for Windows)");
- Serial.println("* or the RemoteDebugApp (in browser: http://joaolopesf.net/remotedebugapp)");
- Serial.println("*");
- Serial.println("* This sample will send messages of debug in all levels.");
- Serial.println("*");
- Serial.println("* Please try change debug level in client (telnet or web app), to see how it works");
- Serial.println("*");
-
-#endif
-
-}
-
-void loop() {
-
-#ifndef DEBUG_DISABLED
- // Time of begin of this loop
- uint32_t timeBeginLoop = millis();
-#endif
-
-
- // Each second
-
- if (millis() >= mTimeToSec) {
-
- // Time
-
- mTimeToSec = millis() + 1000;
-
- mTimeSeconds++;
-
- // Blink the led
-
-#ifdef LED_BUILTIN
- digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
-#endif
-
- // Debug the time (verbose level)
-
- debugV("* Time: %u seconds (VERBOSE)", mTimeSeconds);
-
- if (mTimeSeconds % 5 == 0) { // Each 5 seconds
-
- // Debug levels
-
- debugV("* This is a message of debug level VERBOSE");
- debugD("* This is a message of debug level DEBUG");
- debugI("* This is a message of debug level INFO");
- debugW("* This is a message of debug level WARNING");
- debugE("* This is a message of debug level ERROR");
-
-
- // RemoteDebug isActive? Use this RemoteDebug sintaxe if you need process anything only for debug
- // It is good to avoid overheads (this is only use that is suggest to use isActive)
- // Note this need be surrounded by DEBUG_DISABLED precompiler condition to not compile for production/release
-
-#ifndef DEBUG_DISABLED
-
- if (Debug.isActive(Debug.VERBOSE)) {
-
- debugV("Calling a foo function");
- debugV("At time of %d sec.\n", mTimeSeconds);
-
- // Call a function
-
- foo();
- }
-#endif
-
- }
- }
-
- ////// Services on Wifi
-
-#ifdef USE_ARDUINO_OTA
- // Update over air (OTA)
-
- ArduinoOTA.handle();
-#endif
-
-#ifdef WEB_SERVER_ENABLED
- // Web server
-
- HTTPServer.handleClient();
-#endif
-
-#ifndef DEBUG_DISABLED
- // RemoteDebug handle (for WiFi connections)
-
- Debug.handle();
-#endif
-
- // Give a time for ESP
-
- yield();
-
-#ifndef DEBUG_DISABLED
- // Show a debug - warning if time of these loop is over 50 (info) or 100 ms (warning)
-
- uint32_t time = (millis() - timeBeginLoop);
-
- if (time > 100) {
- debugI("* Time elapsed for the loop: %u ms.", time);
- } else if (time > 200) {
- debugW("* Time elapsed for the loop: %u ms.", time);
- }
-#endif
-
-}
-
-
-// Function example to show a new auto function name of debug* macros
-
-void foo() {
-
- uint8_t var = 1;
-
- debugV("this is a debug - var %u", var);
- debugV("This is a println");
-}
-
-#ifndef DEBUG_DISABLED
-
-// Process commands from RemoteDebug
-
-void processCmdRemoteDebug() {
-
- String lastCmd = Debug.getLastCommand();
-
- if (lastCmd == "bench1") {
-
- // Benchmark 1 - Printf
-
- debugA("* Benchmark 1 - one Printf");
-
-
- uint32_t timeBegin = millis();
- uint8_t times = 50;
-
- for (uint8_t i = 1; i <= times; i++) {
- debugA("%u - 1234567890 - AAAA", i);
-
- }
-
- debugA("* Time elapsed for %u printf: %ld ms.\n", times,
- (millis() - timeBegin));
-
- } else if (lastCmd == "bench2") {
-
- // Benchmark 2 - Print/println
-
- debugA("* Benchmark 2 - Print/Println");
-
- uint32_t timeBegin = millis();
- uint8_t times = 50;
-
- for (uint8_t i = 1; i <= times; i++) {
- if (Debug.isActive(Debug.ANY)) {
- Debug.print(i);
- Debug.print(" - 1234567890");
- Debug.println(" - AAAA");
- }
- }
-
- debugA("* Time elapsed for %u printf: %ld ms.\n", times,
- (millis() - timeBegin));
- }
-}
-#endif
-
-////// WiFi
-
-void connectWiFi() {
-
- ////// Connect WiFi
-
-#ifdef EM_DEPURACAO
- Serial.println("*** connectWiFi: begin conection ...");
-#endif
-
-#ifdef ESP32
- // ESP32 // TODO: is really necessary ?
- WiFi.enableSTA(true);
- delay(100);
-#endif
-
- // Connect with SSID and password stored
-
-#ifndef WIFI_SSID
- WiFi.begin();
-#else
- WiFi.begin(WIFI_SSID, WIFI_PASS);
-#endif
-
- // Wait connection
-
- uint32_t timeout = millis() + 20000; // Time out
-
- while (WiFi.status() != WL_CONNECTED && millis() < timeout) {
- delay(250);
- Serial.print(".");
- }
-
- // Not connected yet?
-
- if (WiFi.status() != WL_CONNECTED) {
-
-#ifndef WIFI_SSID
- // SmartConfig
-
- WiFi.beginSmartConfig();
-
- // Wait for SmartConfig packet from mobile
-
- Serial.println("connectWiFi: Waiting for SmartConfig.");
-
- while (!WiFi.smartConfigDone()) {
- delay(500);
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.println("connectWiFi: SmartConfig received.");
-
- // Wait for WiFi to connect to AP
-
- Serial.println("connectWiFi: Waiting for WiFi");
-
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
-#else
- Serial.println("Not possible connect to WiFi, rebooting");
- ESP.restart();
-#endif
- }
-
- // End
-
- Serial.println("");
- Serial.print("connectWiFi: connect a ");
- Serial.println(WiFi.SSID());
- Serial.print("IP: ");
- Serial.println(WiFi.localIP().toString());
-
-}
-
-#ifdef USE_ARDUINO_OTA
-
-// Initialize o Arduino OTA
-
-void initializeOTA() {
-
- // TODO: option to authentication (password)
-
-#if defined ESP8266
-
- ArduinoOTA.onStart([]() {
- Serial.println("* OTA: Start");
- });
- ArduinoOTA.onEnd([]() {
- Serial.println("\n*OTA: End");
- });
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("*OTA: Progress: %u%%\r", (progress / (total / 100)));
- });
- ArduinoOTA.onError([](ota_error_t error) {
- Serial.printf("*OTA: Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- });
-
-#elif defined ESP32
-
- // ArduinoOTA
-
- ArduinoOTA.onStart([]() {
- String type;
- if (ArduinoOTA.getCommand() == U_FLASH)
- type = "sketch";
- else // U_SPIFFS
- type = "filesystem";
- Serial.println("Start updating " + type);
- }).onEnd([]() {
- Serial.println("\nEnd");
- }).onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
- }).onError([](ota_error_t error) {
- Serial.printf("Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- });
-
-#endif
-
- // Begin
-
- ArduinoOTA.begin();
-
-}
-
-#endif
-
-#ifdef WEB_SERVER_ENABLED
-
-/////////// Handles
-
- void handleRoot() {
-
- // Root web page
-
- HTTPServer.send(200, "text/plain", "hello from esp - RemoteDebug Sample!");
- }
-
- void handleNotFound(){
-
- // Page not Found
-
- String message = "File Not Found\n\n";
- message.concat("URI: ");
- message.concat(HTTPServer.uri());
- message.concat("\nMethod: ");
- message.concat((HTTPServer.method() == HTTP_GET)?"GET":"POST");
- message.concat("\nArguments: ");
- message.concat(HTTPServer.args());
- message.concat("\n");
- for (uint8_t i=0; i)) { // <--- This is very important to reduce overheads and work of debug levels
-// Debug.printf("bla bla bla: %d %s\n", number, str);
-// Debug.println("bla bla bla");
-// }
-//#endif
-//
-// Or short way (prefered if only one debug at time)
-//
-// debugA("This is a any (always showed) - var %d", var);
-//
-// debugV("This is a verbose - var %d", var);
-// debugD("This is a debug - var %d", var);
-// debugI("This is a information - var %d", var);
-// debugW("This is a warning - var %d", var);
-// debugE("This is a error - var %d", var);
-//
-// debugV("This is println");
-//
-//
-///////
-
-////// Defines
-
-// Host name (please change it)
-
-#define HOST_NAME "remotedebug"
-
-// Board especific libraries
-
-#if defined ESP8266 || defined ESP32
-
-// Use mDNS ? (comment this do disable it)
-
-#define USE_MDNS true
-
-// Arduino OTA (uncomment this to enable)
-
-//#define USE_ARDUINO_OTA true
-
-#else
-
-// RemoteDebug library is now only to Espressif boards,
-// as ESP32 and ESP82266,
-// If need for another WiFi boards,
-// please add an issue about this
-// and we will see if it is possible made the port for your board.
-// access: https://github.com/JoaoLopesF/RemoteDebug/issues
-
-#error "The board must be ESP8266 or ESP32"
-
-#endif // ESP
-
-//////// Libraries
-
-#if defined ESP8266
-
-// Includes of ESP8266
-
-#include
-
-#ifdef USE_MDNS
-#include
-#include
-#endif
-
-#elif defined ESP32
-
-// Includes of ESP32
-
-#include
-
-#ifdef USE_MDNS
-#include
-#include "ESPmDNS.h"
-#endif
-
-#endif // ESP
-
-// Remote debug over WiFi - not recommended for production, only for development
-
-#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
-
-RemoteDebug Debug;
-
-// SSID and password
-
-const char* ssid = "........";
-const char* password = "........";
-
-// Time
-
-uint32_t mLastTime = 0;
-uint32_t mTimeSeconds = 0;
-
-////// Setup
-
-void setup() {
-
- // Initialize the Serial (use only in setup codes)
-
- Serial.begin(230400);
-
- // Buildin led of ESP
-
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
-
- // Debug
-
- Serial.println("**** Setup: initializing ...");
-
- // WiFi connection
-
- WiFi.begin(ssid, password);
- Serial.println("");
-
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
-
- // Register host name in WiFi and mDNS
-
- String hostNameWifi = HOST_NAME;
- hostNameWifi.concat(".local");
-
-#ifdef ESP8266 // Only for it
- WiFi.hostname(hostNameWifi);
-#endif
-
-#ifdef USE_MDNS // Use the MDNS ?
-
- if (MDNS.begin(HOST_NAME)) {
- Serial.print("* MDNS responder started. Hostname -> ");
- Serial.println(HOST_NAME);
- }
-
- MDNS.addService("telnet", "tcp", 23);
-
-#endif
-
- // Initialize RemoteDebug
-
- Debug.begin(HOST_NAME); // Initialize the WiFi server
-
- Debug.setResetCmdEnabled(true); // Enable the reset command
-
- Debug.showProfiler(true); // Profiler (Good to measure times, to optimize codes)
- Debug.showColors(true); // Colors
-
- // End off setup
-
- Serial.println("* Arduino RemoteDebug Library");
- Serial.println("*");
- Serial.print("* WiFI connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.println("*");
- Serial.println("* Please use the telnet client (telnet for Mac/Unix or putty and others for Windows)");
- Serial.println("* or the RemoteDebugApp (in browser: http://joaolopesf.net/remotedebugapp)");
- Serial.println("*");
- Serial.println("* This sample will send messages of debug in all levels.");
- Serial.println("*");
- Serial.println("* Please try change debug level in client (telnet or web app), to see how it works");
- Serial.println("*");
-
-}
-
-void loop()
-{
- // Each second
-
- if ((millis() - mLastTime) >= 1000) {
-
- // Time
-
- mLastTime = millis();
-
- mTimeSeconds++;
-
- // Blink the led
-
- digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
-
- // Debug the time (verbose level)
-
- debugV("* Time: %u seconds (VERBOSE)", mTimeSeconds);
-
- if (mTimeSeconds % 5 == 0) { // Each 5 seconds
-
- // Debug levels
-
- debugV("* This is a message of debug level VERBOSE");
- debugD("* This is a message of debug level DEBUG");
- debugI("* This is a message of debug level INFO");
- debugW("* This is a message of debug level WARNING");
- debugE("* This is a message of debug level ERROR");
-
- // Call a function
-
- foo();
- }
- }
-
- // RemoteDebug handle
-
- Debug.handle();
-
- // Give a time for ESP
-
- yield();
-
-}
-
-// Function example to show a new auto function name of debug* macros
-
-void foo() {
-
- uint8_t var = 1;
-
- debugV("this is a debug - var %u", var);
- debugV("This is a println");
-}
-
-/////////// End
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/examples/RemoteDebug_Debugger/RemoteDebug_Debugger.ino b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/examples/RemoteDebug_Debugger/RemoteDebug_Debugger.ino
deleted file mode 100644
index 88b52a9..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/examples/RemoteDebug_Debugger/RemoteDebug_Debugger.ino
+++ /dev/null
@@ -1,893 +0,0 @@
-////////
-// Library: Remote debug - debug over WiFi - for Esp8266 (NodeMCU) or ESP32
-// Author : Joao Lopes
-// File : RemoteDebugger.ino
-// Notes :
-//
-// Attention: This library is only for help development. Please not use this in production
-//
-// This example use the RemoteDebugger library: ao addon to Remotedebug with an simple software debug, based on SerialDebug library
-// Attention: this library must be installed too
-// Please open github repo to informations: //https://github.com/JoaoLopesF/RemoteDebugger
-//
-// Example of use:
-//
-//#ifndef DEBUG_DISABLED
-// if (Debug.isActive(Debug.)) { // <--- This is very important to reduce overheads and work of debug levels
-// Debug.printf("bla bla bla: %d %s\n", number, str);
-// Debug.println("bla bla bla");
-// }
-//#endif
-//
-// Or short way (prefered if only one debug at time)
-//
-// debugA("This is a any (always showed) - var %d", var);
-//
-// debugV("This is a verbose - var %d", var);
-// debugD("This is a debug - var %d", var);
-// debugI("This is a information - var %d", var);
-// debugW("This is a warning - var %d", var);
-// debugE("This is a error - var %d", var);
-//
-// debugV("This is println");
-//
-///////
-
-////// Defines
-
-// Host name (please change it)
-
-#define HOST_NAME "remotedebug"
-
-// Board especific libraries
-
-#if defined ESP8266 || defined ESP32
-
-// Use mDNS ? (comment this do disable it)
-
-#define USE_MDNS true
-
-// Arduino OTA (uncomment this to enable)
-
-//#define USE_ARDUINO_OTA true
-
-#else
-
-// RemoteDebug library is now only to Espressif boards,
-// as ESP32 and ESP82266,
-// If need for another WiFi boards,
-// please add an issue about this
-// and we will see if it is possible made the port for your board.
-// access: https://github.com/JoaoLopesF/RemoteDebug/issues
-
-#error "The board must be ESP8266 or ESP32"
-
-#endif // ESP
-
-// Web server (uncomment this to need this)
-
-//#define WEB_SERVER_ENABLED true
-
-////// Includes
-
-#if defined ESP8266
-
-// Includes of ESP8266
-
-#include
-
-#ifdef USE_MDNS
-#include
-#include
-#endif
-
-#ifdef WEB_SERVER_ENABLED
-#include
-#endif
-
-#elif defined ESP32
-
-// Includes of ESP32
-
-#include
-
-#ifdef USE_MDNS
-#include
-#include "ESPmDNS.h"
-#endif
-
-#ifdef WEB_SERVER_ENABLED
-#include
-#endif
-
-#else
-
-#error "Now RemoteDebug support only boards Espressif, as ESP8266 and ESP32"
-
-#endif // ESP
-
-// Arduino OTA
-
-#ifdef USE_ARDUINO_OTA
-#include
-#endif
-
-// HTTP Web server
-
-#ifdef WEB_SERVER_ENABLED
-
-#if defined ESP8266
-
-ESP8266WebServer HTTPServer(80);
-
-#elif defined ESP32
-
-WebServer HTTPServer(80);
-
-#endif
-
-#endif // WEB_SERVER_ENABLED
-
-// Remote debug over WiFi - not recommended for production/release, only for development
-
-// Options for RemoteDebug of this project
-
-// Attention: read this, before you change any option
-//
-// If yot changed it and not works, the compiler is using catching old compiled files
-// To workaround this:
-// - If have a clean project option (as Eclipse/Platformio), do it
-// - or force compiler to compiler all (changing any configuration of board)
-// - or to this change globally in RemoteDebugCfg.h (on library directory)
-// - And upload again
-//
-// thanks to @22MarioZ for added this issue
-
-// Disable all debug ?
-// Important to compile for prodution/release
-// Disable all debug ? Good to release builds (production)
-// as nothing of RemoteDebug is compiled, zero overhead :-)
-// Uncomment the line below, to do it:
-//#define DEBUG_DISABLED true
-
-// Disable te auto function feature of RemoteDebug
-// Good if your code already have func name on debug messages
-// Uncomment the line below, to do it:
-//#define DEBUG_DISABLE_AUTO_FUNC true
-
-// Disable Websocket? This is used with RemoteDebugApp connection
-// Uncomment the line below, to do it:
-//#define WEBSOCKET_DISABLED true
-
-#ifndef WEBSOCKET_DISABLED // Only if Web socket enabled (RemoteDebugApp)
-// If enabled, you can change the port here (8232 is default)
-// Uncomment the line below, to do it:
-//#define WEBSOCKET_PORT 8232
-
-// Internally, the RemoteDebug uses a local copy of the arduinoWebSockets library (https://github.com/Links2004/arduinoWebSockets)
-// Due it not in Arduino Library Manager
-// If your project already use this library,
-// Uncomment the line below, to do it:
-//#define USE_LIB_WEBSOCKET true
-#endif
-
-
-#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
-
-#ifndef DEBUG_DISABLED // Only if debug is not disabled (for production/release)
-
-// RemoteDebug addon library: RemoteDebugger, an Simple software debugger - based on SerialDebug Library
-
-#include "RemoteDebugger.h" //https://github.com/JoaoLopesF/RemoteDebugger
-
-// Instance of RemoteDebug
-
-RemoteDebug Debug;
-
-#endif
-
-// WiFi credentials
-// Note: if commented, is used the smartConfig
-// That allow to it in mobile app
-// See more details in http://www.iotsharing.com/2017/05/how-to-use-smartconfig-on-esp32.html
-
-//#define WIFI_SSID "..." // your network SSID (name)
-//#define WIFI_PASS "..." // your network key
-
-/////// Variables
-
-// Time
-
-uint32_t mTimeToSec = 0;
-
-uint8_t mRunSeconds = 0;
-uint8_t mRunMinutes = 0;
-uint8_t mRunHours = 0;
-
-// Globals for example of debugger
-
-boolean mBoolean = false;
-char mChar = 'X';
-byte mByte = 'Y';
-int mInt = 1;
-unsigned int mUInt = 2;
-long mLong = 3;
-unsigned long mULong = 4;
-float mFloat = 5.0f;
-double mDouble = 6.0;
-
-String mString = "This is a string";
-String mStringLarge = "This is a large stringggggggggggggggggggggggggggggggggggggggggggggg";
-
-char mCharArray[] = "This is a char array";
-char mCharArrayLarge[] = "This is a large char arrayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
-
-int mIntArray[5] = {1 ,2 ,3, 4, 5};
-
-//const char mCharArrayConst[] = "This is const";
-
-////// Setup
-
-void setup() {
-
- // Initialize the Serial (use only in setup codes)
-
- Serial.begin(230400);
-
- // Buildin led
-
-#ifdef LED_BUILTIN
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
-#endif
-
- // Connect WiFi
-
- connectWiFi();
-
- // Host name of WiFi
-
-#ifdef ESP8266
- WiFi.hostname(HOST_NAME);
-#endif
-
-#ifdef USE_ARDUINO_OTA
- // Update over air (OTA)
-
- initializeOTA();
-#endif
-
- // Register host name in mDNS
-
-#if defined USE_MDNS && defined HOST_NAME
-
- if (MDNS.begin(HOST_NAME)) {
- Serial.print("* MDNS responder started. Hostname -> ");
- Serial.println(HOST_NAME);
- }
-
- // Register the services
-
-#ifdef WEB_SERVER_ENABLED
- MDNS.addService("http", "tcp", 80); // Web server
-#endif
-
-#ifndef DEBUG_DISABLED
- MDNS.addService("telnet", "tcp", 23);// Telnet server RemoteDebug
-#endif
-
-#endif // MDNS
-
- // HTTP web server
-
-#ifdef WEB_SERVER_ENABLED
- HTTPServer.on("/", handleRoot);
-
- HTTPServer.onNotFound(handleNotFound);
-
- HTTPServer.begin();
-
- Serial.println("* HTTP server started");
-#endif
-
-#ifndef DEBUG_DISABLED // Only for development
-
- // Initialize RemoteDebug
-
- Debug.begin(HOST_NAME); // Initialize the WiFi server
-
- //Debug.setPassword("r3m0t0."); // Password on telnet connection ?
-
- Debug.setResetCmdEnabled(true); // Enable the reset command
-
- Debug.showProfiler(true); // Profiler (Good to measure times, to optimize codes)
-
- Debug.showColors(true); // Colors
-
- // Debug.setSerialEnabled(true); // if you wants serial echo - only recommended if ESP is plugged in USB
-
- // Project commands
-
- String helpCmd = "bench1 - Benchmark 1\n";
- helpCmd.concat("bench2 - Benchmark 2");
-
- Debug.setHelpProjectsCmds(helpCmd);
- Debug.setCallBackProjectCmds(&processCmdRemoteDebug);
-
- // Init the simple software debugger, based on SerialDebug library
-
-#ifndef DEBUG_DISABLE_DEBUGGER
-
- Debug.initDebugger(debugGetDebuggerEnabled, debugHandleDebugger, debugGetHelpDebugger, debugProcessCmdDebugger); // Set the callbacks
-
- debugInitDebugger(&Debug); // Init the debugger
-
- // Add Functions and global variables to RemoteDebuggger
-
- // Notes: descriptions is optionals
-
- // Add functions that can called from SerialDebug
-
- if (debugAddFunctionVoid("benchInt", &benchInt) >= 0) {
- debugSetLastFunctionDescription("To run a benchmark of integers");
- }
- if (debugAddFunctionVoid("benchFloat", &benchFloat) >= 0) {
- debugSetLastFunctionDescription("To run a benchmark of float");
- }
- if (debugAddFunctionVoid("benchGpio", &benchGpio) >= 0) {
- debugSetLastFunctionDescription("To run a benchmark of Gpio operations");
- }
- if (debugAddFunctionVoid("benchAll", &benchAll) >= 0) {
- debugSetLastFunctionDescription("To run all benchmarks");
- }
-
- if (debugAddFunctionStr("funcArgStr", &funcArgStr) >= 0) {
- debugSetLastFunctionDescription("To run with String arg");
- }
- if (debugAddFunctionChar("funcArgChar", &funcArgChar) >= 0) {
- debugSetLastFunctionDescription("To run with Character arg");
- }
- if (debugAddFunctionInt("funcArgInt", &funcArgInt) >= 0) {
- debugSetLastFunctionDescription("To run with Integer arg");
- }
-
- // Add global variables that can showed/changed from SerialDebug
- // Note: Only global, if pass local for SerialDebug, can be dangerous
-
- if (debugAddGlobalUInt8_t("mRunSeconds", &mRunSeconds) >= 0) {
- debugSetLastGlobalDescription("Seconds of run time");
- }
- if (debugAddGlobalUInt8_t("mRunMinutes", &mRunMinutes) >= 0) {
- debugSetLastGlobalDescription("Minutes of run time");
- }
- if (debugAddGlobalUInt8_t("mRunHours", &mRunHours) >= 0) {
- debugSetLastGlobalDescription("Hours of run time");
- }
-
- // Note: easy way, no descriptions ....
-
- debugAddGlobalBoolean("mBoolean", &mBoolean);
- debugAddGlobalChar("mChar", &mChar);
- debugAddGlobalByte("mByte", &mByte);
- debugAddGlobalInt("mInt", &mInt);
- debugAddGlobalUInt("mUInt", &mUInt);
- debugAddGlobalLong("mLong", &mLong);
- debugAddGlobalULong("mULong", &mULong);
- debugAddGlobalFloat("mFloat", &mFloat);
- debugAddGlobalDouble("mDouble", &mDouble);
-
- debugAddGlobalString("mString", &mString);
-
- // Note: For char arrays, not use the '&'
-
- debugAddGlobalCharArray("mCharArray", mCharArray);
-
- // Note, here inform to show only 20 characteres of this string or char array
-
- debugAddGlobalString("mStringLarge", &mStringLarge, 20);
-
- debugAddGlobalCharArray("mCharArrayLarge",
- mCharArrayLarge, 20);
-
- // For arrays, need add for each item (not use loop for it, due the name can not by a variable)
- // Notes: Is good added arrays in last order, to help see another variables
- // In next versions, we can have a helper to do it in one command
-
- debugAddGlobalInt("mIntArray[0]", &mIntArray[0]);
- debugAddGlobalInt("mIntArray[1]", &mIntArray[1]);
- debugAddGlobalInt("mIntArray[2]", &mIntArray[2]);
- debugAddGlobalInt("mIntArray[3]", &mIntArray[3]);
- debugAddGlobalInt("mIntArray[4]", &mIntArray[4]);
-
- // Add watches for some global variables
- // Note: watches can be added/changed in serial monitor too
-
- // Watch -> mBoolean when changed (put 0 on value)
-
- debugAddWatchBoolean("mBoolean", DEBUG_WATCH_CHANGED, 0);
-
- // Watch -> mRunSeconds == 10
-
- debugAddWatchUInt8_t("mRunSeconds", DEBUG_WATCH_EQUAL, 10);
-
- // Watch -> mRunMinutes > 3
-
- debugAddWatchUInt8_t("mRunMinutes", DEBUG_WATCH_GREAT, 3);
-
- // Watch -> mRunMinutes == mRunSeconds (just for test)
-
- debugAddWatchCross("mRunMinutes", DEBUG_WATCH_EQUAL, "mRunSeconds");
-
-#endif
-
- // End of setup - show IP
-
- Serial.println("* Arduino RemoteDebug Library");
- Serial.println("*");
- Serial.print("* WiFI connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.println("*");
- Serial.println("* Please use the telnet client (telnet for Mac/Unix or putty and others for Windows)");
- Serial.println("* or the RemoteDebugApp (in browser: http://joaolopesf.net/remotedebugapp)");
- Serial.println("*");
- Serial.println("* This sample will send messages of debug in all levels.");
- Serial.println("*");
- Serial.println("* Please try change debug level in client (telnet or web app), to see how it works");
- Serial.println("*");
-
-#endif
-
-}
-
-void loop() {
-
-#ifndef DEBUG_DISABLED
- // Time of begin of this loop
- uint32_t timeBeginLoop = millis();
-#endif
-
- // Each second
-
- if (millis() >= mTimeToSec) {
-
- // Time
-
- mTimeToSec = millis() + 1000;
-
- // Count run time (just a test - for real suggest the TimeLib and NTP, if board have WiFi)
-
- mRunSeconds++;
-
- if (mRunSeconds == 60) {
- mRunMinutes++;
- mRunSeconds = 0;
- }
- if (mRunMinutes == 60) {
- mRunHours++;
- mRunMinutes = 0;
- }
- if (mRunHours == 24) {
- mRunHours = 0;
- }
-
- // Blink the led
-
-#ifdef LED_BUILTIN
- digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
-#endif
-
- // Debug the time (verbose level)
-
- debugV("* Time: %u seconds (VERBOSE)", mRunSeconds);
-
- if (mRunSeconds % 5 == 0) { // Each 5 seconds
-
- // Debug levels
-
- debugV("* This is a message of debug level VERBOSE");
- debugD("* This is a message of debug level DEBUG");
- debugI("* This is a message of debug level INFO");
- debugW("* This is a message of debug level WARNING");
- debugE("* This is a message of debug level ERROR");
-
-
- // RemoteDebug isActive? Use this RemoteDebug sintaxe if you need process anything only for debug
- // It is good to avoid overheads (this is only use that is suggest to use isActive)
- // Note this need be surrounded by DEBUG_DISABLED precompiler condition to not compile for production/release
-
-#ifndef DEBUG_DISABLED
-
- if (Debug.isActive(Debug.VERBOSE)) {
-
- Debug.println("Calling a foo function");
- Debug.printf("At time of %d sec.\n", mRunSeconds);
-
- // Call a function
-
- foo();
- }
-#endif
-
- }
- }
-
- ////// Services on Wifi
-
-#ifdef USE_ARDUINO_OTA
- // Update over air (OTA)
-
- ArduinoOTA.handle();
-#endif
-
-#ifdef WEB_SERVER_ENABLED
- // Web server
-
- HTTPServer.handleClient();
-#endif
-
-#ifndef DEBUG_DISABLED
- // Remote debug over telnet
-
- Debug.handle();
-#endif
-
- // Give a time for ESP
-
- yield();
-
-#ifndef DEBUG_DISABLED
- // Show a debug - warning if time of these loop is over 50 (info) or 100 ms (warning)
-
- uint32_t time = (millis() - timeBeginLoop);
-
- if (time > 100) {
- debugI("* Time elapsed for the loop: %u ms.", time);
- } else if (time > 200) {
- debugW("* Time elapsed for the loop: %u ms.", time);
- }
-#endif
-
-}
-
-
-// Function example to show a new auto function name of debug* macros
-
-void foo() {
-
- uint8_t var = 1;
-
- debugV("this is a debug - var %u", var);
- debugV("This is a println");
-}
-
-#ifndef DEBUG_DISABLED
-
-// Process commands from RemoteDebug
-
-void processCmdRemoteDebug() {
-
- String lastCmd = Debug.getLastCommand();
-
- if (lastCmd == "bench1") {
-
- // Benchmark 1 - Printf
-
- debugA("* Benchmark 1 - one Printf");
-
-
- uint32_t timeBegin = millis();
- uint8_t times = 50;
-
- for (uint8_t i = 1; i <= times; i++) {
- debugA("%u - 1234567890 - AAAA", i);
-
- }
-
- debugA("* Time elapsed for %u printf: %ld ms.\n", times,
- (millis() - timeBegin));
-
- } else if (lastCmd == "bench2") {
-
- // Benchmark 2 - Print/println
-
- debugA("* Benchmark 2 - Print/Println");
-
- uint32_t timeBegin = millis();
- uint8_t times = 50;
-
- for (uint8_t i = 1; i <= times; i++) {
- if (Debug.isActive(Debug.ANY)) {
- Debug.print(i);
- Debug.print(" - 1234567890");
- Debug.println(" - AAAA");
- }
- }
-
- debugA("* Time elapsed for %u printf: %ld ms.\n", times,
- (millis() - timeBegin));
- }
-}
-#endif
-
-////// Benchmarks - simple
-
-// Note: how it as called by SerialDebug, must be return type void and no args
-// Note: Flash F variables is not used during the tests, due it is slow to use in loops
-
-#define BENCHMARK_EXECS 10000
-
-// Simple benckmark of integers
-
-void benchInt() {
-
- int test = 0;
-
- for (int i = 0; i < BENCHMARK_EXECS; i++) {
-
- // Some integer operations
-
- test++;
- test += 2;
- test -= 2;
- test *= 2;
- test /= 2;
- }
-
- // Note: Debug always is used here
-
- debugA("*** Benchmark of integers. %u exec.", BENCHMARK_EXECS);
-
-}
-
-// Simple benckmark of floats
-
-void benchFloat() {
-
- float test = 0;
-
- for (int i = 0; i < BENCHMARK_EXECS; i++) {
-
- // Some float operations
-
- test++;
- test += 2;
- test -= 2;
- test *= 2;
- test /= 2;
- }
-
- // Note: Debug always is used here
-
- debugA("*** Benchmark of floats, %u exec.", BENCHMARK_EXECS);
-
-}
-
-// Simple benckmark of GPIO
-
-void benchGpio() {
-
-// const int execs = (BENCHMARK_EXECS / 10); // Reduce it
- const int execs = BENCHMARK_EXECS;
-
- for (int i = 0; i < execs; i++) {
-
- // Some GPIO operations
-
- digitalWrite(LED_BUILTIN, HIGH);
- digitalRead(LED_BUILTIN);
- digitalWrite(LED_BUILTIN, LOW);
-
- analogRead(A0);
- analogRead(A0);
- analogRead(A0);
-
- }
-
- // Note: Debug always is used here
-
- debugA("*** Benchmark of GPIO. %u exec.", execs);
-
-}
-
-// Run all benchmarks
-
-void benchAll() {
-
- benchInt();
- benchFloat();
- benchGpio();
-
- // Note: Debug always is used here
-
- debugA("*** All Benchmark done.");
-
-}
-
-// Example functions with argument (only 1) to call from serial monitor
-// Note others types is not yet available in this version of SerialDebug
-
-void funcArgStr (String str) {
-
- debugA("*** called with arg.: %s", str.c_str());
-}
-void funcArgChar (char character) {
-
- debugA("*** called with arg.: %c", character);
-}
-void funcArgInt (int number) {
-
- debugA("*** called with arg.: %d", number);
-}
-
-////// WiFi
-
-void connectWiFi() {
-
- ////// Connect WiFi
-
-#ifdef EM_DEPURACAO
- Serial.println("*** connectWiFi: begin conection ...");
-#endif
-
-#ifdef ESP32
- // ESP32 // TODO: is really necessary ?
- WiFi.enableSTA(true);
- delay(100);
-#endif
-
- // Connect with SSID and password stored
-
-#ifndef WIFI_SSID
- WiFi.begin();
-#else
- WiFi.begin(WIFI_SSID, WIFI_PASS);
-#endif
-
- // Wait connection
-
- uint32_t timeout = millis() + 20000; // Time out
-
- while (WiFi.status() != WL_CONNECTED && millis() < timeout) {
- delay(250);
- Serial.print(".");
- }
-
- // Not connected yet?
-
- if (WiFi.status() != WL_CONNECTED) {
-
-#ifndef WIFI_SSID
- // SmartConfig
-
- WiFi.beginSmartConfig();
-
- // Wait for SmartConfig packet from mobile
-
- Serial.println("connectWiFi: Waiting for SmartConfig.");
-
- while (!WiFi.smartConfigDone()) {
- delay(500);
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.println("connectWiFi: SmartConfig received.");
-
- // Wait for WiFi to connect to AP
-
- Serial.println("connectWiFi: Waiting for WiFi");
-
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
-#else
- Serial.println("Not possible connect to WiFi, rebooting");
- ESP.restart();
-#endif
- }
-
- // End
-
- Serial.println("");
- Serial.print("connectWiFi: connect a ");
- Serial.println(WiFi.SSID());
- Serial.print("IP: ");
- Serial.println(WiFi.localIP().toString());
-
-}
-
-#ifdef USE_ARDUINO_OTA
-
-// Initialize o Arduino OTA
-
-void initializeOTA() {
-
- // TODO: option to authentication (password)
-
-#if defined ESP8266
-
- ArduinoOTA.onStart([]() {
- Serial.println("* OTA: Start");
- });
- ArduinoOTA.onEnd([]() {
- Serial.println("\n*OTA: End");
- });
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("*OTA: Progress: %u%%\r", (progress / (total / 100)));
- });
- ArduinoOTA.onError([](ota_error_t error) {
- Serial.printf("*OTA: Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- });
-
-#elif defined ESP32
-
- // ArduinoOTA
-
- ArduinoOTA.onStart([]() {
- String type;
- if (ArduinoOTA.getCommand() == U_FLASH)
- type = "sketch";
- else // U_SPIFFS
- type = "filesystem";
- Serial.println("Start updating " + type);
- }).onEnd([]() {
- Serial.println("\nEnd");
- }).onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
- }).onError([](ota_error_t error) {
- Serial.printf("Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- });
-
-#endif
-
- // Begin
-
- ArduinoOTA.begin();
-
-}
-
-#endif
-
-#ifdef WEB_SERVER_ENABLED
-
-/////////// Handles
-
- void handleRoot() {
-
- // Root web page
-
- HTTPServer.send(200, "text/plain", "hello from esp - RemoteDebug Sample!");
- }
-
- void handleNotFound(){
-
- // Page not Found
-
- String message = "File Not Found\n\n";
- message.concat("URI: ");
- message.concat(HTTPServer.uri());
- message.concat("\nMethod: ");
- message.concat((HTTPServer.method() == HTTP_GET)?"GET":"POST");
- message.concat("\nArguments: ");
- message.concat(HTTPServer.args());
- message.concat("\n");
- for (uint8_t i=0; i sometimes the processCommand is executed twice. Workaround> check time
- * 1.5.8 2019-02-08 New macros to compatibility with SerialDebug (can use RemoteDebug or SerialDebug) thanks to @phrxmd
- * 1.5.7 2018-11-03 Fixed bug for MAX_TIME_INACTIVE
- * 1.5.6 2018-10-19 Adjustments based on pull request from @jeroenst (to allow serial output with telnet password and setPassword method)
- * 1.5.5 ? Serial output is now not allowed if telnet password is enabled
- * 1.5.4 ? Serial output not depending of telnet password (thanks @jeroenst for suggestion)
- * 1.5.3 ? Serial output adjustments (due bug in password logic)
- * 1.5.2 ? Correct rdebug macro (thanks @stritti)
- * 1.5.1 ? New command: silence
- * Added new rdebug?ln to put auto new line
- * Auto function and core if (for ESP32) in rdebug macros
- * Class destructor implemented
- * 1.5.0 ? Port can be pass in begin method (thanks @PjotrekSE for suggestion)
- * Few adjustments
- * this kind of authentication will not be done now.
- * Such as RemoteDebug now is not for production releases,
- * Note: telnet use advanced authentication (kerberos, etc.)
- * 1.4.0 ? A simple text password request, if enabled (thanks @jeroenst for suggestion)
- * 1.3.1 ? Retired # from VARGS precompiler macros
- * Few adjustments as ESP32 includes
- * Port number can be modified in project Arduino (.ino file)
- * 1.3.0 Aug 2018 Bug in write with latest ESP8266 SDK
- * 1.2.1 ? Adjusts to not cause error in Arduino
- * 1.2.0 ? Added shortcuts and buffering to avoid delays
- * 1.1.1 2017-11-24 Added support for the pass through of commands, and default debug levels thanks B. Harville
- * 1.1.0 Aug 2017 Support to ESP32
- * New commands for CPU frequencies
- * New level> profiler and auto-profiler
- * 1.0.1 Aug 2017 New connection logic
- * 1.0.0 Jan 2017 First RC
- * 0.9.1 Oct 2016 Beta 2
- * 0.9.0 Aug 2016 Beta 1
- *
- */
-
-/*
- * TODO: - Page HTML for begin/stop Telnet server
- * - Add support to another Arduino WiFi boards (if have demand on it)
- */
-
-///// RemoteDebug configuration
-
-#include "RemoteDebugCfg.h"
-
-///// Debug disable for compile to production/release ?
-///// as nothing of RemotedDebug is compiled, zero overhead :-)
-
-#ifndef DEBUG_DISABLED
-
-///// Defines
-
-#define VERSION "3.0.5"
-
-///// Includes
-
-#include "stdint.h"
-
-#if defined(ESP8266)
-// ESP8266 SDK
-extern "C" {
-bool system_update_cpu_freq(uint8_t freq);
-}
-#endif
-
-#include "Arduino.h"
-#include "Print.h"
-
-#ifdef SERIAL_DEBUG_H
-// Cannot used with SerialDebug at same time
-#error "RemoteDebug cannot be used with SerialDebug"
-#endif
-
-// ESP8266 or ESP32 ?
-
-#if defined(ESP8266)
-
-#include
-
-#elif defined(ESP32)
-
-#include
-
-#else
-
-#error Only for ESP8266 or ESP32
-
-#endif
-
-#include "RemoteDebug.h" // This library
-
-#ifdef ALPHA_VERSION // In test, not good yet
-#include "telnet.h"
-#endif
-
-// Support to websocket connection with RemoteDebugApp
-// Note: you must install the arduinoWebSocket library before
-
-#ifndef WEBSOCKET_DISABLED // Only if Web socket enabled (RemoteDebugApp)
-#include "RemoteDebugWS.h"
-#endif
-
-// Internal print macros for send messages to client
-
-#ifndef WEBSOCKET_DISABLED // Only if Web socket enabled (RemoteDebugApp)
-
-#define debugPrintf(fmt, ...) { \
- if (_connected) TelnetClient.printf(fmt, ##__VA_ARGS__);\
- else if (_connectedWS) DebugWS.printf(fmt, ##__VA_ARGS__);\
-}
-#define debugPrintln(str) { \
- if (_connected) TelnetClient.println(str);\
- else if (_connectedWS) DebugWS.println(str);\
-}
-#define debugPrint(str) { \
- if (_connected) TelnetClient.print(str);\
- else if (_connectedWS) DebugWS.print(str);\
-}
-
-#else // With web socket too
-
-#define debugPrintf(fmt, ...) { \
- if (_connected) TelnetClient.printf(fmt, ##__VA_ARGS__);\
-}
-#define debugPrintln(str) { \
- if (_connected) TelnetClient.println(str);\
-}
-#define debugPrint(str) { \
- if (_connected) TelnetClient.print(str);\
-}
-
-#endif
-
-// Internal debug macro - recommended stay disable
-
-#define D(fmt, ...) // Without this
-//#define D(fmt, ...) Serial.printf("rd: " fmt "\n", ##__VA_ARGS__) // Serial debug
-
-////// Variables
-
-// Instance
-
-static RemoteDebug* _instance;
-
-// WiFi server (telnet)
-
-static WiFiServer TelnetServer(TELNET_PORT); // @suppress("Abstract class cannot be instantiated")
-static WiFiClient TelnetClient; // @suppress("Abstract class cannot be instantiated")
-
-// Support to websocket connection with RemoteDebugApp
-
-#ifndef WEBSOCKET_DISABLED
-
-// Instance of RemoteDebugWS
-
-static RemoteDebugWS DebugWS; // @suppress("Abstract class cannot be instantiated")
-
-static boolean _connectedWS = false; // Connected :
-
-// Callbacks
-
-class MyRemoteDebugCallbacks: public RemoteDebugWSCallbacks {
- void onConnect() {
- // Web socket (app) connected
-
- D("rd: onconnect");
-
- _connectedWS = true;
-
- // Is telnet connected -> disconnect it, due reduce overheads
-
- if (_instance->isConnected()) {
-
- _instance->disconnect(true);
- }
-
- // Call same routine that telnet
-
- _instance->onConnection(true);
- }
- void onDisconnect() {
- // Web socket (app) disconnected
-
- D("rd: ondisconnect");
-
- _connectedWS = false;
- }
- void onReceive(const char *message) {
- // Receive a message
-
- D("rd: onreceive");
-
- _instance->wsOnReceive(message);
- }
-};
-
-#endif // WEBSOCKET_DISABLED
-
-////// Methods / routines
-
-// Constructor
-
-RemoteDebug::RemoteDebug() {
-
- // Save the instance
-
- _instance = this;
-}
-
-// Initialize the telnet server
-
-bool RemoteDebug::begin(String hostName, uint8_t startingDebugLevel) {
- return begin(hostName, TELNET_PORT, startingDebugLevel);
-}
-
-bool RemoteDebug::begin(String hostName, uint16_t port, uint8_t startingDebugLevel) {
-
- // Initialize server telnet
-
- if (port != TELNET_PORT) { // Bug: not more can use begin(port)..
- return false;
- }
-
- TelnetServer.begin();
- TelnetServer.setNoDelay(true);
-
-#ifndef WEBSOCKET_DISABLED
- // Initialize web socket (for RemoteDebugApp)
-
- DebugWS.begin(new MyRemoteDebugCallbacks());
-
-#endif
-
- // Reserve space to buffer of print writes
-
- _bufferPrint.reserve(BUFFER_PRINT);
-
-#ifdef CLIENT_BUFFERING
- // Reserve space to buffer of send
-
- _bufferPrint.reserve(MAX_SIZE_SEND);
-
-#endif
-
- // Host name of this device
-
- _hostName = hostName;
-
- // Debug level
-
- _clientDebugLevel = startingDebugLevel;
- _lastDebugLevel = startingDebugLevel;
-
- return true;
-}
-
-#ifdef DEBUGGER_ENABLED
-// Simple software debugger - based on SerialDebug Library
-void RemoteDebug::initDebugger(boolean (*callbackEnabled)(), void (*callbackHandle)(const boolean), String (*callbackGetHelp)(), void (*callbackProcessCmd)()) {
-
- // Init callbacks for the debugger
-
- _callbackDbgEnabled = callbackEnabled;
- _callbackDbgHandle = callbackHandle;
- _callbackDbgHelp = callbackGetHelp;
- _callbackDbgProcessCmd = callbackProcessCmd;
-
-}
-
-WiFiClient* RemoteDebug::getTelnetClient() {
-
- return &TelnetClient;
-}
-
-#endif
-
-// Set the password for telnet - thanks @jeroenst for suggest thist method
-
-void RemoteDebug::setPassword(String password) {
-
- _password = password;
-
-}
-
-// Destructor
-
-RemoteDebug::~RemoteDebug() {
-
- // Flush
-
- if (TelnetClient && TelnetClient.connected()) {
- TelnetClient.flush();
- }
-
- // Stop
-
- stop();
-}
-
-// Stop the server
-
-void RemoteDebug::stop() {
-
- // Stop Client
-
- if (TelnetClient && TelnetClient.connected()) {
- TelnetClient.stop();
- }
-
- // Stop server
-
- TelnetServer.stop();
-
-#ifndef WEBSOCKET_DISABLED
- // Stop web socket (RemoteDebugApp)
-
- DebugWS.stop(); // stop the websocket server
-#endif
-
-}
-
-// Handle the connection (in begin of loop in sketch)
-// TODO: optimize when loop not have a large delay
-
-void RemoteDebug::handle() {
-
-#ifdef ALPHA_VERSION // In test, not good yet
- static uint32_t lastTime = millis();
-#endif
-
-#ifdef DEBUGGER_ENABLED
- static uint32_t dbgTimeHandle = millis(); // To avoid call the handler desnecessary
- static boolean dbgLastConnected = false; // Last is connected ?
-#endif
-
- // Silence timeout ?
-
- if (_silence && _silenceTimeout > 0 && millis() >= _silenceTimeout) {
-
- // Get out of silence mode
-
- silence(false, true);
- }
-
- // Debug level is profiler -> set the level before
-
- if (_clientDebugLevel == PROFILER) {
- if (millis() > _levelProfilerDisable) {
- _clientDebugLevel = _levelBeforeProfiler;
- debugPrintln("* Debug level profile inactive now");
- }
- }
-
-#ifdef ALPHA_VERSION // In test, not good yet
-
- // Automatic change to profiler level if time between handles is greater than n millis
-
- if (_autoLevelProfiler > 0 && _clientDebugLevel != PROFILER) {
-
- uint32_t diff = (millis() - lastTime);
-
- if (diff >= _autoLevelProfiler) {
- _levelBeforeProfiler = _clientDebugLevel;
- _clientDebugLevel = PROFILER;
- _levelProfilerDisable = 1000; // Disable it at 1 sec
-
- debugPrintf("* Debug level profile active now - time between handels: %u\r\n", diff);
- }
-
- lastTime = millis();
- }
-#endif
-
- // look for Client connect trial
-
- if (TelnetServer.hasClient()) {
-
- // Old connection logic
-
-// if (!TelnetClient || !TelnetClient.connected()) {
-//
-// if (TelnetClient) { // Close the last connect - only one supported
-//
-// TelnetClient.stop();
-//
-// }
-
- // New connection logic - 10/08/17
-
- if (TelnetClient && TelnetClient.connected()) {
-
- // Verify if the IP is same than actual conection
-
- WiFiClient newClient; // @suppress("Abstract class cannot be instantiated")
- newClient = TelnetServer.available();
- String ip = newClient.remoteIP().toString();
-
- if (ip == TelnetClient.remoteIP().toString()) {
-
- // Reconnect
-
- TelnetClient.stop();
- TelnetClient = newClient;
-
- } else {
-
- // Disconnect (not allow more than one connection)
-
- newClient.stop();
-
- return;
-
- }
-
- } else {
-
- // New TCP client
-
- TelnetClient = TelnetServer.available();
-
- // Password request ? - 18/07/18
-
- if (_password != "") {
-
- #ifdef ALPHA_VERSION // In test, not good yet
- // Send command to telnet client to not do local echos
- // Experimental code !
-
- sendTelnetCommand(TELNET_WONT, TELNET_ECHO);
- #endif
-
- }
- }
-
- if (!TelnetClient) { // No client yet ???
- return;
- }
-
- // Set client
-
- TelnetClient.setNoDelay(true); // More faster
- TelnetClient.flush(); // clear input buffer, else you get strange characters
-
- // Empty buffer
-
- delay(100);
-
- while (TelnetClient.available()) {
- TelnetClient.read();
- }
-
- // Connection event
-
- onConnection(true);
-
- }
-
- // Is client connected ? (to reduce overhead in active)
-
- _connected = (TelnetClient && TelnetClient.connected());
-
- // Get command over telnet
-
- if (_connected) {
-
- char last = ' '; // To avoid process two times the "\r\n"
-
- while (TelnetClient.available()) { // get data from Client
-
- // Get character
-
- char character = TelnetClient.read();
-
- // Newline (CR or LF) - once one time if (\r\n) - 26/07/17
-
- if (isCRLF(character) == true) {
-
- if (isCRLF(last) == false) {
-
- // Process the command
-
- if (_command.length() > 0) {
-
- _lastCommand = _command; // Store the last command
- processCommand();
-
- }
- }
-
- _command = ""; // Init it for next command
-
- } else if (isPrintable(character)) {
-
- // Concat
-
- _command.concat(character);
-
- }
-
- // Last char
-
- last = character;
- }
-
- }
-
- // Client connected ?
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- boolean connected = (_connected || _connectedWS);
-#else // By telnet
- boolean connected = _connected;
-#endif
-
- if (connected) {
-
-#ifdef CLIENT_BUFFERING
- // Client buffering - send data in intervals to avoid delays or if its is too big
-
- if ((millis() - _lastTimeSend) >= DELAY_TO_SEND || _sizeBufferSend >= MAX_SIZE_SEND) {
- debugPrint(_bufferSend);
- _bufferSend = "";
- _sizeBufferSend = 0;
- _lastTimeSend = millis();
- }
-#endif
-
-#ifdef MAX_TIME_INACTIVE
-#if MAX_TIME_INACTIVE > 0
-
- // Inactivity - close connection if not received commands from user in telnet
- // For reduce overheads
-
- uint32_t maxTime = MAX_TIME_INACTIVE; // Normal
-
- if (_password != "" && !_passwordOk) { // Request password - 18/08/08
- maxTime = 60000; // One minute to password
- }
-
- if ((millis() - _lastTimeCommand) > maxTime) {
-
- debugPrintln("* Closing session by inactivity");
-
- // Disconnect
-
- disconnect();
- return;
- }
-#endif
-#endif
- }
-
-#ifndef WEBSOCKET_DISABLED // For websocket server
-
- // Web socket server handle
-
- DebugWS.handle();
-
-#endif
-
-#ifdef DEBUGGER_ENABLED
-
- // For Simple software debugger - based on SerialDebug Library
-
- // Changed handle debugger logic - 2018-03-01
-
- if (_callbackDbgEnabled && _callbackDbgHandle) { // Calbacks ok ?
-
- boolean callHandle = false;
-
- if (dbgLastConnected != connected) { // Change connection -> always call
-
- dbgLastConnected = connected;
- callHandle = true;
-
- } else if (millis() >= dbgTimeHandle) {
-
- if (_callbackDbgEnabled()) { // Only if it is enabled
- callHandle = true;
- }
- }
-
- if (callHandle) {
-
- // Call the handle
-
- _callbackDbgHandle(true);
-
- // Save time
-
- dbgTimeHandle = millis() + DEBUGGER_HANDLE_TIME;
- }
- }
-#endif
-
- //DV("*handle time: ", (millis() - timeBegin));
-}
-
-
-// Disconnect client
-
-void RemoteDebug::disconnect(boolean onlyTelnetClient) {
-
- // Disconnect
-
- if (onlyTelnetClient) {
- if (_connected) {
- TelnetClient.println("* Closing client connection ..."); // this is to web app new conn not receive it
- }
- } else {
- debugPrintln("* Closing client connection ...");
- }
-
- _silence = false;
- _silenceTimeout = 0;
-
- if (_connected) { // By telnet
- TelnetClient.stop();
- _connected = false;
- }
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- if (_connectedWS && !onlyTelnetClient) {
- DebugWS.disconnect(); // Disconnect client
- _connectedWS = false;
- }
-#endif
-}
-
-// Connection/disconnection event
-
-void RemoteDebug::onConnection(boolean connected) {
-
- // Clear variables
-
- D("rd onconn %d", connected);
-
- _bufferPrint = ""; // Clean buffer
-
- _lastTimeCommand = millis(); // To mark time for inactivity
-
- _command = ""; // Clear command
- _lastCommand = ""; // Clear las command
-
- _lastTimePrint = millis(); // Clear the time
-
- _silence = false; // No silence
- _silenceTimeout = 0;
-
-#ifdef CLIENT_BUFFERING
- // Client buffering - send data in intervals to avoid delays or if its is too big
- _bufferSend = "";
- _sizeBufferSend = 0;
- _lastTimeSend = millis();
-#endif
-
- // Password request ? - 18/07/18
-
- if (_password != "") {
-
- _passwordOk = false;
-
-#ifdef REMOTEDEBUG_PWD_ATTEMPTS
- _passwordAttempt = 1;
-#endif
- }
-
- // Save it
-
- _connected = connected;
-
- // Process
-
- if (connected) { // Connected ?
-
-
- // Callback
-
- if (_callbackNewClient) {
- _callbackNewClient();
- }
-
- // Show the initial message
-
-#if SHOW_HELP
- showHelp();
-#endif
- }
-}
-
-boolean RemoteDebug::isConnected() {
-
- // Is connected
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- return (_connected || _connectedWS);
-#else
- return _connected;
-#endif
-}
-
-// Send to serial too (use only if need)
-
-void RemoteDebug::setSerialEnabled(boolean enable) {
-
- _serialEnabled = enable;
- _showColors = false; // Disable it for Serial
-
-}
-
-// Allow ESP reset over telnet client
-
-void RemoteDebug::setResetCmdEnabled(boolean enable) {
- _resetCommandEnabled = enable;
-}
-
-// Show time in millis
-
-void RemoteDebug::showTime(boolean show) {
- _showTime = show;
-}
-
-// Show profiler - time in millis between messages of debug
-
-void RemoteDebug::showProfiler(boolean show, uint32_t minTime) {
- _showProfiler = show;
- _minTimeShowProfiler = minTime;
-}
-
-#ifdef ALPHA_VERSION // In test, not good yet
-// Automatic change to profiler level if time between handles is greater than n mills (0 - disable)
-
-void RemoteDebug::autoProfilerLevel(uint32_t millisElapsed) {
- _autoLevelProfiler = millisElapsed;
-}
-#endif
-
-// Show debug level
-
-void RemoteDebug::showDebugLevel(boolean show) {
- _showDebugLevel = show;
-}
-
-// Show colors
-
-void RemoteDebug::showColors(boolean show) {
- if (_serialEnabled == false) {
- _showColors = show;
- } else {
- _showColors = false; // Disable it for Serial
- }
-}
-
-// Show in raw mode - only data ?
-
-void RemoteDebug::showRaw(boolean show) {
- _showRaw = show;
-}
-
-
-// Is active ? client telnet connected and level of debug equal or greater then set by user in telnet
-
-boolean RemoteDebug::isActive(uint8_t debugLevel) {
-
- // Active ->
- // Not in silence (new)
- // Debug level ok and
- // Telnet connected or
- // Serial enabled (use only if need)
- // Password ok (if enabled) - 18/08/18
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
-
- boolean ret = (debugLevel >= _clientDebugLevel &&
- !_silence &&
- (_connected || _connectedWS || _serialEnabled));
-
-#else // Telnet only
-
- boolean ret = (debugLevel >= _clientDebugLevel &&
- !_silence &&
- (_connected || _serialEnabled));
-
-#endif
-
-
- if (ret) {
- _lastDebugLevel = debugLevel;
- }
-
- return ret;
-
-}
-
-// Set help for commands over telnet set by sketch
-
-void RemoteDebug::setHelpProjectsCmds(String help) {
-
- _helpProjectCmds = help;
-
-}
-
-// Set callback of sketch function to process project messages
-
-void RemoteDebug::setCallBackProjectCmds(void (*callback)()) {
- _callbackProjectCmds = callback;
-}
-
-void RemoteDebug::setCallBackNewClient(void (*callback)()) {
- _callbackNewClient = callback;
-}
-
-// Print
-
-size_t RemoteDebug::write(const uint8_t *buffer, size_t size) {
-
- // Process buffer
- // Insert due a write bug w/ latest Esp8266 SDK - 17/08/18
-
- for(size_t i=0; i 1) {
- show.concat(COLOR_RESET);
- }
- }
- }
-
- // Show time in millis
-
- if (_showTime) {
- if (show != "")
- show.concat(" ");
- show.concat("t:");
- show.concat(millis());
- show.concat("ms");
- }
-
- // Show profiler (time between messages)
-
- if (_showProfiler) {
- elapsed = (millis() - _lastTimePrint);
- boolean resetColors = false;
- if (show != "")
- show.concat(" ");
- if (_showColors) {
- if (elapsed < 250) {
- ; // not color this
- } else if (elapsed < 1000) {
- show.concat(COLOR_BACKGROUND_CYAN);
- resetColors = true;
- } else if (elapsed < 3000) {
- show.concat(COLOR_BACKGROUND_YELLOW);
- resetColors = true;
- } else if (elapsed < 5000) {
- show.concat(COLOR_BACKGROUND_MAGENTA);
- resetColors = true;
- } else {
- show.concat(COLOR_BACKGROUND_RED);
- resetColors = true;
- }
- }
- show.concat("p:^");
- show.concat(formatNumber(elapsed, 4));
- show.concat("ms");
- if (resetColors) {
- show.concat(COLOR_RESET);
- }
- _lastTimePrint = millis();
- }
-
-#endif
-
- } else { // Raw mode - only data - e.g. used for debugger messages
-
-#ifdef COLOR_NEW_SYSTEM
- show.concat(COLOR_RAW);
-#endif
- }
-
- // Show anything ?
-
- if (show != "") {
-
- if (!_showRaw) {
- show.concat(") ");
- }
-
- // Write to telnet buffered
-
- if (connected || _serialEnabled) { // send data to Client
- _bufferPrint = show;
- }
- }
-
- _newLine = false;
-
- }
-
- // Print ?
-
- boolean doPrint = false;
-
- // New line ?
-
- if (character == '\n') {
-
- _bufferPrint.concat("\r"); // Para clientes windows - 29/01/17
-
- _newLine = true;
- doPrint = true;
-
- } else if (_bufferPrint.length() == BUFFER_PRINT) { // Limit of buffer
-
- doPrint = true;
-
- }
-
- // Write to telnet Buffered
-
- _bufferPrint.concat((char) character);
-
- // Send the characters buffered by print.h
-
- if (doPrint) { // Print the buffer
-
- boolean noPrint = false;
-
- if (_showProfiler && elapsed < _minTimeShowProfiler) { // Profiler time Minimal
- noPrint = true;
- } else if (_filterActive) { // Check filter before print
-
- String aux = _bufferPrint;
- aux.toLowerCase();
-
- if (aux.indexOf(_filter) == -1) { // not find -> no print
- noPrint = true;
- }
- }
-
- if (noPrint == false) {
-
-#ifdef COLOR_NEW_SYSTEM
- _bufferPrint.concat(COLOR_RESET);
-#endif
- // Send to telnet or websocket (buffered)
-
- boolean sendToClient = connected;
-
- if (_password != "" && !_passwordOk) { // With no password -> no telnet output - 2018-10-19
- sendToClient = false;
- }
-
- if (sendToClient) { // send data to Client
-
-
-#ifndef CLIENT_BUFFERING
- debugPrint(_bufferPrint);
-#else // Cliente buffering
-
- uint8_t size = _bufferPrint.length();
-
- // Buffer too big ?
-
- if ((_sizeBufferSend + size) >= MAX_SIZE_SEND) {
-
- // Send it
-
- debugPrint(_bufferSend);
- _bufferSend = "";
- _sizeBufferSend = 0;
- _lastTimeSend = millis();
- }
-
- // Add to buffer of send
-
- _bufferSend.concat(_bufferPrint);
- _sizeBufferSend+=size;
-
- // Client buffering - send data in intervals to avoid delays or if its is too big
- // Not for raw mode
- if (_showRaw || (millis() - _lastTimeSend) >= DELAY_TO_SEND) {
- debugPrint(_bufferSend);
- _bufferSend = "";
- _sizeBufferSend = 0;
- _lastTimeSend = millis();
- }
-#endif
- }
-
- // Echo to serial (not buffering it)
-
- if (_serialEnabled) {
- Serial.print(_bufferPrint);
- }
- }
-
- // Empty the buffer
-
- ret = _bufferPrint.length();
- _bufferPrint = "";
- }
-
- // Retorna
-
- return ret;
-}
-
-////// Private
-
-
-// Show help of commands
-
-void RemoteDebug::showHelp() {
-
- // Show the initial message
-
- String help = "";
-
- // Password request ? - 04/03/18
-
- if (_password != "" && !_passwordOk) {
-
- help.concat("\r\n");
- help.concat("* Please enter with a password to access");
-#ifdef REMOTEDEBUG_PWD_ATTEMPTS
- help.concat(" (attempt ");
- help.concat(_passwordAttempt);
- help.concat(" of ");
- help.concat(REMOTEDEBUG_PWD_ATTEMPTS);
- help.concat(")");
-#endif
- help.concat(':');
- help.concat("\r\n");
-
- debugPrint(help);
-
- return;
-}
-
- // Show help
-
-#if defined(ESP8266)
- help.concat("*** Remote debug - over telnet - for ESP8266 (NodeMCU) - version ");
-#elif defined(ESP32)
- help.concat("*** Remote debug - over telnet - for ESP32 - version ");
-#endif
- help.concat(VERSION);
- help.concat("\r\n");
- help.concat("* Host name: ");
- help.concat(_hostName);
- help.concat(" IP:");
- help.concat(WiFi.localIP().toString());
- help.concat(" Mac address:");
- help.concat(WiFi.macAddress());
- help.concat("\r\n");
- help.concat("* Free Heap RAM: ");
- help.concat(ESP.getFreeHeap());
- help.concat("\r\n");
- help.concat("* ESP SDK version: ");
- help.concat(ESP.getSdkVersion());
- help.concat("\r\n");
- help.concat("******************************************************\r\n");
- help.concat("* Commands:\r\n");
- help.concat(" ? or help -> display these help of commands\r\n");
- help.concat(" q -> quit (close this connection)\r\n");
- help.concat(" m -> display memory available\r\n");
- help.concat(" v -> set debug level to verbose\r\n");
- help.concat(" d -> set debug level to debug\r\n");
- help.concat(" i -> set debug level to info\r\n");
- help.concat(" w -> set debug level to warning\r\n");
- help.concat(" e -> set debug level to errors\r\n");
- help.concat(" s -> set debug silence on/off\r\n");
- help.concat(" l -> show debug level\r\n");
- help.concat(" t -> show time (millis)\r\n");
- help.concat(" profiler:\r\n");
- help.concat(
- " p -> show time between actual and last message (in millis)\r\n");
- help.concat(" p min -> show only if time is this minimal\r\n");
- help.concat(" P time -> set debug level to profiler\r\n");
-#ifdef ALPHA_VERSION // In test, not good yet
- help.concat(" A time -> set auto debug level to profiler\r\n");
-#endif
- help.concat(" c -> show colors\r\n");
- help.concat(" filter:\r\n");
- help.concat(" filter -> show only debugs with this\r\n");
- help.concat(" nofilter -> disable the filter\r\n");
-#if defined(ESP8266)
- help.concat(" cpu80 -> ESP8266 CPU a 80MHz\r\n");
- help.concat(" cpu160 -> ESP8266 CPU a 160MHz\r\n");
- if (_resetCommandEnabled) {
- help.concat(" reset -> reset the ESP8266\r\n");
- }
-#elif defined(ESP32)
- if (_resetCommandEnabled) {
- help.concat(" reset -> reset the ESP32\r\n");
- }
-#endif
-
- // Callbacks
-
- if (_helpProjectCmds != "" && (_callbackProjectCmds)) {
- help.concat("\r\n");
- help.concat(" * Project commands:\r\n");
- String show = "\r\n";
- show.concat(_helpProjectCmds);
- show.replace("\n", "\n "); // ident this
- help.concat(show);
- }
-
-#ifdef DEBUGGER_ENABLED
- // Get help for the debugger
-
- if (_callbackDbgHelp) {
- help.concat("\r\n");
- help.concat(_callbackDbgHelp());
- }
-#endif
- help.concat("\r\n");
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- if (!_connectedWS) { // For telnet only
- help.concat("****\r\n");
- help.concat("* New features available:\r\n");
- help.concat("* - Now you can debug in web browser too.\r\n");
- help.concat("* Please access: http://joaolopesf.net/remotedebugapp\r\n");
- help.concat("* - Now you can add an simple software debuggger.\r\n");
- help.concat("* Please access: https://github.com/JoaoLopesF/RemoteDebugger\r\n");
- help.concat("****\r\n");
- }
-#endif
-
- help.concat("\r\n");
- help.concat(
- "* Please type the command and press enter to execute.(? or h for this help)\r\n");
- help.concat("***\r\n");
-
- // Send to client
-
- debugPrint(help);
-}
-
-// Get last command received
-
-String RemoteDebug::getLastCommand() {
-
- return _lastCommand;
-}
-
-// Clear the last command received
-
-void RemoteDebug::clearLastCommand() {
- _lastCommand = "";
-}
-
-// Process user command over telnet or web socket
-
-void RemoteDebug::processCommand() {
-
- static uint32_t lastTime = 0;
-
- // Bug -> sometimes the command is process twice
- // Workaround -> check time
- // TODO: see correction for this
-
- if (lastTime > 0 && (millis() - lastTime) < 500) {
- debugPrintln("* Bug workaround: ignoring command repeating");
- return;
- }
- lastTime = millis();
-
- D("cmd: %s" , _command.c_str());
-
- // Password request ? - 18/07/18
-
- if (_password != "" && !_passwordOk) { // Process the password - 18/08/18 - adjust in 04/09/08 and 2018-10-19
-
- if (_command == _password) {
-
- debugPrintln("* Password ok, allowing access now...");
-
- _passwordOk = true;
-
-#ifdef ALPHA_VERSION // In test, not good yet
- sendTelnetCommand(TELNET_WILL, TELNET_ECHO); // Send a command to telnet to restore echoes = 18/08/18
-#endif
- showHelp();
-
- } else {
-
- debugPrintln("* Wrong password!");
-
- #ifdef REMOTEDEBUG_PWD_ATTEMPTS
-
- _passwordAttempt++;
-
- if (_passwordAttempt > REMOTEDEBUG_PWD_ATTEMPTS) {
-
- debugPrintln("* Many attempts. Closing session now.");
-
- // Disconnect
-
- disconnect();
-
- } else {
-
- showHelp();
- }
-
- #endif
- }
-
- return;
-
- }
-
- // Process commands
-
- debugPrint("* Debug: Command received: ");
- debugPrintln(_command);
-
- String options = "";
- uint8_t pos = _command.indexOf(" ");
- if (pos > 0) {
- options = _command.substring(pos + 1);
- }
-
- // Set time of last command received
-
- _lastTimeCommand = millis();
-
- // Get out of silent mode
-
- if (_command != "s" && _silence) {
-
- silence(false, true);
- }
-
- // Process the command
-
- if (_command == "h" || _command == "?") {
-
- // Show help
-
- showHelp();
-
- } else if (_command == "q") {
-
- // Quit
-
- debugPrintln("* Closing client connection ...");
-
- TelnetClient.stop();
-
- } else if (_command == "m") {
-
- uint32_t free = ESP.getFreeHeap();
-
- debugPrint("* Free Heap RAM: ");
- debugPrintln(free);
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
-
- // Send status to app
-
- if (_connectedWS) {
- DebugWS.printf("$app:M:%lu:\n", free);
- }
-
-#endif
-
-#if defined(ESP8266)
-
- } else if (_command == "cpu80") {
-
- // Change ESP8266 CPU para 80 MHz
-
- system_update_cpu_freq(80);
- debugPrintln("CPU ESP8266 changed to: 80 MHz");
-
- } else if (_command == "cpu160") {
-
- // Change ESP8266 CPU para 160 MHz
-
- system_update_cpu_freq(160);
- debugPrintln("CPU ESP8266 changed to: 160 MHz");
-
-#endif
-
- } else if (_command == "v") {
-
- // Debug level
-
- _clientDebugLevel = VERBOSE;
-
- debugPrintln("* Debug level set to Verbose");
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- wsSendLevelInfo();
-#endif
-
- } else if (_command == "d") {
-
- // Debug level
-
- _clientDebugLevel = DEBUG;
-
- debugPrintln("* Debug level set to Debug");
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- wsSendLevelInfo();
-#endif
-
- } else if (_command == "i") {
-
- // Debug level
-
- _clientDebugLevel = INFO;
-
- debugPrintln("* Debug level set to Info");
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- wsSendLevelInfo();
-#endif
-
- } else if (_command == "w") {
-
- // Debug level
-
- _clientDebugLevel = WARNING;
-
- debugPrintln("* Debug level set to Warning");
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- wsSendLevelInfo();
-#endif
-
- } else if (_command == "e") {
-
- // Debug level
-
- _clientDebugLevel = ERROR;
-
- debugPrintln("* Debug level set to Error");
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- wsSendLevelInfo();
-#endif
-
- } else if (_command == "l") {
-
- // Show debug level
-
- _showDebugLevel = !_showDebugLevel;
-
- debugPrintf("* Show debug level: %s\r\n",
- (_showDebugLevel) ? "On" : "Off");
-
- } else if (_command == "t") {
-
- // Show time
-
- _showTime = !_showTime;
-
- debugPrintf("* Show time: %s\r\n", (_showTime) ? "On" : "Off");
-
- } else if (_command == "s") {
-
- // Toogle silence (new) = 28/08/18
-
- silence(!_silence);
-
- } else if (_command == "p") {
-
- // Show profiler
-
- _showProfiler = !_showProfiler;
- _minTimeShowProfiler = 0;
-
- debugPrintf("* Show profiler: %s\r\n",
- (_showProfiler) ? "On" : "Off");
-
- } else if (_command.startsWith("p ")) {
-
- // Show profiler with minimal time
-
- if (options.length() > 0) { // With minimal time
- int32_t aux = options.toInt();
- if (aux > 0) { // Valid number
- _showProfiler = true;
- _minTimeShowProfiler = aux;
- debugPrintf(
- "* Show profiler: On (with minimal time: %u)\r\n",
- _minTimeShowProfiler);
- }
- }
-
- } else if (_command == "P") {
-
- // Debug level profile
-
- _levelBeforeProfiler = _clientDebugLevel;
- _clientDebugLevel = PROFILER;
-
- if (_showProfiler == false) {
- _showProfiler = true;
- }
-
- _levelProfilerDisable = 1000; // Default
-
- if (options.length() > 0) { // With time of disable
- int32_t aux = options.toInt();
- if (aux > 0) { // Valid number
- _levelProfilerDisable = millis() + aux;
- }
- }
-
- debugPrintf(
- "* Debug level set to Profiler (disable in %u millis)\r\n",
- _levelProfilerDisable);
-
- } else if (_command == "A") {
-
- // Auto debug level profile
-
- _autoLevelProfiler = 1000; // Default
-
- if (options.length() > 0) { // With time of disable
- int32_t aux = options.toInt();
- if (aux > 0) { // Valid number
- _autoLevelProfiler = aux;
- }
- }
-
- debugPrintf(
- "* Auto profiler debug level active (time >= %u millis)\r\n",
- _autoLevelProfiler);
-
- } else if (_command == "c") {
-
- // Show colors
-
- _showColors = !_showColors;
-
- debugPrintf("* Show colors: %s\r\n",
- (_showColors) ? "On" : "Off");
-
- } else if (_command.startsWith("filter ") && options.length() > 0) {
-
- setFilter(options);
-
- } else if (_command == "nofilter") {
-
- setNoFilter();
- } else if (_command == "reset" && _resetCommandEnabled) {
-
- debugPrintln("* Reset ...");
-
- debugPrintln("* Closing client connection ...");
-
-#if defined(ESP8266)
- debugPrintln("* Resetting the ESP8266 ...");
-#elif defined(ESP32)
- debugPrintln("* Resetting the ESP32 ...");
-#endif
-
- TelnetClient.stop();
- TelnetServer.stop();
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- DebugWS.stop();
-#endif
-
- delay(500);
-
- // Reset
-
- ESP.restart();
-
-#ifdef DEBUGGER_ENABLED
-
- } else if (!_callbackDbgProcessCmd && _command.startsWith("dbg")) {
-
- // Show a message of debugger not is active
-
- debugPrintln("* RemoteDebugger not activate for this project");
- debugPrintln("* Please access it to see how activate this:");
- debugPrintln("* https://github.com/JoaoLopesF/RemoteDebugger");
-
-#endif
-
- } else {
-
- // Callbacks
-
-#ifdef DEBUGGER_ENABLED
- // Process commands for the debugger
-
- if (_callbackDbgProcessCmd) {
- _callbackDbgProcessCmd();
- }
-#endif
-
- // Project commands - set by programmer
-
- if (_callbackProjectCmds) {
-
- _callbackProjectCmds();
-
- }
- }
-}
-
-// Filter
-
-void RemoteDebug::setFilter(String filter) {
-
- _filter = filter;
- _filter.toLowerCase(); // TODO: option to case insensitive ?
- _filterActive = true;
-
- debugPrint("* Debug: Filter active: ");
- debugPrintln(_filter);
-
-}
-
-void RemoteDebug::setNoFilter() {
-
- _filter = "";
- _filterActive = false;
-
- debugPrintln("* Debug: Filter disabled");
-
-}
-
-// Silence
-
-void RemoteDebug::silence(boolean activate, boolean showMessage, boolean fromBreak, uint32_t timeout) {
-
- // Set silence and timeout
-
- if (showMessage) {
-
- if (activate) {
-
- debugPrintln("* Debug now is in silent mode!");
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- if (_connectedWS) {
- debugPrintln("* Press button \"Silence\" or another command to return show debugs");
- } else {
- debugPrintln("* Press s again or another command to return show debugs");
- }
-#else
- debugPrintln("* Press s again or another command to return show debugs");
-#endif
- } else {
-
- debugPrintln("* Debug now exit from silent mode!");
- }
- }
-
- // Set it
-
- _silence = activate;
- _silenceTimeout = (timeout == 0)?0:(millis() + timeout);
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
-
- // Send status to app
-
- if (_connectedWS) {
- DebugWS.printf("$app:S:%c\n", ((_silence)? '1':'0'));
- }
-
-#endif
-
-}
-
-boolean RemoteDebug::isSilence() {
-
- return _silence;
-}
-
-// Format numbers
-
-String RemoteDebug::formatNumber(uint32_t value, uint8_t size, char insert) {
-
- // Putting zeroes in left
-
- String ret = "";
-
- for (uint8_t i = 1; i <= size; i++) {
- uint32_t max = pow(10, i);
- if (value < max) {
- for (uint8_t j = (size - i); j > 0; j--) {
- ret.concat(insert);
- }
- break;
- }
- }
-
- ret.concat(value);
-
- return ret;
-}
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
-
-/////// Web socket routines
-
-// Process user command over telnet or web socket
-
-void RemoteDebug::wsOnReceive(const char* command) { // @suppress("Unused function declaration")
-
- // Process the command
-
- _command = command;
- _lastCommand = _command; // Store the last command
-
- D("cmd: %s", command);
-
- // Is app commands
-
- if (_command == "$app") {
-
- // RemoteDebug connected, send info
-
- wsSendInfo ();
-
- } else { // Normal commands
-
- processCommand();
- }
-}
-
-// Send info to RemoteDebugApp
-
-void RemoteDebug::wsSendInfo() {
-
- // Send version, board, debugger disabled and if is low or enough memory board
-
- char features;
- char dbgEnabled;
-
- // Not connected ?
-
- if (!_connectedWS) {
- return;
- }
-
- // Features
-
-#ifndef DEBUGGER_ENABLED
- features = 'M'; // Disabled
- dbgEnabled = 'D';
-#else
- if (_callbackDbgProcessCmd) {
- features = 'E'; // Enough
- dbgEnabled = 'E';
- } else {
- features = 'M'; // Medium
- dbgEnabled = 'D';
- }
-#endif
-
- // Send info
-
- String version = String(VERSION);
- String board;
-
-#ifdef ESP32
- board = "ESP32";
-#else
- board = "ESP8266";
-#endif
-
- DebugWS.println(); // Workaround to not get dirty "[0m" ???
- DebugWS.printf("$app:V:%s:%s:%c:%lu:%c:N\n", version.c_str(), board.c_str(), features, getFreeMemory(), dbgEnabled);
-
- // Status of debug level
-
- wsSendLevelInfo();
-
- // Send status of debugger
-
- // TODO: made it
-
-}
-
-void RemoteDebug::wsSendLevelInfo() {
-
- // Send debug level info to app
-
- if (_connectedWS) {
- DebugWS.printf("$app:L:%u\n", _clientDebugLevel);
- }
-}
-
-#endif // WEBSOCKET_DISABLED
-
-boolean RemoteDebug::wsIsConnected() {
-
- // Web socket is connected (RemoteDebugApp)
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- return _connectedWS;
-#else
- return false;
-#endif
-}
-
-/////// Utilities
-
-// Get free memory
-
-uint32_t RemoteDebug::getFreeMemory() {
-
- return ESP.getFreeHeap();
-
-}
-
-// Is CR or LF ?
-
-boolean RemoteDebug::isCRLF(char character) {
-
- return (character == '\r' || character == '\n');
-
-}
-
-// Expand characters as CR/LF to \\r, \\n
-// TODO: make this for another chars not printable
-
-String RemoteDebug::expand(String string) {
-
- string.replace("\r", "\\r");
- string.replace("\n", "\\n");
-
- return string;
-}
-
-#ifdef ALPHA_VERSION // In test, not good yet
-// Send telnet commands (as used with password request) - 18/08/18
-// Experimental code !
-
-void RemoteDebug::sendTelnetCommand(uint8_t command, uint8_t option) {
-
- // Send a command to the telnet client
-
- debugPrintf("%c%c%c", TELNET_IAC, command, option);
- TelnetClient.flush();
-}
-#endif
-
-#else // DEBUG_DISABLED
-
-/////// All debug is disabled, this include is to define empty debug macros
-
-#include "RemoteDebug.h" // This library
-
-#endif // DEBUG_DISABLED
-
-/////// End
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/RemoteDebug.h b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/RemoteDebug.h
deleted file mode 100644
index 902cd4d..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/RemoteDebug.h
+++ /dev/null
@@ -1,459 +0,0 @@
-/*
- * Header for RemoteDebug
- *
- * MIT License
- *
- * Copyright (c) 2019 Joao Lopes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- *
- */
-
-#ifndef REMOTEDEBUG_H
-#define REMOTEDEBUG_H
-#pragma once
-
-///// RemoteDebug configuration
-
-#include "RemoteDebugCfg.h"
-
-// Debug enabled ?
-
-#ifndef DEBUG_DISABLED
-
-//////// Defines
-
-// New color system (comment this to return to old system) - 2019-02-27
-
-#define COLOR_NEW_SYSTEM true
-
-// ANSI Colors
-
-#define COLOR_RESET "\x1B[0m"
-
-#define COLOR_BLACK "\x1B[0;30m"
-#define COLOR_RED "\x1B[0;31m"
-#define COLOR_GREEN "\x1B[0;32m"
-#define COLOR_YELLOW "\x1B[0;33m"
-#define COLOR_BLUE "\x1B[0;34m"
-#define COLOR_MAGENTA "\x1B[0;35m"
-#define COLOR_CYAN "\x1B[0;36m"
-#define COLOR_WHITE "\x1B[0;37m"
-
-#define COLOR_DARK_BLACK "\x1B[1;30m"
-
-#define COLOR_LIGHT_RED "\x1B[1;31m"
-#define COLOR_LIGHT_GREEN "\x1B[1;32m"
-#define COLOR_LIGHT_YELLOW "\x1B[1;33m"
-#define COLOR_LIGHT_BLUE "\x1B[1;34m"
-#define COLOR_LIGHT_MAGENTA "\x1B[1;35m"
-#define COLOR_LIGHT_CYAN "\x1B[1;36m"
-#define COLOR_LIGHT_WHITE "\x1B[1;37m"
-
-#define COLOR_BACKGROUND_BLACK "\x1B[40m"
-#define COLOR_BACKGROUND_RED "\x1B[41m"
-#define COLOR_BACKGROUND_GREEN "\x1B[42m"
-#define COLOR_BACKGROUND_YELLOW "\x1B[43m"
-#define COLOR_BACKGROUND_BLUE "\x1B[44m"
-#define COLOR_BACKGROUND_MAGENTA "\x1B[45m"
-#define COLOR_BACKGROUND_CYAN "\x1B[46m"
-#define COLOR_BACKGROUND_WHITE "\x1B[47m"
-
-#ifdef COLOR_NEW_SYSTEM
-// New system of Colors
-// Note: this colors is not equals to SerialDebug colors, due using standard 16 colors of Ansi, for compatibility
-#define COLOR_VERBOSE COLOR_GREEN
-#define COLOR_DEBUG COLOR_LIGHT_GREEN
-//#define COLOR_INFO COLOR_YELLOW
-//#define COLOR_WARNING COLOR_CYAN
-//#define COLOR_ERROR COLOR_RED
-#define COLOR_INFO COLOR_LIGHT_YELLOW
-#define COLOR_WARNING COLOR_LIGHT_CYAN
-#define COLOR_ERROR COLOR_LIGHT_RED
-#define COLOR_RAW COLOR_WHITE // COLOR_MAGENTA
-#endif
-
-//////// Includes
-
-#include "Arduino.h"
-#include "Print.h"
-
-// ESP8266 or ESP32 ?
-
-#if defined(ESP8266)
-
-#include
-
-#elif defined(ESP32)
-
-#include
-
-#else
-
-#error "Only for ESP8266 or ESP32"
-
-#endif
-
-////// Shortcuts macros
-
-// Auto function for debug macros?
-
-#ifndef DEBUG_DISABLE_AUTO_FUNC // With auto func
-
- #ifdef ESP32
-
- // ESP32 -> Multicore - show core id ?
-
- #define DEBUG_AUTO_CORE true // debug show core id ? (comment to disable it)
-
- #ifdef DEBUG_AUTO_CORE
-
- #define rdebugA(fmt, ...) if (Debug.isActive(Debug.ANY)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
- #define rdebugP(fmt, ...) if (Debug.isActive(Debug.PROFILER)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
- #define rdebugV(fmt, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
- #define rdebugD(fmt, ...) if (Debug.isActive(Debug.DEBUG)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
- #define rdebugI(fmt, ...) if (Debug.isActive(Debug.INFO)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
- #define rdebugW(fmt, ...) if (Debug.isActive(Debug.WARNING)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
- #define rdebugE(fmt, ...) if (Debug.isActive(Debug.ERROR)) Debug.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__)
-
- #endif
-
- #endif
-
- #ifndef DEBUG_AUTO_CORE // No auto core or for ESP8266
-
- #define rdebugA(fmt, ...) if (Debug.isActive(Debug.ANY)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
- #define rdebugP(fmt, ...) if (Debug.isActive(Debug.PROFILER)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
- #define rdebugV(fmt, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
- #define rdebugD(fmt, ...) if (Debug.isActive(Debug.DEBUG)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
- #define rdebugI(fmt, ...) if (Debug.isActive(Debug.INFO)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
- #define rdebugW(fmt, ...) if (Debug.isActive(Debug.WARNING)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
- #define rdebugE(fmt, ...) if (Debug.isActive(Debug.ERROR)) Debug.printf("(%s) " fmt, __func__, ##__VA_ARGS__)
-
- #endif
-
-#else // Without auto func
-
- #define rdebugA(fmt, ...) if (Debug.isActive(Debug.ANY)) Debug.printf(fmt, ##__VA_ARGS__)
- #define rdebugP(fmt, ...) if (Debug.isActive(Debug.PROFILER)) Debug.printf(fmt, ##__VA_ARGS__)
- #define rdebugV(fmt, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.printf(fmt, ##__VA_ARGS__)
- #define rdebugD(fmt, ...) if (Debug.isActive(Debug.DEBUG)) Debug.printf(fmt, ##__VA_ARGS__)
- #define rdebugI(fmt, ...) if (Debug.isActive(Debug.INFO)) Debug.printf(fmt, ##__VA_ARGS__)
- #define rdebugW(fmt, ...) if (Debug.isActive(Debug.WARNING)) Debug.printf(fmt, ##__VA_ARGS__)
- #define rdebugE(fmt, ...) if (Debug.isActive(Debug.ERROR)) Debug.printf(fmt, ##__VA_ARGS__)
-
-#endif
-
-// With newline
-
-#define rdebugAln(fmt, ...) rdebugA(fmt "\n", ##__VA_ARGS__)
-#define rdebugPln(fmt, ...) rdebugP(fmt "\n", ##__VA_ARGS__)
-#define rdebugVln(fmt, ...) rdebugV(fmt "\n", ##__VA_ARGS__)
-#define rdebugDln(fmt, ...) rdebugD(fmt "\n", ##__VA_ARGS__)
-#define rdebugIln(fmt, ...) rdebugI(fmt "\n", ##__VA_ARGS__)
-#define rdebugWln(fmt, ...) rdebugW(fmt "\n", ##__VA_ARGS__)
-#define rdebugEln(fmt, ...) rdebugE(fmt "\n", ##__VA_ARGS__)
-
-// For old versions compatibility
-
-#define rdebug(fmt, ...) rdebugA(fmt, ##__VA_ARGS__)
-
-// Another way - for compatibility
-
-#define DEBUG(fmt, ...) rdebugA(fmt, ##__VA_ARGS__)
-
-#define DEBUG_A(fmt, ...) rdebugA(fmt, ##__VA_ARGS__)
-#define DEBUG_P(fmt, ...) rdebugP(fmt, ##__VA_ARGS__)
-#define DEBUG_V(fmt, ...) rdebugV(fmt, ##__VA_ARGS__)
-#define DEBUG_D(fmt, ...) rdebugD(fmt, ##__VA_ARGS__)
-#define DEBUG_I(fmt, ...) rdebugI(fmt, ##__VA_ARGS__)
-#define DEBUG_W(fmt, ...) rdebugW(fmt, ##__VA_ARGS__)
-#define DEBUG_E(fmt, ...) rdebugE(fmt, ##__VA_ARGS__)
-
-// New way: To compatibility with SerialDebug (can use RemoteDebug or SerialDebug)
-// This is my favorite :)
-
-#define debugV(fmt, ...) rdebugVln(fmt, ##__VA_ARGS__)
-#define debugD(fmt, ...) rdebugDln(fmt, ##__VA_ARGS__)
-#define debugI(fmt, ...) rdebugIln(fmt, ##__VA_ARGS__)
-#define debugW(fmt, ...) rdebugWln(fmt, ##__VA_ARGS__)
-#define debugE(fmt, ...) rdebugEln(fmt, ##__VA_ARGS__)
-#define debugA(fmt, ...) rdebugAln(fmt, ##__VA_ARGS__)
-
-#define debugHandle() Debug.handle()
-
-// Macros used by code converter for codes with several prints to only message
-// due the converter cannot
-// convert severals Serial.print in one debug* macro.
-
-#define rprintV(x, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.print(x, ##__VA_ARGS__)
-#define rprintD(x, ...) if (Debug.isActive(Debug.DEBUG)) Debug.print(x, ##__VA_ARGS__)
-#define rprintI(x, ...) if (Debug.isActive(Debug.INFO)) Debug.print(x, ##__VA_ARGS__)
-#define rprintW(x, ...) if (Debug.isActive(Debug.WARNING)) Debug.print(x, ##__VA_ARGS__)
-#define rprintE(x, ...) if (Debug.isActive(Debug.ERROR)) Debug.print(x, ##__VA_ARGS__)
-#define rprintA(x, ...) if (Debug.isActive(Debug.ANY)) Debug.print(x, ##__VA_ARGS__)
-
-
-#define rprintVln(x, ...) if (Debug.isActive(Debug.VERBOSE)) Debug.println(x, ##__VA_ARGS__)
-#define rprintDln(x, ...) if (Debug.isActive(Debug.DEBUG)) Debug.println(x, ##__VA_ARGS__)
-#define rprintIln(x, ...) if (Debug.isActive(Debug.INFO)) Debug.println(x, ##__VA_ARGS__)
-#define rprintWln(x, ...) if (Debug.isActive(Debug.WARNING)) Debug.println(x, ##__VA_ARGS__)
-#define rprintEln(x, ...) if (Debug.isActive(Debug.ERROR)) Debug.println(x, ##__VA_ARGS__)
-#define rprintAln(x, ...) if (Debug.isActive(Debug.ANY)) Debug.println(x, ##__VA_ARGS__)
-
-///// Class
-
-class RemoteDebug: public Print
-{
- public:
-
- // Constructor
-
- RemoteDebug();
-
- // Methods
-
- bool begin(String hostName, uint16_t port, uint8_t startingDebugLevel = DEBUG);
- bool begin(String hostName, uint8_t startingDebugLevel = DEBUG);
-
- void setPassword(String password);
-
- void stop();
-
- void handle();
-
- void disconnect(boolean onlyTelnetClient = false);
-
- void setSerialEnabled(boolean enable);
-
- void setResetCmdEnabled(boolean enable);
-
- void setHelpProjectsCmds(String help);
- void setCallBackProjectCmds(void (*callback)());
- String getLastCommand();
- void clearLastCommand();
-
- void showTime(boolean show);
- void showProfiler(boolean show, uint32_t minTime = 0);
- void showDebugLevel(boolean show);
- void showColors(boolean show);
-
- void showRaw(boolean show);
-
- void setCallBackNewClient(void (*callback)());
-
-#ifdef ALPHA_VERSION // In test, not good yet
- void autoProfilerLevel(uint32_t millisElapsed);
-#endif
-
- void setFilter(String filter);
- void setNoFilter();
-
- boolean isActive(uint8_t debugLevel = DEBUG);
-
- void silence(boolean activate, boolean showMessage = true, boolean fromBreak = false, uint32_t timeout = 0);
- boolean isSilence();
-
- void onConnection(boolean connected);
-
- boolean isConnected();
-
-#ifdef DEBUGGER_ENABLED
- // For Simple software debugger - based on SerialDebug Library
- void initDebugger(boolean (*callbackEnabled)(), void (*callbackHandle)(const boolean), String (*callbackGetHelp)(), void (*callbackProcessCmd)());
- WiFiClient* getTelnetClient();
-#endif
-
-#ifndef WEBSOCKET_DISABLED // For web socket server (app)
- void wsOnReceive(const char* command);
- void wsSendInfo();
- void wsSendLevelInfo();
-#endif
- boolean wsIsConnected();
-
- // Print
-
- virtual size_t write(uint8_t);
-
- virtual size_t write(const uint8_t *buffer, size_t size); // Insert due a write bug w/ latest Esp8266 SDK - 17/08/18
-
- // Debug levels
-
- static const uint8_t PROFILER = 0; // Used for show time of execution of pieces of code(profiler)
- static const uint8_t VERBOSE = 1; // Used for show verboses messages
- static const uint8_t DEBUG = 2; // Used for show debug messages
- static const uint8_t INFO = 3; // Used for show info messages
- static const uint8_t WARNING = 4; // Used for show warning messages
- static const uint8_t ERROR = 5; // Used for show error messages
- static const uint8_t ANY = 6; // Used for show always messages, for any current debug level
-
- // Expand characters as CR/LF to \\r, \\n
-
- String expand(String string);
-
- // Destructor
-
- ~RemoteDebug();
-
-private:
-
- // Variables
-
- String _hostName = ""; // Host name
-
- boolean _connected = false; // Client is connected ?
-
- String _password = ""; // Password
-
- boolean _passwordOk = false; // Password request ? - 18/07/18
- uint8_t _passwordAttempt = 0;
-
- boolean _silence = false; // Silence mode ?
- uint32_t _silenceTimeout = 0; // Silence timeout
-
- uint8_t _clientDebugLevel = DEBUG; // Level setted by user in web app or telnet client
- uint8_t _lastDebugLevel = DEBUG; // Last Level setted by active()
-
- uint32_t _lastTimePrint = millis(); // Last time print a line
-
- uint8_t _levelBeforeProfiler=DEBUG; // Last Level before Profiler level
- uint32_t _levelProfilerDisable = 0; // time in millis to disable the profiler level
- uint32_t _autoLevelProfiler = 0; // Automatic change to profiler level if time between handles is greater than n millis
-
- boolean _showTime = false; // Show time in millis
-
- boolean _showProfiler = false; // Show time between messages
- uint32_t _minTimeShowProfiler = 0; // Minimal time to show profiler
-
- boolean _showDebugLevel = true; // Show debug Level
-
- boolean _showColors = false; // Show colors
-
- boolean _showRaw = false; // Show in raw mode ?
-
- boolean _serialEnabled = false; // Send to serial too (not recommended)
-
- boolean _resetCommandEnabled=false; // Enable command to reset the board
-
- boolean _newLine = true; // New line write ?
-
- String _command = ""; // Command received
- String _lastCommand = ""; // Last Command received
- uint32_t _lastTimeCommand = millis();// Last time command received
- String _helpProjectCmds = ""; // Help of comands setted by project (sketch)
- void (*_callbackProjectCmds)() = NULL; // Callable for projects commands
- void (*_callbackNewClient)() = NULL; // Callable for when have a new client connected
-
- String _filter = ""; // Filter
- boolean _filterActive = false;
-
- String _bufferPrint = ""; // Buffer of print write to WiFi
-
-#ifdef CLIENT_BUFFERING
- String _bufferSend = ""; // Buffer to send data to web app or telnet client
- uint16_t _sizeBufferSend = 0; // Size of it
- uint32_t _lastTimeSend = 0; // Last time command send data
-#endif
-
-#ifdef DEBUGGER_ENABLED
-// // For Simple software debugger - based on SerialDebug Library
- boolean (*_callbackDbgEnabled)() = NULL;// Callable for debugger enabled
- void (*_callbackDbgHandle)(const boolean) = NULL; // Callable for handle of debugger
- String (*_callbackDbgHelp)() = NULL; // Callable for get debugger help
- void (*_callbackDbgProcessCmd)() = NULL;// Callable for process commands of debugger
-#endif
-
- //////// Privates
-
- void showHelp();
- void processCommand();
- String formatNumber(uint32_t value, uint8_t size, char insert='0');
- boolean isCRLF(char character);
- uint32_t getFreeMemory();
-
-#ifdef ALPHA_VERSION // In test, not good yet
- void sendTelnetCommand(uint8_t command, uint8_t option);
-#endif
-
-};
-
-#else // DEBUG_DISABLED
-
-// Disable debug macros
-
-#define rdebugAln(...)
-#define rdebugPln(...)
-#define rdebugVln(...)
-#define rdebugDln(...)
-#define rdebugIln(...)
-#define rdebugWln(...)
-#define rdebugEln(...)
-#define rdebug(...)
-
-#define DEBUG(...)
-
-#define DEBUG_A(...)
-#define DEBUG_P(...)
-#define DEBUG_V(...)
-#define DEBUG_D(...)
-#define DEBUG_I(...)
-#define DEBUG_W(...)
-#define DEBUG_E(...)
-
-#define debugA(...)
-#define debugP(...)
-#define debugV(...)
-#define debugD(...)
-#define debugI(...)
-#define debugW(...)
-#define debugE(...)
-
-#define rprintA(...)
-#define rprintV(...)
-#define rprintD(...)
-#define rprintI(...)
-#define rprintW(...)
-#define rprintE(...)
-
-#define rprintAln(...)
-#define rprintVln(...)
-#define rprintDln(...)
-#define rprintIln(...)
-#define rprintWln(...)
-#define rprintEln(...)
-
-#define debugHandle()
-
-// Note all of Debug. codes need uses "#ifndef DEBUG_DISABLED"
-// For example, the initialization codes and:
-
-//#ifndef DEBUG_DISABLED
-//if (Debug.isActive(Debug.VERBOSE)) {
-// Debug.printf("bla bla bla: %d %s", number, str); // OR
-// Debug.printf("bla bla bla: %d %s", number, str.c_str()); // Note: if type is String need c_str() // OR
-// Debug.println("bla bla bla 2 ln");
-//}
-//#endif
-
-#endif // DEBUG_DISABLED
-
-#endif // H
-
-//////// End
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/RemoteDebugCfg.h b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/RemoteDebugCfg.h
deleted file mode 100644
index 215c898..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/RemoteDebugCfg.h
+++ /dev/null
@@ -1,135 +0,0 @@
-
-/*
- * Header for RemoteDebugCfg
- *
- * MIT License
- *
- * Copyright (c) 2019 Joao Lopes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- *
- */
-
-/*
- * All configurations have moved to RemoteDebugCfg.h,
- * to facilitate changes
- */
-
-///////////// User config, to not lost in library updates
-
-#ifndef REMOTEDEBUGCFG_H_
-#define REMOTEDEBUGCFG_H_
-#pragma once
-
-///////////// For RemoteDebug ///////////////////
-
-///// Debug disable for compile to production/release
-///// as nothing of RemotedDebug is compiled, zero overhead :-)
-//#define DEBUG_DISABLED true
-
-// Debug enabled ?
-
-#ifndef DEBUG_DISABLED
-
-///// Port for telnet server
-#define TELNET_PORT 23
-
-// Disable auto function for debug macros? (uncomment this if not want this)
-//#define DEBUG_DISABLE_AUTO_FUNC true
-
-// Simple password request - left commented if not need this - 18/07/18
-// Notes:
-// It is very simple feature, only text, no cryptography,
-// and the password is echoed in screen (I not discovery yet how disable it)
-// telnet use advanced authentication (kerberos, etc.)
-// Such now as RemoteDebug now is not for production releases,
-// this kind of authentication will not be done now.
-// Can be by project, just call setPassword method
-#define REMOTEDEBUG_PWD_ATTEMPTS 3
-
-// Maximum time for inactivity (em milliseconds)
-// Default: 10 minutes
-// Comment it if you not want this
-// Can be by project, just define it before include this file
-//#define MAX_TIME_INACTIVE 600000
-
-// Buffered print write to WiFi -> length of buffer
-// Can be by project, just define it before include this file
-#define BUFFER_PRINT 170
-
-// Should the help text be displayed on connection.
-// Enabled by default, comment to disable
-#define SHOW_HELP true
-
-// Buffering (sends in interval of time to avoid ESP misterious delays)
-// Uncomment this to disable it
-#define CLIENT_BUFFERING true
-#ifdef CLIENT_BUFFERING
-#define DELAY_TO_SEND 10 // Time to send buffer
-#define MAX_SIZE_SEND 1460 // Maximum size of packet (limit of TCP/IP)
-#endif
-
-// Enable if you test features yet in development
-//#define ALPHA_VERSION true
-
-// Debugger support enabled ?
-// Comment this to disable it
-#define DEBUGGER_ENABLED true
-#ifdef DEBUGGER_ENABLED
-#define DEBUGGER_HANDLE_TIME 850 // Interval to call handle of debugger - equal to implemented in debugger
-// App have debugger elements on screen ?
-// Note: app not have it yet
-//#define DEBUGGER_SEND_INFO true
-#endif
-
-///// Websocket server to support debug over web browser (RemoteDebugApp)
-// Uncomment this to disable it
-#define WEBSOCKET_DISABLED true
-
-///////////// For RemoteDebugWS ///////////////////
-
-#ifndef WEBSOCKET_DISABLED
-
-// Websocket port
-#define WEBSOCKET_PORT 8232
-
-// Library arduinoWebSockets already installed, uncomment to use it
-// Do this if you receive errors of multiple definition ...
-//#define USE_LIB_WEBSOCKET true
-#endif
-
-///////////// For RemoteDebugger ///////////////////
-
-// Enable Flash variables support - F()
-// Used internally in SerialDebug and in public API
-// If is a low memory board, like AVR, all strings in SerialDebug is using flash memory
-// If have RAM memory, this is more fast than flash
-//#define DEBUG_USE_FLASH_F true
-
-// For Espressif boards, default is not flash support for printf,
-// due it have a lot of memory and Serial.printf is not compatible with it
-// If you need more memory, can force it:
-//#define DEBUG_USE_FLASH_F true
-
-#endif /* DEBUG_DISABLED */
-
-#endif /* REMOTEDEBUGCFG_H_ */
-
-////// End
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/telnet.h b/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/telnet.h
deleted file mode 100644
index 474dcde..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/RemoteDebug/src/telnet.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * telnet.h - Telnet Defines
- *
- * Note: only used is uncommented
- * */
-
-#ifndef TELNET_H
-#define TELNET_TELNET_H
-
-#define TELNET_IAC 255
-#define TELNET_DONT 254
-#define TELNET_DO 253
-#define TELNET_WONT 252
-#define TELNET_WILL 251
-
-// #define TELNET_SE 240 // Subnegotiation End
-// #define TELNET_NOP 241 // No Operation
-// #define TELNET_DM 242 // Data Mark
-// #define TELNET_BRK 243 // Break
-// #define TELNET_IP 244 // Interrupt process
-// #define TELNET_AO 245 // Abort output
-// #define TELNET_AYT 246 // Are You There
-// #define TELNET_EC 247 // Erase Character
-// #define TELNET_EL 248 // Erase Line
-//#define TELNET_GA 249 // Go Ahead
-// #define TELNET_SB 250 // Subnegotiation Begin
-
-// #define TELNET_BINARY 0 // 8-bit data path
-#define TELNET_ECHO 1 // echo
-// #define TELNET_RCP 2 // prepare to reconnect
-#define TELNET_SGA 3 // suppress go ahead
-// #define TELNET_NAMS 4 // approximate message size
-// #define TELNET_STATUS 5 // give status
-// #define TELNET_TM 6 // timing mark
-// #define TELNET_RCTE 7 // remote controlled transmission and echo
-// #define TELNET_NAOL 8 // negotiate about output line width
-// #define TELNET_NAOP 9 // negotiate about output page size
-// #define TELNET_NAOCRD 10 // negotiate about CR disposition
-// #define TELNET_NAOHTS 11 // negotiate about horizontal tabstops
-// #define TELNET_NAOHTD 12 // negotiate about horizontal tab disposition
-// #define TELNET_NAOFFD 13 // negotiate about formfeed disposition
-// #define TELNET_NAOVTS 14 // negotiate about vertical tab stops
-// #define TELNET_NAOVTD 15 // negotiate about vertical tab disposition
-// #define TELNET_NAOLFD 16 // negotiate about output LF disposition
-// #define TELNET_XASCII 17 // extended ascii character set
-// #define TELNET_LOGOUT 18 // force logout
-// #define TELNET_BM 19 // byte macro
-// #define TELNET_DET 20 // data entry terminal
-// #define TELNET_SUPDUP 21 // supdup protocol
-// #define TELNET_SUPDUPOUTPUT 22 // supdup output
-// #define TELNET_SNDLOC 23 // send location
-// #define TELNET_TTYPE 24 // terminal type
-// #define TELNET_EOR 25 // end or record
-// #define TELNET_TUID 26 // TACACS user identification
-// #define TELNET_OUTMRK 27 // output marking
-// #define TELNET_TTYLOC 28 // terminal location number
-// #define TELNET_VT3270REGIME 29 // 3270 regime
-// #define TELNET_X3PAD 30 // X.3 PAD
-// #define TELNET_NAWS 31 // window size
-// #define TELNET_TSPEED 32 // terminal speed
-// #define TELNET_LFLOW 33 // remote flow control
-// #define TELNET_LINEMODE 34 // Linemode option
-// #define TELNET_XDISPLOC 35 // X Display Location
-// #define TELNET_OLD_ENVIRON 36 // Old - Environment variables
-// #define TELNET_AUTHENTICATION 37 // Authenticate
-// #define TELNET_ENCRYPT 38 // Encryption option
-// #define TELNET_NEW_ENVIRON 39 // New - Environment variables
-// #define TELNET_TN3270E 40 // TN3270E
-// #define TELNET_XAUTH 41 // XAUTH
-// #define TELNET_CHARSET 42 // CHARSET
-// #define TELNET_RSP 43 // Telnet Remote Serial Port
-// #define TELNET_COM_PORT_OPTION 44 // Com Port Control Option
-#define TELNET_SUPPRESS_LOCAL_ECHO 45 // Telnet Suppress Local Echo
-// #define TELNET_TLS 46 // Telnet Start TLS
-// #define TELNET_KERMIT 47 // KERMIT
-// #define TELNET_SEND_URL 48 // SEND-URL
-// #define TELNET_FORWARD_X 49 // FORWARD_X
-// #define TELNET_PRAGMA_LOGON 138 // TELOPT PRAGMA LOGON
-// #define TELNET_SSPI_LOGON 139 // TELOPT SSPI LOGON
-// #define TELNET_PRAGMA_HEARTBEAT 140 // TELOPT PRAGMA HEARTBEAT
-// #define TELNET_EXOPL 255 // Extended-Options-List
-// #define TELNET_NOOPT 0
-
-// #define TELNET_IS 0
-// #define TELNET_SEND 1
-
-#endif // TELNET_H
-
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/LICENSE b/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/LICENSE
deleted file mode 100644
index cf1ab25..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-This is free and unencumbered software released into the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/README.md b/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/README.md
deleted file mode 100644
index 7dc5190..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/README.md
+++ /dev/null
@@ -1,518 +0,0 @@
-[](https://github.com/chrisjoyce911/esp32FOTA/actions/)
-
-[](https://www.ardu-badge.com/esp32FOTA)
-[](https://registry.platformio.org/libraries/chrisjoyce911/esp32FOTA)
-
-
-
-# esp32FOTA library for Arduino
-
-## Purpose
-
-A simple library to add support for Over-The-Air (OTA) updates to your project.
-
-## Features
-
-- [x] Zlib or gzip compressed firmware support
-- [x] SPIFFS/LittleFS partition Update [#25], [#47], [#60], [#92] (thanks to all participants)
-- [x] Any fs::FS support (SPIFFS/LITTLEFS/SD) for cert/signature storage [#79], [#74], [#91], [#92] (thanks to all participants)
-- [x] Seamless http/https
-- [x] Web update (requires web server)
-- [x] Batch firmware sync
-- [x] Force firmware update [#8]
-- [x] https support [#26] ( Thanks to @fbambusi )
-- [x] Signature check of downloaded firmware-image [#65]
-- [x] Signature verification
-- [x] Semantic versioning support
-- [ ] Checking for update via bin headers [#15]
-
-## How it works
-
-This library tries to access a JSON file hosted on a webserver, and reviews it to decide if a newer firmware has been published, if so it will download it and install it.
-
-There are a few things that need to be in place for an update to work.
-
-- A webserver with the firmware information in a JSON file
-- Firmware version
-- Firmware type
-- Firmware bin (can optionnally be compressed with zlib or gzip)
-- For https or signature check: SPIFFS with root_ca.pem (https) and rsa_key.pem (signature check)
-
-You can supply http or https URLs. If you are using https, you need the root_ca.pem in your SPIFFS partition. For the actual firmware it will use https when you define port 443 or 4433. Otherwise it will use plain http.
-
-## Usage
-
-### Hosted JSON
-
-This is hosted by a webserver and contains information about the latest firmware:
-
-```json
-{
- "type": "esp32-fota-http",
- "version": 2,
- "host": "192.168.0.100",
- "port": 80,
- "bin": "/fota/esp32-fota-http-2.bin"
-}
-```
-
-Version information can be either a single number or a semantic version string. Alternatively, a full URL path can be provided:
-
-```json
-{
- "type": "esp32-fota-http",
- "version": "2.5.1",
- "url": "http://192.168.0.100/fota/esp32-fota-http-2.bin"
-}
-```
-
-A single JSON file can provide information on multiple firmware types by combining them together into an array. When this is loaded, the firmware manifest with a type matching the one passed to the esp32FOTA constructor will be selected:
-
-```json
-[
- {
- "type":"esp32-fota-http",
- "version":"0.0.2",
- "url":"http://192.168.0.100/fota/esp32-fota-http-2.bin"
- },
- {
- "type":"esp32-other-hardware",
- "version":"0.0.3",
- "url":"http://192.168.0.100/fota/esp32-other-hardware.bin"
- }
-]
-```
-
-
-A single JSON file can also contain several versions of a single firmware type:
-
-```json
-[
- {
- "type":"esp32-fota-http",
- "version":"0.0.2",
- "url":"http://192.168.0.100/fota/esp32-fota-0.0.2.bin"
- },
- {
- "type":"esp32-fota-http",
- "version":"0.0.3",
- "url":"http://192.168.0.100/fota/esp32-fota-0.0.3.bin",
- "spiffs":"http://192.168.0.100/fota/esp32-fota-0.0.3.spiffs.bin"
- }
-]
-```
-
-
-
-
-#### Filesystem image (spiffs/littlefs)
-
-Adding `spiffs` key to the JSON entry will end up with the filesystem being updated first, then the firmware.
-
-Obviously don't use the filesystem you're updating to store certificates needed by the update, spiffs partition
-doesn't have redundancy like OTA0/OTA1 and won't recover from a failed update without a restart and format.
-
-```json
-{
- "type": "esp32-fota-http",
- "version": 2,
- "host": "192.168.0.100",
- "port": 80,
- "bin": "/fota/esp32-fota-http-2.bin",
- "spiffs": "/fota/default_spiffs.bin"
-}
-```
-
-Other accepted keys for filesystems are `spiffs`, `littlefs` and `fatfs`.
-Picking one or another doesn't make any difference yet.
-
-
-#### Firmware types
-
-Types are used to compare with the current loaded firmware, this is used to make sure that when loaded, the device will still do the intended job.
-
-As an example, a device used as a data logger should ony be updated with new versions of the data logger.
-
-##### examples
-
-- TTGO-T8-ESP32-Logger
-- TTGO-T8-ESP32-Temp
-- TTGO-T8-ESP32-Relay
-
-
-### Debug
-
-Messages depends of build level. If you pass -D CORE_DEBUG_LEVEL=3 to build flags, it enable the messages
-
-### Sketch
-
-In this early init example, a version 1 of 'esp32-fota-http' is in use, it would be updated when using the JSON example.
-
-```cpp
-#include
-
-const char *ssid = "";
-const char *password = "";
-
-esp32FOTA esp32FOTA("esp32-fota-http", "1.0.0");
-
-const char* manifest_url = "http://server/fota/fota.json";
-
-void setup()
-{
- Serial.begin(115200);
- setup_wifi();
- esp32FOTA.setManifestURL( manifest_url );
- // esp32FOTA.useDeviceId( true ); // optionally append the device ID to the HTTP query
-}
-
-void setup_wifi()
-{
- delay(10);
- Serial.print("Connecting to ");
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
-}
-
-void loop()
-{
- esp32FOTA.handle();
- // or ...
- // bool updatedNeeded = esp32FOTA.execHTTPcheck();
- // if (updatedNeeded) {
- // esp32FOTA.execOTA();
- // }
- delay(2000);
-}
-```
-
-
-Late init is possible using `FOTAConfig_t`, allowing more complex configurations:
-
-```cpp
-#include // include filesystem *before* esp32FOTA librart
-#include
-
-esp32FOTA FOTA;
-
-const char* manifest_url = "http://server/fota/fota.json";
-const char* fota_name = "esp32-fota-http";
-
-// CryptoFileAsset *MyRootCA = new CryptoFileAsset( "/root_ca.pem", &SPIFFS );
-// CryptoFileAsset *MyRSAKey = new CryptoFileAsset( "/rsa_key.pub", &SD );
-
-void setup()
-{
- Serial.begin( 115200 );
- setup_wifi();
-
- {
- auto cfg = FOTA.getConfig();
- cfg.name = fota_name;
- cfg.manifest_url = manifest_url;
- cfg.sem = SemverClass( 1, 0, 0 ); // major, minor, patch
- cfg.check_sig = false; // verify signed firmware with rsa public key
- cfg.unsafe = true; // disable certificate check when using TLS
- //cfg.root_ca = MyRootCA;
- //cfg.pub_key = MyRSAKey;
- //cfg.use_device_id = false;
- FOTA.setConfig( cfg );
- }
-}
-
-void loop()
-{
- esp32FOTA.handle();
- // or ...
- // bool updatedNeeded = esp32FOTA.execHTTPcheck();
- // if (updatedNeeded) {
- // esp32FOTA.execOTA();
- // }
- delay(2000);
-}
-
-```
-
-
-### Zlib/gzip support
-
-⚠️ This feature cannot be used with signature check.
-
-
-For firmwares compressed with `pigz` utility (see , file extension must be `.zz`:
-
-```cpp
-#include // http://github.com/vortigont/esp32-flashz
-#include
-```
-
-```bash
-$ pigz -9kzc esp32-fota-http-2.bin > esp32-fota-http-2.bin.zz
-```
-
-```json
-{
- "type": "esp32-fota-http",
- "version": "2.5.1",
- "url": "http://192.168.0.100/fota/esp32-fota-http-2.bin.zz"
-}
-```
-
-
-For firmwares compressed with `gzip` utility, file extension must be `.gz`
-
-```cpp
-#include // http://github.com/tobozo/ESP32-targz
-#include
-```
-
-```bash
-$ gzip -c esp32-fota-http-2.bin > esp32-fota-http-2.bin.gz
-```
-
-```json
-{
- "type": "esp32-fota-http",
- "version": "2.5.1",
- "url": "http://192.168.0.100/fota/esp32-fota-http-2.bin.gz"
-}
-```
-
-
-
-
-
-
-### Root Certificates
-
-Certificates and signatures can be stored in different places: any fs::FS filesystem or progmem as const char*.
-
-Filesystems:
-
-```C++
-CryptoFileAsset *MyRootCA = new CryptoFileAsset( "/root_ca.pem", &SPIFFS );
-```
-
-```C++
-CryptoFileAsset *MyRootCA = new CryptoFileAsset( "/root_ca.pem", &LittleFS );
-```
-
-```C++
-CryptoFileAsset *MyRootCA = new CryptoFileAsset( "/root_ca.pem", &SD );
-```
-
-Progmem:
-
-```C++
-const char* root_ca = R"ROOT_CA(
------BEGIN CERTIFICATE-----
-MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
-MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
-d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
-QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
-MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
-b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
-9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
-CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
-nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
-43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
-T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
-gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
-BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
-TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
-DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
-hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
-06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
-PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
-YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
-CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
------END CERTIFICATE-----
-)ROOT_CA";
-
-// mixed sources is possible
-CryptoMemAsset *MyRootCA = new CryptoMemAsset("Root CA", root_ca, strlen(root_ca)+1 );
-CryptoFileAsset *MyPubKey = new CryptoFileAsset("RSA Key", "/rsa_key.pub", &SD);
-
-```
-
-Then later in the `setup()`:
-
-```C++
-
-const char* manifest_url = "http://server/fota/fota.json";
-
-void setup()
-{
- // (...)
- esp32FOTA.setManifestURL( manifest_url );
- esp32FOTA.setRootCA( MyRootCA );
- esp32FOTA.setPubKey( MyPubKey );
-}
-
-```
-
-
-# Update callbacks
-
-
-## Progress callback
-
-Can be used to draw a progress bar e.g. on a TFT.
-
-The callback signature is: `void my_progress_callback( size_t progress, size_t size);`, lambda functions are accepted.
-
-Use `esp32FOTA.setProgressCb( my_progress_callback )` to attach the callback.
-
-This method is aliased to Update.h `onProgress()` feature and defaults to printing dots in the serial console.
-
-```C++
-void my_progress_callback( size_t progress, size_t size )
-{
- if( progress == size || progress == 0 ) Serial.println();
- Serial.print(".");
-}
-
-void setup()
-{
- // (...)
-
- // usage with callback function:
- esp32FOTA.setProgressCb( my_progress_callback ) ;
-
- // usage with lambda function:
- esp32FOTA.setProgressCb( [](size_t progress, size_t size) {
- if( progress == size || progress == 0 ) Serial.println();
- Serial.print(".");
- });
-}
-```
-
-
-## Update begin-fail callback
-
-- Description: fired when Update.begin() failed
-- Callback type: `void(int partition)`
-- Callback setter: `setUpdateBeginFailCb( cb )`
-- Usage:
-
-```cpp
-esp32FOTA.setUpdateBeginFailCb( [](int partition) {
- Serial.printf("Update could not begin with %s partition\n", partition==U_SPIFFS ? "spiffs" : "firmware" );
-});
-```
-
-## Update end callback
-
-- Description: fired after Update.end() and before signature check
-- Callback type: `void(int partition)`
-- Callback setter: `setUpdateEndCb( cb )`
-- Usage:
-
-```cpp
-esp32FOTA.setUpdateEndCb( [](int partition) {
- Serial.printf("Update could not finish with %s partition\n", partition==U_SPIFFS ? "spiffs" : "firmware" );
-});
-```
-
-
-## Update check-fail callback
-
-- Description: fired when partition or signature check failed
-- Callback type: `void(int partition, int update_error_code)`
-- Callback setter: `setUpdateCheckFailCb( cb )`
-- Usage:
-
-```cpp
-esp32FOTA.setUpdateCheckFailCb( [](int partition, int error_code) {
- Serial.printf("Update could validate %s partition (error %d)\n", partition==U_SPIFFS ? "spiffs" : "firmware", error_code );
- // error codes:
- // -1 : partition not found
- // -2 : validation (signature check) failed
-});
-```
-
-
-## Update finished callback
-
-- Description: fired update is complete
-- Callback type: `void(int partition, bool needs_restart)`
-- Callback setter: `setUpdateFinishedCb( cb )`
-- Usage:
-
-```cpp
-esp32FOTA.setUpdateFinishedCb( [](int partition, bool restart_after) {
- Serial.printf("Update could not begin with %s partition\n", partition==U_SPIFFS ? "spiffs" : "firmware" );
- // do some stuff e.g. notify a MQTT server the update completed successfully
- if( restart_after ) {
- ESP.restart();
- }
-});
-```
-
-
-
-
-
-
-### Verified images via signature
-
-You can now sign your firmware image with an RSA public/private key pair and have the ESP32 check if the signature is correct before
-it switches over to the new image.
-
-In order to use this feature just set the boolean `validate` to `true` in the constructor. Next create a key-pair to sign your firmware image:
-```
-openssl genrsa -out priv_key.pem 4096
-openssl rsa -in priv_key.pem -pubout > rsa_key.pub
-```
-
-Compile your code so you get your OTA update file (e.g. `firmware.bin`). Now it's time to create the signature:
-```
-# Create signature file
-openssl dgst -sign priv_key.pem -keyform PEM -sha256 -out firmware.sign -binary firmware.bin
-
-# throw it all in one file
-cat firmware.sign firmware.bin > firmware.img
-```
-
-Upload `firmware.img` to your OTA server and point to it in your `firmware.json`
-
-Last step, create an SPIFFS partition with your `rsa_key.pub` in it. The OTA update should not touch this partition during the update. You'll only need to distribute this partition once.
-
-On the next update-check the ESP32 will download the `firmware.img` extract the first 512 bytes with the signature and check it together with the public key against the new image. If the signature check runs OK, it'll reset into the new firmware.
-
-
-
-[#8]: https://github.com/chrisjoyce911/esp32FOTA/issues/8
-[#15]: https://github.com/chrisjoyce911/esp32FOTA/issues/15
-[#25]: https://github.com/chrisjoyce911/esp32FOTA/issues/25
-[#26]: https://github.com/chrisjoyce911/esp32FOTA/issues/26
-[#60]: https://github.com/chrisjoyce911/esp32FOTA/issues/60
-[#65]: https://github.com/chrisjoyce911/esp32FOTA/issues/65
-[#74]: https://github.com/chrisjoyce911/esp32FOTA/issues/74
-[#47]: https://github.com/chrisjoyce911/esp32FOTA/pull/47
-[#79]: https://github.com/chrisjoyce911/esp32FOTA/pull/79
-[#91]: https://github.com/chrisjoyce911/esp32FOTA/pull/91
-[#92]: https://github.com/chrisjoyce911/esp32FOTA/pull/92
-
-
-### Libraries
-
-This library relies on [semver.c by h2non](https://github.com/h2non/semver.c) for semantic versioning support. semver.c is licensed under [MIT](https://github.com/h2non/semver.c/blob/master/LICENSE).
-
-Optional dependencies (zlib/gzip support):
-* [esp32-flashz](https://github.com/vortigont/esp32-flashz)
-* [esp32-targz](https://github.com/tobozo/ESP32-targz)
-
-
-### Thanks to
-
-* @nuclearcat
-* @thinksilicon
-* @tuan-karma
-* @hpsaturn
-* @tobozo
-* @vortigont
-
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTP/HTTP.ino b/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTP/HTTP.ino
deleted file mode 100644
index 0f58694..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTP/HTTP.ino
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- esp32 firmware OTA
-
- Purpose: Perform an OTA update from a bin located on a webserver (HTTP Only)
-
- Setup:
- Step 1 : Set your WiFi (ssid & password)
- Step 2 : set esp32fota()
-
- Upload:
- Step 1 : Menu > Sketch > Export Compiled Library. The bin file will be saved in the sketch folder (Menu > Sketch > Show Sketch folder)
- Step 2 : Upload it to your webserver
- Step 3 : Update your firmware JSON file ( see firwmareupdate )
-
-*/
-
-#include
-#include
-
-
-// esp32fota esp32fota("", , );
-esp32FOTA esp32FOTA("esp32-fota-http", 1, false);
-
-const char* manifest_url = "http://server/fota/fota.json";
-
-void setup_wifi()
-{
- delay(10);
- Serial.print("Connecting to WiFi");
- WiFi.begin(); // no WiFi creds in this demo :-)
-
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.println(WiFi.localIP());
-}
-
-void setup()
-{
- Serial.begin(115200);
- esp32FOTA.setManifestURL( manifest_url );
- esp32FOTA.printConfig();
- setup_wifi();
-}
-
-void loop()
-{
-
- bool updatedNeeded = esp32FOTA.execHTTPcheck();
- if (updatedNeeded)
- {
- esp32FOTA.execOTA();
- }
-
- delay(2000);
-}
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTPS/HTTPS.ino b/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTPS/HTTPS.ino
deleted file mode 100644
index dfbab0e..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTPS/HTTPS.ino
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- esp32 firmware OTA
-
- Purpose: Perform an OTA update from a bin located on a webserver (HTTPS)
-
- Setup:
- Step 1 : Set your WiFi (ssid & password)
- Step 2 : set esp32fota()
- Step 3 : Provide SPIFFS filesystem with root_ca.pem of your webserver
-
- Upload:
- Step 1 : Menu > Sketch > Export Compiled Library. The bin file will be saved in the sketch folder (Menu > Sketch > Show Sketch folder)
- Step 2 : Upload it to your webserver
- Step 3 : Update your firmware JSON file ( see firwmareupdate )
-
-*/
-
-#include
-
-#include
-
-#include
-#include
-#include
-
-
-// esp32fota esp32fota("", , );
-esp32FOTA esp32FOTA("esp32-fota-http", 1, false);
-const char* manifest_url = "https://server/fota/fota.json";
-
-CryptoFileAsset *MyRootCA = new CryptoFileAsset( "/root_ca.pem", &SPIFFS );
-
-void setup_wifi()
-{
- delay(10);
- Serial.print("Connecting to WiFi");
-
- WiFi.begin(); // no WiFi creds in this demo :-)
-
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.println(WiFi.localIP());
-}
-
-void setup()
-{
- Serial.begin(115200);
- // Provide spiffs with root_ca.pem to validate server certificate
- SPIFFS.begin(true);
- esp32FOTA.setManifestURL( manifest_url );
- esp32FOTA.setRootCA( MyRootCA );
- esp32FOTA.printConfig();
- setup_wifi();
-}
-
-void loop()
-{
-
- bool updatedNeeded = esp32FOTA.execHTTPcheck();
- if (updatedNeeded)
- {
- esp32FOTA.execOTA();
- }
-
- delay(2000);
-}
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTPS_without_root_cert/HTTPS_without_root_cert.ino b/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTPS_without_root_cert/HTTPS_without_root_cert.ino
deleted file mode 100644
index ac19647..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTPS_without_root_cert/HTTPS_without_root_cert.ino
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- esp32 firmware OTA
-
- Purpose: Perform an OTA update from a bin located on a webserver (HTTPS) without having a root cert
-
- Setup:
- Step 1 : Set your WiFi (ssid & password)
- Step 2 : set esp32fota()
-
- Upload:
- Step 1 : Menu > Sketch > Export Compiled Library. The bin file will be saved in the sketch folder (Menu > Sketch > Show Sketch folder)
- Step 2 : Upload it to your webserver
- Step 3 : Update your firmware JSON file ( see firwmareupdate )
-
-*/
-
-#include
-
-#include
-
-#include
-#include
-#include
-
-
-// esp32fota esp32fota("", , , );
-esp32FOTA esp32FOTA("esp32-fota-http", 1, false, true);
-const char* manifest_url = "http://server/fota/fota.json";
-
-void setup_wifi()
-{
- delay(10);
- Serial.print("Connecting to WiFi");
-
- WiFi.begin(); // no WiFi creds in this demo :-)
-
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.println(WiFi.localIP());
-}
-
-void setup()
-{
- Serial.begin(115200);
- esp32FOTA.setManifestURL( manifest_url );
- esp32FOTA.printConfig();
- setup_wifi();
-}
-
-void loop()
-{
-
- bool updatedNeeded = esp32FOTA.execHTTPcheck();
- if (updatedNeeded)
- {
- esp32FOTA.execOTA();
- }
-
- delay(2000);
-}
diff --git a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTP_signature_check/HTTP_signature_check.ino b/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTP_signature_check/HTTP_signature_check.ino
deleted file mode 100644
index ae56dff..0000000
--- a/SmartEVSE-3/SmartEVSE-3/lib/esp32FOTA/examples/HTTP/HTTP_signature_check/HTTP_signature_check.ino
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- esp32 firmware OTA
-
- Purpose: Perform an OTA update from a bin located on a webserver (HTTP Only)
-
- Setup:
- Step 1 : Set your WiFi (ssid & password)
- Step 2 : set esp32fota()
-
- Upload:
- Step 1 : Menu > Sketch > Export Compiled Library. The bin file will be saved in the sketch folder (Menu > Sketch > Show Sketch folder)
- Step 2 : Upload it to your webserver
- Step 3 : Update your firmware JSON file ( see firwmareupdate )
-
-*/
-#include