I want to get data from several (generally unknown number) of rfduinos.
Found this thread on the forum: viewtopic.php?t=1473#p3838
According to the answer:
another point to note - you can only have a single device connected at any time; if you want to connect to both, you'll need to build some fancy logic to connect/do something/disconnect and move along to another device. great if you want to cycle through a few devices and collect information from them
I struggled for several days to make it work.
Results:
1. For some reason can only read data from one device most of the time;
2. If I have N devices on the list - the app reads data from the device N times (not one time from each device as I want to);
3. Sometimes the reading suddenly switches (I have the loop executed each second) to another device (this behaviour very rare - only saw once).
4. Getting connect error: "null" - this happens often.
Please help with functional code.
Details of my buggy code are below:
Code:
Code: Select all
for (var i = 0; i < app.activeDevices.length; i++)
{
app.connect(app.activeDevices[i]);
app.measure(app.device);
}
- activeDevices - stores names for devices to connect to - it populates correctly;
- connect(deviceName) is function from rfduino LED On/Off example (includes rfduinoble.close() in the beginning)
- measure(device) - is my function that makes graphical display of the data - works properly for single device.
Code: Select all
connect: function(deviceName)
{
rfduinoble.close();
//app.showMessage("Connecting...");
setTimeout(function()
{
rfduinoble.connect(
deviceName,
function(device)
{
//app.showMessage(deviceName + " connected");
app.device = device;
},
function(errorCode)
{
app.showMessage("Connect error: " + errorCode);
});
},
500);
},