Use the obniz Board to search for and display a list of BLE devices in the vicinity.
Materials- BLE devices(unspecified, More than one is better.)
- obniz Board
- portable battery
- Mobile phone or PC
Hardware
The BLE is wireless, so you don’t need to connect anything to the pins of the obnizBoard.
Please connect only USB and turn on the power.
Software
In order to use the BLE, you need to initialize it first. The initialization code is as follows.
await obniz.ble.initWait();
To search for BLE devices around you, use the following code
You can change the search conditions by specifying the parameters in {}.
obniz.ble.scan.start({duration: 30});
You can read more information about BLE here.
When you start the program, you will see a list of device addresses in the list.Discovered devices will be added sequentially over time.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/obniz@3.x/obniz.js"></script>
</head>
<body>
<div id="obniz-debug"></div>
<select
name="device"
id="deviceSelector"
size="8"
style="width:200px"
></select>
<script>
/* eslint-disable no-undef, no-unused-vars */
let deviceSelector = $("#deviceSelector");
var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function() {
await obniz.ble.initWait();
obniz.ble.scan.start({ duration: 30 });
obniz.ble.scan.onfind = function(peripheral) {
let address = peripheral.address;
let localName = peripheral.localName
? "(" + peripheral.localName + ")"
: "";
let optionTag = `<option value="${address}">${address}${localName}</option>`;
deviceSelector.append(optionTag);
};
};
</script>
</body>
</html>
What is obniz?Before we get into the project, let's look into obniz.
Here → obniz for DIY electronics
obniz is a cloud-connected IoT development board. You can program on the web browser of any smartphone or computer and the command is sent to obniz through the internet via obniz cloud. By connecting the obniz to the cloud through wifi, users can remotely control devices that are physically connected to obniz.
Thanks to this cloud based approach, you can program with Python, Javascript, or other languages you prefer and control hardware directly. You don't need to integrate firmware into the device side. Recording and analyzing data is also easy with obniz cloud service.
Want to control hardware things with your current Python or Javascript skill? Want to start IoT project but don't know where to start? Want to learn programming with languages you prefer?
obniz will help you broaden your viewpoint and develop both your SW and HW skills.
For more information, please visit our official website → Official Website
Where to get obniz board? → Amazon /Official Store
Comments