Skip to content

Commit 4d97730

Browse files
Fixed issues and extended documentation
1 parent 23567a3 commit 4d97730

9 files changed

Lines changed: 203 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Ubuntu 20.04 and contains all necessary dependencies.
2424
Firstly, build the image:
2525

2626
```shell
27-
docker build -t matthx/microocppsimulator:latest .
27+
docker build -t northprim/microocppsimulator:latest .
2828
```
2929

3030
Then run the image:
3131

3232
```shell
33-
docker run -p 8000:8000 matthx/microocppsimulator:latest
33+
docker run -p 8000:8000 northprim/microocppsimulator:latest
3434
```
3535

3636
The Simulator should be up and running now on [localhost:8000](http://localhost:8000).
@@ -51,7 +51,7 @@ sudo apt install cmake libssl-dev build-essential
5151
Navigate to the preferred installation directory or just to the home folder. Clone the Simulator and all submodules:
5252

5353
```shell
54-
git clone --recurse-submodules https://github.com/matth-x/MicroOcppSimulator
54+
git clone --recurse-submodules https://github.com/northprim/MicroOcppSimulator
5555
```
5656

5757
Navigate to the copy of the Simulator and build:

ReverseProxy.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Conceptual Overview
2+
3+
A reverse proxy acts as an intermediary server that sits between clients and your backend application. In this configuration:
4+
5+
- Nginx listens on ports 80 (HTTP) and 443 (HTTPS)
6+
- It forwards incoming requests to your MicroOcpp application on port 8000
7+
- All communication appears to come directly from your domain to users
8+
9+
# Prerequisites
10+
11+
1. Nginx installed on your system
12+
2. MicroOcpp running on port 8000
13+
3. Domain name (for SSL certificates)
14+
4. Root access to your server
15+
16+
# Step-by-Step Configuration
17+
18+
1. Instal Nginx (if not installed)
19+
```
20+
sudo apt update
21+
sudo apt install nginx
22+
```
23+
24+
2. Create a configuration file
25+
```
26+
sudo nano /etc/nginx/sites-available/mo_simulator.conf
27+
```
28+
29+
4. Add reverse proxy configuration mapping 80 and 443 to 8000
30+
```
31+
server {
32+
listen 80;
33+
server_name 10.199.67.55;
34+
35+
location / {
36+
proxy_pass http://10.199.67.55:8000;
37+
proxy_set_header Host $host;
38+
proxy_set_header X-Real-IP $remote_addr;
39+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
40+
proxy_set_header X-Forwarded-Proto $scheme;
41+
}
42+
}
43+
44+
server {
45+
listen 443 ssl;
46+
server_name 10.199.67.55;
47+
48+
ssl_certificate /etc/nginx/certs/selfsigned.crt;
49+
ssl_certificate_key /etc/nginx/certs/selfsigned.key;
50+
51+
ssl_protocols TLSv1.2 TLSv1.3;
52+
ssl_ciphers HIGH:!aNULL:!MD5;
53+
54+
location / {
55+
proxy_pass http://10.199.67.55:8000;
56+
proxy_set_header Host $host;
57+
proxy_set_header X-Real-IP $remote_addr;
58+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
59+
proxy_set_header X-Forwarded-Proto $scheme;
60+
}
61+
}
62+
```
63+
64+
5. Security Considerations
65+
- SSL Certificate Setup
66+
Generate self-signed certificate (development):
67+
```
68+
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
69+
-keyout /etc/nginx/certs/selfsigned.key \
70+
-out /etc/nginx/certs/selfsigned.crt \
71+
-subj "/C=SWE/ST=Uppland/L=se/O=OKQ8/CN=microocp-simulator"
72+
```
73+
74+
- Firewall Configuration, firewall may cause problems with RDC and SSH
75+
```
76+
sudo ufw allow ssh
77+
sudo ufw allow 3389
78+
sudo ufw allow http
79+
sudo ufw allow https
80+
sudo ufw enable
81+
```
82+
83+
6. Enable the configuration
84+
```
85+
sudo ln -s /etc/nginx/sites-available/mo_simulator.conf /etc/nginx/sites-enabled/
86+
sudo nginx -t
87+
```
88+
89+
7. Restart Nginx
90+
```
91+
sudo systemctl restart nginx
92+
```
93+
94+
8. Troubleshooting Tips
95+
- Check Nginx logs for errors:
96+
```
97+
tail -f /var/log/nginx/error.log
98+
```
99+
- Verify MicroOcpp is accessible
100+
```
101+
curl 10.199.67.55:80
102+
curl 10.199.67.55:8000
103+
curl -I 10.199.67.55:80
104+
curl -I 10.199.67.55:8000
105+
```
106+
- Test both HTTP and HTTPS connections
107+
```
108+
curl http://10.199.67.55
109+
curl https://10.199.67.55
110+
```
111+
- List TCP Listened ports
112+
```
113+
ss -lntp
114+
```

mo_simulator_as_a_service.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Create mo_simulator service
2+
3+
## Step 1: Create a Service File
4+
```
5+
sudo nano /etc/systemd/system/mo_simulator.service
6+
```
7+
## Step 2: Add following configuration to the Service File
8+
```
9+
[Unit]
10+
Description=Mo Simulator Service
11+
After=network.target
12+
13+
[Service]
14+
Type=simple
15+
ExecStart=/home/azadmin/MicroOcppSimulator/build/mo_simulator # Change to appropriate full executable path
16+
WorkingDirectory=/home/azadmin/MicroOcppSimulator # Change to appropriate full working directory path
17+
Restart=always
18+
RestartSec=5
19+
User=azadmin # Change to appropriate user
20+
StandardOutput=syslog
21+
StandardError=syslog
22+
23+
[Install]
24+
WantedBy=multi-user.target
25+
```
26+
## Step 3: Enable and start Service
27+
```
28+
sudo systemctl daemon-reload
29+
sudo systemctl enable mo_simulator
30+
sudo systemctl start mo_simulator
31+
```
32+
## Step 4: Managing Your Service
33+
```
34+
# Start the service
35+
sudo systemctl start mo_simulator
36+
37+
# Stop the service
38+
sudo systemctl stop mo_simulator
39+
40+
# Check status
41+
sudo systemctl status mo_simulator
42+
43+
# View logs
44+
journalctl -u mo_simulator -f
45+
```
46+
47+
# Important Considerations
48+
49+
## Make sure your executable has proper permissions:
50+
```
51+
chmod +x /home/azadmin/MicroOcppSimulator/build/mo_simulator
52+
```
53+
## Test the service thoroughly after setup:
54+
```
55+
sudo systemctl restart mo_simulator
56+
sleep 5
57+
sudo systemctl status mo_simulator
58+
```
59+
## Monitor logs regularly for issues:
60+
```
61+
journalctl -u mo_simulator -n 100 --no-pager
62+
```

public/bundle.html

Lines changed: 18 additions & 0 deletions
Large diffs are not rendered by default.

public/bundle.html.gz

-35.8 KB
Binary file not shown.

src/evse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void Evse::loop() {
126126
status = MicroOcpp::cstrFromOcppEveState(curStatus);
127127
}
128128

129-
bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvsePluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool();
129+
bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool();
130130

131131
simulate_isCharging &= limit_power >= 720.f; //minimum charging current is 6A (720W for 120V grids) according to J1772
132132

src/evse.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Evse {
2626
std::string trackEvseReadyKey;
2727

2828
const float SIMULATE_POWER_CONST = 11000.f;
29-
float simulate_power = 0;
29+
float simulate_power = 1;
3030
float limit_power = 11000.f;
3131
const float SIMULATE_ENERGY_DELTA_MS = SIMULATE_POWER_CONST / (3600.f * 1000.f);
32-
unsigned long simulate_energy_track_time = 0;
33-
float simulate_energy = 0;
32+
unsigned long simulate_energy_track_time = 1;
33+
float simulate_energy = 1;
3434

3535
std::string status;
3636
public:

src/net_mongoose.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data) {
151151
struct mg_http_serve_opts opts;
152152
memset(&opts, 0, sizeof(opts));
153153
opts.root_dir = "./public";
154-
opts.extra_headers = "Content-Type: text/html\r\nContent-Encoding: gzip\r\n";
155-
mg_http_serve_file(c, message_data, "public/bundle.html.gz", &opts);
154+
mg_http_serve_file(c, message_data, "public/bundle.html", &opts);
156155
} else {
157156
mg_http_reply(c, 404, final_headers, "API endpoint not found");
158157
}

webapp-src

Submodule webapp-src updated 1 file

0 commit comments

Comments
 (0)