How to detect 4G dongle(s) connected to my computer using NodeJs - node.js

How can I detect 4G dongle(s) connected to my computer using NodeJS?
I tried the following code:
var os = require('os');
var allNetworkInterfaces = os.networkInterfaces();
console.log(allNetworkInterfaces);
It works, but I got all network interfaces... I would like to get a list with my 4G dongles only. Knowing that I could have either 1 dongle, or several dongles connected to the same computer, as well as other USB hardwares connected.

After installing the usb package by running npm install usb I was able to get a list of usb devices using the following code:
const usb = require('usb');
const devices = usb.getDeviceList();
console.log( devices );
You will have to go through that list and decide which is your "4G dongle".

Related

Does WiPy Pysense Device will connect with Other Bluetooth Sensor Devices.?

Does the Pysense(WiPy) device will connect and get service from any other Bluetooth Sensor Devices available in the market.?
Yes we can connect any Bluetooth sensor with mac address using
bluetooth = Bluetooth()
bluetooth.start_scan(5)
while bluetooth.isscanning():
adv = bluetooth.get_adv()
if adv:
if(str(binascii.hexlify(adv.mac).decode()) == '78a50454b267'):
conn = bluetooth.connect(adv.mac)
print(type(conn))

SIM808 bluetooth issue

I've connected my sim808 module to a HC05 bluetooth module with SPP profile.
Hc05 UART config is 9600 , no parity,1 stop.
i'm connecting with these at commands:
AT+BTPOWER=1
AT+BTCONNECT=1,4 // I have already paired two devices
when i send message printf("0adch=0&temp=27&hu=14") via HC05 to SIM808 , it breaks message to multiple parts like below (I've connected SIM808 to PC via a usb-ttl convertor,so i can see messages on sim RX port) :
+BTSPPDATA: 1,1,0
+BTSPPDATA: 1,10,adch=0&tem
+BTSPPDATA: 1,10,p=27&hu=14

UWP Bluetooth RFComm ConnectAsync problems

I am developing an application which makes Bluetooth (RFComm, SPP) connections with a device. My Android App works like a charm but with UWP I have big problems getting the connection done using:
socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
When the device is connected everything works.
Sometimes the ConnectAsync takes a long time (1 minute) or finally it doesnt work.
It seems like when I start the App the first connection works and connects within a vew seconds but all following connections seem to be very unstable.
I tried different USB Dongles, but with same results. I am now on Win 10 Pro 64 1709.
I also tried the UWP RFComm Chat sample app. Same problems there.
Does somebody have similar problems? Any ideas?
Thanks,
Joachim
A few updates:
I testet a few other Dongles and SPP Devices. My results:
One SPP Device works, two have this problem. A not working example: BluePort XP and ASUS USB-BT400
Using Virtual COM Ports over Win32 API or .net SerialPort works on all devices!
Conclusion: Hardware works. The problem is on UWP using socket.ConnectAsync!
Is this a Win10 UWP Bug??!!
Second update:
I found out that if I use Devices from:
DeviceInformationCollection collection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
and connect using rfcomm:
var services = await _device.GetRfcommServicesForIdAsync(RfcommServiceId.SerialPort, BluetoothCacheMode.Uncached);
var op = _socket.ConnectAsync(_service.ConnectionHostName, _service.ConnectionServiceName);
then I have this problems with connection times - manly after the first connect/disconnect phase
BUT: When I use the virtual com ports created from SPP Dongles
DeviceInformationCollection collection = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{86E0D1E0-8089-11D0-9CE4-08003E301F73}\" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True");
and create a SerialDevice using:
var serialDevice = await SerialDevice.FromIdAsync(info.Id);
which automatically connects the bluetooth target while this serialDevice is created, then everything works perfect.

Johnny Five Over Bluetooth Connection Issue

I want to run commands from my computer to an Arduino using JS/Johnny-Five, wirelessly.
I have an Uno and an HC-05. I set the HC-05 up per the instructions in this URL. I can pair my computer to it and I have uploaded StandardFirmata to the Uno.
But it seems to time out when I try to communicate with it.
When I type, through NodeJS command line
> var five = require("johnny-five");
> var board = new five.Board({repl: false, port:'/dev/cu.ailaGduino-DevB'})
I get:
1480635008609 Connected /dev/cu.ailaGduino-DevB
undefined
> 1480635018633 Device or Firmware Error A timeout occurred while connecting to the Board.
Please check that you've properly flashed the board with the correct firmware.
See: https://github.com/rwaldron/johnny-five/wiki/Getting-Started#trouble-shooting
It later mentions Timer.listOnTimeout as part of the error call stack.
The Arduino IDE lists that specific device when paired, I guess that's why it says "Connected".
When I try the same command again, I get
> var board = new five.Board({port:'/dev/cu.ailaGduino-DevB'})
1480635041136 Connected /dev/cu.ailaGduino-DevB
undefined
> 1480635041138 Error Error Resource temporarily unavailable Cannot lock port
It was fine through USB.
Any ideas?
I think this bit is wrong as your addressing a locally connected device rather than a wifi connected device.
var board = new five.Board({port:'/dev/cu.ailaGduino-DevB'})
This tut suggests you need to connect to the board in a different fasion.
var EtherPortClient = require("etherport-client").EtherPortClient;
var board = new five.Board({
port: new EtherPortClient({
host: "xxx.xxx.xxx.xxx", // IP ESP8266
port: 3030
}),
timeout: 10000,
repl: false
});

Windows 10 - how to detect when a Bluetooth device is in range

I have previously paired with a Bluetooth device that supports RFCOMM.
When my app is opened I continuously try to connect to the device by opening the RFCOMM. This way my app automatically connects when the device comes in range.
deviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
LogData(String.Format("Number of mldp devices is {0}", deviceInfoCollection.Count));
foreach (DeviceInformation deviceInfo in deviceInfoCollection)
{
LogData(String.Format("ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
Then run this on a timer:
try
{
// The first time this method is invoked by a store app, it should be called
// from a UI thread in order to display the consent prompt
// https://msdn.microsoft.com/en-us/windows.devices.bluetooth.rfcomm.rfcommdeviceservice.fromidasync
RfcommDeviceService rfcommService = await RfcommDeviceService.FromIdAsync(deviceInfo.Id);
LogData(String.Format("ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
catch (Exception)
{
LogData(String.Format("Can not request rfcomm service from device ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
Is there any way to query when the device is in range , rather than trying to connect? I would prefer to only attempt connection when the device is in range.
For RFCOMM (BT2.0, BT2.1) you can run a device enumeration periodically, see also Get bluetooth devices in range
However your actual implementation with a connection attempt may work a little better.
For Bluetooth 4.0, you can listen to the advertisements of the BT module, see also https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BluetoothAdvertisement
If you're talking to an embedded device (e.g. some robot, or homebrew appliances using RFCOMM) I am afraid there is no better solution than what you're doing.
If you're taking to a phone (which supports both BT4.0 and BT2.1) you can use the BT4 advertisements to signal the proximity of the device, then connect via RFCOMM.

Resources