src/
screens/ # All screen components (UI pages)
services/ # API and MQTT service logic
utils/ # Utility/helper functions
navigation/ # Navigation setup (React Navigation)
components/ # (Optional) Reusable UI components
App.js # Entry point
- HomeScreen.tsx: Welcome/landing page, entry to the app.
- DevicesScreen.tsx: List and control your IoT devices (switches, sensors).
- ConnectedDevicesScreen.tsx: Shows all connected devices, with status and quick info.
- SensorDetailScreen.tsx: Detailed view for a sensor, with charts and controls.
- ControlPanelScreen.tsx: (If used) For advanced device controls.
- SettingsScreen.tsx: App and account settings.
- HistoryScreen.js: (If used) Shows historical sensor/device data.
- DashboardScreen.js: (If used) Main dashboard with summary widgets.
- api.js: Handles HTTP requests to your backend (fetch latest data, fetch history, etc.) using Axios. Uses
EXPO_PUBLIC_API_URLfrom your environment. - mqttService.ts: Handles MQTT connections, subscriptions, and publishing (mocked or real).
- deviceUtils.ts: Device type definitions, ID generation, value formatting, MQTT message parsing/creation.
- index.tsx: Sets up React Navigation (tab and stack navigators). Example: Home, Devices, Settings tabs, with nested stacks for device details.
import React from 'react';
import Navigation from './src/navigation';
export default function App() {
return <Navigation />;
}- Use
.envorapp.json/app.config.jsto setEXPO_PUBLIC_API_URLfor your backend API.
Install these in your new project:
npx create-expo-app my-iot-app
cd my-iot-app
npm install @expo/vector-icons @react-navigation/native @react-navigation/bottom-tabs @react-navigation/native-stack react-native-screens react-native-safe-area-context axios mqtt
npm install react-native-reanimated react-native-gesture-handler react-native-svg
npm install --save-dev @types/react @types/react-native typescript- Create a new Expo project:
npx create-expo-app my-iot-app - Copy only these folders/files from your old project to the new one:
src/screens/src/services/src/utils/src/navigation/- (Optional)
src/components/
- Copy your
App.js(see example above). - Install dependencies as listed above.
- Set up your environment variable for the API URL.
- Run the app:
npm startornpx expo run:android
- If you see errors about missing packages, install them as needed.
- If you see native build errors, make sure you have not copied any
android/orios/folders from the old project. - Only copy JavaScript/TypeScript source files and assets.