I'm running a sample code from ESP32 examples and I'm scanning available BLE devices. I can see device MAC address etc. But for few devices I can't see their names.I am using ESP-WROOM-32 with hardware support checked out directly from their github.When I use LightBlue app for discovery of BLE Devices I can see names for more devices than ESP can. What can I change to see the names correctly? OR Can how can I parse device name from the data I'm receiving?
This callback code
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
Serial.print(" RSSI: ");
Serial.println(advertisedDevice.getRSSI());
}
};
produces this output:
Advertised Device: Name: , Address: 1d:0c:c7:3a:fb:c6, manufacturer data: 4c0009060378c0a81f12, payload: 1073609632
RSSI: -75
Related
I am looking for a way to get the device IP that is not based on Wifi. I am unable to find the local IP of the current device when compiling to Linux app running on an ethernet connection with no wifi card.
I tried using 'package:wifi/wifi.dart' and 'package:network_info_plus/network_info_plus.dart' to get the device's local ip and both packages gave this error: MissingPluginException (MissingPluginException(No implementation found for method ip on channel plugins.ly.com/wifi))
Is there a way to get the device local IP without a Wifi card?
UPDATE:
Using https://stackoverflow.com/a/52411510/5861729 and https://stackoverflow.com/a/43803986/16477035 I was able to figure out a clean way to get my local ip.
// Find localIp
String localIp = '';
final List<String> privateNetworkMasks = ['10', '172.16', '192.168'];
for (var interface in await NetworkInterface.list()) {
for (var addr in interface.addresses) {
for (final possibleMask in privateNetworkMasks) {
if (addr.address.startsWith(possibleMask)) {
localIp = addr.address;
break;
}
}
}
}
Run 'flutter clean' then 'flutter pub get' and re install your app
I was given a react native application to work with bluetooth headset. By using the following code I was able to detect the bluetooth device connectivity on/off and alert the end user. But addition to these I was asked to fetch the battery level and some more information and some more features to be implemented with the mobile application like control the volume level of the headset through the mobile application. Is there are any react native library which we can use for this purpose apart from the following code ?
import { NativeEventEmitter, NativeModules } from "react-native"
const BluetoothHeadsetDetectModule = NativeModules.RNBluetoothHeadsetDetect
const bluetoothHeadsetDetectEmitter = new NativeEventEmitter(
BluetoothHeadsetDetectModule
)
export default class MainScreen extends Component {
componentDidMount() {
bluetoothHeadsetDetectEmitter.addListener("onChange", ({ devices }) => {
if (devices.length && devices == "xxxx") {
}
})
}
}
I have a c# application that can open a cash drawer with the Windows Driver Installed. Pretty simple as the driver makes the USB device appears as a serial port:
SerialPort rsPort = new SerialPort(textBox1.Text);
byte[] openCmd = new byte[5];
openCmd[0] = 27;
openCmd[1] = 112;
openCmd[2] = 0;
openCmd[3] = 60;
openCmd[4] = 255;
rsPort.Open();
Thread.Sleep(100);
rsPort.Write(openCmd, 0, 5);
Thread.Sleep(100);
rsPort.Close();
I'm now trying to open the same USB cash Drawer via WebUSB. I've used ZaDig to install a generic USB drive and Chrome can see the USB device; can open the device; however, i'm struggling to send the correct commands.
Here is an image of the config:
Here is my current code:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript WebUSB</h2>
<button id="myBtn">Try it</button>
<script>
document.getElementById("myBtn").addEventListener("click", talkToDrawer);
async function talkToDrawer() {
try {
let device = await navigator.usb.requestDevice({ filters: [{ vendorId: 1659 }] });
console.log(device);
await device.open(); // Begin a session.
await device.selectConfiguration(1); // Select configuration #1 for the device.
await device.claimInterface(0); // Request exclusive control over interface #2.
result = await device.controlTransferOut({
requestType: 'standard', // tried all combinations: standard / class / vendor
recipient: 'endpoint', // tried all combinations: device / interface / endpoint / other
request: 0x27,
value: 0,
index: 1
});
result = await device.controlTransferOut({
requestType: 'standard', // tried all combinations: standard / class / vendor
recipient: 'endpoint', // tried all combinations: device / interface / endpoint / other
request: 0x112,
value: 0,
index: 1
});
result = await device.controlTransferOut({
requestType: 'standard', // tried all combinations: standard / class / vendor
recipient: 'endpoint', // tried all combinations: device / interface / endpoint / other
request: 0x0,
value: 0,
index: 1
});
result = await device.controlTransferOut({
requestType: 'standard', // tried all combinations: standard / class / vendor
recipient: 'endpoint', // tried all combinations: device / interface / endpoint / other
request: 0x60,
value: 0,
index: 1
});
result = await device.controlTransferOut({
requestType: 'standard', // tried all combinations: standard / class / vendor
recipient: 'endpoint', // tried all combinations: device / interface / endpoint / other
request: 0x255,
value: 0,
index: 1
});
} catch (error) {
console.log(error);
}
}
</script>
</body>
</html>
Without knowing more about the device there are two errors I see in the code,
In the C# example the command is [27, 112, 0, 60, 255] with the values given in decimal while in the Javascript example the values are given as hexadecimal constants. The appropriate code for constructing the command buffer in Javascript is,
const cmd = new Uint8Array([27, 112, 0, 60, 255]);
Rather than using controlTransferOut() to send the data it is most likely correct to use transferOut() and select endpoint number 3. The Prolific USB-to-serial converter chips implement a protocol similar to the standard USB serial class, which uses a pair of bulk IN and OUT endpoints for the serial data stream,
result = await device.transferOut(3, cmd);
The remaining open question is whether you need to perform any control transfers before you can send this command. Control transfers are used to configure the device and for a USB-to-serial chip this usually involves things like setting baud rate or setting the DCE bit high. When reverse-engineering how to communicate with a USB device I recommend using Wireshark to view the USB traffic from a working driver.
Note, that if you are working with a serial device you should take a the Serial API. There is an experimental implementation available in Chrome behind the chrome://flags/#enable-experimental-web-platform-features flag. This API is designed for applications specifically targeting serial devices and avoids having to re-implement the driver for the USB-to-serial chip.
https://learn.microsoft.com/en-us/azure/iot-suite/iot-suite-connecting-devices#create-a-c-sample-solution-on-windows
Add the following functions that execute when the device receives the SetTemperature and SetHumidity commands from IoT Hub:
EXECUTE_COMMAND_RESULT SetTemperature(Thermostat* thermostat, int temperature)
{
(void)printf("Received temperature %d\r\n", temperature);
thermostat->Temperature = temperature;
return EXECUTE_COMMAND_SUCCESS;
}
EXECUTE_COMMAND_RESULT SetHumidity(Thermostat* thermostat, int humidity)
{
(void)printf("Received humidity %d\r\n", humidity);
thermostat->Humidity = humidity;
return EXECUTE_COMMAND_SUCCESS;
}
Add the following function that sends a message to IoT Hub:
static void sendMessage(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const unsigned char* buffer, size_t size)
{
IOTHUB_MESSAGE_HANDLE messageHandle = IoTHubMessage_CreateFromByteArray(buffer, size);
if (messageHandle == NULL)
{
printf("unable to create a new IoTHubMessage\r\n");
}
else
{
if (IoTHubClient_SendEventAsync(iotHubClientHandle, messageHandle, NULL, NULL) != IOTHUB_CLIENT_OK)
{
printf("failed to hand over the message to IoTHubClient");
}
else
{
printf("IoTHubClient accepted the message for delivery\r\n");
}
IoTHubMessage_Destroy(messageHandle);
}
free((void*)buffer);
}
More in given link
The article you're referring to here shows you how to build and run this sample code on a Windows desktop machine using Visual Studio. There are two other equivalent articles that show you how to run the same code on a Linux machine or an mbed device.
If you want to follow an in-depth tutorial on how to use another hardware device such as a Raspberry Pi or Intel Edison with Azure IoT Hub, then take a look at the collection of IoT Hub tutorials in the Get started folder here.
Im trying to read the data in NFC tag using web development. I am able to detect tags from emulator, but on Gear S2 it does not work.
I have given all the privileges in config.xml
<tizen:privilege name="http://tizen.org/privilege/nfc.common"/>
<tizen:privilege name="http://tizen.org/privilege/nfc.tag"/>
<tizen:privilege name="http://tizen.org/privilege/bluetooth.admin"/>
<tizen:privilege name="http://tizen.org/privilege/nfc.admin"/>
<tizen:privilege name="http://tizen.org/privilege/nfc.cardemulation"/>
I am using whiztags NFC tags with Gear S2, they are working with my mobile(Nexus 5).
I have switched on the NFC in my watch, but still they don't respond to tags.
Code:
var adapter = tizen.nfc.getDefaultAdapter();
adapter.setPowered(
true, // Enable NFC adapter
function () {console.log('Power on success');}, // Handle succes
function () {console.log('Power on failed');}); // Handle failure
//
var onSuccessCB = {onattach : function(nfcTag) {
console.log("NFC Tag's type is " + nfcTag.type);
navigator.vibrate([600, 100, 300, 200, 0]);
for(var i in nfcTag.properties) {
console.log("key:" + i + " value:" + nfcTag.properties[i]);
}
}, ondetach : function() {
console.log("NFC Tag is detached");
}};
adapter.setTagListener(onSuccessCB);
The NFC API is optional for both Tizen mobile and wearable profiles, which means that it may not be supported in all mobile and wearable devices. The NFC API is supported on the Tizen wearable Emulator, but not on the Tizen mobile Emulator.
Please go through this link for more details.
I've seen some other people having same issue. Have a look on this link too.