From 11b5ca27a757b236b92dbaf1697e5b90379c212a Mon Sep 17 00:00:00 2001 From: Miroslav Novta Date: Mon, 17 Mar 2025 21:14:49 +0100 Subject: [PATCH 1/4] Fixed issue #36 - Energy, Power, Current, Voltage value are always 0 --- .gitmodules | 12 +++---- .vscode/settings.json | 81 +++++++++++++++++++++++++++++++++++++++++++ lib/ArduinoJson | 2 +- lib/MicroOcpp | 2 +- lib/MicroOcppMongoose | 2 +- lib/mongoose | 2 +- src/evse.cpp | 3 +- src/evse.h | 8 ++--- src/main.cpp | 4 +-- webapp-src | 2 +- 10 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitmodules b/.gitmodules index ceb826b..6d2d705 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +1,18 @@ [submodule "lib/ArduinoJson"] path = lib/ArduinoJson - url = https://github.com/bblanchon/ArduinoJson.git + url = https://github.com/novta/ArduinoJson.git [submodule "lib/MicroOcpp"] path = lib/MicroOcpp - url = https://github.com/matth-x/MicroOcpp + url = https://github.com/novta/MicroOcpp [submodule "lib/MicroOcppMongoose"] path = lib/MicroOcppMongoose - url = https://github.com/matth-x/MicroOcppMongoose + url = https://github.com/novta/MicroOcppMongoose [submodule "lib/mongoose"] path = lib/mongoose - url = https://github.com/cesanta/mongoose + url = https://github.com/novta/mongoose [submodule "webapp-src"] path = webapp-src - url = https://github.com/agruenb/arduino-ocpp-dashboard.git + url = https://github.com/novta/arduino-ocpp-dashboard.git [submodule "lib/mbedtls"] path = lib/mbedtls - url = https://github.com/Mbed-TLS/mbedtls + url = https://github.com/novta/mbedtls diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ffe4200 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,81 @@ +{ + "files.associations": { + "memory": "cpp", + "limits": "cpp", + "xutility": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ostream": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "variant": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp" + } +} \ No newline at end of file diff --git a/lib/ArduinoJson b/lib/ArduinoJson index b350a96..8f7e793 160000 --- a/lib/ArduinoJson +++ b/lib/ArduinoJson @@ -1 +1 @@ -Subproject commit b350a9664370f37654a406d75f99b1e5b3a2d637 +Subproject commit 8f7e793f37bff2ebcc806e92245f1540452ef9f3 diff --git a/lib/MicroOcpp b/lib/MicroOcpp index 4b89f46..4b080f6 160000 --- a/lib/MicroOcpp +++ b/lib/MicroOcpp @@ -1 +1 @@ -Subproject commit 4b89f4649d65c83cc559e4cc7c65f430db482217 +Subproject commit 4b080f63847e6f5b1328a205edfbf8906ab0e720 diff --git a/lib/MicroOcppMongoose b/lib/MicroOcppMongoose index e228297..2bbf03a 160000 --- a/lib/MicroOcppMongoose +++ b/lib/MicroOcppMongoose @@ -1 +1 @@ -Subproject commit e2282976eed4b98e200e5987f2dded5313902cab +Subproject commit 2bbf03a34d8246770b692e11fcc686405d446a93 diff --git a/lib/mongoose b/lib/mongoose index 9729693..3882b5d 160000 --- a/lib/mongoose +++ b/lib/mongoose @@ -1 +1 @@ -Subproject commit 97296934ab594241ba2489f018a21779882a7936 +Subproject commit 3882b5d74259553f9facc4ccfabb4abc5991f23c diff --git a/src/evse.cpp b/src/evse.cpp index a0261d6..a112f39 100644 --- a/src/evse.cpp +++ b/src/evse.cpp @@ -126,7 +126,8 @@ void Evse::loop() { status = MicroOcpp::cstrFromOcppEveState(curStatus); } - bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvsePluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool(); + // bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvsePluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool(); + bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool(); simulate_isCharging &= limit_power >= 720.f; //minimum charging current is 6A (720W for 120V grids) according to J1772 diff --git a/src/evse.h b/src/evse.h index eaf37dc..fdfb11c 100644 --- a/src/evse.h +++ b/src/evse.h @@ -26,12 +26,12 @@ class Evse { std::string trackEvseReadyKey; const float SIMULATE_POWER_CONST = 11000.f; - float simulate_power = 0; + float simulate_power = 1; float limit_power = 11000.f; const float SIMULATE_ENERGY_DELTA_MS = SIMULATE_POWER_CONST / (3600.f * 1000.f); - unsigned long simulate_energy_track_time = 0; - float simulate_energy = 0; - + unsigned long simulate_energy_track_time = 10; + float simulate_energy = 1; + std::string status; public: Evse(unsigned int connectorId); diff --git a/src/main.cpp b/src/main.cpp index 0e945fd..789a23c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -166,8 +166,8 @@ int main() { mg_http_listen(&mgr, api_url, http_serve, (void*)api_url); // Create listening connection osock = new MicroOcpp::MOcppMongooseClient(&mgr, - "ws://echo.websocket.events", - "charger-01", + "wss://ocpp-j-15-16-pub.device-test.virta-ev.com", // "ws://echo.websocket.events", + "okq8_microocpp_01", // "charger-01", "", "", filesystem, diff --git a/webapp-src b/webapp-src index 015a0e8..33a3182 160000 --- a/webapp-src +++ b/webapp-src @@ -1 +1 @@ -Subproject commit 015a0e816ca4fc617e67acdbe7d067688d6b3939 +Subproject commit 33a318296a416fad2707051817dbf68506c7a2f9 From bd02d0f6f157958d6b39d4ddc9b39db8d30661d5 Mon Sep 17 00:00:00 2001 From: Miroslav Novta Date: Wed, 30 Apr 2025 16:27:26 +0200 Subject: [PATCH 2/4] Updated documentation and submodule path --- .gitmodules | 2 +- README.md | 25 +++++++++++++------------ webapp-src | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.gitmodules b/.gitmodules index 6d2d705..56134ca 100644 --- a/.gitmodules +++ b/.gitmodules @@ -12,7 +12,7 @@ url = https://github.com/novta/mongoose [submodule "webapp-src"] path = webapp-src - url = https://github.com/novta/arduino-ocpp-dashboard.git + url = https://github.com/novta/micro-ocpp-dashboard.git [submodule "lib/mbedtls"] path = lib/mbedtls url = https://github.com/novta/mbedtls diff --git a/README.md b/README.md index 6ccc07f..5cd55fd 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# Icon   MicroOcppSimulator +# Icon   MicroOcppSimulator -[![Build (Ubuntu)](https://github.com/matth-x/MicroOcppSimulator/workflows/Ubuntu/badge.svg)]((https://github.com/matth-x/MicroOcppSimulator/actions)) -[![Build (Docker)](https://github.com/matth-x/MicroOcppSimulator/workflows/Docker/badge.svg)]((https://github.com/matth-x/MicroOcppSimulator/actions)) -[![Build (WebAssembly)](https://github.com/matth-x/MicroOcppSimulator/workflows/WebAssembly/badge.svg)]((https://github.com/matth-x/MicroOcppSimulator/actions)) +[![Build (Ubuntu)](https://github.com/novta/MicroOcppSimulator/workflows/Ubuntu/badge.svg)]((https://github.com/novta/MicroOcppSimulator/actions)) +[![Build (Docker)](https://github.com/novta/MicroOcppSimulator/workflows/Docker/badge.svg)]((https://github.com/novta/MicroOcppSimulator/actions)) +[![Build (WebAssembly)](https://github.com/novta/MicroOcppSimulator/workflows/WebAssembly/badge.svg)]((https://github.com/novta/MicroOcppSimulator/actions)) -Tester / Demo App for the [MicroOCPP](https://github.com/matth-x/MicroOcpp) Client, running on native Ubuntu, WSL, WebAssembly or MSYS2. Online demo: [Try it](https://demo.micro-ocpp.com/) +Tester / Demo App for the [MicroOCPP](https://github.com/novta/MicroOcpp) Client, running on native Ubuntu, WSL, WebAssembly or MSYS2. Online demo: [Try it](https://demo.micro-ocpp.com/) -[![Screenshot](https://github.com/agruenb/arduino-ocpp-dashboard/blob/master/docs/img/status_page.png)](https://demo.micro-ocpp.com/) +[![Screenshot](https://github.com/novta/micro-ocpp-dashboard/blob/master/docs/img/status_page.png)](https://demo.micro-ocpp.com/) The Simulator has two purposes: - As a development tool, it allows to run MicroOCPP directly on the host computer and simplifies the development (no flashing of the microcontroller required) @@ -24,16 +24,17 @@ Ubuntu 20.04 and contains all necessary dependencies. Firstly, build the image: ```shell -docker build -t matthx/microocppsimulator:latest . +docker build -t novta/microocppsimulator:latest . ``` Then run the image: ```shell -docker run -p 8000:8000 matthx/microocppsimulator:latest +docker run -p 8000:8000 novta/microocppsimulator:latest ``` The Simulator should be up and running now on [localhost:8000](http://localhost:8000). +In the case of running in Azure Virtual Machine localhost is not defined and the real IP address is to be used. Also webapp is to be updated. Follow Readme.md fle for instructions. The .env file is to be created and updated to point the local IP address instead of localhost. ## Installation (Ubuntu or WSL) @@ -51,7 +52,7 @@ sudo apt install cmake libssl-dev build-essential Navigate to the preferred installation directory or just to the home folder. Clone the Simulator and all submodules: ```shell -git clone --recurse-submodules https://github.com/matth-x/MicroOcppSimulator +git clone --recurse-submodules https://github.com/novta/MicroOcppSimulator ``` Navigate to the copy of the Simulator and build: @@ -86,7 +87,7 @@ root directory. For this to work NodeJS, npm and git have to be installed on your machine. The called script automatically performs the following tasks: -- pull the newest version of the the [arduino-ocpp-dashboard](https://github.com/agruenb/arduino-ocpp-dashboard) +- pull the newest version of the the [micro-ocpp-dashboard](https://github.com/novta/micro-ocpp-dashboard) - check if you have added a *.env.production* file - install webapp dependencies - build the webapp @@ -114,10 +115,10 @@ The compiler toolchain should emit the WebAssembly binary and a JavaScript wrapp ./build-webapp/install_webassembly.sh ``` -Now, the GUI can be developed or built as described in the [webapp repository](https://github.com/agruenb/arduino-ocpp-dashboard). +Now, the GUI can be developed or built as described in the [webapp repository](https://github.com/novta/micro-ocpp-dashboard). After building the GUI, the emited files contain the full Simulator functionality. To run the Simualtor, start an HTTP file server in the dist folder and access it with your browser. ## License -This project is licensed under the GPL as it uses the [Mongoose Embedded Networking Library](https://github.com/cesanta/mongoose). If you have a proprietary license of Mongoose, then the [MIT License](https://github.com/matth-x/MicroOcpp/blob/master/LICENSE) applies. +This project is licensed under the GPL as it uses the [Mongoose Embedded Networking Library](https://github.com/novta/mongoose). If you have a proprietary license of Mongoose, then the [MIT License](https://github.com/novta/MicroOcpp/blob/master/LICENSE) applies. diff --git a/webapp-src b/webapp-src index 33a3182..956db2f 160000 --- a/webapp-src +++ b/webapp-src @@ -1 +1 @@ -Subproject commit 33a318296a416fad2707051817dbf68506c7a2f9 +Subproject commit 956db2f99759bf8f22717e31d3eba6e30e6694f0 From 067a301cb0b74692d43c54387e0572b4af786593 Mon Sep 17 00:00:00 2001 From: Miroslav Novta Date: Wed, 7 May 2025 11:26:23 +0200 Subject: [PATCH 3/4] Added steps how to make mo_simulator service --- Create mo_simulator service.md | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Create mo_simulator service.md diff --git a/Create mo_simulator service.md b/Create mo_simulator service.md new file mode 100644 index 0000000..72cbac7 --- /dev/null +++ b/Create mo_simulator service.md @@ -0,0 +1,62 @@ +# Create mo_simulator service + +## Step 1: Create a Service File +``` +sudo nano /etc/systemd/system/mo_simulator.service +``` +## Step 2: Add following configuration to the Service File +``` +[Unit] +Description=Mo Simulator Service +After=network.target + +[Service] +Type=simple +ExecStart=/home/azadmin/MicroOcppSimulator/build/mo_simulator # Change to appropriate full executable path +WorkingDirectory=/home/azadmin/MicroOcppSimulator # Change to appropriate full working directory path +Restart=always +RestartSec=5 +User=azadmin # Change to appropriate user +StandardOutput=syslog +StandardError=syslog + +[Install] +WantedBy=multi-user.target +``` +## Step 3: Enable and start Service +``` +sudo systemctl daemon-reload +sudo systemctl enable mo_simulator +sudo systemctl start mo_simulator +``` +## Step 4: Managing Your Service +``` +# Start the service +sudo systemctl start mo_simulator + +# Stop the service +sudo systemctl stop mo_simulator + +# Check status +sudo systemctl status mo_simulator + +# View logs +journalctl -u mo_simulator -f +``` + +# Important Considerations + +## Make sure your executable has proper permissions: +``` +chmod +x /home/azadmin/MicroOcppSimulator/build/mo_simulator +``` +## Test the service thoroughly after setup: +``` +sudo systemctl restart mo_simulator +sleep 5 +sudo systemctl status mo_simulator +``` +## Monitor logs regularly for issues: +``` +journalctl -u mo_simulator -n 100 --no-pager +``` \ No newline at end of file From ab5b2d92bb22b4c5fe8b0d63ceb7fa3c54009b6e Mon Sep 17 00:00:00 2001 From: Miroslav Novta Date: Mon, 12 May 2025 18:03:43 +0200 Subject: [PATCH 4/4] Added reverse proxy configuration --- reverse_proxy.md | 122 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 reverse_proxy.md diff --git a/reverse_proxy.md b/reverse_proxy.md new file mode 100644 index 0000000..688d09b --- /dev/null +++ b/reverse_proxy.md @@ -0,0 +1,122 @@ +# Conceptual Overview + +A reverse proxy acts as an intermediary server that sits between clients and your backend application. In this configuration: + +- Nginx listens on ports 80 (HTTP) and 443 (HTTPS) +- It forwards incoming requests to your MicroOcpp application on port 8000 +- All communication appears to come directly from your domain to users + +# Prerequisites + +1. Nginx installed on your system +2. MicroOcpp running on port 8000 +3. Domain name (for SSL certificates) +4. Root access to your server + +# Step-by-Step Configuration + +1. Instal Nginx (if not installed) +``` +sudo apt update +sudo apt install nginx +``` + +2. Create a configuration file +``` +sudo nano /etc/nginx/sites-available/mo_simulator.conf +``` + +3. Define domain name in /etc/hosts to point to local IP address, How to make local DNS lookup table +``` +echo "10.199.67.5 microocp-simulator" | sudo tee -a /etc/hosts +``` +In order to check +``` +cat /etc/hosts +``` +and confirm there is +``` +10.199.67.5 microocp-simulator +``` +or +``` +ping microocp-simulator +``` + +4. Add reverse proxy configuration mapping 80 and 443 to 8000 +``` +server { + listen 80; + server_name microocp-simulator; + + location / { + proxy_pass http://0.0.0.0:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} + +server { + listen 443 ssl; + server_name microocp-simulator; + + ssl_certificate /etc/nginx/certs/selfsigned.crt; + ssl_certificate_key /etc/nginx/certs/selfsigned.key; + + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + + location / { + proxy_pass http://0.0.0.0:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` + +5. Security Considerations + - SSL Certificate Setup + Generate self-signed certificate (development): + ``` + sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ + -keyout /etc/nginx/certs/selfsigned.key \ + -out /etc/nginx/certs/selfsigned.crt \ + -subj "/C=SWE/ST=Uppland/L=se/O=OKQ8/CN=microocp-simulator" + ``` + + - Firewall Configuration + ``` + sudo ufw allow http + sudo ufw allow https + sudo ufw enable + ``` + +6. Enable the configuration +``` +sudo ln -s /etc/nginx/sites-available/mo_simulator.conf /etc/nginx/sites-enabled/ +sudo nginx -t +``` + +7. Restart Nginx +``` +sudo systemctl restart nginx +``` + +8. Troubleshooting Tips +- Check Nginx logs for errors: +``` +tail -f /var/log/nginx/error.log +``` +- Verify MicroOcpp is accessible +``` +curl localhost:8000 +``` +- Test both HTTP and HTTPS connections +``` +curl http://microocp-simulator +curl https://microocp-simulator +``` \ No newline at end of file