{"action":"opened","issue":{"url":"https://api.github.com/repos/mysensors/MySensors/issues/928","repository_url":"https://api.github.com/repos/mysensors/MySensors","labels_url":"https://api.github.com/repos/mysensors/MySensors/issues/928/labels{/name}","comments_url":"https://api.github.com/repos/mysensors/MySensors/issues/928/comments","events_url":"https://api.github.com/repos/mysensors/MySensors/issues/928/events","html_url":"https://github.com/mysensors/MySensors/issues/928","id":258047272,"number":928,"title":"Receive corrupted ID when using multiple repeaters.","user":{"login":"goodchip","id":4836635,"avatar_url":"https://avatars3.githubusercontent.com/u/4836635?v=4","gravatar_id":"","url":"https://api.github.com/users/goodchip","html_url":"https://github.com/goodchip","followers_url":"https://api.github.com/users/goodchip/followers","following_url":"https://api.github.com/users/goodchip/following{/other_user}","gists_url":"https://api.github.com/users/goodchip/gists{/gist_id}","starred_url":"https://api.github.com/users/goodchip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goodchip/subscriptions","organizations_url":"https://api.github.com/users/goodchip/orgs","repos_url":"https://api.github.com/users/goodchip/repos","events_url":"https://api.github.com/users/goodchip/events{/privacy}","received_events_url":"https://api.github.com/users/goodchip/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-15T13:52:21Z","updated_at":"2017-09-15T13:52:21Z","closed_at":null,"author_association":"NONE","body":"\r\nHello,\r\n\r\nI recently installed a mysensors network in a large building on two floors. Since I have placed several repeaters, I find random problems during the associations of sensors.\r\n\r\n\r\n## Description of the problem :\r\n\r\nDuring the association, **randomly**, the sensor receives an ID longer than the 3 characters of range 0-255 normally expected.\r\n\r\nThese are often numbers 255 or 100 placed after the ID, other numbers appear or changes the ID itself, but this is more rare.\r\n\r\nI suspect that repeaters \"overwrite\" the value by repeating at the same time the payload. (not sure).\r\n\r\nThe fewer repeaters in the bridge area, the less problems are manifested. (no problem without repeaters).\r\n\r\n### Here are my logs when the problem occurs:\r\n> 0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1\r\n> 40 MCO:BGN:BFR\r\n> 57 TSM:INIT\r\n> 69 TSF:WUR:MS=0\r\n> 92 TSM:INIT:TSP OK\r\n> 112 TSM:FPAR\r\n> 126 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 686 TSF:MSG:READ,10-10-255,s=255,c=3,t=8,pt=1,l=1,sg=0:1\r\n> 747 TSF:MSG:FPAR OK,ID=10,D=2\r\n> 802 TSF:MSG:READ,111-111-255,s=255,c=3,t=8,pt=1,l=1,sg=0:1\r\n> 2205 TSM:FPAR:OK\r\n> 2222 TSM:ID\r\n> 2236 TSM:ID:REQ\r\n> 2252 TSF:MSG:SEND,255-255-10-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 4329 TSM:ID\r\n> 4341 TSM:ID:REQ\r\n> 4360 TSF:MSG:SEND,255-255-10-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 6434 TSM:ID\r\n> 6447 TSM:ID:REQ\r\n> 6465 TSF:MSG:SEND,255-255-10-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 8540 TSM:ID\r\n> 8552 TSM:ID:REQ\r\n> 8570 TSF:MSG:SEND,255-255-10-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 8644 TSF:MSG:READ,0-0-255,s=255,c=3,t=4,pt=0,l=6,sg=0:**197255**\r\n> **8708 TSF:SID:OK,ID=135**\r\n> 8732 TSF:MSG:READ,0-10-255,s=255,c=3,t=4,pt=0,l=6,sg=0:**197255**\r\n> 8798 TSF:MSG:BC\r\n> 8814 TSF:MSG:READ,0-111-255,s=255,c=3,t=4,pt=0,l=6,sg=0:**197255**\r\n> 8880 TSF:MSG:BC\r\n> 8898 TSF:MSG:READ,0-12-255,s=255,c=3,t=4,pt=0,l=6,sg=0:**197255**\r\n> 8962 TSF:MSG:BC\r\n> 8980 TSM:ID:OK\r\n> 8996 TSM:UPL\r\n> 9011 TSF:MSG:SEND,**135**-135-10-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1\r\n> 9099 TSF:MSG:READ,0-10-**135**,s=255,c=3,t=25,pt=1,l=1,sg=0:2\r\n> 9160 TSF:MSG:PONG RECV,HP=2\r\n> 9191 TSM:UPL:OK\r\n> 9207 TSM:READY:ID=**135**,PAR=10,DIS=2\r\n> 9246 TSF:MSG:SEND,**135**-135-10-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100\r\n> 9326 TSF:MSG:READ,0-10-**135**,s=255,c=3,t=15,pt=6,l=2,sg=0:0100\r\n> 9392 TSF:MSG:SEND,**135**-135-10-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1\r\n> 9474 TSF:MSG:SEND,**135**-135-10-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:10\r\n> 11552 TSF:MSG:SEND,**135**-135-10-0,s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=OK:sensor_test\r\n> 11642 TSF:MSG:SEND,**135**-135-10-0,s=255,c=3,t=12,pt=0,l=4,sg=0,ft=0,st=OK:v0.1\r\n> 11722 MCO:REG:REQ\r\n> 11743 TSF:MSG:SEND,**135**-135-10-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2\r\n> 11821 TSF:MSG:READ,0-10-**135**,s=255,c=3,t=27,pt=1,l=1,sg=0:1\r\n> 11884 MCO:PIM:NODE REG=1\r\n> 11909 MCO:BGN:STP\r\n> 11929 MCO:BGN:INIT OK,TSP=1\r\n> 22341 TSF:MSG:READ,0-10-**135**,s=255,c=3,t=6,pt=0,l=1,sg=0:M\r\n\r\nIn the example below, the good ID sent by the gateway is 197, the sensor receives 197255 and takes ID 135 after conversion:\r\n197255 = b110000001010000111, converted to uint8, only the last 8 bits on the right (b010000111) are retrieved, giving 135.\r\n\r\n### For information, here is the topology of the network setup:\r\n\r\n![img_0931](https://user-images.githubusercontent.com/4836635/30483613-c7ca5586-9a27-11e7-846d-1b4640149b0c.jpg)\r\n\r\n\r\n## Proposed amendment to the code:\r\n\r\nI have not yet figured out the exact origin of the problem, however it seems to me it would be a good idea that the protocol is resistant to this ID corruption:\r\n\r\nIn the transportAssignNodeID function of MyTransport.cpp, the test:\r\n```\r\n// verify if ID valid\r\nif (newNodeId! = GATEWAY_ADDRESS && newNodeId <= AUTO) {\r\n```\r\nReplacing \"! =\" With \"<=\" is not enough because the conversion to uint8 returns a pseudo-random number when the ID is greater than 255;\r\n\r\nChange to uint32 type rather than uint8 works but is not optimized and could result many side-effects.\r\n\r\nI propose this modification based on the length of the message which has the advantage of not touching the statement of the function:\r\n\r\n### Before:\r\n```\r\nbool transportAssignNodeID(const uint8_t newNodeId)\r\n{\r\n\t// verify if ID valid\r\n\tif (newNodeId != GATEWAY_ADDRESS && newNodeId != AUTO) {\r\n\t\t_transportConfig.nodeId = newNodeId;\r\n\t\ttransportSetAddress(newNodeId);\r\n\t\t// Write ID to EEPROM\r\n\t\thwWriteConfig(EEPROM_NODE_ID_ADDRESS, newNodeId);\r\n\t\tTRANSPORT_DEBUG(PSTR(\"TSF:SID:OK,ID=%d\\n\"),newNodeId);\t// Node ID assigned\r\n\t\treturn true;\r\n\t} else {\r\n\t\tTRANSPORT_DEBUG(PSTR(\"!TSF:SID:FAIL,ID=%d\\n\"),newNodeId);\t// ID is invalid, cannot assign ID\r\n\t\tsetIndication(INDICATION_ERR_NET_FULL);\r\n\t\t_transportConfig.nodeId = AUTO;\r\n\t\treturn false;\r\n\t}\r\n}\r\n```\r\n\r\n### After:\r\n```\r\nbool transportAssignNodeID(const uint8_t newNodeId)\r\n{\r\n\t// verify if ID corrupted\r\n\tif(mGetLength(_msg) <= 3) {\r\n\t\t// verify if ID valid\r\n\t\tif (newNodeId != GATEWAY_ADDRESS && newNodeId <= AUTO) {\r\n\t\t\t_transportConfig.nodeId = newNodeId;\r\n\t\t\ttransportSetAddress(newNodeId);\r\n\t\t\t// Write ID to EEPROM\r\n\t\t\thwWriteConfig(EEPROM_NODE_ID_ADDRESS, newNodeId);\r\n\t\t\tTRANSPORT_DEBUG(PSTR(\"TSF:SID:OK,ID=%d\\n\"),newNodeId);\t// Node ID assigned\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tTRANSPORT_DEBUG(PSTR(\"!TSF:SID:FAIL,ID=%d\\n\"),newNodeId);\t// ID is invalid, cannot assign ID\r\n\t} else {\r\n\t\tTRANSPORT_DEBUG(PSTR(\"!TSF:SID:FAIL,CORRUPT\\n\"),newNodeId);\t// ID is corrupted, cannot assign ID\r\n\t}\r\n\tsetIndication(INDICATION_ERR_NET_FULL);\r\n\t_transportConfig.nodeId = AUTO;\r\n\treturn false;\r\n}\r\n```\r\n\r\n### Log result example when ID corruction appears with this new transportAssignNodeID() function:\r\n> 0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1\r\n> 40 MCO:BGN:BFR\r\n> 57 TSM:INIT\r\n> 69 TSF:WUR:MS=0\r\n> 92 TSM:INIT:TSP OK\r\n> 112 TSM:FPAR\r\n> 126 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 710 TSF:MSG:READ,111-111-255,s=255,c=3,t=8,pt=1,l=1,sg=0:1\r\n> 772 TSF:MSG:FPAR OK,ID=111,D=2\r\n> 985 TSF:MSG:READ,10-10-255,s=255,c=3,t=8,pt=1,l=1,sg=0:1\r\n> 2205 TSM:FPAR:OK\r\n> 2222 TSM:ID\r\n> 2236 TSM:ID:REQ\r\n> 2252 TSF:MSG:SEND,255-255-111-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 4329 TSM:ID\r\n> 4341 TSM:ID:REQ\r\n> 4360 TSF:MSG:SEND,255-255-111-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 6434 TSM:ID\r\n> 6447 TSM:ID:REQ\r\n> 6465 TSF:MSG:SEND,255-255-111-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 8540 TSM:ID\r\n> 8552 TSM:ID:REQ\r\n> 8570 TSF:MSG:SEND,255-255-111-0,s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:\r\n> 8646 TSF:MSG:READ,0-10-255,s=255,c=3,t=4,pt=0,**l=6**,sg=0:**197255**\r\n> **8710 !TSF:SID:FAIL,CORRUPT**\r\n> 8730 TSF:MSG:READ,0-111-255,s=255,c=3,t=4,pt=0,**l=6**,sg=0:**197255**\r\n> **8796 !TSF:SID:FAIL,CORRUPT**\r\n> 8816 TSF:MSG:READ,0-111-255,s=255,c=3,t=4,pt=0,**l=3**,sg=0:**197**\r\n> **8880 TSF:SID:OK,ID=197**\r\n> 8904 TSM:ID:OK\r\n> 8921 TSM:UPL\r\n> 8935 TSF:MSG:SEND,**197**-197-111-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1\r\n> 9029 TSF:MSG:READ,0-111-197,s=255,c=3,t=25,pt=1,l=1,sg=0:2\r\n> 9091 TSF:MSG:PONG RECV,HP=2\r\n> 9119 TSM:UPL:OK\r\n> 9138 TSM:READY:ID=**197**,PAR=111,DIS=2\r\n> 9177 TSF:MSG:SEND,**197**-197-111-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100\r\n> 9256 TSF:MSG:READ,0-111-**197**,s=255,c=3,t=15,pt=6,l=2,sg=0:0100\r\n> 9324 TSF:MSG:SEND,**197**-197-111-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1\r\n> 9408 TSF:MSG:SEND,**197**-197-111-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:111\r\n> 9531 TSF:MSG:READ,0-111-**197**,s=255,c=3,t=6,pt=0,l=1,sg=0:M\r\n> 9594 TSF:MSG:SEND,**197**-197-111-0,s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=OK:sensor_test\r\n> 9684 TSF:MSG:SEND,**197**-197-111-0,s=255,c=3,t=12,pt=0,l=4,sg=0,ft=0,st=OK:v0.1\r\n> 9764 MCO:REG:REQ\r\n> 9785 TSF:MSG:SEND,**197**-197-111-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2\r\n> 9863 TSF:MSG:READ,0-111-**197**,s=255,c=3,t=27,pt=1,l=1,sg=0:1\r\n> 9924 MCO:PIM:NODE REG=1\r\n> 9949 MCO:BGN:STP\r\n> 9967 MCO:BGN:INIT OK,TSP=1\r\n\r\nBest Regards.\r\n\r\n"}}
{"actor":{"display_login":"goodchip"}}