sandeepmistry / node-sensortag

Node.js lib for the TI SensorTag
MIT License
218 stars 111 forks source link

Problem with the node sensorTag on Node-RED #15

Closed alphabeat closed 10 years ago

alphabeat commented 10 years ago

Hello,

First of all, thank you for providing such tools as noble and the sensortag library, that helped ma a lot !

I have a problem with the SensorTag and I have no idea of where it is coming from, despite a lot of debugging... I have two SensorTags and face the same problem with both of them : the SensorTags disconnect randomly with no reason and the only way to reconnect them is to press the Publish button on Node-RED (which means I have to make a change on my sheet and undo that change). I only have a SensorTag node and a debug node on the sheet. I run node-RED on a raspberry Pi (raspbian wheezy) and use a USB Bluetooth 4.0 dongle.

Sometimes the deconnexion happens after 5 minutes, sometimes it's after 30...

I have a few ideas to solve this problem but I'm not sure they are relevant and/or doable :

Do you have an idea of where the problem might be coming from ? Is it the node itself ? the sensortag library ? the noble library ?

I'm a bit lost and I don't have a lot of experience in node.js or debugging so I don't really know how to deal with that issue.

Another question : is it possible to connect two SensorTags at the same time with Node-RED ?

I also noticed that when I delete a SensorTag node from my sheet and add a new one, the old one is still active (I get every data twice !). I managed to fix that by removing the 'connect' and 'disconnect' listeners when the event 'disconnect' is triggered.

Thank you in advance for your answers, Julien K.

sandeepmistry commented 10 years ago

@alphabeat I haven't really used Node-RED, so most of your questions maybe be better answered by @hardillb or on this repo: https://github.com/node-red/node-red-nodes

@lahorde has noticed that enabling the gyroscope seems to make the SensorTag disconnect after a while. He also has an unmerged pull request (#13) that may address it.

noble supports connecting multiple sensortags.

Lahorde commented 10 years ago

@alphabeat to have reconnection working you must get sensortag node AND noble from my repo. Disconnection events are sent from native noble part. To test it, you can run https://github.com/Lahorde/node-sensortag/blob/master/test.js , during test you can put tag away from raspberry and then put it back more closely or you can enclose tag with your hands : in these case you should see disconnection events. For multiple sensortag node in node red, look at sensortag node red code, more precisely discovery.

Lahorde

alphabeat commented 10 years ago

Thank you for the quick replies !

@Lahorde I installed the sensortag node and noble from your repo, and ran test.js but I still have the same issues : when I enclose the tag with my hands, a disconnect event is triggered but test.js stops running instead of reconnecting the sensortag right after, it lasted a lot longer on Node-RED though, 1h45 this time before the disconnexion, that's a lot better ! :)

@sandeepmistry : unfortunately I need to use the gyroscope of the sensortag :/

I'm still looking for a way to go through this.

alphabeat commented 10 years ago

I added a button on the left of the node SensorTag (just like the node Inject) that launches the scan and makes it less difficult to reload everything (I don't have to delete the current node and add a new to make things work again when a disconnexion happen). The disconnexions still happen randomly, I'm trying right now with the gyroscope disabled to see if it could be the source of the problem.

I managed to launch the two SensorTags together too, without difficulty.

sandeepmistry commented 10 years ago

Closing due to lack of activity ... please re-open if necessary ...

vielmetti commented 9 years ago

Reopening....

The "random sensortag disconnect" feature is part of the stock sensortag firmware, which will go to sleep to save battery.

This organization has built new firmware for the sensortag that disables sleep mode, so that the device will be on continuously. They don't release source code for it but the object might be useful to your purpose. From all I can tell this doesn't otherwise affect communications with the device.

http://www.myweathercenter.net/installing-a-new-firmware-for-ti-sensortag/

Lahorde commented 9 years ago

@alphabeat I've modified test.js in order to continue test execution after a reconnection. @vielmetti check out http://stackoverflow.com/questions/22090954/how-to-modify-the-ti-sensortag-firmware-to-advertise-indefinitely , to reduce power consumption you can modify #define DEFAULT_ADVERTISING_INTERVAL 16384-1 it corresponds to max advertising interval : "For a Central to be able to connect to a Peripheral, the Peripheral must be advertising. It sends advertising packets with a time interval, known as the advertising interval, that ranges between 20 ms and 10.24 s. The advertising interval affects how long it takes to initiate a connection."

With this modification and https://github.com/Lahorde/node-sensortag sensortag won't be disconnected anymore.

vielmetti commented 9 years ago

@alphabeat You write

I added a button on the left of the node SensorTag (just like the node Inject)

Can you share that patch? It would be useful.

Thanks @Lahorde for the changes. I notice that your version of node-sensortag also supports reading the battery level, that's helpful too.

vargascyntiam commented 9 years ago

I am new to node red and was trying to use this library. I downloaded it from here, because it is different than the one npm gives me. However, when I run node, it says that it is waiting to register sensortag. Before I used thethingbox-sensortag, but I already uninstalled it so it wouldn't generate any conflict.

sandeepmistry commented 9 years ago

@vargascyntiam the version of node-sensortag that in master is not compatible with the node-red as far as I know.

@vielmetti has created an issue here to update node-red-nodes support: https://github.com/node-red/node-red-nodes/issues/107

vielmetti commented 9 years ago

Yes, there is an open issue. I've now got both a Mac and a Pi ready to test this, and a couple of sensortags (both v1 and v2, and three different firmware versions of the v1). I'll update issues when there's any progress.