- Tue Oct 25, 2016 1:19 pm
#57102
There is a bug hidden in the manageConnections() function in the easyMeshConnection.cpp file ... after stripping all of the timesync stuff from the code and just running the connection and nodesync code I still get STA disconnects (dropping by the AP) for NO apparent reason ... even when the timeout is set as high as 10 sec ... here is one of the debug message from the AP log ...
Code: Select allmanageConnections(): dropping 10417291 NODE_TIMEOUT last=4289636273 node=4289641320
and here is the code snippit that generated this line ...
Code: Select allvoid ICACHE_FLASH_ATTR easyMesh::manageConnections( void ) {
debugMsg( GENERAL, "manageConnections():\n");
SimpleList<meshConnectionType>::iterator connection = _connections.begin();
while ( connection != _connections.end() ) {
if ( connection->lastRecieved + NODE_TIMEOUT < getNodeTime() ) {
debugMsg( CONNECTION, "manageConnections(): dropping %d NODE_TIMEOUT last=%u node=%u\n",
connection->chipId, connection->lastRecieved, getNodeTime() );
connection = closeConnection( connection );
continue;
}
as you can see ... the node timeout value isn't being applied to the equation as expected ...
lastrecieved (4289636273) + timeout (10000000) = 4299636273 ... but that doesn't match the results ...
because 4299636273 is NOT less than 4289641320 (but 4289636273 is) ... so the only way this would kick off is if NODE_TIMEOUT value was not being added to lastrecieved value ... If it is being evaluated
as 0 ... this would explain why it kicked off here ... BUT why isn't it always kicking off?? since
lastrecieved will always be less than now ... so I tried this ... to see what is going on ...
Code: Select allvoid ICACHE_FLASH_ATTR easyMesh::manageConnections( void ) {
debugMsg( GENERAL, "manageConnections():\n");
uint32_t nowNodeTime;
SimpleList<meshConnectionType>::iterator connection = _connections.begin();
while ( connection != _connections.end() ) {
nowNodeTime = getNodeTime();
if ( (connection->lastRecieved + NODE_TIMEOUT ) < nowNodeTime ) {
debugMsg( CONNECTION, "manageConnections(): dropping %d timeout=%u + last=%u (%u) <
now=%u\n", connection->chipId, NODE_TIMEOUT, connection->lastRecieved,
connection->lastRecieved+NODE_TIMEOUT, nowNodeTime );
connection = closeConnection( connection );
continue;
}
as you can see ... this equation is not working as expected ...
Code: Select allmanageConnections(): dropping 10417291 timeout=10000000 + last=4287984446 (4297984446) < now=4287989636
manageConnections(): dropping 0 timeout=10000000 + last=4293502101 (4303502101) < now=4293513943
manageConnections(): dropping 10417291 timeout=10000000 + last=4288418750 (4298418750) < now=4288424734
manageConnections(): dropping 10417291 timeout=10000000 + last=4288672786 (4298672786) < now=4288678269
so now i'm trying this ... i'll let you know how it goes ...
Code: Select allvoid ICACHE_FLASH_ATTR easyMesh::manageConnections( void ) {
debugMsg( GENERAL, "manageConnections():\n");
uint32_t nowNodeTime;
uint32_t nodeTimeOut = NODE_TIMEOUT;
uint32_t connLastRecieved;
uint32_t totalTimeOut;
SimpleList<meshConnectionType>::iterator connection = _connections.begin();
while ( connection != _connections.end() ) {
nowNodeTime = getNodeTime();
connLastRecieved = connection->lastRecieved;
totalTimeOut = connLastRecieved + nodeTimeOut;
if ( totalTimeOut < nowNodeTime ) {
debugMsg( CONNECTION, "manageConnections(): dropping %d timeout=%u + last=%u (%u) <
now=%u\n", connection->chipId, nodeTimeOut, connLastRecieved,
totalTimeOut, nowNodeTime );
connection = closeConnection( connection );
continue;
}
UPDATE: this code is doomed to crash at the clock rollover ... I am now running this to see if the drops continue ...
Code: Select allvoid ICACHE_FLASH_ATTR easyMesh::manageConnections( void ) {
debugMsg( GENERAL, "manageConnections():\n");
uint32_t nowNodeTime;
uint32_t nodeTimeOut = NODE_TIMEOUT;
uint32_t connLastRecieved;
SimpleList<meshConnectionType>::iterator connection = _connections.begin();
while ( connection != _connections.end() ) {
nowNodeTime = getNodeTime();
connLastRecieved = connection->lastRecieved;
// The trick is to always calculate the time difference, and not compare the two time values.
if ( nowNodeTime - connLastRecieved > nodeTimeOut ) {
debugMsg( CONNECTION, "manageConnections(): dropping %d now= %u - last= %u ( %u ) > timeout= %u \n", connection->chipId, nowNodeTime, connLastRecieved, nowNodeTime - connLastRecieved, nodeTimeOut );
connection = closeConnection( connection );
continue;
}
If this makes a change tonight ... i'll push changes to github devel ...
UPDATE: If anyone wants to run this across multiple nodes ... I pushed the code here ... just a reminder ... it's ONLY the connection and nodesync stuff ... no timesync ... just for testing
https://github.com/sfranzyshen/easyMesh/tree/no-timing
Last edited by sfranzyshen on Tue Oct 25, 2016 7:30 pm, edited 3 times in total.