Skip to content

Commit

Permalink
Changes to support upgrade of platform-espressif32 to 4.3.0 (rjwats#301)
Browse files Browse the repository at this point in the history
* support latest espressif32 PIO platform
* upgrade react, react router, axios and material
  • Loading branch information
rjwats authored May 21, 2022
1 parent baae203 commit 004659b
Show file tree
Hide file tree
Showing 21 changed files with 895 additions and 772 deletions.
1,563 changes: 835 additions & 728 deletions interface/package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
"private": true,
"proxy": "http://192.168.0.23",
"dependencies": {
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@mui/icons-material": "^5.2.4",
"@mui/material": "^5.2.4",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.8.0",
"@mui/material": "^5.8.0",
"@types/lodash": "^4.14.176",
"@types/node": "^16.11.14",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"async-validator": "^4.0.7",
"axios": "^0.24.0",
"@types/react": "^18.0.9",
"@types/react-dom": "^18.0.4",
"async-validator": "^4.1.1",
"axios": "^0.27.2",
"http-proxy-middleware": "^2.0.1",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"notistack": "^2.0.3",
"notistack": "^2.0.5",
"parse-ms": "^3.0.0",
"react": "^17.0.2",
"react": "^18.1.0",
"react-app-rewired": "^2.1.8",
"react-dom": "^17.0.2",
"react-dom": "^18.1.0",
"react-dropzone": "^11.4.2",
"react-router-dom": "^6.0.2",
"react-scripts": "5.0.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"sockette": "^2.0.6",
"typescript": "^4.5.4"
"typescript": "^4.6.4"
},
"scripts": {
"start": "react-app-rewired start",
Expand Down
4 changes: 3 additions & 1 deletion interface/src/CustomTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { CssBaseline } from '@mui/material';
import { createTheme, responsiveFontSizes, ThemeProvider } from '@mui/material/styles';
import { indigo, blueGrey, orange, red, green } from '@mui/material/colors';

import { RequiredChildrenProps } from './utils';

const theme = responsiveFontSizes(
createTheme({
palette: {
Expand All @@ -28,7 +30,7 @@ const theme = responsiveFontSizes(
})
);

const CustomTheme: FC = ({ children }) => (
const CustomTheme: FC<RequiredChildrenProps> = ({ children }) => (
<ThemeProvider theme={theme}>
<CssBaseline />
{children}
Expand Down
4 changes: 3 additions & 1 deletion interface/src/components/SectionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';

import { Paper, Typography } from '@mui/material';

interface SectionContentProps {
import { RequiredChildrenProps } from '../utils';

interface SectionContentProps extends RequiredChildrenProps {
title: string;
titleGutter?: boolean;
}
Expand Down
4 changes: 3 additions & 1 deletion interface/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { useLocation } from 'react-router-dom';
import { Box, Toolbar } from '@mui/material';

import { PROJECT_NAME } from '../../api/env';
import { RequiredChildrenProps } from '../../utils';

import LayoutDrawer from './LayoutDrawer';
import LayoutAppBar from './LayoutAppBar';
import { LayoutContext } from './context';

export const DRAWER_WIDTH = 280;

const Layout: FC = ({ children }) => {
const Layout: FC<RequiredChildrenProps> = ({ children }) => {

const [mobileOpen, setMobileOpen] = useState(false);
const [title, setTitle] = useState(PROJECT_NAME);
Expand Down
3 changes: 2 additions & 1 deletion interface/src/components/routing/RequireAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { FC, useContext } from 'react';
import { Navigate } from "react-router-dom";

import { AuthenticatedContext } from '../../contexts/authentication';
import { RequiredChildrenProps } from '../../utils';

const RequireAdmin: FC = ({ children }) => {
const RequireAdmin: FC<RequiredChildrenProps> = ({ children }) => {
const authenticatedContext = useContext(AuthenticatedContext);
return authenticatedContext.me.admin ? <>{children}</> : <Navigate replace to='/' />;
};
Expand Down
3 changes: 2 additions & 1 deletion interface/src/components/routing/RequireAuthenticated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Navigate, useLocation } from "react-router-dom";

import { AuthenticatedContext, AuthenticatedContextValue, AuthenticationContext } from '../../contexts/authentication/context';
import { storeLoginRedirect } from '../../api/authentication';
import { RequiredChildrenProps } from '../../utils';

const RequireAuthenticated: FC = ({ children }) => {
const RequireAuthenticated: FC<RequiredChildrenProps> = ({ children }) => {
const authenticationContext = useContext(AuthenticationContext);
const location = useLocation();

Expand Down
3 changes: 2 additions & 1 deletion interface/src/components/routing/RequireUnauthenticated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Navigate } from "react-router-dom";

import * as AuthenticationApi from '../../api/authentication';
import { AuthenticationContext } from '../../contexts/authentication';
import { RequiredChildrenProps } from '../../utils';
import { FeaturesContext } from '../../contexts/features';

const RequireUnauthenticated: FC = ({ children }) => {
const RequireUnauthenticated: FC<RequiredChildrenProps> = ({ children }) => {
const { features } = useContext(FeaturesContext);
const authenticationContext = useContext(AuthenticationContext);

Expand Down
4 changes: 3 additions & 1 deletion interface/src/components/routing/RouterTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { useNavigate } from 'react-router-dom';

import { Tabs, useMediaQuery, useTheme } from '@mui/material';

interface RouterTabsProps {
import { RequiredChildrenProps } from '../../utils';

interface RouterTabsProps extends RequiredChildrenProps {
value: string | false;
}

Expand Down
4 changes: 3 additions & 1 deletion interface/src/contexts/authentication/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { useNavigate } from 'react-router-dom';

import * as AuthenticationApi from '../../api/authentication';
import { ACCESS_TOKEN } from '../../api/endpoints';
import { RequiredChildrenProps } from '../../utils';
import { LoadingSpinner } from '../../components';
import { Me } from '../../types';

import { FeaturesContext } from '../features';
import { AuthenticationContext } from './context';

const Authentication: FC = ({ children }) => {
const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
const { features } = useContext(FeaturesContext);
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();
Expand Down
4 changes: 2 additions & 2 deletions interface/src/contexts/features/FeaturesLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { FC, useCallback, useEffect, useState } from 'react';

import * as FeaturesApi from '../../api/features';

import { extractErrorMessage } from '../../utils';
import { extractErrorMessage, RequiredChildrenProps } from '../../utils';
import { Features } from '../../types';
import {ApplicationError, LoadingSpinner} from '../../components';

import { FeaturesContext } from '.';

const FeaturesLoader: FC = (props) => {
const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {

const [errorMessage, setErrorMessage] = useState<string>();
const [features, setFeatures] = useState<Features>();
Expand Down
4 changes: 2 additions & 2 deletions interface/src/utils/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AxiosError } from "axios";

export const extractErrorMessage = (error: AxiosError, defaultMessage: string) => (
(error.response && error.response.data ? error.response.data.message : error.message) || defaultMessage
export const extractErrorMessage = (error: AxiosError<{ message?: string }>, defaultMessage: string) => (
(error?.response?.data?.message ? error.response.data.message : error.message) || defaultMessage
);
1 change: 1 addition & 0 deletions interface/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './submit';
export * from './time';
export * from './useRest';
export * from './useWs';
export * from './props';
3 changes: 3 additions & 0 deletions interface/src/utils/props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface RequiredChildrenProps {
children: React.ReactNode;
}
5 changes: 0 additions & 5 deletions lib/framework/ESPFS.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#ifdef ESP32
#include <SPIFFS.h>
#define ESPFS SPIFFS
#elif defined(ESP8266)
#include <LittleFS.h>
#define ESPFS LittleFS
#endif
4 changes: 2 additions & 2 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ MqttSettingsService::MqttSettingsService(AsyncWebServer* server, FS* fs, Securit
#ifdef ESP32
WiFi.onEvent(
std::bind(&MqttSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.onEvent(std::bind(&MqttSettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
#elif defined(ESP8266)
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(
std::bind(&MqttSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/NTPSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ NTPSettingsService::NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityM
#ifdef ESP32
WiFi.onEvent(
std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.onEvent(std::bind(&NTPSettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
#elif defined(ESP8266)
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(
std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/OTASettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OTASettingsService::OTASettingsService(AsyncWebServer* server, FS* fs, SecurityM
_arduinoOTA(nullptr) {
#ifdef ESP32
WiFi.onEvent(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
#elif defined(ESP8266)
_onStationModeGotIPHandler =
WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1));
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/WiFiSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
WiFi.mode(WIFI_MODE_NULL);
WiFi.onEvent(
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeStop, this, std::placeholders::_1, std::placeholders::_2),
WiFiEvent_t::SYSTEM_EVENT_STA_STOP);
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_STOP);
#elif defined(ESP8266)
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
Expand Down
8 changes: 4 additions & 4 deletions lib/framework/WiFiStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ WiFiStatus::WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager)
securityManager->wrapRequest(std::bind(&WiFiStatus::wifiStatus, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED));
#ifdef ESP32
WiFi.onEvent(onStationModeConnected, WiFiEvent_t::SYSTEM_EVENT_STA_CONNECTED);
WiFi.onEvent(onStationModeDisconnected, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
WiFi.onEvent(onStationModeGotIP, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
WiFi.onEvent(onStationModeConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
WiFi.onEvent(onStationModeDisconnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.onEvent(onStationModeGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
#elif defined(ESP8266)
_onStationModeConnectedHandler = WiFi.onStationModeConnected(onStationModeConnected);
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(onStationModeDisconnected);
Expand All @@ -23,7 +23,7 @@ void WiFiStatus::onStationModeConnected(WiFiEvent_t event, WiFiEventInfo_t info)

void WiFiStatus::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
Serial.print(F("WiFi Disconnected. Reason code="));
Serial.println(info.disconnected.reason);
Serial.println(info.wifi_sta_disconnected.reason);
}

void WiFiStatus::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
Expand Down
8 changes: 6 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ extra_scripts =

lib_deps =
ArduinoJson@>=6.0.0,<7.0.0
ESP Async WebServer@>=1.2.0,<2.0.0
AsyncMqttClient@>=0.8.2,<1.0.0
; The following allows the use of the latest code for ESPAsyncWebServer - there hasn't been a release in a while
; Work around for https://github.com/me-no-dev/ESPAsyncWebServer/issues/1151
https://github.com/me-no-dev/ESPAsyncWebServer
;ESP Async WebServer@>=1.2.0,<2.0.0
AsyncMqttClient@>=0.9.0,<1.0.0

[env:esp12e]
platform = espressif8266
Expand All @@ -48,3 +51,4 @@ board_build.filesystem = littlefs
board_build.partitions = min_spiffs.csv
platform = espressif32
board = node32s
board_build.filesystem = littlefs

0 comments on commit 004659b

Please sign in to comment.