An application for reading air quality data from SDS011/SDS021 particulate matter sensors via USB serial connection.
We've significantly improved the codebase through several key changes:
-
Organized by Functionality: Grouped related functions into logical namespaces:
ByteUtils: Hex/decimal conversion utilitiesSensorPacket: Packet handling and parsing functionsSensorCommands: Command generationAirQualityIndex: Air quality categorization
-
Removed Debug Code: Eliminated excessive console.log statements to improve readability and performance
-
Better Structure: Improved organization makes the code more maintainable and easier to understand
-
Consolidated State Management:
- Combined related state variables into structured objects
- Better organization of connection state, config options, and timers
-
Improved Type Safety:
- Added proper TypeScript interfaces for all data structures
- Fixed issues with dynamic function references
-
Reliable Connection Handling:
- Better handling of device attachment/detachment
- More robust error recovery mechanisms
-
Updated to Use New Utilities:
- Leveraging the restructured utility functions
- Type-safe access to style properties
-
Reduced Code Duplication:
- Eliminated redundant conversion code
- Centralized sensor data processing logic
- More maintainable code: Better organization makes the code easier to understand and modify
- Reduced duplication: Common functions are defined once and reused
- Improved reliability: More robust error handling and device connection management
- Better type safety: Proper TypeScript typing throughout the codebase
Connect your SDS011/SDS021 sensor to your Android device via USB (requires OTG support). The app will automatically detect and connect to the sensor and begin displaying air quality measurements.
- PM2.5: Fine particulate matter (2.5 micrometers or smaller)
- PM10: Coarse particulate matter (10 micrometers or smaller)
The readings are color-coded according to standard air quality categories from Good (green) to Hazardous (dark pink).
- Connect to SDS011/SDS021 particulate matter sensors via USB
- Real-time monitoring of PM2.5 and PM10 air quality data
- Running averages of air quality measurements
- Device discovery and connection management
- Logs with user-friendly and developer modes
- Cross-platform support for Android and iOS
- Node.js (v18 or higher)
- React Native CLI
- Android Studio or Xcode (depending on target platform)
- SDS011 or SDS021 PM sensor (for testing)
-
Install dependencies:
npm install
-
Start the Metro server:
npm start
-
Run the app:
# For Android npm run android # For iOS npm run ios
-
Make sure you have a keystore file in
android/app/my-release-key.keystore- If you need to generate a keystore, run:
keytool -genkeypair -v -storetype PKCS12 -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
- Then move the generated file to
android/app/ - Important: The key alias must be exactly
my-key-aliasas configured in the app's build.gradle
- If you need to generate a keystore, run:
-
Create a
.envfile in the project root with your keystore passwords:ANDROID_STORE_PASSWORD=your-store-password ANDROID_KEY_PASSWORD=your-key-password
Run the following command to build a signed APK:
npm run build-android-releaseThe generated APK will be located at android/app/build/outputs/apk/release/app-release.apk
To build for iOS in release configuration:
npm run build-ios-releaseTo build for both platforms:
npm run build-releaseThis project includes a GitHub Actions workflow that automatically builds and publishes Android APKs when a new version tag is pushed.
-
Add the following secrets to your GitHub repository:
KEYSTORE_BASE64: Your base64-encoded keystore fileANDROID_STORE_PASSWORD: The password for your keystoreANDROID_KEY_PASSWORD: The password for your key alias
-
Convert your keystore to base64:
# On Linux/macOS base64 -i my-release-key.keystore # On Windows PowerShell [Convert]::ToBase64String([IO.File]::ReadAllBytes("my-release-key.keystore"))
-
Push a version tag to trigger a build:
git tag v1.0.0 git push origin v1.0.0
The workflow will:
- Build the APK with release signing
- Create a GitHub release for the tag
- Attach the APK to the release
-
Create a
.envfile in the project root with your keystore passwords:ANDROID_STORE_PASSWORD=your_store_password ANDROID_KEY_PASSWORD=your_key_password -
Make sure your keystore file is placed at
android/app/my-release-key.keystore -
Run the build command with environment variables loaded from .env:
npm run build-android-release-env
You can also provide environment variables directly:
# Windows PowerShell
$env:ANDROID_STORE_PASSWORD="your_password"
$env:ANDROID_KEY_PASSWORD="your_password"
npm run build-android-release
# Windows CMD
set ANDROID_STORE_PASSWORD=your_password
set ANDROID_KEY_PASSWORD=your_password
npm run build-android-release
# Linux/macOS
ANDROID_STORE_PASSWORD=your_password ANDROID_KEY_PASSWORD=your_password npm run build-android-release