Skip to content

Commit a1f4e57

Browse files
authored
Rework backend add MQTT and WebSocket support
* Update back end to add MQTT and WebSocket support * Update demo project to demonstrate MQTT and WebSockets * Update documentation to describe newly added and modified functionallity * Introduce separate MQTT pub/sub, HTTP get/post and WebSocket rx/tx classes * Significant reanaming - more accurate class names * Use PROGMEM_WWW as default * Update README documenting PROGMEM_WWW as default * Update README with API changes
1 parent c47ea49 commit a1f4e57

File tree

77 files changed

+2877
-1162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2877
-1162
lines changed

README.md

Lines changed: 236 additions & 128 deletions
Large diffs are not rendered by default.

data/config/demoSettings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

data/config/mqttSettings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"enabled": false,
3+
"host": "test.mosquitto.org",
4+
"port": 1883,
5+
"authenticated": false,
6+
"username": "mqttuser",
7+
"password": "mqttpassword",
8+
"keepAlive": 16,
9+
"cleanSession": true,
10+
"maxTopicLength": 128
11+
}

interface/.env.development

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Change the IP address to that of your ESP device to enable local development of the UI.
22
# Remember to also enable CORS in platformio.ini before uploading the code to the device.
3-
REACT_APP_ENDPOINT_ROOT=http://192.168.0.21/rest/
3+
REACT_APP_HTTP_ROOT=http://192.168.0.99
4+
REACT_APP_WEB_SOCKET_ROOT=ws://192.168.0.99

interface/.env.production

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
REACT_APP_ENDPOINT_ROOT=/rest/
21
GENERATE_SOURCEMAP=false

interface/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

interface/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@material-ui/core": "^4.9.8",
77
"@material-ui/icons": "^4.9.1",
88
"@types/jwt-decode": "^2.2.1",
9+
"@types/lodash": "^4.14.149",
910
"@types/node": "^12.12.32",
1011
"@types/react": "^16.9.27",
1112
"@types/react-dom": "^16.9.5",
@@ -14,6 +15,7 @@
1415
"@types/react-router-dom": "^5.1.3",
1516
"compression-webpack-plugin": "^3.0.1",
1617
"jwt-decode": "^2.2.0",
18+
"lodash": "^4.17.15",
1719
"mime-types": "^2.1.25",
1820
"moment": "^2.24.0",
1921
"notistack": "^0.9.7",
@@ -24,6 +26,7 @@
2426
"react-router": "^5.1.2",
2527
"react-router-dom": "^5.1.2",
2628
"react-scripts": "3.4.1",
29+
"sockette": "^2.0.6",
2730
"typescript": "^3.7.5",
2831
"zlib": "^1.0.5"
2932
},

interface/src/AppRouting.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Security from './security/Security';
1515
import System from './system/System';
1616

1717
import { PROJECT_PATH } from './api';
18+
import Mqtt from './mqtt/Mqtt';
1819

1920
class AppRouting extends Component {
2021

@@ -31,6 +32,7 @@ class AppRouting extends Component {
3132
<AuthenticatedRoute exact path="/wifi/*" component={WiFiConnection} />
3233
<AuthenticatedRoute exact path="/ap/*" component={AccessPoint} />
3334
<AuthenticatedRoute exact path="/ntp/*" component={NetworkTime} />
35+
<AuthenticatedRoute exact path="/mqtt/*" component={Mqtt} />
3436
<AuthenticatedRoute exact path="/security/*" component={Security} />
3537
<AuthenticatedRoute exact path="/system/*" component={System} />
3638
<Redirect to="/" />

interface/src/api/Endpoints.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const LIST_NETWORKS_ENDPOINT = ENDPOINT_ROOT + "listNetworks";
99
export const WIFI_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "wifiSettings";
1010
export const WIFI_STATUS_ENDPOINT = ENDPOINT_ROOT + "wifiStatus";
1111
export const OTA_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "otaSettings";
12+
export const MQTT_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "mqttSettings";
13+
export const MQTT_STATUS_ENDPOINT = ENDPOINT_ROOT + "mqttStatus";
1214
export const SYSTEM_STATUS_ENDPOINT = ENDPOINT_ROOT + "systemStatus";
1315
export const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn";
1416
export const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization";

interface/src/api/Env.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
export const PROJECT_NAME = process.env.REACT_APP_PROJECT_NAME!;
22
export const PROJECT_PATH = process.env.REACT_APP_PROJECT_PATH!;
3-
export const ENDPOINT_ROOT = process.env.REACT_APP_ENDPOINT_ROOT!;
3+
4+
export const ENDPOINT_ROOT = calculateEndpointRoot("/rest/");
5+
export const WEB_SOCKET_ROOT = calculateWebSocketRoot("/ws/");
6+
7+
function calculateEndpointRoot(endpointPath: string) {
8+
const httpRoot = process.env.REACT_APP_HTTP_ROOT;
9+
if (httpRoot) {
10+
return httpRoot + endpointPath;
11+
}
12+
const location = window.location;
13+
return location.protocol + "//" + location.host + endpointPath;
14+
}
15+
16+
function calculateWebSocketRoot(webSocketPath: string) {
17+
const webSocketRoot = process.env.REACT_APP_WEB_SOCKET_ROOT;
18+
if (webSocketRoot) {
19+
return webSocketRoot + webSocketPath;
20+
}
21+
const location = window.location;
22+
const webProtocol = location.protocol === "https:" ? "wss:" : "ws:";
23+
return webProtocol + "//" + location.host + webSocketPath;
24+
}

0 commit comments

Comments
 (0)