I need to integrate DLMS/COSEM meter communication into a React Native mobile application. I came across the Gurux.DLMS.Android library, which seems to provide the functionality I need.
However, as someone relatively new to Java and unfamiliar with the inner workings of the Gurux library, I'm seeking advice and guidance on how to integrate it into my React Native project.
Here are a few specific questions I have:
1. Which classes/functions within the Gurux.DLMS.Android library should I focus on bridging for meter communication and data reading functionalities?
2. Are there any best practices or recommended approaches for bridging Java/Kotlin functionalities to React Native, especially for someone with limited Java experience?
3. How can I ensure compatibility and seamless interaction between the Gurux library and my React Native app.
Any tips or advice from those who have experience with similar integrations would be greatly appreciated. Also, If there are any resources that could help me better understand the usage of the Gurux library within a React Native context, please share them.
I can do the BLE part in the react native app itself.
Thank you in advance for your assistance!
hi piyushupadhyay i am…
hi piyushupadhyay i am facing same problem
form React Native JS class Through i am opening Android Activity and getting data
but i need to do click functionality in React Native
Hi, You need all classes…
Hi,
You need all classes. DLMS is not a very simple protocol and it's offering lots of features.
Our clients are not using React Native, so I can't help you with this.
BR,
Mikko
Include Gurux DLMS library …
You'll need to include Gurux DLMS Android library as Native Module in React Native (v0.62.3):
1. Generate the Gurux DLMS client library (.aar file)*. (Change default name "app-debug" to something meaningful)
2. Copy .aar file into /YOUR_REACT_NATIVE_APP/android/app/libs
(If you don't have libs folder, create a new one)
3. Add the following dependencies to android/app/build.gradle:
```gradle
implementation files('libs/gurux_dlms.aar')
implementation 'com.github.gurux:gurux.common.android:-SNAPSHOT'
implementation 'com.github.gurux:gurux.serial.android:-SNAPSHOT'
```
4. Modify the minSdkVersion in the android/build.gradle file from 21 to 28.
5. Modify android:allowBackup="false" to android:allowBackup="true" in the android/app/src/main/AndroidManifest.xml file.
6. Copy and paste the GXDevice.java file from Gurux DLMS Android repo -> https://github.com/Gurux/Gurux.DLMS.Android/blob/master/Java/app/src/ma… to android/app/src/main/java/com/YOUR_PROJECT/GXDevice.java.
7. Create the files DLMSClientModule.java, DLMSClientPackage.java (or name those files to anything you like), and modify MainApplication.java to include DLMSClientPackage. (Read this: https://reactnative.dev/docs/native-modules-android)
8. In the file where you'll use the native methods, add:
```javascript
import {
NativeModules,
} from 'react-native';
const MyNativeModule = NativeModules.YOUR_MODULE_NAME_HERE;
```
*To generate a .aar file in Android Studio, follow these steps:
1. Clone the GitHub repository - Gurux/Gurux.DLMS.Android: Gurux DLMS library for Android.
2. Open it with Android Studio.
3. Verify/wait for Gradle to download all necessary dependencies for the project.
4. Go to Build > Clean Project.
5. Go to Build > Rebuild Project.
6. Find the generated file (.aar) in ./AndroidStudioProjects/guruxDLMS/guruxlibrary/build/outputs.
Hi delanou, Thank you for…
Hi delanou,
Thank you for this information. It's interesting if Java packages can be used from React Native without any changes. This means that you can use builds from Maven Central and you only need to add those components for your grade like this:
implementation 'org.gurux:Gurux.Common.Android:2.0.2'
implementation 'org.gurux:gurux.serial.android:2.0.3'
implementation 'org.gurux:gurux.dlms.android:2.0.4'
BR,
Mikko