ETI Bluetherm LE Protocol 1.1 integration
This is an integration to the thermalib SDK from the company ETI, to read temperature from their theromoter devices, e.g. Thermapen © Blue Theromoter (pictured).
- thermalib-expo
- Installation in managed Expo projects
- Installation in bare React Native projects
- Usage
- Permissions
- Scanning for devices
- Configure for Android
- Configure for iOS
- Running the Expo module example
- Contributing
Table of contents generated with markdown-toc
Note that you need to install expo-location as well to make BLE work on Android API >= 30.
Make sure to configure your app.json accordingly.
npx expo install @mobione/thermalib-expo expo-location
Add @mobione/thermalib-expo
to your app.json
to include the module in Expo build:
// ./app.json
{
"expo": {
"name": "ThermalibApp",
"slug": "thermalib",
"version": "1.0.0",
"orientation": "portrait",
"plugins": [
"@mobione/thermalib-expo",
]
}
}
For bare React Native projects, you must ensure that you have installed and configured the expo
package before continuing.
Screenshot is from the included example.
When you call upon any function like startScanning
, it is still imperative that you request bluetooth permissions first. The module includes a standard helper to achieve this.
import { requestBluetoothPermission } from "@mobioone/thermalib-expo";
await requestBluetoothPermission();
import thermalib, { Device, requestBluetoothPermission } from "@mobioone/thermalib-expo";
export default function App() {
const onChangePayload = useEvent(thermalib, "onChange");
const startScanning = async () => {
await requestBluetoothPermission();
await thermalib?.startScanning();
getDevices();
};
...
}
import { thermalib, Device, requestBluetoothPermission } from "@mobioone/thermalib-expo";
export default function App() {
const [devices, setDevices] = useState<Device[]>([]);
const getDevices = async () => {
await requestBluetoothPermission();
const devs = thermalib?.devices();
if (devs) {
setDevices(devs.map((d) => d as Device));
} else {
console.log("No devices");
}
};
...
}
import { thermalib, Device, requestBluetoothPermission } from "@mobioone/thermalib-expo";
export default function App() {
const [selectedDev, setSelectedDev] = useState<Device | undefined>(undefined);
const selectDevice = (deviceId: string) => {
console.log("Fetch device", deviceId);
const dev = thermalib.readDevice(deviceId) as { device?: Device };
if (dev?.device?.deviceName) {
setSelectedDev(dev.device);
}
};
...
}
import { thermalib, Device, requestBluetoothPermission } from "@mobioone/thermalib-expo";
export default function App() {
const [reading, setReading] = useState<number | undefined>(undefined);
const getTemperature = (deviceId: string) => {
console.log("Scan device", deviceId);
const read = thermalib.readTemperature(deviceId) as {
reading?: number;
};
setReading(read.reading);
};
...
}
This library depends on Bluetooth LE (low energy) and will add the required permissions to your app. For Android, the following permissions are added. Remember to still ask for permissions before calling any BT function.
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:targetApi="31"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
Run npx pod-install
after installing the npm package.
npm run build # typescript
# in a separate terminal
npm run prepare
npm run prepub
npm run pods
cd example
npm run prebuild
npm run pods
npm run android # or ios
For convenience, we've added a command that runs all the required steps from the root project:
npm run android:build
- Commit and push your feature.
- Up version in
package.json
using the scriptnpm version patch
. This will tag and push to your branch. - PR and merge your branch.
- Draft a new Release from that the new tag.
- GitHub Action builds and publishes. The package becomes available in "packages" GitHub page.
Contributions are very welcome! Please refer to guidelines described in the contributing guide.